Merge branch 'w02_MDL-30717_m23_usercreated' of git://github.com/skodak/moodle
[moodle.git] / admin / renderer.php
blobd823e0e7465446c6f065ec65d3d9432f11337100
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 return $this->warning(get_string('sitemaintenancewarning2', 'admin',
343 new moodle_url('/admin/settings.php', array('section' => 'maintenancemode'))));
347 * Display a warning about installing development code if necesary.
348 * @param int $maturity
349 * @return string HTML to output.
351 protected function maturity_warning($maturity) {
352 if ($maturity == MATURITY_STABLE) {
353 return ''; // No worries.
356 $maturitylevel = get_string('maturity' . $maturity, 'admin');
357 return $this->box(
358 $this->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
359 $this->container($this->doc_link('admin/versions', get_string('morehelp'))),
360 'generalbox maturitywarning');
364 * Output the copyright notice.
365 * @return string HTML to output.
367 protected function moodle_copyright() {
368 global $CFG;
370 //////////////////////////////////////////////////////////////////////////////////////////////////
371 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
372 $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
373 '<a href="http://docs.moodle.org/dev/Releases" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
374 'Copyright &copy; 1999 onwards, Martin Dougiamas<br />'.
375 'and <a href="http://docs.moodle.org/dev/Credits">many other contributors</a>.<br />'.
376 '<a href="http://docs.moodle.org/dev/License">GNU Public License</a>';
377 //////////////////////////////////////////////////////////////////////////////////////////////////
379 return $this->box($copyrighttext, 'copyright');
383 * Display a warning about installing development code if necesary.
384 * @param int $maturity
385 * @return string HTML to output.
387 protected function maturity_info($maturity) {
388 if ($maturity == MATURITY_STABLE) {
389 return ''; // No worries.
392 $maturitylevel = get_string('maturity' . $maturity, 'admin');
393 return $this->box(
394 get_string('maturitycoreinfo', 'admin', $maturitylevel) . ' ' .
395 $this->doc_link('admin/versions', get_string('morehelp')),
396 'generalbox adminwarning maturityinfo');
400 * Display a link to the release notes.
401 * @return string HTML to output.
403 protected function release_notes_link() {
404 $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/dev/Releases');
405 $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
406 return $this->box($releasenoteslink, 'generalbox releasenoteslink');
410 * Display the reload link that appears on several upgrade/install pages.
411 * @return string HTML to output.
413 function upgrade_reload($url) {
414 return html_writer::empty_tag('br') .
415 html_writer::tag('div',
416 html_writer::link($url, $this->pix_icon('i/reload', '') .
417 get_string('reload'), array('title' => get_string('reload'))),
418 array('class' => 'continuebutton')) . html_writer::empty_tag('br');
422 * Displays all known plugins and information about their installation or upgrade
424 * This default implementation renders all plugins into one big table. The rendering
425 * options support:
426 * (bool)full = false: whether to display up-to-date plugins, too
428 * @param plugin_manager $pluginman provides information about the plugins.
429 * @param int $version the version of the Moodle code from version.php.
430 * @param array $options rendering options
431 * @return string HTML code
433 public function plugins_check_table(plugin_manager $pluginman, $version, array $options = null) {
434 $plugininfo = $pluginman->get_plugins();
436 if (empty($plugininfo)) {
437 return '';
440 if (empty($options)) {
441 $options = array(
442 'full' => false,
446 $table = new html_table();
447 $table->id = 'plugins-check';
448 $table->head = array(
449 get_string('displayname', 'core_plugin'),
450 get_string('rootdir', 'core_plugin'),
451 get_string('source', 'core_plugin'),
452 get_string('versiondb', 'core_plugin'),
453 get_string('versiondisk', 'core_plugin'),
454 get_string('requires', 'core_plugin'),
455 get_string('status', 'core_plugin'),
457 $table->colclasses = array(
458 'displayname', 'rootdir', 'source', 'versiondb', 'versiondisk', 'requires', 'status',
460 $table->data = array();
462 $numofhighlighted = array(); // number of highlighted rows per this subsection
464 foreach ($plugininfo as $type => $plugins) {
466 $header = new html_table_cell($pluginman->plugintype_name_plural($type));
467 $header->header = true;
468 $header->colspan = count($table->head);
469 $header = new html_table_row(array($header));
470 $header->attributes['class'] = 'plugintypeheader type-' . $type;
472 $numofhighlighted[$type] = 0;
474 if (empty($plugins) and $options['full']) {
475 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
476 $msg->colspan = count($table->head);
477 $row = new html_table_row(array($msg));
478 $row->attributes['class'] .= 'msg msg-noneinstalled';
479 $table->data[] = $header;
480 $table->data[] = $row;
481 continue;
484 $plugintyperows = array();
486 foreach ($plugins as $name => $plugin) {
487 $row = new html_table_row();
488 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
490 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) {
491 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
492 } else {
493 $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon'));
495 $displayname = $icon . ' ' . $plugin->displayname;
496 $displayname = new html_table_cell($displayname);
498 $rootdir = new html_table_cell($plugin->get_dir());
500 if ($isstandard = $plugin->is_standard()) {
501 $row->attributes['class'] .= ' standard';
502 $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
503 } else {
504 $row->attributes['class'] .= ' extension';
505 $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
508 $versiondb = new html_table_cell($plugin->versiondb);
509 $versiondisk = new html_table_cell($plugin->versiondisk);
511 $statuscode = $plugin->get_status();
512 $row->attributes['class'] .= ' status-' . $statuscode;
514 $status = new html_table_cell(get_string('status_' . $statuscode, 'core_plugin'));
516 $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version));
518 $statusisboring = in_array($statuscode, array(
519 plugin_manager::PLUGIN_STATUS_NODB, plugin_manager::PLUGIN_STATUS_UPTODATE));
520 $dependenciesok = $pluginman->are_dependencies_satisfied(
521 $plugin->get_other_required_plugins());
522 if ($isstandard and $statusisboring and $dependenciesok) {
523 if (empty($options['full'])) {
524 continue;
526 } else {
527 $numofhighlighted[$type]++;
530 $row->cells = array($displayname, $rootdir, $source,
531 $versiondb, $versiondisk, $requires, $status);
532 $plugintyperows[] = $row;
535 if (empty($numofhighlighted[$type]) and empty($options['full'])) {
536 continue;
539 $table->data[] = $header;
540 $table->data = array_merge($table->data, $plugintyperows);
543 $sumofhighlighted = array_sum($numofhighlighted);
545 if ($sumofhighlighted == 0) {
546 $out = $this->output->container_start('nonehighlighted', 'plugins-check-info');
547 $out .= $this->output->heading(get_string('nonehighlighted', 'core_plugin'));
548 if (empty($options['full'])) {
549 $out .= html_writer::link(new moodle_url('/admin/index.php',
550 array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1)),
551 get_string('nonehighlightedinfo', 'core_plugin'));
553 $out .= $this->output->container_end();
555 } else {
556 $out = $this->output->container_start('somehighlighted', 'plugins-check-info');
557 $out .= $this->output->heading(get_string('somehighlighted', 'core_plugin', $sumofhighlighted));
558 if (empty($options['full'])) {
559 $out .= html_writer::link(new moodle_url('/admin/index.php',
560 array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1)),
561 get_string('somehighlightedinfo', 'core_plugin'));
563 $out .= $this->output->container_end();
566 if ($sumofhighlighted > 0 or $options['full']) {
567 $out .= html_writer::table($table);
570 return $out;
574 * Formats the information that needs to go in the 'Requires' column.
575 * @param plugin_information $plugin the plugin we are rendering the row for.
576 * @param plugin_manager $pluginman provides data on all the plugins.
577 * @param string $version
578 * @return string HTML code
580 protected function required_column(plugin_information $plugin, plugin_manager $pluginman, $version) {
581 $requires = array();
583 if (!empty($plugin->versionrequires)) {
584 if ($plugin->versionrequires <= $version) {
585 $class = 'requires-ok';
586 } else {
587 $class = 'requires-failed';
589 $requires[] = html_writer::tag('li',
590 get_string('moodleversion', 'core_plugin', $plugin->versionrequires),
591 array('class' => $class));
594 foreach ($plugin->get_other_required_plugins() as $component => $requiredversion) {
595 $ok = true;
596 $otherplugin = $pluginman->get_plugin_info($component);
598 if (is_null($otherplugin)) {
599 $ok = false;
601 if ($requiredversion != ANY_VERSION and $otherplugin->versiondisk < $requiredversion) {
602 $ok = false;
605 if ($ok) {
606 $class = 'requires-ok';
607 } else {
608 $class = 'requires-failed';
611 if ($requiredversion != ANY_VERSION) {
612 $str = 'otherpluginversion';
613 } else {
614 $str = 'otherplugin';
616 $requires[] = html_writer::tag('li',
617 get_string($str, 'core_plugin',
618 array('component' => $component, 'version' => $requiredversion)),
619 array('class' => $class));
622 if (!$requires) {
623 return '';
625 return html_writer::tag('ul', implode("\n", $requires));
629 * Displays all known plugins and links to manage them
631 * This default implementation renders all plugins into one big table.
633 * @param plugin_manager $pluginman provides information about the plugins.
634 * @return string HTML code
636 public function plugins_control_panel(plugin_manager $pluginman) {
637 $plugininfo = $pluginman->get_plugins();
639 if (empty($plugininfo)) {
640 return '';
643 $table = new html_table();
644 $table->id = 'plugins-control-panel';
645 $table->head = array(
646 get_string('displayname', 'core_plugin'),
647 get_string('systemname', 'core_plugin'),
648 get_string('source', 'core_plugin'),
649 get_string('version', 'core_plugin'),
650 get_string('availability', 'core_plugin'),
651 get_string('settings', 'core_plugin'),
652 get_string('uninstall','core_plugin'),
654 $table->colclasses = array(
655 'displayname', 'systemname', 'source', 'version', 'availability', 'settings', 'uninstall',
658 foreach ($plugininfo as $type => $plugins) {
660 $header = new html_table_cell($pluginman->plugintype_name_plural($type));
661 $header->header = true;
662 $header->colspan = count($table->head);
663 $header = new html_table_row(array($header));
664 $header->attributes['class'] = 'plugintypeheader type-' . $type;
665 $table->data[] = $header;
667 if (empty($plugins)) {
668 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
669 $msg->colspan = count($table->head);
670 $row = new html_table_row(array($msg));
671 $row->attributes['class'] .= 'msg msg-noneinstalled';
672 $table->data[] = $row;
673 continue;
676 foreach ($plugins as $name => $plugin) {
677 $row = new html_table_row();
678 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
680 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) {
681 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
682 } else {
683 $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon'));
685 if ($plugin->get_status() === plugin_manager::PLUGIN_STATUS_MISSING) {
686 $msg = html_writer::tag('span', get_string('status_missing', 'core_plugin'), array('class' => 'notifyproblem'));
687 $row->attributes['class'] .= ' missingfromdisk';
688 } else {
689 $msg = '';
691 $displayname = $icon . ' ' . $plugin->displayname . ' ' . $msg;
692 $displayname = new html_table_cell($displayname);
694 $systemname = new html_table_cell($plugin->type . '_' . $plugin->name);
696 if ($plugin->is_standard()) {
697 $row->attributes['class'] .= ' standard';
698 $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
699 } else {
700 $row->attributes['class'] .= ' extension';
701 $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
704 $version = new html_table_cell($plugin->versiondb);
706 $isenabled = $plugin->is_enabled();
707 if (is_null($isenabled)) {
708 $availability = new html_table_cell('');
709 } else if ($isenabled) {
710 $row->attributes['class'] .= ' enabled';
711 $icon = $this->output->pix_icon('i/hide', get_string('pluginenabled', 'core_plugin'));
712 $availability = new html_table_cell($icon . ' ' . get_string('pluginenabled', 'core_plugin'));
713 } else {
714 $row->attributes['class'] .= ' disabled';
715 $icon = $this->output->pix_icon('i/show', get_string('plugindisabled', 'core_plugin'));
716 $availability = new html_table_cell($icon . ' ' . get_string('plugindisabled', 'core_plugin'));
719 $settingsurl = $plugin->get_settings_url();
720 if (is_null($settingsurl)) {
721 $settings = new html_table_cell('');
722 } else {
723 $settings = html_writer::link($settingsurl, get_string('settings', 'core_plugin'));
724 $settings = new html_table_cell($settings);
727 $uninstallurl = $plugin->get_uninstall_url();
728 $requriedby = $pluginman->other_plugins_that_require($plugin->component);
729 if (is_null($uninstallurl)) {
730 $uninstall = new html_table_cell('');
731 } else if ($requriedby) {
732 $uninstall = new html_table_cell(get_string('requiredby', 'core_plugin', implode(', ', $requriedby)));
733 $uninstall->attributes['class'] = 'requiredby';
734 } else {
735 $uninstall = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin'));
736 $uninstall = new html_table_cell($uninstall);
739 $row->cells = array(
740 $displayname, $systemname, $source, $version, $availability, $settings, $uninstall
742 $table->data[] = $row;
746 return html_writer::table($table);
750 * This function will render one beautiful table with all the environmental
751 * configuration and how it suits Moodle needs.
753 * @param boolean $result final result of the check (true/false)
754 * @param array $environment_results array of results gathered
755 * @return string HTML to output.
757 public function environment_check_table($result, $environment_results) {
758 global $CFG;
760 // Table headers
761 $servertable = new html_table();//table for server checks
762 $servertable->head = array(
763 get_string('name'),
764 get_string('info'),
765 get_string('report'),
766 get_string('status'),
768 $servertable->align = array('center', 'center', 'left', 'center');
769 $servertable->wrap = array('nowrap', '', '', 'nowrap');
770 $servertable->size = array('10', 10, '100%', '10');
771 $servertable->attributes['class'] = 'environmenttable generaltable';
773 $serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
775 $othertable = new html_table();//table for custom checks
776 $othertable->head = array(
777 get_string('info'),
778 get_string('report'),
779 get_string('status'),
781 $othertable->align = array('center', 'left', 'center');
782 $othertable->wrap = array('', '', 'nowrap');
783 $othertable->size = array(10, '100%', '10');
784 $othertable->attributes['class'] = 'environmenttable generaltable';
786 $otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
788 // Iterate over each environment_result
789 $continue = true;
790 foreach ($environment_results as $environment_result) {
791 $errorline = false;
792 $warningline = false;
793 $stringtouse = '';
794 if ($continue) {
795 $type = $environment_result->getPart();
796 $info = $environment_result->getInfo();
797 $status = $environment_result->getStatus();
798 $error_code = $environment_result->getErrorCode();
799 // Process Report field
800 $rec = new stdClass();
801 // Something has gone wrong at parsing time
802 if ($error_code) {
803 $stringtouse = 'environmentxmlerror';
804 $rec->error_code = $error_code;
805 $status = get_string('error');
806 $errorline = true;
807 $continue = false;
810 if ($continue) {
811 if ($rec->needed = $environment_result->getNeededVersion()) {
812 // We are comparing versions
813 $rec->current = $environment_result->getCurrentVersion();
814 if ($environment_result->getLevel() == 'required') {
815 $stringtouse = 'environmentrequireversion';
816 } else {
817 $stringtouse = 'environmentrecommendversion';
820 } else if ($environment_result->getPart() == 'custom_check') {
821 // We are checking installed & enabled things
822 if ($environment_result->getLevel() == 'required') {
823 $stringtouse = 'environmentrequirecustomcheck';
824 } else {
825 $stringtouse = 'environmentrecommendcustomcheck';
828 } else if ($environment_result->getPart() == 'php_setting') {
829 if ($status) {
830 $stringtouse = 'environmentsettingok';
831 } else if ($environment_result->getLevel() == 'required') {
832 $stringtouse = 'environmentmustfixsetting';
833 } else {
834 $stringtouse = 'environmentshouldfixsetting';
837 } else {
838 if ($environment_result->getLevel() == 'required') {
839 $stringtouse = 'environmentrequireinstall';
840 } else {
841 $stringtouse = 'environmentrecommendinstall';
845 // Calculate the status value
846 if ($environment_result->getBypassStr() != '') { //Handle bypassed result (warning)
847 $status = get_string('bypassed');
848 $warningline = true;
849 } else if ($environment_result->getRestrictStr() != '') { //Handle restricted result (error)
850 $status = get_string('restricted');
851 $errorline = true;
852 } else {
853 if ($status) { //Handle ok result (ok)
854 $status = get_string('ok');
855 } else {
856 if ($environment_result->getLevel() == 'optional') {//Handle check result (warning)
857 $status = get_string('check');
858 $warningline = true;
859 } else { //Handle error result (error)
860 $status = get_string('check');
861 $errorline = true;
867 // Build the text
868 $linkparts = array();
869 $linkparts[] = 'admin/environment';
870 $linkparts[] = $type;
871 if (!empty($info)){
872 $linkparts[] = $info;
874 if (empty($CFG->docroot)) {
875 $report = get_string($stringtouse, 'admin', $rec);
876 } else {
877 $report = $this->doc_link(join($linkparts, '/'), get_string($stringtouse, 'admin', $rec));
880 // Format error or warning line
881 if ($errorline || $warningline) {
882 $messagetype = $errorline? 'error':'warn';
883 } else {
884 $messagetype = 'ok';
886 $status = '<span class="'.$messagetype.'">'.$status.'</span>';
887 // Here we'll store all the feedback found
888 $feedbacktext = '';
889 // Append the feedback if there is some
890 $feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), $messagetype);
891 //Append the bypass if there is some
892 $feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'warn');
893 //Append the restrict if there is some
894 $feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'error');
896 $report .= $feedbacktext;
898 // Add the row to the table
899 if ($environment_result->getPart() == 'custom_check'){
900 $otherdata[$messagetype][] = array ($info, $report, $status);
901 } else {
902 $serverdata[$messagetype][] = array ($type, $info, $report, $status);
907 //put errors first in
908 $servertable->data = array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']);
909 $othertable->data = array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']);
911 // Print table
912 $output = '';
913 $output .= $this->heading(get_string('serverchecks', 'admin'));
914 $output .= html_writer::table($servertable);
915 if (count($othertable->data)){
916 $output .= $this->heading(get_string('customcheck', 'admin'));
917 $output .= html_writer::table($othertable);
920 // Finally, if any error has happened, print the summary box
921 if (!$result) {
922 $output .= $this->box(get_string('environmenterrortodo', 'admin'), 'environmentbox errorbox');
925 return $output;