forked from pauln/moodle-block_gismo-uc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.php
126 lines (109 loc) · 6.61 KB
/
common.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
/*
error_reporting(E_ALL);
ini_set('display_errors', true);
*/
// error mode
$error_mode = (isset($error_mode) AND in_array($error_mode, array("json", "moodle"))) ? $error_mode : "moodle";
// define constants
define('ROOT', (realpath(dirname( __FILE__ )) . DIRECTORY_SEPARATOR));
define('LIB_DIR', ROOT . "lib" . DIRECTORY_SEPARATOR);
// include moodle config file
require_once realpath(ROOT . ".." . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "config.php");
if(!function_exists("json_encode")) {
require_once('lib/gismo/server_side/json_encode.php');
}
// query filter between pages
$query = (isset($_REQUEST['q'])) ? addslashes($_REQUEST['q']) : '';
// LIBRARIES MANAGEMENT
// Please use this section to set server side and cliend side libraries to be included
// server side: please note that '.php' extension will be automatically added
$server_side_libraries = array("gismo" => array("FetchStaticDataMoodle", "GISMOutil"),
"third_parties" => array());
// client side: please note that '.js' extension will be automatically added
$jqPlotVer = "1.0.0b2";
$client_side_libraries = array("gismo" => array("gismo", "top_menu", "left_menu", "time_line", "gismo_util"),
"third_parties" => array("jquery/jquery-1.7.1.min",
"jquery-ui-1.8.6/js/jquery-ui-1.8.6.custom.min",
"jqplot.$jqPlotVer/jquery.jqplot.min",
"jqplot.$jqPlotVer/plugins/jqplot.barRenderer.min",
"jqplot.$jqPlotVer/plugins/jqplot.canvasAxisLabelRenderer.min",
"jqplot.$jqPlotVer/plugins/jqplot.canvasAxisTickRenderer.min",
"jqplot.$jqPlotVer/plugins/jqplot.canvasTextRenderer.min",
"jqplot.$jqPlotVer/plugins/jqplot.categoryAxisRenderer.min",
// "jqplot.0.9.7/plugins/jqplot.cursor.min",
"jqplot.$jqPlotVer/plugins/jqplot.dateAxisRenderer.min",
// "jqplot.0.9.7/plugins/jqplot.dragable.min",
"jqplot.$jqPlotVer/plugins/jqplot.highlighter.min",
// "jqplot.0.9.7/plugins/jqplot.logAxisRenderer.min",
// "jqplot.0.9.7/plugins/jqplot.mekkoAxisRenderer.min",
// "jqplot.0.9.7/plugins/jqplot.mekkoRenderer.min",
// "jqplot.0.9.7/plugins/jqplot.ohlcRenderer.min",
// "jqplot.0.9.7/plugins/jqplot.pieRenderer.min",
"jqplot.$jqPlotVer/plugins/jqplot.pointLabels.min"
// "jqplot.0.9.7/plugins/jqplot.trendline.min"
));
// include server-side libraries libraries
if (is_array($server_side_libraries) AND count($server_side_libraries) > 0) {
foreach ($server_side_libraries as $key => $server_side_libs) {
if (is_array($server_side_libs) AND count($server_side_libs) > 0) {
foreach ($server_side_libs as $server_side_lib) {
$lib_full_path = LIB_DIR . $key . DIRECTORY_SEPARATOR . "server_side" . DIRECTORY_SEPARATOR . $server_side_lib . ".php";
if (is_file($lib_full_path) AND is_readable($lib_full_path)) {
require_once $lib_full_path;
}
}
}
}
}
// check input data
if (!isset($_REQUEST["srv_data"])) {
GISMOutil::gismo_error('err_srv_data_not_set', $error_mode);
exit;
}
$srv_data_encoded = $_REQUEST["srv_data"];
$srv_data = (object) unserialize(base64_decode(urldecode($srv_data_encoded)));
// course id
if (!property_exists($srv_data, "course_id")) {
GISMOutil::gismo_error('err_course_not_set', $error_mode);
exit;
}
// block instance id
if (!property_exists($srv_data, "block_instance_id")) {
GISMOutil::gismo_error('err_block_instance_id_not_set', $error_mode);
exit;
}
// extract the course
if (! $course = get_record("course", "id", intval($srv_data->course_id))) {
GISMOutil::gismo_error('err_course_not_set', $error_mode);
exit;
}
// check authorization
if (!has_capability('block/gismo:view', get_context_instance(CONTEXT_COURSE, intval($srv_data->course_id)))) {
GISMOutil::gismo_error('err_access_denied', $error_mode);
exit;
}
// get gismo settings
$gismo_settings = get_field("block_instance", "configdata", "id", intval($srv_data->block_instance_id));
if (is_null($gismo_settings) OR $gismo_settings === "") {
$gismo_settings = get_object_vars(GISMOutil::get_default_options());
} else {
$gismo_settings = get_object_vars(unserialize(base64_decode($gismo_settings)));
if (is_array($gismo_settings) AND count($gismo_settings) > 0) {
foreach ($gismo_settings as $key => $value) {
if (is_numeric($value)) {
if (strval(intval($value)) === strval($value)) {
$gismo_settings[$key] = intval($value);
} else if (strval(floatval($value)) === strval($value)) {
$gismo_settings[$key] = floatval($value);
}
}
}
}
// include_hidden_items
if (!array_key_exists("include_hidden_items", $gismo_settings)) {
$gismo_settings["include_hidden_items"] = 1;
}
}
$gismo_config = json_encode($gismo_settings);
?>