This repository has been archived by the owner on May 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
88 lines (76 loc) · 2.55 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
require_once 'common.inc.php';
use smtech\CanvasICSSync\Toolbox;
use smtech\ReflexiveCanvasLTI\LTI\ToolProvider;
use smtech\ReflexiveCanvasLTI\Exception\ConfigurationException;
define('ACTION_CONFIG', 'config');
define('ACTION_INSTALL', 'install');
define('ACTION_CONSUMERS', 'consumers');
define('ACTION_UNSPECIFIED', false);
/* store any requested actions for future handling */
$action = (empty($_REQUEST['action']) ?
ACTION_UNSPECIFIED :
strtolower($_REQUEST['action'])
);
/* action requests only come from outside the LTI! */
if ($action) {
unset($_SESSION[ToolProvider::class]);
}
/* authenticate LTI launch request, if present */
if ($toolbox->lti_isLaunching()) {
$toolbox->resetSession();
$toolbox->lti_authenticate();
exit;
}
/* if authenticated LTI launch, get the current user profile */
if (!empty($_SESSION[ToolProvider::class]['canvas'])) {
try {
$profile = $toolbox->api_get('users/' . $_SESSION[ToolProvider::class]['canvas']['user_id'] . '/profile');
} catch (Exception $e) {
$toolbox->smarty_addMessage(
'Error',
json_decode($e->getMessage(), true),
NotificationMessage::DANGER
);
}
$toolbox->smarty_assign([
'profile' => $profile,
]);
header('Location: import.php');
exit;
/* if not authenticated, default to showing credentials */
} else {
$action = (empty($action) ?
ACTION_CONFIG :
$action
);
}
/* process any actions */
switch ($action) {
/* reset cached install data from config file */
case ACTION_INSTALL:
$_SESSION['toolbox'] = Toolbox::fromConfiguration(CONFIG_FILE, true);
$toolbox =& $_SESSION['toolbox'];
/* test to see if we can connect to the API */
try {
$toolbox->getAPI();
} catch (ConfigurationException $e) {
/* if there isn't an API token in config.xml, are there OAuth credentials? */
if ($e->getCode() === ConfigurationException::CANVAS_API_INCORRECT) {
$toolbox->interactiveGetAccessToken();
exit;
} else { /* no (understandable) API credentials available -- doh! */
throw $e;
}
}
/* load the the database schema */
$toolbox->loadSchema();
/* finish by opening consumers control panel */
header('Location: consumers.php');
exit;
/* show LTI configuration XML file */
case ACTION_CONFIG:
header('Content-type: application/xml');
echo $toolbox->saveConfigurationXML();
exit;
}