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 page explaining proper upgrade process,
62 * there can not be any PHP file leftovers...
64 * @return string HTML to output.
66 public function upgrade_stale_php_files_page() {
68 $output .= $this->header();
69 $output .= $this->heading(get_string('upgradestalefiles', 'admin'));
70 $output .= $this->box_start('generalbox', 'notice');
71 $output .= get_string('upgradestalefilesinfo', 'admin', get_docs_url('Upgrading'));
72 $output .= html_writer
::empty_tag('br');
73 $output .= html_writer
::tag('div', $this->single_button($this->page
->url
, get_string('reload'), 'get'), array('class' => 'buttons'));
74 $output .= $this->box_end();
75 $output .= $this->footer();
81 * Display the 'environment check' page that is displayed during install.
82 * @param int $maturity
83 * @param boolean $envstatus final result of the check (true/false)
84 * @param array $environment_results array of results gathered
85 * @param string $release moodle release
86 * @return string HTML to output.
88 public function install_environment_page($maturity, $envstatus, $environment_results, $release) {
92 $output .= $this->header();
93 $output .= $this->maturity_warning($maturity);
94 $output .= $this->heading("Moodle $release");
95 $output .= $this->release_notes_link();
97 $output .= $this->environment_check_table($envstatus, $environment_results);
100 $output .= $this->upgrade_reload(new moodle_url('/admin/index.php', array('agreelicense' => 1, 'lang' => $CFG->lang
)));
102 $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
103 $output .= $this->continue_button(new moodle_url('/admin/index.php', array('agreelicense'=>1, 'confirmrelease'=>1, 'lang'=>$CFG->lang
)));
106 $output .= $this->footer();
111 * Display the 'You are about to upgrade Moodle' page. The first page
113 * @param string $strnewversion
114 * @param int $maturity
115 * @return string HTML to output.
117 public function upgrade_confirm_page($strnewversion, $maturity) {
120 $continueurl = new moodle_url('index.php', array('confirmupgrade' => 1));
121 $cancelurl = new moodle_url('index.php');
123 $output .= $this->header();
124 $output .= $this->maturity_warning($maturity);
125 $output .= $this->confirm(get_string('upgradesure', 'admin', $strnewversion), $continueurl, $cancelurl);
126 $output .= $this->footer();
132 * Display the environment page during the upgrade process.
133 * @param string $release
134 * @param boolean $envstatus final result of env check (true/false)
135 * @param array $environment_results array of results gathered
136 * @return string HTML to output.
138 public function upgrade_environment_page($release, $envstatus, $environment_results) {
142 $output .= $this->header();
143 $output .= $this->heading("Moodle $release");
144 $output .= $this->release_notes_link();
145 $output .= $this->environment_check_table($envstatus, $environment_results);
148 $output .= $this->upgrade_reload(new moodle_url('/admin/index.php'), array('confirmupgrade' => 1));
151 $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
153 if (empty($CFG->skiplangupgrade
) and current_language() !== 'en') {
154 $output .= $this->box(get_string('langpackwillbeupdated', 'admin'), 'generalbox', 'notice');
157 $output .= $this->continue_button(new moodle_url('/admin/index.php', array('confirmupgrade' => 1, 'confirmrelease' => 1)));
160 $output .= $this->footer();
166 * Display the upgrade page that lists all the plugins that require attention.
167 * @param plugin_manager $pluginman provides information about the plugins.
168 * @param int $version the version of the Moodle code from version.php.
169 * @param bool $showallplugins
170 * @param moodle_url $reloadurl
171 * @param moodle_url $continueurl
172 * @return string HTML to output.
174 public function upgrade_plugin_check_page(plugin_manager
$pluginman, $version, $showallplugins, $reloadurl, $continueurl) {
177 $output .= $this->header();
178 $output .= $this->box_start('generalbox');
179 $output .= $this->container(get_string('pluginchecknotice', 'core_plugin'), 'generalbox', 'notice');
180 $output .= $this->plugins_check_table($pluginman, $version, array('full' => $showallplugins));
181 $output .= $this->box_end();
182 $output .= $this->upgrade_reload($reloadurl);
184 if ($pluginman->all_plugins_ok($version)) {
185 $button = new single_button($continueurl, get_string('upgradestart', 'admin'), 'get');
186 $button->class = 'continuebutton';
187 $output .= $this->render($button);
189 $output .= $this->box(get_string('pluginschecktodo', 'admin'), 'environmentbox errorbox');
192 $output .= $this->footer();
198 * Display the admin notifications page.
199 * @param int $maturity
200 * @param bool $insecuredataroot warn dataroot is invalid
201 * @param bool $errorsdisplayed warn invalid dispaly error setting
202 * @param bool $cronoverdue warn cron not running
203 * @param bool $dbproblems warn db has problems
204 * @param bool $maintenancemode warn in maintenance mode
205 * @return string HTML to output.
207 public function admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed,
208 $cronoverdue, $dbproblems, $maintenancemode) {
211 $output .= $this->header();
212 $output .= $this->maturity_info($maturity);
213 $output .= $this->insecure_dataroot_warning($insecuredataroot);
214 $output .= $this->display_errors_warning($errorsdisplayed);
215 $output .= $this->cron_overdue_warning($cronoverdue);
216 $output .= $this->db_problems($dbproblems);
217 $output .= $this->maintenance_mode_warning($maintenancemode);
219 //////////////////////////////////////////////////////////////////////////////////////////////////
220 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
221 $output .= $this->moodle_copyright();
222 //////////////////////////////////////////////////////////////////////////////////////////////////
224 $output .= $this->footer();
230 * Display the plugin management page (admin/plugins.php).
231 * @param plugin_manager $pluginman
232 * @return string HTML to output.
234 public function plugin_management_page(plugin_manager
$pluginman) {
237 $output .= $this->header();
238 $output .= $this->heading(get_string('pluginsoverview', 'core_admin'));
239 $output .= $this->box_start('generalbox');
240 $output .= $this->plugins_control_panel($pluginman);
241 $output .= $this->box_end();
242 $output .= $this->footer();
248 * Display the plugin management page (admin/environment.php).
249 * @param array $versions
250 * @param string $version
251 * @param boolean $envstatus final result of env check (true/false)
252 * @param array $environment_results array of results gathered
253 * @return string HTML to output.
255 public function environment_check_page($versions, $version, $envstatus, $environment_results) {
257 $output .= $this->header();
259 // Print the component download link
260 $output .= html_writer
::tag('div', html_writer
::link(
261 new moodle_url('/admin/environment.php', array('action' => 'updatecomponent', 'sesskey' => sesskey())),
262 get_string('updatecomponent', 'admin')),
263 array('class' => 'reportlink'));
266 $output .= $this->heading(get_string('environment', 'admin'));
268 // Box with info and a menu to choose the version.
269 $output .= $this->box_start();
270 $output .= html_writer
::tag('div', get_string('adminhelpenvironment'));
271 $select = new single_select(new moodle_url('/admin/environment.php'), 'version', $versions, $version, null);
272 $select->label
= get_string('moodleversion');
273 $output .= $this->render($select);
274 $output .= $this->box_end();
277 $output .= $this->environment_check_table($envstatus, $environment_results);
279 $output .= $this->footer();
284 * Output a warning message, of the type that appears on the admin notifications page.
285 * @param string $message the message to display.
286 * @param string $type type class
287 * @return string HTML to output.
289 protected function warning($message, $type = 'warning') {
290 return $this->box($message, 'generalbox admin' . $type);
294 * Render an appropriate message if dataroot is insecure.
295 * @param bool $insecuredataroot
296 * @return string HTML to output.
298 protected function insecure_dataroot_warning($insecuredataroot) {
301 if ($insecuredataroot == INSECURE_DATAROOT_WARNING
) {
302 return $this->warning(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot
));
304 } else if ($insecuredataroot == INSECURE_DATAROOT_ERROR
) {
305 return $this->warning(get_string('datarootsecurityerror', 'admin', $CFG->dataroot
), 'error');
313 * Render an appropriate message if dataroot is insecure.
314 * @param bool $errorsdisplayed
315 * @return string HTML to output.
317 protected function display_errors_warning($errorsdisplayed) {
318 if (!$errorsdisplayed) {
322 return $this->warning(get_string('displayerrorswarning', 'admin'));
326 * Render an appropriate message if cron has not been run recently.
327 * @param bool $cronoverdue
328 * @return string HTML to output.
330 public function cron_overdue_warning($cronoverdue) {
335 return $this->warning(get_string('cronwarning', 'admin') . ' ' .
336 $this->help_icon('cron', 'admin'));
340 * Render an appropriate message if there are any problems with the DB set-up.
341 * @param bool $dbproblems
342 * @return string HTML to output.
344 public function db_problems($dbproblems) {
349 return $this->warning($dbproblems);
353 * Render an appropriate message if the site in in maintenance mode.
354 * @param bool $maintenancemode
355 * @return string HTML to output.
357 public function maintenance_mode_warning($maintenancemode) {
358 if (!$maintenancemode) {
362 $url = new moodle_url('/admin/settings.php', array('section' => 'maintenancemode'));
363 $url = $url->out(); // get_string() does not support objects in params
365 return $this->warning(get_string('sitemaintenancewarning2', 'admin', $url));
369 * Display a warning about installing development code if necesary.
370 * @param int $maturity
371 * @return string HTML to output.
373 protected function maturity_warning($maturity) {
374 if ($maturity == MATURITY_STABLE
) {
375 return ''; // No worries.
378 $maturitylevel = get_string('maturity' . $maturity, 'admin');
380 $this->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
381 $this->container($this->doc_link('admin/versions', get_string('morehelp'))),
382 'generalbox maturitywarning');
386 * Output the copyright notice.
387 * @return string HTML to output.
389 protected function moodle_copyright() {
392 //////////////////////////////////////////////////////////////////////////////////////////////////
393 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
394 $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
395 '<a href="http://docs.moodle.org/dev/Releases" title="'.$CFG->version
.'">'.$CFG->release
.'</a><br />'.
396 'Copyright © 1999 onwards, Martin Dougiamas<br />'.
397 'and <a href="http://docs.moodle.org/dev/Credits">many other contributors</a>.<br />'.
398 '<a href="http://docs.moodle.org/dev/License">GNU Public License</a>';
399 //////////////////////////////////////////////////////////////////////////////////////////////////
401 return $this->box($copyrighttext, 'copyright');
405 * Display a warning about installing development code if necesary.
406 * @param int $maturity
407 * @return string HTML to output.
409 protected function maturity_info($maturity) {
410 if ($maturity == MATURITY_STABLE
) {
411 return ''; // No worries.
414 $maturitylevel = get_string('maturity' . $maturity, 'admin');
416 get_string('maturitycoreinfo', 'admin', $maturitylevel) . ' ' .
417 $this->doc_link('admin/versions', get_string('morehelp')),
418 'generalbox adminwarning maturityinfo');
422 * Display a link to the release notes.
423 * @return string HTML to output.
425 protected function release_notes_link() {
426 $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/dev/Releases');
427 $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
428 return $this->box($releasenoteslink, 'generalbox releasenoteslink');
432 * Display the reload link that appears on several upgrade/install pages.
433 * @return string HTML to output.
435 function upgrade_reload($url) {
436 return html_writer
::empty_tag('br') .
437 html_writer
::tag('div',
438 html_writer
::link($url, $this->pix_icon('i/reload', '') .
439 get_string('reload'), array('title' => get_string('reload'))),
440 array('class' => 'continuebutton')) . html_writer
::empty_tag('br');
444 * Displays all known plugins and information about their installation or upgrade
446 * This default implementation renders all plugins into one big table. The rendering
448 * (bool)full = false: whether to display up-to-date plugins, too
450 * @param plugin_manager $pluginman provides information about the plugins.
451 * @param int $version the version of the Moodle code from version.php.
452 * @param array $options rendering options
453 * @return string HTML code
455 public function plugins_check_table(plugin_manager
$pluginman, $version, array $options = null) {
456 $plugininfo = $pluginman->get_plugins();
458 if (empty($plugininfo)) {
462 if (empty($options)) {
468 $table = new html_table();
469 $table->id
= 'plugins-check';
470 $table->head
= array(
471 get_string('displayname', 'core_plugin'),
472 get_string('rootdir', 'core_plugin'),
473 get_string('source', 'core_plugin'),
474 get_string('versiondb', 'core_plugin'),
475 get_string('versiondisk', 'core_plugin'),
476 get_string('requires', 'core_plugin'),
477 get_string('status', 'core_plugin'),
479 $table->colclasses
= array(
480 'displayname', 'rootdir', 'source', 'versiondb', 'versiondisk', 'requires', 'status',
482 $table->data
= array();
484 $numofhighlighted = array(); // number of highlighted rows per this subsection
486 foreach ($plugininfo as $type => $plugins) {
488 $header = new html_table_cell($pluginman->plugintype_name_plural($type));
489 $header->header
= true;
490 $header->colspan
= count($table->head
);
491 $header = new html_table_row(array($header));
492 $header->attributes
['class'] = 'plugintypeheader type-' . $type;
494 $numofhighlighted[$type] = 0;
496 if (empty($plugins) and $options['full']) {
497 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
498 $msg->colspan
= count($table->head
);
499 $row = new html_table_row(array($msg));
500 $row->attributes
['class'] .= 'msg msg-noneinstalled';
501 $table->data
[] = $header;
502 $table->data
[] = $row;
506 $plugintyperows = array();
508 foreach ($plugins as $name => $plugin) {
509 $row = new html_table_row();
510 $row->attributes
['class'] = 'type-' . $plugin->type
. ' name-' . $plugin->type
. '_' . $plugin->name
;
512 if ($this->page
->theme
->resolve_image_location('icon', $plugin->type
. '_' . $plugin->name
)) {
513 $icon = $this->output
->pix_icon('icon', '', $plugin->type
. '_' . $plugin->name
, array('class' => 'smallicon pluginicon'));
515 $icon = $this->output
->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon'));
517 $displayname = $icon . ' ' . $plugin->displayname
;
518 $displayname = new html_table_cell($displayname);
520 $rootdir = new html_table_cell($plugin->get_dir());
522 if ($isstandard = $plugin->is_standard()) {
523 $row->attributes
['class'] .= ' standard';
524 $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
526 $row->attributes
['class'] .= ' extension';
527 $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
530 $versiondb = new html_table_cell($plugin->versiondb
);
531 $versiondisk = new html_table_cell($plugin->versiondisk
);
533 $statuscode = $plugin->get_status();
534 $row->attributes
['class'] .= ' status-' . $statuscode;
536 $status = new html_table_cell(get_string('status_' . $statuscode, 'core_plugin'));
538 $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version));
540 $statusisboring = in_array($statuscode, array(
541 plugin_manager
::PLUGIN_STATUS_NODB
, plugin_manager
::PLUGIN_STATUS_UPTODATE
));
542 $dependenciesok = $pluginman->are_dependencies_satisfied(
543 $plugin->get_other_required_plugins());
544 if ($isstandard and $statusisboring and $dependenciesok) {
545 if (empty($options['full'])) {
549 $numofhighlighted[$type]++
;
552 $row->cells
= array($displayname, $rootdir, $source,
553 $versiondb, $versiondisk, $requires, $status);
554 $plugintyperows[] = $row;
557 if (empty($numofhighlighted[$type]) and empty($options['full'])) {
561 $table->data
[] = $header;
562 $table->data
= array_merge($table->data
, $plugintyperows);
565 $sumofhighlighted = array_sum($numofhighlighted);
567 if ($sumofhighlighted == 0) {
568 $out = $this->output
->container_start('nonehighlighted', 'plugins-check-info');
569 $out .= $this->output
->heading(get_string('nonehighlighted', 'core_plugin'));
570 if (empty($options['full'])) {
571 $out .= html_writer
::link(new moodle_url('/admin/index.php',
572 array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1)),
573 get_string('nonehighlightedinfo', 'core_plugin'));
575 $out .= $this->output
->container_end();
578 $out = $this->output
->container_start('somehighlighted', 'plugins-check-info');
579 $out .= $this->output
->heading(get_string('somehighlighted', 'core_plugin', $sumofhighlighted));
580 if (empty($options['full'])) {
581 $out .= html_writer
::link(new moodle_url('/admin/index.php',
582 array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1)),
583 get_string('somehighlightedinfo', 'core_plugin'));
585 $out .= $this->output
->container_end();
588 if ($sumofhighlighted > 0 or $options['full']) {
589 $out .= html_writer
::table($table);
596 * Formats the information that needs to go in the 'Requires' column.
597 * @param plugin_information $plugin the plugin we are rendering the row for.
598 * @param plugin_manager $pluginman provides data on all the plugins.
599 * @param string $version
600 * @return string HTML code
602 protected function required_column(plugin_information
$plugin, plugin_manager
$pluginman, $version) {
605 if (!empty($plugin->versionrequires
)) {
606 if ($plugin->versionrequires
<= $version) {
607 $class = 'requires-ok';
609 $class = 'requires-failed';
611 $requires[] = html_writer
::tag('li',
612 get_string('moodleversion', 'core_plugin', $plugin->versionrequires
),
613 array('class' => $class));
616 foreach ($plugin->get_other_required_plugins() as $component => $requiredversion) {
618 $otherplugin = $pluginman->get_plugin_info($component);
620 if (is_null($otherplugin)) {
622 } else if ($requiredversion != ANY_VERSION
and $otherplugin->versiondisk
< $requiredversion) {
627 $class = 'requires-ok';
629 $class = 'requires-failed';
632 if ($requiredversion != ANY_VERSION
) {
633 $str = 'otherpluginversion';
635 $str = 'otherplugin';
637 $requires[] = html_writer
::tag('li',
638 get_string($str, 'core_plugin',
639 array('component' => $component, 'version' => $requiredversion)),
640 array('class' => $class));
646 return html_writer
::tag('ul', implode("\n", $requires));
650 * Displays all known plugins and links to manage them
652 * This default implementation renders all plugins into one big table.
654 * @param plugin_manager $pluginman provides information about the plugins.
655 * @return string HTML code
657 public function plugins_control_panel(plugin_manager
$pluginman) {
658 $plugininfo = $pluginman->get_plugins();
660 if (empty($plugininfo)) {
664 $table = new html_table();
665 $table->id
= 'plugins-control-panel';
666 $table->head
= array(
667 get_string('displayname', 'core_plugin'),
668 get_string('systemname', 'core_plugin'),
669 get_string('source', 'core_plugin'),
670 get_string('version', 'core_plugin'),
671 get_string('availability', 'core_plugin'),
672 get_string('settings', 'core_plugin'),
673 get_string('uninstall','core_plugin'),
675 $table->colclasses
= array(
676 'displayname', 'systemname', 'source', 'version', 'availability', 'settings', 'uninstall',
679 foreach ($plugininfo as $type => $plugins) {
681 $header = new html_table_cell($pluginman->plugintype_name_plural($type));
682 $header->header
= true;
683 $header->colspan
= count($table->head
);
684 $header = new html_table_row(array($header));
685 $header->attributes
['class'] = 'plugintypeheader type-' . $type;
686 $table->data
[] = $header;
688 if (empty($plugins)) {
689 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
690 $msg->colspan
= count($table->head
);
691 $row = new html_table_row(array($msg));
692 $row->attributes
['class'] .= 'msg msg-noneinstalled';
693 $table->data
[] = $row;
697 foreach ($plugins as $name => $plugin) {
698 $row = new html_table_row();
699 $row->attributes
['class'] = 'type-' . $plugin->type
. ' name-' . $plugin->type
. '_' . $plugin->name
;
701 if ($this->page
->theme
->resolve_image_location('icon', $plugin->type
. '_' . $plugin->name
)) {
702 $icon = $this->output
->pix_icon('icon', '', $plugin->type
. '_' . $plugin->name
, array('class' => 'smallicon pluginicon'));
704 $icon = $this->output
->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon'));
706 if ($plugin->get_status() === plugin_manager
::PLUGIN_STATUS_MISSING
) {
707 $msg = html_writer
::tag('span', get_string('status_missing', 'core_plugin'), array('class' => 'notifyproblem'));
708 $row->attributes
['class'] .= ' missingfromdisk';
712 $displayname = $icon . ' ' . $plugin->displayname
. ' ' . $msg;
713 $displayname = new html_table_cell($displayname);
715 $systemname = new html_table_cell($plugin->type
. '_' . $plugin->name
);
717 if ($plugin->is_standard()) {
718 $row->attributes
['class'] .= ' standard';
719 $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
721 $row->attributes
['class'] .= ' extension';
722 $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
725 $version = new html_table_cell($plugin->versiondb
);
727 $isenabled = $plugin->is_enabled();
728 if (is_null($isenabled)) {
729 $availability = new html_table_cell('');
730 } else if ($isenabled) {
731 $row->attributes
['class'] .= ' enabled';
732 $icon = $this->output
->pix_icon('i/hide', get_string('pluginenabled', 'core_plugin'));
733 $availability = new html_table_cell($icon . ' ' . get_string('pluginenabled', 'core_plugin'));
735 $row->attributes
['class'] .= ' disabled';
736 $icon = $this->output
->pix_icon('i/show', get_string('plugindisabled', 'core_plugin'));
737 $availability = new html_table_cell($icon . ' ' . get_string('plugindisabled', 'core_plugin'));
740 $settingsurl = $plugin->get_settings_url();
741 if (is_null($settingsurl)) {
742 $settings = new html_table_cell('');
744 $settings = html_writer
::link($settingsurl, get_string('settings', 'core_plugin'));
745 $settings = new html_table_cell($settings);
748 $uninstallurl = $plugin->get_uninstall_url();
749 $requriedby = $pluginman->other_plugins_that_require($plugin->component
);
750 if (is_null($uninstallurl)) {
751 $uninstall = new html_table_cell('');
752 } else if ($requriedby) {
753 $uninstall = new html_table_cell(get_string('requiredby', 'core_plugin', implode(', ', $requriedby)));
754 $uninstall->attributes
['class'] = 'requiredby';
756 $uninstall = html_writer
::link($uninstallurl, get_string('uninstall', 'core_plugin'));
757 $uninstall = new html_table_cell($uninstall);
761 $displayname, $systemname, $source, $version, $availability, $settings, $uninstall
763 $table->data
[] = $row;
767 return html_writer
::table($table);
771 * This function will render one beautiful table with all the environmental
772 * configuration and how it suits Moodle needs.
774 * @param boolean $result final result of the check (true/false)
775 * @param array $environment_results array of results gathered
776 * @return string HTML to output.
778 public function environment_check_table($result, $environment_results) {
782 $servertable = new html_table();//table for server checks
783 $servertable->head
= array(
786 get_string('report'),
787 get_string('status'),
789 $servertable->align
= array('center', 'center', 'left', 'center');
790 $servertable->wrap
= array('nowrap', '', '', 'nowrap');
791 $servertable->size
= array('10', 10, '100%', '10');
792 $servertable->attributes
['class'] = 'environmenttable generaltable';
794 $serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
796 $othertable = new html_table();//table for custom checks
797 $othertable->head
= array(
799 get_string('report'),
800 get_string('status'),
802 $othertable->align
= array('center', 'left', 'center');
803 $othertable->wrap
= array('', '', 'nowrap');
804 $othertable->size
= array(10, '100%', '10');
805 $othertable->attributes
['class'] = 'environmenttable generaltable';
807 $otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
809 // Iterate over each environment_result
811 foreach ($environment_results as $environment_result) {
813 $warningline = false;
816 $type = $environment_result->getPart();
817 $info = $environment_result->getInfo();
818 $status = $environment_result->getStatus();
819 $error_code = $environment_result->getErrorCode();
820 // Process Report field
821 $rec = new stdClass();
822 // Something has gone wrong at parsing time
824 $stringtouse = 'environmentxmlerror';
825 $rec->error_code
= $error_code;
826 $status = get_string('error');
832 if ($rec->needed
= $environment_result->getNeededVersion()) {
833 // We are comparing versions
834 $rec->current
= $environment_result->getCurrentVersion();
835 if ($environment_result->getLevel() == 'required') {
836 $stringtouse = 'environmentrequireversion';
838 $stringtouse = 'environmentrecommendversion';
841 } else if ($environment_result->getPart() == 'custom_check') {
842 // We are checking installed & enabled things
843 if ($environment_result->getLevel() == 'required') {
844 $stringtouse = 'environmentrequirecustomcheck';
846 $stringtouse = 'environmentrecommendcustomcheck';
849 } else if ($environment_result->getPart() == 'php_setting') {
851 $stringtouse = 'environmentsettingok';
852 } else if ($environment_result->getLevel() == 'required') {
853 $stringtouse = 'environmentmustfixsetting';
855 $stringtouse = 'environmentshouldfixsetting';
859 if ($environment_result->getLevel() == 'required') {
860 $stringtouse = 'environmentrequireinstall';
862 $stringtouse = 'environmentrecommendinstall';
866 // Calculate the status value
867 if ($environment_result->getBypassStr() != '') { //Handle bypassed result (warning)
868 $status = get_string('bypassed');
870 } else if ($environment_result->getRestrictStr() != '') { //Handle restricted result (error)
871 $status = get_string('restricted');
874 if ($status) { //Handle ok result (ok)
875 $status = get_string('ok');
877 if ($environment_result->getLevel() == 'optional') {//Handle check result (warning)
878 $status = get_string('check');
880 } else { //Handle error result (error)
881 $status = get_string('check');
889 $linkparts = array();
890 $linkparts[] = 'admin/environment';
891 $linkparts[] = $type;
893 $linkparts[] = $info;
895 if (empty($CFG->docroot
)) {
896 $report = get_string($stringtouse, 'admin', $rec);
898 $report = $this->doc_link(join($linkparts, '/'), get_string($stringtouse, 'admin', $rec));
901 // Format error or warning line
902 if ($errorline ||
$warningline) {
903 $messagetype = $errorline?
'error':'warn';
907 $status = '<span class="'.$messagetype.'">'.$status.'</span>';
908 // Here we'll store all the feedback found
910 // Append the feedback if there is some
911 $feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), $messagetype);
912 //Append the bypass if there is some
913 $feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'warn');
914 //Append the restrict if there is some
915 $feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'error');
917 $report .= $feedbacktext;
919 // Add the row to the table
920 if ($environment_result->getPart() == 'custom_check'){
921 $otherdata[$messagetype][] = array ($info, $report, $status);
923 $serverdata[$messagetype][] = array ($type, $info, $report, $status);
928 //put errors first in
929 $servertable->data
= array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']);
930 $othertable->data
= array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']);
934 $output .= $this->heading(get_string('serverchecks', 'admin'));
935 $output .= html_writer
::table($servertable);
936 if (count($othertable->data
)){
937 $output .= $this->heading(get_string('customcheck', 'admin'));
938 $output .= html_writer
::table($othertable);
941 // Finally, if any error has happened, print the summary box
943 $output .= $this->box(get_string('environmenterrortodo', 'admin'), 'environmentbox errorbox');