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 available_update_checker $checker provides information about available updates.
169 * @param int $version the version of the Moodle code from version.php.
170 * @param bool $showallplugins
171 * @param moodle_url $reloadurl
172 * @param moodle_url $continueurl
173 * @return string HTML to output.
175 public function upgrade_plugin_check_page(plugin_manager
$pluginman, available_update_checker
$checker,
176 $version, $showallplugins, $reloadurl, $continueurl) {
181 $output .= $this->header();
182 $output .= $this->box_start('generalbox');
183 $output .= $this->container_start('generalbox', 'notice');
184 $output .= html_writer
::tag('p', get_string('pluginchecknotice', 'core_plugin'));
185 if (empty($CFG->disableupdatenotifications
)) {
186 $output .= $this->container_start('checkforupdates');
187 $output .= $this->single_button(new moodle_url($reloadurl, array('fetchupdates' => 1)), get_string('checkforupdates', 'core_plugin'));
188 if ($timefetched = $checker->get_last_timefetched()) {
189 $output .= $this->container(get_string('checkforupdateslast', 'core_plugin',
190 userdate($timefetched, get_string('strftimedatetime', 'core_langconfig'))));
192 $output .= $this->container_end();
194 $output .= $this->container_end();
196 $output .= $this->plugins_check_table($pluginman, $version, array('full' => $showallplugins));
197 $output .= $this->box_end();
198 $output .= $this->upgrade_reload($reloadurl);
200 if ($pluginman->all_plugins_ok($version)) {
201 if ($pluginman->some_plugins_updatable()) {
202 $output .= $this->container_start('upgradepluginsinfo');
203 $output .= $this->help_icon('upgradepluginsinfo', 'core_admin', get_string('upgradepluginsfirst', 'core_admin'));
204 $output .= $this->container_end();
206 $button = new single_button($continueurl, get_string('upgradestart', 'admin'), 'get');
207 $button->class = 'continuebutton';
208 $output .= $this->render($button);
210 $output .= $this->box(get_string('pluginschecktodo', 'admin'), 'environmentbox errorbox');
213 $output .= $this->footer();
219 * Display the admin notifications page.
220 * @param int $maturity
221 * @param bool $insecuredataroot warn dataroot is invalid
222 * @param bool $errorsdisplayed warn invalid dispaly error setting
223 * @param bool $cronoverdue warn cron not running
224 * @param bool $dbproblems warn db has problems
225 * @param bool $maintenancemode warn in maintenance mode
226 * @param array|null $availableupdates array of available_update_info objects or null
227 * @param int|null $availableupdatesfetch timestamp of the most recent updates fetch or null (unknown)
229 * @return string HTML to output.
231 public function admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed,
232 $cronoverdue, $dbproblems, $maintenancemode, $availableupdates, $availableupdatesfetch) {
236 $output .= $this->header();
237 $output .= $this->maturity_info($maturity);
238 $output .= empty($CFG->disableupdatenotifications
) ?
$this->available_updates($availableupdates, $availableupdatesfetch) : '';
239 $output .= $this->insecure_dataroot_warning($insecuredataroot);
240 $output .= $this->display_errors_warning($errorsdisplayed);
241 $output .= $this->cron_overdue_warning($cronoverdue);
242 $output .= $this->db_problems($dbproblems);
243 $output .= $this->maintenance_mode_warning($maintenancemode);
245 //////////////////////////////////////////////////////////////////////////////////////////////////
246 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
247 $output .= $this->moodle_copyright();
248 //////////////////////////////////////////////////////////////////////////////////////////////////
250 $output .= $this->footer();
256 * Display the plugin management page (admin/plugins.php).
258 * @param plugin_manager $pluginman
259 * @param available_update_checker $checker
260 * @return string HTML to output.
262 public function plugin_management_page(plugin_manager
$pluginman, available_update_checker
$checker) {
267 $output .= $this->header();
268 $output .= $this->heading(get_string('pluginsoverview', 'core_admin'));
269 $output .= $this->plugins_overview_panel($pluginman);
271 if (empty($CFG->disableupdatenotifications
)) {
272 $output .= $this->container_start('checkforupdates');
273 $output .= $this->single_button(new moodle_url($this->page
->url
, array('fetchremote' => 1)), get_string('checkforupdates', 'core_plugin'));
274 if ($timefetched = $checker->get_last_timefetched()) {
275 $output .= $this->container(get_string('checkforupdateslast', 'core_plugin',
276 userdate($timefetched, get_string('strftimedatetime', 'core_langconfig'))));
278 $output .= $this->container_end();
281 $output .= $this->box($this->plugins_control_panel($pluginman), 'generalbox');
282 $output .= $this->footer();
288 * Display the plugin management page (admin/environment.php).
289 * @param array $versions
290 * @param string $version
291 * @param boolean $envstatus final result of env check (true/false)
292 * @param array $environment_results array of results gathered
293 * @return string HTML to output.
295 public function environment_check_page($versions, $version, $envstatus, $environment_results) {
297 $output .= $this->header();
299 // Print the component download link
300 $output .= html_writer
::tag('div', html_writer
::link(
301 new moodle_url('/admin/environment.php', array('action' => 'updatecomponent', 'sesskey' => sesskey())),
302 get_string('updatecomponent', 'admin')),
303 array('class' => 'reportlink'));
306 $output .= $this->heading(get_string('environment', 'admin'));
308 // Box with info and a menu to choose the version.
309 $output .= $this->box_start();
310 $output .= html_writer
::tag('div', get_string('adminhelpenvironment'));
311 $select = new single_select(new moodle_url('/admin/environment.php'), 'version', $versions, $version, null);
312 $select->label
= get_string('moodleversion');
313 $output .= $this->render($select);
314 $output .= $this->box_end();
317 $output .= $this->environment_check_table($envstatus, $environment_results);
319 $output .= $this->footer();
324 * Output a warning message, of the type that appears on the admin notifications page.
325 * @param string $message the message to display.
326 * @param string $type type class
327 * @return string HTML to output.
329 protected function warning($message, $type = 'warning') {
330 return $this->box($message, 'generalbox admin' . $type);
334 * Render an appropriate message if dataroot is insecure.
335 * @param bool $insecuredataroot
336 * @return string HTML to output.
338 protected function insecure_dataroot_warning($insecuredataroot) {
341 if ($insecuredataroot == INSECURE_DATAROOT_WARNING
) {
342 return $this->warning(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot
));
344 } else if ($insecuredataroot == INSECURE_DATAROOT_ERROR
) {
345 return $this->warning(get_string('datarootsecurityerror', 'admin', $CFG->dataroot
), 'error');
353 * Render an appropriate message if dataroot is insecure.
354 * @param bool $errorsdisplayed
355 * @return string HTML to output.
357 protected function display_errors_warning($errorsdisplayed) {
358 if (!$errorsdisplayed) {
362 return $this->warning(get_string('displayerrorswarning', 'admin'));
366 * Render an appropriate message if cron has not been run recently.
367 * @param bool $cronoverdue
368 * @return string HTML to output.
370 public function cron_overdue_warning($cronoverdue) {
375 return $this->warning(get_string('cronwarning', 'admin') . ' ' .
376 $this->help_icon('cron', 'admin'));
380 * Render an appropriate message if there are any problems with the DB set-up.
381 * @param bool $dbproblems
382 * @return string HTML to output.
384 public function db_problems($dbproblems) {
389 return $this->warning($dbproblems);
393 * Render an appropriate message if the site in in maintenance mode.
394 * @param bool $maintenancemode
395 * @return string HTML to output.
397 public function maintenance_mode_warning($maintenancemode) {
398 if (!$maintenancemode) {
402 $url = new moodle_url('/admin/settings.php', array('section' => 'maintenancemode'));
403 $url = $url->out(); // get_string() does not support objects in params
405 return $this->warning(get_string('sitemaintenancewarning2', 'admin', $url));
409 * Display a warning about installing development code if necesary.
410 * @param int $maturity
411 * @return string HTML to output.
413 protected function maturity_warning($maturity) {
414 if ($maturity == MATURITY_STABLE
) {
415 return ''; // No worries.
418 $maturitylevel = get_string('maturity' . $maturity, 'admin');
420 $this->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
421 $this->container($this->doc_link('admin/versions', get_string('morehelp'))),
422 'generalbox maturitywarning');
426 * Output the copyright notice.
427 * @return string HTML to output.
429 protected function moodle_copyright() {
432 //////////////////////////////////////////////////////////////////////////////////////////////////
433 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
434 $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
435 '<a href="http://docs.moodle.org/dev/Releases" title="'.$CFG->version
.'">'.$CFG->release
.'</a><br />'.
436 'Copyright © 1999 onwards, Martin Dougiamas<br />'.
437 'and <a href="http://docs.moodle.org/dev/Credits">many other contributors</a>.<br />'.
438 '<a href="http://docs.moodle.org/dev/License">GNU Public License</a>';
439 //////////////////////////////////////////////////////////////////////////////////////////////////
441 return $this->box($copyrighttext, 'copyright');
445 * Display a warning about installing development code if necesary.
446 * @param int $maturity
447 * @return string HTML to output.
449 protected function maturity_info($maturity) {
450 if ($maturity == MATURITY_STABLE
) {
451 return ''; // No worries.
454 $maturitylevel = get_string('maturity' . $maturity, 'admin');
456 get_string('maturitycoreinfo', 'admin', $maturitylevel) . ' ' .
457 $this->doc_link('admin/versions', get_string('morehelp')),
458 'generalbox adminwarning maturityinfo maturity'.$maturity);
462 * Displays the info about available Moodle updates
464 * @param array|null $updates array of available_update_info objects or null
465 * @param int|null $fetch timestamp of the most recent updates fetch or null (unknown)
468 protected function available_updates($updates, $fetch) {
470 $updateinfo = $this->box_start('generalbox adminwarning availableupdatesinfo');
471 if (is_array($updates)) {
472 $updateinfo .= $this->heading(get_string('updateavailable', 'core_admin'), 3);
473 foreach ($updates as $update) {
474 $updateinfo .= $this->moodle_available_update_info($update);
478 if ($fetch and ($fetch <= $now) and ($now - $fetch < HOURSECS
)) {
479 $updateinfo .= $this->heading(get_string('updateavailablenot', 'core_admin'), 3);
483 $updateinfo .= $this->container_start('checkforupdates');
484 $updateinfo .= $this->single_button(new moodle_url($this->page
->url
, array('fetchupdates' => 1)), get_string('checkforupdates', 'core_plugin'));
486 $updateinfo .= $this->container(get_string('checkforupdateslast', 'core_plugin',
487 userdate($fetch, get_string('strftimedatetime', 'core_langconfig'))));
489 $updateinfo .= $this->container_end();
491 $updateinfo .= $this->box_end();
497 * Helper method to render the information about the available Moodle update
499 * @param available_update_info $updateinfo information about the available Moodle core update
501 protected function moodle_available_update_info(available_update_info
$updateinfo) {
503 $boxclasses = 'moodleupdateinfo';
506 if (isset($updateinfo->release
)) {
507 $info[] = html_writer
::tag('span', get_string('updateavailable_release', 'core_admin', $updateinfo->release
),
508 array('class' => 'info release'));
511 if (isset($updateinfo->version
)) {
512 $info[] = html_writer
::tag('span', get_string('updateavailable_version', 'core_admin', $updateinfo->version
),
513 array('class' => 'info version'));
516 if (isset($updateinfo->maturity
)) {
517 $info[] = html_writer
::tag('span', get_string('maturity'.$updateinfo->maturity
, 'core_admin'),
518 array('class' => 'info maturity'));
519 $boxclasses .= ' maturity'.$updateinfo->maturity
;
522 if (isset($updateinfo->download
)) {
523 $info[] = html_writer
::link($updateinfo->download
, get_string('download'), array('class' => 'info download'));
526 if (isset($updateinfo->url
)) {
527 $info[] = html_writer
::link($updateinfo->url
, get_string('updateavailable_moreinfo', 'core_plugin'),
528 array('class' => 'info more'));
531 $box = $this->output
->box_start($boxclasses);
532 $box .= $this->output
->box(implode(html_writer
::tag('span', ' ', array('class' => 'separator')), $info), '');
533 $box .= $this->output
->box_end();
539 * Display a link to the release notes.
540 * @return string HTML to output.
542 protected function release_notes_link() {
543 $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/dev/Releases');
544 $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
545 return $this->box($releasenoteslink, 'generalbox releasenoteslink');
549 * Display the reload link that appears on several upgrade/install pages.
550 * @return string HTML to output.
552 function upgrade_reload($url) {
553 return html_writer
::empty_tag('br') .
554 html_writer
::tag('div',
555 html_writer
::link($url, $this->pix_icon('i/reload', '') .
556 get_string('reload'), array('title' => get_string('reload'))),
557 array('class' => 'continuebutton')) . html_writer
::empty_tag('br');
561 * Displays all known plugins and information about their installation or upgrade
563 * This default implementation renders all plugins into one big table. The rendering
565 * (bool)full = false: whether to display up-to-date plugins, too
567 * @param plugin_manager $pluginman provides information about the plugins.
568 * @param int $version the version of the Moodle code from version.php.
569 * @param array $options rendering options
570 * @return string HTML code
572 public function plugins_check_table(plugin_manager
$pluginman, $version, array $options = null) {
575 $plugininfo = $pluginman->get_plugins();
577 if (empty($plugininfo)) {
581 if (empty($options)) {
587 $table = new html_table();
588 $table->id
= 'plugins-check';
589 $table->head
= array(
590 get_string('displayname', 'core_plugin'),
591 get_string('rootdir', 'core_plugin'),
592 get_string('source', 'core_plugin'),
593 get_string('versiondb', 'core_plugin'),
594 get_string('versiondisk', 'core_plugin'),
595 get_string('requires', 'core_plugin'),
596 get_string('status', 'core_plugin'),
598 $table->colclasses
= array(
599 'displayname', 'rootdir', 'source', 'versiondb', 'versiondisk', 'requires', 'status',
601 $table->data
= array();
603 $numofhighlighted = array(); // number of highlighted rows per this subsection
605 foreach ($plugininfo as $type => $plugins) {
607 $header = new html_table_cell($pluginman->plugintype_name_plural($type));
608 $header->header
= true;
609 $header->colspan
= count($table->head
);
610 $header = new html_table_row(array($header));
611 $header->attributes
['class'] = 'plugintypeheader type-' . $type;
613 $numofhighlighted[$type] = 0;
615 if (empty($plugins) and $options['full']) {
616 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
617 $msg->colspan
= count($table->head
);
618 $row = new html_table_row(array($msg));
619 $row->attributes
['class'] .= 'msg msg-noneinstalled';
620 $table->data
[] = $header;
621 $table->data
[] = $row;
625 $plugintyperows = array();
627 foreach ($plugins as $name => $plugin) {
628 $row = new html_table_row();
629 $row->attributes
['class'] = 'type-' . $plugin->type
. ' name-' . $plugin->type
. '_' . $plugin->name
;
631 if ($this->page
->theme
->resolve_image_location('icon', $plugin->type
. '_' . $plugin->name
)) {
632 $icon = $this->output
->pix_icon('icon', '', $plugin->type
. '_' . $plugin->name
, array('class' => 'smallicon pluginicon'));
634 $icon = $this->output
->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon'));
636 $displayname = $icon . ' ' . $plugin->displayname
;
637 $displayname = new html_table_cell($displayname);
639 $rootdir = new html_table_cell($plugin->get_dir());
641 if ($isstandard = $plugin->is_standard()) {
642 $row->attributes
['class'] .= ' standard';
643 $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
645 $row->attributes
['class'] .= ' extension';
646 $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
649 $versiondb = new html_table_cell($plugin->versiondb
);
650 $versiondisk = new html_table_cell($plugin->versiondisk
);
652 $statuscode = $plugin->get_status();
653 $row->attributes
['class'] .= ' status-' . $statuscode;
654 $status = get_string('status_' . $statuscode, 'core_plugin');
656 $availableupdates = $plugin->available_updates();
657 if (!empty($availableupdates) and empty($CFG->disableupdatenotifications
)) {
658 foreach ($availableupdates as $availableupdate) {
659 $status .= $this->plugin_available_update_info($availableupdate);
663 $status = new html_table_cell($status);
665 $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version));
667 $statusisboring = in_array($statuscode, array(
668 plugin_manager
::PLUGIN_STATUS_NODB
, plugin_manager
::PLUGIN_STATUS_UPTODATE
));
669 $dependenciesok = $pluginman->are_dependencies_satisfied(
670 $plugin->get_other_required_plugins());
671 if ($isstandard and $statusisboring and $dependenciesok and empty($availableupdates)) {
672 if (empty($options['full'])) {
676 $numofhighlighted[$type]++
;
679 $row->cells
= array($displayname, $rootdir, $source,
680 $versiondb, $versiondisk, $requires, $status);
681 $plugintyperows[] = $row;
684 if (empty($numofhighlighted[$type]) and empty($options['full'])) {
688 $table->data
[] = $header;
689 $table->data
= array_merge($table->data
, $plugintyperows);
692 $sumofhighlighted = array_sum($numofhighlighted);
694 if ($sumofhighlighted == 0) {
695 $out = $this->output
->container_start('nonehighlighted', 'plugins-check-info');
696 $out .= $this->output
->heading(get_string('nonehighlighted', 'core_plugin'));
697 if (empty($options['full'])) {
698 $out .= html_writer
::link(new moodle_url('/admin/index.php',
699 array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1)),
700 get_string('nonehighlightedinfo', 'core_plugin'));
702 $out .= $this->output
->container_end();
705 $out = $this->output
->container_start('somehighlighted', 'plugins-check-info');
706 $out .= $this->output
->heading(get_string('somehighlighted', 'core_plugin', $sumofhighlighted));
707 if (empty($options['full'])) {
708 $out .= html_writer
::link(new moodle_url('/admin/index.php',
709 array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1)),
710 get_string('somehighlightedinfo', 'core_plugin'));
712 $out .= html_writer
::link(new moodle_url('/admin/index.php',
713 array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 0)),
714 get_string('somehighlightedonly', 'core_plugin'));
716 $out .= $this->output
->container_end();
719 if ($sumofhighlighted > 0 or $options['full']) {
720 $out .= html_writer
::table($table);
727 * Formats the information that needs to go in the 'Requires' column.
728 * @param plugininfo_base $plugin the plugin we are rendering the row for.
729 * @param plugin_manager $pluginman provides data on all the plugins.
730 * @param string $version
731 * @return string HTML code
733 protected function required_column(plugininfo_base
$plugin, plugin_manager
$pluginman, $version) {
736 if (!empty($plugin->versionrequires
)) {
737 if ($plugin->versionrequires
<= $version) {
738 $class = 'requires-ok';
740 $class = 'requires-failed';
742 $requires[] = html_writer
::tag('li',
743 get_string('moodleversion', 'core_plugin', $plugin->versionrequires
),
744 array('class' => $class));
747 foreach ($plugin->get_other_required_plugins() as $component => $requiredversion) {
749 $otherplugin = $pluginman->get_plugin_info($component);
751 if (is_null($otherplugin)) {
753 } else if ($requiredversion != ANY_VERSION
and $otherplugin->versiondisk
< $requiredversion) {
758 $class = 'requires-ok';
760 $class = 'requires-failed';
763 if ($requiredversion != ANY_VERSION
) {
764 $str = 'otherpluginversion';
766 $str = 'otherplugin';
768 $requires[] = html_writer
::tag('li',
769 get_string($str, 'core_plugin',
770 array('component' => $component, 'version' => $requiredversion)),
771 array('class' => $class));
777 return html_writer
::tag('ul', implode("\n", $requires));
781 * Prints an overview about the plugins - number of installed, number of extensions etc.
783 * @param plugin_manager $pluginman provides information about the plugins
784 * @return string as usually
786 public function plugins_overview_panel(plugin_manager
$pluginman) {
789 $plugininfo = $pluginman->get_plugins();
791 $numtotal = $numdisabled = $numextension = $numupdatable = 0;
793 foreach ($plugininfo as $type => $plugins) {
794 foreach ($plugins as $name => $plugin) {
795 if ($plugin->get_status() === plugin_manager
::PLUGIN_STATUS_MISSING
) {
799 if ($plugin->is_enabled() === false) {
802 if (!$plugin->is_standard()) {
805 if (empty($CFG->disableupdatenotifications
) and $plugin->available_updates()) {
812 $info[] = html_writer
::tag('span', get_string('numtotal', 'core_plugin', $numtotal), array('class' => 'info total'));
813 $info[] = html_writer
::tag('span', get_string('numdisabled', 'core_plugin', $numdisabled), array('class' => 'info disabled'));
814 $info[] = html_writer
::tag('span', get_string('numextension', 'core_plugin', $numextension), array('class' => 'info extension'));
815 if ($numupdatable > 0) {
816 $info[] = html_writer
::tag('span', get_string('numupdatable', 'core_plugin', $numupdatable), array('class' => 'info updatable'));
819 return $this->output
->box(implode(html_writer
::tag('span', ' ', array('class' => 'separator')), $info), '', 'plugins-overview-panel');
823 * Displays all known plugins and links to manage them
825 * This default implementation renders all plugins into one big table.
827 * @param plugin_manager $pluginman provides information about the plugins.
828 * @return string HTML code
830 public function plugins_control_panel(plugin_manager
$pluginman) {
833 $plugininfo = $pluginman->get_plugins();
835 if (empty($plugininfo)) {
839 $table = new html_table();
840 $table->id
= 'plugins-control-panel';
841 $table->head
= array(
842 get_string('displayname', 'core_plugin'),
843 get_string('source', 'core_plugin'),
844 get_string('version', 'core_plugin'),
845 get_string('availability', 'core_plugin'),
846 get_string('actions', 'core_plugin'),
847 get_string('notes','core_plugin'),
849 $table->colclasses
= array(
850 'pluginname', 'source', 'version', 'availability', 'actions', 'notes'
853 foreach ($plugininfo as $type => $plugins) {
855 $header = new html_table_cell($pluginman->plugintype_name_plural($type));
856 $header->header
= true;
857 $header->colspan
= count($table->head
);
858 $header = new html_table_row(array($header));
859 $header->attributes
['class'] = 'plugintypeheader type-' . $type;
860 $table->data
[] = $header;
862 if (empty($plugins)) {
863 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
864 $msg->colspan
= count($table->head
);
865 $row = new html_table_row(array($msg));
866 $row->attributes
['class'] .= 'msg msg-noneinstalled';
867 $table->data
[] = $row;
871 foreach ($plugins as $name => $plugin) {
872 $row = new html_table_row();
873 $row->attributes
['class'] = 'type-' . $plugin->type
. ' name-' . $plugin->type
. '_' . $plugin->name
;
875 if ($this->page
->theme
->resolve_image_location('icon', $plugin->type
. '_' . $plugin->name
)) {
876 $icon = $this->output
->pix_icon('icon', '', $plugin->type
. '_' . $plugin->name
, array('class' => 'smallicon pluginicon'));
878 $icon = $this->output
->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon'));
880 if ($plugin->get_status() === plugin_manager
::PLUGIN_STATUS_MISSING
) {
881 $msg = html_writer
::tag('span', get_string('status_missing', 'core_plugin'), array('class' => 'notifyproblem'));
882 $row->attributes
['class'] .= ' missingfromdisk';
886 $pluginname = html_writer
::tag('div', $icon . ' ' . $plugin->displayname
. ' ' . $msg, array('class' => 'displayname')).
887 html_writer
::tag('div', $plugin->component
, array('class' => 'componentname'));
888 $pluginname = new html_table_cell($pluginname);
890 if ($plugin->is_standard()) {
891 $row->attributes
['class'] .= ' standard';
892 $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
894 $row->attributes
['class'] .= ' extension';
895 $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
898 $version = new html_table_cell($plugin->versiondb
);
900 $isenabled = $plugin->is_enabled();
901 if (is_null($isenabled)) {
902 $availability = new html_table_cell('');
903 } else if ($isenabled) {
904 $row->attributes
['class'] .= ' enabled';
905 $icon = $this->output
->pix_icon('i/hide', get_string('pluginenabled', 'core_plugin'));
906 $availability = new html_table_cell($icon . ' ' . get_string('pluginenabled', 'core_plugin'));
908 $row->attributes
['class'] .= ' disabled';
909 $icon = $this->output
->pix_icon('i/show', get_string('plugindisabled', 'core_plugin'));
910 $availability = new html_table_cell($icon . ' ' . get_string('plugindisabled', 'core_plugin'));
915 $settingsurl = $plugin->get_settings_url();
916 if (!is_null($settingsurl)) {
917 $actions[] = html_writer
::link($settingsurl, get_string('settings', 'core_plugin'), array('class' => 'settings'));
920 $uninstallurl = $plugin->get_uninstall_url();
921 if (!is_null($uninstallurl)) {
922 $actions[] = html_writer
::link($uninstallurl, get_string('uninstall', 'core_plugin'), array('class' => 'uninstall'));
925 $actions = new html_table_cell(implode(html_writer
::tag('span', ' ', array('class' => 'separator')), $actions));
927 $requriedby = $pluginman->other_plugins_that_require($plugin->component
);
929 $requiredby = html_writer
::tag('div', get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
930 array('class' => 'requiredby'));
936 if (empty($CFG->disableupdatenotifications
) and is_array($plugin->available_updates())) {
937 foreach ($plugin->available_updates() as $availableupdate) {
938 $updateinfo .= $this->plugin_available_update_info($availableupdate);
942 $notes = new html_table_cell($requiredby.$updateinfo);
945 $pluginname, $source, $version, $availability, $actions, $notes
947 $table->data
[] = $row;
951 return html_writer
::table($table);
955 * Helper method to render the information about the available plugin update
957 * The passed objects always provides at least the 'version' property containing
958 * the (higher) version of the plugin available.
960 * @param available_update_info $updateinfo information about the available update for the plugin
962 protected function plugin_available_update_info(available_update_info
$updateinfo) {
964 $boxclasses = 'pluginupdateinfo';
967 if (isset($updateinfo->release
)) {
968 $info[] = html_writer
::tag('span', get_string('updateavailable_release', 'core_plugin', $updateinfo->release
),
969 array('class' => 'info release'));
972 if (isset($updateinfo->maturity
)) {
973 $info[] = html_writer
::tag('span', get_string('maturity'.$updateinfo->maturity
, 'core_admin'),
974 array('class' => 'info maturity'));
975 $boxclasses .= ' maturity'.$updateinfo->maturity
;
978 if (isset($updateinfo->download
)) {
979 $info[] = html_writer
::link($updateinfo->download
, get_string('download'), array('class' => 'info download'));
982 if (isset($updateinfo->url
)) {
983 $info[] = html_writer
::link($updateinfo->url
, get_string('updateavailable_moreinfo', 'core_plugin'),
984 array('class' => 'info more'));
987 $box = $this->output
->box_start($boxclasses);
988 $box .= html_writer
::tag('div', get_string('updateavailable', 'core_plugin', $updateinfo->version
), array('class' => 'version'));
989 $box .= $this->output
->box(implode(html_writer
::tag('span', ' ', array('class' => 'separator')), $info), '');
990 $box .= $this->output
->box_end();
996 * This function will render one beautiful table with all the environmental
997 * configuration and how it suits Moodle needs.
999 * @param boolean $result final result of the check (true/false)
1000 * @param array $environment_results array of results gathered
1001 * @return string HTML to output.
1003 public function environment_check_table($result, $environment_results) {
1007 $servertable = new html_table();//table for server checks
1008 $servertable->head
= array(
1011 get_string('report'),
1012 get_string('status'),
1014 $servertable->align
= array('center', 'center', 'left', 'center');
1015 $servertable->wrap
= array('nowrap', '', '', 'nowrap');
1016 $servertable->size
= array('10', 10, '100%', '10');
1017 $servertable->attributes
['class'] = 'environmenttable generaltable';
1019 $serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
1021 $othertable = new html_table();//table for custom checks
1022 $othertable->head
= array(
1024 get_string('report'),
1025 get_string('status'),
1027 $othertable->align
= array('center', 'left', 'center');
1028 $othertable->wrap
= array('', '', 'nowrap');
1029 $othertable->size
= array(10, '100%', '10');
1030 $othertable->attributes
['class'] = 'environmenttable generaltable';
1032 $otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
1034 // Iterate over each environment_result
1036 foreach ($environment_results as $environment_result) {
1038 $warningline = false;
1041 $type = $environment_result->getPart();
1042 $info = $environment_result->getInfo();
1043 $status = $environment_result->getStatus();
1044 $error_code = $environment_result->getErrorCode();
1045 // Process Report field
1046 $rec = new stdClass();
1047 // Something has gone wrong at parsing time
1049 $stringtouse = 'environmentxmlerror';
1050 $rec->error_code
= $error_code;
1051 $status = get_string('error');
1057 if ($rec->needed
= $environment_result->getNeededVersion()) {
1058 // We are comparing versions
1059 $rec->current
= $environment_result->getCurrentVersion();
1060 if ($environment_result->getLevel() == 'required') {
1061 $stringtouse = 'environmentrequireversion';
1063 $stringtouse = 'environmentrecommendversion';
1066 } else if ($environment_result->getPart() == 'custom_check') {
1067 // We are checking installed & enabled things
1068 if ($environment_result->getLevel() == 'required') {
1069 $stringtouse = 'environmentrequirecustomcheck';
1071 $stringtouse = 'environmentrecommendcustomcheck';
1074 } else if ($environment_result->getPart() == 'php_setting') {
1076 $stringtouse = 'environmentsettingok';
1077 } else if ($environment_result->getLevel() == 'required') {
1078 $stringtouse = 'environmentmustfixsetting';
1080 $stringtouse = 'environmentshouldfixsetting';
1084 if ($environment_result->getLevel() == 'required') {
1085 $stringtouse = 'environmentrequireinstall';
1087 $stringtouse = 'environmentrecommendinstall';
1091 // Calculate the status value
1092 if ($environment_result->getBypassStr() != '') { //Handle bypassed result (warning)
1093 $status = get_string('bypassed');
1094 $warningline = true;
1095 } else if ($environment_result->getRestrictStr() != '') { //Handle restricted result (error)
1096 $status = get_string('restricted');
1099 if ($status) { //Handle ok result (ok)
1100 $status = get_string('ok');
1102 if ($environment_result->getLevel() == 'optional') {//Handle check result (warning)
1103 $status = get_string('check');
1104 $warningline = true;
1105 } else { //Handle error result (error)
1106 $status = get_string('check');
1114 $linkparts = array();
1115 $linkparts[] = 'admin/environment';
1116 $linkparts[] = $type;
1118 $linkparts[] = $info;
1120 if (empty($CFG->docroot
)) {
1121 $report = get_string($stringtouse, 'admin', $rec);
1123 $report = $this->doc_link(join($linkparts, '/'), get_string($stringtouse, 'admin', $rec));
1126 // Format error or warning line
1127 if ($errorline ||
$warningline) {
1128 $messagetype = $errorline?
'error':'warn';
1130 $messagetype = 'ok';
1132 $status = '<span class="'.$messagetype.'">'.$status.'</span>';
1133 // Here we'll store all the feedback found
1135 // Append the feedback if there is some
1136 $feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), $messagetype);
1137 //Append the bypass if there is some
1138 $feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'warn');
1139 //Append the restrict if there is some
1140 $feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'error');
1142 $report .= $feedbacktext;
1144 // Add the row to the table
1145 if ($environment_result->getPart() == 'custom_check'){
1146 $otherdata[$messagetype][] = array ($info, $report, $status);
1148 $serverdata[$messagetype][] = array ($type, $info, $report, $status);
1153 //put errors first in
1154 $servertable->data
= array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']);
1155 $othertable->data
= array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']);
1159 $output .= $this->heading(get_string('serverchecks', 'admin'));
1160 $output .= html_writer
::table($servertable);
1161 if (count($othertable->data
)){
1162 $output .= $this->heading(get_string('customcheck', 'admin'));
1163 $output .= html_writer
::table($othertable);
1166 // Finally, if any error has happened, print the summary box
1168 $output .= $this->box(get_string('environmenterrortodo', 'admin'), 'environmentbox errorbox');