2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
18 * Renderer for core_admin subsystem
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');
31 * Standard HTML output renderer for core_admin subsystem
33 class core_admin_renderer
extends plugin_renderer_base
{
36 * Display the 'Do you acknowledge the terms of the GPL' page. The first page
38 * @return string HTML to output.
40 public function install_licence_page() {
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();
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) {
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);
80 $output .= $this->upgrade_reload(new moodle_url('/admin/index.php', array('agreelicense' => 1, 'lang' => $CFG->lang
)));
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();
91 * Display the 'You are about to upgrade Moodle' page. The first page
93 * @param string $strnewversion
94 * @param int $maturity
95 * @return string HTML to output.
97 public function upgrade_confirm_page($strnewversion, $maturity) {
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();
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) {
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);
128 $output .= $this->upgrade_reload(new moodle_url('/admin/index.php'), array('confirmupgrade' => 1));
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();
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) {
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);
169 $output .= $this->box(get_string('pluginschecktodo', 'admin'), 'environmentbox errorbox');
172 $output .= $this->footer();
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) {
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();
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) {
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();
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) {
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'));
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();
257 $output .= $this->environment_check_table($envstatus, $environment_results);
259 $output .= $this->footer();
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) {
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');
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) {
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) {
315 return $this->warning(get_string('cronwarning', 'admin') . ' ' .
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) {
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) {
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');
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() {
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 © 1999 onwards, Martin Dougiamas<br />'.
377 'and <a href="http://moodle.org/dev">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');
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
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)) {
442 if (empty($options)) {
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;
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'));
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'));
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'])) {
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'])) {
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();
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);
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) {
585 if (!empty($plugin->versionrequires
)) {
586 if ($plugin->versionrequires
<= $version) {
587 $class = 'requires-ok';
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) {
598 $otherplugin = $pluginman->get_plugin_info($component);
600 if (is_null($otherplugin)) {
602 } else if ($requiredversion != ANY_VERSION
and $otherplugin->versiondisk
< $requiredversion) {
607 $class = 'requires-ok';
609 $class = 'requires-failed';
612 if ($requiredversion != ANY_VERSION
) {
613 $str = 'otherpluginversion';
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));
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)) {
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;
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'));
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';
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'));
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'));
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('');
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';
736 $uninstall = html_writer
::link($uninstallurl, get_string('uninstall', 'core_plugin'));
737 $uninstall = new html_table_cell($uninstall);
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) {
762 $servertable = new html_table();//table for server checks
763 $servertable->head
= array(
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(
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
791 foreach ($environment_results as $environment_result) {
793 $warningline = false;
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
804 $stringtouse = 'environmentxmlerror';
805 $rec->error_code
= $error_code;
806 $status = get_string('error');
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';
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';
826 $stringtouse = 'environmentrecommendcustomcheck';
829 } else if ($environment_result->getPart() == 'php_setting') {
831 $stringtouse = 'environmentsettingok';
832 } else if ($environment_result->getLevel() == 'required') {
833 $stringtouse = 'environmentmustfixsetting';
835 $stringtouse = 'environmentshouldfixsetting';
839 if ($environment_result->getLevel() == 'required') {
840 $stringtouse = 'environmentrequireinstall';
842 $stringtouse = 'environmentrecommendinstall';
846 // Calculate the status value
847 if ($environment_result->getBypassStr() != '') { //Handle bypassed result (warning)
848 $status = get_string('bypassed');
850 } else if ($environment_result->getRestrictStr() != '') { //Handle restricted result (error)
851 $status = get_string('restricted');
854 if ($status) { //Handle ok result (ok)
855 $status = get_string('ok');
857 if ($environment_result->getLevel() == 'optional') {//Handle check result (warning)
858 $status = get_string('check');
860 } else { //Handle error result (error)
861 $status = get_string('check');
869 $linkparts = array();
870 $linkparts[] = 'admin/environment';
871 $linkparts[] = $type;
873 $linkparts[] = $info;
875 if (empty($CFG->docroot
)) {
876 $report = get_string($stringtouse, 'admin', $rec);
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';
887 $status = '<span class="'.$messagetype.'">'.$status.'</span>';
888 // Here we'll store all the feedback found
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);
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']);
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
923 $output .= $this->box(get_string('environmenterrortodo', 'admin'), 'environmentbox errorbox');