1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
require_once('common.inc.php'); |
4
|
|
|
|
5
|
|
|
use Battis\DataUtilities; |
6
|
|
|
use Battis\BootstrapSmarty\NotificationMessage; |
7
|
|
|
|
8
|
|
|
define('STEP_INSTRUCTIONS', 1); |
9
|
|
|
define('STEP_CONFIRM', 2); |
10
|
|
|
define('STEP_UPDATE', 3); |
11
|
|
|
|
12
|
|
|
$step = (empty($_REQUEST['step']) ? STEP_INSTRUCTIONS : $_REQUEST['step']); |
13
|
|
|
|
14
|
|
|
switch ($step) { |
15
|
|
|
case STEP_CONFIRM: |
16
|
|
|
$courses = DataUtilities::loadCsvToArray('csv'); |
17
|
|
|
|
18
|
|
|
if (empty($courses)) { |
19
|
|
|
$step = STEP_INSTRUCTIONS; |
20
|
|
|
$toolbox->smarty_addMessage( |
21
|
|
|
'Empty course list', |
22
|
|
|
'The uploaded CSV file contained no courses.', |
23
|
|
|
NotificationMessage::WARNING |
24
|
|
|
); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
if ($step == STEP_CONFIRM) { |
28
|
|
|
$toolbox->smarty_assign('fields', array_keys($courses[0])); |
29
|
|
|
$toolbox->smarty_assign('courses', $courses); |
30
|
|
|
$toolbox->smarty_assign('formHidden', array('step' => STEP_UPDATE)); |
31
|
|
|
$toolbox->smarty_display(basename(__FILE__, '.php') . '/confirm.tpl'); |
32
|
|
|
break; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/* flows into STEP_UPDATE */ |
36
|
|
|
|
37
|
|
|
case STEP_UPDATE: |
38
|
|
|
if ($step == STEP_UPDATE) { |
39
|
|
|
$links = ""; |
40
|
|
|
foreach ($_REQUEST['courses'] as $course) { |
41
|
|
|
if (isset($course['batch-include']) && $course['batch-include'] == 'include') { |
42
|
|
|
/* build parameter list */ |
43
|
|
|
$params = array(); |
44
|
|
|
if (!empty($course['account_id'])) { |
45
|
|
|
$params['account_id'] = "sis_account_id:{$course['account_id']}"; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
if (!empty($course['long_name'])) { |
49
|
|
|
$params['name'] = $course['long_name']; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
View Code Duplication |
if (!empty($course['short_name'])) { |
53
|
|
|
$params['course_code'] = $course['short_name']; |
54
|
|
|
} elseif (!empty($params['name'])) { |
55
|
|
|
$params['course_code'] = $params['name']; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
if (!empty($course['term_id'])) { |
59
|
|
|
$params['term_id'] = "sis_term_id:{$course['term_id']}"; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
if (!empty($course['course_id'])) { |
63
|
|
|
$params['sis_course_id'] = $course['course_id']; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
try { |
67
|
|
|
$response = $toolbox->api_put( |
68
|
|
|
"courses/sis_course_id%3A{$course['old_course_id']}", |
69
|
|
|
array( |
70
|
|
|
'course' => $params |
71
|
|
|
) |
72
|
|
|
); |
73
|
|
|
if (!empty($links)) { |
74
|
|
|
$links .= ", "; |
75
|
|
|
} |
76
|
|
|
$links .= "<a target=\"_parent\" href=\"{$_SESSION[CANVAS_INSTANCE_URL]}/courses/{$response['id']}/settings\">{$response['name']}</a>"; |
77
|
|
|
} catch (Exception $e) { |
78
|
|
|
$toolbox->exceptionErrorMessage($e); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
$toolbox->smarty_addMessage( |
84
|
|
|
'Update completed', |
85
|
|
|
'The following courses have been updated: ' . $links, |
86
|
|
|
NotificationMessage::GOOD |
|
|
|
|
87
|
|
|
); |
88
|
|
|
} else { |
89
|
|
|
$toolbox->smarty_addMessage( |
90
|
|
|
'Empty course list', |
91
|
|
|
'The uploaded CSV file contained no courses.', |
92
|
|
|
NotificationMessage::WARNING |
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/* flows into STEP_INSTRUCTIONS */ |
97
|
|
|
|
98
|
|
|
case STEP_INSTRUCTIONS: |
99
|
|
|
default: |
100
|
|
|
$toolbox->smarty_assign('formHidden', array('step' => STEP_CONFIRM)); |
101
|
|
|
$toolbox->smarty_display(basename(__FILE__, '.php') . '/instructions.tpl'); |
102
|
|
|
} |
103
|
|
|
|
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.