2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Renderer for core_admin subsystem
22 * @copyright 2011 David Mudrak <david@moodle.com>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') || die();
30 * Standard HTML output renderer for core_admin subsystem
32 class core_admin_renderer extends plugin_renderer_base {
35 * Display the 'Do you acknowledge the terms of the GPL' page. The first page
37 * @return string HTML to output.
39 public function install_licence_page() {
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();
61 * Display page explaining proper upgrade process,
62 * there can not be any PHP file leftovers...
64 * @return string HTML to output.
66 public function upgrade_stale_php_files_page() {
68 $output .= $this->header();
69 $output .= $this->heading(get_string('upgradestalefiles', 'admin'));
70 $output .= $this->box_start('generalbox', 'notice');
71 $output .= 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();
81 * Display the 'environment check' page that is displayed during install.
82 * @param int $maturity
83 * @param boolean $envstatus final result of the check (true/false)
84 * @param array $environment_results array of results gathered
85 * @param string $release moodle release
86 * @return string HTML to output.
88 public function install_environment_page($maturity, $envstatus, $environment_results, $release) {
92 $output .= $this->header();
93 $output .= $this->maturity_warning($maturity);
94 $output .= $this->heading("Moodle $release");
95 $output .= $this->release_notes_link();
97 $output .= $this->environment_check_table($envstatus, $environment_results);
100 $output .= $this->upgrade_reload(new moodle_url($this->page->url, array('agreelicense' => 1, 'lang' => $CFG->lang)));
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();
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) {
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();
135 * Display the 'You are about to upgrade Moodle' page. The first page
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) {
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();
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) {
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);
175 $output .= $this->upgrade_reload(new moodle_url($this->page->url, array('confirmupgrade' => 1, 'cache' => 0)));
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();
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) {
208 $output .= $this->header();
209 $output .= $this->box_start('generalbox', 'plugins-check-page');
210 $output .= html_writer::tag('p', get_string('pluginchecknotice', 'core_plugin'), array('class' => 'page-description'));
212 if ($checker->enabled()) {
213 $output .= $this->container_start('checkforupdates');
214 $output .= $this->single_button(
215 new moodle_url($reloadurl, array('fetchupdates' => 1)),
216 get_string('checkforupdates', 'core_plugin')
218 if ($timefetched = $checker->get_last_timefetched()) {
219 $output .= $this->container(get_string('checkforupdateslast', 'core_plugin',
220 userdate($timefetched, get_string('strftimedatetime', 'core_langconfig'))));
222 $output .= $this->container_end();
225 $output .= $this->missing_dependencies($pluginman);
226 $output .= $this->plugins_check_table($pluginman, $version, array('full' => $showallplugins));
227 $output .= $this->box_end();
228 $output .= $this->upgrade_reload($reloadurl);
230 if ($pluginman->some_plugins_updatable()) {
231 $output .= $this->container_start('upgradepluginsinfo');
232 $output .= $this->help_icon('upgradepluginsinfo', 'core_admin', get_string('upgradepluginsfirst', 'core_admin'));
233 $output .= $this->container_end();
236 $button = new single_button($continueurl, get_string('upgradestart', 'admin'), 'get');
237 $button->class = 'continuebutton';
238 $output .= $this->render($button);
239 $output .= $this->footer();
245 * Display the admin notifications page.
246 * @param int $maturity
247 * @param bool $insecuredataroot warn dataroot is invalid
248 * @param bool $errorsdisplayed warn invalid dispaly error setting
249 * @param bool $cronoverdue warn cron not running
250 * @param bool $dbproblems warn db has problems
251 * @param bool $maintenancemode warn in maintenance mode
252 * @param bool $buggyiconvnomb warn iconv problems
253 * @param array|null $availableupdates array of \core\update\info objects or null
254 * @param int|null $availableupdatesfetch timestamp of the most recent updates fetch or null (unknown)
255 * @param string[] $cachewarnings An array containing warnings from the Cache API.
257 * @return string HTML to output.
259 public function admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed,
260 $cronoverdue, $dbproblems, $maintenancemode, $availableupdates, $availableupdatesfetch,
261 $buggyiconvnomb, $registered, array $cachewarnings = array()) {
265 $output .= $this->header();
266 $output .= $this->maturity_info($maturity);
267 $output .= empty($CFG->disableupdatenotifications) ? $this->available_updates($availableupdates, $availableupdatesfetch) : '';
268 $output .= $this->insecure_dataroot_warning($insecuredataroot);
269 $output .= $this->display_errors_warning($errorsdisplayed);
270 $output .= $this->buggy_iconv_warning($buggyiconvnomb);
271 $output .= $this->cron_overdue_warning($cronoverdue);
272 $output .= $this->db_problems($dbproblems);
273 $output .= $this->maintenance_mode_warning($maintenancemode);
274 $output .= $this->cache_warnings($cachewarnings);
275 $output .= $this->registration_warning($registered);
277 //////////////////////////////////////////////////////////////////////////////////////////////////
278 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
279 $output .= $this->moodle_copyright();
280 //////////////////////////////////////////////////////////////////////////////////////////////////
282 $output .= $this->footer();
288 * Display the plugin management page (admin/plugins.php).
290 * The filtering options array may contain following items:
291 * bool contribonly - show only contributed extensions
292 * bool updatesonly - show only plugins with an available update
294 * @param core_plugin_manager $pluginman
295 * @param \core\update\checker $checker
296 * @param array $options filtering options
297 * @return string HTML to output.
299 public function plugin_management_page(core_plugin_manager $pluginman, \core\update\checker $checker, array $options = array()) {
303 $output .= $this->header();
304 $output .= $this->heading(get_string('pluginsoverview', 'core_admin'));
305 $output .= $this->plugins_overview_panel($pluginman, $options);
307 if ($checker->enabled()) {
308 $output .= $this->container_start('checkforupdates');
309 $output .= $this->single_button(
310 new moodle_url($this->page->url, array_merge($options, array('fetchremote' => 1))),
311 get_string('checkforupdates', 'core_plugin')
313 if ($timefetched = $checker->get_last_timefetched()) {
314 $output .= $this->container(get_string('checkforupdateslast', 'core_plugin',
315 userdate($timefetched, get_string('strftimedatetime', 'core_langconfig'))));
317 $output .= $this->container_end();
320 $output .= $this->box($this->plugins_control_panel($pluginman, $options), 'generalbox');
321 $output .= $this->footer();
327 * Display a page to confirm the plugin uninstallation.
329 * @param core_plugin_manager $pluginman
330 * @param \core\plugininfo\base $pluginfo
331 * @param moodle_url $continueurl URL to continue after confirmation
332 * @param moodle_url $cancelurl URL to to go if cancelled
335 public function plugin_uninstall_confirm_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, moodle_url $continueurl, moodle_url $cancelurl) {
338 $pluginname = $pluginman->plugin_name($pluginfo->component);
340 $confirm = '<p>' . get_string('uninstallconfirm', 'core_plugin', array('name' => $pluginname)) . '</p>';
341 if ($extraconfirm = $pluginfo->get_uninstall_extra_warning()) {
342 $confirm .= $extraconfirm;
345 $output .= $this->output->header();
346 $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
347 $output .= $this->output->confirm($confirm, $continueurl, $cancelurl);
348 $output .= $this->output->footer();
354 * Display a page with results of plugin uninstallation and offer removal of plugin files.
356 * @param core_plugin_manager $pluginman
357 * @param \core\plugininfo\base $pluginfo
358 * @param progress_trace_buffer $progress
359 * @param moodle_url $continueurl URL to continue to remove the plugin folder
362 public function plugin_uninstall_results_removable_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo,
363 progress_trace_buffer $progress, moodle_url $continueurl) {
366 $pluginname = $pluginman->plugin_name($pluginfo->component);
368 // Do not show navigation here, they must click one of the buttons.
369 $this->page->set_pagelayout('maintenance');
370 $this->page->set_cacheable(false);
372 $output .= $this->output->header();
373 $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
375 $output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
377 $confirm = $this->output->container(get_string('uninstalldeleteconfirm', 'core_plugin',
378 array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'uninstalldeleteconfirm');
380 if ($repotype = $pluginman->plugin_external_source($pluginfo->component)) {
381 $confirm .= $this->output->container(get_string('uninstalldeleteconfirmexternal', 'core_plugin', $repotype),
382 'uninstalldeleteconfirmexternal');
385 // After any uninstall we must execute full upgrade to finish the cleanup!
386 $output .= $this->output->confirm($confirm, $continueurl, new moodle_url('/admin/index.php'));
387 $output .= $this->output->footer();
393 * Display a page with results of plugin uninstallation and inform about the need to remove plugin files manually.
395 * @param core_plugin_manager $pluginman
396 * @param \core\plugininfo\base $pluginfo
397 * @param progress_trace_buffer $progress
400 public function plugin_uninstall_results_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, progress_trace_buffer $progress) {
403 $pluginname = $pluginfo->component;
405 $output .= $this->output->header();
406 $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
408 $output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
410 $output .= $this->output->box(get_string('uninstalldelete', 'core_plugin',
411 array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'generalbox uninstalldelete');
412 $output .= $this->output->continue_button(new moodle_url('/admin/index.php'));
413 $output .= $this->output->footer();
419 * Display the plugin management page (admin/environment.php).
420 * @param array $versions
421 * @param string $version
422 * @param boolean $envstatus final result of env check (true/false)
423 * @param array $environment_results array of results gathered
424 * @return string HTML to output.
426 public function environment_check_page($versions, $version, $envstatus, $environment_results) {
428 $output .= $this->header();
430 // Print the component download link
431 $output .= html_writer::tag('div', html_writer::link(
432 new moodle_url('/admin/environment.php', array('action' => 'updatecomponent', 'sesskey' => sesskey())),
433 get_string('updatecomponent', 'admin')),
434 array('class' => 'reportlink'));
437 $output .= $this->heading(get_string('environment', 'admin'));
439 // Box with info and a menu to choose the version.
440 $output .= $this->box_start();
441 $output .= html_writer::tag('div', get_string('adminhelpenvironment'));
442 $select = new single_select(new moodle_url('/admin/environment.php'), 'version', $versions, $version, null);
443 $select->label = get_string('moodleversion');
444 $output .= $this->render($select);
445 $output .= $this->box_end();
448 $output .= $this->environment_check_table($envstatus, $environment_results);
450 $output .= $this->footer();
455 * Output a warning message, of the type that appears on the admin notifications page.
456 * @param string $message the message to display.
457 * @param string $type type class
458 * @return string HTML to output.
460 protected function warning($message, $type = 'warning') {
461 return $this->box($message, 'generalbox admin' . $type);
465 * Render an appropriate message if dataroot is insecure.
466 * @param bool $insecuredataroot
467 * @return string HTML to output.
469 protected function insecure_dataroot_warning($insecuredataroot) {
472 if ($insecuredataroot == INSECURE_DATAROOT_WARNING) {
473 return $this->warning(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot));
475 } else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) {
476 return $this->warning(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'error');
484 * Render an appropriate message if dataroot is insecure.
485 * @param bool $errorsdisplayed
486 * @return string HTML to output.
488 protected function display_errors_warning($errorsdisplayed) {
489 if (!$errorsdisplayed) {
493 return $this->warning(get_string('displayerrorswarning', 'admin'));
497 * Render an appropriate message if iconv is buggy and mbstring missing.
498 * @param bool $buggyiconvnomb
499 * @return string HTML to output.
501 protected function buggy_iconv_warning($buggyiconvnomb) {
502 if (!$buggyiconvnomb) {
506 return $this->warning(get_string('warningiconvbuggy', 'admin'));
510 * Render an appropriate message if cron has not been run recently.
511 * @param bool $cronoverdue
512 * @return string HTML to output.
514 public function cron_overdue_warning($cronoverdue) {
520 if (empty($CFG->cronclionly)) {
521 $url = new moodle_url('/admin/cron.php');
522 if (!empty($CFG->cronremotepassword)) {
523 $url = new moodle_url('/admin/cron.php', array('password' => $CFG->cronremotepassword));
526 return $this->warning(get_string('cronwarning', 'admin', $url->out()) . ' ' .
527 $this->help_icon('cron', 'admin'));
530 // $CFG->cronclionly is not empty: cron can run only from CLI.
531 return $this->warning(get_string('cronwarningcli', 'admin') . ' ' .
532 $this->help_icon('cron', 'admin'));
536 * Render an appropriate message if there are any problems with the DB set-up.
537 * @param bool $dbproblems
538 * @return string HTML to output.
540 public function db_problems($dbproblems) {
545 return $this->warning($dbproblems);
549 * Renders cache warnings if there are any.
551 * @param string[] $cachewarnings
554 public function cache_warnings(array $cachewarnings) {
555 if (!count($cachewarnings)) {
558 return join("\n", array_map(array($this, 'warning'), $cachewarnings));
562 * Render an appropriate message if the site in in maintenance mode.
563 * @param bool $maintenancemode
564 * @return string HTML to output.
566 public function maintenance_mode_warning($maintenancemode) {
567 if (!$maintenancemode) {
571 $url = new moodle_url('/admin/settings.php', array('section' => 'maintenancemode'));
572 $url = $url->out(); // get_string() does not support objects in params
574 return $this->warning(get_string('sitemaintenancewarning2', 'admin', $url));
578 * Display a warning about installing development code if necesary.
579 * @param int $maturity
580 * @return string HTML to output.
582 protected function maturity_warning($maturity) {
583 if ($maturity == MATURITY_STABLE) {
584 return ''; // No worries.
587 $maturitylevel = get_string('maturity' . $maturity, 'admin');
588 return $this->warning(
589 $this->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
590 $this->container($this->doc_link('admin/versions', get_string('morehelp'))),
595 * If necessary, displays a warning about upgrading a test site.
597 * @param string $testsite
598 * @return string HTML
600 protected function test_site_warning($testsite) {
606 $warning = (get_string('testsiteupgradewarning', 'admin', $testsite));
607 return $this->warning($warning, 'error');
611 * Output the copyright notice.
612 * @return string HTML to output.
614 protected function moodle_copyright() {
617 //////////////////////////////////////////////////////////////////////////////////////////////////
618 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
619 $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
620 '<a href="http://docs.moodle.org/dev/Releases" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
621 'Copyright © 1999 onwards, Martin Dougiamas<br />'.
622 'and <a href="http://moodle.org/dev">many other contributors</a>.<br />'.
623 '<a href="http://docs.moodle.org/dev/License">GNU Public License</a>';
624 //////////////////////////////////////////////////////////////////////////////////////////////////
626 return $this->box($copyrighttext, 'copyright');
630 * Display a warning about installing development code if necesary.
631 * @param int $maturity
632 * @return string HTML to output.
634 protected function maturity_info($maturity) {
635 if ($maturity == MATURITY_STABLE) {
636 return ''; // No worries.
641 if ($maturity == MATURITY_ALPHA) {
645 $maturitylevel = get_string('maturity' . $maturity, 'admin');
646 $warningtext = get_string('maturitycoreinfo', 'admin', $maturitylevel);
647 $warningtext .= ' ' . $this->doc_link('admin/versions', get_string('morehelp'));
648 return $this->warning($warningtext, $level);
652 * Displays the info about available Moodle core and plugin updates
654 * The structure of the $updates param has changed since 2.4. It contains not only updates
655 * for the core itself, but also for all other installed plugins.
657 * @param array|null $updates array of (string)component => array of \core\update\info objects or null
658 * @param int|null $fetch timestamp of the most recent updates fetch or null (unknown)
661 protected function available_updates($updates, $fetch) {
664 $someupdateavailable = false;
665 if (is_array($updates)) {
666 if (is_array($updates['core'])) {
667 $someupdateavailable = true;
668 $updateinfo .= $this->heading(get_string('updateavailable', 'core_admin'), 3);
669 foreach ($updates['core'] as $update) {
670 $updateinfo .= $this->moodle_available_update_info($update);
672 $updateinfo .= html_writer::tag('p', get_string('updateavailablerecommendation', 'core_admin'),
673 array('class' => 'updateavailablerecommendation'));
675 unset($updates['core']);
676 // If something has left in the $updates array now, it is updates for plugins.
677 if (!empty($updates)) {
678 $someupdateavailable = true;
679 $updateinfo .= $this->heading(get_string('updateavailableforplugin', 'core_admin'), 3);
680 $pluginsoverviewurl = new moodle_url('/admin/plugins.php', array('updatesonly' => 1));
681 $updateinfo .= $this->container(get_string('pluginsoverviewsee', 'core_admin',
682 array('url' => $pluginsoverviewurl->out())));
686 if (!$someupdateavailable) {
688 if ($fetch and ($fetch <= $now) and ($now - $fetch < HOURSECS)) {
689 $updateinfo .= $this->heading(get_string('updateavailablenot', 'core_admin'), 3);
693 $updateinfo .= $this->container_start('checkforupdates');
694 $fetchurl = new moodle_url('/admin/index.php', array('fetchupdates' => 1, 'sesskey' => sesskey(), 'cache' => 0));
695 $updateinfo .= $this->single_button($fetchurl, get_string('checkforupdates', 'core_plugin'));
697 $updateinfo .= $this->container(get_string('checkforupdateslast', 'core_plugin',
698 userdate($fetch, get_string('strftimedatetime', 'core_langconfig'))));
700 $updateinfo .= $this->container_end();
702 return $this->warning($updateinfo);
706 * Display a warning about not being registered on Moodle.org if necesary.
708 * @param boolean $registered true if the site is registered on Moodle.org
709 * @return string HTML to output.
711 protected function registration_warning($registered) {
715 $registerbutton = $this->single_button(new moodle_url('/admin/registration/register.php',
716 array('huburl' => HUB_MOODLEORGHUBURL, 'hubname' => 'Moodle.org')),
717 get_string('register', 'admin'));
719 return $this->warning( get_string('registrationwarning', 'admin')
720 . ' ' . $this->help_icon('registration', 'admin') . $registerbutton );
727 * Helper method to render the information about the available Moodle update
729 * @param \core\update\info $updateinfo information about the available Moodle core update
731 protected function moodle_available_update_info(\core\update\info $updateinfo) {
733 $boxclasses = 'moodleupdateinfo';
736 if (isset($updateinfo->release)) {
737 $info[] = html_writer::tag('span', get_string('updateavailable_release', 'core_admin', $updateinfo->release),
738 array('class' => 'info release'));
741 if (isset($updateinfo->version)) {
742 $info[] = html_writer::tag('span', get_string('updateavailable_version', 'core_admin', $updateinfo->version),
743 array('class' => 'info version'));
746 if (isset($updateinfo->maturity)) {
747 $info[] = html_writer::tag('span', get_string('maturity'.$updateinfo->maturity, 'core_admin'),
748 array('class' => 'info maturity'));
749 $boxclasses .= ' maturity'.$updateinfo->maturity;
752 if (isset($updateinfo->download)) {
753 $info[] = html_writer::link($updateinfo->download, get_string('download'), array('class' => 'info download'));
756 if (isset($updateinfo->url)) {
757 $info[] = html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin'),
758 array('class' => 'info more'));
761 $box = $this->output->box_start($boxclasses);
762 $box .= $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $info), '');
763 $box .= $this->output->box_end();
769 * Display a link to the release notes.
770 * @return string HTML to output.
772 protected function release_notes_link() {
773 $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/dev/Releases');
774 $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
775 return $this->box($releasenoteslink, 'generalbox releasenoteslink');
779 * Display the reload link that appears on several upgrade/install pages.
780 * @return string HTML to output.
782 function upgrade_reload($url) {
783 return html_writer::empty_tag('br') .
784 html_writer::tag('div',
785 html_writer::link($url, $this->pix_icon('i/reload', '', '', array('class' => 'icon icon-pre')) .
786 get_string('reload'), array('title' => get_string('reload'))),
787 array('class' => 'continuebutton')) . html_writer::empty_tag('br');
791 * Displays all known plugins and information about their installation or upgrade
793 * This default implementation renders all plugins into one big table. The rendering
795 * (bool)full = false: whether to display up-to-date plugins, too
796 * (bool)xdep = false: display the plugins with unsatisified dependecies only
798 * @param core_plugin_manager $pluginman provides information about the plugins.
799 * @param int $version the version of the Moodle code from version.php.
800 * @param array $options rendering options
801 * @return string HTML code
803 public function plugins_check_table(core_plugin_manager $pluginman, $version, array $options = array()) {
805 $plugininfo = $pluginman->get_plugins();
807 if (empty($plugininfo)) {
811 $options['full'] = isset($options['full']) ? (bool)$options['full'] : false;
812 $options['xdep'] = isset($options['xdep']) ? (bool)$options['xdep'] : false;
814 $table = new html_table();
815 $table->id = 'plugins-check';
816 $table->head = array(
817 get_string('displayname', 'core_plugin').' / '.get_string('rootdir', 'core_plugin'),
818 get_string('versiondb', 'core_plugin'),
819 get_string('versiondisk', 'core_plugin'),
820 get_string('requires', 'core_plugin'),
821 get_string('source', 'core_plugin').' / '.get_string('status', 'core_plugin'),
823 $table->colclasses = array(
824 'displayname', 'versiondb', 'versiondisk', 'requires', 'status',
826 $table->data = array();
828 // Number of displayed plugins per type.
829 $numdisplayed = array();
830 // Number of plugins known to the plugin manager.
832 // Number of plugins requiring attention.
834 // List of all components we can cancel installation of.
835 $installabortable = array();
837 foreach ($plugininfo as $type => $plugins) {
839 $header = new html_table_cell($pluginman->plugintype_name_plural($type));
840 $header->header = true;
841 $header->colspan = count($table->head);
842 $header = new html_table_row(array($header));
843 $header->attributes['class'] = 'plugintypeheader type-' . $type;
845 $numdisplayed[$type] = 0;
847 if (empty($plugins) and $options['full']) {
848 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
849 $msg->colspan = count($table->head);
850 $row = new html_table_row(array($msg));
851 $row->attributes['class'] .= 'msg msg-noneinstalled';
852 $table->data[] = $header;
853 $table->data[] = $row;
857 $plugintyperows = array();
859 foreach ($plugins as $name => $plugin) {
861 $row = new html_table_row();
862 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
864 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name, null)) {
865 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
870 $displayname = new html_table_cell(
872 html_writer::span($plugin->displayname, 'pluginname').
873 html_writer::div($plugin->get_dir(), 'plugindir')
876 $versiondb = new html_table_cell($plugin->versiondb);
877 $versiondisk = new html_table_cell($plugin->versiondisk);
879 if ($isstandard = $plugin->is_standard()) {
880 $row->attributes['class'] .= ' standard';
881 $sourcelabel = html_writer::span(get_string('sourcestd', 'core_plugin'), 'sourcetext label');
883 $row->attributes['class'] .= ' extension';
884 $sourcelabel = html_writer::span(get_string('sourceext', 'core_plugin'), 'sourcetext label label-info');
887 $coredependency = $plugin->is_core_dependency_satisfied($version);
888 $otherpluginsdependencies = $pluginman->are_dependencies_satisfied($plugin->get_other_required_plugins());
889 $dependenciesok = $coredependency && $otherpluginsdependencies;
891 $statuscode = $plugin->get_status();
892 $row->attributes['class'] .= ' status-' . $statuscode;
893 $statusclass = 'statustext label ';
894 switch ($statuscode) {
895 case core_plugin_manager::PLUGIN_STATUS_NEW:
896 $statusclass .= $dependenciesok ? 'label-success' : 'label-warning';
898 case core_plugin_manager::PLUGIN_STATUS_UPGRADE:
899 $statusclass .= $dependenciesok ? 'label-info' : 'label-warning';
901 case core_plugin_manager::PLUGIN_STATUS_MISSING:
902 case core_plugin_manager::PLUGIN_STATUS_DOWNGRADE:
903 case core_plugin_manager::PLUGIN_STATUS_DELETE:
904 $statusclass .= 'label-important';
906 case core_plugin_manager::PLUGIN_STATUS_NODB:
907 case core_plugin_manager::PLUGIN_STATUS_UPTODATE:
908 $statusclass .= $dependenciesok ? '' : 'label-warning';
911 $status = html_writer::span(get_string('status_' . $statuscode, 'core_plugin'), $statusclass);
913 if ($statuscode == core_plugin_manager::PLUGIN_STATUS_NEW and !$plugin->is_standard()) {
914 if ($pluginman->is_plugin_folder_removable($plugin->component)) {
915 $installabortable[] = $plugin->component;
916 $status .= $this->output->single_button(
917 new moodle_url($this->page->url, array('abortinstall' => $plugin->component)),
918 get_string('cancelinstallone', 'core_plugin'),
920 array('class' => 'actionbutton')
925 $availableupdates = $plugin->available_updates();
926 if (!empty($availableupdates)) {
927 foreach ($availableupdates as $availableupdate) {
928 $status .= $this->plugin_available_update_info($pluginman, $availableupdate);
932 $status = new html_table_cell($sourcelabel.' '.$status);
934 $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version));
936 $statusisboring = in_array($statuscode, array(
937 core_plugin_manager::PLUGIN_STATUS_NODB, core_plugin_manager::PLUGIN_STATUS_UPTODATE));
939 if ($options['xdep']) {
940 // we want to see only plugins with failed dependencies
941 if ($dependenciesok) {
945 } else if ($statusisboring and $dependenciesok and empty($availableupdates)) {
946 // no change is going to happen to the plugin - display it only
947 // if the user wants to see the full list
948 if (empty($options['full'])) {
956 // The plugin should be displayed.
957 $numdisplayed[$type]++;
958 $row->cells = array($displayname, $versiondb, $versiondisk, $requires, $status);
959 $plugintyperows[] = $row;
962 if (empty($numdisplayed[$type]) and empty($options['full'])) {
966 $table->data[] = $header;
967 $table->data = array_merge($table->data, $plugintyperows);
970 // Total number of displayed plugins.
971 $sumdisplayed = array_sum($numdisplayed);
973 if ($options['xdep']) {
974 // At the plugins dependencies check page, display the table only.
975 return html_writer::table($table);
978 $out = $this->output->container_start('', 'plugins-check-info');
980 if ($sumdisplayed == 0) {
981 $out .= $this->output->heading(get_string('pluginchecknone', 'core_plugin'));
984 if (empty($options['full'])) {
985 $out .= $this->output->heading(get_string('plugincheckattention', 'core_plugin'));
987 $out .= $this->output->heading(get_string('plugincheckall', 'core_plugin'));
991 $out .= $this->output->container_start('actions');
992 if ($installabortable) {
993 $out .= $this->output->single_button(
994 new moodle_url($this->page->url, array('abortinstallx' => 1)),
995 get_string('cancelinstallall', 'core_plugin', count($installabortable)),
997 array('class' => 'singlebutton cancelinstallall')
1001 $out .= html_writer::div(html_writer::link(new moodle_url($this->page->url, array('showallplugins' => 0)),
1002 get_string('plugincheckattention', 'core_plugin')).' '.html_writer::span($sumattention, 'badge'));
1004 $out .= html_writer::div(html_writer::link(new moodle_url($this->page->url, array('showallplugins' => 1)),
1005 get_string('plugincheckall', 'core_plugin')).' '.html_writer::span($sumtotal, 'badge'));
1007 $out .= $this->output->container_end(); // .actions
1008 $out .= $this->output->container_end(); // #plugins-check-info
1010 if ($sumdisplayed > 0 or $options['full']) {
1011 $out .= html_writer::table($table);
1018 * Displays the information about missing dependencies
1020 * @param core_plugin_manager $pluginman
1023 protected function missing_dependencies(core_plugin_manager $pluginman) {
1025 $dependencies = $pluginman->missing_dependencies();
1027 if (empty($dependencies)) {
1031 $available = array();
1032 $unavailable = array();
1035 foreach ($dependencies as $component => $remoteinfo) {
1036 if ($remoteinfo === false) {
1037 // The required version is not available. Let us check if there
1038 // is at least some version in the plugins directory.
1039 $remoteinfoanyversion = $pluginman->get_remote_plugin_info($component, ANY_VERSION, false);
1040 if ($remoteinfoanyversion === false) {
1041 $unknown[$component] = $component;
1043 $unavailable[$component] = $remoteinfoanyversion;
1046 $available[$component] = $remoteinfo;
1050 $out = $this->output->container_start('plugins-check-dependencies');
1052 if ($unavailable or $unknown) {
1053 $out .= $this->output->heading(get_string('misdepsunavail', 'core_plugin'));
1055 $out .= $this->output->notification(get_string('misdepsunknownlist', 'core_plugin', implode($unknown, ', ')));
1058 $unavailablelist = array();
1059 foreach ($unavailable as $component => $remoteinfoanyversion) {
1060 $unavailablelistitem = html_writer::link('https://moodle.org/plugins/view.php?plugin='.$component,
1061 '<strong>'.$remoteinfoanyversion->name.'</strong>');
1062 if ($remoteinfoanyversion->version) {
1063 $unavailablelistitem .= ' ('.$component.' > '.$remoteinfoanyversion->version->version.')';
1065 $unavailablelistitem .= ' ('.$component.')';
1067 $unavailablelist[] = $unavailablelistitem;
1069 $out .= $this->output->notification(get_string('misdepsunavaillist', 'core_plugin',
1070 implode($unavailablelist, ', ')));
1072 $out .= $this->output->container_start('plugins-check-dependencies-actions');
1073 $out .= ' '.html_writer::link(new moodle_url('/admin/tool/installaddon/'),
1074 get_string('dependencyuploadmissing', 'core_plugin'));
1075 $out .= $this->output->container_end(); // .plugins-check-dependencies-actions
1079 $out .= $this->output->heading(get_string('misdepsavail', 'core_plugin'));
1080 $installable = array();
1081 foreach ($available as $component => $remoteinfo) {
1082 if ($pluginman->is_remote_plugin_installable($component, $remoteinfo->version->version)) {
1083 $installable[$component] = $remoteinfo;
1087 $out .= $this->output->container_start('plugins-check-dependencies-actions');
1090 $out .= $this->output->single_button(
1091 new moodle_url($this->page->url, array('installdepx' => 1)),
1092 get_string('dependencyinstallmissing', 'core_plugin', count($installable)),
1094 array('class' => 'singlebutton dependencyinstallmissing')
1098 $out.= html_writer::div(html_writer::link(new moodle_url('/admin/tool/installaddon/'),
1099 get_string('dependencyuploadmissing', 'core_plugin')), 'dependencyuploadmissing');
1101 $out .= $this->output->container_end(); // .plugins-check-dependencies-actions
1103 $out .= $this->available_missing_dependencies_list($pluginman, $available);
1106 $out .= $this->output->container_end(); // .plugins-check-dependencies
1112 * Displays the list if available missing dependencies.
1114 * @param core_plugin_manager $pluginman
1115 * @param array $dependencies
1118 protected function available_missing_dependencies_list(core_plugin_manager $pluginman, array $dependencies) {
1121 $table = new html_table();
1122 $table->id = 'plugins-check-available-dependencies';
1123 $table->head = array(
1124 get_string('displayname', 'core_plugin'),
1125 get_string('release', 'core_plugin'),
1126 get_string('version', 'core_plugin'),
1127 get_string('supportedmoodleversions', 'core_plugin'),
1128 get_string('info', 'core'),
1130 $table->colclasses = array('displayname', 'release', 'version', 'supportedmoodleversions', 'info');
1131 $table->data = array();
1133 foreach ($dependencies as $plugin) {
1135 $supportedmoodles = array();
1136 foreach ($plugin->version->supportedmoodles as $moodle) {
1137 if ($CFG->branch == str_replace('.', '', $moodle->release)) {
1138 $supportedmoodles[] = html_writer::span($moodle->release, 'label label-success');
1140 $supportedmoodles[] = html_writer::span($moodle->release, 'label');
1144 $requriedby = $pluginman->other_plugins_that_require($plugin->component);
1146 foreach ($requriedby as $ix => $val) {
1147 $inf = $pluginman->get_plugin_info($val);
1149 $requriedby[$ix] = $inf->displayname.' ('.$inf->component.')';
1152 $info = html_writer::div(
1153 get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
1160 $info .= $this->output->container_start('actions');
1162 $info .= html_writer::div(
1163 html_writer::link('https://moodle.org/plugins/view.php?plugin='.$plugin->component,
1164 get_string('misdepinfoplugin', 'core_plugin')),
1168 $info .= html_writer::div(
1169 html_writer::link('https://moodle.org/plugins/pluginversion.php?id='.$plugin->version->id,
1170 get_string('misdepinfoversion', 'core_plugin')),
1174 $info .= html_writer::div(html_writer::link($plugin->version->downloadurl, get_string('download')), 'misdepdownload');
1176 if ($pluginman->is_remote_plugin_installable($plugin->component, $plugin->version->version, $reason)) {
1177 $info .= $this->output->single_button(
1178 new moodle_url($this->page->url, array('installdep' => $plugin->component)),
1179 get_string('dependencyinstall', 'core_plugin'),
1181 array('class' => 'singlebutton dependencyinstall')
1184 $reasonhelp = $this->info_remote_plugin_not_installable($reason);
1186 $info .= html_writer::div($reasonhelp, 'reasonhelp dependencyinstall');
1190 $info .= $this->output->container_end(); // .actions
1192 $table->data[] = array(
1193 html_writer::div($plugin->name, 'name').' '.html_writer::div($plugin->component, 'component'),
1194 $plugin->version->release,
1195 $plugin->version->version,
1196 implode($supportedmoodles, ' '),
1201 return html_writer::table($table);
1205 * Explain why {@link core_plugin_manager::is_remote_plugin_installable()} returned false.
1207 * @param string $reason the reason code as returned by the plugin manager
1210 protected function info_remote_plugin_not_installable($reason) {
1212 if ($reason === 'notwritableplugintype' or $reason === 'notwritableplugin') {
1213 return $this->output->help_icon('notwritable', 'core_plugin', get_string('notwritable', 'core_plugin'));
1216 if ($reason === 'remoteunavailable') {
1217 return $this->output->help_icon('notdownloadable', 'core_plugin', get_string('notdownloadable', 'core_plugin'));
1224 * Formats the information that needs to go in the 'Requires' column.
1225 * @param \core\plugininfo\base $plugin the plugin we are rendering the row for.
1226 * @param core_plugin_manager $pluginman provides data on all the plugins.
1227 * @param string $version
1228 * @return string HTML code
1230 protected function required_column(\core\plugininfo\base $plugin, core_plugin_manager $pluginman, $version) {
1232 $requires = array();
1233 $displayuploadlink = false;
1234 $displayupdateslink = false;
1236 foreach ($pluginman->resolve_requirements($plugin, $version) as $reqname => $reqinfo) {
1237 if ($reqname === 'core') {
1238 if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OK) {
1239 $class = 'requires-ok';
1242 $class = 'requires-failed';
1243 $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'label label-important');
1245 $requires[] = html_writer::tag('li',
1246 html_writer::span(get_string('moodleversion', 'core_plugin', $plugin->versionrequires), 'dep dep-core').
1247 ' '.$label, array('class' => $class));
1252 if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OK) {
1254 $class = 'requires-ok';
1256 } else if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_MISSING) {
1257 if ($reqinfo->availability == $pluginman::REQUIREMENT_AVAILABLE) {
1258 $label = html_writer::span(get_string('dependencymissing', 'core_plugin'), 'label label-warning');
1259 $label .= ' '.html_writer::span(get_string('dependencyavailable', 'core_plugin'), 'label label-warning');
1260 $class = 'requires-failed requires-missing requires-available';
1261 $actions[] = html_writer::link(
1262 new moodle_url('https://moodle.org/plugins/view.php', array('plugin' => $reqname)),
1263 get_string('misdepinfoplugin', 'core_plugin')
1267 $label = html_writer::span(get_string('dependencymissing', 'core_plugin'), 'label label-important');
1268 $label .= ' '.html_writer::span(get_string('dependencyunavailable', 'core_plugin'),
1269 'label label-important');
1270 $class = 'requires-failed requires-missing requires-unavailable';
1272 $displayuploadlink = true;
1274 } else if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OUTDATED) {
1275 if ($reqinfo->availability == $pluginman::REQUIREMENT_AVAILABLE) {
1276 $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'label label-warning');
1277 $label .= ' '.html_writer::span(get_string('dependencyavailable', 'core_plugin'), 'label label-warning');
1278 $class = 'requires-failed requires-outdated requires-available';
1279 $displayupdateslink = true;
1282 $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'label label-important');
1283 $label .= ' '.html_writer::span(get_string('dependencyunavailable', 'core_plugin'),
1284 'label label-important');
1285 $class = 'requires-failed requires-outdated requires-unavailable';
1287 $displayuploadlink = true;
1290 if ($reqinfo->reqver != ANY_VERSION) {
1291 $str = 'otherpluginversion';
1293 $str = 'otherplugin';
1296 $requires[] = html_writer::tag('li', html_writer::span(
1297 get_string($str, 'core_plugin', array('component' => $reqname, 'version' => $reqinfo->reqver)),
1298 'dep dep-plugin').' '.$label.' '.html_writer::span(implode(' | ', $actions), 'actions'),
1299 array('class' => $class)
1308 $out = html_writer::tag('ul', implode("\n", $requires));
1310 if ($displayuploadlink) {
1311 $out .= html_writer::div(
1313 new moodle_url('/admin/tool/installaddon/'),
1314 get_string('dependencyuploadmissing', 'core_plugin')
1316 'dependencyuploadmissing'
1320 if ($displayupdateslink) {
1321 $out .= html_writer::div(
1323 new moodle_url($this->page->url, array('sesskey' => sesskey(), 'fetchupdates' => 1)),
1324 get_string('checkforupdates', 'core_plugin')
1335 * Prints an overview about the plugins - number of installed, number of extensions etc.
1337 * @param core_plugin_manager $pluginman provides information about the plugins
1338 * @param array $options filtering options
1339 * @return string as usually
1341 public function plugins_overview_panel(core_plugin_manager $pluginman, array $options = array()) {
1343 $plugininfo = $pluginman->get_plugins();
1345 $numtotal = $numdisabled = $numextension = $numupdatable = 0;
1347 foreach ($plugininfo as $type => $plugins) {
1348 foreach ($plugins as $name => $plugin) {
1349 if ($plugin->get_status() === core_plugin_manager::PLUGIN_STATUS_MISSING) {
1353 if ($plugin->is_enabled() === false) {
1356 if (!$plugin->is_standard()) {
1359 if ($plugin->available_updates()) {
1367 $somefilteractive = false;
1368 $info[] = html_writer::tag('span', get_string('numtotal', 'core_plugin', $numtotal), array('class' => 'info total'));
1369 $info[] = html_writer::tag('span', get_string('numdisabled', 'core_plugin', $numdisabled), array('class' => 'info disabled'));
1370 $info[] = html_writer::tag('span', get_string('numextension', 'core_plugin', $numextension), array('class' => 'info extension'));
1371 if ($numextension > 0) {
1372 if (empty($options['contribonly'])) {
1373 $filter[] = html_writer::link(
1374 new moodle_url($this->page->url, array('contribonly' => 1)),
1375 get_string('filtercontribonly', 'core_plugin'),
1376 array('class' => 'filter-item show-contribonly')
1379 $filter[] = html_writer::tag('span', get_string('filtercontribonlyactive', 'core_plugin'),
1380 array('class' => 'filter-item active show-contribonly'));
1381 $somefilteractive = true;
1384 if ($numupdatable > 0) {
1385 $info[] = html_writer::tag('span', get_string('numupdatable', 'core_plugin', $numupdatable), array('class' => 'info updatable'));
1386 if (empty($options['updatesonly'])) {
1387 $filter[] = html_writer::link(
1388 new moodle_url($this->page->url, array('updatesonly' => 1)),
1389 get_string('filterupdatesonly', 'core_plugin'),
1390 array('class' => 'filter-item show-updatesonly')
1393 $filter[] = html_writer::tag('span', get_string('filterupdatesonlyactive', 'core_plugin'),
1394 array('class' => 'filter-item active show-updatesonly'));
1395 $somefilteractive = true;
1398 if ($somefilteractive) {
1399 $filter[] = html_writer::link($this->page->url, get_string('filterall', 'core_plugin'), array('class' => 'filter-item show-all'));
1402 $output = $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $info), '', 'plugins-overview-panel');
1404 if (!empty($filter)) {
1405 $output .= $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $filter), '', 'plugins-overview-filter');
1412 * Displays all known plugins and links to manage them
1414 * This default implementation renders all plugins into one big table.
1416 * @param core_plugin_manager $pluginman provides information about the plugins.
1417 * @param array $options filtering options
1418 * @return string HTML code
1420 public function plugins_control_panel(core_plugin_manager $pluginman, array $options = array()) {
1422 $plugininfo = $pluginman->get_plugins();
1424 // Filter the list of plugins according the options.
1425 if (!empty($options['updatesonly'])) {
1426 $updateable = array();
1427 foreach ($plugininfo as $plugintype => $pluginnames) {
1428 foreach ($pluginnames as $pluginname => $pluginfo) {
1429 $pluginavailableupdates = $pluginfo->available_updates();
1430 if (!empty($pluginavailableupdates)) {
1431 foreach ($pluginavailableupdates as $pluginavailableupdate) {
1432 $updateable[$plugintype][$pluginname] = $pluginfo;
1437 $plugininfo = $updateable;
1440 if (!empty($options['contribonly'])) {
1441 $contribs = array();
1442 foreach ($plugininfo as $plugintype => $pluginnames) {
1443 foreach ($pluginnames as $pluginname => $pluginfo) {
1444 if (!$pluginfo->is_standard()) {
1445 $contribs[$plugintype][$pluginname] = $pluginfo;
1449 $plugininfo = $contribs;
1452 if (empty($plugininfo)) {
1456 $table = new html_table();
1457 $table->id = 'plugins-control-panel';
1458 $table->head = array(
1459 get_string('displayname', 'core_plugin'),
1460 get_string('source', 'core_plugin'),
1461 get_string('version', 'core_plugin'),
1462 get_string('release', 'core_plugin'),
1463 get_string('availability', 'core_plugin'),
1464 get_string('actions', 'core_plugin'),
1465 get_string('notes','core_plugin'),
1467 $table->headspan = array(1, 1, 1, 1, 1, 2, 1);
1468 $table->colclasses = array(
1469 'pluginname', 'source', 'version', 'release', 'availability', 'settings', 'uninstall', 'notes'
1472 foreach ($plugininfo as $type => $plugins) {
1473 $heading = $pluginman->plugintype_name_plural($type);
1474 $pluginclass = core_plugin_manager::resolve_plugininfo_class($type);
1475 if ($manageurl = $pluginclass::get_manage_url()) {
1476 $heading = html_writer::link($manageurl, $heading);
1478 $header = new html_table_cell(html_writer::tag('span', $heading, array('id'=>'plugin_type_cell_'.$type)));
1479 $header->header = true;
1480 $header->colspan = array_sum($table->headspan);
1481 $header = new html_table_row(array($header));
1482 $header->attributes['class'] = 'plugintypeheader type-' . $type;
1483 $table->data[] = $header;
1485 if (empty($plugins)) {
1486 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
1487 $msg->colspan = array_sum($table->headspan);
1488 $row = new html_table_row(array($msg));
1489 $row->attributes['class'] .= 'msg msg-noneinstalled';
1490 $table->data[] = $row;
1494 foreach ($plugins as $name => $plugin) {
1495 $row = new html_table_row();
1496 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
1498 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) {
1499 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'icon pluginicon'));
1501 $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'icon pluginicon noicon'));
1503 $status = $plugin->get_status();
1504 $row->attributes['class'] .= ' status-'.$status;
1505 if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) {
1506 $msg = html_writer::tag('span', get_string('status_missing', 'core_plugin'), array('class' => 'statusmsg'));
1507 } else if ($status === core_plugin_manager::PLUGIN_STATUS_NEW) {
1508 $msg = html_writer::tag('span', get_string('status_new', 'core_plugin'), array('class' => 'statusmsg'));
1512 $pluginname = html_writer::tag('div', $icon . '' . $plugin->displayname . ' ' . $msg, array('class' => 'displayname')).
1513 html_writer::tag('div', $plugin->component, array('class' => 'componentname'));
1514 $pluginname = new html_table_cell($pluginname);
1516 if ($plugin->is_standard()) {
1517 $row->attributes['class'] .= ' standard';
1518 $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
1520 $row->attributes['class'] .= ' extension';
1521 $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
1524 $version = new html_table_cell($plugin->versiondb);
1525 $release = new html_table_cell($plugin->release);
1527 $isenabled = $plugin->is_enabled();
1528 if (is_null($isenabled)) {
1529 $availability = new html_table_cell('');
1530 } else if ($isenabled) {
1531 $row->attributes['class'] .= ' enabled';
1532 $availability = new html_table_cell(get_string('pluginenabled', 'core_plugin'));
1534 $row->attributes['class'] .= ' disabled';
1535 $availability = new html_table_cell(get_string('plugindisabled', 'core_plugin'));
1538 $settingsurl = $plugin->get_settings_url();
1539 if (!is_null($settingsurl)) {
1540 $settings = html_writer::link($settingsurl, get_string('settings', 'core_plugin'), array('class' => 'settings'));
1544 $settings = new html_table_cell($settings);
1546 if ($uninstallurl = $pluginman->get_uninstall_url($plugin->component, 'overview')) {
1547 $uninstall = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin'));
1551 $uninstall = new html_table_cell($uninstall);
1553 $requriedby = $pluginman->other_plugins_that_require($plugin->component);
1555 $requiredby = html_writer::tag('div', get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
1556 array('class' => 'requiredby'));
1562 if (is_array($plugin->available_updates())) {
1563 foreach ($plugin->available_updates() as $availableupdate) {
1564 $updateinfo .= $this->plugin_available_update_info($pluginman, $availableupdate);
1568 $notes = new html_table_cell($requiredby.$updateinfo);
1570 $row->cells = array(
1571 $pluginname, $source, $version, $release, $availability, $settings, $uninstall, $notes
1573 $table->data[] = $row;
1577 return html_writer::table($table);
1581 * Helper method to render the information about the available plugin update
1583 * @param core_plugin_manager $pluginman plugin manager instance
1584 * @param \core\update\info $updateinfo information about the available update for the plugin
1586 protected function plugin_available_update_info(core_plugin_manager $pluginman, \core\update\info $updateinfo) {
1588 $boxclasses = 'pluginupdateinfo';
1591 if (isset($updateinfo->release)) {
1592 $info[] = html_writer::tag('span', get_string('updateavailable_release', 'core_plugin', $updateinfo->release),
1593 array('class' => 'info release'));
1596 if (isset($updateinfo->maturity)) {
1597 $info[] = html_writer::tag('span', get_string('maturity'.$updateinfo->maturity, 'core_admin'),
1598 array('class' => 'info maturity'));
1599 $boxclasses .= ' maturity'.$updateinfo->maturity;
1602 if (isset($updateinfo->download)) {
1603 $info[] = html_writer::link($updateinfo->download, get_string('download'), array('class' => 'info download'));
1606 if (isset($updateinfo->url)) {
1607 $info[] = html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin'),
1608 array('class' => 'info more'));
1611 $box = $this->output->box_start($boxclasses);
1612 $box .= html_writer::tag('div', get_string('updateavailable', 'core_plugin', $updateinfo->version), array('class' => 'version'));
1613 $box .= $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $info), '');
1615 if ($pluginman->is_remote_plugin_installable($updateinfo->component, $updateinfo->version, $reason)) {
1616 $box .= $this->output->single_button(
1617 new moodle_url($this->page->url, array('installupdate' => $updateinfo->component,
1618 'installupdateversion' => $updateinfo->version)),
1619 get_string('updateavailableinstall', 'core_admin'),
1621 array('class' => 'singlebutton updateavailableinstall')
1624 $reasonhelp = $this->info_remote_plugin_not_installable($reason);
1626 $box .= html_writer::div($reasonhelp, 'reasonhelp updateavailableinstall');
1630 $box .= $this->output->box_end();
1636 * This function will render one beautiful table with all the environmental
1637 * configuration and how it suits Moodle needs.
1639 * @param boolean $result final result of the check (true/false)
1640 * @param environment_results[] $environment_results array of results gathered
1641 * @return string HTML to output.
1643 public function environment_check_table($result, $environment_results) {
1647 $servertable = new html_table();//table for server checks
1648 $servertable->head = array(
1651 get_string('report'),
1652 get_string('plugin'),
1653 get_string('status'),
1655 $servertable->colclasses = array('centeralign name', 'centeralign info', 'leftalign report', 'leftalign plugin', 'centeralign status');
1656 $servertable->attributes['class'] = 'admintable environmenttable generaltable';
1657 $servertable->id = 'serverstatus';
1659 $serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
1661 $othertable = new html_table();//table for custom checks
1662 $othertable->head = array(
1664 get_string('report'),
1665 get_string('plugin'),
1666 get_string('status'),
1668 $othertable->colclasses = array('aligncenter info', 'alignleft report', 'alignleft plugin', 'aligncenter status');
1669 $othertable->attributes['class'] = 'admintable environmenttable generaltable';
1670 $othertable->id = 'otherserverstatus';
1672 $otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
1674 // Iterate over each environment_result
1676 foreach ($environment_results as $environment_result) {
1678 $warningline = false;
1681 $type = $environment_result->getPart();
1682 $info = $environment_result->getInfo();
1683 $status = $environment_result->getStatus();
1684 $plugin = $environment_result->getPluginName();
1685 $error_code = $environment_result->getErrorCode();
1686 // Process Report field
1687 $rec = new stdClass();
1688 // Something has gone wrong at parsing time
1690 $stringtouse = 'environmentxmlerror';
1691 $rec->error_code = $error_code;
1692 $status = get_string('error');
1698 if ($rec->needed = $environment_result->getNeededVersion()) {
1699 // We are comparing versions
1700 $rec->current = $environment_result->getCurrentVersion();
1701 if ($environment_result->getLevel() == 'required') {
1702 $stringtouse = 'environmentrequireversion';
1704 $stringtouse = 'environmentrecommendversion';
1707 } else if ($environment_result->getPart() == 'custom_check') {
1708 // We are checking installed & enabled things
1709 if ($environment_result->getLevel() == 'required') {
1710 $stringtouse = 'environmentrequirecustomcheck';
1712 $stringtouse = 'environmentrecommendcustomcheck';
1715 } else if ($environment_result->getPart() == 'php_setting') {
1717 $stringtouse = 'environmentsettingok';
1718 } else if ($environment_result->getLevel() == 'required') {
1719 $stringtouse = 'environmentmustfixsetting';
1721 $stringtouse = 'environmentshouldfixsetting';
1725 if ($environment_result->getLevel() == 'required') {
1726 $stringtouse = 'environmentrequireinstall';
1728 $stringtouse = 'environmentrecommendinstall';
1732 // Calculate the status value
1733 if ($environment_result->getBypassStr() != '') { //Handle bypassed result (warning)
1734 $status = get_string('bypassed');
1735 $warningline = true;
1736 } else if ($environment_result->getRestrictStr() != '') { //Handle restricted result (error)
1737 $status = get_string('restricted');
1740 if ($status) { //Handle ok result (ok)
1741 $status = get_string('ok');
1743 if ($environment_result->getLevel() == 'optional') {//Handle check result (warning)
1744 $status = get_string('check');
1745 $warningline = true;
1746 } else { //Handle error result (error)
1747 $status = get_string('check');
1755 $linkparts = array();
1756 $linkparts[] = 'admin/environment';
1757 $linkparts[] = $type;
1759 $linkparts[] = $info;
1761 // Plugin environments do not have docs pages yet.
1762 if (empty($CFG->docroot) or $environment_result->plugin) {
1763 $report = get_string($stringtouse, 'admin', $rec);
1765 $report = $this->doc_link(join($linkparts, '/'), get_string($stringtouse, 'admin', $rec));
1768 // Format error or warning line
1769 if ($errorline || $warningline) {
1770 $messagetype = $errorline? 'error':'warn';
1772 $messagetype = 'ok';
1774 $status = '<span class="'.$messagetype.'">'.$status.'</span>';
1775 // Here we'll store all the feedback found
1777 // Append the feedback if there is some
1778 $feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), $messagetype);
1779 //Append the bypass if there is some
1780 $feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'warn');
1781 //Append the restrict if there is some
1782 $feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'error');
1784 $report .= $feedbacktext;
1786 // Add the row to the table
1787 if ($environment_result->getPart() == 'custom_check'){
1788 $otherdata[$messagetype][] = array ($info, $report, $plugin, $status);
1790 $serverdata[$messagetype][] = array ($type, $info, $report, $plugin, $status);
1795 //put errors first in
1796 $servertable->data = array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']);
1797 $othertable->data = array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']);
1801 $output .= $this->heading(get_string('serverchecks', 'admin'));
1802 $output .= html_writer::table($servertable);
1803 if (count($othertable->data)){
1804 $output .= $this->heading(get_string('customcheck', 'admin'));
1805 $output .= html_writer::table($othertable);
1808 // Finally, if any error has happened, print the summary box
1810 $output .= $this->box(get_string('environmenterrortodo', 'admin'), 'environmentbox errorbox');
1817 * Render a simple page for providing the upgrade key.
1819 * @param moodle_url|string $url
1822 public function upgradekey_form_page($url) {
1825 $output .= $this->header();
1826 $output .= $this->container_start('upgradekeyreq');
1827 $output .= $this->heading(get_string('upgradekeyreq', 'core_admin'));
1828 $output .= html_writer::start_tag('form', array('method' => 'POST', 'action' => $url));
1829 $output .= html_writer::empty_tag('input', array('name' => 'upgradekey', 'type' => 'password'));
1830 $output .= html_writer::empty_tag('input', array('value' => get_string('submit'), 'type' => 'submit'));
1831 $output .= html_writer::end_tag('form');
1832 $output .= $this->container_end();
1833 $output .= $this->footer();