MDL-43681 report_log: Modified log report to use log readers
[moodle.git] / admin / renderer.php
blob944b5016047601dc4d7bb8809c8f06e559af5bfe
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * Renderer for core_admin subsystem
20 * @package core
21 * @subpackage admin
22 * @copyright 2011 David Mudrak <david@moodle.com>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') || die();
29 /**
30 * Standard HTML output renderer for core_admin subsystem
32 class core_admin_renderer extends plugin_renderer_base {
34 /**
35 * Display the 'Do you acknowledge the terms of the GPL' page. The first page
36 * during install.
37 * @return string HTML to output.
39 public function install_licence_page() {
40 global $CFG;
41 $output = '';
43 $copyrightnotice = text_to_html(get_string('gpl3'));
44 $copyrightnotice = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $copyrightnotice); // extremely ugly validation hack
46 $continue = new single_button(new moodle_url('/admin/index.php', array('lang'=>$CFG->lang, 'agreelicense'=>1)), get_string('continue'), 'get');
48 $output .= $this->header();
49 $output .= $this->heading('<a href="http://moodle.org">Moodle</a> - Modular Object-Oriented Dynamic Learning Environment');
50 $output .= $this->heading(get_string('copyrightnotice'));
51 $output .= $this->box($copyrightnotice, 'copyrightnotice');
52 $output .= html_writer::empty_tag('br');
53 $output .= $this->confirm(get_string('doyouagree'), $continue, "http://docs.moodle.org/dev/License");
54 $output .= $this->footer();
56 return $output;
59 /**
60 * Display page explaining proper upgrade process,
61 * there can not be any PHP file leftovers...
63 * @return string HTML to output.
65 public function upgrade_stale_php_files_page() {
66 $output = '';
67 $output .= $this->header();
68 $output .= $this->heading(get_string('upgradestalefiles', 'admin'));
69 $output .= $this->box_start('generalbox', 'notice');
70 $output .= format_text(get_string('upgradestalefilesinfo', 'admin', get_docs_url('Upgrading')), FORMAT_MARKDOWN);
71 $output .= html_writer::empty_tag('br');
72 $output .= html_writer::tag('div', $this->single_button($this->page->url, get_string('reload'), 'get'), array('class' => 'buttons'));
73 $output .= $this->box_end();
74 $output .= $this->footer();
76 return $output;
79 /**
80 * Display the 'environment check' page that is displayed during install.
81 * @param int $maturity
82 * @param boolean $envstatus final result of the check (true/false)
83 * @param array $environment_results array of results gathered
84 * @param string $release moodle release
85 * @return string HTML to output.
87 public function install_environment_page($maturity, $envstatus, $environment_results, $release) {
88 global $CFG;
89 $output = '';
91 $output .= $this->header();
92 $output .= $this->maturity_warning($maturity);
93 $output .= $this->heading("Moodle $release");
94 $output .= $this->release_notes_link();
96 $output .= $this->environment_check_table($envstatus, $environment_results);
98 if (!$envstatus) {
99 $output .= $this->upgrade_reload(new moodle_url('/admin/index.php', array('agreelicense' => 1, 'lang' => $CFG->lang)));
100 } else {
101 $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
102 $output .= $this->continue_button(new moodle_url('/admin/index.php', array('agreelicense'=>1, 'confirmrelease'=>1, 'lang'=>$CFG->lang)));
105 $output .= $this->footer();
106 return $output;
110 * Displays the list of plugins with unsatisfied dependencies
112 * @param double|string|int $version Moodle on-disk version
113 * @param array $failed list of plugins with unsatisfied dependecies
114 * @param moodle_url $reloadurl URL of the page to recheck the dependencies
115 * @return string HTML
117 public function unsatisfied_dependencies_page($version, array $failed, moodle_url $reloadurl) {
118 $output = '';
120 $output .= $this->header();
121 $output .= $this->heading(get_string('pluginscheck', 'admin'));
122 $output .= $this->warning(get_string('pluginscheckfailed', 'admin', array('pluginslist' => implode(', ', array_unique($failed)))));
123 $output .= $this->plugins_check_table(core_plugin_manager::instance(), $version, array('xdep' => true));
124 $output .= $this->warning(get_string('pluginschecktodo', 'admin'));
125 $output .= $this->continue_button($reloadurl);
127 $output .= $this->footer();
129 return $output;
133 * Display the 'You are about to upgrade Moodle' page. The first page
134 * during upgrade.
135 * @param string $strnewversion
136 * @param int $maturity
137 * @param string $testsite
138 * @return string HTML to output.
140 public function upgrade_confirm_page($strnewversion, $maturity, $testsite) {
141 $output = '';
143 $continueurl = new moodle_url('/admin/index.php', array('confirmupgrade' => 1, 'cache' => 0));
144 $continue = new single_button($continueurl, get_string('continue'), 'get');
145 $cancelurl = new moodle_url('/admin/index.php');
147 $output .= $this->header();
148 $output .= $this->maturity_warning($maturity);
149 $output .= $this->test_site_warning($testsite);
150 $output .= $this->confirm(get_string('upgradesure', 'admin', $strnewversion), $continue, $cancelurl);
151 $output .= $this->footer();
153 return $output;
157 * Display the environment page during the upgrade process.
158 * @param string $release
159 * @param boolean $envstatus final result of env check (true/false)
160 * @param array $environment_results array of results gathered
161 * @return string HTML to output.
163 public function upgrade_environment_page($release, $envstatus, $environment_results) {
164 global $CFG;
165 $output = '';
167 $output .= $this->header();
168 $output .= $this->heading("Moodle $release");
169 $output .= $this->release_notes_link();
170 $output .= $this->environment_check_table($envstatus, $environment_results);
172 if (!$envstatus) {
173 $output .= $this->upgrade_reload(new moodle_url('/admin/index.php'), array('confirmupgrade' => 1, 'cache' => 0));
175 } else {
176 $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
178 if (empty($CFG->skiplangupgrade) and current_language() !== 'en') {
179 $output .= $this->box(get_string('langpackwillbeupdated', 'admin'), 'generalbox', 'notice');
182 $output .= $this->continue_button(new moodle_url('/admin/index.php', array('confirmupgrade' => 1, 'confirmrelease' => 1, 'cache' => 0)));
185 $output .= $this->footer();
187 return $output;
191 * Display the upgrade page that lists all the plugins that require attention.
192 * @param core_plugin_manager $pluginman provides information about the plugins.
193 * @param \core\update\checker $checker provides information about available updates.
194 * @param int $version the version of the Moodle code from version.php.
195 * @param bool $showallplugins
196 * @param moodle_url $reloadurl
197 * @param moodle_url $continueurl
198 * @return string HTML to output.
200 public function upgrade_plugin_check_page(core_plugin_manager $pluginman, \core\update\checker $checker,
201 $version, $showallplugins, $reloadurl, $continueurl) {
202 global $CFG;
204 $output = '';
206 $output .= $this->header();
207 $output .= $this->box_start('generalbox');
208 $output .= $this->container_start('generalbox', 'notice');
209 $output .= html_writer::tag('p', get_string('pluginchecknotice', 'core_plugin'));
210 if (empty($CFG->disableupdatenotifications)) {
211 $output .= $this->container_start('checkforupdates');
212 $output .= $this->single_button(new moodle_url($reloadurl, array('fetchupdates' => 1)), get_string('checkforupdates', 'core_plugin'));
213 if ($timefetched = $checker->get_last_timefetched()) {
214 $output .= $this->container(get_string('checkforupdateslast', 'core_plugin',
215 userdate($timefetched, get_string('strftimedatetime', 'core_langconfig'))));
217 $output .= $this->container_end();
219 $output .= $this->container_end();
221 $output .= $this->plugins_check_table($pluginman, $version, array('full' => $showallplugins));
222 $output .= $this->box_end();
223 $output .= $this->upgrade_reload($reloadurl);
225 if ($pluginman->some_plugins_updatable()) {
226 $output .= $this->container_start('upgradepluginsinfo');
227 $output .= $this->help_icon('upgradepluginsinfo', 'core_admin', get_string('upgradepluginsfirst', 'core_admin'));
228 $output .= $this->container_end();
231 $button = new single_button($continueurl, get_string('upgradestart', 'admin'), 'get');
232 $button->class = 'continuebutton';
233 $output .= $this->render($button);
234 $output .= $this->footer();
236 return $output;
240 * Prints a page with a summary of plugin deployment to be confirmed.
242 * @param \core\update\deployer $deployer
243 * @param array $data deployer's data package as returned by {@link \core\update\deployer::submitted_data()}
244 * @return string
246 public function upgrade_plugin_confirm_deploy_page(\core\update\deployer $deployer, array $data) {
248 if (!$deployer->initialized()) {
249 throw new coding_exception('Unable to render a page for non-initialized deployer.');
252 if (empty($data['updateinfo'])) {
253 throw new coding_exception('Missing required data component.');
256 $updateinfo = $data['updateinfo'];
258 $output = '';
259 $output .= $this->header();
260 $output .= $this->container_start('generalbox updateplugin', 'notice');
262 $a = new stdClass();
263 if (get_string_manager()->string_exists('pluginname', $updateinfo->component)) {
264 $a->name = get_string('pluginname', $updateinfo->component);
265 } else {
266 $a->name = $updateinfo->component;
269 if (isset($updateinfo->release)) {
270 $a->version = $updateinfo->release . ' (' . $updateinfo->version . ')';
271 } else {
272 $a->version = $updateinfo->version;
274 $a->url = $updateinfo->download;
276 $output .= $this->output->heading(get_string('updatepluginconfirm', 'core_plugin'));
277 $output .= $this->output->container(format_text(get_string('updatepluginconfirminfo', 'core_plugin', $a)), 'updatepluginconfirminfo');
278 $output .= $this->output->container(get_string('updatepluginconfirmwarning', 'core_plugin', 'updatepluginconfirmwarning'));
280 if ($repotype = $deployer->plugin_external_source($data['updateinfo'])) {
281 $output .= $this->output->container(get_string('updatepluginconfirmexternal', 'core_plugin', $repotype), 'updatepluginconfirmexternal');
284 $widget = $deployer->make_execution_widget($data['updateinfo'], $data['returnurl']);
285 $output .= $this->output->render($widget);
287 $output .= $this->output->single_button($data['callerurl'], get_string('cancel', 'core'), 'get');
289 $output .= $this->container_end();
290 $output .= $this->footer();
292 return $output;
296 * Display the admin notifications page.
297 * @param int $maturity
298 * @param bool $insecuredataroot warn dataroot is invalid
299 * @param bool $errorsdisplayed warn invalid dispaly error setting
300 * @param bool $cronoverdue warn cron not running
301 * @param bool $dbproblems warn db has problems
302 * @param bool $maintenancemode warn in maintenance mode
303 * @param bool $buggyiconvnomb warn iconv problems
304 * @param array|null $availableupdates array of \core\update\info objects or null
305 * @param int|null $availableupdatesfetch timestamp of the most recent updates fetch or null (unknown)
307 * @return string HTML to output.
309 public function admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed,
310 $cronoverdue, $dbproblems, $maintenancemode, $availableupdates, $availableupdatesfetch,
311 $buggyiconvnomb, $registered) {
312 global $CFG;
313 $output = '';
315 $output .= $this->header();
316 $output .= $this->maturity_info($maturity);
317 $output .= empty($CFG->disableupdatenotifications) ? $this->available_updates($availableupdates, $availableupdatesfetch) : '';
318 $output .= $this->insecure_dataroot_warning($insecuredataroot);
319 $output .= $this->display_errors_warning($errorsdisplayed);
320 $output .= $this->buggy_iconv_warning($buggyiconvnomb);
321 $output .= $this->cron_overdue_warning($cronoverdue);
322 $output .= $this->db_problems($dbproblems);
323 $output .= $this->maintenance_mode_warning($maintenancemode);
324 $output .= $this->registration_warning($registered);
326 //////////////////////////////////////////////////////////////////////////////////////////////////
327 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
328 $output .= $this->moodle_copyright();
329 //////////////////////////////////////////////////////////////////////////////////////////////////
331 $output .= $this->footer();
333 return $output;
337 * Display the plugin management page (admin/plugins.php).
339 * The filtering options array may contain following items:
340 * bool contribonly - show only contributed extensions
341 * bool updatesonly - show only plugins with an available update
343 * @param core_plugin_manager $pluginman
344 * @param \core\update\checker $checker
345 * @param array $options filtering options
346 * @return string HTML to output.
348 public function plugin_management_page(core_plugin_manager $pluginman, \core\update\checker $checker, array $options = array()) {
349 global $CFG;
351 $output = '';
353 $output .= $this->header();
354 $output .= $this->heading(get_string('pluginsoverview', 'core_admin'));
355 $output .= $this->plugins_overview_panel($pluginman, $options);
357 if (empty($CFG->disableupdatenotifications)) {
358 $output .= $this->container_start('checkforupdates');
359 $output .= $this->single_button(
360 new moodle_url($this->page->url, array_merge($options, array('fetchremote' => 1))),
361 get_string('checkforupdates', 'core_plugin')
363 if ($timefetched = $checker->get_last_timefetched()) {
364 $output .= $this->container(get_string('checkforupdateslast', 'core_plugin',
365 userdate($timefetched, get_string('strftimedatetime', 'core_langconfig'))));
367 $output .= $this->container_end();
370 $output .= $this->box($this->plugins_control_panel($pluginman, $options), 'generalbox');
371 $output .= $this->footer();
373 return $output;
377 * Display a page to confirm the plugin uninstallation.
379 * @param core_plugin_manager $pluginman
380 * @param \core\plugininfo\base $pluginfo
381 * @param moodle_url $continueurl URL to continue after confirmation
382 * @param moodle_url $cancelurl URL to to go if cancelled
383 * @return string
385 public function plugin_uninstall_confirm_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, moodle_url $continueurl, moodle_url $cancelurl) {
386 $output = '';
388 $pluginname = $pluginman->plugin_name($pluginfo->component);
390 $confirm = '<p>' . get_string('uninstallconfirm', 'core_plugin', array('name' => $pluginname)) . '</p>';
391 if ($extraconfirm = $pluginfo->get_uninstall_extra_warning()) {
392 $confirm .= $extraconfirm;
395 $output .= $this->output->header();
396 $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
397 $output .= $this->output->confirm($confirm, $continueurl, $cancelurl);
398 $output .= $this->output->footer();
400 return $output;
404 * Display a page with results of plugin uninstallation and offer removal of plugin files.
406 * @param core_plugin_manager $pluginman
407 * @param \core\plugininfo\base $pluginfo
408 * @param progress_trace_buffer $progress
409 * @param moodle_url $continueurl URL to continue to remove the plugin folder
410 * @return string
412 public function plugin_uninstall_results_removable_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo,
413 progress_trace_buffer $progress, moodle_url $continueurl) {
414 $output = '';
416 $pluginname = $pluginman->plugin_name($pluginfo->component);
418 // Do not show navigation here, they must click one of the buttons.
419 $this->page->set_pagelayout('maintenance');
420 $this->page->set_cacheable(false);
422 $output .= $this->output->header();
423 $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
425 $output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
427 $confirm = $this->output->container(get_string('uninstalldeleteconfirm', 'core_plugin',
428 array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'uninstalldeleteconfirm');
430 if ($repotype = $pluginman->plugin_external_source($pluginfo->component)) {
431 $confirm .= $this->output->container(get_string('uninstalldeleteconfirmexternal', 'core_plugin', $repotype),
432 'uninstalldeleteconfirmexternal');
435 // After any uninstall we must execute full upgrade to finish the cleanup!
436 $output .= $this->output->confirm($confirm, $continueurl, new moodle_url('/admin/index.php'));
437 $output .= $this->output->footer();
439 return $output;
443 * Display a page with results of plugin uninstallation and inform about the need to remove plugin files manually.
445 * @param core_plugin_manager $pluginman
446 * @param \core\plugininfo\base $pluginfo
447 * @param progress_trace_buffer $progress
448 * @return string
450 public function plugin_uninstall_results_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, progress_trace_buffer $progress) {
451 $output = '';
453 $pluginname = $pluginfo->component;
455 $output .= $this->output->header();
456 $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
458 $output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
460 $output .= $this->output->box(get_string('uninstalldelete', 'core_plugin',
461 array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'generalbox uninstalldelete');
462 $output .= $this->output->continue_button(new moodle_url('/admin/index.php'));
463 $output .= $this->output->footer();
465 return $output;
469 * Display the plugin management page (admin/environment.php).
470 * @param array $versions
471 * @param string $version
472 * @param boolean $envstatus final result of env check (true/false)
473 * @param array $environment_results array of results gathered
474 * @return string HTML to output.
476 public function environment_check_page($versions, $version, $envstatus, $environment_results) {
477 $output = '';
478 $output .= $this->header();
480 // Print the component download link
481 $output .= html_writer::tag('div', html_writer::link(
482 new moodle_url('/admin/environment.php', array('action' => 'updatecomponent', 'sesskey' => sesskey())),
483 get_string('updatecomponent', 'admin')),
484 array('class' => 'reportlink'));
486 // Heading.
487 $output .= $this->heading(get_string('environment', 'admin'));
489 // Box with info and a menu to choose the version.
490 $output .= $this->box_start();
491 $output .= html_writer::tag('div', get_string('adminhelpenvironment'));
492 $select = new single_select(new moodle_url('/admin/environment.php'), 'version', $versions, $version, null);
493 $select->label = get_string('moodleversion');
494 $output .= $this->render($select);
495 $output .= $this->box_end();
497 // The results
498 $output .= $this->environment_check_table($envstatus, $environment_results);
500 $output .= $this->footer();
501 return $output;
505 * Output a warning message, of the type that appears on the admin notifications page.
506 * @param string $message the message to display.
507 * @param string $type type class
508 * @return string HTML to output.
510 protected function warning($message, $type = 'warning') {
511 return $this->box($message, 'generalbox admin' . $type);
515 * Render an appropriate message if dataroot is insecure.
516 * @param bool $insecuredataroot
517 * @return string HTML to output.
519 protected function insecure_dataroot_warning($insecuredataroot) {
520 global $CFG;
522 if ($insecuredataroot == INSECURE_DATAROOT_WARNING) {
523 return $this->warning(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot));
525 } else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) {
526 return $this->warning(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'error');
528 } else {
529 return '';
534 * Render an appropriate message if dataroot is insecure.
535 * @param bool $errorsdisplayed
536 * @return string HTML to output.
538 protected function display_errors_warning($errorsdisplayed) {
539 if (!$errorsdisplayed) {
540 return '';
543 return $this->warning(get_string('displayerrorswarning', 'admin'));
547 * Render an appropriate message if iconv is buggy and mbstring missing.
548 * @param bool $buggyiconvnomb
549 * @return string HTML to output.
551 protected function buggy_iconv_warning($buggyiconvnomb) {
552 if (!$buggyiconvnomb) {
553 return '';
556 return $this->warning(get_string('warningiconvbuggy', 'admin'));
560 * Render an appropriate message if cron has not been run recently.
561 * @param bool $cronoverdue
562 * @return string HTML to output.
564 public function cron_overdue_warning($cronoverdue) {
565 global $CFG;
566 if (!$cronoverdue) {
567 return '';
570 if (empty($CFG->cronclionly)) {
571 $url = new moodle_url('/admin/cron.php');
572 if (!empty($CFG->cronremotepassword)) {
573 $url = new moodle_url('/admin/cron.php', array('password' => $CFG->cronremotepassword));
576 return $this->warning(get_string('cronwarning', 'admin', $url->out()) . '&nbsp;' .
577 $this->help_icon('cron', 'admin'));
580 // $CFG->cronclionly is not empty: cron can run only from CLI.
581 return $this->warning(get_string('cronwarningcli', 'admin') . '&nbsp;' .
582 $this->help_icon('cron', 'admin'));
586 * Render an appropriate message if there are any problems with the DB set-up.
587 * @param bool $dbproblems
588 * @return string HTML to output.
590 public function db_problems($dbproblems) {
591 if (!$dbproblems) {
592 return '';
595 return $this->warning($dbproblems);
599 * Render an appropriate message if the site in in maintenance mode.
600 * @param bool $maintenancemode
601 * @return string HTML to output.
603 public function maintenance_mode_warning($maintenancemode) {
604 if (!$maintenancemode) {
605 return '';
608 $url = new moodle_url('/admin/settings.php', array('section' => 'maintenancemode'));
609 $url = $url->out(); // get_string() does not support objects in params
611 return $this->warning(get_string('sitemaintenancewarning2', 'admin', $url));
615 * Display a warning about installing development code if necesary.
616 * @param int $maturity
617 * @return string HTML to output.
619 protected function maturity_warning($maturity) {
620 if ($maturity == MATURITY_STABLE) {
621 return ''; // No worries.
624 $maturitylevel = get_string('maturity' . $maturity, 'admin');
625 return $this->warning(
626 $this->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
627 $this->container($this->doc_link('admin/versions', get_string('morehelp'))),
628 'error');
632 * If necessary, displays a warning about upgrading a test site.
634 * @param string $testsite
635 * @return string HTML
637 protected function test_site_warning($testsite) {
639 if (!$testsite) {
640 return '';
643 $warning = (get_string('testsiteupgradewarning', 'admin', $testsite));
644 return $this->warning($warning, 'error');
648 * Output the copyright notice.
649 * @return string HTML to output.
651 protected function moodle_copyright() {
652 global $CFG;
654 //////////////////////////////////////////////////////////////////////////////////////////////////
655 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
656 $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
657 '<a href="http://docs.moodle.org/dev/Releases" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
658 'Copyright &copy; 1999 onwards, Martin Dougiamas<br />'.
659 'and <a href="http://moodle.org/dev">many other contributors</a>.<br />'.
660 '<a href="http://docs.moodle.org/dev/License">GNU Public License</a>';
661 //////////////////////////////////////////////////////////////////////////////////////////////////
663 return $this->box($copyrighttext, 'copyright');
667 * Display a warning about installing development code if necesary.
668 * @param int $maturity
669 * @return string HTML to output.
671 protected function maturity_info($maturity) {
672 if ($maturity == MATURITY_STABLE) {
673 return ''; // No worries.
676 $level = 'warning';
678 if ($maturity == MATURITY_ALPHA) {
679 $level = 'error';
682 $maturitylevel = get_string('maturity' . $maturity, 'admin');
683 $warningtext = get_string('maturitycoreinfo', 'admin', $maturitylevel);
684 $warningtext .= ' ' . $this->doc_link('admin/versions', get_string('morehelp'));
685 return $this->warning($warningtext, $level);
689 * Displays the info about available Moodle core and plugin updates
691 * The structure of the $updates param has changed since 2.4. It contains not only updates
692 * for the core itself, but also for all other installed plugins.
694 * @param array|null $updates array of (string)component => array of \core\update\info objects or null
695 * @param int|null $fetch timestamp of the most recent updates fetch or null (unknown)
696 * @return string
698 protected function available_updates($updates, $fetch) {
700 $updateinfo = '';
701 $someupdateavailable = false;
702 if (is_array($updates)) {
703 if (is_array($updates['core'])) {
704 $someupdateavailable = true;
705 $updateinfo .= $this->heading(get_string('updateavailable', 'core_admin'), 3);
706 foreach ($updates['core'] as $update) {
707 $updateinfo .= $this->moodle_available_update_info($update);
710 unset($updates['core']);
711 // If something has left in the $updates array now, it is updates for plugins.
712 if (!empty($updates)) {
713 $someupdateavailable = true;
714 $updateinfo .= $this->heading(get_string('updateavailableforplugin', 'core_admin'), 3);
715 $pluginsoverviewurl = new moodle_url('/admin/plugins.php', array('updatesonly' => 1));
716 $updateinfo .= $this->container(get_string('pluginsoverviewsee', 'core_admin',
717 array('url' => $pluginsoverviewurl->out())));
721 if (!$someupdateavailable) {
722 $now = time();
723 if ($fetch and ($fetch <= $now) and ($now - $fetch < HOURSECS)) {
724 $updateinfo .= $this->heading(get_string('updateavailablenot', 'core_admin'), 3);
728 $updateinfo .= $this->container_start('checkforupdates');
729 $fetchurl = new moodle_url('/admin/index.php', array('fetchupdates' => 1, 'sesskey' => sesskey(), 'cache' => 0));
730 $updateinfo .= $this->single_button($fetchurl, get_string('checkforupdates', 'core_plugin'));
731 if ($fetch) {
732 $updateinfo .= $this->container(get_string('checkforupdateslast', 'core_plugin',
733 userdate($fetch, get_string('strftimedatetime', 'core_langconfig'))));
735 $updateinfo .= $this->container_end();
737 return $this->warning($updateinfo);
741 * Display a warning about not being registered on Moodle.org if necesary.
743 * @param boolean $registered true if the site is registered on Moodle.org
744 * @return string HTML to output.
746 protected function registration_warning($registered) {
748 if (!$registered) {
750 $registerbutton = $this->single_button(new moodle_url('/admin/registration/register.php',
751 array('huburl' => HUB_MOODLEORGHUBURL, 'hubname' => 'Moodle.org')),
752 get_string('register', 'admin'));
754 return $this->warning( get_string('registrationwarning', 'admin')
755 . '&nbsp;' . $this->help_icon('registration', 'admin') . $registerbutton );
758 return '';
762 * Helper method to render the information about the available Moodle update
764 * @param \core\update\info $updateinfo information about the available Moodle core update
766 protected function moodle_available_update_info(\core\update\info $updateinfo) {
768 $boxclasses = 'moodleupdateinfo';
769 $info = array();
771 if (isset($updateinfo->release)) {
772 $info[] = html_writer::tag('span', get_string('updateavailable_release', 'core_admin', $updateinfo->release),
773 array('class' => 'info release'));
776 if (isset($updateinfo->version)) {
777 $info[] = html_writer::tag('span', get_string('updateavailable_version', 'core_admin', $updateinfo->version),
778 array('class' => 'info version'));
781 if (isset($updateinfo->maturity)) {
782 $info[] = html_writer::tag('span', get_string('maturity'.$updateinfo->maturity, 'core_admin'),
783 array('class' => 'info maturity'));
784 $boxclasses .= ' maturity'.$updateinfo->maturity;
787 if (isset($updateinfo->download)) {
788 $info[] = html_writer::link($updateinfo->download, get_string('download'), array('class' => 'info download'));
791 if (isset($updateinfo->url)) {
792 $info[] = html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin'),
793 array('class' => 'info more'));
796 $box = $this->output->box_start($boxclasses);
797 $box .= $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $info), '');
798 $box .= $this->output->box_end();
800 return $box;
804 * Display a link to the release notes.
805 * @return string HTML to output.
807 protected function release_notes_link() {
808 $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/dev/Releases');
809 $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
810 return $this->box($releasenoteslink, 'generalbox releasenoteslink');
814 * Display the reload link that appears on several upgrade/install pages.
815 * @return string HTML to output.
817 function upgrade_reload($url) {
818 return html_writer::empty_tag('br') .
819 html_writer::tag('div',
820 html_writer::link($url, $this->pix_icon('i/reload', '', '', array('class' => 'icon icon-pre')) .
821 get_string('reload'), array('title' => get_string('reload'))),
822 array('class' => 'continuebutton')) . html_writer::empty_tag('br');
826 * Displays all known plugins and information about their installation or upgrade
828 * This default implementation renders all plugins into one big table. The rendering
829 * options support:
830 * (bool)full = false: whether to display up-to-date plugins, too
831 * (bool)xdep = false: display the plugins with unsatisified dependecies only
833 * @param core_plugin_manager $pluginman provides information about the plugins.
834 * @param int $version the version of the Moodle code from version.php.
835 * @param array $options rendering options
836 * @return string HTML code
838 public function plugins_check_table(core_plugin_manager $pluginman, $version, array $options = array()) {
839 global $CFG;
841 $plugininfo = $pluginman->get_plugins();
843 if (empty($plugininfo)) {
844 return '';
847 $options['full'] = isset($options['full']) ? (bool)$options['full'] : false;
848 $options['xdep'] = isset($options['xdep']) ? (bool)$options['xdep'] : false;
850 $table = new html_table();
851 $table->id = 'plugins-check';
852 $table->head = array(
853 get_string('displayname', 'core_plugin'),
854 get_string('rootdir', 'core_plugin'),
855 get_string('source', 'core_plugin'),
856 get_string('versiondb', 'core_plugin'),
857 get_string('versiondisk', 'core_plugin'),
858 get_string('requires', 'core_plugin'),
859 get_string('status', 'core_plugin'),
861 $table->colclasses = array(
862 'displayname', 'rootdir', 'source', 'versiondb', 'versiondisk', 'requires', 'status',
864 $table->data = array();
866 $numofhighlighted = array(); // number of highlighted rows per this subsection
868 foreach ($plugininfo as $type => $plugins) {
870 $header = new html_table_cell($pluginman->plugintype_name_plural($type));
871 $header->header = true;
872 $header->colspan = count($table->head);
873 $header = new html_table_row(array($header));
874 $header->attributes['class'] = 'plugintypeheader type-' . $type;
876 $numofhighlighted[$type] = 0;
878 if (empty($plugins) and $options['full']) {
879 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
880 $msg->colspan = count($table->head);
881 $row = new html_table_row(array($msg));
882 $row->attributes['class'] .= 'msg msg-noneinstalled';
883 $table->data[] = $header;
884 $table->data[] = $row;
885 continue;
888 $plugintyperows = array();
890 foreach ($plugins as $name => $plugin) {
891 $row = new html_table_row();
892 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
894 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name, null)) {
895 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
896 } else {
897 $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon'));
899 $displayname = $icon . ' ' . $plugin->displayname;
900 $displayname = new html_table_cell($displayname);
902 $rootdir = new html_table_cell($plugin->get_dir());
904 if ($isstandard = $plugin->is_standard()) {
905 $row->attributes['class'] .= ' standard';
906 $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
907 } else {
908 $row->attributes['class'] .= ' extension';
909 $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
912 $versiondb = new html_table_cell($plugin->versiondb);
913 $versiondisk = new html_table_cell($plugin->versiondisk);
915 $statuscode = $plugin->get_status();
916 $row->attributes['class'] .= ' status-' . $statuscode;
917 $status = get_string('status_' . $statuscode, 'core_plugin');
919 $availableupdates = $plugin->available_updates();
920 if (!empty($availableupdates) and empty($CFG->disableupdatenotifications)) {
921 foreach ($availableupdates as $availableupdate) {
922 $status .= $this->plugin_available_update_info($availableupdate);
926 $status = new html_table_cell($status);
928 $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version));
930 $statusisboring = in_array($statuscode, array(
931 core_plugin_manager::PLUGIN_STATUS_NODB, core_plugin_manager::PLUGIN_STATUS_UPTODATE));
933 $coredependency = $plugin->is_core_dependency_satisfied($version);
934 $otherpluginsdependencies = $pluginman->are_dependencies_satisfied($plugin->get_other_required_plugins());
935 $dependenciesok = $coredependency && $otherpluginsdependencies;
937 if ($options['xdep']) {
938 // we want to see only plugins with failed dependencies
939 if ($dependenciesok) {
940 continue;
943 } else if ($statusisboring and $dependenciesok and empty($availableupdates)) {
944 // no change is going to happen to the plugin - display it only
945 // if the user wants to see the full list
946 if (empty($options['full'])) {
947 continue;
951 // ok, the plugin should be displayed
952 $numofhighlighted[$type]++;
954 $row->cells = array($displayname, $rootdir, $source,
955 $versiondb, $versiondisk, $requires, $status);
956 $plugintyperows[] = $row;
959 if (empty($numofhighlighted[$type]) and empty($options['full'])) {
960 continue;
963 $table->data[] = $header;
964 $table->data = array_merge($table->data, $plugintyperows);
967 $sumofhighlighted = array_sum($numofhighlighted);
969 if ($options['xdep']) {
970 // we do not want to display no heading and links in this mode
971 $out = '';
973 } else if ($sumofhighlighted == 0) {
974 $out = $this->output->container_start('nonehighlighted', 'plugins-check-info');
975 $out .= $this->output->heading(get_string('nonehighlighted', 'core_plugin'));
976 if (empty($options['full'])) {
977 $out .= html_writer::link(new moodle_url('/admin/index.php',
978 array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1, 'cache' => 0)),
979 get_string('nonehighlightedinfo', 'core_plugin'));
981 $out .= $this->output->container_end();
983 } else {
984 $out = $this->output->container_start('somehighlighted', 'plugins-check-info');
985 $out .= $this->output->heading(get_string('somehighlighted', 'core_plugin', $sumofhighlighted));
986 if (empty($options['full'])) {
987 $out .= html_writer::link(new moodle_url('/admin/index.php',
988 array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1, 'cache' => 0)),
989 get_string('somehighlightedinfo', 'core_plugin'));
990 } else {
991 $out .= html_writer::link(new moodle_url('/admin/index.php',
992 array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 0, 'cache' => 0)),
993 get_string('somehighlightedonly', 'core_plugin'));
995 $out .= $this->output->container_end();
998 if ($sumofhighlighted > 0 or $options['full']) {
999 $out .= html_writer::table($table);
1002 return $out;
1006 * Formats the information that needs to go in the 'Requires' column.
1007 * @param \core\plugininfo\base $plugin the plugin we are rendering the row for.
1008 * @param core_plugin_manager $pluginman provides data on all the plugins.
1009 * @param string $version
1010 * @return string HTML code
1012 protected function required_column(\core\plugininfo\base $plugin, core_plugin_manager $pluginman, $version) {
1013 $requires = array();
1015 if (!empty($plugin->versionrequires)) {
1016 if ($plugin->versionrequires <= $version) {
1017 $class = 'requires-ok';
1018 } else {
1019 $class = 'requires-failed';
1021 $requires[] = html_writer::tag('li',
1022 get_string('moodleversion', 'core_plugin', $plugin->versionrequires),
1023 array('class' => $class));
1026 foreach ($plugin->get_other_required_plugins() as $component => $requiredversion) {
1027 $ok = true;
1028 $otherplugin = $pluginman->get_plugin_info($component);
1030 if (is_null($otherplugin)) {
1031 $ok = false;
1032 } else if ($requiredversion != ANY_VERSION and $otherplugin->versiondisk < $requiredversion) {
1033 $ok = false;
1036 if ($ok) {
1037 $class = 'requires-ok';
1038 } else {
1039 $class = 'requires-failed';
1042 if ($requiredversion != ANY_VERSION) {
1043 $str = 'otherpluginversion';
1044 } else {
1045 $str = 'otherplugin';
1047 $componenturl = new moodle_url('https://moodle.org/plugins/view.php?plugin='.$component);
1048 $componenturl = html_writer::tag('a', $component, array('href' => $componenturl->out()));
1049 $requires[] = html_writer::tag('li',
1050 get_string($str, 'core_plugin',
1051 array('component' => $componenturl, 'version' => $requiredversion)),
1052 array('class' => $class));
1055 if (!$requires) {
1056 return '';
1058 return html_writer::tag('ul', implode("\n", $requires));
1062 * Prints an overview about the plugins - number of installed, number of extensions etc.
1064 * @param core_plugin_manager $pluginman provides information about the plugins
1065 * @param array $options filtering options
1066 * @return string as usually
1068 public function plugins_overview_panel(core_plugin_manager $pluginman, array $options = array()) {
1069 global $CFG;
1071 $plugininfo = $pluginman->get_plugins();
1073 $numtotal = $numdisabled = $numextension = $numupdatable = 0;
1075 foreach ($plugininfo as $type => $plugins) {
1076 foreach ($plugins as $name => $plugin) {
1077 if ($plugin->get_status() === core_plugin_manager::PLUGIN_STATUS_MISSING) {
1078 continue;
1080 $numtotal++;
1081 if ($plugin->is_enabled() === false) {
1082 $numdisabled++;
1084 if (!$plugin->is_standard()) {
1085 $numextension++;
1087 if (empty($CFG->disableupdatenotifications) and $plugin->available_updates()) {
1088 $numupdatable++;
1093 $info = array();
1094 $filter = array();
1095 $somefilteractive = false;
1096 $info[] = html_writer::tag('span', get_string('numtotal', 'core_plugin', $numtotal), array('class' => 'info total'));
1097 $info[] = html_writer::tag('span', get_string('numdisabled', 'core_plugin', $numdisabled), array('class' => 'info disabled'));
1098 $info[] = html_writer::tag('span', get_string('numextension', 'core_plugin', $numextension), array('class' => 'info extension'));
1099 if ($numextension > 0) {
1100 if (empty($options['contribonly'])) {
1101 $filter[] = html_writer::link(
1102 new moodle_url($this->page->url, array('contribonly' => 1)),
1103 get_string('filtercontribonly', 'core_plugin'),
1104 array('class' => 'filter-item show-contribonly')
1106 } else {
1107 $filter[] = html_writer::tag('span', get_string('filtercontribonlyactive', 'core_plugin'),
1108 array('class' => 'filter-item active show-contribonly'));
1109 $somefilteractive = true;
1112 if ($numupdatable > 0) {
1113 $info[] = html_writer::tag('span', get_string('numupdatable', 'core_plugin', $numupdatable), array('class' => 'info updatable'));
1114 if (empty($options['updatesonly'])) {
1115 $filter[] = html_writer::link(
1116 new moodle_url($this->page->url, array('updatesonly' => 1)),
1117 get_string('filterupdatesonly', 'core_plugin'),
1118 array('class' => 'filter-item show-updatesonly')
1120 } else {
1121 $filter[] = html_writer::tag('span', get_string('filterupdatesonlyactive', 'core_plugin'),
1122 array('class' => 'filter-item active show-updatesonly'));
1123 $somefilteractive = true;
1126 if ($somefilteractive) {
1127 $filter[] = html_writer::link($this->page->url, get_string('filterall', 'core_plugin'), array('class' => 'filter-item show-all'));
1130 $output = $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $info), '', 'plugins-overview-panel');
1132 if (!empty($filter)) {
1133 $output .= $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $filter), '', 'plugins-overview-filter');
1136 return $output;
1140 * Displays all known plugins and links to manage them
1142 * This default implementation renders all plugins into one big table.
1144 * @param core_plugin_manager $pluginman provides information about the plugins.
1145 * @param array $options filtering options
1146 * @return string HTML code
1148 public function plugins_control_panel(core_plugin_manager $pluginman, array $options = array()) {
1149 global $CFG;
1151 $plugininfo = $pluginman->get_plugins();
1153 // Filter the list of plugins according the options.
1154 if (!empty($options['updatesonly'])) {
1155 $updateable = array();
1156 foreach ($plugininfo as $plugintype => $pluginnames) {
1157 foreach ($pluginnames as $pluginname => $pluginfo) {
1158 if (!empty($pluginfo->availableupdates)) {
1159 foreach ($pluginfo->availableupdates as $pluginavailableupdate) {
1160 if ($pluginavailableupdate->version > $pluginfo->versiondisk) {
1161 $updateable[$plugintype][$pluginname] = $pluginfo;
1167 $plugininfo = $updateable;
1170 if (!empty($options['contribonly'])) {
1171 $contribs = array();
1172 foreach ($plugininfo as $plugintype => $pluginnames) {
1173 foreach ($pluginnames as $pluginname => $pluginfo) {
1174 if (!$pluginfo->is_standard()) {
1175 $contribs[$plugintype][$pluginname] = $pluginfo;
1179 $plugininfo = $contribs;
1182 if (empty($plugininfo)) {
1183 return '';
1186 $table = new html_table();
1187 $table->id = 'plugins-control-panel';
1188 $table->head = array(
1189 get_string('displayname', 'core_plugin'),
1190 get_string('source', 'core_plugin'),
1191 get_string('version', 'core_plugin'),
1192 get_string('release', 'core_plugin'),
1193 get_string('availability', 'core_plugin'),
1194 get_string('actions', 'core_plugin'),
1195 get_string('notes','core_plugin'),
1197 $table->headspan = array(1, 1, 1, 1, 1, 2, 1);
1198 $table->colclasses = array(
1199 'pluginname', 'source', 'version', 'release', 'availability', 'settings', 'uninstall', 'notes'
1202 foreach ($plugininfo as $type => $plugins) {
1203 $heading = $pluginman->plugintype_name_plural($type);
1204 $pluginclass = core_plugin_manager::resolve_plugininfo_class($type);
1205 if ($manageurl = $pluginclass::get_manage_url()) {
1206 $heading = html_writer::link($manageurl, $heading);
1208 $header = new html_table_cell(html_writer::tag('span', $heading, array('id'=>'plugin_type_cell_'.$type)));
1209 $header->header = true;
1210 $header->colspan = array_sum($table->headspan);
1211 $header = new html_table_row(array($header));
1212 $header->attributes['class'] = 'plugintypeheader type-' . $type;
1213 $table->data[] = $header;
1215 if (empty($plugins)) {
1216 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
1217 $msg->colspan = array_sum($table->headspan);
1218 $row = new html_table_row(array($msg));
1219 $row->attributes['class'] .= 'msg msg-noneinstalled';
1220 $table->data[] = $row;
1221 continue;
1224 foreach ($plugins as $name => $plugin) {
1225 $row = new html_table_row();
1226 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
1228 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) {
1229 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'icon pluginicon'));
1230 } else {
1231 $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'icon pluginicon noicon'));
1233 $status = $plugin->get_status();
1234 $row->attributes['class'] .= ' status-'.$status;
1235 if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) {
1236 $msg = html_writer::tag('span', get_string('status_missing', 'core_plugin'), array('class' => 'statusmsg'));
1237 } else if ($status === core_plugin_manager::PLUGIN_STATUS_NEW) {
1238 $msg = html_writer::tag('span', get_string('status_new', 'core_plugin'), array('class' => 'statusmsg'));
1239 } else {
1240 $msg = '';
1242 $pluginname = html_writer::tag('div', $icon . '' . $plugin->displayname . ' ' . $msg, array('class' => 'displayname')).
1243 html_writer::tag('div', $plugin->component, array('class' => 'componentname'));
1244 $pluginname = new html_table_cell($pluginname);
1246 if ($plugin->is_standard()) {
1247 $row->attributes['class'] .= ' standard';
1248 $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
1249 } else {
1250 $row->attributes['class'] .= ' extension';
1251 $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
1254 $version = new html_table_cell($plugin->versiondb);
1255 $release = new html_table_cell($plugin->release);
1257 $isenabled = $plugin->is_enabled();
1258 if (is_null($isenabled)) {
1259 $availability = new html_table_cell('');
1260 } else if ($isenabled) {
1261 $row->attributes['class'] .= ' enabled';
1262 $availability = new html_table_cell(get_string('pluginenabled', 'core_plugin'));
1263 } else {
1264 $row->attributes['class'] .= ' disabled';
1265 $availability = new html_table_cell(get_string('plugindisabled', 'core_plugin'));
1268 $settingsurl = $plugin->get_settings_url();
1269 if (!is_null($settingsurl)) {
1270 $settings = html_writer::link($settingsurl, get_string('settings', 'core_plugin'), array('class' => 'settings'));
1271 } else {
1272 $settings = '';
1274 $settings = new html_table_cell($settings);
1276 if ($uninstallurl = $pluginman->get_uninstall_url($plugin->component, 'overview')) {
1277 $uninstall = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin'));
1278 } else {
1279 $uninstall = '';
1281 $uninstall = new html_table_cell($uninstall);
1283 $requriedby = $pluginman->other_plugins_that_require($plugin->component);
1284 if ($requriedby) {
1285 $requiredby = html_writer::tag('div', get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
1286 array('class' => 'requiredby'));
1287 } else {
1288 $requiredby = '';
1291 $updateinfo = '';
1292 if (empty($CFG->disableupdatenotifications) and is_array($plugin->available_updates())) {
1293 foreach ($plugin->available_updates() as $availableupdate) {
1294 $updateinfo .= $this->plugin_available_update_info($availableupdate);
1298 $notes = new html_table_cell($requiredby.$updateinfo);
1300 $row->cells = array(
1301 $pluginname, $source, $version, $release, $availability, $settings, $uninstall, $notes
1303 $table->data[] = $row;
1307 return html_writer::table($table);
1311 * Helper method to render the information about the available plugin update
1313 * The passed objects always provides at least the 'version' property containing
1314 * the (higher) version of the plugin available.
1316 * @param \core\update\info $updateinfo information about the available update for the plugin
1318 protected function plugin_available_update_info(\core\update\info $updateinfo) {
1320 $boxclasses = 'pluginupdateinfo';
1321 $info = array();
1323 if (isset($updateinfo->release)) {
1324 $info[] = html_writer::tag('span', get_string('updateavailable_release', 'core_plugin', $updateinfo->release),
1325 array('class' => 'info release'));
1328 if (isset($updateinfo->maturity)) {
1329 $info[] = html_writer::tag('span', get_string('maturity'.$updateinfo->maturity, 'core_admin'),
1330 array('class' => 'info maturity'));
1331 $boxclasses .= ' maturity'.$updateinfo->maturity;
1334 if (isset($updateinfo->download)) {
1335 $info[] = html_writer::link($updateinfo->download, get_string('download'), array('class' => 'info download'));
1338 if (isset($updateinfo->url)) {
1339 $info[] = html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin'),
1340 array('class' => 'info more'));
1343 $box = $this->output->box_start($boxclasses);
1344 $box .= html_writer::tag('div', get_string('updateavailable', 'core_plugin', $updateinfo->version), array('class' => 'version'));
1345 $box .= $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $info), '');
1347 $deployer = \core\update\deployer::instance();
1348 if ($deployer->initialized()) {
1349 $impediments = $deployer->deployment_impediments($updateinfo);
1350 if (empty($impediments)) {
1351 $widget = $deployer->make_confirm_widget($updateinfo);
1352 $box .= $this->output->render($widget);
1353 } else {
1354 if (isset($impediments['notwritable'])) {
1355 $box .= $this->output->help_icon('notwritable', 'core_plugin', get_string('notwritable', 'core_plugin'));
1357 if (isset($impediments['notdownloadable'])) {
1358 $box .= $this->output->help_icon('notdownloadable', 'core_plugin', get_string('notdownloadable', 'core_plugin'));
1363 $box .= $this->output->box_end();
1365 return $box;
1369 * This function will render one beautiful table with all the environmental
1370 * configuration and how it suits Moodle needs.
1372 * @param boolean $result final result of the check (true/false)
1373 * @param array $environment_results array of results gathered
1374 * @return string HTML to output.
1376 public function environment_check_table($result, $environment_results) {
1377 global $CFG;
1379 // Table headers
1380 $servertable = new html_table();//table for server checks
1381 $servertable->head = array(
1382 get_string('name'),
1383 get_string('info'),
1384 get_string('report'),
1385 get_string('status'),
1387 $servertable->colclasses = array('centeralign name', 'centeralign status', 'leftalign report', 'centeralign info');
1388 $servertable->attributes['class'] = 'admintable environmenttable generaltable';
1389 $servertable->id = 'serverstatus';
1391 $serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
1393 $othertable = new html_table();//table for custom checks
1394 $othertable->head = array(
1395 get_string('info'),
1396 get_string('report'),
1397 get_string('status'),
1399 $othertable->colclasses = array('aligncenter info', 'alignleft report', 'aligncenter status');
1400 $othertable->attributes['class'] = 'admintable environmenttable generaltable';
1401 $othertable->id = 'otherserverstatus';
1403 $otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
1405 // Iterate over each environment_result
1406 $continue = true;
1407 foreach ($environment_results as $environment_result) {
1408 $errorline = false;
1409 $warningline = false;
1410 $stringtouse = '';
1411 if ($continue) {
1412 $type = $environment_result->getPart();
1413 $info = $environment_result->getInfo();
1414 $status = $environment_result->getStatus();
1415 $error_code = $environment_result->getErrorCode();
1416 // Process Report field
1417 $rec = new stdClass();
1418 // Something has gone wrong at parsing time
1419 if ($error_code) {
1420 $stringtouse = 'environmentxmlerror';
1421 $rec->error_code = $error_code;
1422 $status = get_string('error');
1423 $errorline = true;
1424 $continue = false;
1427 if ($continue) {
1428 if ($rec->needed = $environment_result->getNeededVersion()) {
1429 // We are comparing versions
1430 $rec->current = $environment_result->getCurrentVersion();
1431 if ($environment_result->getLevel() == 'required') {
1432 $stringtouse = 'environmentrequireversion';
1433 } else {
1434 $stringtouse = 'environmentrecommendversion';
1437 } else if ($environment_result->getPart() == 'custom_check') {
1438 // We are checking installed & enabled things
1439 if ($environment_result->getLevel() == 'required') {
1440 $stringtouse = 'environmentrequirecustomcheck';
1441 } else {
1442 $stringtouse = 'environmentrecommendcustomcheck';
1445 } else if ($environment_result->getPart() == 'php_setting') {
1446 if ($status) {
1447 $stringtouse = 'environmentsettingok';
1448 } else if ($environment_result->getLevel() == 'required') {
1449 $stringtouse = 'environmentmustfixsetting';
1450 } else {
1451 $stringtouse = 'environmentshouldfixsetting';
1454 } else {
1455 if ($environment_result->getLevel() == 'required') {
1456 $stringtouse = 'environmentrequireinstall';
1457 } else {
1458 $stringtouse = 'environmentrecommendinstall';
1462 // Calculate the status value
1463 if ($environment_result->getBypassStr() != '') { //Handle bypassed result (warning)
1464 $status = get_string('bypassed');
1465 $warningline = true;
1466 } else if ($environment_result->getRestrictStr() != '') { //Handle restricted result (error)
1467 $status = get_string('restricted');
1468 $errorline = true;
1469 } else {
1470 if ($status) { //Handle ok result (ok)
1471 $status = get_string('ok');
1472 } else {
1473 if ($environment_result->getLevel() == 'optional') {//Handle check result (warning)
1474 $status = get_string('check');
1475 $warningline = true;
1476 } else { //Handle error result (error)
1477 $status = get_string('check');
1478 $errorline = true;
1484 // Build the text
1485 $linkparts = array();
1486 $linkparts[] = 'admin/environment';
1487 $linkparts[] = $type;
1488 if (!empty($info)){
1489 $linkparts[] = $info;
1491 if (empty($CFG->docroot)) {
1492 $report = get_string($stringtouse, 'admin', $rec);
1493 } else {
1494 $report = $this->doc_link(join($linkparts, '/'), get_string($stringtouse, 'admin', $rec));
1497 // Format error or warning line
1498 if ($errorline || $warningline) {
1499 $messagetype = $errorline? 'error':'warn';
1500 } else {
1501 $messagetype = 'ok';
1503 $status = '<span class="'.$messagetype.'">'.$status.'</span>';
1504 // Here we'll store all the feedback found
1505 $feedbacktext = '';
1506 // Append the feedback if there is some
1507 $feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), $messagetype);
1508 //Append the bypass if there is some
1509 $feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'warn');
1510 //Append the restrict if there is some
1511 $feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'error');
1513 $report .= $feedbacktext;
1515 // Add the row to the table
1516 if ($environment_result->getPart() == 'custom_check'){
1517 $otherdata[$messagetype][] = array ($info, $report, $status);
1518 } else {
1519 $serverdata[$messagetype][] = array ($type, $info, $report, $status);
1524 //put errors first in
1525 $servertable->data = array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']);
1526 $othertable->data = array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']);
1528 // Print table
1529 $output = '';
1530 $output .= $this->heading(get_string('serverchecks', 'admin'));
1531 $output .= html_writer::table($servertable);
1532 if (count($othertable->data)){
1533 $output .= $this->heading(get_string('customcheck', 'admin'));
1534 $output .= html_writer::table($othertable);
1537 // Finally, if any error has happened, print the summary box
1538 if (!$result) {
1539 $output .= $this->box(get_string('environmenterrortodo', 'admin'), 'environmentbox errorbox');
1542 return $output;