-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathget_context.php
More file actions
51 lines (45 loc) · 1.64 KB
/
get_context.php
File metadata and controls
51 lines (45 loc) · 1.64 KB
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
<?php
// return a JSON-encoded list for the specified path from the
// webctimport cache - top-level contexts only, for adding permissions, falling back to
// directory structure
require_once("../../config.php");
require_once("$CFG->dirroot/mod/webctimport/locallib.php");
require_login();
$context = get_context_instance(CONTEXT_SYSTEM);
$PAGE->set_context($context);
$path = required_param('path', PARAM_PATH); // directory path
$config = get_config('webctimport');
$rootfolderpath = $config->rootfolderpath;
if (substr($rootfolderpath, -1)=='/') {
$rootfolderpath = substr($rootfolderpath, 0, strlen($rootfolderpath)-1);
}
//debugging('get_listing from '.$rootfolderpath.' '.$path);
if (strpos($path, '../')===0 || strpos($path, '/../')!==false) {
print_error('getcontextpath','mod_webctimport', $path);
return;
}
$jsontext = file_get_contents($rootfolderpath.$path.'get_listing.json');
if ($jsontext==false) {
debugging('Not found: get_listing from '.$rootfolderpath.' '.$path);
// fall back to directory listing...
echo '{"error":"File not found - the WebCT cache may be incomplete"}';
}
else {
try {
// filter...
$json = json_decode($jsontext);
$list = array();
foreach ($json->list as $item) {
if ($item->webcttype=='Institution' || $item->webcttype=='Course' || $item->webcttype=='Section') {
webctimport_get_item_extra_info($item);
$list[] = $item;
}
}
$json->list = $list;
//debugging('get_listing from '.$rootfolderpath.$path.' -> '.$jsontext);
echo json_encode($json);
}
catch (Exception $e) {
print_error('getcontextjson','mod_webctimport', $e->getMessage());
}
}