1
|
|
|
<?php |
|
|
|
|
2
|
|
|
//$Id: staff.php,v 1.23 2005/11/30 15:58:08 eric_juden Exp $ |
3
|
|
|
include('../../../include/cp_header.php'); |
4
|
|
|
include_once('admin_header.php'); |
5
|
|
|
include_once(XHELP_CLASS_PATH.'/xhelpPageNav.php'); |
6
|
|
|
|
7
|
|
|
global $xoopsModule, $xoopsModuleConfig; |
|
|
|
|
8
|
|
|
$module_id = $xoopsModule->getVar('mid'); |
9
|
|
|
$displayName =& $xoopsModuleConfig['xhelp_displayName']; // Determines if username or real name is displayed |
10
|
|
|
|
11
|
|
|
$aLimitByS = array('10' => 10, '15' => 15, '20' => 20, '25' => 25, '50' => 50, '100' => 100); |
12
|
|
|
$aLimitByD = array('1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '10' => 10); |
13
|
|
|
|
14
|
|
|
$op = 'default'; |
15
|
|
|
|
16
|
|
|
if ( isset( $_REQUEST['op'] ) ) |
17
|
|
|
{ |
18
|
|
|
$op = $_REQUEST['op']; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
switch ( $op ) |
22
|
|
|
{ |
23
|
|
|
case "addRole": |
24
|
|
|
addRole(); |
25
|
|
|
break; |
26
|
|
|
|
27
|
|
|
case "clearOrphanedStaff": |
28
|
|
|
clearOrphanedStaff(); |
29
|
|
|
break; |
30
|
|
|
|
31
|
|
|
case "clearRoles": |
32
|
|
|
clearRoles(); |
33
|
|
|
break; |
34
|
|
|
|
35
|
|
|
case "customDept": |
36
|
|
|
customDept(); |
37
|
|
|
break; |
38
|
|
|
|
39
|
|
|
case "editRole": |
40
|
|
|
editRole(); |
41
|
|
|
break; |
42
|
|
|
|
43
|
|
|
case "editStaff": |
44
|
|
|
editStaff(); |
45
|
|
|
break; |
46
|
|
|
|
47
|
|
|
case "manageStaff": |
48
|
|
|
manageStaff(); |
49
|
|
|
break; |
50
|
|
|
|
51
|
|
|
default: |
52
|
|
|
header("Location: ".XHELP_BASE_URL."/admin/index.php"); |
53
|
|
|
break; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
function addRole() |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
require_once(XHELP_CLASS_PATH.'/session.php'); |
59
|
|
|
$_xhelpSession = new Session(); |
60
|
|
|
if(!isset($_POST['add'])){ |
61
|
|
|
// Set array of security items |
62
|
|
|
$tasks = array(XHELP_SEC_TICKET_ADD => _AM_XHELP_SEC_TEXT_TICKET_ADD, |
63
|
|
|
XHELP_SEC_TICKET_EDIT => _AM_XHELP_SEC_TEXT_TICKET_EDIT, |
64
|
|
|
XHELP_SEC_TICKET_DELETE => _AM_XHELP_SEC_TEXT_TICKET_DELETE, |
65
|
|
|
XHELP_SEC_TICKET_MERGE => _AM_XHELP_SEC_TEXT_TICKET_MERGE, |
66
|
|
|
XHELP_SEC_TICKET_OWNERSHIP => _AM_XHELP_SEC_TEXT_TICKET_OWNERSHIP, |
67
|
|
|
XHELP_SEC_TICKET_STATUS => _AM_XHELP_SEC_TEXT_TICKET_STATUS, |
68
|
|
|
XHELP_SEC_TICKET_PRIORITY => _AM_XHELP_SEC_TEXT_TICKET_PRIORITY, |
69
|
|
|
XHELP_SEC_TICKET_LOGUSER => _AM_XHELP_SEC_TEXT_TICKET_LOGUSER, |
70
|
|
|
XHELP_SEC_RESPONSE_ADD => _AM_XHELP_SEC_TEXT_RESPONSE_ADD, |
71
|
|
|
XHELP_SEC_RESPONSE_EDIT => _AM_XHELP_SEC_TEXT_RESPONSE_EDIT, |
72
|
|
|
XHELP_SEC_FILE_DELETE => _AM_XHELP_SEC_TEXT_FILE_DELETE, |
73
|
|
|
XHELP_SEC_FAQ_ADD => _AM_XHELP_SEC_TEXT_FAQ_ADD, |
74
|
|
|
XHELP_SEC_TICKET_TAKE_OWNERSHIP => _AM_XHELP_SEC_TEXT_TICKET_TAKE_OWNERSHIP); |
75
|
|
|
xoops_cp_header(); |
76
|
|
|
//echo $oAdminButton->renderButtons('manStaff'); |
77
|
|
|
$indexAdmin = new ModuleAdmin(); |
78
|
|
|
echo $indexAdmin->addNavigation('staff.php?op=addRole'); |
79
|
|
|
|
80
|
|
|
echo '<script type="text/javascript" src="'.XOOPS_URL.'/modules/xhelp/include/functions.js"></script>'; |
81
|
|
|
echo "<form action='staff.php?op=addRole' method='post'>"; |
82
|
|
|
echo "<table width='100%' cellspacing='1' class='outer'>"; |
83
|
|
|
echo "<tr><th colspan='2'>"._AM_XHELP_TEXT_CREATE_ROLE."</th></tr>"; |
84
|
|
|
echo "<tr><td class='head'>"._AM_XHELP_TEXT_NAME."</td> |
85
|
|
|
<td class='even'><input type='text' name='roleName' maxlength='35' value='' class='formButton'></td> |
86
|
|
|
</tr>"; |
87
|
|
|
echo "<tr><td class='head'>"._AM_XHELP_TEXT_DESCRIPTION."</td> |
88
|
|
|
<td class='even'><textarea name='roleDescription' class='formButton'></textarea></td> |
89
|
|
|
</tr>"; |
90
|
|
|
echo "<tr><td class='head'>"._AM_XHELP_TEXT_PERMISSIONS."</td> |
91
|
|
|
<td class='even'> |
92
|
|
|
<table border='0'> |
93
|
|
|
<tr><td>"; |
94
|
|
|
foreach($tasks as $bit_value => $task){ |
95
|
|
|
echo "<tr><td><input type='checkbox' name='tasks[]' value='". pow(2,$bit_value) ."' />".$task."</td></tr>"; |
96
|
|
|
} |
97
|
|
|
echo "<tr><td><input type='checkbox' name='allTasks' value='0' onclick='selectAll(this.form,\"tasks[]\",this.checked);' /><b>"._AM_XHELP_TEXT_SELECT_ALL."</b></td></tr>"; |
98
|
|
|
echo "</table> |
99
|
|
|
</td> |
100
|
|
|
</tr>"; |
101
|
|
|
echo "<tr> |
102
|
|
|
<td colspan='2' class='foot'> |
103
|
|
|
<input type='submit' name='add' value='". _AM_XHELP_BUTTON_CREATE_ROLE ."' class='formButton'> |
104
|
|
|
<input type='button' name='cancel' value='"._AM_XHELP_BUTTON_CANCEL."' onclick='history.go(-1)' class='formButton' /> |
105
|
|
|
</td> |
106
|
|
|
</tr>"; |
107
|
|
|
echo "</table></form>"; |
108
|
|
|
include_once "admin_footer.php"; |
109
|
|
View Code Duplication |
} else { |
110
|
|
|
$hRole =& xhelpGetHandler('role'); |
111
|
|
|
|
112
|
|
|
$role =& $hRole->create(); |
113
|
|
|
$role->setVar('name', $_POST['roleName']); |
114
|
|
|
$role->setVar('description', $_POST['roleDescription']); |
115
|
|
|
if(isset($_POST['tasks'])){ |
116
|
|
|
$tasksValue = array_sum($_POST['tasks']); |
117
|
|
|
} else { |
118
|
|
|
$tasksValue = 0; |
119
|
|
|
} |
120
|
|
|
$role->setVar('tasks', $tasksValue); |
121
|
|
|
|
122
|
|
|
$lastPage = $_xhelpSession->get("xhelp_return_op"); |
123
|
|
|
|
124
|
|
|
if($hRole->insert($role)){ |
125
|
|
|
$message = _AM_XHELP_MESSAGE_ROLE_INSERT; |
|
|
|
|
126
|
|
|
header("Location: ".XHELP_ADMIN_URL."/staff.php?op=$lastPage"); |
127
|
|
|
} else { |
128
|
|
|
$message = _AM_XHELP_MESSAGE_ROLE_INSERT_ERROR; |
129
|
|
|
redirect_header(XHELP_ADMIN_URL."/staff.php?op=$lastPage", 3, $message); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
function clearOrphanedStaff() |
135
|
|
|
{ |
136
|
|
|
$hMember =& xoops_gethandler('member'); |
137
|
|
|
$hStaff =& xhelpGetHandler('staff'); |
138
|
|
|
$users =& $hMember->getUserList(); |
139
|
|
|
$staff =& $hStaff->getObjects(); |
140
|
|
|
|
141
|
|
|
$aUsers = array(); |
142
|
|
|
foreach($staff as $stf){ |
143
|
|
|
$staff_uid = $stf->getVar('uid'); |
144
|
|
|
if(!array_key_exists($staff_uid, $users)){ |
145
|
|
|
$aUsers[$staff_uid] = $staff_uid; |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
$crit = new Criteria('uid', "(". implode($aUsers, ',') .")", "IN"); |
150
|
|
|
$ret = $hStaff->deleteAll($crit); |
151
|
|
|
|
152
|
|
|
if($ret){ |
153
|
|
|
header("Location: ".XHELP_ADMIN_URL."/staff.php?op=manageStaff"); |
154
|
|
|
} else { |
155
|
|
|
redirect_header(XHELP_ADMIN_URL."/staff.php?op=manageStaff", 3, _AM_XHELP_MSG_CLEAR_ORPHANED_ERR); |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
function clearRoles() |
160
|
|
|
{ |
161
|
|
|
require_once(XHELP_CLASS_PATH.'/session.php'); |
162
|
|
|
$_xhelpSession = new Session(); |
163
|
|
|
|
164
|
|
|
$hDept =& xhelpGetHandler('department'); |
165
|
|
|
$depts =& $hDept->getObjects(); |
166
|
|
|
|
167
|
|
|
foreach($depts as $dept){ |
168
|
|
|
$deptid = $dept->getVar('id'); |
169
|
|
|
if($deptRoles = $_xhelpSession->get("xhelp_dept_$deptid")){ |
|
|
|
|
170
|
|
|
$_xhelpSession->del("xhelp_dept_$deptid"); |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
if(!$returnPage =& $_xhelpSession->get("xhelp_return_page")){ |
175
|
|
|
$returnPage = false; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
$_xhelpSession->del("xhelp_return_page"); |
179
|
|
|
$_xhelpSession->del("xhelp_mainRoles"); |
180
|
|
|
$_xhelpSession->del("xhelp_mainDepts"); |
181
|
|
|
$_xhelpSession->del("xhelp_return_op"); |
182
|
|
|
|
183
|
|
View Code Duplication |
if(!$returnPage){ |
184
|
|
|
header("Location: ".XHELP_ADMIN_URL."/staff.php?op=manageStaff"); |
185
|
|
|
} else { |
186
|
|
|
header("Location: ".XHELP_ADMIN_URL."/$returnPage"); |
187
|
|
|
} |
188
|
|
|
exit(); |
|
|
|
|
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
function customDept() |
|
|
|
|
192
|
|
|
{ |
193
|
|
|
require_once(XHELP_CLASS_PATH.'/session.php'); |
194
|
|
|
$_xhelpSession = new Session(); |
195
|
|
|
global $xoopsUser, $displayName; |
|
|
|
|
196
|
|
|
|
197
|
|
|
$lastPage = $_xhelpSession->get("xhelp_return_op"); |
198
|
|
|
|
199
|
|
View Code Duplication |
if(isset($_REQUEST['uid'])){ |
200
|
|
|
$uid = intval($_REQUEST['uid']); |
201
|
|
|
} else { |
202
|
|
|
$uid = 0; |
203
|
|
|
} |
204
|
|
|
if($uid == 0){ |
205
|
|
|
redirect_header(XHELP_ADMIN_URL."/staff.php?op=$lastPage", 3, _AM_XHELP_MSG_NEED_UID); |
206
|
|
|
} |
207
|
|
|
if(isset($_REQUEST['deptid'])){ |
208
|
|
|
$deptid = intval($_REQUEST['deptid']); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
if(!isset($_POST['submit'])){ |
212
|
|
|
if(isset($_POST['addRole'])){ |
213
|
|
|
|
214
|
|
|
$_xhelpSession->set("xhelp_return_op2", $lastPage); |
215
|
|
|
$_xhelpSession->set("xhelp_return_op", substr(strstr($_SERVER['REQUEST_URI'], 'op='), 3)); |
216
|
|
|
header("Location: ".XHELP_ADMIN_URL."/staff.php?op=addRole"); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
View Code Duplication |
if(isset($_GET['xhelp_role'])){ |
220
|
|
|
$aRoles = explode(",", $_GET['xhelp_role']); |
221
|
|
|
foreach($aRoles as $role){ |
222
|
|
|
$role = intval($role); |
223
|
|
|
} |
224
|
|
|
$_xhelpSession->set("xhelp_mainRoles", $aRoles); // Store roles from the manage staff page |
225
|
|
|
} |
226
|
|
|
|
227
|
|
View Code Duplication |
if(isset($_GET['xhelp_depts'])){ |
228
|
|
|
$aDepts = explode(",", $_GET['xhelp_depts']); |
229
|
|
|
foreach($aDepts as $dept){ |
230
|
|
|
$dept = intval($dept); |
231
|
|
|
} |
232
|
|
|
$_xhelpSession->set("xhelp_mainDepts", $aDepts); // Store depts from the manage staff page |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
$hDept =& xhelpGetHandler('department'); |
236
|
|
|
$hRole =& xhelpGetHandler('role'); |
237
|
|
|
|
238
|
|
|
$dept =& $hDept->get($deptid); |
|
|
|
|
239
|
|
|
|
240
|
|
|
$crit = new Criteria('', ''); |
241
|
|
|
$crit->setOrder('ASC'); |
242
|
|
|
$crit->setSort('name'); |
243
|
|
|
$roles =& $hRole->getObjects($crit); |
244
|
|
|
|
245
|
|
|
$lastPage = $_xhelpSession->get("xhelp_return_op"); |
246
|
|
|
xoops_cp_header(); |
247
|
|
|
|
248
|
|
|
echo '<script type="text/javascript" src="'.XOOPS_URL.'/modules/xhelp/include/functions.js"></script>'; |
249
|
|
|
echo "<form action='staff.php?op=customDept&deptid=".$deptid."&uid=".$uid."' method='post'>"; |
250
|
|
|
echo "<table width='100%' cellspacing='1' class='outer'>"; |
251
|
|
|
echo "<tr><th colspan='2'>"._AM_XHELP_TEXT_DEPT_PERMS."</th></tr>"; |
252
|
|
|
echo "<tr><td class='head' width='20%'>"._AM_XHELP_TEXT_USER."</td> |
253
|
|
|
<td class='even'>".xhelpGetUsername($uid, $displayName)."</td></tr>"; |
254
|
|
|
echo "<tr><td class='head'>"._AM_XHELP_TEXT_DEPARTMENT."</td> |
255
|
|
|
<td class='even'>".$dept->getVar('department')."</td></tr>"; |
256
|
|
|
echo "<tr><td class='head'>". _AM_XHELP_TEXT_ROLES ."</td> |
257
|
|
|
<td class='even'><table width='75%'>"; |
258
|
|
|
|
259
|
|
|
$bFound = false; |
260
|
|
|
if($storedRoles =& $_xhelpSession->get("xhelp_dept_$deptid")){ // If editing previously customized dept |
261
|
|
|
foreach ($roles as $role){ |
262
|
|
|
if($storedRoles['roles'] != -1){ |
263
|
|
|
foreach($storedRoles['roles'] as $storedRole){ |
264
|
|
|
if($role->getVar('id') == $storedRole){ |
265
|
|
|
$bFound = true; |
266
|
|
|
break; |
267
|
|
|
} else { |
268
|
|
|
$bFound = false; |
269
|
|
|
} |
270
|
|
|
} |
271
|
|
|
} |
272
|
|
|
if($bFound){ |
273
|
|
|
echo "<tr><td><input type='checkbox' name='roles[]' checked='checked' value='". $role->getVar('id')."' /><a href='staff.php?op=editRole&id=".$role->getVar('id')."&uid=". $uid ."'>". $role->getVar('name') ."</a> - ". $role->getVar('description')."</td></tr>"; |
274
|
|
|
} else { |
275
|
|
|
echo "<tr><td><input type='checkbox' name='roles[]' value='". $role->getVar('id')."' /><a href='staff.php?op=editRole&id=".$role->getVar('id')."&uid=". $uid ."'>". $role->getVar('name') ."</a> - ". $role->getVar('description')."</td></tr>"; |
276
|
|
|
} |
277
|
|
|
} |
278
|
|
|
} elseif($mainRoles = $_xhelpSession->get("xhelp_mainRoles")){ // If roles set on manage staff page |
279
|
|
View Code Duplication |
foreach($roles as $role){ |
280
|
|
|
if(!in_array($role->getVar('id'), $mainRoles)){ |
281
|
|
|
echo "<tr><td><input type='checkbox' name='roles[]' value='". $role->getVar('id')."' /><a href='staff.php?op=editRole&id=".$role->getVar('id')."&uid=". $uid ."'>". $role->getVar('name') ."</a> - ". $role->getVar('description')."</td></tr>"; |
282
|
|
|
} else { |
283
|
|
|
echo "<tr><td><input type='checkbox' name='roles[]' value='". $role->getVar('id')."' checked='checked' /><a href='staff.php?op=editRole&id=".$role->getVar('id')."&uid=". $uid ."'>". $role->getVar('name') ."</a> - ". $role->getVar('description')."</td></tr>"; |
284
|
|
|
} |
285
|
|
|
} |
286
|
|
|
} elseif($lastPage == "editStaff" && (!$storedRoles =& $_xhelpSession->get("xhelp_dept_$deptid"))){ |
287
|
|
|
$hStaff =& xhelpGetHandler('staff'); |
288
|
|
|
$myRoles =& $hStaff->getRolesByDept($uid, $deptid); |
289
|
|
|
|
290
|
|
|
$bFound = false; |
291
|
|
|
foreach($roles as $role){ |
292
|
|
|
if(!empty($myRoles)){ |
293
|
|
|
foreach($myRoles as $myRole){ |
294
|
|
|
if($role->getVar('id') == $myRole->getVar('roleid')){ |
295
|
|
|
$bFound = true; |
296
|
|
|
break; |
297
|
|
|
} else { |
298
|
|
|
$bFound = false; |
299
|
|
|
} |
300
|
|
|
} |
301
|
|
|
} |
302
|
|
|
if($bFound){ |
303
|
|
|
echo "<tr><td><input type='checkbox' name='roles[]' checked='checked' value='". $role->getVar('id')."' /><a href='staff.php?op=editRole&id=".$role->getVar('id')."&uid=". $uid ."'>". $role->getVar('name') ."</a> - ". $role->getVar('description')."</td></tr>"; |
304
|
|
|
} else { |
305
|
|
|
echo "<tr><td><input type='checkbox' name='roles[]' value='". $role->getVar('id')."' /><a href='staff.php?op=editRole&id=".$role->getVar('id')."&uid=". $uid ."'>". $role->getVar('name') ."</a> - ". $role->getVar('description')."</td></tr>"; |
306
|
|
|
} |
307
|
|
|
} |
308
|
|
|
} else { |
309
|
|
|
foreach($roles as $role){ // If no roles set |
310
|
|
|
echo "<tr><td><input type='checkbox' name='roles[]' value='". $role->getVar('id')."' /><a href='staff.php?op=editRole&id=".$role->getVar('id')."&uid=". $uid ."'>". $role->getVar('name') ."</a> - ". $role->getVar('description')."</td></tr>"; |
311
|
|
|
} |
312
|
|
|
} |
313
|
|
|
echo "<tr><td><input type='checkbox' name='checkallRoles' value='0' onclick='selectAll(this.form,\"roles[]\",this.checked);' /><b>"._AM_XHELP_TEXT_SELECT_ALL."</b></td></tr>"; |
314
|
|
|
echo "</table></td></tr>"; |
315
|
|
|
echo "<tr><td colspan='2' class='foot'> |
316
|
|
|
<input type='submit' name='submit' value='". _AM_XHELP_BUTTON_UPDATE ."' class='formButton' /> |
317
|
|
|
<input type='submit' name='addRole' value='". _AM_XHELP_BUTTON_CREATE_ROLE ."' class='formButton' /> |
318
|
|
|
<input type='button' name='cancel' value='"._AM_XHELP_BUTTON_CANCEL."' onclick='history.go(-1)' class='formButton' /> |
319
|
|
|
</td> |
320
|
|
|
</tr>"; |
321
|
|
|
echo "</table>"; |
322
|
|
|
include_once "admin_footer.php"; |
323
|
|
|
} else { |
324
|
|
|
$hRole =& xhelpGetHandler('role'); |
325
|
|
|
|
326
|
|
|
if(!empty($_POST['roles'])){ |
327
|
|
|
foreach($_POST['roles'] as $role){ |
328
|
|
|
$thisRole =& $hRole->get($role); |
329
|
|
|
$aRoleNames[] = $thisRole->getVar('name'); |
|
|
|
|
330
|
|
|
} |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
$_xhelpSession->set("xhelp_dept_$deptid", // Store roles for customized dept |
334
|
|
|
array('id' => $deptid, |
335
|
|
|
'roles' => ((!empty($_POST['roles'])) ? $_POST['roles']: -1), |
336
|
|
|
'roleNames' => ((!empty($aRoleNames)) ? $aRoleNames : -1) |
337
|
|
|
)); |
338
|
|
|
|
339
|
|
|
$xhelp_has_deptRoles = false; |
340
|
|
|
if($hasRoles = $_xhelpSession->get("xhelp_dept_$deptid")){ |
341
|
|
|
$xhelp_has_deptRoles = true; |
342
|
|
|
if($hasRoles['roles'] == -1){ // No perms for this dept |
343
|
|
|
//$_xhelpSession->del("xhelp_dept_$deptid"); // Delete custom roles for dept |
344
|
|
|
$xhelp_has_deptRoles = false; |
345
|
|
|
} |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
if($mainDepts = $_xhelpSession->get("xhelp_mainDepts")){ |
349
|
|
|
if($xhelp_has_deptRoles){ // If dept has roles |
350
|
|
|
if(!in_array($deptid, $mainDepts)){ // Does dept already exist in array? |
351
|
|
|
array_push($mainDepts, $deptid); // Add dept to array |
352
|
|
|
$_xhelpSession->set("xhelp_mainDepts", $mainDepts); // Set session with new dept value |
353
|
|
|
} |
354
|
|
|
} else { |
355
|
|
|
// Unset element in array with current dept value |
356
|
|
|
foreach($mainDepts as $dept){ |
357
|
|
|
if($dept == $deptid){ |
358
|
|
|
unset($dept); |
359
|
|
|
} |
360
|
|
|
} |
361
|
|
|
$_xhelpSession->set("xhelp_mainDepts",$mainDepts); |
362
|
|
|
} |
363
|
|
|
} else { // If mainDepts is not set |
364
|
|
|
if($xhelp_has_deptRoles){ // If dept has any roles |
365
|
|
|
$_xhelpSession->set("xhelp_mainDepts", array($deptid)); |
366
|
|
|
} |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
if(!$lastPage = $_xhelpSession->get("xhelp_return_op2")){ |
370
|
|
|
$lastPage = $_xhelpSession->get("xhelp_return_op"); |
371
|
|
|
} |
372
|
|
|
header("Location: ".XHELP_ADMIN_URL."/staff.php?op=$lastPage&uid=$uid"); |
373
|
|
|
} |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
function deleteRole($xhelp_id, $return_op) |
377
|
|
|
{ |
378
|
|
|
|
379
|
|
|
$xhelp_id = intval($xhelp_id); |
380
|
|
|
|
381
|
|
|
$hRole =& xhelpGetHandler('role'); |
382
|
|
|
$role =& $hRole->get($xhelp_id); |
383
|
|
|
|
384
|
|
|
if($hRole->delete($role, true)){ |
385
|
|
|
$message = _AM_XHELP_MESSAGE_ROLE_DELETE; |
|
|
|
|
386
|
|
|
header("Location: ".XHELP_ADMIN_URL."/staff.php?op=$return_op"); |
387
|
|
|
} else { |
388
|
|
|
$message = _AM_XHELP_MESSAGE_ROLE_DELETE_ERROR; |
389
|
|
|
redirect_header(XHELP_ADMIN_URL."/staff.php?op=$return_op", 3, $message); |
390
|
|
|
} |
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
function editRole() |
|
|
|
|
394
|
|
|
{ |
395
|
|
|
require_once(XHELP_CLASS_PATH.'/session.php'); |
396
|
|
|
$_xhelpSession = new Session(); |
397
|
|
|
|
398
|
|
|
$lastPage = $_xhelpSession->get("xhelp_return_op"); |
399
|
|
|
|
400
|
|
|
if(isset($_REQUEST['id'])){ |
401
|
|
|
$xhelp_id = intval($_REQUEST['id']); |
402
|
|
|
} |
403
|
|
|
|
404
|
|
View Code Duplication |
if(isset($_REQUEST['uid'])){ |
405
|
|
|
$uid = intval($_REQUEST['uid']); |
406
|
|
|
} else { |
407
|
|
|
$uid = 0; |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
$hRole =& xhelpGetHandler('role'); |
411
|
|
|
$role =& $hRole->get($xhelp_id); |
|
|
|
|
412
|
|
|
|
413
|
|
|
if(isset($_POST['deleteRole'])){ |
414
|
|
|
deleteRole($xhelp_id, "manageStaff"); |
415
|
|
|
exit(); |
|
|
|
|
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
if(!isset($_POST['edit'])){ |
419
|
|
|
$_xhelpSession->set("xhelp_return_op2", $lastPage); |
420
|
|
|
$_xhelpSession->set("xhelp_return_op", substr(strstr($_SERVER['REQUEST_URI'], 'op='), 3)); |
421
|
|
|
|
422
|
|
|
// Set array of security items |
423
|
|
|
$tasks = array(XHELP_SEC_TICKET_ADD => _AM_XHELP_SEC_TEXT_TICKET_ADD, |
424
|
|
|
XHELP_SEC_TICKET_EDIT => _AM_XHELP_SEC_TEXT_TICKET_EDIT, |
425
|
|
|
XHELP_SEC_TICKET_DELETE => _AM_XHELP_SEC_TEXT_TICKET_DELETE, |
426
|
|
|
XHELP_SEC_TICKET_OWNERSHIP => _AM_XHELP_SEC_TEXT_TICKET_OWNERSHIP, |
427
|
|
|
XHELP_SEC_TICKET_STATUS => _AM_XHELP_SEC_TEXT_TICKET_STATUS, |
428
|
|
|
XHELP_SEC_TICKET_PRIORITY => _AM_XHELP_SEC_TEXT_TICKET_PRIORITY, |
429
|
|
|
XHELP_SEC_TICKET_LOGUSER => _AM_XHELP_SEC_TEXT_TICKET_LOGUSER, |
430
|
|
|
XHELP_SEC_RESPONSE_ADD => _AM_XHELP_SEC_TEXT_RESPONSE_ADD, |
431
|
|
|
XHELP_SEC_RESPONSE_EDIT => _AM_XHELP_SEC_TEXT_RESPONSE_EDIT, |
432
|
|
|
XHELP_SEC_TICKET_MERGE => _AM_XHELP_SEC_TEXT_TICKET_MERGE, |
433
|
|
|
XHELP_SEC_FILE_DELETE => _AM_XHELP_SEC_TEXT_FILE_DELETE, |
434
|
|
|
XHELP_SEC_FAQ_ADD => _AM_XHELP_SEC_TEXT_FAQ_ADD, |
435
|
|
|
XHELP_SEC_TICKET_TAKE_OWNERSHIP => _AM_XHELP_SEC_TEXT_TICKET_TAKE_OWNERSHIP); |
436
|
|
|
xoops_cp_header(); |
437
|
|
|
//echo $oAdminButton->renderButtons('manStaff'); |
438
|
|
|
$indexAdmin = new ModuleAdmin(); |
439
|
|
|
echo $indexAdmin->addNavigation('staff.php?op=editRole'); |
440
|
|
|
|
441
|
|
|
echo '<script type="text/javascript" src="'.XOOPS_URL.'/modules/xhelp/include/functions.js"></script>'; |
442
|
|
|
echo "<form action='staff.php?op=editRole&id=".$xhelp_id."&uid=".$uid."' method='post'>"; |
443
|
|
|
echo "<table width='100%' cellspacing='1' class='outer'>"; |
444
|
|
|
echo "<tr><th colspan='2'>"._AM_XHELP_TEXT_EDIT_ROLE."</th></tr>"; |
445
|
|
|
echo "<tr><td class='head'>"._AM_XHELP_TEXT_NAME."</td> |
446
|
|
|
<td class='even'><input type='text' name='roleName' maxlength='35' value='".$role->getVar('name')."' class='formButton'></td> |
447
|
|
|
</tr>"; |
448
|
|
|
echo "<tr><td class='head'>"._AM_XHELP_TEXT_DESCRIPTION."</td> |
449
|
|
|
<td class='even'><textarea name='roleDescription' class='formButton'>".$role->getVar('description')."</textarea></td> |
450
|
|
|
</tr>"; |
451
|
|
|
echo "<tr><td class='head'>"._AM_XHELP_TEXT_PERMISSIONS."</td> |
452
|
|
|
<td class='even'> |
453
|
|
|
<table border='0'> |
454
|
|
|
<tr><td>"; |
455
|
|
|
foreach($tasks as $bit_value => $task){ |
456
|
|
|
if(($role->getVar('tasks') & pow(2, $bit_value)) > 0){ |
457
|
|
|
echo "<tr><td><input type='checkbox' name='tasks[]' value='". pow(2,$bit_value) ."' checked='checked' />".$task."</td></tr>"; |
458
|
|
|
} else { |
459
|
|
|
echo "<tr><td><input type='checkbox' name='tasks[]' value='". pow(2,$bit_value) ."' />".$task."</td></tr>"; |
460
|
|
|
} |
461
|
|
|
} |
462
|
|
|
echo "<tr><td><input type='checkbox' name='allTasks' value='0' onclick='selectAll(this.form,\"tasks[]\",this.checked);' /><b>"._AM_XHELP_TEXT_SELECT_ALL."</b></td></tr>"; |
463
|
|
|
echo "</table> |
464
|
|
|
</td> |
465
|
|
|
</tr>"; |
466
|
|
|
echo "<tr> |
467
|
|
|
<td colspan='2' class='foot'> |
468
|
|
|
<input type='submit' name='edit' value='". _AM_XHELP_BUTTON_UPDATE ."' class='formButton' /> |
469
|
|
|
<input type='button' name='cancel' value='"._AM_XHELP_BUTTON_CANCEL."' onclick='history.go(-1)' class='formButton' /> |
470
|
|
|
<input type='submit' name='deleteRole' value='"._AM_XHELP_BUTTON_DELETE."' class='formButton' /> |
471
|
|
|
|
472
|
|
|
</td> |
473
|
|
|
</tr>"; |
474
|
|
|
echo "</table></form>"; |
475
|
|
|
include_once "admin_footer.php"; |
476
|
|
View Code Duplication |
} else { |
477
|
|
|
$role->setVar('name', $_POST['roleName']); |
478
|
|
|
$role->setVar('description', $_POST['roleDescription']); |
479
|
|
|
if(isset($_POST['tasks'])){ |
480
|
|
|
$tasksValue = array_sum($_POST['tasks']); |
481
|
|
|
} else { |
482
|
|
|
$tasksValue = 0; |
483
|
|
|
} |
484
|
|
|
$role->setVar('tasks', $tasksValue); |
485
|
|
|
|
486
|
|
|
if(!$lastPage = $_xhelpSession->get("xhelp_return_op2")){ |
487
|
|
|
$lastPage = $_xhelpSession->get("xhelp_return_op"); |
488
|
|
|
} |
489
|
|
|
|
490
|
|
|
if($hRole->insert($role)){ |
491
|
|
|
xhelpResetStaffUpdatedTime(); |
492
|
|
|
|
493
|
|
|
$message = _AM_XHELP_MESSAGE_ROLE_UPDATE; |
|
|
|
|
494
|
|
|
header("Location: ".XHELP_ADMIN_URL."/staff.php?op=$lastPage&uid=$uid"); |
495
|
|
|
} else { |
496
|
|
|
$message = _AM_XHELP_MESSAGE_ROLE_UPDATE_ERROR; |
497
|
|
|
redirect_header(XHELP_ADMIN_URL."/staff.php?op=$lastPage&uid=$uid", 3, $message); |
498
|
|
|
} |
499
|
|
|
} |
500
|
|
|
} |
501
|
|
|
|
502
|
|
|
function editStaff() |
|
|
|
|
503
|
|
|
{ |
504
|
|
|
global $_POST, $_GET, $xoopsModule, $xoopsUser, $displayName; |
|
|
|
|
505
|
|
|
require_once(XHELP_CLASS_PATH.'/session.php'); |
506
|
|
|
$_xhelpSession = new Session(); |
507
|
|
|
|
508
|
|
|
if (isset($_REQUEST['uid'])) |
509
|
|
|
{ |
510
|
|
|
$uid = $_REQUEST['uid']; |
511
|
|
|
} |
512
|
|
|
/* |
513
|
|
|
if(isset($_REQUEST['user'])){ // Remove me |
514
|
|
|
$uid = $_REQUEST['user']; |
515
|
|
|
} |
516
|
|
|
*/ |
517
|
|
|
if(isset($_POST['clearRoles'])){ |
518
|
|
|
header("Location: ".XHELP_ADMIN_URL."/staff.php?op=clearRoles"); |
519
|
|
|
exit(); |
|
|
|
|
520
|
|
|
} |
521
|
|
|
|
522
|
|
|
$_xhelpSession->set("xhelp_return_op", "editStaff"); |
523
|
|
|
|
524
|
|
|
if(!isset($_POST['updateStaff'])){ |
525
|
|
|
//xoops_cp_header(); |
526
|
|
|
$member_handler =& xoops_gethandler('member'); // Get member handler |
527
|
|
|
$member =& $member_handler->getUser($uid); |
|
|
|
|
528
|
|
|
|
529
|
|
|
$hRoles =& xhelpGetHandler('role'); |
530
|
|
|
$crit = new Criteria('', ''); |
531
|
|
|
$crit->setOrder('ASC'); |
532
|
|
|
$crit->setSort('name'); |
533
|
|
|
$roles =& $hRoles->getObjects($crit, true); |
534
|
|
|
|
535
|
|
|
$hDepartments =& xhelpGetHandler('department'); // Get department handler |
536
|
|
|
$crit = new Criteria('',''); |
537
|
|
|
$crit->setSort('department'); |
538
|
|
|
$crit->setOrder('ASC'); |
539
|
|
|
$total = $hDepartments->getCount($crit); |
|
|
|
|
540
|
|
|
$departmentInfo =& $hDepartments->getObjects($crit); |
541
|
|
|
|
542
|
|
|
$hStaff =& xhelpGetHandler('staff'); // Get staff handler |
543
|
|
|
$staff =& $hStaff->getByUid($uid); |
544
|
|
|
$hMembership =& xhelpGetHandler('membership'); |
545
|
|
|
$staffDepts = $hMembership->membershipByStaff($uid); |
546
|
|
|
$staffroles = $staff->getAllRoleRights(); |
547
|
|
|
$global_roles = (isset($staffroles[0]['roles']) ? array_keys($staffroles[0]['roles']) : array()); //Get all Global Roles |
548
|
|
|
|
549
|
|
|
$xhelp_depts = array(); |
550
|
|
|
foreach($staffDepts as $myDept){ |
551
|
|
|
$deptid = $myDept->getVar('id'); |
552
|
|
|
if($deptid != 0){ |
553
|
|
|
$xhelp_depts[] = $deptid; |
554
|
|
|
} |
555
|
|
|
} |
556
|
|
|
$xhelp_depts = implode(',', $xhelp_depts); |
557
|
|
|
|
558
|
|
|
//$myRoles =& $hStaff->getRoles($staff->getVar('uid')); |
559
|
|
|
xoops_cp_header(); |
560
|
|
|
//echo $oAdminButton->renderButtons('manStaff'); |
561
|
|
|
$indexAdmin = new ModuleAdmin(); |
562
|
|
|
echo $indexAdmin->addNavigation('staff.php?op=editStaff'); |
563
|
|
|
|
564
|
|
|
echo '<script type="text/javascript" src="'.XOOPS_URL.'/modules/xhelp/include/functions.js"></script>'; |
565
|
|
|
echo "<form name='frmEditStaff' method='post' action='staff.php?op=editStaff&uid=".$uid."'>"; |
566
|
|
|
echo "<table width='100%' border='0' cellspacing='1' class='outer'> |
567
|
|
|
<tr><th colspan='2'><label>"._AM_XHELP_EDIT_STAFF ."</label></th></tr>"; |
568
|
|
|
echo "<tr><td class='head' width='20%'>". _AM_XHELP_TEXT_USER ."</td> |
569
|
|
|
<td class='even'>". xhelpGetUsername($member, $displayName); |
570
|
|
|
echo "</td></tr>"; |
571
|
|
|
echo "<tr><td class='head'>". _AM_XHELP_TEXT_ROLES ."</td> |
572
|
|
|
<td class='even'><table width='75%'>"; |
573
|
|
|
|
574
|
|
|
foreach($roles as $role){ |
575
|
|
|
$roleid = $role->getVar('id'); |
576
|
|
|
if (in_array($roleid, $global_roles)) { |
577
|
|
|
echo "<tr><td><input type='checkbox' name='roles[]' checked='checked' value='". $role->getVar('id')."' onclick=\"xhelpRoleCustOnClick('frmEditStaff', 'roles[]', 'xhelp_role', '&', 'xhelp_dept_cust');\" /><a href='staff.php?op=editRole&id=".$role->getVar('id')."&uid=". $uid ."'>". $role->getVar('name') ."</a> - ". $role->getVar('description')."</td></tr>"; |
578
|
|
|
} else { |
579
|
|
|
if($mainRoles = $_xhelpSession->get("xhelp_mainRoles")){ |
580
|
|
|
if(in_array($roleid, $mainRoles)){ |
581
|
|
|
echo "<tr><td><input type='checkbox' name='roles[]' checked='checked' value='". $role->getVar('id')."' onclick=\"xhelpRoleCustOnClick('frmEditStaff', 'roles[]', 'xhelp_role', '&', 'xhelp_dept_cust');\" /><a href='staff.php?op=editRole&id=".$role->getVar('id')."&uid=". $uid ."'>". $role->getVar('name') ."</a> - ". $role->getVar('description')."</td></tr>"; |
582
|
|
|
} else { |
583
|
|
|
echo "<tr><td><input type='checkbox' name='roles[]' value='". $role->getVar('id')."' onclick=\"xhelpRoleCustOnClick('frmEditStaff', 'roles[]', 'xhelp_role', '&', 'xhelp_dept_cust');\" /><a href='staff.php?op=editRole&id=".$role->getVar('id')."&uid=". $uid ."'>". $role->getVar('name') ."</a> - ". $role->getVar('description')."</td></tr>"; |
584
|
|
|
} |
585
|
|
|
} else { |
586
|
|
|
echo "<tr><td><input type='checkbox' name='roles[]' value='". $role->getVar('id')."' onclick=\"xhelpRoleCustOnClick('frmEditStaff', 'roles[]', 'xhelp_role', '&', 'xhelp_dept_cust');\" /><a href='staff.php?op=editRole&id=".$role->getVar('id')."&uid=". $uid ."'>". $role->getVar('name') ."</a> - ". $role->getVar('description')."</td></tr>"; |
587
|
|
|
} |
588
|
|
|
} |
589
|
|
|
} |
590
|
|
|
echo "<tr><td><input type='checkbox' name='checkallRoles' value='0' onclick='selectAll(this.form,\"roles[]\",this.checked); xhelpRoleCustOnClick(\"frmEditStaff\", \"roles[]\", \"xhelp_role\", \"&\", \"xhelp_dept_cust\");' /><b>"._AM_XHELP_TEXT_SELECT_ALL."</b></td></tr>"; |
591
|
|
|
echo "</table></td></tr>"; |
592
|
|
|
echo "<tr><td class='head'>". _AM_XHELP_TEXT_DEPARTMENTS ."</td> |
593
|
|
|
<td class='even'><table width='75%'>"; |
594
|
|
|
|
595
|
|
|
// This block is used to append custom role names to each department |
596
|
|
|
foreach($departmentInfo as $dept) { |
597
|
|
|
$deptid = $dept->getVar('id'); |
598
|
|
|
$deptname = $dept->getVar('department'); |
599
|
|
|
$inDept = false; //Is the user a member of the dept |
|
|
|
|
600
|
|
|
|
601
|
|
|
$deptroleids = ''; |
602
|
|
|
$deptrolenames = ''; |
603
|
|
|
|
604
|
|
|
if ($sess_roles = $_xhelpSession->get("xhelp_dept_$deptid")) { //Customized roles stored in session? |
605
|
|
|
if ($sess_roles['roles'] != -1) { //Is the user assigned to any roles in the dept? |
606
|
|
|
$inDept = true; |
607
|
|
|
foreach($sess_roles['roles'] as $roleid){ // Check if customized roles match global roles |
608
|
|
|
if(in_array($roleid, $global_roles)){ // If found role in global roles |
609
|
|
|
$deptroleids[] = $roleid; // Add role to array of checked roles |
610
|
|
|
} |
611
|
|
|
} |
612
|
|
|
$deptroleids = implode(',', $sess_roles['roles']); // Put all roles into 1 string separated by a ',' |
613
|
|
|
|
614
|
|
|
//An empty string means dept roles match global roles |
615
|
|
|
if (strlen($deptroleids) > 0) { //Customized Roles |
616
|
|
|
$deptrolenames = implode(', ', $sess_roles['roleNames']); |
617
|
|
|
} |
618
|
|
|
} else { //Not a member of the dept |
619
|
|
|
$inDept = false; |
620
|
|
|
} |
621
|
|
|
} elseif (isset($staffroles[$deptid])) { //User has assigned dept roles |
622
|
|
|
$inDept = true; |
623
|
|
|
|
624
|
|
|
if ($staffroles[$deptid]['roles'] == $staffroles[0]['roles']) { // If global roles same as dept roles |
625
|
|
|
$deptrolenames = ''; |
626
|
|
|
$deptroleids = array(); |
627
|
|
View Code Duplication |
foreach($staffroles[$deptid]['roles'] as $roleid=>$tasks){ |
628
|
|
|
if(isset($roles[$roleid])){ |
629
|
|
|
$deptroleids[] = $roleid; |
630
|
|
|
} |
631
|
|
|
} |
632
|
|
|
$deptroleids = implode(',', $deptroleids); |
633
|
|
|
} else { |
634
|
|
|
$deptrolenames = array(); |
635
|
|
|
$deptroleids = array(); |
636
|
|
|
foreach($staffroles[$deptid]['roles'] as $roleid=>$tasks) { |
637
|
|
|
if (isset($roles[$roleid])) { |
638
|
|
|
$deptroleids[] = $roleid; |
639
|
|
|
$deptrolenames[] = $roles[$roleid]->getVar('name'); |
640
|
|
|
} |
641
|
|
|
} |
642
|
|
|
$deptrolenames = implode(', ', $deptrolenames); |
643
|
|
|
$deptroleids = implode(',', $deptroleids); |
644
|
|
|
} |
645
|
|
|
} else { //Not a member of the dept |
646
|
|
|
$deptroleids = array(); |
647
|
|
View Code Duplication |
foreach($staffroles[0]['roles'] as $roleid=>$tasks){ |
648
|
|
|
if(isset($roles[$roleid])){ |
649
|
|
|
$deptroleids[] = $roleid; |
650
|
|
|
} |
651
|
|
|
} |
652
|
|
|
$deptroleids = implode(',', $deptroleids); |
653
|
|
|
$deptrolenames = ''; |
654
|
|
|
|
655
|
|
|
$inDept = false; |
656
|
|
|
} |
657
|
|
|
|
658
|
|
|
//Should element be checked? |
659
|
|
|
$checked = ($inDept ? "checked='checked'" : ''); |
660
|
|
|
|
661
|
|
|
printf("<tr><td><input type='checkbox' name='departments[]' value='%u' %s onclick=\"xhelpRoleCustOnClick('frmEditStaff', 'departments[]', 'xhelp_depts', '&', 'xhelp_dept_cust');\" />%s [<a href='staff.php?op=customDept&deptid=%u&uid=%u&xhelp_role=%s&xhelp_depts=%s' class='xhelp_dept_cust'>Customize</a>] <i>%s</i><input type='hidden' name='custrole[%u]' value='%s' /></td></tr>", $deptid, $checked, $deptname, $deptid, $uid, $deptroleids, $xhelp_depts, $deptrolenames, $deptid, $deptroleids); |
662
|
|
|
} |
663
|
|
|
echo "<tr><td> |
664
|
|
|
<input type='checkbox' name='checkAll' value='0' onclick='selectAll(this.form,\"departments[]\", this.checked);xhelpRoleCustOnClick(\"frmEditStaff\", \"departments[]\", \"xhelp_depts\", \"&\", \"xhelp_dept_cust\");' /><b>"._AM_XHELP_TEXT_SELECT_ALL."</b></td></tr>"; |
665
|
|
|
echo "<tr><td>"; |
666
|
|
|
echo "</td></tr>"; |
667
|
|
|
echo "</table>"; |
668
|
|
|
echo "</td></tr>"; |
669
|
|
|
echo "<tr><td colspan='2' class='foot'> |
670
|
|
|
<input type='hidden' name='uid' value='".$uid."' /> |
671
|
|
|
<input type='submit' name='updateStaff' value='". _AM_XHELP_BUTTON_UPDATESTAFF ."' /> |
672
|
|
|
<input type='button' name='cancel' value='"._AM_XHELP_BUTTON_CANCEL."' onclick='history.go(-1)' class='formButton' /> |
673
|
|
|
</td></tr>"; |
674
|
|
|
echo "</table></form>"; |
675
|
|
|
|
676
|
|
|
include_once "admin_footer.php"; |
677
|
|
|
} else { |
678
|
|
|
$uid = intval($_POST['uid']); |
679
|
|
|
$depts = $_POST['departments']; |
680
|
|
|
$roles = $_POST['roles']; |
681
|
|
|
$custroles = $_POST['custrole']; |
682
|
|
|
|
683
|
|
|
$hStaff =& xhelpGetHandler('staff'); |
684
|
|
|
$hMembership =& xhelpGetHandler('membership'); |
685
|
|
|
|
686
|
|
|
//Remove existing dept membership |
687
|
|
|
if(!$hMembership->clearStaffMembership($uid)){ |
688
|
|
|
$message = _XHELP_MESSAGE_EDITSTAFF_NOCLEAR_ERROR; |
689
|
|
|
redirect_header(XHELP_ADMIN_URL.'/staff.php?op=manageStaff', 3, $message); |
690
|
|
|
} |
691
|
|
|
|
692
|
|
|
//Add staff member to selected depts |
693
|
|
|
if($hMembership->addDeptToStaff($depts, $uid)){ |
694
|
|
|
$message = _XHELP_MESSAGE_EDITSTAFF; |
695
|
|
|
} else { |
696
|
|
|
$message = _XHELP_MESSAGE_EDITSTAFF_ERROR; |
697
|
|
|
} |
698
|
|
|
|
699
|
|
|
//Clear Existing Staff Role Permissions |
700
|
|
|
$removedRoles = $hStaff->removeStaffRoles($uid); |
|
|
|
|
701
|
|
|
|
702
|
|
|
//Add Global Role Permissions |
703
|
|
|
foreach($roles as $role){ |
704
|
|
|
$hStaff->addStaffRole($uid, $role, 0); |
705
|
|
|
} |
706
|
|
|
|
707
|
|
|
//Add Department Specific Roles |
708
|
|
|
foreach($depts as $dept){ |
709
|
|
|
if (strlen($custroles[$dept]) > 0) { |
710
|
|
|
$dept_roles = explode(',', $custroles[$dept]); |
711
|
|
|
} else { |
712
|
|
|
$dept_roles = $roles; |
713
|
|
|
} |
714
|
|
|
|
715
|
|
|
foreach ($dept_roles as $role) { |
716
|
|
|
$hStaff->addStaffRole($uid, $role, $dept); |
717
|
|
|
} |
718
|
|
|
} |
719
|
|
|
|
720
|
|
|
$staff =& $hStaff->getByUid($uid); |
721
|
|
|
$staff->setVar('permTimestamp', time()); |
722
|
|
|
if(!$hStaff->insert($staff)){ |
723
|
|
|
$message = _XHELP_MESSAGE_EDITSTAFF; |
724
|
|
|
} |
725
|
|
|
|
726
|
|
|
redirect_header(XHELP_ADMIN_URL.'/staff.php?op=clearRoles', 3, $message); |
727
|
|
|
}//end if |
728
|
|
|
}//end function |
729
|
|
|
|
730
|
|
|
function manageStaff() |
|
|
|
|
731
|
|
|
{ |
732
|
|
|
global $xoopsModule, $xoopsUser, $displayName, $aLimitByS, $aLimitByD; |
|
|
|
|
733
|
|
|
require_once(XHELP_CLASS_PATH.'/session.php'); |
734
|
|
|
$_xhelpSession = new Session(); |
735
|
|
|
$_xhelpSession->del("xhelp_return_page"); |
736
|
|
|
|
737
|
|
|
$start = $limit = 0; |
738
|
|
|
$dstart = $dlimit = 0; |
739
|
|
|
$staff_search = false; |
740
|
|
|
$dept_search = false; |
741
|
|
|
|
742
|
|
|
if(isset($_POST['addRole'])){ |
743
|
|
|
header("Location: ".XHELP_ADMIN_URL."/staff.php?op=addRole"); |
744
|
|
|
exit(); |
|
|
|
|
745
|
|
|
} |
746
|
|
|
if(isset($_POST['clearRoles'])){ |
747
|
|
|
header("Location: ".XHELP_ADMIN_URL."/staff.php?op=clearRoles"); |
748
|
|
|
exit(); |
|
|
|
|
749
|
|
|
} |
750
|
|
|
|
751
|
|
|
if (isset($_REQUEST['limit'])) { |
752
|
|
|
$limit = intval($_REQUEST['limit']); |
753
|
|
|
} |
754
|
|
|
|
755
|
|
|
if (isset($_REQUEST['start'])) { |
756
|
|
|
$start = intval($_REQUEST['start']); |
757
|
|
|
} |
758
|
|
|
if(isset($_REQUEST['staff_search'])) { |
759
|
|
|
$staff_search = $_REQUEST['staff_search']; |
760
|
|
|
} |
761
|
|
|
|
762
|
|
|
if(isset($_REQUEST['dept_search'])) { |
763
|
|
|
$dept_search = $_REQUEST['dept_search']; |
764
|
|
|
} |
765
|
|
|
|
766
|
|
|
if (!$limit) { |
767
|
|
|
$limit = 20; |
768
|
|
|
} |
769
|
|
|
|
770
|
|
|
if (isset($_REQUEST['dlimit'])) { |
771
|
|
|
$dlimit = intval($_REQUEST['dlimit']); |
772
|
|
|
} |
773
|
|
|
|
774
|
|
|
if (isset($_REQUEST['dstart'])) { |
775
|
|
|
$dstart = intval($_REQUEST['dstart']); |
776
|
|
|
} |
777
|
|
|
|
778
|
|
|
if (!$dlimit) { |
779
|
|
|
$dlimit = 10; |
780
|
|
|
} |
781
|
|
|
|
782
|
|
|
$_xhelpSession->set("xhelp_return_op", "manageStaff"); |
783
|
|
|
|
784
|
|
|
if(!isset($_POST['addStaff'])){ |
785
|
|
|
|
786
|
|
|
$member_handler =& xoops_gethandler('member'); // Get member handler |
787
|
|
|
$hStaff =& xhelpGetHandler('staff'); // Get staff handler |
788
|
|
|
$hDepartments =& xhelpGetHandler('department'); // Get department handler |
789
|
|
|
$hRoles =& xhelpGetHandler('role'); |
790
|
|
|
|
791
|
|
|
//Get List of depts in system |
792
|
|
|
$crit = new Criteria('',''); |
793
|
|
|
$crit->setSort('department'); |
794
|
|
|
$crit->setOrder('ASC'); |
795
|
|
|
|
796
|
|
|
$dept_count = $hDepartments->getCount($crit); |
797
|
|
|
$dept_obj =& $hDepartments->getObjects($crit); |
798
|
|
|
xoops_cp_header(); |
799
|
|
|
//echo $oAdminButton->renderButtons('manStaff'); |
800
|
|
|
$indexAdmin = new ModuleAdmin(); |
801
|
|
|
echo $indexAdmin->addNavigation('staff.php?op=manageStaff'); |
802
|
|
|
|
803
|
|
|
if(isset($_GET['uid'])){ |
804
|
|
|
$userid = intval($_GET['uid']); |
805
|
|
|
$uname = $xoopsUser->getUnameFromId($userid); |
806
|
|
|
} else { |
807
|
|
|
$userid = 0; |
|
|
|
|
808
|
|
|
$uname = ''; |
809
|
|
|
} |
810
|
|
|
|
811
|
|
|
if ($dept_count > 0) { |
812
|
|
|
$userid = (isset($_GET['uid']) ? intval($_GET['uid']) : 0); |
813
|
|
|
|
814
|
|
|
//Get List of staff members |
815
|
|
|
$crit = new Criteria('', ''); |
816
|
|
|
$crit->setStart($start); |
817
|
|
|
$crit->setLimit($limit); |
818
|
|
|
|
819
|
|
|
$staff_obj =& $hStaff->getObjects($crit); |
820
|
|
|
$staff_count = $hStaff->getCount($crit); |
821
|
|
|
$user_count = $member_handler->getUserCount(); |
|
|
|
|
822
|
|
|
|
823
|
|
|
$nav = new xhelpPageNav($staff_count, $limit, $start, 'start', "op=manageStaff&limit=$limit"); |
824
|
|
|
|
825
|
|
|
//Get List of Staff Roles |
826
|
|
|
$crit = new Criteria('', ''); |
827
|
|
|
$crit->setOrder('ASC'); |
828
|
|
|
$crit->setSort('name'); |
829
|
|
|
$roles =& $hRoles->getObjects($crit); |
830
|
|
|
|
831
|
|
|
echo '<script type="text/javascript" src="'.XOOPS_URL.'/modules/xhelp/include/functions.js"></script>'; |
832
|
|
|
echo "<form method='post' id='manageStaff' name='manageStaff' action='staff.php?op=manageStaff'>"; |
833
|
|
|
echo "<table width='100%' cellspacing='1' class='outer'> |
834
|
|
|
<tr><th colspan='2'>"._AM_XHELP_ADD_STAFF."</th></tr>"; |
835
|
|
|
|
836
|
|
|
echo "<tr><td class='head' width='20%'>". _AM_XHELP_TEXT_USER ."</td> |
837
|
|
|
<td class='even'> |
838
|
|
|
<input type='text' id='fullname' name='fullname' class='formButton' value='".$uname."' disabled='disabled' style='background-color:#E1E1E1;' onchange=\"window.location='staff.php?op=manageStaff&uid='+user_id.value;\" /> |
839
|
|
|
<input type='hidden' id='user_id' name='user_id' class='formButton' value='".$userid."' />"; |
840
|
|
|
echo " <a href=\"javascript:openWithSelfMain('".XHELP_BASE_URL."/lookup.php?admin=1', 'lookup',400, 300);\" title='"._AM_XHELP_TEXT_FIND_USERS."'>"._AM_XHELP_TEXT_FIND_USERS."</a> |
841
|
|
|
</td> |
842
|
|
|
</tr>"; |
843
|
|
|
|
844
|
|
|
echo "</td></tr>"; |
845
|
|
|
echo "<tr><td class='head' width='20%'>". _AM_XHELP_TEXT_ROLES ."</td> |
846
|
|
|
<td class='even'><table width='75%'>"; |
847
|
|
|
if($mainRoles = $_xhelpSession->get("xhelp_mainRoles")){ |
848
|
|
View Code Duplication |
foreach($roles as $role){ |
849
|
|
|
if(!in_array($role->getVar('id'), $mainRoles)){ |
850
|
|
|
echo "<tr><td><input type='checkbox' name='roles[]' value='". $role->getVar('id')."' onclick=\"xhelpRoleCustOnClick('manageStaff', 'roles[]', 'xhelp_role', '&', 'xhelp_dept_cust');\" /> |
851
|
|
|
<a href='staff.php?op=editRole&id=".$role->getVar('id')."&uid=". $userid ."'>". $role->getVar('name') ."</a> - ". $role->getVar('description')."</td></tr>"; |
852
|
|
|
} else { |
853
|
|
|
echo "<tr><td><input type='checkbox' name='roles[]' value='". $role->getVar('id')."' checked='checked' onclick=\"xhelpRoleCustOnClick('manageStaff', 'roles[]', 'xhelp_role', '&', 'xhelp_dept_cust');\" /> |
854
|
|
|
<a href='staff.php?op=editRole&id=".$role->getVar('id')."&uid=". $userid ."'>". $role->getVar('name') ."</a> - ". $role->getVar('description')."</td></tr>"; |
855
|
|
|
} |
856
|
|
|
} |
857
|
|
|
} else { |
858
|
|
|
foreach($roles as $role){ |
859
|
|
|
echo "<tr><td><input type='checkbox' name='roles[]' value='". $role->getVar('id')."' onclick=\"xhelpRoleCustOnClick('manageStaff', 'roles[]', 'xhelp_role', '&', 'xhelp_dept_cust');\" /> |
860
|
|
|
<a href='staff.php?op=editRole&id=".$role->getVar('id')."&uid=". $userid ."'>". $role->getVar('name') ."</a> - ". $role->getVar('description')."</td></tr>"; |
861
|
|
|
} |
862
|
|
|
} |
863
|
|
|
echo "<tr><td><input type='checkbox' name='checkallRoles' value='0' onclick='selectAll(this.form,\"roles[]\",this.checked); xhelpRoleCustOnClick(\"manageStaff\", \"roles[]\", \"xhelp_role\", \"&\", \"xhelp_dept_cust\");' /><b>"._AM_XHELP_TEXT_SELECT_ALL."</b></td></tr>"; |
864
|
|
|
echo "</table></td></tr>"; |
865
|
|
|
echo "<tr><td class='head' width='20%'>". _AM_XHELP_TEXT_DEPARTMENTS ."</td> |
866
|
|
|
<td class='even' width='50%'><table width='75%'>"; |
867
|
|
|
if($mainDepts =& $_xhelpSession->get("xhelp_mainDepts")){ |
868
|
|
|
foreach($dept_obj as $dept){ |
869
|
|
|
$deptid = $dept->getVar('id'); |
870
|
|
|
$aDept = $_xhelpSession->get("xhelp_dept_$deptid"); |
871
|
|
|
$aDeptRoles = $aDept['roleNames']; |
872
|
|
|
if(!empty($aDeptRoles) && is_array($aDeptRoles)){ |
873
|
|
|
$deptRoles = implode(", ", $aDeptRoles); |
874
|
|
|
} else { |
875
|
|
|
$deptRoles = ''; |
876
|
|
|
} |
877
|
|
|
if(!in_array($dept->getVar('id'), $mainDepts)){ |
878
|
|
|
echo "<tr><td> |
879
|
|
|
<input type='checkbox' name='departments[]' value='".$dept->getVar('id')."' onclick=\"xhelpRoleCustOnClick('manageStaff', 'departments[]', 'xhelp_depts', '&', 'xhelp_dept_cust');\" /> |
880
|
|
|
".$dept->getVar('department')." [<a href='staff.php?op=customDept&deptid=".$dept->getVar('id')."&uid=".$userid."' class='xhelp_dept_cust'>". _AM_XHELP_TEXT_CUSTOMIZE ."</a>] <i>". $deptRoles ."</i> |
881
|
|
|
</td></tr>"; |
882
|
|
|
} else { |
883
|
|
|
echo "<tr><td> |
884
|
|
|
<input type='checkbox' name='departments[]' checked='checked' value='".$dept->getVar('id')."' onclick=\"xhelpRoleCustOnClick('manageStaff', 'departments[]', 'xhelp_depts', '&', 'xhelp_dept_cust');\" /> |
885
|
|
|
".$dept->getVar('department')." [<a href='staff.php?op=customDept&deptid=".$dept->getVar('id')."&uid=".$userid."' class='xhelp_dept_cust'>". _AM_XHELP_TEXT_CUSTOMIZE ."</a>] <i>". $deptRoles ."</i> |
886
|
|
|
</td></tr>"; |
887
|
|
|
} |
888
|
|
|
} |
889
|
|
|
} else { |
890
|
|
|
foreach($dept_obj as $dept){ |
891
|
|
|
$deptid = $dept->getVar('id'); |
892
|
|
|
$aDept = $_xhelpSession->get("xhelp_dept_$deptid"); |
893
|
|
|
$aDeptRoles = $aDept['roleNames']; |
894
|
|
|
if(!empty($aDeptRoles)){ |
895
|
|
|
$deptRoles = implode(", ", $aDeptRoles); |
896
|
|
|
} else { |
897
|
|
|
$deptRoles = ''; |
898
|
|
|
} |
899
|
|
|
echo "<tr><td> |
900
|
|
|
<input type='checkbox' name='departments[]' value='".$dept->getVar('id')."' onclick=\"xhelpRoleCustOnClick('manageStaff', 'departments[]', 'xhelp_depts', '&', 'xhelp_dept_cust');\" /> |
901
|
|
|
".$dept->getVar('department')." [<a href='staff.php?op=customDept&deptid=".$dept->getVar('id')."&uid=".$userid."' class='xhelp_dept_cust'>". _AM_XHELP_TEXT_CUSTOMIZE ."</a>] <i>". $deptRoles ."</i> |
902
|
|
|
</td></tr>"; |
903
|
|
|
} |
904
|
|
|
} |
905
|
|
|
echo "<tr><td><input type='checkbox' name='checkallDepts' value='0' onclick='selectAll(this.form,\"departments[]\",this.checked);xhelpRoleCustOnClick(\"manageStaff\", \"departments[]\", \"xhelp_depts\", \"&\", \"xhelp_dept_cust\");' /><b>"._AM_XHELP_TEXT_SELECT_ALL."</b></td></tr>"; |
906
|
|
|
echo "</table></td></tr>"; |
907
|
|
|
echo "<tr><td colspan='2' class='foot'> |
908
|
|
|
<input type='submit' name='addStaff' value='". _AM_XHELP_BUTTON_ADDSTAFF ."' /> |
909
|
|
|
<input type='submit' name='addRole' value='". _AM_XHELP_BUTTON_CREATE_ROLE ."' class='formButton' /> |
910
|
|
|
<input type='submit' name='clearRoles' value='"._AM_XHELP_BUTTON_CLEAR_PERMS."' class='formButton' /> |
911
|
|
|
</td></tr>"; |
912
|
|
|
echo "</table></form>"; |
913
|
|
|
|
914
|
|
|
echo "<form method='post' id='cleanStaff' name='cleanStaff' action='staff.php?op=clearOrphanedStaff'>"; |
915
|
|
|
echo "<table width='100%' cellspacing='1' class='outer'> |
916
|
|
|
<tr><th colspan='2'>"._AM_XHELP_TEXT_MAINTENANCE."</th></tr>"; |
917
|
|
|
echo "<tr><td class='head' width='40%'>"._AM_XHELP_TEXT_ORPHANED."</td> |
918
|
|
|
<td class='even'><input type='submit' name='cleanStaff' value='"._AM_XHELP_BUTTON_SUBMIT."' /></td> |
919
|
|
|
</tr>"; |
920
|
|
|
echo "</table></form>"; |
921
|
|
|
|
922
|
|
|
if($staff_count > 0){ |
923
|
|
|
//Get User Information for each staff member |
924
|
|
|
$staff_uids = array(); |
925
|
|
|
foreach($staff_obj as $obj) { |
926
|
|
|
$staff_uids[] = $obj->getVar('uid'); |
927
|
|
|
} |
928
|
|
|
if($staff_search == false){ |
929
|
|
|
$crit = new Criteria('uid', '('.implode(',', $staff_uids).')', 'IN'); |
930
|
|
|
} else { |
931
|
|
|
$crit = new CriteriaCompo(new Criteria('uname',"%$staff_search%",'LIKE'), 'OR'); |
932
|
|
|
$crit->add(new Criteria('name',"%$staff_search%",'LIKE'), 'OR'); |
933
|
|
|
$crit->add(new Criteria('email',"%$staff_search%",'LIKE'), 'OR'); |
934
|
|
|
} |
935
|
|
|
$staff_users = $member_handler->getUsers($crit); |
936
|
|
|
|
937
|
|
View Code Duplication |
if($dept_search == false){ |
938
|
|
|
$crit = new Criteria('', ''); |
939
|
|
|
} else { |
940
|
|
|
$crit = new Criteria('department', "%$dept_search%", 'LIKE'); |
941
|
|
|
} |
942
|
|
|
$crit->setStart($dstart); |
943
|
|
|
$crit->setLimit($dlimit); |
944
|
|
|
|
945
|
|
|
$allDepts = $hDepartments->getObjects($crit, true); |
946
|
|
|
$dnav = new xhelpPageNav($hDepartments->getCount($crit), $dlimit, $dstart, 'dstart', "op=manageStaff&start=$start&limit=$limit&dlimit=$dlimit", "tblManageStaff"); |
947
|
|
|
|
948
|
|
|
echo "<form action='". XHELP_ADMIN_URL."/staff.php?op=manageStaff' style='margin:0; padding:0;' method='post'>"; |
949
|
|
|
echo "<table width='100%' cellspacing='1' class='outer'>"; |
950
|
|
|
echo "<tr><td align='right'>"._AM_XHELP_TEXT_STAFF .": "._AM_XHELP_BUTTON_SEARCH." <input type='text' name='staff_search' value='$staff_search' /> |
951
|
|
|
"._AM_XHELP_TEXT_NUMBER_PER_PAGE."<select name='limit'>"; |
952
|
|
|
foreach($aLimitByS as $value=>$text){ |
953
|
|
|
($limit == $value) ? $selected = "selected='selected'" : $selected = ''; |
954
|
|
|
echo "<option value='$value' $selected>$text</option>"; |
955
|
|
|
} |
956
|
|
|
echo "</select> |
957
|
|
|
|
958
|
|
|
"._AM_XHELP_TEXT_DEPARTMENTS.": "._AM_XHELP_BUTTON_SEARCH." |
959
|
|
|
<input type='text' name='dept_search' value='$dept_search' /> |
960
|
|
|
"._AM_XHELP_TEXT_NUMBER_PER_PAGE." |
961
|
|
|
<select name='dlimit'>"; |
962
|
|
|
foreach($aLimitByD as $value=>$text){ |
963
|
|
|
($dlimit == $value) ? $selected = "selected='selected'" : $selected = ''; |
964
|
|
|
echo "<option value='$value' $selected>$text</option>"; |
965
|
|
|
} |
966
|
|
|
echo "</select> |
967
|
|
|
|
968
|
|
|
<input type='submit' name='staff_select' id='staff_select' value='"._AM_XHELP_BUTTON_SUBMIT."' /> |
969
|
|
|
</td> |
970
|
|
|
</tr>"; |
971
|
|
|
echo "</table></form>"; |
972
|
|
|
|
973
|
|
|
echo "<table width='100%' cellspacing='1' class='outer' id='tblManageStaff'> |
974
|
|
|
<tr><th colspan='".(3+count($allDepts))."'><label>". _AM_XHELP_MANAGE_STAFF ."</label></th></tr>"; |
975
|
|
|
echo "<tr class='head'><td rowspan='2'>"._AM_XHELP_TEXT_ID."</td><td rowspan='2'>"._AM_XHELP_TEXT_USER."</td><td colspan='".count($allDepts)."'>"._AM_XHELP_TEXT_DEPARTMENTS." ".$dnav->renderNav()."</td><td rowspan='2'>"._AM_XHELP_TEXT_ACTIONS."</td></tr>"; |
976
|
|
|
echo "<tr class='head'>"; |
977
|
|
|
foreach ($allDepts as $thisdept) echo "<td>".$thisdept->getVar('department')."</td>"; |
978
|
|
|
echo "</tr>"; |
979
|
|
|
$hMembership =& xhelpGetHandler('membership'); |
980
|
|
|
$hStaffRole =& xhelpGetHandler('staffRole'); |
981
|
|
|
foreach($staff_users as $staff){ |
982
|
|
|
$departments = $hMembership->membershipByStaff($staff->getVar('uid'), true); |
983
|
|
|
echo "<tr class='even'><td>".$staff->getVar('uid')."</td><td>".$staff->getVar('uname')."</td>"; |
984
|
|
|
foreach ($allDepts as $thisdept) { |
985
|
|
|
echo "<td><img src='".XOOPS_URL."/modules/xhelp/images/"; |
986
|
|
|
echo (array_key_exists($thisdept->getVar('id'), $departments)) ? "on" : "off"; |
987
|
|
|
echo ".png' /></td>"; |
988
|
|
|
} |
989
|
|
|
echo "<td><a href='staff.php?op=editStaff&uid=".$staff->getVar('uid')."'><img src='".XOOPS_URL."/modules/xhelp/images/button_edit.png' title='"._AM_XHELP_TEXT_EDIT."' name='editStaff' /></a> |
990
|
|
|
<a href='delete.php?deleteStaff=1&uid=".$staff->getVar('uid')."'><img src='".XOOPS_URL."/modules/xhelp/images/button_delete.png' title='"._AM_XHELP_TEXT_DELETE."' name='deleteStaff' /></a> |
991
|
|
|
</td></tr>"; |
992
|
|
|
} |
993
|
|
|
echo "</table><br />"; |
994
|
|
|
echo "<div id='staff_nav'>".$nav->renderNav()."</div>"; |
995
|
|
|
} |
996
|
|
|
} else { |
997
|
|
|
echo "<div id='readOnly' class='errorMsg'>"; |
998
|
|
|
echo _AM_XHELP_TEXT_MAKE_DEPTS; |
999
|
|
|
echo "</div>"; |
1000
|
|
|
echo "<br /><a href='department.php?op=manageDepartments'>". _AM_XHELP_LINK_ADD_DEPT ."</a>"; |
1001
|
|
|
} |
1002
|
|
|
|
1003
|
|
|
include_once "admin_footer.php"; |
1004
|
|
|
} else { |
1005
|
|
|
$uid = $_POST['user_id']; |
1006
|
|
|
$depts = $_POST['departments']; |
1007
|
|
|
$roles = $_POST['roles']; |
1008
|
|
|
//$selectAll = $_POST['selectall']; |
1009
|
|
|
|
1010
|
|
|
$hStaff =& xhelpGetHandler('staff'); |
1011
|
|
|
|
1012
|
|
|
if(!isset($uid) || $uid == ''){ |
1013
|
|
|
redirect_header(XHELP_ADMIN_URL.'/staff.php?op=manageStaff', 3, _AM_XHELP_STAFF_ERROR_USERS); |
1014
|
|
|
} |
1015
|
|
|
if (!isset($depts)) { |
1016
|
|
|
redirect_header(XHELP_ADMIN_URL.'/staff.php?op=manageStaff', 3, _AM_XHELP_STAFF_ERROR_DEPTARTMENTS); |
1017
|
|
|
} |
1018
|
|
|
if (!isset($roles)) { |
1019
|
|
|
redirect_header(XHELP_ADMIN_URL.'/staff.php?op=manageStaff', 3, _AM_XHELP_STAFF_ERROR_ROLES); |
1020
|
|
|
} |
1021
|
|
|
if($hStaff->isStaff($uid)){ |
1022
|
|
|
redirect_header(XHELP_ADMIN_URL.'/staff.php?op=manageStaff', 3, _AM_XHELP_STAFF_EXISTS); |
1023
|
|
|
} |
1024
|
|
|
|
1025
|
|
|
$member_handler =& xoops_gethandler('member'); // Get member handler |
1026
|
|
|
$newUser =& $member_handler->getUser($uid); |
1027
|
|
|
|
1028
|
|
|
$email = $newUser->getVar('email'); |
1029
|
|
|
if($hStaff->addStaff($uid, $email)){ // $selectAll |
1030
|
|
|
$message = _XHELP_MESSAGE_ADDSTAFF; |
|
|
|
|
1031
|
|
|
$hMembership =& xhelpGetHandler('membership'); |
1032
|
|
|
|
1033
|
|
|
//Set Department Membership |
1034
|
|
|
if($hMembership->addDeptToStaff($depts, $uid)){ |
1035
|
|
|
$message = _XHELP_MESSAGE_ADDSTAFF; |
|
|
|
|
1036
|
|
|
} else { |
1037
|
|
|
$message = _XHELP_MESSAGE_ADDSTAFF_ERROR; |
|
|
|
|
1038
|
|
|
} |
1039
|
|
|
|
1040
|
|
|
//Set Global Roles |
1041
|
|
|
foreach($roles as $role){ |
1042
|
|
|
$hStaff->addStaffRole($uid, $role, 0); |
1043
|
|
|
} |
1044
|
|
|
|
1045
|
|
|
//Set Department Roles |
1046
|
|
|
foreach($depts as $dept){ |
1047
|
|
|
if($custRoles = $_xhelpSession->get("xhelp_dept_$dept")){ |
1048
|
|
|
if($custRoles['roles'] != -1){ |
1049
|
|
|
foreach($custRoles['roles'] as $role){ |
1050
|
|
|
$hStaff->addStaffRole($uid, $role, $dept); |
1051
|
|
|
} |
1052
|
|
|
} else { |
1053
|
|
|
// If dept still checked, but no custom depts, give global roles to dept |
1054
|
|
|
foreach($roles as $role){ |
1055
|
|
|
$hStaff->addStaffRole($uid, $role, $dept); |
1056
|
|
|
} |
1057
|
|
|
} |
1058
|
|
|
} else { |
1059
|
|
|
foreach($roles as $role){ |
1060
|
|
|
$hStaff->addStaffRole($uid, $role, $dept); |
1061
|
|
|
} |
1062
|
|
|
} |
1063
|
|
|
} |
1064
|
|
|
$hTicketList =& xhelpGetHandler('ticketList'); |
1065
|
|
|
$hasTicketLists = $hTicketList->createStaffGlobalLists($uid); |
|
|
|
|
1066
|
|
|
|
1067
|
|
|
header("Location: ".XHELP_ADMIN_URL."/staff.php?op=clearRoles"); |
1068
|
|
|
} else { |
1069
|
|
|
$message = _XHELP_MESSAGE_ADDSTAFF_ERROR; |
1070
|
|
|
redirect_header(XHELP_ADMIN_URL.'/staff.php?op=clearRoles', 3, $message); |
1071
|
|
|
} |
1072
|
|
|
}//end if |
1073
|
|
|
} |
1074
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.