Merge branch 'MDL-27818_22' of git://github.com/timhunt/moodle into MOODLE_22_STABLE
[moodle.git] / admin / renderer.php
blob93b22c663689e21d8131489fb37b6294ece345df
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.
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/>.
17 /**
18 * Renderer for core_admin subsystem
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
26 defined('MOODLE_INTERNAL') || die();
28 require_once($CFG->libdir . '/pluginlib.php');
30 /**
31 * Standard HTML output renderer for core_admin subsystem
33 class core_admin_renderer extends plugin_renderer_base {
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.
40 public function install_licence_page() {
41 global $CFG;
42 $output = '';
44 $copyrightnotice = text_to_html(get_string('gpl3'));
45 $copyrightnotice = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $copyrightnotice); // extremely ugly validation hack
47 $continue = new single_button(new moodle_url('/admin/index.php', array('lang'=>$CFG->lang, 'agreelicense'=>1)), get_string('continue'), 'get');
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();
57 return $output;
60 /**
61 * Display the 'environment check' page that is displayed during install.
62 * @param int $maturity
63 * @param boolean $envstatus final result of the check (true/false)
64 * @param array $environment_results array of results gathered
65 * @param string $release moodle release
66 * @return string HTML to output.
68 public function install_environment_page($maturity, $envstatus, $environment_results, $release) {
69 global $CFG;
70 $output = '';
72 $output .= $this->header();
73 $output .= $this->maturity_warning($maturity);
74 $output .= $this->heading("Moodle $release");
75 $output .= $this->release_notes_link();
77 $output .= $this->environment_check_table($envstatus, $environment_results);
79 if (!$envstatus) {
80 $output .= $this->upgrade_reload(new moodle_url('/admin/index.php', array('agreelicense' => 1, 'lang' => $CFG->lang)));
81 } else {
82 $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
83 $output .= $this->continue_button(new moodle_url('/admin/index.php', array('agreelicense'=>1, 'confirmrelease'=>1, 'lang'=>$CFG->lang)));
86 $output .= $this->footer();
87 return $output;
90 /**
91 * Display the 'You are about to upgrade Moodle' page. The first page
92 * during upgrade.
93 * @param string $strnewversion
94 * @param int $maturity
95 * @return string HTML to output.
97 public function upgrade_confirm_page($strnewversion, $maturity) {
98 $output = '';
100 $continueurl = new moodle_url('index.php', array('confirmupgrade' => 1));
101 $cancelurl = new moodle_url('index.php');
103 $output .= $this->header();
104 $output .= $this->maturity_warning($maturity);
105 $output .= $this->confirm(get_string('upgradesure', 'admin', $strnewversion), $continueurl, $cancelurl);
106 $output .= $this->footer();
108 return $output;
112 * Display the environment page during the upgrade process.
113 * @param string $release
114 * @param boolean $envstatus final result of env check (true/false)
115 * @param array $environment_results array of results gathered
116 * @return string HTML to output.
118 public function upgrade_environment_page($release, $envstatus, $environment_results) {
119 global $CFG;
120 $output = '';
122 $output .= $this->header();
123 $output .= $this->heading("Moodle $release");
124 $output .= $this->release_notes_link();
125 $output .= $this->environment_check_table($envstatus, $environment_results);
127 if (!$envstatus) {
128 $output .= $this->upgrade_reload(new moodle_url('/admin/index.php'), array('confirmupgrade' => 1));
130 } else {
131 $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
133 if (empty($CFG->skiplangupgrade) and current_language() !== 'en') {
134 $output .= $this->box(get_string('langpackwillbeupdated', 'admin'), 'generalbox', 'notice');
137 $output .= $this->continue_button(new moodle_url('/admin/index.php', array('confirmupgrade' => 1, 'confirmrelease' => 1)));
140 $output .= $this->footer();
142 return $output;
146 * Display the upgrade page that lists all the plugins that require attention.
147 * @param plugin_manager $pluginman provides information about the plugins.
148 * @param int $version the version of the Moodle code from version.php.
149 * @param bool $showallplugins
150 * @param moodle_url $reloadurl
151 * @param moodle_url $continueurl
152 * @return string HTML to output.
154 public function upgrade_plugin_check_page(plugin_manager $pluginman, $version, $showallplugins, $reloadurl, $continueurl) {
155 $output = '';
157 $output .= $this->header();
158 $output .= $this->box_start('generalbox');
159 $output .= $this->container(get_string('pluginchecknotice', 'core_plugin'), 'generalbox', 'notice');
160 $output .= $this->plugins_check_table($pluginman, $version, array('full' => $showallplugins));
161 $output .= $this->box_end();
162 $output .= $this->upgrade_reload($reloadurl);
164 if ($pluginman->all_plugins_ok($version)) {
165 $button = new single_button($continueurl, get_string('upgradestart', 'admin'), 'get');
166 $button->class = 'continuebutton';
167 $output .= $this->render($button);
168 } else {
169 $output .= $this->box(get_string('pluginschecktodo', 'admin'), 'environmentbox errorbox');
172 $output .= $this->footer();
174 return $output;
178 * Display the admin notifications page.
179 * @param int $maturity
180 * @param bool $insecuredataroot warn dataroot is invalid
181 * @param bool $errorsdisplayed warn invalid dispaly error setting
182 * @param bool $cronoverdue warn cron not running
183 * @param bool $dbproblems warn db has problems
184 * @param bool $maintenancemode warn in maintenance mode
185 * @return string HTML to output.
187 public function admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed,
188 $cronoverdue, $dbproblems, $maintenancemode) {
189 $output = '';
191 $output .= $this->header();
192 $output .= $this->maturity_info($maturity);
193 $output .= $this->insecure_dataroot_warning($insecuredataroot);
194 $output .= $this->display_errors_warning($errorsdisplayed);
195 $output .= $this->cron_overdue_warning($cronoverdue);
196 $output .= $this->db_problems($dbproblems);
197 $output .= $this->maintenance_mode_warning($maintenancemode);
199 //////////////////////////////////////////////////////////////////////////////////////////////////
200 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
201 $output .= $this->moodle_copyright();
202 //////////////////////////////////////////////////////////////////////////////////////////////////
204 $output .= $this->footer();
206 return $output;
210 * Display the plugin management page (admin/plugins.php).
211 * @param plugin_manager $pluginman
212 * @return string HTML to output.
214 public function plugin_management_page(plugin_manager $pluginman) {
215 $output = '';
217 $output .= $this->header();
218 $output .= $this->heading(get_string('pluginsoverview', 'core_admin'));
219 $output .= $this->box_start('generalbox');
220 $output .= $this->plugins_control_panel($pluginman);
221 $output .= $this->box_end();
222 $output .= $this->footer();
224 return $output;
228 * Display the plugin management page (admin/environment.php).
229 * @param array $versions
230 * @param string $version
231 * @param boolean $envstatus final result of env check (true/false)
232 * @param array $environment_results array of results gathered
233 * @return string HTML to output.
235 public function environment_check_page($versions, $version, $envstatus, $environment_results) {
236 $output = '';
237 $output .= $this->header();
239 // Print the component download link
240 $output .= html_writer::tag('div', html_writer::link(
241 new moodle_url('/admin/environment.php', array('action' => 'updatecomponent', 'sesskey' => sesskey())),
242 get_string('updatecomponent', 'admin')),
243 array('class' => 'reportlink'));
245 // Heading.
246 $output .= $this->heading(get_string('environment', 'admin'));
248 // Box with info and a menu to choose the version.
249 $output .= $this->box_start();
250 $output .= html_writer::tag('div', get_string('adminhelpenvironment'));
251 $select = new single_select(new moodle_url('/admin/environment.php'), 'version', $versions, $version, null);
252 $select->label = get_string('moodleversion');
253 $output .= $this->render($select);
254 $output .= $this->box_end();
256 // The results
257 $output .= $this->environment_check_table($envstatus, $environment_results);
259 $output .= $this->footer();
260 return $output;
264 * Output a warning message, of the type that appears on the admin notifications page.
265 * @param string $message the message to display.
266 * @param string $type type class
267 * @return string HTML to output.
269 protected function warning($message, $type = 'warning') {
270 return $this->box($message, 'generalbox admin' . $type);
274 * Render an appropriate message if dataroot is insecure.
275 * @param bool $insecuredataroot
276 * @return string HTML to output.
278 protected function insecure_dataroot_warning($insecuredataroot) {
279 global $CFG;
281 if ($insecuredataroot == INSECURE_DATAROOT_WARNING) {
282 return $this->warning(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot));
284 } else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) {
285 return $this->warning(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'error');
287 } else {
288 return '';
293 * Render an appropriate message if dataroot is insecure.
294 * @param bool $errorsdisplayed
295 * @return string HTML to output.
297 protected function display_errors_warning($errorsdisplayed) {
298 if (!$errorsdisplayed) {
299 return '';
302 return $this->warning(get_string('displayerrorswarning', 'admin'));
306 * Render an appropriate message if cron has not been run recently.
307 * @param bool $cronoverdue
308 * @return string HTML to output.
310 public function cron_overdue_warning($cronoverdue) {
311 if (!$cronoverdue) {
312 return '';
315 return $this->warning(get_string('cronwarning', 'admin') . '&nbsp;' .
316 $this->help_icon('cron', 'admin'));
320 * Render an appropriate message if there are any problems with the DB set-up.
321 * @param bool $dbproblems
322 * @return string HTML to output.
324 public function db_problems($dbproblems) {
325 if (!$dbproblems) {
326 return '';
329 return $this->warning($dbproblems);
333 * Render an appropriate message if the site in in maintenance mode.
334 * @param bool $maintenancemode
335 * @return string HTML to output.
337 public function maintenance_mode_warning($maintenancemode) {
338 if (!$maintenancemode) {
339 return '';
342 $url = new moodle_url('/admin/settings.php', array('section' => 'maintenancemode'));
343 $url = $url->out(); // get_string() does not support objects in params
345 return $this->warning(get_string('sitemaintenancewarning2', 'admin', $url));
349 * Display a warning about installing development code if necesary.
350 * @param int $maturity
351 * @return string HTML to output.
353 protected function maturity_warning($maturity) {
354 if ($maturity == MATURITY_STABLE) {
355 return ''; // No worries.
358 $maturitylevel = get_string('maturity' . $maturity, 'admin');
359 return $this->box(
360 $this->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
361 $this->container($this->doc_link('admin/versions', get_string('morehelp'))),
362 'generalbox maturitywarning');
366 * Output the copyright notice.
367 * @return string HTML to output.
369 protected function moodle_copyright() {
370 global $CFG;
372 //////////////////////////////////////////////////////////////////////////////////////////////////
373 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
374 $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
375 '<a href="http://docs.moodle.org/dev/Releases" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
376 'Copyright &copy; 1999 onwards, Martin Dougiamas<br />'.
377 'and <a href="http://docs.moodle.org/dev/Credits">many other contributors</a>.<br />'.
378 '<a href="http://docs.moodle.org/dev/License">GNU Public License</a>';
379 //////////////////////////////////////////////////////////////////////////////////////////////////
381 return $this->box($copyrighttext, 'copyright');
385 * Display a warning about installing development code if necesary.
386 * @param int $maturity
387 * @return string HTML to output.
389 protected function maturity_info($maturity) {
390 if ($maturity == MATURITY_STABLE) {
391 return ''; // No worries.
394 $maturitylevel = get_string('maturity' . $maturity, 'admin');
395 return $this->box(
396 get_string('maturitycoreinfo', 'admin', $maturitylevel) . ' ' .
397 $this->doc_link('admin/versions', get_string('morehelp')),
398 'generalbox adminwarning maturityinfo');
402 * Display a link to the release notes.
403 * @return string HTML to output.
405 protected function release_notes_link() {
406 $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/dev/Releases');
407 $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
408 return $this->box($releasenoteslink, 'generalbox releasenoteslink');
412 * Display the reload link that appears on several upgrade/install pages.
413 * @return string HTML to output.
415 function upgrade_reload($url) {
416 return html_writer::empty_tag('br') .
417 html_writer::tag('div',
418 html_writer::link($url, $this->pix_icon('i/reload', '') .
419 get_string('reload'), array('title' => get_string('reload'))),
420 array('class' => 'continuebutton')) . html_writer::empty_tag('br');
424 * Displays all known plugins and information about their installation or upgrade
426 * This default implementation renders all plugins into one big table. The rendering
427 * options support:
428 * (bool)full = false: whether to display up-to-date plugins, too
430 * @param plugin_manager $pluginman provides information about the plugins.
431 * @param int $version the version of the Moodle code from version.php.
432 * @param array $options rendering options
433 * @return string HTML code
435 public function plugins_check_table(plugin_manager $pluginman, $version, array $options = null) {
436 $plugininfo = $pluginman->get_plugins();
438 if (empty($plugininfo)) {
439 return '';
442 if (empty($options)) {
443 $options = array(
444 'full' => false,
448 $table = new html_table();
449 $table->id = 'plugins-check';
450 $table->head = array(
451 get_string('displayname', 'core_plugin'),
452 get_string('rootdir', 'core_plugin'),
453 get_string('source', 'core_plugin'),
454 get_string('versiondb', 'core_plugin'),
455 get_string('versiondisk', 'core_plugin'),
456 get_string('requires', 'core_plugin'),
457 get_string('status', 'core_plugin'),
459 $table->colclasses = array(
460 'displayname', 'rootdir', 'source', 'versiondb', 'versiondisk', 'requires', 'status',
462 $table->data = array();
464 $numofhighlighted = array(); // number of highlighted rows per this subsection
466 foreach ($plugininfo as $type => $plugins) {
468 $header = new html_table_cell($pluginman->plugintype_name_plural($type));
469 $header->header = true;
470 $header->colspan = count($table->head);
471 $header = new html_table_row(array($header));
472 $header->attributes['class'] = 'plugintypeheader type-' . $type;
474 $numofhighlighted[$type] = 0;
476 if (empty($plugins) and $options['full']) {
477 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
478 $msg->colspan = count($table->head);
479 $row = new html_table_row(array($msg));
480 $row->attributes['class'] .= 'msg msg-noneinstalled';
481 $table->data[] = $header;
482 $table->data[] = $row;
483 continue;
486 $plugintyperows = array();
488 foreach ($plugins as $name => $plugin) {
489 $row = new html_table_row();
490 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
492 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) {
493 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
494 } else {
495 $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon'));
497 $displayname = $icon . ' ' . $plugin->displayname;
498 $displayname = new html_table_cell($displayname);
500 $rootdir = new html_table_cell($plugin->get_dir());
502 if ($isstandard = $plugin->is_standard()) {
503 $row->attributes['class'] .= ' standard';
504 $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
505 } else {
506 $row->attributes['class'] .= ' extension';
507 $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
510 $versiondb = new html_table_cell($plugin->versiondb);
511 $versiondisk = new html_table_cell($plugin->versiondisk);
513 $statuscode = $plugin->get_status();
514 $row->attributes['class'] .= ' status-' . $statuscode;
516 $status = new html_table_cell(get_string('status_' . $statuscode, 'core_plugin'));
518 $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version));
520 $statusisboring = in_array($statuscode, array(
521 plugin_manager::PLUGIN_STATUS_NODB, plugin_manager::PLUGIN_STATUS_UPTODATE));
522 $dependenciesok = $pluginman->are_dependencies_satisfied(
523 $plugin->get_other_required_plugins());
524 if ($isstandard and $statusisboring and $dependenciesok) {
525 if (empty($options['full'])) {
526 continue;
528 } else {
529 $numofhighlighted[$type]++;
532 $row->cells = array($displayname, $rootdir, $source,
533 $versiondb, $versiondisk, $requires, $status);
534 $plugintyperows[] = $row;
537 if (empty($numofhighlighted[$type]) and empty($options['full'])) {
538 continue;
541 $table->data[] = $header;
542 $table->data = array_merge($table->data, $plugintyperows);
545 $sumofhighlighted = array_sum($numofhighlighted);
547 if ($sumofhighlighted == 0) {
548 $out = $this->output->container_start('nonehighlighted', 'plugins-check-info');
549 $out .= $this->output->heading(get_string('nonehighlighted', 'core_plugin'));
550 if (empty($options['full'])) {
551 $out .= html_writer::link(new moodle_url('/admin/index.php',
552 array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1)),
553 get_string('nonehighlightedinfo', 'core_plugin'));
555 $out .= $this->output->container_end();
557 } else {
558 $out = $this->output->container_start('somehighlighted', 'plugins-check-info');
559 $out .= $this->output->heading(get_string('somehighlighted', 'core_plugin', $sumofhighlighted));
560 if (empty($options['full'])) {
561 $out .= html_writer::link(new moodle_url('/admin/index.php',
562 array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1)),
563 get_string('somehighlightedinfo', 'core_plugin'));
565 $out .= $this->output->container_end();
568 if ($sumofhighlighted > 0 or $options['full']) {
569 $out .= html_writer::table($table);
572 return $out;
576 * Formats the information that needs to go in the 'Requires' column.
577 * @param plugin_information $plugin the plugin we are rendering the row for.
578 * @param plugin_manager $pluginman provides data on all the plugins.
579 * @param string $version
580 * @return string HTML code
582 protected function required_column(plugin_information $plugin, plugin_manager $pluginman, $version) {
583 $requires = array();
585 if (!empty($plugin->versionrequires)) {
586 if ($plugin->versionrequires <= $version) {
587 $class = 'requires-ok';
588 } else {
589 $class = 'requires-failed';
591 $requires[] = html_writer::tag('li',
592 get_string('moodleversion', 'core_plugin', $plugin->versionrequires),
593 array('class' => $class));
596 foreach ($plugin->get_other_required_plugins() as $component => $requiredversion) {
597 $ok = true;
598 $otherplugin = $pluginman->get_plugin_info($component);
600 if (is_null($otherplugin)) {
601 $ok = false;
602 } else if ($requiredversion != ANY_VERSION and $otherplugin->versiondisk < $requiredversion) {
603 $ok = false;
606 if ($ok) {
607 $class = 'requires-ok';
608 } else {
609 $class = 'requires-failed';
612 if ($requiredversion != ANY_VERSION) {
613 $str = 'otherpluginversion';
614 } else {
615 $str = 'otherplugin';
617 $requires[] = html_writer::tag('li',
618 get_string($str, 'core_plugin',
619 array('component' => $component, 'version' => $requiredversion)),
620 array('class' => $class));
623 if (!$requires) {
624 return '';
626 return html_writer::tag('ul', implode("\n", $requires));
630 * Displays all known plugins and links to manage them
632 * This default implementation renders all plugins into one big table.
634 * @param plugin_manager $pluginman provides information about the plugins.
635 * @return string HTML code
637 public function plugins_control_panel(plugin_manager $pluginman) {
638 $plugininfo = $pluginman->get_plugins();
640 if (empty($plugininfo)) {
641 return '';
644 $table = new html_table();
645 $table->id = 'plugins-control-panel';
646 $table->head = array(
647 get_string('displayname', 'core_plugin'),
648 get_string('systemname', 'core_plugin'),
649 get_string('source', 'core_plugin'),
650 get_string('version', 'core_plugin'),
651 get_string('availability', 'core_plugin'),
652 get_string('settings', 'core_plugin'),
653 get_string('uninstall','core_plugin'),
655 $table->colclasses = array(
656 'displayname', 'systemname', 'source', 'version', 'availability', 'settings', 'uninstall',
659 foreach ($plugininfo as $type => $plugins) {
661 $header = new html_table_cell($pluginman->plugintype_name_plural($type));
662 $header->header = true;
663 $header->colspan = count($table->head);
664 $header = new html_table_row(array($header));
665 $header->attributes['class'] = 'plugintypeheader type-' . $type;
666 $table->data[] = $header;
668 if (empty($plugins)) {
669 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
670 $msg->colspan = count($table->head);
671 $row = new html_table_row(array($msg));
672 $row->attributes['class'] .= 'msg msg-noneinstalled';
673 $table->data[] = $row;
674 continue;
677 foreach ($plugins as $name => $plugin) {
678 $row = new html_table_row();
679 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
681 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) {
682 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
683 } else {
684 $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon'));
686 if ($plugin->get_status() === plugin_manager::PLUGIN_STATUS_MISSING) {
687 $msg = html_writer::tag('span', get_string('status_missing', 'core_plugin'), array('class' => 'notifyproblem'));
688 $row->attributes['class'] .= ' missingfromdisk';
689 } else {
690 $msg = '';
692 $displayname = $icon . ' ' . $plugin->displayname . ' ' . $msg;
693 $displayname = new html_table_cell($displayname);
695 $systemname = new html_table_cell($plugin->type . '_' . $plugin->name);
697 if ($plugin->is_standard()) {
698 $row->attributes['class'] .= ' standard';
699 $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
700 } else {
701 $row->attributes['class'] .= ' extension';
702 $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
705 $version = new html_table_cell($plugin->versiondb);
707 $isenabled = $plugin->is_enabled();
708 if (is_null($isenabled)) {
709 $availability = new html_table_cell('');
710 } else if ($isenabled) {
711 $row->attributes['class'] .= ' enabled';
712 $icon = $this->output->pix_icon('i/hide', get_string('pluginenabled', 'core_plugin'));
713 $availability = new html_table_cell($icon . ' ' . get_string('pluginenabled', 'core_plugin'));
714 } else {
715 $row->attributes['class'] .= ' disabled';
716 $icon = $this->output->pix_icon('i/show', get_string('plugindisabled', 'core_plugin'));
717 $availability = new html_table_cell($icon . ' ' . get_string('plugindisabled', 'core_plugin'));
720 $settingsurl = $plugin->get_settings_url();
721 if (is_null($settingsurl)) {
722 $settings = new html_table_cell('');
723 } else {
724 $settings = html_writer::link($settingsurl, get_string('settings', 'core_plugin'));
725 $settings = new html_table_cell($settings);
728 $uninstallurl = $plugin->get_uninstall_url();
729 $requriedby = $pluginman->other_plugins_that_require($plugin->component);
730 if (is_null($uninstallurl)) {
731 $uninstall = new html_table_cell('');
732 } else if ($requriedby) {
733 $uninstall = new html_table_cell(get_string('requiredby', 'core_plugin', implode(', ', $requriedby)));
734 $uninstall->attributes['class'] = 'requiredby';
735 } else {
736 $uninstall = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin'));
737 $uninstall = new html_table_cell($uninstall);
740 $row->cells = array(
741 $displayname, $systemname, $source, $version, $availability, $settings, $uninstall
743 $table->data[] = $row;
747 return html_writer::table($table);
751 * This function will render one beautiful table with all the environmental
752 * configuration and how it suits Moodle needs.
754 * @param boolean $result final result of the check (true/false)
755 * @param array $environment_results array of results gathered
756 * @return string HTML to output.
758 public function environment_check_table($result, $environment_results) {
759 global $CFG;
761 // Table headers
762 $servertable = new html_table();//table for server checks
763 $servertable->head = array(
764 get_string('name'),
765 get_string('info'),
766 get_string('report'),
767 get_string('status'),
769 $servertable->align = array('center', 'center', 'left', 'center');
770 $servertable->wrap = array('nowrap', '', '', 'nowrap');
771 $servertable->size = array('10', 10, '100%', '10');
772 $servertable->attributes['class'] = 'environmenttable generaltable';
774 $serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
776 $othertable = new html_table();//table for custom checks
777 $othertable->head = array(
778 get_string('info'),
779 get_string('report'),
780 get_string('status'),
782 $othertable->align = array('center', 'left', 'center');
783 $othertable->wrap = array('', '', 'nowrap');
784 $othertable->size = array(10, '100%', '10');
785 $othertable->attributes['class'] = 'environmenttable generaltable';
787 $otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
789 // Iterate over each environment_result
790 $continue = true;
791 foreach ($environment_results as $environment_result) {
792 $errorline = false;
793 $warningline = false;
794 $stringtouse = '';
795 if ($continue) {
796 $type = $environment_result->getPart();
797 $info = $environment_result->getInfo();
798 $status = $environment_result->getStatus();
799 $error_code = $environment_result->getErrorCode();
800 // Process Report field
801 $rec = new stdClass();
802 // Something has gone wrong at parsing time
803 if ($error_code) {
804 $stringtouse = 'environmentxmlerror';
805 $rec->error_code = $error_code;
806 $status = get_string('error');
807 $errorline = true;
808 $continue = false;
811 if ($continue) {
812 if ($rec->needed = $environment_result->getNeededVersion()) {
813 // We are comparing versions
814 $rec->current = $environment_result->getCurrentVersion();
815 if ($environment_result->getLevel() == 'required') {
816 $stringtouse = 'environmentrequireversion';
817 } else {
818 $stringtouse = 'environmentrecommendversion';
821 } else if ($environment_result->getPart() == 'custom_check') {
822 // We are checking installed & enabled things
823 if ($environment_result->getLevel() == 'required') {
824 $stringtouse = 'environmentrequirecustomcheck';
825 } else {
826 $stringtouse = 'environmentrecommendcustomcheck';
829 } else if ($environment_result->getPart() == 'php_setting') {
830 if ($status) {
831 $stringtouse = 'environmentsettingok';
832 } else if ($environment_result->getLevel() == 'required') {
833 $stringtouse = 'environmentmustfixsetting';
834 } else {
835 $stringtouse = 'environmentshouldfixsetting';
838 } else {
839 if ($environment_result->getLevel() == 'required') {
840 $stringtouse = 'environmentrequireinstall';
841 } else {
842 $stringtouse = 'environmentrecommendinstall';
846 // Calculate the status value
847 if ($environment_result->getBypassStr() != '') { //Handle bypassed result (warning)
848 $status = get_string('bypassed');
849 $warningline = true;
850 } else if ($environment_result->getRestrictStr() != '') { //Handle restricted result (error)
851 $status = get_string('restricted');
852 $errorline = true;
853 } else {
854 if ($status) { //Handle ok result (ok)
855 $status = get_string('ok');
856 } else {
857 if ($environment_result->getLevel() == 'optional') {//Handle check result (warning)
858 $status = get_string('check');
859 $warningline = true;
860 } else { //Handle error result (error)
861 $status = get_string('check');
862 $errorline = true;
868 // Build the text
869 $linkparts = array();
870 $linkparts[] = 'admin/environment';
871 $linkparts[] = $type;
872 if (!empty($info)){
873 $linkparts[] = $info;
875 if (empty($CFG->docroot)) {
876 $report = get_string($stringtouse, 'admin', $rec);
877 } else {
878 $report = $this->doc_link(join($linkparts, '/'), get_string($stringtouse, 'admin', $rec));
881 // Format error or warning line
882 if ($errorline || $warningline) {
883 $messagetype = $errorline? 'error':'warn';
884 } else {
885 $messagetype = 'ok';
887 $status = '<span class="'.$messagetype.'">'.$status.'</span>';
888 // Here we'll store all the feedback found
889 $feedbacktext = '';
890 // Append the feedback if there is some
891 $feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), $messagetype);
892 //Append the bypass if there is some
893 $feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'warn');
894 //Append the restrict if there is some
895 $feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'error');
897 $report .= $feedbacktext;
899 // Add the row to the table
900 if ($environment_result->getPart() == 'custom_check'){
901 $otherdata[$messagetype][] = array ($info, $report, $status);
902 } else {
903 $serverdata[$messagetype][] = array ($type, $info, $report, $status);
908 //put errors first in
909 $servertable->data = array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']);
910 $othertable->data = array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']);
912 // Print table
913 $output = '';
914 $output .= $this->heading(get_string('serverchecks', 'admin'));
915 $output .= html_writer::table($servertable);
916 if (count($othertable->data)){
917 $output .= $this->heading(get_string('customcheck', 'admin'));
918 $output .= html_writer::table($othertable);
921 // Finally, if any error has happened, print the summary box
922 if (!$result) {
923 $output .= $this->box(get_string('environmenterrortodo', 'admin'), 'environmentbox errorbox');
926 return $output;