dropdownValidator.php 6.06 KB
Newer Older
moyooo's avatar
moyooo committed
1
<?php
2 3 4
/**
 * ---------------------------------------------------------------------
 * GLPI - Gestionnaire Libre de Parc Informatique
5
 * Copyright (C) 2015-2018 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
      case 'user' :
yllen's avatar
yllen committed
46
         if (isset($_POST['users_id_validate']['groups_id'])) {
47
            $_POST['users_id_validate'] = [];
yllen's avatar
yllen committed
48 49
         }
         $value = (isset($_POST['users_id_validate'][0]) ? $_POST['users_id_validate'][0] : 0);
50
         User::dropdown(['name'   => !empty($_POST['name']) ? $_POST['name'].'[]'
moyooo's avatar
moyooo committed
51 52
                                                                 :'users_id_validate[]',
                              'entity' => $_POST['entity'],
yllen's avatar
yllen committed
53
                              'value'  => $value,
54
                              'right'  => $_POST['right']]);
moyooo's avatar
moyooo committed
55 56 57
         break;

      case 'group' :
yllen's avatar
yllen committed
58
         $name = !empty($_POST['name']) ? $_POST['name'].'[groups_id]':'groups_id';
yllen's avatar
yllen committed
59 60
         $value = (isset($_POST['users_id_validate']['groups_id']) ? $_POST['users_id_validate']['groups_id'] : $_POST['groups_id']);

61
         $rand = Group::dropdown(['name'      => $name,
yllen's avatar
yllen committed
62
                                       'value'     => $value,
63
                                       'entity'    => $_POST["entity"]]);
moyooo's avatar
moyooo committed
64

65
         $param                        = ['validatortype' => 'list_users'];
yllen's avatar
yllen committed
66
         $param['name']                = !empty($_POST['name']) ? $_POST['name'] : '';
moyooo's avatar
moyooo committed
67
         $param['users_id_validate']   = isset($_POST['users_id_validate'])
yllen's avatar
yllen committed
68
                                             ? $_POST['users_id_validate'] : '';
moyooo's avatar
moyooo committed
69 70 71 72 73 74
         $param['right']               = $_POST['right'];
         $param['entity']              = $_POST["entity"];
         $param['groups_id']           = '__VALUE__';
         Ajax::updateItemOnSelectEvent("dropdown_$name$rand", "show_list_users",
                                       $CFG_GLPI["root_doc"]."/ajax/dropdownValidator.php",
                                       $param);
yllen's avatar
yllen committed
75 76 77 78 79 80 81
         if ($value) {
            $param['validatortype'] = 'list_users';
            $param['groups_id']     = $value;
            unset($param['users_id_validate']['groups_id']);
            Ajax::updateItem('show_list_users', $CFG_GLPI["root_doc"]."/ajax/dropdownValidator.php",
            $param);
         }
moyooo's avatar
moyooo committed
82 83 84 85
         echo "<br><span id='show_list_users'>&nbsp;</span>\n";
         break;

      case 'list_users' :
yllen's avatar
yllen committed
86
         if (isset($_POST['users_id_validate']['groups_id'])) {
87
            $_POST['users_id_validate'] = [];
yllen's avatar
yllen committed
88
         }
89
         $opt             = ['groups_id' => $_POST["groups_id"],
yllen's avatar
yllen committed
90
                                  'right'     => $_POST['right'],
91
                                  'entity'    => $_POST["entity"]];
yllen's avatar
yllen committed
92
         $data_users      = TicketValidation::getGroupUserHaveRights($opt);
93 94 95
         $users           = [];
         $param['values'] = [];
         $values          = [];
yllen's avatar
yllen committed
96 97 98
         if (isset($_POST['users_id_validate']) && is_array($_POST['users_id_validate'])) {
            $values = $_POST['users_id_validate'];
         }
Anael Mobilia's avatar
Anael Mobilia committed
99
         foreach ($data_users as $data) {
moyooo's avatar
moyooo committed
100 101
            $users[$data['id']] = formatUserName($data['id'], $data['name'], $data['realname'],
                                                 $data['firstname']);
yllen's avatar
yllen committed
102 103 104
            if (in_array($data['id'], $values)) {
               $param['values'][] = $data['id'];
            }
moyooo's avatar
moyooo committed
105
         }
yllen's avatar
yllen committed
106

107 108 109
         // Display all users
         if (isset($_POST['all_users'])
             && $_POST['all_users']) {
moyooo's avatar
moyooo committed
110 111 112 113 114 115
            $param['values'] =  array_keys($users);
         }
         $param['multiple']= true;
         $param['display'] = true;
         $param['size']    = count($users);

116
         $rand  = Dropdown::showFromArray(!empty($_POST['name']) ? $_POST['name']:'users_id_validate',
yllen's avatar
yllen committed
117
                                          $users, $param);
moyooo's avatar
moyooo committed
118 119

         // Display all/none buttons to select all or no users in group
Anael Mobilia's avatar
Anael Mobilia committed
120
         if (!empty($_POST['groups_id'])) {
121
            echo "<br><br><a id='all_users' class='vsubmit'>".__('All')."</a>";
Cédric Anne's avatar
Cédric Anne committed
122 123 124 125 126 127 128 129 130
            $param_button = [
               'validatortype'     => 'list_users',
               'name'              => !empty($_POST['name']) ? $_POST['name']:'',
               'users_id_validate' => '',
               'all_users'         => 1,
               'groups_id'         => $_POST['groups_id'],
               'entity'            => $_POST['entity'],
               'right'             => $_POST['right'],
            ];
yllen's avatar
yllen committed
131 132
            Ajax::updateItemOnEvent('all_users', 'show_list_users',
                                    $CFG_GLPI["root_doc"]."/ajax/dropdownValidator.php",
133
                                    $param_button, ['click']);
moyooo's avatar
moyooo committed
134 135 136

            echo "&nbsp;<a id='no_users' class='vsubmit'>".__('None')."</a>";
            $param_button['all_users'] = 0;
yllen's avatar
yllen committed
137 138
            Ajax::updateItemOnEvent('no_users', 'show_list_users',
                                    $CFG_GLPI["root_doc"]."/ajax/dropdownValidator.php",
139
                                    $param_button, ['click']);
moyooo's avatar
moyooo committed
140 141 142 143
         }
         break;
   }
}