@@ -148,8 +148,7 @@ |
||
148 | 148 | $enrollment = $toolbox->api_post( |
149 | 149 | ( |
150 | 150 | $courseEnrollment ? |
151 | - "/courses/{$_REQUEST['course']}/enrollments" : |
|
152 | - "/sections/{$_REQUEST['section']}/enrollments" |
|
151 | + "/courses/{$_REQUEST['course']}/enrollments" : "/sections/{$_REQUEST['section']}/enrollments" |
|
153 | 152 | ), |
154 | 153 | array( |
155 | 154 | 'enrollment[user_id]' => $user['id'], |
@@ -31,180 +31,180 @@ |
||
31 | 31 | } |
32 | 32 | |
33 | 33 | switch ($step) { |
34 | - case $STEP_CONFIRM: |
|
35 | - try { |
|
36 | - $users = $toolbox->explodeCommaAndNewlines($_REQUEST['users']); |
|
37 | - |
|
38 | - if (empty($_REQUEST['course'])) { |
|
39 | - $toolbox->smarty_addMessage( |
|
40 | - 'Course', |
|
41 | - 'was not selected, so no enrollments can happen', |
|
42 | - NotificationMessage::ERROR |
|
43 | - ); |
|
44 | - $step = $STEP_INSTRUCTIONS; |
|
45 | - } else { |
|
46 | - $sections = $toolbox->cache_get("courses/{$_REQUEST['course']}"); |
|
47 | - if (empty($sections)) { |
|
48 | - $section = array(); |
|
49 | - $courses = $toolbox->api_get( |
|
50 | - 'accounts/1/courses', |
|
51 | - array( |
|
52 | - 'search_term' => $_REQUEST['course'] |
|
53 | - ) |
|
34 | + case $STEP_CONFIRM: |
|
35 | + try { |
|
36 | + $users = $toolbox->explodeCommaAndNewlines($_REQUEST['users']); |
|
37 | + |
|
38 | + if (empty($_REQUEST['course'])) { |
|
39 | + $toolbox->smarty_addMessage( |
|
40 | + 'Course', |
|
41 | + 'was not selected, so no enrollments can happen', |
|
42 | + NotificationMessage::ERROR |
|
54 | 43 | ); |
55 | - foreach ($courses as $course) { |
|
56 | - $courseSections = $toolbox->api_get("courses/{$course['id']}/sections"); |
|
57 | - if ($courseSections->count() == 0) { |
|
58 | - /* we have only the "magic" default section */ |
|
59 | - $sections[] = array('course' => $course); |
|
60 | - } else { |
|
61 | - foreach ($courseSections as $section) { |
|
62 | - $sections[] = array( |
|
63 | - 'course' => $course, |
|
64 | - 'section' => $section |
|
65 | - ); |
|
44 | + $step = $STEP_INSTRUCTIONS; |
|
45 | + } else { |
|
46 | + $sections = $toolbox->cache_get("courses/{$_REQUEST['course']}"); |
|
47 | + if (empty($sections)) { |
|
48 | + $section = array(); |
|
49 | + $courses = $toolbox->api_get( |
|
50 | + 'accounts/1/courses', |
|
51 | + array( |
|
52 | + 'search_term' => $_REQUEST['course'] |
|
53 | + ) |
|
54 | + ); |
|
55 | + foreach ($courses as $course) { |
|
56 | + $courseSections = $toolbox->api_get("courses/{$course['id']}/sections"); |
|
57 | + if ($courseSections->count() == 0) { |
|
58 | + /* we have only the "magic" default section */ |
|
59 | + $sections[] = array('course' => $course); |
|
60 | + } else { |
|
61 | + foreach ($courseSections as $section) { |
|
62 | + $sections[] = array( |
|
63 | + 'course' => $course, |
|
64 | + 'section' => $section |
|
65 | + ); |
|
66 | + } |
|
66 | 67 | } |
67 | 68 | } |
69 | + $toolbox->cache_set("courses/{$_REQUEST['course']}", $sections, $CACHE_LIFETIME); |
|
68 | 70 | } |
69 | - $toolbox->cache_set("courses/{$_REQUEST['course']}", $sections, $CACHE_LIFETIME); |
|
70 | - } |
|
71 | 71 | |
72 | - if (empty($sections)) { |
|
73 | - $toolbox->smarty_addMessage( |
|
74 | - 'No Courses', |
|
75 | - "matched your search term '{$_REQUEST['course']}'.", |
|
76 | - NotificationMessage::WARNING |
|
77 | - ); |
|
78 | - $step = $STEP_INSTRUCTIONS; |
|
72 | + if (empty($sections)) { |
|
73 | + $toolbox->smarty_addMessage( |
|
74 | + 'No Courses', |
|
75 | + "matched your search term '{$_REQUEST['course']}'.", |
|
76 | + NotificationMessage::WARNING |
|
77 | + ); |
|
78 | + $step = $STEP_INSTRUCTIONS; |
|
79 | + } |
|
79 | 80 | } |
80 | - } |
|
81 | 81 | |
82 | - if ($step == $STEP_CONFIRM) { |
|
83 | - if (!empty($users)) { |
|
84 | - $confirm = array(); |
|
85 | - foreach ($users as $term) { |
|
86 | - $confirm[$term] = $toolbox->cache_get("users/$term"); |
|
87 | - if ($confirm[$term] === false) { |
|
88 | - $found = $toolbox->api_get( |
|
89 | - 'accounts/1/users', |
|
90 | - [ |
|
91 | - 'search_term' => $term, |
|
92 | - 'include[]' => 'term' |
|
93 | - ] |
|
94 | - ); |
|
95 | - foreach ($found as $user) { |
|
96 | - if (!stripos($user['sis_user_id'], '-advisor')) { |
|
97 | - $confirm[$term][] = $user; |
|
82 | + if ($step == $STEP_CONFIRM) { |
|
83 | + if (!empty($users)) { |
|
84 | + $confirm = array(); |
|
85 | + foreach ($users as $term) { |
|
86 | + $confirm[$term] = $toolbox->cache_get("users/$term"); |
|
87 | + if ($confirm[$term] === false) { |
|
88 | + $found = $toolbox->api_get( |
|
89 | + 'accounts/1/users', |
|
90 | + [ |
|
91 | + 'search_term' => $term, |
|
92 | + 'include[]' => 'term' |
|
93 | + ] |
|
94 | + ); |
|
95 | + foreach ($found as $user) { |
|
96 | + if (!stripos($user['sis_user_id'], '-advisor')) { |
|
97 | + $confirm[$term][] = $user; |
|
98 | + } |
|
98 | 99 | } |
100 | + $toolbox->cache_set("users/$term", $confirm[$term], $CACHE_LIFETIME); |
|
99 | 101 | } |
100 | - $toolbox->cache_set("users/$term", $confirm[$term], $CACHE_LIFETIME); |
|
101 | 102 | } |
102 | - } |
|
103 | 103 | |
104 | - $toolbox->smarty_assign([ |
|
105 | - 'sections' => $sections, |
|
106 | - 'terms' => $toolbox->getTermList(), |
|
107 | - 'accounts' => $toolbox->getAccountList(), |
|
108 | - 'confirm' => $confirm, |
|
109 | - 'roles' => $toolbox->api_get('accounts/1/roles'), // TODO make this account-specific |
|
110 | - 'formHidden'=> [ |
|
111 | - 'step' => $STEP_ENROLL |
|
112 | - ] |
|
113 | - ]); |
|
114 | - $toolbox->smarty_display(basename(__FILE__, '.php') . '/confirm.tpl'); |
|
115 | - break; |
|
116 | - } else { |
|
117 | - $toolbox->smarty_addMessage( |
|
118 | - 'Users', |
|
119 | - 'were not selected, so no enrollments can happen.', |
|
120 | - NotificationMessage::ERROR |
|
121 | - ); |
|
122 | - $step = $STEP_INSTRUCTIONS; |
|
123 | - } |
|
124 | - } |
|
125 | - } catch (Pest_Exception $e) { |
|
126 | - $toolbox->exceptionErrorMessage($e); |
|
127 | - } |
|
128 | - |
|
129 | - /* flow into $STEP_ENROLL (and $STEP_INSTRUCTIONS) */ |
|
130 | - |
|
131 | - case $STEP_ENROLL: |
|
132 | - try { |
|
133 | - if ($step == $STEP_ENROLL) { |
|
134 | - $courseEnrollment = false; |
|
135 | - if (empty($_REQUEST['section'])) { |
|
136 | - if (!empty($_REQUEST['course'])) { |
|
137 | - $courseEnrollment = true; |
|
104 | + $toolbox->smarty_assign([ |
|
105 | + 'sections' => $sections, |
|
106 | + 'terms' => $toolbox->getTermList(), |
|
107 | + 'accounts' => $toolbox->getAccountList(), |
|
108 | + 'confirm' => $confirm, |
|
109 | + 'roles' => $toolbox->api_get('accounts/1/roles'), // TODO make this account-specific |
|
110 | + 'formHidden'=> [ |
|
111 | + 'step' => $STEP_ENROLL |
|
112 | + ] |
|
113 | + ]); |
|
114 | + $toolbox->smarty_display(basename(__FILE__, '.php') . '/confirm.tpl'); |
|
115 | + break; |
|
138 | 116 | } else { |
139 | 117 | $toolbox->smarty_addMessage( |
140 | - 'Course or Section', |
|
141 | - 'Missing from enrollment request.', |
|
118 | + 'Users', |
|
119 | + 'were not selected, so no enrollments can happen.', |
|
142 | 120 | NotificationMessage::ERROR |
143 | 121 | ); |
144 | 122 | $step = $STEP_INSTRUCTIONS; |
145 | 123 | } |
146 | 124 | } |
125 | + } catch (Pest_Exception $e) { |
|
126 | + $toolbox->exceptionErrorMessage($e); |
|
127 | + } |
|
147 | 128 | |
148 | - if (empty($_REQUEST['users'])) { |
|
149 | - $toolbox->smarty_addMessage( |
|
150 | - 'Users', |
|
151 | - 'missing from enrollment request.', |
|
152 | - NotificationMessage::ERROR |
|
153 | - ); |
|
154 | - } elseif ($step == $STEP_ENROLL) { |
|
155 | - $count = 0; |
|
156 | - foreach ($_REQUEST['users'] as $user) { |
|
157 | - $enrollment = $toolbox->api_post( |
|
158 | - ( |
|
159 | - $courseEnrollment ? |
|
160 | - "/courses/{$_REQUEST['course']}/enrollments" : |
|
161 | - "/sections/{$_REQUEST['section']}/enrollments" |
|
162 | - ), |
|
163 | - array( |
|
164 | - 'enrollment[user_id]' => $user['id'], |
|
165 | - 'enrollment[role_id]' => $user['role'], |
|
166 | - 'enrollment[enrollment_state]' => 'active', |
|
167 | - 'enrollment[notify]' => (empty($user['notify']) ? 'false' : $user['notify']) |
|
168 | - ) |
|
169 | - ); |
|
170 | - if (!empty($enrollment['id'])) { |
|
171 | - $count++; |
|
172 | - } // FIXME should really list errors, no? |
|
173 | - } |
|
129 | + /* flow into $STEP_ENROLL (and $STEP_INSTRUCTIONS) */ |
|
174 | 130 | |
175 | - if ($courseEnrollment) { |
|
176 | - $course = $_REQUEST['course']; |
|
177 | - } else { |
|
178 | - $section = $toolbox->api_get("sections/{$_REQUEST['section']}"); |
|
179 | - $course = $section['course_id']; |
|
131 | + case $STEP_ENROLL: |
|
132 | + try { |
|
133 | + if ($step == $STEP_ENROLL) { |
|
134 | + $courseEnrollment = false; |
|
135 | + if (empty($_REQUEST['section'])) { |
|
136 | + if (!empty($_REQUEST['course'])) { |
|
137 | + $courseEnrollment = true; |
|
138 | + } else { |
|
139 | + $toolbox->smarty_addMessage( |
|
140 | + 'Course or Section', |
|
141 | + 'Missing from enrollment request.', |
|
142 | + NotificationMessage::ERROR |
|
143 | + ); |
|
144 | + $step = $STEP_INSTRUCTIONS; |
|
145 | + } |
|
180 | 146 | } |
181 | 147 | |
182 | - // FIXME no longer have the course ID… link is broken |
|
183 | - $toolbox->smarty_addMessage( |
|
184 | - 'Success', |
|
185 | - "<a target=\"_top\" href=\"{$_SESSION[CANVAS_INSTANCE_URL]}/courses/$course/users\">$count users enrolled</a>", |
|
186 | - NotificationMessage::GOOD |
|
187 | - ); |
|
148 | + if (empty($_REQUEST['users'])) { |
|
149 | + $toolbox->smarty_addMessage( |
|
150 | + 'Users', |
|
151 | + 'missing from enrollment request.', |
|
152 | + NotificationMessage::ERROR |
|
153 | + ); |
|
154 | + } elseif ($step == $STEP_ENROLL) { |
|
155 | + $count = 0; |
|
156 | + foreach ($_REQUEST['users'] as $user) { |
|
157 | + $enrollment = $toolbox->api_post( |
|
158 | + ( |
|
159 | + $courseEnrollment ? |
|
160 | + "/courses/{$_REQUEST['course']}/enrollments" : |
|
161 | + "/sections/{$_REQUEST['section']}/enrollments" |
|
162 | + ), |
|
163 | + array( |
|
164 | + 'enrollment[user_id]' => $user['id'], |
|
165 | + 'enrollment[role_id]' => $user['role'], |
|
166 | + 'enrollment[enrollment_state]' => 'active', |
|
167 | + 'enrollment[notify]' => (empty($user['notify']) ? 'false' : $user['notify']) |
|
168 | + ) |
|
169 | + ); |
|
170 | + if (!empty($enrollment['id'])) { |
|
171 | + $count++; |
|
172 | + } // FIXME should really list errors, no? |
|
173 | + } |
|
174 | + |
|
175 | + if ($courseEnrollment) { |
|
176 | + $course = $_REQUEST['course']; |
|
177 | + } else { |
|
178 | + $section = $toolbox->api_get("sections/{$_REQUEST['section']}"); |
|
179 | + $course = $section['course_id']; |
|
180 | + } |
|
188 | 181 | |
189 | - $_REQUEST = array(); |
|
182 | + // FIXME no longer have the course ID… link is broken |
|
183 | + $toolbox->smarty_addMessage( |
|
184 | + 'Success', |
|
185 | + "<a target=\"_top\" href=\"{$_SESSION[CANVAS_INSTANCE_URL]}/courses/$course/users\">$count users enrolled</a>", |
|
186 | + NotificationMessage::GOOD |
|
187 | + ); |
|
188 | + |
|
189 | + $_REQUEST = array(); |
|
190 | + } |
|
190 | 191 | } |
192 | + } catch (Pest_Exception $e) { |
|
193 | + $toolbox->exceptionErrorMessage($e); |
|
191 | 194 | } |
192 | - } catch (Pest_Exception $e) { |
|
193 | - $toolbox->exceptionErrorMessage($e); |
|
194 | - } |
|
195 | - |
|
196 | - /* fall through to STEP_INSTRUCTION */ |
|
197 | - |
|
198 | - case $STEP_INSTRUCTIONS: |
|
199 | - default: |
|
200 | - if (!empty($_REQUEST['users'])) { |
|
201 | - $toolbox->smarty_assign('users', $_REQUEST['users']); |
|
202 | - } |
|
203 | - if (!empty($_REQUEST['course'])) { |
|
204 | - $toolbox->smarty_assign('course', $_REQUEST['course']); |
|
205 | - } |
|
206 | - |
|
207 | - $toolbox->smarty_assign('roles', $roles); |
|
208 | - $toolbox->smarty_assign('formHidden', array('step' => $STEP_CONFIRM)); |
|
209 | - $toolbox->smarty_display(basename(__FILE__, '.php') . '/instructions.tpl'); |
|
195 | + |
|
196 | + /* fall through to STEP_INSTRUCTION */ |
|
197 | + |
|
198 | + case $STEP_INSTRUCTIONS: |
|
199 | + default: |
|
200 | + if (!empty($_REQUEST['users'])) { |
|
201 | + $toolbox->smarty_assign('users', $_REQUEST['users']); |
|
202 | + } |
|
203 | + if (!empty($_REQUEST['course'])) { |
|
204 | + $toolbox->smarty_assign('course', $_REQUEST['course']); |
|
205 | + } |
|
206 | + |
|
207 | + $toolbox->smarty_assign('roles', $roles); |
|
208 | + $toolbox->smarty_assign('formHidden', array('step' => $STEP_CONFIRM)); |
|
209 | + $toolbox->smarty_display(basename(__FILE__, '.php') . '/instructions.tpl'); |
|
210 | 210 | } |
@@ -8,8 +8,7 @@ discard block |
||
8 | 8 | |
9 | 9 | /* store any requested actions for future handling */ |
10 | 10 | $action = (empty($_REQUEST['action']) ? |
11 | - ACTION_UNSPECIFIED : |
|
12 | - strtolower($_REQUEST['action']) |
|
11 | + ACTION_UNSPECIFIED : strtolower($_REQUEST['action']) |
|
13 | 12 | ); |
14 | 13 | |
15 | 14 | /* action requests only come from outside the LTI! */ |
@@ -25,7 +24,7 @@ discard block |
||
25 | 24 | @session_unset(); |
26 | 25 | @session_start(); |
27 | 26 | @session_regenerate_id(true); |
28 | - $_SESSION[Toolbox::class] =& $toolbox; |
|
27 | + $_SESSION[Toolbox::class] = & $toolbox; |
|
29 | 28 | session_write_close(); |
30 | 29 | $toolbox->lti_authenticate(); |
31 | 30 | exit; |
@@ -39,8 +38,7 @@ discard block |
||
39 | 38 | /* if not authenticated, default to showing credentials */ |
40 | 39 | } else { |
41 | 40 | $action = (empty($action) ? |
42 | - ACTION_CONFIG : |
|
43 | - $action |
|
41 | + ACTION_CONFIG : $action |
|
44 | 42 | ); |
45 | 43 | } |
46 | 44 | |
@@ -49,7 +47,7 @@ discard block |
||
49 | 47 | /* reset cached install data from config file */ |
50 | 48 | case ACTION_INSTALL: |
51 | 49 | $_SESSION['toolbox'] = Toolbox::fromConfiguration(CONFIG_FILE, true); |
52 | - $toolbox =& $_SESSION['toolbox']; |
|
50 | + $toolbox = & $_SESSION['toolbox']; |
|
53 | 51 | |
54 | 52 | /* test to see if we can connect to the API */ |
55 | 53 | try { |
@@ -121,7 +121,7 @@ |
||
121 | 121 | /* ...and purge users who should not be enrolled */ |
122 | 122 | } elseif (!isset($potentialDuplicates[$enrollment['user']['id']])) { |
123 | 123 | if (empty($enrollment['id'])) { |
124 | - $toolbox->smarty_addMessage('No enrollment to delete', '<pre>'. print_r($enrollment, true) . '</pre>', NotificationMessage::WARNING); |
|
124 | + $toolbox->smarty_addMessage('No enrollment to delete', '<pre>' . print_r($enrollment, true) . '</pre>', NotificationMessage::WARNING); |
|
125 | 125 | } else { |
126 | 126 | $toolbox->api_delete( |
127 | 127 | "courses/$courseId/enrollments/{$enrollment['id']}", |
@@ -70,7 +70,7 @@ |
||
70 | 70 | if ($step == STEP_FORCE) { |
71 | 71 | try { |
72 | 72 | $notificationPreferences = []; |
73 | - foreach($_REQUEST['notification_preferences'] as $notification => $settings) { |
|
73 | + foreach ($_REQUEST['notification_preferences'] as $notification => $settings) { |
|
74 | 74 | if (!empty($settings['enabled']) && $settings['enabled']) { |
75 | 75 | $notificationPreferences[$notification]['frequency'] = $settings['frequency']; |
76 | 76 | } |
@@ -28,7 +28,7 @@ |
||
28 | 28 | $user['name'] |
29 | 29 | ]; |
30 | 30 | } else { |
31 | - foreach($views as $view) { |
|
31 | + foreach ($views as $view) { |
|
32 | 32 | if (preg_match('%.*/user_notes\??.*%', $view['url']) && !preg_match('/Advisory%20Group/', $view['url'])) { |
33 | 33 | preg_match('/.*course_name=(.*)/', $view['url'], $match); |
34 | 34 | $timestamp = new DateTime($view['created_at'], new DateTimeZone('America/New_York')); |
@@ -13,7 +13,7 @@ |
||
13 | 13 | if (empty($_SESSION[Toolbox::class])) { |
14 | 14 | $_SESSION[Toolbox::class] = Toolbox::fromConfiguration(CONFIG_FILE); |
15 | 15 | } |
16 | -$toolbox =& $_SESSION[Toolbox::class]; |
|
16 | +$toolbox = & $_SESSION[Toolbox::class]; |
|
17 | 17 | |
18 | 18 | /* set the Tool Consumer's instance URL, if present */ |
19 | 19 | if (empty($_SESSION[CANVAS_INSTANCE_URL])) { |