dropdownMassiveActionAddValidator.php 4.99 KB
Newer Older
moyooo's avatar
moyooo committed
1
<?php
2
3
4
/**
 * ---------------------------------------------------------------------
 * GLPI - Gestionnaire Libre de Parc Informatique
5
 * Copyright (C) 2015-2021 Teclib' and contributors.
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 *
 * http://glpi-project.org
 *
 * based on GLPI - Gestionnaire Libre de Parc Informatique
 * Copyright (C) 2003-2014 by the INDEPNET Development Team.
 *
 * ---------------------------------------------------------------------
 *
 * LICENSE
 *
 * This file is part of GLPI.
 *
 * GLPI is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * GLPI is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GLPI. If not, see <http://www.gnu.org/licenses/>.
 * ---------------------------------------------------------------------
moyooo's avatar
moyooo committed
31
32
 */

Anael Mobilia's avatar
Anael Mobilia committed
33
34
35
/**
 * @since 0.85
 */
moyooo's avatar
moyooo committed
36
37
38
39
40
41
42
43

$AJAX_INCLUDE = 1;
include ('../inc/includes.php');

header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();

if (isset($_POST["validatortype"])) {
Anael Mobilia's avatar
Anael Mobilia committed
44
   switch ($_POST["validatortype"]) {
moyooo's avatar
moyooo committed
45
46
      case 'user' :
         echo "<input type='hidden' name='groups_id' value=0 />";
47
         User::dropdown(['name'   => 'users_id_validate',
moyooo's avatar
moyooo committed
48
                              'entity' => $_SESSION["glpiactive_entity"],
49
                              'right'  => ['validate_request', 'validate_incident']]);
moyooo's avatar
moyooo committed
50
51
52
53

         echo "<br><br>".__('Comments')." ";
         echo "<textarea name='comment_submission' cols='50' rows='6'></textarea>&nbsp;";

Cédric Anne's avatar
Cédric Anne committed
54
         echo "<input type='submit' name='add' value=\""._sx('button', 'Add')."\" class='btn btn-primary'>";
moyooo's avatar
moyooo committed
55
56
57
58
         break;

      case 'group' :
         echo "<input type='hidden' name='users_id_validate' value=0 />";
59
60
         $rand = Group::dropdown(['name'      => 'groups_id',
                                       'entity'    => $_SESSION["glpiactive_entity"]]);
moyooo's avatar
moyooo committed
61

62
         $param = ['validatortype'      => 'group_user',
moyooo's avatar
moyooo committed
63
                        'groups_id' =>'__VALUE__',
64
                        'right'     => ['validate_request', 'validate_incident']];
moyooo's avatar
moyooo committed
65
66
67
68
69
70
71
72
73

         Ajax::updateItemOnSelectEvent("dropdown_groups_id$rand", "show_groups_users",
                                       $CFG_GLPI["root_doc"]."/ajax/dropdownMassiveActionAddValidator.php",
                                       $param);

         echo "<br><span id='show_groups_users'>&nbsp;</span>\n";
         break;

      case 'group_user' :
74

75
         $opt = ['groups_id'   => $_POST["groups_id"],
moyooo's avatar
moyooo committed
76
                           'right'     => $_POST['right'],
77
                           'entity'    => $_SESSION["glpiactive_entity"]];
78

moyooo's avatar
moyooo committed
79
80
         $groups_users = TicketValidation::getGroupUserHaveRights($opt);

81
82
         $users           = [];
         $param['values'] =  [];
Anael Mobilia's avatar
Anael Mobilia committed
83
         foreach ($groups_users as $data) {
moyooo's avatar
moyooo committed
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
            $users[$data['id']] = formatUserName($data['id'], $data['name'], $data['realname'],
                                                 $data['firstname']);
         }

         if (isset($_POST['all_users'])
             && $_POST['all_users']) {
            $param['values'] =  array_keys($users);
         }

         $param['multiple']= true;
         $param['display'] = true;
         $param['size']    = count($users);

         Dropdown::showFromArray("users_id_validate", $users, $param);

          // Display all/none buttons to select all or no users in group
Anael Mobilia's avatar
Anael Mobilia committed
100
         if (!empty($_POST['groups_id'])) {
Cédric Anne's avatar
Cédric Anne committed
101
            echo "<a id='all_users' class='btn btn-primary'>".__('All')."</a>";
Cédric Anne's avatar
Cédric Anne committed
102
103
104
105
106
107
108
109
            $param_button = [
               'validatortype'     => 'group_user',
               'users_id_validate' => '',
               'all_users'         => 1,
               'groups_id'         => $_POST['groups_id'],
               'right'             => ['validate_request', 'validate_incident'],
               'entity'            => $_SESSION["glpiactive_entity"],
            ];
moyooo's avatar
moyooo committed
110
111
            Ajax::updateItemOnEvent('all_users', 'show_groups_users',
                                    $CFG_GLPI["root_doc"]."/ajax/dropdownMassiveActionAddValidator.php",
112
                                    $param_button, ['click']);
moyooo's avatar
moyooo committed
113

Cédric Anne's avatar
Cédric Anne committed
114
            echo "&nbsp;<a id='no_users' class='btn btn-primary'>".__('None')."</a>";
moyooo's avatar
moyooo committed
115
116
117
            $param_button['all_users'] = 0;
            Ajax::updateItemOnEvent('no_users', 'show_groups_users',
                                    $CFG_GLPI["root_doc"]."/ajax/dropdownMassiveActionAddValidator.php",
118
                                    $param_button, ['click']);
moyooo's avatar
moyooo committed
119
120
121
122
123
         }

         echo "<br><br>".__('Comments')." ";
         echo "<textarea name='comment_submission' cols='50' rows='6'></textarea>&nbsp;";

Cédric Anne's avatar
Cédric Anne committed
124
         echo "<input type='submit' name='add' value=\""._sx('button', 'Add')."\" class='btn btn-primary'>";
moyooo's avatar
moyooo committed
125
126
127
128
         break;
   }

}