1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
require_once('common.inc.php'); |
4
|
|
|
|
5
|
|
|
use Battis\BootstrapSmarty\NotificationMessage; |
6
|
|
|
|
7
|
|
|
$toolbox->cache_pushKey(basename(__FILE__, '.php')); |
8
|
|
|
$toolbox->getCache()->setLifetime(60 * 60); |
9
|
|
|
|
10
|
|
|
define('STEP_INSTRUCTIONS', 1); |
11
|
|
|
define('STEP_LISTING', 2); |
12
|
|
|
define('STEP_RESULT', 3); |
13
|
|
|
|
14
|
|
|
$step = (empty($_REQUEST['step']) ? STEP_INSTRUCTIONS : $_REQUEST['step']); |
15
|
|
|
|
16
|
|
|
switch ($step) { |
17
|
|
|
case STEP_LISTING: |
18
|
|
|
case STEP_RESULT: |
19
|
|
|
try { |
20
|
|
|
$users = $toolbox->cache_get('users'); |
21
|
|
|
if ($users === false) { |
22
|
|
|
$users = array(); |
23
|
|
|
$response = $toolbox->api_get('/accounts/1/users'); |
24
|
|
|
foreach ($response as $user) { |
25
|
|
|
$users[$user['id']] = $user; |
26
|
|
|
} |
27
|
|
|
$toolbox->cache_set('users', $users); |
28
|
|
|
} |
29
|
|
|
} catch (Exception $e) { |
30
|
|
|
$toolbox->exceptionErrorMessage($e); |
31
|
|
|
$step = STEP_INSTRUCTIONS; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
if ($step == STEP_LISTING || $step == STEP_RESULT) { |
35
|
|
|
$ROLES = array( |
36
|
|
|
'faculty', |
37
|
|
|
'staff', |
38
|
|
|
'student', |
39
|
|
|
'advisor', |
40
|
|
|
'no-menu', |
41
|
|
|
'alum', |
42
|
|
|
'departed' |
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
if ($step == STEP_RESULT) { |
46
|
|
|
foreach ($_REQUEST['users'] as $id => $data) { |
47
|
|
|
if ($data['dirty']) { |
48
|
|
|
if (empty($id) || empty($data['role'])) { |
49
|
|
|
$toolbox->smarty_addMessage( |
50
|
|
|
'Error', |
51
|
|
|
"Empty ID ($id) or role ({$data['role']})", |
52
|
|
|
NotificationMessage::ERROR |
|
|
|
|
53
|
|
|
); |
54
|
|
|
} else { |
55
|
|
|
$updated = false; |
56
|
|
|
if ($response = $customPrefs->query(" |
57
|
|
|
SELECT * |
58
|
|
|
FROM `users` |
59
|
|
|
WHERE |
60
|
|
|
`id` = '$id' |
61
|
|
|
")) { |
62
|
|
|
if ($response->num_rows > 0) { |
63
|
|
|
$updated = $customPrefs->query(" |
64
|
|
|
UPDATE `users` |
65
|
|
|
SET `role` = '{$data['role']}' |
66
|
|
|
WHERE `id` = '$id' |
67
|
|
|
"); |
68
|
|
|
} else { |
69
|
|
|
$updated = $customPrefs->query(" |
70
|
|
|
INSERT |
71
|
|
|
INTO `users` |
72
|
|
|
(`id`, `role`) VALUES ('$id', '{$data['role']}') |
73
|
|
|
"); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
if ($updated) { |
77
|
|
|
$toolbox->smarty_addMessage( |
78
|
|
|
$users[$id]['name'], |
79
|
|
|
"is now {$data['role']}.", |
80
|
|
|
NotificationMessage::GOOD |
|
|
|
|
81
|
|
|
); |
82
|
|
|
} else { |
83
|
|
|
$toolbox->smarty_addMessage( |
84
|
|
|
$users[$id]['name'], |
85
|
|
|
"was not updated to {$data['role']}. " . $customPrefs->error, |
86
|
|
|
NotificationMessage::WARNING |
87
|
|
|
); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$assignedUsers = array(); |
95
|
|
|
$unassignedUsers = array(); |
96
|
|
|
|
97
|
|
|
foreach ($users as $user) { |
98
|
|
|
if (!empty($user['sis_user_id'])) { |
99
|
|
|
if ($response = $customPrefs->query(" |
100
|
|
|
SELECT * |
101
|
|
|
FROM `users` |
102
|
|
|
WHERE |
103
|
|
|
`id` = '{$user['id']}' |
104
|
|
|
")) { |
105
|
|
|
if ($row = $response->fetch_assoc()) { |
106
|
|
|
$row['groups'] = unserialize($row['groups']); |
107
|
|
|
if (!empty($row['groups'])) { |
108
|
|
|
$groupResponse = $customPrefs->query(" |
109
|
|
|
SELECT * |
110
|
|
|
FROM `groups` |
111
|
|
|
WHERE |
112
|
|
|
`id` = '" . implode("' OR `id` = '", $row['groups']) . "' |
113
|
|
|
"); |
114
|
|
|
$groups = array(); |
115
|
|
|
while ($groupRow = $groupResponse->fetch_assoc()) { |
116
|
|
|
$groups[$groupRow['id']] = $groupRow; |
117
|
|
|
} |
118
|
|
|
$row['groups'] = $groups; |
119
|
|
|
} |
120
|
|
|
$assignedUsers[$row['role']][$user['id']]['custom-prefs'] = $row; |
121
|
|
|
$assignedUsers[$row['role']][$user['id']]['user'] = $user; |
122
|
|
|
} else { |
123
|
|
|
$unassignedUsers[0][$user['id']]['user'] = $user; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
$toolbox->smarty_assign('roles', $ROLES); |
130
|
|
|
$toolbox->smarty_assign('assignedUsers', $assignedUsers); |
131
|
|
|
$toolbox->smarty_assign('unassignedUsers', $unassignedUsers); |
132
|
|
|
$toolbox->smarty_assign('formHidden', array('step' => STEP_RESULT)); |
133
|
|
|
$toolbox->smarty_display(basename(__FILE__, '.php') . '/listing.tpl'); |
134
|
|
|
break; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/* continue into STEP_INSTRUCTIONS */ |
138
|
|
|
|
139
|
|
|
case STEP_INSTRUCTIONS: |
140
|
|
|
default: |
141
|
|
|
$toolbox->smarty_assign('formHidden', array('step' => STEP_LISTING)); |
142
|
|
|
$toolbox->smarty_display(basename(__FILE__, '.php') . '/instructions.tpl'); |
143
|
|
|
exit; |
144
|
|
|
} |
145
|
|
|
|
This class constant has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.