-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdashboardpage.class.php
304 lines (282 loc) · 12.2 KB
/
dashboardpage.class.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<?php
/**
* ELIS(TM): Enterprise Learning Intelligence Suite
* Copyright (C) 2008-2013 Remote-Learner.net Inc (http://www.remote-learner.net)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package local_elisprogram
* @author Remote-Learner.net Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright (C) 2008-2013 Remote Learner.net Inc http://www.remote-learner.net
*
*/
defined('MOODLE_INTERNAL') || die();
require_once elispm::lib('deprecatedlib.php'); // cm_get_crlmuserid()
require_once elispm::lib('page.class.php');
require_once elispm::file('healthpage.class.php');
/**
* This page is just a dummy that allows generic linking to the dashboard
* from the Curriculum Admin menu
*
*/
class dashboardpage extends pm_page {
// Arrays for which components last cron runtimes to include
private $blocks = array(); // empty array for none; 'elisadmin' ?
private $plugins = array(); // TBD: 'local_elisprogram', 'local_eliscore' ?
/**
* Determines whether or not the current user can navigate to the
* Curriculum Admin dashboard
*
* @return boolean Whether or not access is allowed
*
*/
function can_do_default() {
//allow any logged-in user since the dashboard varies based on the user
return isloggedin();
}
/**
* Create a url to the current page (just points to the main PM index)
*
* @return moodle_url
*/
function get_moodle_url($extra = array()) {
$page = $this->get_new_page($extra);
$url = $page->url;
return $url;
}
function last_cron_runtimes() {
global $DB;
$description = '';
foreach ($this->blocks as $block) {
$a = new stdClass;
$a->name = $block;
$lastcron = $DB->get_field('block', 'lastcron', array('name' => $block));
$a->lastcron = $lastcron ? userdate($lastcron) : get_string('cron_notrun', 'local_elisprogram');
$description .= get_string('health_cron_block', 'local_elisprogram', $a);
}
foreach ($this->plugins as $plugin) {
$a = new stdClass;
$a->name = $plugin;
$lastcron = $DB->get_field('config_plugins', 'value', array('plugin' => $plugin, 'name' => 'lastcron'));
$a->lastcron = $lastcron ? userdate($lastcron) : get_string('cron_notrun', 'local_elisprogram');
$description .= get_string('health_cron_plugin', 'local_elisprogram', $a);
}
$lasteliscron = $DB->get_field('local_eliscore_sched_tasks', 'MAX(lastruntime)', array());
$lastcron = $lasteliscron ? userdate($lasteliscron) : get_string('cron_notrun', 'local_elisprogram');
$description .= get_string('health_cron_elis', 'local_elisprogram', $lastcron);
return $description;
}
/**
* Entry point to the page
*/
function do_default() {
global $USER, $CFG;
require_once(elispm::lib('lib.php'));
//update the current user's info in the PM system
//todo: check return status?
pm_update_user_information($USER->id);
//display as normal
$this->display('default');
}
/**
* get_tcpdf_info method to get TCPDF library version info
* @return array componentname, release, version
*/
public function get_tcpdf_info() {
global $CFG;
$ret = array(null, null, null);
$tcpdfinfofile = $CFG->dirroot.'/local/elisreports/lib/tcpdf/README.TXT';
if (file_exists($tcpdfinfofile)) {
$tcpdfreadme = file_get_contents($tcpdfinfofile);
$matches = array();
$name = '';
$release = '';
$version = '';
if (preg_match('/Name: (.*)/', $tcpdfreadme, $matches)) {
$name = $matches[1];
}
if (preg_match('/Version: (.*)/', $tcpdfreadme, $matches)) {
$release = $matches[1];
}
if (preg_match('/Release date: (.*)/', $tcpdfreadme, $matches)) {
$version = $matches[1];
}
$ret = array($name, $release, $version);
}
return $ret;
}
/**
* get_pchart_info method to get pChart library version info
* @return array componentname, release, version
*/
public function get_pchart_info() {
global $CFG;
$ret = array(null, null, null);
$pchartinfofile = $CFG->dirroot.'/local/elisreports/lib/pChart.1.27d/pChart/pChart.class';
if (file_exists($pchartinfofile)) {
$ret = array('pChart', '1.27d', '06/17/2008'); // TBD - get from file?
}
return $ret;
}
/**
* get_jquery_file_info method to get jQuery library version info from specified file
* @param array $files list of files to get info from
* @param array $infostrings associative array of default values, i.e. array('name' => 'Name', 'version' => 'Version', 'release' => 'Release date')
* @return array componentname, release, version
*/
public function get_jquery_file_info($files, $infostrings) {
$ret = array(null, null, null);
foreach ($files as $filename) {
$matches = array();
$name = null;
if (preg_match("/.*{$infostrings['name']}-([0-9.]*)/", $filename, $matches)) {
$name = $infostrings['name'];
$release = trim($matches[1], '.');
$version = '';
$ret = array($name, $release, $version);
break;
}
}
return $ret;
}
/**
* get_re_jquery_info method to get jQuery library version info
* @return array componentname, release, version
*/
public function get_re_jquery_info() {
global $CFG;
$files = glob($CFG->dirroot.'/local/elisprogram/js/results_engine/jquery-*');
return $this->get_jquery_file_info($files, array('name' => 'jquery'));
}
/**
* get_re_jquery_ui_info method to get jQuery library version info
* @return array componentname, release, version
*/
public function get_re_jquery_ui_info() {
global $CFG;
$files = glob($CFG->dirroot.'/local/elisprogram/js/results_engine/jquery-ui-*');
return $this->get_jquery_file_info($files, array('name' => 'jquery-ui'));
}
/**
* get_ds_jquery_info method to get jQuery library version info
* @return array componentname, release, version
*/
public function get_ds_jquery_info() {
global $CFG;
$files = glob($CFG->dirroot.'/local/elisprogram/lib/deepsight/js/jquery-*');
return $this->get_jquery_file_info($files, array('name' => 'jquery'));
}
/**
* get_ds_jquery_ui_info method to get jQuery library version info
* @return array componentname, release, version
*/
public function get_ds_jquery_ui_info() {
global $CFG;
$files = glob($CFG->dirroot.'/local/elisprogram/lib/deepsight/js/jquery-ui-*');
return $this->get_jquery_file_info($files, array('name' => 'jquery-ui'));
}
/**
* elis_versions method to get all ELIS PM and component version info
* @return string
*/
protected function elis_versions() {
global $CFG;
$ret = html_writer::script(
"function toggle_elis_component_versions() {
var compdiv;
if (compdiv = document.getElementById('eliscomponentversions')) {
if (compdiv.className.indexOf('accesshide') != -1) {
compdiv.className = '';
} else {
compdiv.className = 'accesshide';
}
}
}");
$ret .= html_writer::tag('p', get_string('elispmversion', 'local_elisprogram', elispm::$release).' '.
html_writer::empty_tag('input', array(
'type' => 'button',
'value' => get_string('alleliscomponents', 'local_elisprogram'),
'onclick' => 'toggle_elis_component_versions();'
)));
$eliscomponents = array(
'block_elisadmin' => null,
'block_courserequest' => null,
'block_enrolsurvey' => null,
'block_repository' => null,
'enrol_elis' => null,
'local_eliscore' => null,
'local_elisprogram' => null,
'local_elisreports' => null,
'local_datahub' => null,
'auth_elisfilessso' => null,
'repository_elisfiles' => null,
'lib_tcpdf' => array($this, 'get_tcpdf_info'),
'lib_pChart' => array($this, 'get_pchart_info'),
'lib_jquery1' => array($this, 'get_re_jquery_info'),
'lib_jquery_ui1' => array($this, 'get_re_jquery_ui_info'),
'lib_jquery2' => array($this, 'get_ds_jquery_info'),
'lib_jquery_ui2' => array($this, 'get_ds_jquery_ui_info')
);
$componenttable = new html_table();
$componenttable->attributes = array('width' => '70%', 'border' => '0');
$componenttable->head = array(get_string('eliscomponent', 'local_elisprogram'),
get_string('eliscomponentrelease', 'local_elisprogram'),
get_string('eliscomponentversion', 'local_elisprogram'));
$componenttable->data = array();
foreach ($eliscomponents as $eliscomponent => $getinfocallback) {
list($plugintype, $pluginname) = explode('_', $eliscomponent);
if (!empty($getinfocallback)) {
list($componentname, $release, $version) = call_user_func($getinfocallback);
// error_log("elis_versions(): {$componentname}, {$release}, {$version}");
if (!empty($componentname)) {
$thirdpartylib = get_string('thirdpartylib', 'local_elisprogram');
$componenttable->data[] = array("$componentname $thirdpartylib",
$release, $version);
}
} else if (($compdir = core_component::get_plugin_directory($plugintype, $pluginname)) && file_exists($compdir.'/version.php')) {
$plugin = new stdClass;
require($compdir.'/version.php');
if (!empty($plugin->version)) {
$version = $plugin->version;
$release = !empty($plugin->release) ? $plugin->release : '';
$componenttable->data[] = array($eliscomponent, $release, $version);
}
}
}
$ret .= html_writer::tag('div', html_writer::table($componenttable), array(
'id' => 'eliscomponentversions',
'class' => 'accesshide'));
return $ret;
}
function display_default() {
global $CFG, $USER, $OUTPUT;
$context = context_system::instance();
if (has_capability('local/elisprogram:manage', $context) || has_capability('local/elisprogram:config', $context)) {
echo $OUTPUT->heading(get_string('admin_dashboard', 'local_elisprogram'));
echo $OUTPUT->box(html_writer::tag('p', get_string('elis_doc_class_link', 'local_elisprogram')));
echo $OUTPUT->box(html_writer::tag('p', $this->last_cron_runtimes()));
$healthpg = new healthpage();
if ($healthpg->can_do_default()) {
echo $OUTPUT->box(html_writer::tag('p', get_string('health_check_link', 'local_elisprogram', $CFG)));
}
// Output ELIS version info
echo $OUTPUT->box($this->elis_versions());
}
if ($cmuid = cm_get_crlmuserid($USER->id)) {
$user = new user($cmuid);
echo $user->get_dashboard();
}
}
}