Commit | Line | Data |
---|---|---|
b9934a17 DM |
1 | <?php |
2 | // This file is part of Moodle - http://moodle.org/ | |
3 | // | |
4 | // Moodle is free software: you can redistribute it and/or modify | |
5 | // it under the terms of the GNU General Public License as published by | |
6 | // the Free Software Foundation, either version 3 of the License, or | |
7 | // (at your option) any later version. | |
8 | // | |
9 | // Moodle is distributed in the hope that it will be useful, | |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | // GNU General Public License for more details. | |
13 | // | |
14 | // You should have received a copy of the GNU General Public License | |
15 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
16 | ||
17 | /** | |
18 | * Renderer for core_admin subsystem | |
19 | * | |
20 | * @package core | |
21 | * @subpackage admin | |
22 | * @copyright 2011 David Mudrak <david@moodle.com> | |
23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
24 | */ | |
25 | ||
26 | defined('MOODLE_INTERNAL') || die(); | |
27 | ||
28 | require_once($CFG->libdir . '/pluginlib.php'); | |
29 | ||
30 | /** | |
31 | * Standard HTML output renderer for core_admin subsystem | |
32 | */ | |
33 | class core_admin_renderer extends plugin_renderer_base { | |
34 | ||
cc359566 TH |
35 | /** |
36 | * Display the 'Do you acknowledge the terms of the GPL' page. The first page | |
37 | * during install. | |
38 | * @return string HTML to output. | |
39 | */ | |
40 | public function install_licence_page() { | |
41 | global $CFG; | |
42 | $output = ''; | |
43 | ||
44 | $copyrightnotice = text_to_html(get_string('gpl3')); | |
45 | $copyrightnotice = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $copyrightnotice); // extremely ugly validation hack | |
46 | ||
47 | $continue = new single_button(new moodle_url('/admin/index.php', array('lang'=>$CFG->lang, 'agreelicense'=>1)), get_string('continue'), 'get'); | |
48 | ||
49 | $output .= $this->header(); | |
50 | $output .= $this->heading('<a href="http://moodle.org">Moodle</a> - Modular Object-Oriented Dynamic Learning Environment'); | |
51 | $output .= $this->heading(get_string('copyrightnotice')); | |
52 | $output .= $this->box($copyrightnotice, 'copyrightnotice'); | |
53 | $output .= html_writer::empty_tag('br'); | |
54 | $output .= $this->confirm(get_string('doyouagree'), $continue, "http://docs.moodle.org/dev/License"); | |
55 | $output .= $this->footer(); | |
56 | ||
57 | return $output; | |
58 | } | |
59 | ||
60 | /** | |
61 | * Display the 'environment check' page that is displayed during install. | |
62 | * @return string HTML to output. | |
63 | */ | |
64 | public function install_environment_page($maturity, $envstatus, $environment_results) { | |
65 | global $CFG; | |
66 | $output = ''; | |
67 | ||
68 | $output .= $this->header(); | |
69 | $output .= $this->maturity_warning($maturity); | |
70 | $output .= $this->heading("Moodle $release"); | |
71 | $output .= $this->release_notes_link(); | |
72 | ||
73 | $output .= $this->environment_check_table($envstatus, $environment_results); | |
74 | ||
75 | if (!$envstatus) { | |
76 | $output .= $this->upgrade_reload(new moodle_url('/admin/index.php', array('agreelicense' => 1, 'lang' => $CFG->lang))); | |
77 | } else { | |
78 | $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess'); | |
79 | $output .= $this->continue_button(new moodle_url('/admin/index.php', array('agreelicense'=>1, 'confirmrelease'=>1, 'lang'=>$CFG->lang))); | |
80 | } | |
81 | ||
82 | $output .= $this->footer(); | |
83 | return $output; | |
84 | } | |
85 | ||
86 | /** | |
87 | * Display the 'You are about to upgrade Moodle' page. The first page | |
88 | * during upgrade. | |
89 | * @return string HTML to output. | |
90 | */ | |
91 | public function upgrade_confirm_page($strnewversion, $maturity) { | |
92 | $output = ''; | |
93 | ||
94 | $continueurl = new moodle_url('index.php', array('confirmupgrade' => 1)); | |
95 | $cancelurl = new moodle_url('index.php'); | |
96 | ||
97 | $output .= $this->header(); | |
98 | $output .= $this->maturity_warning($maturity); | |
99 | $output .= $this->confirm(get_string('upgradesure', 'admin', $strnewversion), $continueurl, $cancelurl); | |
100 | $output .= $this->footer(); | |
101 | ||
102 | return $output; | |
103 | } | |
104 | ||
105 | /** | |
106 | * Display the environment page during the upgrade process. | |
107 | * @return string HTML to output. | |
108 | */ | |
109 | public function upgrade_environment_page($release, $envstatus, $environment_results) { | |
110 | global $CFG; | |
111 | $output = ''; | |
112 | ||
113 | $output .= $this->header(); | |
114 | $output .= $this->heading("Moodle $release"); | |
115 | $output .= $this->release_notes_link(); | |
116 | $output .= $this->environment_check_table($envstatus, $environment_results); | |
117 | ||
118 | if (!$envstatus) { | |
119 | $output .= $this->upgrade_reload(new moodle_url('/admin/index.php'), array('confirmupgrade' => 1)); | |
120 | ||
121 | } else { | |
faadd326 | 122 | $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess'); |
cc359566 TH |
123 | |
124 | if (empty($CFG->skiplangupgrade) and current_language() !== 'en') { | |
125 | $output .= $this->box(get_string('langpackwillbeupdated', 'admin'), 'generalbox', 'notice'); | |
126 | } | |
127 | ||
128 | $output .= $this->continue_button(new moodle_url('/admin/index.php', array('confirmupgrade' => 1, 'confirmrelease' => 1))); | |
129 | } | |
130 | ||
131 | $output .= $this->footer(); | |
132 | ||
133 | return $output; | |
134 | } | |
135 | ||
136 | /** | |
137 | * Display the upgrade page that lists all the plugins that require attention. | |
138 | * @return string HTML to output. | |
139 | */ | |
faadd326 | 140 | public function upgrade_plugin_check_page($pluginman, $version, $showallplugins, $reloadurl, $continueurl) { |
cc359566 TH |
141 | $output = ''; |
142 | ||
143 | $output .= $this->header(); | |
144 | $output .= $this->box_start('generalbox'); | |
145 | $output .= $this->container(get_string('pluginchecknotice', 'core_plugin'), 'generalbox', 'notice'); | |
faadd326 | 146 | $output .= $this->plugins_check_table($pluginman, $version, array('full' => $showallplugins)); |
cc359566 TH |
147 | $output .= $this->box_end(); |
148 | $output .= $this->upgrade_reload($reloadurl); | |
149 | ||
faadd326 TH |
150 | if ($pluginman->all_plugins_ok($version)) { |
151 | $button = new single_button($continueurl, get_string('upgradestart', 'admin'), 'get'); | |
152 | $button->class = 'continuebutton'; | |
153 | $output .= $this->render($button); | |
154 | } else { | |
155 | $output .= $this->box(get_string('pluginschecktodo', 'admin'), 'environmentbox errorbox'); | |
156 | } | |
cc359566 TH |
157 | |
158 | $output .= $this->footer(); | |
159 | ||
160 | return $output; | |
161 | } | |
162 | ||
163 | /** | |
164 | * Display the admin notifications page. | |
165 | * @return string HTML to output. | |
166 | */ | |
167 | public function admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed, | |
168 | $cronoverdue, $dbproblems, $maintenancemode) { | |
169 | $output = ''; | |
170 | ||
171 | $output .= $this->header(); | |
172 | $output .= $this->maturity_info($maturity); | |
173 | $output .= $this->insecure_dataroot_warning($insecuredataroot); | |
174 | $output .= $this->display_errors_warning($errorsdisplayed); | |
175 | $output .= $this->cron_overdue_warning($errorsdisplayed); | |
176 | $output .= $this->db_problems($dbproblems); | |
177 | $output .= $this->maintenance_mode_warning($maintenancemode); | |
178 | ||
179 | ////////////////////////////////////////////////////////////////////////////////////////////////// | |
180 | //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE /// | |
181 | $output .= $this->moodle_copyright(); | |
182 | ////////////////////////////////////////////////////////////////////////////////////////////////// | |
183 | ||
184 | $output .= $this->footer(); | |
185 | ||
186 | return $output; | |
187 | } | |
188 | ||
189 | /** | |
190 | * Display the plugin management page (admin/plugins.php). | |
191 | * @return string HTML to output. | |
192 | */ | |
193 | public function plugin_management_page($pluginman) { | |
194 | $output = ''; | |
195 | ||
196 | $output .= $this->header(); | |
197 | $output .= $this->heading(get_string('pluginsoverview', 'core_admin')); | |
198 | $output .= $this->box_start('generalbox'); | |
199 | $output .= $this->plugins_control_panel($pluginman); | |
200 | $output .= $this->box_end(); | |
201 | $output .= $this->footer(); | |
202 | ||
203 | return $output; | |
204 | } | |
205 | ||
206 | /** | |
207 | * Display the plugin management page (admin/environment.php). | |
208 | * @return string HTML to output. | |
209 | */ | |
210 | public function environment_check_page($versions, $version, $envstatus, $environment_results) { | |
211 | $output = ''; | |
212 | $output .= $this->header(); | |
213 | ||
214 | // Print the component download link | |
215 | $output .= html_writer::tag('div', html_writer::link( | |
216 | new moodle_url('/admin/environment.php', array('action' => 'updatecomponent', 'sesskey' => sesskey())), | |
217 | get_string('updatecomponent', 'admin')), | |
218 | array('class' => 'reportlink')); | |
219 | ||
220 | // Heading. | |
221 | $output .= $this->heading(get_string('environment', 'admin')); | |
222 | ||
223 | // Box with info and a menu to choose the version. | |
224 | $output .= $this->box_start(); | |
225 | $output .= html_writer::tag('div', get_string('adminhelpenvironment')); | |
226 | $select = new single_select(new moodle_url('/admin/environment.php'), 'version', $versions, $version, null); | |
227 | $select->label = get_string('moodleversion'); | |
228 | $output .= $this->render($select); | |
229 | $output .= $this->box_end(); | |
230 | ||
231 | // The results | |
232 | $output .= $this->environment_check_table($envstatus, $environment_results); | |
233 | ||
234 | $output .= $this->footer(); | |
235 | return $output; | |
236 | } | |
237 | ||
238 | /** | |
239 | * Output a warning message, of the type that appears on the admin notifications page. | |
240 | * @param string $message the message to display. | |
241 | * @return string HTML to output. | |
242 | */ | |
243 | protected function warning($message, $type = 'warning') { | |
244 | return $this->box($message, 'generalbox admin' . $type); | |
245 | } | |
246 | ||
247 | /** | |
248 | * Render an appropriate message if dataroot is insecure. | |
249 | * @return string HTML to output. | |
250 | */ | |
251 | protected function insecure_dataroot_warning($insecuredataroot) { | |
252 | global $CFG; | |
253 | ||
254 | if ($insecuredataroot == INSECURE_DATAROOT_WARNING) { | |
255 | return $this->warning(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot)); | |
256 | ||
257 | } else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) { | |
258 | return $this->warning(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'error'); | |
259 | ||
260 | } else { | |
261 | return ''; | |
262 | } | |
263 | } | |
264 | ||
265 | /** | |
266 | * Render an appropriate message if dataroot is insecure. | |
267 | * @return string HTML to output. | |
268 | */ | |
269 | protected function display_errors_warning($errorsdisplayed) { | |
270 | if (!$errorsdisplayed) { | |
271 | return ''; | |
272 | } | |
273 | ||
274 | return $this->warning(get_string('displayerrorswarning', 'admin')); | |
275 | } | |
276 | ||
277 | /** | |
278 | * Render an appropriate message if cron has not been run recently. | |
279 | * @return string HTML to output. | |
280 | */ | |
281 | public function cron_overdue_warning($cronoverdue) { | |
282 | if (!$cronoverdue) { | |
283 | return ''; | |
284 | } | |
285 | ||
286 | return $this->warning(get_string('cronwarning', 'admin') . ' ' . | |
287 | $this->help_icon('cron', 'admin')); | |
288 | } | |
289 | ||
290 | /** | |
291 | * Render an appropriate message if there are any problems with the DB set-up. | |
292 | * @return string HTML to output. | |
293 | */ | |
294 | public function db_problems($dbproblems) { | |
295 | if (!$dbproblems) { | |
296 | return ''; | |
297 | } | |
298 | ||
299 | return $this->warning($dbproblems); | |
300 | } | |
301 | ||
302 | /** | |
303 | * Render an appropriate message if the site in in maintenance mode. | |
304 | * @return string HTML to output. | |
305 | */ | |
306 | public function maintenance_mode_warning($maintenancemode) { | |
307 | if (!$maintenancemode) { | |
308 | return ''; | |
309 | } | |
310 | ||
311 | return $this->warning(get_string('sitemaintenancewarning2', 'admin', | |
312 | new moodle_url('/admin/settings.php', array('section' => 'maintenancemode')))); | |
313 | } | |
314 | ||
315 | /** | |
316 | * Display a warning about installing development code if necesary. | |
317 | * @return string HTML to output. | |
318 | */ | |
319 | protected function maturity_warning($maturity) { | |
320 | if ($maturity == MATURITY_STABLE) { | |
321 | return ''; // No worries. | |
322 | } | |
323 | ||
324 | $maturitylevel = get_string('maturity' . $maturity, 'admin'); | |
325 | return $this->box( | |
326 | $this->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) . | |
327 | $this->container($this->doc_link('admin/versions', get_string('morehelp'))), | |
328 | 'generalbox maturitywarning'); | |
329 | } | |
330 | ||
331 | /** | |
332 | * Output the copyright notice. | |
333 | * @return string HTML to output. | |
334 | */ | |
335 | protected function moodle_copyright() { | |
336 | global $CFG; | |
337 | ||
338 | ////////////////////////////////////////////////////////////////////////////////////////////////// | |
339 | //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE /// | |
340 | $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '. | |
341 | '<a href="http://docs.moodle.org/dev/Releases" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'. | |
342 | 'Copyright © 1999 onwards, Martin Dougiamas<br />'. | |
343 | 'and <a href="http://docs.moodle.org/dev/Credits">many other contributors</a>.<br />'. | |
344 | '<a href="http://docs.moodle.org/dev/License">GNU Public License</a>'; | |
345 | ////////////////////////////////////////////////////////////////////////////////////////////////// | |
346 | ||
347 | return $this->box($copyrighttext, 'copyright'); | |
348 | } | |
349 | ||
350 | /** | |
351 | * Display a warning about installing development code if necesary. | |
352 | * @param string HTML to output. | |
353 | */ | |
354 | protected function maturity_info($maturity) { | |
355 | if ($maturity == MATURITY_STABLE) { | |
356 | return ''; // No worries. | |
357 | } | |
358 | ||
359 | $maturitylevel = get_string('maturity' . $maturity, 'admin'); | |
360 | return $this->box( | |
361 | get_string('maturitycoreinfo', 'admin', $maturitylevel) . ' ' . | |
362 | $this->doc_link('admin/versions', get_string('morehelp')), | |
363 | 'generalbox adminwarning maturityinfo'); | |
364 | } | |
365 | ||
366 | /** | |
367 | * Display a link to the release notes. | |
368 | * @param string HTML to output. | |
369 | */ | |
370 | protected function release_notes_link() { | |
371 | $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/dev/Releases'); | |
372 | $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack | |
373 | return $this->box($releasenoteslink, 'generalbox releasenoteslink'); | |
374 | } | |
375 | ||
376 | /** | |
377 | * Display the reload link that appears on several upgrade/install pages. | |
378 | */ | |
379 | function upgrade_reload($url) { | |
380 | return html_writer::empty_tag('br') . | |
381 | html_writer::tag('div', | |
382 | html_writer::link($url, $this->pix_icon('i/reload', '') . | |
383 | get_string('reload'), array('title' => get_string('reload'))), | |
384 | array('class' => 'continuebutton')) . html_writer::empty_tag('br'); | |
385 | } | |
386 | ||
b9934a17 DM |
387 | /** |
388 | * Displays all known plugins and information about their installation or upgrade | |
389 | * | |
390 | * This default implementation renders all plugins into one big table. The rendering | |
391 | * options support: | |
392 | * (bool)full = false: whether to display up-to-date plugins, too | |
393 | * | |
36ca62ca | 394 | * @param plugin_manager $pluginman provides information about the plugins. |
faadd326 | 395 | * @param int $version the version of the Moodle code from version.php. |
b9934a17 DM |
396 | * @param array $options rendering options |
397 | * @return string HTML code | |
398 | */ | |
faadd326 | 399 | public function plugins_check_table(plugin_manager $pluginman, $version, array $options = null) { |
36ca62ca | 400 | $plugininfo = $pluginman->get_plugins(); |
b9934a17 DM |
401 | |
402 | if (empty($plugininfo)) { | |
403 | return ''; | |
404 | } | |
405 | ||
406 | if (empty($options)) { | |
407 | $options = array( | |
408 | 'full' => false, | |
409 | ); | |
410 | } | |
411 | ||
b9934a17 DM |
412 | $table = new html_table(); |
413 | $table->id = 'plugins-check'; | |
414 | $table->head = array( | |
415 | get_string('displayname', 'core_plugin'), | |
416 | get_string('rootdir', 'core_plugin'), | |
417 | get_string('source', 'core_plugin'), | |
418 | get_string('versiondb', 'core_plugin'), | |
419 | get_string('versiondisk', 'core_plugin'), | |
36ca62ca | 420 | get_string('requires', 'core_plugin'), |
b9934a17 DM |
421 | get_string('status', 'core_plugin'), |
422 | ); | |
423 | $table->colclasses = array( | |
36ca62ca | 424 | 'displayname', 'rootdir', 'source', 'versiondb', 'versiondisk', 'requires', 'status', |
b9934a17 DM |
425 | ); |
426 | $table->data = array(); | |
427 | ||
428 | $numofhighlighted = array(); // number of highlighted rows per this subsection | |
429 | ||
430 | foreach ($plugininfo as $type => $plugins) { | |
431 | ||
432 | $header = new html_table_cell($pluginman->plugintype_name_plural($type)); | |
433 | $header->header = true; | |
434 | $header->colspan = count($table->head); | |
435 | $header = new html_table_row(array($header)); | |
436 | $header->attributes['class'] = 'plugintypeheader type-' . $type; | |
437 | ||
438 | $numofhighlighted[$type] = 0; | |
439 | ||
440 | if (empty($plugins) and $options['full']) { | |
441 | $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin')); | |
442 | $msg->colspan = count($table->head); | |
443 | $row = new html_table_row(array($msg)); | |
444 | $row->attributes['class'] .= 'msg msg-noneinstalled'; | |
445 | $table->data[] = $header; | |
446 | $table->data[] = $row; | |
447 | continue; | |
448 | } | |
449 | ||
450 | $plugintyperows = array(); | |
451 | ||
452 | foreach ($plugins as $name => $plugin) { | |
453 | $row = new html_table_row(); | |
454 | $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name; | |
455 | ||
456 | if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) { | |
457 | $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon')); | |
458 | } else { | |
459 | $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon')); | |
460 | } | |
461 | $displayname = $icon . ' ' . $plugin->displayname; | |
462 | $displayname = new html_table_cell($displayname); | |
463 | ||
464 | $rootdir = new html_table_cell($plugin->get_dir()); | |
465 | ||
466 | if ($isstandard = $plugin->is_standard()) { | |
467 | $row->attributes['class'] .= ' standard'; | |
468 | $source = new html_table_cell(get_string('sourcestd', 'core_plugin')); | |
469 | } else { | |
470 | $row->attributes['class'] .= ' extension'; | |
471 | $source = new html_table_cell(get_string('sourceext', 'core_plugin')); | |
472 | } | |
473 | ||
474 | $versiondb = new html_table_cell($plugin->versiondb); | |
475 | $versiondisk = new html_table_cell($plugin->versiondisk); | |
476 | ||
477 | $statuscode = $plugin->get_status(); | |
478 | $row->attributes['class'] .= ' status-' . $statuscode; | |
479 | ||
480 | $status = new html_table_cell(get_string('status_' . $statuscode, 'core_plugin')); | |
481 | ||
faadd326 | 482 | $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version)); |
36ca62ca TH |
483 | |
484 | $statusisboring = in_array($statuscode, array( | |
485 | plugin_manager::PLUGIN_STATUS_NODB, plugin_manager::PLUGIN_STATUS_UPTODATE)); | |
777781d1 | 486 | $dependenciesok = $pluginman->are_dependencies_satisfied( |
36ca62ca | 487 | $plugin->get_other_required_plugins()); |
777781d1 | 488 | if ($isstandard and $statusisboring and $dependenciesok) { |
b9934a17 DM |
489 | if (empty($options['full'])) { |
490 | continue; | |
491 | } | |
492 | } else { | |
493 | $numofhighlighted[$type]++; | |
494 | } | |
495 | ||
36ca62ca TH |
496 | $row->cells = array($displayname, $rootdir, $source, |
497 | $versiondb, $versiondisk, $requires, $status); | |
b9934a17 DM |
498 | $plugintyperows[] = $row; |
499 | } | |
500 | ||
501 | if (empty($numofhighlighted[$type]) and empty($options['full'])) { | |
502 | continue; | |
503 | } | |
504 | ||
505 | $table->data[] = $header; | |
506 | $table->data = array_merge($table->data, $plugintyperows); | |
507 | } | |
508 | ||
509 | $sumofhighlighted = array_sum($numofhighlighted); | |
510 | ||
511 | if ($sumofhighlighted == 0) { | |
512 | $out = $this->output->container_start('nonehighlighted', 'plugins-check-info'); | |
513 | $out .= $this->output->heading(get_string('nonehighlighted', 'core_plugin')); | |
514 | if (empty($options['full'])) { | |
515 | $out .= html_writer::link(new moodle_url('/admin/index.php', | |
516 | array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1)), | |
517 | get_string('nonehighlightedinfo', 'core_plugin')); | |
518 | } | |
519 | $out .= $this->output->container_end(); | |
520 | ||
521 | } else { | |
522 | $out = $this->output->container_start('somehighlighted', 'plugins-check-info'); | |
523 | $out .= $this->output->heading(get_string('somehighlighted', 'core_plugin', $sumofhighlighted)); | |
524 | if (empty($options['full'])) { | |
525 | $out .= html_writer::link(new moodle_url('/admin/index.php', | |
526 | array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1)), | |
527 | get_string('somehighlightedinfo', 'core_plugin')); | |
528 | } | |
529 | $out .= $this->output->container_end(); | |
530 | } | |
531 | ||
532 | if ($sumofhighlighted > 0 or $options['full']) { | |
533 | $out .= html_writer::table($table); | |
534 | } | |
535 | ||
536 | return $out; | |
537 | } | |
538 | ||
36ca62ca TH |
539 | /** |
540 | * Formats the information that needs to go in the 'Requires' column. | |
541 | * @param plugin_information $plugin the plugin we are rendering the row for. | |
542 | * @param plugin_manager $pluginman provides data on all the plugins. | |
543 | */ | |
faadd326 | 544 | protected function required_column($plugin, $pluginman, $version) { |
36ca62ca TH |
545 | $requires = array(); |
546 | ||
547 | if (!empty($plugin->versionrequires)) { | |
faadd326 | 548 | if ($plugin->versionrequires <= $version) { |
36ca62ca TH |
549 | $class = 'requires-ok'; |
550 | } else { | |
551 | $class = 'requires-failed'; | |
552 | } | |
553 | $requires[] = html_writer::tag('li', | |
554 | get_string('moodleversion', 'core_plugin', $plugin->versionrequires), | |
555 | array('class' => $class)); | |
556 | } | |
557 | ||
558 | foreach ($plugin->get_other_required_plugins() as $component => $requiredversion) { | |
559 | $ok = true; | |
560 | $otherplugin = $pluginman->get_plugin_info($component); | |
561 | ||
562 | if (is_null($otherplugin)) { | |
563 | $ok = false; | |
564 | } | |
565 | if ($requiredversion != ANY_VERSION and $otherplugin->versiondb < $requiredversion) { | |
566 | $ok = false; | |
567 | } | |
568 | ||
569 | if ($ok) { | |
570 | $class = 'requires-ok'; | |
571 | } else { | |
572 | $class = 'requires-failed'; | |
573 | } | |
574 | ||
575 | if ($requiredversion != ANY_VERSION) { | |
576 | $str = 'otherpluginversion'; | |
577 | } else { | |
578 | $str = 'otherplugin'; | |
579 | } | |
580 | $requires[] = html_writer::tag('li', | |
581 | get_string($str, 'core_plugin', | |
582 | array('component' => $component, 'version' => $requiredversion)), | |
583 | array('class' => $class)); | |
584 | } | |
585 | ||
586 | if (!$requires) { | |
587 | return ''; | |
588 | } | |
589 | return html_writer::tag('ul', implode("\n", $requires)); | |
590 | } | |
591 | ||
b9934a17 DM |
592 | /** |
593 | * Displays all known plugins and links to manage them | |
594 | * | |
595 | * This default implementation renders all plugins into one big table. | |
596 | * | |
36ca62ca | 597 | * @param plugin_manager $pluginman provides information about the plugins. |
b9934a17 DM |
598 | * @return string HTML code |
599 | */ | |
36ca62ca TH |
600 | public function plugins_control_panel(plugin_manager $pluginman) { |
601 | $plugininfo = $pluginman->get_plugins(); | |
b9934a17 DM |
602 | |
603 | if (empty($plugininfo)) { | |
604 | return ''; | |
605 | } | |
606 | ||
b9934a17 DM |
607 | $table = new html_table(); |
608 | $table->id = 'plugins-control-panel'; | |
609 | $table->head = array( | |
610 | get_string('displayname', 'core_plugin'), | |
611 | get_string('systemname', 'core_plugin'), | |
612 | get_string('source', 'core_plugin'), | |
613 | get_string('version', 'core_plugin'), | |
614 | get_string('availability', 'core_plugin'), | |
615 | get_string('settings', 'core_plugin'), | |
616 | get_string('uninstall','core_plugin'), | |
617 | ); | |
618 | $table->colclasses = array( | |
619 | 'displayname', 'systemname', 'source', 'version', 'availability', 'settings', 'uninstall', | |
620 | ); | |
621 | ||
622 | foreach ($plugininfo as $type => $plugins) { | |
623 | ||
624 | $header = new html_table_cell($pluginman->plugintype_name_plural($type)); | |
625 | $header->header = true; | |
626 | $header->colspan = count($table->head); | |
627 | $header = new html_table_row(array($header)); | |
628 | $header->attributes['class'] = 'plugintypeheader type-' . $type; | |
629 | $table->data[] = $header; | |
630 | ||
631 | if (empty($plugins)) { | |
632 | $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin')); | |
633 | $msg->colspan = count($table->head); | |
634 | $row = new html_table_row(array($msg)); | |
635 | $row->attributes['class'] .= 'msg msg-noneinstalled'; | |
636 | $table->data[] = $row; | |
637 | continue; | |
638 | } | |
639 | ||
640 | foreach ($plugins as $name => $plugin) { | |
641 | $row = new html_table_row(); | |
642 | $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name; | |
643 | ||
644 | if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) { | |
645 | $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon')); | |
646 | } else { | |
647 | $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon')); | |
648 | } | |
649 | if ($plugin->get_status() === plugin_manager::PLUGIN_STATUS_MISSING) { | |
650 | $msg = html_writer::tag('span', get_string('status_missing', 'core_plugin'), array('class' => 'notifyproblem')); | |
651 | $row->attributes['class'] .= ' missingfromdisk'; | |
652 | } else { | |
653 | $msg = ''; | |
654 | } | |
655 | $displayname = $icon . ' ' . $plugin->displayname . ' ' . $msg; | |
656 | $displayname = new html_table_cell($displayname); | |
657 | ||
658 | $systemname = new html_table_cell($plugin->type . '_' . $plugin->name); | |
659 | ||
660 | if ($plugin->is_standard()) { | |
661 | $row->attributes['class'] .= ' standard'; | |
662 | $source = new html_table_cell(get_string('sourcestd', 'core_plugin')); | |
663 | } else { | |
664 | $row->attributes['class'] .= ' extension'; | |
665 | $source = new html_table_cell(get_string('sourceext', 'core_plugin')); | |
666 | } | |
667 | ||
668 | $version = new html_table_cell($plugin->versiondb); | |
669 | ||
670 | $isenabled = $plugin->is_enabled(); | |
671 | if (is_null($isenabled)) { | |
672 | $availability = new html_table_cell(''); | |
673 | } else if ($isenabled) { | |
674 | $row->attributes['class'] .= ' enabled'; | |
675 | $icon = $this->output->pix_icon('i/hide', get_string('pluginenabled', 'core_plugin')); | |
676 | $availability = new html_table_cell($icon . ' ' . get_string('pluginenabled', 'core_plugin')); | |
677 | } else { | |
678 | $row->attributes['class'] .= ' disabled'; | |
679 | $icon = $this->output->pix_icon('i/show', get_string('plugindisabled', 'core_plugin')); | |
680 | $availability = new html_table_cell($icon . ' ' . get_string('plugindisabled', 'core_plugin')); | |
681 | } | |
682 | ||
683 | $settingsurl = $plugin->get_settings_url(); | |
684 | if (is_null($settingsurl)) { | |
685 | $settings = new html_table_cell(''); | |
686 | } else { | |
687 | $settings = html_writer::link($settingsurl, get_string('settings', 'core_plugin')); | |
688 | $settings = new html_table_cell($settings); | |
689 | } | |
690 | ||
691 | $uninstallurl = $plugin->get_uninstall_url(); | |
692 | if (is_null($uninstallurl)) { | |
693 | $uninstall = new html_table_cell(''); | |
694 | } else { | |
695 | $uninstall = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin')); | |
696 | $uninstall = new html_table_cell($uninstall); | |
697 | } | |
698 | ||
699 | $row->cells = array( | |
700 | $displayname, $systemname, $source, $version, $availability, $settings, $uninstall | |
701 | ); | |
702 | $table->data[] = $row; | |
703 | } | |
704 | } | |
705 | ||
706 | return html_writer::table($table); | |
707 | } | |
da2fdc3f TH |
708 | |
709 | /** | |
cc359566 TH |
710 | * This function will render one beautiful table with all the environmental |
711 | * configuration and how it suits Moodle needs. | |
712 | * | |
713 | * @param boolean $result final result of the check (true/false) | |
714 | * @param array $environment_results array of results gathered | |
715 | * @return string HTML to output. | |
da2fdc3f | 716 | */ |
cc359566 TH |
717 | public function environment_check_table($result, $environment_results) { |
718 | global $CFG; | |
719 | ||
720 | // Table headers | |
721 | $servertable = new html_table();//table for server checks | |
722 | $servertable->head = array( | |
723 | get_string('name'), | |
724 | get_string('info'), | |
725 | get_string('report'), | |
726 | get_string('status'), | |
727 | ); | |
728 | $servertable->align = array('center', 'center', 'left', 'center'); | |
729 | $servertable->wrap = array('nowrap', '', '', 'nowrap'); | |
730 | $servertable->size = array('10', 10, '100%', '10'); | |
731 | $servertable->attributes['class'] = 'environmenttable generaltable'; | |
732 | ||
733 | $serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array()); | |
734 | ||
735 | $othertable = new html_table();//table for custom checks | |
736 | $othertable->head = array( | |
737 | get_string('info'), | |
738 | get_string('report'), | |
739 | get_string('status'), | |
740 | ); | |
741 | $othertable->align = array('center', 'left', 'center'); | |
742 | $othertable->wrap = array('', '', 'nowrap'); | |
743 | $othertable->size = array(10, '100%', '10'); | |
744 | $othertable->attributes['class'] = 'environmenttable generaltable'; | |
745 | ||
746 | $otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array()); | |
747 | ||
748 | // Iterate over each environment_result | |
749 | $continue = true; | |
750 | foreach ($environment_results as $environment_result) { | |
751 | $errorline = false; | |
752 | $warningline = false; | |
753 | $stringtouse = ''; | |
754 | if ($continue) { | |
755 | $type = $environment_result->getPart(); | |
756 | $info = $environment_result->getInfo(); | |
757 | $status = $environment_result->getStatus(); | |
758 | $error_code = $environment_result->getErrorCode(); | |
759 | // Process Report field | |
760 | $rec = new stdClass(); | |
761 | // Something has gone wrong at parsing time | |
762 | if ($error_code) { | |
763 | $stringtouse = 'environmentxmlerror'; | |
764 | $rec->error_code = $error_code; | |
765 | $status = get_string('error'); | |
766 | $errorline = true; | |
767 | $continue = false; | |
768 | } | |
769 | ||
770 | if ($continue) { | |
771 | if ($rec->needed = $environment_result->getNeededVersion()) { | |
772 | // We are comparing versions | |
773 | $rec->current = $environment_result->getCurrentVersion(); | |
774 | if ($environment_result->getLevel() == 'required') { | |
775 | $stringtouse = 'environmentrequireversion'; | |
776 | } else { | |
777 | $stringtouse = 'environmentrecommendversion'; | |
778 | } | |
779 | ||
780 | } else if ($environment_result->getPart() == 'custom_check') { | |
781 | // We are checking installed & enabled things | |
782 | if ($environment_result->getLevel() == 'required') { | |
783 | $stringtouse = 'environmentrequirecustomcheck'; | |
784 | } else { | |
785 | $stringtouse = 'environmentrecommendcustomcheck'; | |
786 | } | |
787 | ||
788 | } else if ($environment_result->getPart() == 'php_setting') { | |
789 | if ($status) { | |
790 | $stringtouse = 'environmentsettingok'; | |
791 | } else if ($environment_result->getLevel() == 'required') { | |
792 | $stringtouse = 'environmentmustfixsetting'; | |
793 | } else { | |
794 | $stringtouse = 'environmentshouldfixsetting'; | |
795 | } | |
796 | ||
797 | } else { | |
798 | if ($environment_result->getLevel() == 'required') { | |
799 | $stringtouse = 'environmentrequireinstall'; | |
800 | } else { | |
801 | $stringtouse = 'environmentrecommendinstall'; | |
802 | } | |
803 | } | |
804 | ||
805 | // Calculate the status value | |
806 | if ($environment_result->getBypassStr() != '') { //Handle bypassed result (warning) | |
807 | $status = get_string('bypassed'); | |
808 | $warningline = true; | |
809 | } else if ($environment_result->getRestrictStr() != '') { //Handle restricted result (error) | |
810 | $status = get_string('restricted'); | |
811 | $errorline = true; | |
812 | } else { | |
813 | if ($status) { //Handle ok result (ok) | |
814 | $status = get_string('ok'); | |
815 | } else { | |
816 | if ($environment_result->getLevel() == 'optional') {//Handle check result (warning) | |
817 | $status = get_string('check'); | |
818 | $warningline = true; | |
819 | } else { //Handle error result (error) | |
820 | $status = get_string('check'); | |
821 | $errorline = true; | |
822 | } | |
823 | } | |
824 | } | |
825 | } | |
826 | ||
827 | // Build the text | |
828 | $linkparts = array(); | |
829 | $linkparts[] = 'admin/environment'; | |
830 | $linkparts[] = $type; | |
831 | if (!empty($info)){ | |
832 | $linkparts[] = $info; | |
833 | } | |
834 | if (empty($CFG->docroot)) { | |
835 | $report = get_string($stringtouse, 'admin', $rec); | |
836 | } else { | |
837 | $report = $this->doc_link(join($linkparts, '/'), get_string($stringtouse, 'admin', $rec)); | |
838 | } | |
839 | ||
840 | // Format error or warning line | |
841 | if ($errorline || $warningline) { | |
842 | $messagetype = $errorline? 'error':'warn'; | |
843 | } else { | |
844 | $messagetype = 'ok'; | |
845 | } | |
846 | $status = '<span class="'.$messagetype.'">'.$status.'</span>'; | |
847 | // Here we'll store all the feedback found | |
848 | $feedbacktext = ''; | |
849 | // Append the feedback if there is some | |
850 | $feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), $messagetype); | |
851 | //Append the bypass if there is some | |
852 | $feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'warn'); | |
853 | //Append the restrict if there is some | |
854 | $feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'error'); | |
855 | ||
856 | $report .= $feedbacktext; | |
857 | ||
858 | // Add the row to the table | |
859 | if ($environment_result->getPart() == 'custom_check'){ | |
860 | $otherdata[$messagetype][] = array ($info, $report, $status); | |
861 | } else { | |
862 | $serverdata[$messagetype][] = array ($type, $info, $report, $status); | |
863 | } | |
864 | } | |
865 | } | |
866 | ||
867 | //put errors first in | |
868 | $servertable->data = array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']); | |
869 | $othertable->data = array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']); | |
870 | ||
871 | // Print table | |
872 | $output = ''; | |
873 | $output .= $this->heading(get_string('serverchecks', 'admin')); | |
874 | $output .= html_writer::table($servertable); | |
875 | if (count($othertable->data)){ | |
876 | $output .= $this->heading(get_string('customcheck', 'admin')); | |
877 | $output .= html_writer::table($othertable); | |
878 | } | |
879 | ||
880 | // Finally, if any error has happened, print the summary box | |
881 | if (!$result) { | |
882 | $output .= $this->box(get_string('environmenterrortodo', 'admin'), 'environmentbox errorbox'); | |
883 | } | |
884 | ||
885 | return $output; | |
da2fdc3f | 886 | } |
b9934a17 | 887 | } |