Merge branch 'MDL-51227-master' of https://github.com/dthies/moodle
[moodle.git] / admin / renderer.php
blob40036daa07dbb8800730a6aba67ebd8a215e791e
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($this->page->url, array(
47 'lang' => $CFG->lang, 'agreelicense' => 1)), get_string('continue'), 'get');
49 $output .= $this->header();
50 $output .= $this->heading('<a href="http://moodle.org">Moodle</a> - Modular Object-Oriented Dynamic Learning Environment');
51 $output .= $this->heading(get_string('copyrightnotice'));
52 $output .= $this->box($copyrightnotice, 'copyrightnotice');
53 $output .= html_writer::empty_tag('br');
54 $output .= $this->confirm(get_string('doyouagree'), $continue, "http://docs.moodle.org/dev/License");
55 $output .= $this->footer();
57 return $output;
60 /**
61 * Display 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() {
67 $output = '';
68 $output .= $this->header();
69 $output .= $this->heading(get_string('upgradestalefiles', 'admin'));
70 $output .= $this->box_start('generalbox', 'notice');
71 $output .= format_text(get_string('upgradestalefilesinfo', 'admin', get_docs_url('Upgrading')), FORMAT_MARKDOWN);
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();
77 return $output;
80 /**
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) {
89 global $CFG;
90 $output = '';
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);
99 if (!$envstatus) {
100 $output .= $this->upgrade_reload(new moodle_url($this->page->url, array('agreelicense' => 1, 'lang' => $CFG->lang)));
101 } else {
102 $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
103 $output .= $this->continue_button(new moodle_url($this->page->url, array(
104 'agreelicense' => 1, 'confirmrelease' => 1, 'lang' => $CFG->lang)));
107 $output .= $this->footer();
108 return $output;
112 * Displays the list of plugins with unsatisfied dependencies
114 * @param double|string|int $version Moodle on-disk version
115 * @param array $failed list of plugins with unsatisfied dependecies
116 * @param moodle_url $reloadurl URL of the page to recheck the dependencies
117 * @return string HTML
119 public function unsatisfied_dependencies_page($version, array $failed, moodle_url $reloadurl) {
120 $output = '';
122 $output .= $this->header();
123 $output .= $this->heading(get_string('pluginscheck', 'admin'));
124 $output .= $this->warning(get_string('pluginscheckfailed', 'admin', array('pluginslist' => implode(', ', array_unique($failed)))));
125 $output .= $this->plugins_check_table(core_plugin_manager::instance(), $version, array('xdep' => true));
126 $output .= $this->warning(get_string('pluginschecktodo', 'admin'));
127 $output .= $this->continue_button($reloadurl);
129 $output .= $this->footer();
131 return $output;
135 * Display the 'You are about to upgrade Moodle' page. The first page
136 * during upgrade.
137 * @param string $strnewversion
138 * @param int $maturity
139 * @param string $testsite
140 * @return string HTML to output.
142 public function upgrade_confirm_page($strnewversion, $maturity, $testsite) {
143 $output = '';
145 $continueurl = new moodle_url($this->page->url, array('confirmupgrade' => 1, 'cache' => 0));
146 $continue = new single_button($continueurl, get_string('continue'), 'get');
147 $cancelurl = new moodle_url('/admin/index.php');
149 $output .= $this->header();
150 $output .= $this->maturity_warning($maturity);
151 $output .= $this->test_site_warning($testsite);
152 $output .= $this->confirm(get_string('upgradesure', 'admin', $strnewversion), $continue, $cancelurl);
153 $output .= $this->footer();
155 return $output;
159 * Display the environment page during the upgrade process.
160 * @param string $release
161 * @param boolean $envstatus final result of env check (true/false)
162 * @param array $environment_results array of results gathered
163 * @return string HTML to output.
165 public function upgrade_environment_page($release, $envstatus, $environment_results) {
166 global $CFG;
167 $output = '';
169 $output .= $this->header();
170 $output .= $this->heading("Moodle $release");
171 $output .= $this->release_notes_link();
172 $output .= $this->environment_check_table($envstatus, $environment_results);
174 if (!$envstatus) {
175 $output .= $this->upgrade_reload(new moodle_url($this->page->url, array('confirmupgrade' => 1, 'cache' => 0)));
177 } else {
178 $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
180 if (empty($CFG->skiplangupgrade) and current_language() !== 'en') {
181 $output .= $this->box(get_string('langpackwillbeupdated', 'admin'), 'generalbox', 'notice');
184 $output .= $this->continue_button(new moodle_url($this->page->url, array(
185 'confirmupgrade' => 1, 'confirmrelease' => 1, 'cache' => 0)));
188 $output .= $this->footer();
190 return $output;
194 * Display the upgrade page that lists all the plugins that require attention.
195 * @param core_plugin_manager $pluginman provides information about the plugins.
196 * @param \core\update\checker $checker provides information about available updates.
197 * @param int $version the version of the Moodle code from version.php.
198 * @param bool $showallplugins
199 * @param moodle_url $reloadurl
200 * @param moodle_url $continueurl
201 * @return string HTML to output.
203 public function upgrade_plugin_check_page(core_plugin_manager $pluginman, \core\update\checker $checker,
204 $version, $showallplugins, $reloadurl, $continueurl) {
205 global $CFG;
207 $output = '';
209 $output .= $this->header();
210 $output .= $this->box_start('generalbox');
211 $output .= $this->container_start('generalbox', 'notice');
212 $output .= html_writer::tag('p', get_string('pluginchecknotice', 'core_plugin'));
213 if (empty($CFG->disableupdatenotifications)) {
214 $output .= $this->container_start('checkforupdates');
215 $output .= $this->single_button(new moodle_url($reloadurl, array('fetchupdates' => 1)), get_string('checkforupdates', 'core_plugin'));
216 if ($timefetched = $checker->get_last_timefetched()) {
217 $output .= $this->container(get_string('checkforupdateslast', 'core_plugin',
218 userdate($timefetched, get_string('strftimedatetime', 'core_langconfig'))));
220 $output .= $this->container_end();
222 $output .= $this->container_end();
224 $output .= $this->plugins_check_table($pluginman, $version, array('full' => $showallplugins));
225 $output .= $this->box_end();
226 $output .= $this->upgrade_reload($reloadurl);
228 if ($pluginman->some_plugins_updatable()) {
229 $output .= $this->container_start('upgradepluginsinfo');
230 $output .= $this->help_icon('upgradepluginsinfo', 'core_admin', get_string('upgradepluginsfirst', 'core_admin'));
231 $output .= $this->container_end();
234 $button = new single_button($continueurl, get_string('upgradestart', 'admin'), 'get');
235 $button->class = 'continuebutton';
236 $output .= $this->render($button);
237 $output .= $this->footer();
239 return $output;
243 * Prints a page with a summary of plugin deployment to be confirmed.
245 * @param \core\update\deployer $deployer
246 * @param array $data deployer's data package as returned by {@link \core\update\deployer::submitted_data()}
247 * @return string
249 public function upgrade_plugin_confirm_deploy_page(\core\update\deployer $deployer, array $data) {
251 if (!$deployer->initialized()) {
252 throw new coding_exception('Unable to render a page for non-initialized deployer.');
255 if (empty($data['updateinfo'])) {
256 throw new coding_exception('Missing required data component.');
259 $updateinfo = $data['updateinfo'];
261 $output = '';
262 $output .= $this->header();
263 $output .= $this->container_start('generalbox updateplugin', 'notice');
265 $a = new stdClass();
266 if (get_string_manager()->string_exists('pluginname', $updateinfo->component)) {
267 $a->name = get_string('pluginname', $updateinfo->component);
268 } else {
269 $a->name = $updateinfo->component;
272 if (isset($updateinfo->release)) {
273 $a->version = $updateinfo->release . ' (' . $updateinfo->version . ')';
274 } else {
275 $a->version = $updateinfo->version;
277 $a->url = $updateinfo->download;
279 $output .= $this->output->heading(get_string('updatepluginconfirm', 'core_plugin'));
280 $output .= $this->output->container(format_text(get_string('updatepluginconfirminfo', 'core_plugin', $a)), 'updatepluginconfirminfo');
281 $output .= $this->output->container(get_string('updatepluginconfirmwarning', 'core_plugin', 'updatepluginconfirmwarning'));
283 if ($repotype = $deployer->plugin_external_source($data['updateinfo'])) {
284 $output .= $this->output->container(get_string('updatepluginconfirmexternal', 'core_plugin', $repotype), 'updatepluginconfirmexternal');
287 $widget = $deployer->make_execution_widget($data['updateinfo'], $data['returnurl']);
288 $output .= $this->output->render($widget);
290 $output .= $this->output->single_button($data['callerurl'], get_string('cancel', 'core'), 'get');
292 $output .= $this->container_end();
293 $output .= $this->footer();
295 return $output;
299 * Display the admin notifications page.
300 * @param int $maturity
301 * @param bool $insecuredataroot warn dataroot is invalid
302 * @param bool $errorsdisplayed warn invalid dispaly error setting
303 * @param bool $cronoverdue warn cron not running
304 * @param bool $dbproblems warn db has problems
305 * @param bool $maintenancemode warn in maintenance mode
306 * @param bool $buggyiconvnomb warn iconv problems
307 * @param array|null $availableupdates array of \core\update\info objects or null
308 * @param int|null $availableupdatesfetch timestamp of the most recent updates fetch or null (unknown)
309 * @param string[] $cachewarnings An array containing warnings from the Cache API.
311 * @return string HTML to output.
313 public function admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed,
314 $cronoverdue, $dbproblems, $maintenancemode, $availableupdates, $availableupdatesfetch,
315 $buggyiconvnomb, $registered, array $cachewarnings = array()) {
316 global $CFG;
317 $output = '';
319 $output .= $this->header();
320 $output .= $this->maturity_info($maturity);
321 $output .= empty($CFG->disableupdatenotifications) ? $this->available_updates($availableupdates, $availableupdatesfetch) : '';
322 $output .= $this->insecure_dataroot_warning($insecuredataroot);
323 $output .= $this->display_errors_warning($errorsdisplayed);
324 $output .= $this->buggy_iconv_warning($buggyiconvnomb);
325 $output .= $this->cron_overdue_warning($cronoverdue);
326 $output .= $this->db_problems($dbproblems);
327 $output .= $this->maintenance_mode_warning($maintenancemode);
328 $output .= $this->cache_warnings($cachewarnings);
329 $output .= $this->registration_warning($registered);
331 //////////////////////////////////////////////////////////////////////////////////////////////////
332 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
333 $output .= $this->moodle_copyright();
334 //////////////////////////////////////////////////////////////////////////////////////////////////
336 $output .= $this->footer();
338 return $output;
342 * Display the plugin management page (admin/plugins.php).
344 * The filtering options array may contain following items:
345 * bool contribonly - show only contributed extensions
346 * bool updatesonly - show only plugins with an available update
348 * @param core_plugin_manager $pluginman
349 * @param \core\update\checker $checker
350 * @param array $options filtering options
351 * @return string HTML to output.
353 public function plugin_management_page(core_plugin_manager $pluginman, \core\update\checker $checker, array $options = array()) {
354 global $CFG;
356 $output = '';
358 $output .= $this->header();
359 $output .= $this->heading(get_string('pluginsoverview', 'core_admin'));
360 $output .= $this->plugins_overview_panel($pluginman, $options);
362 if (empty($CFG->disableupdatenotifications)) {
363 $output .= $this->container_start('checkforupdates');
364 $output .= $this->single_button(
365 new moodle_url($this->page->url, array_merge($options, array('fetchremote' => 1))),
366 get_string('checkforupdates', 'core_plugin')
368 if ($timefetched = $checker->get_last_timefetched()) {
369 $output .= $this->container(get_string('checkforupdateslast', 'core_plugin',
370 userdate($timefetched, get_string('strftimedatetime', 'core_langconfig'))));
372 $output .= $this->container_end();
375 $output .= $this->box($this->plugins_control_panel($pluginman, $options), 'generalbox');
376 $output .= $this->footer();
378 return $output;
382 * Display a page to confirm the plugin uninstallation.
384 * @param core_plugin_manager $pluginman
385 * @param \core\plugininfo\base $pluginfo
386 * @param moodle_url $continueurl URL to continue after confirmation
387 * @param moodle_url $cancelurl URL to to go if cancelled
388 * @return string
390 public function plugin_uninstall_confirm_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, moodle_url $continueurl, moodle_url $cancelurl) {
391 $output = '';
393 $pluginname = $pluginman->plugin_name($pluginfo->component);
395 $confirm = '<p>' . get_string('uninstallconfirm', 'core_plugin', array('name' => $pluginname)) . '</p>';
396 if ($extraconfirm = $pluginfo->get_uninstall_extra_warning()) {
397 $confirm .= $extraconfirm;
400 $output .= $this->output->header();
401 $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
402 $output .= $this->output->confirm($confirm, $continueurl, $cancelurl);
403 $output .= $this->output->footer();
405 return $output;
409 * Display a page with results of plugin uninstallation and offer removal of plugin files.
411 * @param core_plugin_manager $pluginman
412 * @param \core\plugininfo\base $pluginfo
413 * @param progress_trace_buffer $progress
414 * @param moodle_url $continueurl URL to continue to remove the plugin folder
415 * @return string
417 public function plugin_uninstall_results_removable_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo,
418 progress_trace_buffer $progress, moodle_url $continueurl) {
419 $output = '';
421 $pluginname = $pluginman->plugin_name($pluginfo->component);
423 // Do not show navigation here, they must click one of the buttons.
424 $this->page->set_pagelayout('maintenance');
425 $this->page->set_cacheable(false);
427 $output .= $this->output->header();
428 $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
430 $output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
432 $confirm = $this->output->container(get_string('uninstalldeleteconfirm', 'core_plugin',
433 array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'uninstalldeleteconfirm');
435 if ($repotype = $pluginman->plugin_external_source($pluginfo->component)) {
436 $confirm .= $this->output->container(get_string('uninstalldeleteconfirmexternal', 'core_plugin', $repotype),
437 'uninstalldeleteconfirmexternal');
440 // After any uninstall we must execute full upgrade to finish the cleanup!
441 $output .= $this->output->confirm($confirm, $continueurl, new moodle_url('/admin/index.php'));
442 $output .= $this->output->footer();
444 return $output;
448 * Display a page with results of plugin uninstallation and inform about the need to remove plugin files manually.
450 * @param core_plugin_manager $pluginman
451 * @param \core\plugininfo\base $pluginfo
452 * @param progress_trace_buffer $progress
453 * @return string
455 public function plugin_uninstall_results_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, progress_trace_buffer $progress) {
456 $output = '';
458 $pluginname = $pluginfo->component;
460 $output .= $this->output->header();
461 $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
463 $output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
465 $output .= $this->output->box(get_string('uninstalldelete', 'core_plugin',
466 array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'generalbox uninstalldelete');
467 $output .= $this->output->continue_button(new moodle_url('/admin/index.php'));
468 $output .= $this->output->footer();
470 return $output;
474 * Display the plugin management page (admin/environment.php).
475 * @param array $versions
476 * @param string $version
477 * @param boolean $envstatus final result of env check (true/false)
478 * @param array $environment_results array of results gathered
479 * @return string HTML to output.
481 public function environment_check_page($versions, $version, $envstatus, $environment_results) {
482 $output = '';
483 $output .= $this->header();
485 // Print the component download link
486 $output .= html_writer::tag('div', html_writer::link(
487 new moodle_url('/admin/environment.php', array('action' => 'updatecomponent', 'sesskey' => sesskey())),
488 get_string('updatecomponent', 'admin')),
489 array('class' => 'reportlink'));
491 // Heading.
492 $output .= $this->heading(get_string('environment', 'admin'));
494 // Box with info and a menu to choose the version.
495 $output .= $this->box_start();
496 $output .= html_writer::tag('div', get_string('adminhelpenvironment'));
497 $select = new single_select(new moodle_url('/admin/environment.php'), 'version', $versions, $version, null);
498 $select->label = get_string('moodleversion');
499 $output .= $this->render($select);
500 $output .= $this->box_end();
502 // The results
503 $output .= $this->environment_check_table($envstatus, $environment_results);
505 $output .= $this->footer();
506 return $output;
510 * Output a warning message, of the type that appears on the admin notifications page.
511 * @param string $message the message to display.
512 * @param string $type type class
513 * @return string HTML to output.
515 protected function warning($message, $type = 'warning') {
516 return $this->box($message, 'generalbox admin' . $type);
520 * Render an appropriate message if dataroot is insecure.
521 * @param bool $insecuredataroot
522 * @return string HTML to output.
524 protected function insecure_dataroot_warning($insecuredataroot) {
525 global $CFG;
527 if ($insecuredataroot == INSECURE_DATAROOT_WARNING) {
528 return $this->warning(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot));
530 } else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) {
531 return $this->warning(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'error');
533 } else {
534 return '';
539 * Render an appropriate message if dataroot is insecure.
540 * @param bool $errorsdisplayed
541 * @return string HTML to output.
543 protected function display_errors_warning($errorsdisplayed) {
544 if (!$errorsdisplayed) {
545 return '';
548 return $this->warning(get_string('displayerrorswarning', 'admin'));
552 * Render an appropriate message if iconv is buggy and mbstring missing.
553 * @param bool $buggyiconvnomb
554 * @return string HTML to output.
556 protected function buggy_iconv_warning($buggyiconvnomb) {
557 if (!$buggyiconvnomb) {
558 return '';
561 return $this->warning(get_string('warningiconvbuggy', 'admin'));
565 * Render an appropriate message if cron has not been run recently.
566 * @param bool $cronoverdue
567 * @return string HTML to output.
569 public function cron_overdue_warning($cronoverdue) {
570 global $CFG;
571 if (!$cronoverdue) {
572 return '';
575 if (empty($CFG->cronclionly)) {
576 $url = new moodle_url('/admin/cron.php');
577 if (!empty($CFG->cronremotepassword)) {
578 $url = new moodle_url('/admin/cron.php', array('password' => $CFG->cronremotepassword));
581 return $this->warning(get_string('cronwarning', 'admin', $url->out()) . '&nbsp;' .
582 $this->help_icon('cron', 'admin'));
585 // $CFG->cronclionly is not empty: cron can run only from CLI.
586 return $this->warning(get_string('cronwarningcli', 'admin') . '&nbsp;' .
587 $this->help_icon('cron', 'admin'));
591 * Render an appropriate message if there are any problems with the DB set-up.
592 * @param bool $dbproblems
593 * @return string HTML to output.
595 public function db_problems($dbproblems) {
596 if (!$dbproblems) {
597 return '';
600 return $this->warning($dbproblems);
604 * Renders cache warnings if there are any.
606 * @param string[] $cachewarnings
607 * @return string
609 public function cache_warnings(array $cachewarnings) {
610 if (!count($cachewarnings)) {
611 return '';
613 return join("\n", array_map(array($this, 'warning'), $cachewarnings));
617 * Render an appropriate message if the site in in maintenance mode.
618 * @param bool $maintenancemode
619 * @return string HTML to output.
621 public function maintenance_mode_warning($maintenancemode) {
622 if (!$maintenancemode) {
623 return '';
626 $url = new moodle_url('/admin/settings.php', array('section' => 'maintenancemode'));
627 $url = $url->out(); // get_string() does not support objects in params
629 return $this->warning(get_string('sitemaintenancewarning2', 'admin', $url));
633 * Display a warning about installing development code if necesary.
634 * @param int $maturity
635 * @return string HTML to output.
637 protected function maturity_warning($maturity) {
638 if ($maturity == MATURITY_STABLE) {
639 return ''; // No worries.
642 $maturitylevel = get_string('maturity' . $maturity, 'admin');
643 return $this->warning(
644 $this->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
645 $this->container($this->doc_link('admin/versions', get_string('morehelp'))),
646 'error');
650 * If necessary, displays a warning about upgrading a test site.
652 * @param string $testsite
653 * @return string HTML
655 protected function test_site_warning($testsite) {
657 if (!$testsite) {
658 return '';
661 $warning = (get_string('testsiteupgradewarning', 'admin', $testsite));
662 return $this->warning($warning, 'error');
666 * Output the copyright notice.
667 * @return string HTML to output.
669 protected function moodle_copyright() {
670 global $CFG;
672 //////////////////////////////////////////////////////////////////////////////////////////////////
673 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
674 $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
675 '<a href="http://docs.moodle.org/dev/Releases" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
676 'Copyright &copy; 1999 onwards, Martin Dougiamas<br />'.
677 'and <a href="http://moodle.org/dev">many other contributors</a>.<br />'.
678 '<a href="http://docs.moodle.org/dev/License">GNU Public License</a>';
679 //////////////////////////////////////////////////////////////////////////////////////////////////
681 return $this->box($copyrighttext, 'copyright');
685 * Display a warning about installing development code if necesary.
686 * @param int $maturity
687 * @return string HTML to output.
689 protected function maturity_info($maturity) {
690 if ($maturity == MATURITY_STABLE) {
691 return ''; // No worries.
694 $level = 'warning';
696 if ($maturity == MATURITY_ALPHA) {
697 $level = 'error';
700 $maturitylevel = get_string('maturity' . $maturity, 'admin');
701 $warningtext = get_string('maturitycoreinfo', 'admin', $maturitylevel);
702 $warningtext .= ' ' . $this->doc_link('admin/versions', get_string('morehelp'));
703 return $this->warning($warningtext, $level);
707 * Displays the info about available Moodle core and plugin updates
709 * The structure of the $updates param has changed since 2.4. It contains not only updates
710 * for the core itself, but also for all other installed plugins.
712 * @param array|null $updates array of (string)component => array of \core\update\info objects or null
713 * @param int|null $fetch timestamp of the most recent updates fetch or null (unknown)
714 * @return string
716 protected function available_updates($updates, $fetch) {
718 $updateinfo = '';
719 $someupdateavailable = false;
720 if (is_array($updates)) {
721 if (is_array($updates['core'])) {
722 $someupdateavailable = true;
723 $updateinfo .= $this->heading(get_string('updateavailable', 'core_admin'), 3);
724 foreach ($updates['core'] as $update) {
725 $updateinfo .= $this->moodle_available_update_info($update);
727 $updateinfo .= html_writer::tag('p', get_string('updateavailablerecommendation', 'core_admin'),
728 array('class' => 'updateavailablerecommendation'));
730 unset($updates['core']);
731 // If something has left in the $updates array now, it is updates for plugins.
732 if (!empty($updates)) {
733 $someupdateavailable = true;
734 $updateinfo .= $this->heading(get_string('updateavailableforplugin', 'core_admin'), 3);
735 $pluginsoverviewurl = new moodle_url('/admin/plugins.php', array('updatesonly' => 1));
736 $updateinfo .= $this->container(get_string('pluginsoverviewsee', 'core_admin',
737 array('url' => $pluginsoverviewurl->out())));
741 if (!$someupdateavailable) {
742 $now = time();
743 if ($fetch and ($fetch <= $now) and ($now - $fetch < HOURSECS)) {
744 $updateinfo .= $this->heading(get_string('updateavailablenot', 'core_admin'), 3);
748 $updateinfo .= $this->container_start('checkforupdates');
749 $fetchurl = new moodle_url('/admin/index.php', array('fetchupdates' => 1, 'sesskey' => sesskey(), 'cache' => 0));
750 $updateinfo .= $this->single_button($fetchurl, get_string('checkforupdates', 'core_plugin'));
751 if ($fetch) {
752 $updateinfo .= $this->container(get_string('checkforupdateslast', 'core_plugin',
753 userdate($fetch, get_string('strftimedatetime', 'core_langconfig'))));
755 $updateinfo .= $this->container_end();
757 return $this->warning($updateinfo);
761 * Display a warning about not being registered on Moodle.org if necesary.
763 * @param boolean $registered true if the site is registered on Moodle.org
764 * @return string HTML to output.
766 protected function registration_warning($registered) {
768 if (!$registered) {
770 $registerbutton = $this->single_button(new moodle_url('/admin/registration/register.php',
771 array('huburl' => HUB_MOODLEORGHUBURL, 'hubname' => 'Moodle.org')),
772 get_string('register', 'admin'));
774 return $this->warning( get_string('registrationwarning', 'admin')
775 . '&nbsp;' . $this->help_icon('registration', 'admin') . $registerbutton );
778 return '';
782 * Helper method to render the information about the available Moodle update
784 * @param \core\update\info $updateinfo information about the available Moodle core update
786 protected function moodle_available_update_info(\core\update\info $updateinfo) {
788 $boxclasses = 'moodleupdateinfo';
789 $info = array();
791 if (isset($updateinfo->release)) {
792 $info[] = html_writer::tag('span', get_string('updateavailable_release', 'core_admin', $updateinfo->release),
793 array('class' => 'info release'));
796 if (isset($updateinfo->version)) {
797 $info[] = html_writer::tag('span', get_string('updateavailable_version', 'core_admin', $updateinfo->version),
798 array('class' => 'info version'));
801 if (isset($updateinfo->maturity)) {
802 $info[] = html_writer::tag('span', get_string('maturity'.$updateinfo->maturity, 'core_admin'),
803 array('class' => 'info maturity'));
804 $boxclasses .= ' maturity'.$updateinfo->maturity;
807 if (isset($updateinfo->download)) {
808 $info[] = html_writer::link($updateinfo->download, get_string('download'), array('class' => 'info download'));
811 if (isset($updateinfo->url)) {
812 $info[] = html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin'),
813 array('class' => 'info more'));
816 $box = $this->output->box_start($boxclasses);
817 $box .= $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $info), '');
818 $box .= $this->output->box_end();
820 return $box;
824 * Display a link to the release notes.
825 * @return string HTML to output.
827 protected function release_notes_link() {
828 $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/dev/Releases');
829 $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
830 return $this->box($releasenoteslink, 'generalbox releasenoteslink');
834 * Display the reload link that appears on several upgrade/install pages.
835 * @return string HTML to output.
837 function upgrade_reload($url) {
838 return html_writer::empty_tag('br') .
839 html_writer::tag('div',
840 html_writer::link($url, $this->pix_icon('i/reload', '', '', array('class' => 'icon icon-pre')) .
841 get_string('reload'), array('title' => get_string('reload'))),
842 array('class' => 'continuebutton')) . html_writer::empty_tag('br');
846 * Displays all known plugins and information about their installation or upgrade
848 * This default implementation renders all plugins into one big table. The rendering
849 * options support:
850 * (bool)full = false: whether to display up-to-date plugins, too
851 * (bool)xdep = false: display the plugins with unsatisified dependecies only
853 * @param core_plugin_manager $pluginman provides information about the plugins.
854 * @param int $version the version of the Moodle code from version.php.
855 * @param array $options rendering options
856 * @return string HTML code
858 public function plugins_check_table(core_plugin_manager $pluginman, $version, array $options = array()) {
859 global $CFG;
861 $plugininfo = $pluginman->get_plugins();
863 if (empty($plugininfo)) {
864 return '';
867 $options['full'] = isset($options['full']) ? (bool)$options['full'] : false;
868 $options['xdep'] = isset($options['xdep']) ? (bool)$options['xdep'] : false;
870 $table = new html_table();
871 $table->id = 'plugins-check';
872 $table->head = array(
873 get_string('displayname', 'core_plugin'),
874 get_string('rootdir', 'core_plugin'),
875 get_string('source', 'core_plugin'),
876 get_string('versiondb', 'core_plugin'),
877 get_string('versiondisk', 'core_plugin'),
878 get_string('requires', 'core_plugin'),
879 get_string('status', 'core_plugin'),
881 $table->colclasses = array(
882 'displayname', 'rootdir', 'source', 'versiondb', 'versiondisk', 'requires', 'status',
884 $table->data = array();
886 $numofhighlighted = array(); // number of highlighted rows per this subsection
888 foreach ($plugininfo as $type => $plugins) {
890 $header = new html_table_cell($pluginman->plugintype_name_plural($type));
891 $header->header = true;
892 $header->colspan = count($table->head);
893 $header = new html_table_row(array($header));
894 $header->attributes['class'] = 'plugintypeheader type-' . $type;
896 $numofhighlighted[$type] = 0;
898 if (empty($plugins) and $options['full']) {
899 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
900 $msg->colspan = count($table->head);
901 $row = new html_table_row(array($msg));
902 $row->attributes['class'] .= 'msg msg-noneinstalled';
903 $table->data[] = $header;
904 $table->data[] = $row;
905 continue;
908 $plugintyperows = array();
910 foreach ($plugins as $name => $plugin) {
911 $row = new html_table_row();
912 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
914 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name, null)) {
915 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
916 } else {
917 $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon'));
919 $displayname = $icon . ' ' . $plugin->displayname;
920 $displayname = new html_table_cell($displayname);
922 $rootdir = new html_table_cell($plugin->get_dir());
924 if ($isstandard = $plugin->is_standard()) {
925 $row->attributes['class'] .= ' standard';
926 $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
927 } else {
928 $row->attributes['class'] .= ' extension';
929 $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
932 $versiondb = new html_table_cell($plugin->versiondb);
933 $versiondisk = new html_table_cell($plugin->versiondisk);
935 $statuscode = $plugin->get_status();
936 $row->attributes['class'] .= ' status-' . $statuscode;
937 $status = get_string('status_' . $statuscode, 'core_plugin');
939 $availableupdates = $plugin->available_updates();
940 if (!empty($availableupdates) and empty($CFG->disableupdatenotifications)) {
941 foreach ($availableupdates as $availableupdate) {
942 $status .= $this->plugin_available_update_info($availableupdate);
946 $status = new html_table_cell($status);
948 $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version));
950 $statusisboring = in_array($statuscode, array(
951 core_plugin_manager::PLUGIN_STATUS_NODB, core_plugin_manager::PLUGIN_STATUS_UPTODATE));
953 $coredependency = $plugin->is_core_dependency_satisfied($version);
954 $otherpluginsdependencies = $pluginman->are_dependencies_satisfied($plugin->get_other_required_plugins());
955 $dependenciesok = $coredependency && $otherpluginsdependencies;
957 if ($options['xdep']) {
958 // we want to see only plugins with failed dependencies
959 if ($dependenciesok) {
960 continue;
963 } else if ($statusisboring and $dependenciesok and empty($availableupdates)) {
964 // no change is going to happen to the plugin - display it only
965 // if the user wants to see the full list
966 if (empty($options['full'])) {
967 continue;
971 // ok, the plugin should be displayed
972 $numofhighlighted[$type]++;
974 $row->cells = array($displayname, $rootdir, $source,
975 $versiondb, $versiondisk, $requires, $status);
976 $plugintyperows[] = $row;
979 if (empty($numofhighlighted[$type]) and empty($options['full'])) {
980 continue;
983 $table->data[] = $header;
984 $table->data = array_merge($table->data, $plugintyperows);
987 $sumofhighlighted = array_sum($numofhighlighted);
989 if ($options['xdep']) {
990 // we do not want to display no heading and links in this mode
991 $out = '';
993 } else if ($sumofhighlighted == 0) {
994 $out = $this->output->container_start('nonehighlighted', 'plugins-check-info');
995 $out .= $this->output->heading(get_string('nonehighlighted', 'core_plugin'));
996 if (empty($options['full'])) {
997 $out .= html_writer::link(new moodle_url($this->page->url,
998 array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1, 'cache' => 0)),
999 get_string('nonehighlightedinfo', 'core_plugin'));
1001 $out .= $this->output->container_end();
1003 } else {
1004 $out = $this->output->container_start('somehighlighted', 'plugins-check-info');
1005 if (empty($options['full'])) {
1006 $out .= $this->output->heading(get_string('somehighlighted', 'core_plugin', $sumofhighlighted));
1007 $out .= html_writer::link(new moodle_url($this->page->url,
1008 array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1, 'cache' => 0)),
1009 get_string('somehighlightedinfo', 'core_plugin'));
1010 } else {
1011 $out .= $this->output->heading(get_string('somehighlightedall', 'core_plugin', $sumofhighlighted));
1012 $out .= html_writer::link(new moodle_url($this->page->url,
1013 array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 0, 'cache' => 0)),
1014 get_string('somehighlightedonly', 'core_plugin'));
1016 $out .= $this->output->container_end();
1019 if ($sumofhighlighted > 0 or $options['full']) {
1020 $out .= html_writer::table($table);
1023 return $out;
1027 * Formats the information that needs to go in the 'Requires' column.
1028 * @param \core\plugininfo\base $plugin the plugin we are rendering the row for.
1029 * @param core_plugin_manager $pluginman provides data on all the plugins.
1030 * @param string $version
1031 * @return string HTML code
1033 protected function required_column(\core\plugininfo\base $plugin, core_plugin_manager $pluginman, $version) {
1034 $requires = array();
1036 if (!empty($plugin->versionrequires)) {
1037 if ($plugin->versionrequires <= $version) {
1038 $class = 'requires-ok';
1039 } else {
1040 $class = 'requires-failed';
1042 $requires[] = html_writer::tag('li',
1043 get_string('moodleversion', 'core_plugin', $plugin->versionrequires),
1044 array('class' => $class));
1047 foreach ($plugin->get_other_required_plugins() as $component => $requiredversion) {
1048 $otherplugin = $pluginman->get_plugin_info($component);
1049 $actions = array();
1051 if (is_null($otherplugin)) {
1052 // The required plugin is not installed.
1053 $class = 'requires-failed requires-missing';
1054 $installurl = new moodle_url('https://moodle.org/plugins/view.php', array('plugin' => $component));
1055 $uploadurl = new moodle_url('/admin/tool/installaddon/');
1056 $actions[] = html_writer::link($installurl, get_string('dependencyinstall', 'core_plugin'));
1057 $actions[] = html_writer::link($uploadurl, get_string('dependencyupload', 'core_plugin'));
1059 } else if ($requiredversion != ANY_VERSION and $otherplugin->versiondisk < $requiredversion) {
1060 // The required plugin is installed but needs to be updated.
1061 $class = 'requires-failed requires-outdated';
1062 if (!$otherplugin->is_standard()) {
1063 $updateurl = new moodle_url($this->page->url, array('sesskey' => sesskey(), 'fetchupdates' => 1));
1064 $actions[] = html_writer::link($updateurl, get_string('checkforupdates', 'core_plugin'));
1067 } else {
1068 // Already installed plugin with sufficient version.
1069 $class = 'requires-ok';
1072 if ($requiredversion != ANY_VERSION) {
1073 $str = 'otherpluginversion';
1074 } else {
1075 $str = 'otherplugin';
1078 $requires[] = html_writer::tag('li',
1079 html_writer::div(get_string($str, 'core_plugin',
1080 array('component' => $component, 'version' => $requiredversion)), 'component').
1081 html_writer::div(implode(' | ', $actions), 'actions'),
1082 array('class' => $class));
1085 if (!$requires) {
1086 return '';
1088 return html_writer::tag('ul', implode("\n", $requires));
1092 * Prints an overview about the plugins - number of installed, number of extensions etc.
1094 * @param core_plugin_manager $pluginman provides information about the plugins
1095 * @param array $options filtering options
1096 * @return string as usually
1098 public function plugins_overview_panel(core_plugin_manager $pluginman, array $options = array()) {
1099 global $CFG;
1101 $plugininfo = $pluginman->get_plugins();
1103 $numtotal = $numdisabled = $numextension = $numupdatable = 0;
1105 foreach ($plugininfo as $type => $plugins) {
1106 foreach ($plugins as $name => $plugin) {
1107 if ($plugin->get_status() === core_plugin_manager::PLUGIN_STATUS_MISSING) {
1108 continue;
1110 $numtotal++;
1111 if ($plugin->is_enabled() === false) {
1112 $numdisabled++;
1114 if (!$plugin->is_standard()) {
1115 $numextension++;
1117 if (empty($CFG->disableupdatenotifications) and $plugin->available_updates()) {
1118 $numupdatable++;
1123 $info = array();
1124 $filter = array();
1125 $somefilteractive = false;
1126 $info[] = html_writer::tag('span', get_string('numtotal', 'core_plugin', $numtotal), array('class' => 'info total'));
1127 $info[] = html_writer::tag('span', get_string('numdisabled', 'core_plugin', $numdisabled), array('class' => 'info disabled'));
1128 $info[] = html_writer::tag('span', get_string('numextension', 'core_plugin', $numextension), array('class' => 'info extension'));
1129 if ($numextension > 0) {
1130 if (empty($options['contribonly'])) {
1131 $filter[] = html_writer::link(
1132 new moodle_url($this->page->url, array('contribonly' => 1)),
1133 get_string('filtercontribonly', 'core_plugin'),
1134 array('class' => 'filter-item show-contribonly')
1136 } else {
1137 $filter[] = html_writer::tag('span', get_string('filtercontribonlyactive', 'core_plugin'),
1138 array('class' => 'filter-item active show-contribonly'));
1139 $somefilteractive = true;
1142 if ($numupdatable > 0) {
1143 $info[] = html_writer::tag('span', get_string('numupdatable', 'core_plugin', $numupdatable), array('class' => 'info updatable'));
1144 if (empty($options['updatesonly'])) {
1145 $filter[] = html_writer::link(
1146 new moodle_url($this->page->url, array('updatesonly' => 1)),
1147 get_string('filterupdatesonly', 'core_plugin'),
1148 array('class' => 'filter-item show-updatesonly')
1150 } else {
1151 $filter[] = html_writer::tag('span', get_string('filterupdatesonlyactive', 'core_plugin'),
1152 array('class' => 'filter-item active show-updatesonly'));
1153 $somefilteractive = true;
1156 if ($somefilteractive) {
1157 $filter[] = html_writer::link($this->page->url, get_string('filterall', 'core_plugin'), array('class' => 'filter-item show-all'));
1160 $output = $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $info), '', 'plugins-overview-panel');
1162 if (!empty($filter)) {
1163 $output .= $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $filter), '', 'plugins-overview-filter');
1166 return $output;
1170 * Displays all known plugins and links to manage them
1172 * This default implementation renders all plugins into one big table.
1174 * @param core_plugin_manager $pluginman provides information about the plugins.
1175 * @param array $options filtering options
1176 * @return string HTML code
1178 public function plugins_control_panel(core_plugin_manager $pluginman, array $options = array()) {
1179 global $CFG;
1181 $plugininfo = $pluginman->get_plugins();
1183 // Filter the list of plugins according the options.
1184 if (!empty($options['updatesonly'])) {
1185 $updateable = array();
1186 foreach ($plugininfo as $plugintype => $pluginnames) {
1187 foreach ($pluginnames as $pluginname => $pluginfo) {
1188 if (!empty($pluginfo->availableupdates)) {
1189 foreach ($pluginfo->availableupdates as $pluginavailableupdate) {
1190 if ($pluginavailableupdate->version > $pluginfo->versiondisk) {
1191 $updateable[$plugintype][$pluginname] = $pluginfo;
1197 $plugininfo = $updateable;
1200 if (!empty($options['contribonly'])) {
1201 $contribs = array();
1202 foreach ($plugininfo as $plugintype => $pluginnames) {
1203 foreach ($pluginnames as $pluginname => $pluginfo) {
1204 if (!$pluginfo->is_standard()) {
1205 $contribs[$plugintype][$pluginname] = $pluginfo;
1209 $plugininfo = $contribs;
1212 if (empty($plugininfo)) {
1213 return '';
1216 $table = new html_table();
1217 $table->id = 'plugins-control-panel';
1218 $table->head = array(
1219 get_string('displayname', 'core_plugin'),
1220 get_string('source', 'core_plugin'),
1221 get_string('version', 'core_plugin'),
1222 get_string('release', 'core_plugin'),
1223 get_string('availability', 'core_plugin'),
1224 get_string('actions', 'core_plugin'),
1225 get_string('notes','core_plugin'),
1227 $table->headspan = array(1, 1, 1, 1, 1, 2, 1);
1228 $table->colclasses = array(
1229 'pluginname', 'source', 'version', 'release', 'availability', 'settings', 'uninstall', 'notes'
1232 foreach ($plugininfo as $type => $plugins) {
1233 $heading = $pluginman->plugintype_name_plural($type);
1234 $pluginclass = core_plugin_manager::resolve_plugininfo_class($type);
1235 if ($manageurl = $pluginclass::get_manage_url()) {
1236 $heading = html_writer::link($manageurl, $heading);
1238 $header = new html_table_cell(html_writer::tag('span', $heading, array('id'=>'plugin_type_cell_'.$type)));
1239 $header->header = true;
1240 $header->colspan = array_sum($table->headspan);
1241 $header = new html_table_row(array($header));
1242 $header->attributes['class'] = 'plugintypeheader type-' . $type;
1243 $table->data[] = $header;
1245 if (empty($plugins)) {
1246 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
1247 $msg->colspan = array_sum($table->headspan);
1248 $row = new html_table_row(array($msg));
1249 $row->attributes['class'] .= 'msg msg-noneinstalled';
1250 $table->data[] = $row;
1251 continue;
1254 foreach ($plugins as $name => $plugin) {
1255 $row = new html_table_row();
1256 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
1258 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) {
1259 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'icon pluginicon'));
1260 } else {
1261 $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'icon pluginicon noicon'));
1263 $status = $plugin->get_status();
1264 $row->attributes['class'] .= ' status-'.$status;
1265 if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) {
1266 $msg = html_writer::tag('span', get_string('status_missing', 'core_plugin'), array('class' => 'statusmsg'));
1267 } else if ($status === core_plugin_manager::PLUGIN_STATUS_NEW) {
1268 $msg = html_writer::tag('span', get_string('status_new', 'core_plugin'), array('class' => 'statusmsg'));
1269 } else {
1270 $msg = '';
1272 $pluginname = html_writer::tag('div', $icon . '' . $plugin->displayname . ' ' . $msg, array('class' => 'displayname')).
1273 html_writer::tag('div', $plugin->component, array('class' => 'componentname'));
1274 $pluginname = new html_table_cell($pluginname);
1276 if ($plugin->is_standard()) {
1277 $row->attributes['class'] .= ' standard';
1278 $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
1279 } else {
1280 $row->attributes['class'] .= ' extension';
1281 $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
1284 $version = new html_table_cell($plugin->versiondb);
1285 $release = new html_table_cell($plugin->release);
1287 $isenabled = $plugin->is_enabled();
1288 if (is_null($isenabled)) {
1289 $availability = new html_table_cell('');
1290 } else if ($isenabled) {
1291 $row->attributes['class'] .= ' enabled';
1292 $availability = new html_table_cell(get_string('pluginenabled', 'core_plugin'));
1293 } else {
1294 $row->attributes['class'] .= ' disabled';
1295 $availability = new html_table_cell(get_string('plugindisabled', 'core_plugin'));
1298 $settingsurl = $plugin->get_settings_url();
1299 if (!is_null($settingsurl)) {
1300 $settings = html_writer::link($settingsurl, get_string('settings', 'core_plugin'), array('class' => 'settings'));
1301 } else {
1302 $settings = '';
1304 $settings = new html_table_cell($settings);
1306 if ($uninstallurl = $pluginman->get_uninstall_url($plugin->component, 'overview')) {
1307 $uninstall = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin'));
1308 } else {
1309 $uninstall = '';
1311 $uninstall = new html_table_cell($uninstall);
1313 $requriedby = $pluginman->other_plugins_that_require($plugin->component);
1314 if ($requriedby) {
1315 $requiredby = html_writer::tag('div', get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
1316 array('class' => 'requiredby'));
1317 } else {
1318 $requiredby = '';
1321 $updateinfo = '';
1322 if (empty($CFG->disableupdatenotifications) and is_array($plugin->available_updates())) {
1323 foreach ($plugin->available_updates() as $availableupdate) {
1324 $updateinfo .= $this->plugin_available_update_info($availableupdate);
1328 $notes = new html_table_cell($requiredby.$updateinfo);
1330 $row->cells = array(
1331 $pluginname, $source, $version, $release, $availability, $settings, $uninstall, $notes
1333 $table->data[] = $row;
1337 return html_writer::table($table);
1341 * Helper method to render the information about the available plugin update
1343 * The passed objects always provides at least the 'version' property containing
1344 * the (higher) version of the plugin available.
1346 * @param \core\update\info $updateinfo information about the available update for the plugin
1348 protected function plugin_available_update_info(\core\update\info $updateinfo) {
1350 $boxclasses = 'pluginupdateinfo';
1351 $info = array();
1353 if (isset($updateinfo->release)) {
1354 $info[] = html_writer::tag('span', get_string('updateavailable_release', 'core_plugin', $updateinfo->release),
1355 array('class' => 'info release'));
1358 if (isset($updateinfo->maturity)) {
1359 $info[] = html_writer::tag('span', get_string('maturity'.$updateinfo->maturity, 'core_admin'),
1360 array('class' => 'info maturity'));
1361 $boxclasses .= ' maturity'.$updateinfo->maturity;
1364 if (isset($updateinfo->download)) {
1365 $info[] = html_writer::link($updateinfo->download, get_string('download'), array('class' => 'info download'));
1368 if (isset($updateinfo->url)) {
1369 $info[] = html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin'),
1370 array('class' => 'info more'));
1373 $box = $this->output->box_start($boxclasses);
1374 $box .= html_writer::tag('div', get_string('updateavailable', 'core_plugin', $updateinfo->version), array('class' => 'version'));
1375 $box .= $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $info), '');
1377 $deployer = \core\update\deployer::instance();
1378 if ($deployer->initialized()) {
1379 $impediments = $deployer->deployment_impediments($updateinfo);
1380 if (empty($impediments)) {
1381 $widget = $deployer->make_confirm_widget($updateinfo);
1382 $box .= $this->output->render($widget);
1383 } else {
1384 if (isset($impediments['notwritable'])) {
1385 $box .= $this->output->help_icon('notwritable', 'core_plugin', get_string('notwritable', 'core_plugin'));
1387 if (isset($impediments['notdownloadable'])) {
1388 $box .= $this->output->help_icon('notdownloadable', 'core_plugin', get_string('notdownloadable', 'core_plugin'));
1393 $box .= $this->output->box_end();
1395 return $box;
1399 * This function will render one beautiful table with all the environmental
1400 * configuration and how it suits Moodle needs.
1402 * @param boolean $result final result of the check (true/false)
1403 * @param environment_results[] $environment_results array of results gathered
1404 * @return string HTML to output.
1406 public function environment_check_table($result, $environment_results) {
1407 global $CFG;
1409 // Table headers
1410 $servertable = new html_table();//table for server checks
1411 $servertable->head = array(
1412 get_string('name'),
1413 get_string('info'),
1414 get_string('report'),
1415 get_string('plugin'),
1416 get_string('status'),
1418 $servertable->colclasses = array('centeralign name', 'centeralign info', 'leftalign report', 'leftalign plugin', 'centeralign status');
1419 $servertable->attributes['class'] = 'admintable environmenttable generaltable';
1420 $servertable->id = 'serverstatus';
1422 $serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
1424 $othertable = new html_table();//table for custom checks
1425 $othertable->head = array(
1426 get_string('info'),
1427 get_string('report'),
1428 get_string('plugin'),
1429 get_string('status'),
1431 $othertable->colclasses = array('aligncenter info', 'alignleft report', 'alignleft plugin', 'aligncenter status');
1432 $othertable->attributes['class'] = 'admintable environmenttable generaltable';
1433 $othertable->id = 'otherserverstatus';
1435 $otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
1437 // Iterate over each environment_result
1438 $continue = true;
1439 foreach ($environment_results as $environment_result) {
1440 $errorline = false;
1441 $warningline = false;
1442 $stringtouse = '';
1443 if ($continue) {
1444 $type = $environment_result->getPart();
1445 $info = $environment_result->getInfo();
1446 $status = $environment_result->getStatus();
1447 $plugin = $environment_result->getPluginName();
1448 $error_code = $environment_result->getErrorCode();
1449 // Process Report field
1450 $rec = new stdClass();
1451 // Something has gone wrong at parsing time
1452 if ($error_code) {
1453 $stringtouse = 'environmentxmlerror';
1454 $rec->error_code = $error_code;
1455 $status = get_string('error');
1456 $errorline = true;
1457 $continue = false;
1460 if ($continue) {
1461 if ($rec->needed = $environment_result->getNeededVersion()) {
1462 // We are comparing versions
1463 $rec->current = $environment_result->getCurrentVersion();
1464 if ($environment_result->getLevel() == 'required') {
1465 $stringtouse = 'environmentrequireversion';
1466 } else {
1467 $stringtouse = 'environmentrecommendversion';
1470 } else if ($environment_result->getPart() == 'custom_check') {
1471 // We are checking installed & enabled things
1472 if ($environment_result->getLevel() == 'required') {
1473 $stringtouse = 'environmentrequirecustomcheck';
1474 } else {
1475 $stringtouse = 'environmentrecommendcustomcheck';
1478 } else if ($environment_result->getPart() == 'php_setting') {
1479 if ($status) {
1480 $stringtouse = 'environmentsettingok';
1481 } else if ($environment_result->getLevel() == 'required') {
1482 $stringtouse = 'environmentmustfixsetting';
1483 } else {
1484 $stringtouse = 'environmentshouldfixsetting';
1487 } else {
1488 if ($environment_result->getLevel() == 'required') {
1489 $stringtouse = 'environmentrequireinstall';
1490 } else {
1491 $stringtouse = 'environmentrecommendinstall';
1495 // Calculate the status value
1496 if ($environment_result->getBypassStr() != '') { //Handle bypassed result (warning)
1497 $status = get_string('bypassed');
1498 $warningline = true;
1499 } else if ($environment_result->getRestrictStr() != '') { //Handle restricted result (error)
1500 $status = get_string('restricted');
1501 $errorline = true;
1502 } else {
1503 if ($status) { //Handle ok result (ok)
1504 $status = get_string('ok');
1505 } else {
1506 if ($environment_result->getLevel() == 'optional') {//Handle check result (warning)
1507 $status = get_string('check');
1508 $warningline = true;
1509 } else { //Handle error result (error)
1510 $status = get_string('check');
1511 $errorline = true;
1517 // Build the text
1518 $linkparts = array();
1519 $linkparts[] = 'admin/environment';
1520 $linkparts[] = $type;
1521 if (!empty($info)){
1522 $linkparts[] = $info;
1524 // Plugin environments do not have docs pages yet.
1525 if (empty($CFG->docroot) or $environment_result->plugin) {
1526 $report = get_string($stringtouse, 'admin', $rec);
1527 } else {
1528 $report = $this->doc_link(join($linkparts, '/'), get_string($stringtouse, 'admin', $rec));
1531 // Format error or warning line
1532 if ($errorline || $warningline) {
1533 $messagetype = $errorline? 'error':'warn';
1534 } else {
1535 $messagetype = 'ok';
1537 $status = '<span class="'.$messagetype.'">'.$status.'</span>';
1538 // Here we'll store all the feedback found
1539 $feedbacktext = '';
1540 // Append the feedback if there is some
1541 $feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), $messagetype);
1542 //Append the bypass if there is some
1543 $feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'warn');
1544 //Append the restrict if there is some
1545 $feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'error');
1547 $report .= $feedbacktext;
1549 // Add the row to the table
1550 if ($environment_result->getPart() == 'custom_check'){
1551 $otherdata[$messagetype][] = array ($info, $report, $plugin, $status);
1552 } else {
1553 $serverdata[$messagetype][] = array ($type, $info, $report, $plugin, $status);
1558 //put errors first in
1559 $servertable->data = array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']);
1560 $othertable->data = array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']);
1562 // Print table
1563 $output = '';
1564 $output .= $this->heading(get_string('serverchecks', 'admin'));
1565 $output .= html_writer::table($servertable);
1566 if (count($othertable->data)){
1567 $output .= $this->heading(get_string('customcheck', 'admin'));
1568 $output .= html_writer::table($othertable);
1571 // Finally, if any error has happened, print the summary box
1572 if (!$result) {
1573 $output .= $this->box(get_string('environmenterrortodo', 'admin'), 'environmentbox errorbox');
1576 return $output;
1580 * Render a simple page for providing the upgrade key.
1582 * @param moodle_url|string $url
1583 * @return string
1585 public function upgradekey_form_page($url) {
1587 $output = '';
1588 $output .= $this->header();
1589 $output .= $this->container_start('upgradekeyreq');
1590 $output .= $this->heading(get_string('upgradekeyreq', 'core_admin'));
1591 $output .= html_writer::start_tag('form', array('method' => 'POST', 'action' => $url));
1592 $output .= html_writer::empty_tag('input', array('name' => 'upgradekey', 'type' => 'password'));
1593 $output .= html_writer::empty_tag('input', array('value' => get_string('submit'), 'type' => 'submit'));
1594 $output .= html_writer::end_tag('form');
1595 $output .= $this->container_end();
1596 $output .= $this->footer();
1598 return $output;