-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathuser.class.php
More file actions
180 lines (157 loc) · 5.74 KB
/
user.class.php
File metadata and controls
180 lines (157 loc) · 5.74 KB
1
2
3
4
5
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?php
/**
* -------------------------------------------------------------------------
* Escalade plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Escalade.
*
* Escalade 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.
*
* Escalade 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 Escalade. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2015-2023 by Escalade plugin team.
* @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/pluginsGLPI/escalade
* -------------------------------------------------------------------------
*/
class PluginEscaladeUser extends CommonDBTM {
/**
* @since version 0.85
*
* @see CommonDBTM::showMassiveActionsSubForm()
**/
static function showMassiveActionsSubForm(MassiveAction $ma) {
switch ($ma->getAction()) {
case "use_filter_assign_group" :
Dropdown::showYesNo("use_filter_assign_group", 0, -1, [
'width' => '100%',
]);
echo "<br><br><input type=\"submit\" name=\"massiveaction\" class=\"submit\" value=\"" .
_sx('button', 'Post') . "\" >";
break;
}
return true;
}
/**
* @since version 0.85
*
* @see CommonDBTM::processMassiveActionsForOneItemtype()
**/
static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) {
switch ($ma->getAction()) {
case "use_filter_assign_group":
$escalade_user = new self();
$input = $ma->getInput();
foreach ($ids as $id) {
if ($escalade_user->getFromDBByCrit(['users_id' => $id])) {
$escalade_user->fields['use_filter_assign_group'] = $input['use_filter_assign_group'];
if ($escalade_user->update($escalade_user->fields)) {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
}
}
}
}
}
static private function getUserGroup($entity, $userid, $filter = '', $first = true) {
global $DB;
$criteria = [
'SELECT' => ['glpi_groups.id'],
'FROM' => 'glpi_groups_users',
'INNER JOIN' => [
'glpi_groups' => [
'ON' => [
'glpi_groups_users' => 'groups_id',
'glpi_groups' => 'id'
]
]
],
'WHERE' => [
'glpi_groups_users.users_id' => $userid,
getEntitiesRestrictCriteria('glpi_groups', '', $entity, true, true)
],
'ORDER' => ['glpi_groups_users.id']
];
if ($filter) {
$criteria['WHERE'][] = new QueryExpression($filter);
}
$it = $DB->request($criteria);
$rep = [];
foreach ($it as $data) {
if ($first) {
return $data['id'];
}
$rep[] = $data['id'];
}
return ($first ? 0 : array_pop($rep));
}
static function getRequesterGroup($entity, $userid, $first = true) {
return self::getUserGroup($entity, $userid, '`is_requester`', $first);
}
static function getTechnicianGroup($entity, $userid, $first = true) {
return self::getUserGroup($entity, $userid, '`is_assign`', $first);
}
function showForm($ID, array $options = []) {
$is_exist = $this->getFromDBByCrit(['users_id' => $ID]);
if (! $is_exist) { //"Security"
$this->fields["use_filter_assign_group"] = 0;
}
echo "<form action='" . $this->getFormURL() . "' method='post'>";
echo "<table class='tab_cadre_fixe'>";
$rand = mt_rand();
echo "<tr class='tab_bg_1'>";
echo "<td><label>";
echo __("Bypass filtering on the groups assignment", "escalade");
echo " ";
Dropdown::showYesNo("use_filter_assign_group", $this->fields["use_filter_assign_group"], -1, [
'width' => '100%',
'rand' => $rand,
]);
echo "</label>";
echo "</td>";
echo "</tr>";
echo "<tr class='tab_bg_1'>";
echo "<td class='center' colspan='2'>";
echo "<input type='hidden' name='users_id' value='$ID'>";
if (! $is_exist) {
echo "<input type='submit' name='add' value='"._sx('button', 'Add')."' class='submit'>";
} else {
echo "<input type='hidden' name='id' value='".$this->getID()."'>";
echo "<input type='submit' name='update' value='"._sx('button', 'Update')."' class='submit'>";
}
echo "</td></tr>";
echo "</table>";
Html::closeForm();
}
static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {
switch ($item->getType()) {
case 'User':
$user = new self();
$ID = $item->getField('id');
$user->showForm($ID);
break;
}
return true;
}
function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
switch ($item->getType()) {
case 'User':
return __("Escalation", "escalade");
default :
return '';
}
}
}