|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
require_once 'common.inc.php'; |
|
4
|
|
|
|
|
5
|
|
|
use smtech\StMarksSmarty\StMarksSmarty; |
|
6
|
|
|
use Battis\BootstrapSmarty\NotificationMessage; |
|
7
|
|
|
|
|
8
|
|
|
$toolbox->getSmarty()->enable(StMarksSmarty::MODULE_COLORPICKER); |
|
9
|
|
|
|
|
10
|
|
|
define("STEP_INSTRUCTIONS", 1); |
|
11
|
|
|
define("STEP_CONFIRM", 2); |
|
12
|
|
|
define("STEP_SET_COLOR", 3); |
|
13
|
|
|
|
|
14
|
|
|
$step = (empty($_REQUEST['step']) ? STEP_INSTRUCTIONS : $_REQUEST['step']); |
|
15
|
|
|
|
|
16
|
|
|
switch ($step) { |
|
17
|
|
|
case STEP_SET_COLOR: |
|
18
|
|
|
if (empty($_REQUEST['course'])) { |
|
19
|
|
|
$toolbox->smarty_addMessage( |
|
20
|
|
|
'Course required', |
|
21
|
|
|
'Hard to set the color for an unspecified course.', |
|
22
|
|
|
NotificationMessage::ERROR |
|
|
|
|
|
|
23
|
|
|
); |
|
24
|
|
|
} else { |
|
25
|
|
|
if (empty($_REQUEST['color'])) { |
|
26
|
|
|
$toolbox->smarty_addMessage( |
|
27
|
|
|
'Color required', |
|
28
|
|
|
'Hard to set a color without the color', |
|
29
|
|
|
NotificationMessage::ERROR |
|
|
|
|
|
|
30
|
|
|
); |
|
31
|
|
|
} else { |
|
32
|
|
|
$color = preg_replace('/#/', '', $_REQUEST['color']); |
|
33
|
|
|
try { |
|
34
|
|
|
$enrollments = $toolbox->api_get("courses/{$_REQUEST['course']}/enrollments"); |
|
35
|
|
|
foreach ($enrollments as $enrollment) { |
|
36
|
|
|
$toolbox->api_put( |
|
37
|
|
|
"users/{$enrollment['user']['id']}/colors/course_{$_REQUEST['course']}", |
|
38
|
|
|
array( |
|
39
|
|
|
'hexcode' => $color |
|
40
|
|
|
) |
|
41
|
|
|
); |
|
42
|
|
|
} |
|
43
|
|
|
$toolbox->smarty_addMessage( |
|
44
|
|
|
'Color updated', |
|
45
|
|
|
"Updated the course color to <span style=\"color: #$color; background: white; border-radius: .25em; padding: .1em;\">#$color ◼</span> for <a target=\"_top\" href=\"" . $_SESSION[CANVAS_INSTANCE_URL] . '/courses/' . $_REQUEST['course'] . '/users">' . $enrollments->count() . ' users</a>.' |
|
46
|
|
|
); |
|
47
|
|
|
} catch (Exception $e) { |
|
48
|
|
|
$toolbox->exceptionErrorMessage($e); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/* TODO should really objectify rather than using gotos, huh? */ |
|
54
|
|
|
/* flow into STEP_CONFIRM (and thence STEP_INSTRUCTIONS) */ |
|
55
|
|
|
|
|
56
|
|
|
case STEP_CONFIRM: |
|
57
|
|
|
if ($step == STEP_CONFIRM) { |
|
58
|
|
|
if (empty($_REQUEST['course'])) { |
|
59
|
|
|
$toolbox->smarty_addMessage( |
|
60
|
|
|
'Course required', |
|
61
|
|
|
'Hard to set the color for an unspecified course.', |
|
62
|
|
|
NotificationMessage::ERROR |
|
|
|
|
|
|
63
|
|
|
); |
|
64
|
|
|
} else { |
|
65
|
|
|
try { |
|
66
|
|
|
$courses = $toolbox->api_get( |
|
67
|
|
|
// FIXME don't hard code account numbers... yeesh |
|
68
|
|
|
'accounts/1/courses', |
|
69
|
|
|
array( |
|
70
|
|
|
'search_term' => $_REQUEST['course'], |
|
71
|
|
|
'include[]' => 'term' |
|
72
|
|
|
) |
|
73
|
|
|
); |
|
74
|
|
|
$toolbox->smarty_assign('courses', $courses); |
|
75
|
|
|
$toolbox->smarty_assign('formHidden', array('step' => STEP_SET_COLOR)); |
|
76
|
|
|
$toolbox->smarty_display(basename(__FILE__, '.php') . '/confirm.tpl'); |
|
77
|
|
|
exit; |
|
78
|
|
|
} catch (Exception $e) { |
|
79
|
|
|
$toolbox->exceptionErrorMessage($e); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/* flow into STEP_INSTRUCTIONS */ |
|
85
|
|
|
|
|
86
|
|
|
case STEP_INSTRUCTIONS: |
|
87
|
|
|
default: |
|
88
|
|
|
$toolbox->smarty_assign('formHidden', array('step' => STEP_CONFIRM)); |
|
89
|
|
|
$toolbox->smarty_display(basename(__FILE__, '.php') . '/instructions.tpl'); |
|
90
|
|
|
} |
|
91
|
|
|
|
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.