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'));
211 $output .= $this->check_for_updates_button($checker, $reloadurl);
212 $output .= $this->missing_dependencies($pluginman);
213 $output .= $this->plugins_check_table($pluginman, $version, array('full' => $showallplugins));
214 $output .= $this->box_end();
215 $output .= $this->upgrade_reload($reloadurl);
217 if ($pluginman->some_plugins_updatable()) {
218 $output .= $this->container_start('upgradepluginsinfo');
219 $output .= $this->help_icon('upgradepluginsinfo', 'core_admin', get_string('upgradepluginsfirst', 'core_admin'));
220 $output .= $this->container_end();
223 $button = new single_button($continueurl, get_string('upgradestart', 'admin'), 'get');
224 $button->class = 'continuebutton';
225 $output .= $this->render($button);
226 $output .= $this->footer();
232 * Display a page to confirm plugin installation cancelation.
234 * @param array $abortable list of \core\update\plugininfo
235 * @param moodle_url $continue
238 public function upgrade_confirm_abort_install_page(array $abortable, moodle_url
$continue) {
240 $pluginman = core_plugin_manager
::instance();
242 if (empty($abortable)) {
243 // The UI should not allow this.
244 throw new moodle_exception('err_no_plugin_install_abortable', 'core_plugin');
247 $out = $this->output
->header();
248 $out .= $this->output
->heading(get_string('cancelinstallhead', 'core_plugin'), 3);
249 $out .= $this->output
->container(get_string('cancelinstallinfo', 'core_plugin'), 'cancelinstallinfo');
251 foreach ($abortable as $pluginfo) {
252 $out .= $this->output
->heading($pluginfo->displayname
.' ('.$pluginfo->component
.')', 4);
253 $out .= $this->output
->container(get_string('cancelinstallinfodir', 'core_plugin', $pluginfo->rootdir
));
254 if ($repotype = $pluginman->plugin_external_source($pluginfo->component
)) {
255 $out .= $this->output
->container(get_string('uninstalldeleteconfirmexternal', 'core_plugin', $repotype),
256 'uninstalldeleteconfirmexternal');
260 $out .= $this->plugins_management_confirm_buttons($continue, $this->page
->url
);
261 $out .= $this->output
->footer();
267 * Display the admin notifications page.
268 * @param int $maturity
269 * @param bool $insecuredataroot warn dataroot is invalid
270 * @param bool $errorsdisplayed warn invalid dispaly error setting
271 * @param bool $cronoverdue warn cron not running
272 * @param bool $dbproblems warn db has problems
273 * @param bool $maintenancemode warn in maintenance mode
274 * @param bool $buggyiconvnomb warn iconv problems
275 * @param array|null $availableupdates array of \core\update\info objects or null
276 * @param int|null $availableupdatesfetch timestamp of the most recent updates fetch or null (unknown)
277 * @param string[] $cachewarnings An array containing warnings from the Cache API.
278 * @param array $eventshandlers Events 1 API handlers.
279 * @param bool $themedesignermode Warn about the theme designer mode.
280 * @param bool $devlibdir Warn about development libs directory presence.
282 * @return string HTML to output.
284 public function admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed,
285 $cronoverdue, $dbproblems, $maintenancemode, $availableupdates, $availableupdatesfetch,
286 $buggyiconvnomb, $registered, array $cachewarnings = array(), $eventshandlers = 0,
287 $themedesignermode = false, $devlibdir = false) {
291 $output .= $this->header();
292 $output .= $this->maturity_info($maturity);
293 $output .= $this->legacy_log_store_writing_error();
294 $output .= empty($CFG->disableupdatenotifications
) ?
$this->available_updates($availableupdates, $availableupdatesfetch) : '';
295 $output .= $this->insecure_dataroot_warning($insecuredataroot);
296 $output .= $this->development_libs_directories_warning($devlibdir);
297 $output .= $this->themedesignermode_warning($themedesignermode);
298 $output .= $this->display_errors_warning($errorsdisplayed);
299 $output .= $this->buggy_iconv_warning($buggyiconvnomb);
300 $output .= $this->cron_overdue_warning($cronoverdue);
301 $output .= $this->db_problems($dbproblems);
302 $output .= $this->maintenance_mode_warning($maintenancemode);
303 $output .= $this->cache_warnings($cachewarnings);
304 $output .= $this->events_handlers($eventshandlers);
305 $output .= $this->registration_warning($registered);
307 //////////////////////////////////////////////////////////////////////////////////////////////////
308 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
309 $output .= $this->moodle_copyright();
310 //////////////////////////////////////////////////////////////////////////////////////////////////
312 $output .= $this->footer();
318 * Display the plugin management page (admin/plugins.php).
320 * The filtering options array may contain following items:
321 * bool contribonly - show only contributed extensions
322 * bool updatesonly - show only plugins with an available update
324 * @param core_plugin_manager $pluginman
325 * @param \core\update\checker $checker
326 * @param array $options filtering options
327 * @return string HTML to output.
329 public function plugin_management_page(core_plugin_manager
$pluginman, \core\update\checker
$checker, array $options = array()) {
333 $output .= $this->header();
334 $output .= $this->heading(get_string('pluginsoverview', 'core_admin'));
335 $output .= $this->check_for_updates_button($checker, $this->page
->url
);
336 $output .= $this->plugins_overview_panel($pluginman, $options);
337 $output .= $this->plugins_control_panel($pluginman, $options);
338 $output .= $this->footer();
344 * Renders a button to fetch for available updates.
346 * @param \core\update\checker $checker
347 * @param moodle_url $reloadurl
348 * @return string HTML
350 public function check_for_updates_button(\core\update\checker
$checker, $reloadurl) {
354 if ($checker->enabled()) {
355 $output .= $this->container_start('checkforupdates');
356 $output .= $this->single_button(
357 new moodle_url($reloadurl, array('fetchupdates' => 1)),
358 get_string('checkforupdates', 'core_plugin')
360 if ($timefetched = $checker->get_last_timefetched()) {
361 $timefetched = userdate($timefetched, get_string('strftimedatetime', 'core_langconfig'));
362 $output .= $this->container(get_string('checkforupdateslast', 'core_plugin', $timefetched), 'lasttimefetched');
364 $output .= $this->container_end();
371 * Display a page to confirm the plugin uninstallation.
373 * @param core_plugin_manager $pluginman
374 * @param \core\plugininfo\base $pluginfo
375 * @param moodle_url $continueurl URL to continue after confirmation
376 * @param moodle_url $cancelurl URL to to go if cancelled
379 public function plugin_uninstall_confirm_page(core_plugin_manager
$pluginman, \core\plugininfo\base
$pluginfo, moodle_url
$continueurl, moodle_url
$cancelurl) {
382 $pluginname = $pluginman->plugin_name($pluginfo->component
);
384 $confirm = '<p>' . get_string('uninstallconfirm', 'core_plugin', array('name' => $pluginname)) . '</p>';
385 if ($extraconfirm = $pluginfo->get_uninstall_extra_warning()) {
386 $confirm .= $extraconfirm;
389 $output .= $this->output
->header();
390 $output .= $this->output
->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
391 $output .= $this->output
->confirm($confirm, $continueurl, $cancelurl);
392 $output .= $this->output
->footer();
398 * Display a page with results of plugin uninstallation and offer removal of plugin files.
400 * @param core_plugin_manager $pluginman
401 * @param \core\plugininfo\base $pluginfo
402 * @param progress_trace_buffer $progress
403 * @param moodle_url $continueurl URL to continue to remove the plugin folder
406 public function plugin_uninstall_results_removable_page(core_plugin_manager
$pluginman, \core\plugininfo\base
$pluginfo,
407 progress_trace_buffer
$progress, moodle_url
$continueurl) {
410 $pluginname = $pluginman->plugin_name($pluginfo->component
);
412 // Do not show navigation here, they must click one of the buttons.
413 $this->page
->set_pagelayout('maintenance');
414 $this->page
->set_cacheable(false);
416 $output .= $this->output
->header();
417 $output .= $this->output
->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
419 $output .= $this->output
->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
421 $confirm = $this->output
->container(get_string('uninstalldeleteconfirm', 'core_plugin',
422 array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir
)), 'uninstalldeleteconfirm');
424 if ($repotype = $pluginman->plugin_external_source($pluginfo->component
)) {
425 $confirm .= $this->output
->container(get_string('uninstalldeleteconfirmexternal', 'core_plugin', $repotype),
426 'uninstalldeleteconfirmexternal');
429 // After any uninstall we must execute full upgrade to finish the cleanup!
430 $output .= $this->output
->confirm($confirm, $continueurl, new moodle_url('/admin/index.php'));
431 $output .= $this->output
->footer();
437 * Display a page with results of plugin uninstallation and inform about the need to remove plugin files manually.
439 * @param core_plugin_manager $pluginman
440 * @param \core\plugininfo\base $pluginfo
441 * @param progress_trace_buffer $progress
444 public function plugin_uninstall_results_page(core_plugin_manager
$pluginman, \core\plugininfo\base
$pluginfo, progress_trace_buffer
$progress) {
447 $pluginname = $pluginfo->component
;
449 $output .= $this->output
->header();
450 $output .= $this->output
->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
452 $output .= $this->output
->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
454 $output .= $this->output
->box(get_string('uninstalldelete', 'core_plugin',
455 array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir
)), 'generalbox uninstalldelete');
456 $output .= $this->output
->continue_button(new moodle_url('/admin/index.php'));
457 $output .= $this->output
->footer();
463 * Display the plugin management page (admin/environment.php).
464 * @param array $versions
465 * @param string $version
466 * @param boolean $envstatus final result of env check (true/false)
467 * @param array $environment_results array of results gathered
468 * @return string HTML to output.
470 public function environment_check_page($versions, $version, $envstatus, $environment_results) {
472 $output .= $this->header();
474 // Print the component download link
475 $output .= html_writer
::tag('div', html_writer
::link(
476 new moodle_url('/admin/environment.php', array('action' => 'updatecomponent', 'sesskey' => sesskey())),
477 get_string('updatecomponent', 'admin')),
478 array('class' => 'reportlink'));
481 $output .= $this->heading(get_string('environment', 'admin'));
483 // Box with info and a menu to choose the version.
484 $output .= $this->box_start();
485 $output .= html_writer
::tag('div', get_string('adminhelpenvironment'));
486 $select = new single_select(new moodle_url('/admin/environment.php'), 'version', $versions, $version, null);
487 $select->label
= get_string('moodleversion');
488 $output .= $this->render($select);
489 $output .= $this->box_end();
492 $output .= $this->environment_check_table($envstatus, $environment_results);
494 $output .= $this->footer();
499 * Output a warning message, of the type that appears on the admin notifications page.
500 * @param string $message the message to display.
501 * @param string $type type class
502 * @return string HTML to output.
504 protected function warning($message, $type = 'warning') {
505 return $this->box($message, 'generalbox admin' . $type);
509 * Render an appropriate message if dataroot is insecure.
510 * @param bool $insecuredataroot
511 * @return string HTML to output.
513 protected function insecure_dataroot_warning($insecuredataroot) {
516 if ($insecuredataroot == INSECURE_DATAROOT_WARNING
) {
517 return $this->warning(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot
));
519 } else if ($insecuredataroot == INSECURE_DATAROOT_ERROR
) {
520 return $this->warning(get_string('datarootsecurityerror', 'admin', $CFG->dataroot
), 'error');
528 * Render a warning that a directory with development libs is present.
530 * @param bool $devlibdir True if the warning should be displayed.
533 protected function development_libs_directories_warning($devlibdir) {
536 $moreinfo = new moodle_url('/report/security/index.php');
537 $warning = get_string('devlibdirpresent', 'core_admin', ['moreinfourl' => $moreinfo->out()]);
538 return $this->warning($warning, 'error');
546 * Render an appropriate message if dataroot is insecure.
547 * @param bool $errorsdisplayed
548 * @return string HTML to output.
550 protected function display_errors_warning($errorsdisplayed) {
551 if (!$errorsdisplayed) {
555 return $this->warning(get_string('displayerrorswarning', 'admin'));
559 * Render an appropriate message if themdesignermode is enabled.
560 * @param bool $themedesignermode true if enabled
561 * @return string HTML to output.
563 protected function themedesignermode_warning($themedesignermode) {
564 if (!$themedesignermode) {
568 return $this->warning(get_string('themedesignermodewarning', 'admin'));
572 * Render an appropriate message if iconv is buggy and mbstring missing.
573 * @param bool $buggyiconvnomb
574 * @return string HTML to output.
576 protected function buggy_iconv_warning($buggyiconvnomb) {
577 if (!$buggyiconvnomb) {
581 return $this->warning(get_string('warningiconvbuggy', 'admin'));
585 * Render an appropriate message if cron has not been run recently.
586 * @param bool $cronoverdue
587 * @return string HTML to output.
589 public function cron_overdue_warning($cronoverdue) {
595 if (empty($CFG->cronclionly
)) {
596 $url = new moodle_url('/admin/cron.php');
597 if (!empty($CFG->cronremotepassword
)) {
598 $url = new moodle_url('/admin/cron.php', array('password' => $CFG->cronremotepassword
));
601 return $this->warning(get_string('cronwarning', 'admin', $url->out()) . ' ' .
602 $this->help_icon('cron', 'admin'));
605 // $CFG->cronclionly is not empty: cron can run only from CLI.
606 return $this->warning(get_string('cronwarningcli', 'admin') . ' ' .
607 $this->help_icon('cron', 'admin'));
611 * Render an appropriate message if there are any problems with the DB set-up.
612 * @param bool $dbproblems
613 * @return string HTML to output.
615 public function db_problems($dbproblems) {
620 return $this->warning($dbproblems);
624 * Renders cache warnings if there are any.
626 * @param string[] $cachewarnings
629 public function cache_warnings(array $cachewarnings) {
630 if (!count($cachewarnings)) {
633 return join("\n", array_map(array($this, 'warning'), $cachewarnings));
637 * Renders events 1 API handlers warning.
639 * @param array $eventshandlers
642 public function events_handlers($eventshandlers) {
643 if ($eventshandlers) {
645 foreach ($eventshandlers as $eventhandler) {
646 $components .= $eventhandler->component
. ', ';
648 $components = rtrim($components, ', ');
649 return $this->warning(get_string('eventshandlersinuse', 'admin', $components));
654 * Render an appropriate message if the site in in maintenance mode.
655 * @param bool $maintenancemode
656 * @return string HTML to output.
658 public function maintenance_mode_warning($maintenancemode) {
659 if (!$maintenancemode) {
663 $url = new moodle_url('/admin/settings.php', array('section' => 'maintenancemode'));
664 $url = $url->out(); // get_string() does not support objects in params
666 return $this->warning(get_string('sitemaintenancewarning2', 'admin', $url));
670 * Display a warning about installing development code if necesary.
671 * @param int $maturity
672 * @return string HTML to output.
674 protected function maturity_warning($maturity) {
675 if ($maturity == MATURITY_STABLE
) {
676 return ''; // No worries.
679 $maturitylevel = get_string('maturity' . $maturity, 'admin');
680 return $this->warning(
681 $this->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
682 $this->container($this->doc_link('admin/versions', get_string('morehelp'))),
687 * If necessary, displays a warning about upgrading a test site.
689 * @param string $testsite
690 * @return string HTML
692 protected function test_site_warning($testsite) {
698 $warning = (get_string('testsiteupgradewarning', 'admin', $testsite));
699 return $this->warning($warning, 'error');
703 * Output the copyright notice.
704 * @return string HTML to output.
706 protected function moodle_copyright() {
709 //////////////////////////////////////////////////////////////////////////////////////////////////
710 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
711 $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
712 '<a href="http://docs.moodle.org/dev/Releases" title="'.$CFG->version
.'">'.$CFG->release
.'</a><br />'.
713 'Copyright © 1999 onwards, Martin Dougiamas<br />'.
714 'and <a href="http://moodle.org/dev">many other contributors</a>.<br />'.
715 '<a href="http://docs.moodle.org/dev/License">GNU Public License</a>';
716 //////////////////////////////////////////////////////////////////////////////////////////////////
718 return $this->box($copyrighttext, 'copyright');
722 * Display a warning about installing development code if necesary.
723 * @param int $maturity
724 * @return string HTML to output.
726 protected function maturity_info($maturity) {
727 if ($maturity == MATURITY_STABLE
) {
728 return ''; // No worries.
733 if ($maturity == MATURITY_ALPHA
) {
737 $maturitylevel = get_string('maturity' . $maturity, 'admin');
738 $warningtext = get_string('maturitycoreinfo', 'admin', $maturitylevel);
739 $warningtext .= ' ' . $this->doc_link('admin/versions', get_string('morehelp'));
740 return $this->warning($warningtext, $level);
744 * Displays the info about available Moodle core and plugin updates
746 * The structure of the $updates param has changed since 2.4. It contains not only updates
747 * for the core itself, but also for all other installed plugins.
749 * @param array|null $updates array of (string)component => array of \core\update\info objects or null
750 * @param int|null $fetch timestamp of the most recent updates fetch or null (unknown)
753 protected function available_updates($updates, $fetch) {
756 $someupdateavailable = false;
757 if (is_array($updates)) {
758 if (is_array($updates['core'])) {
759 $someupdateavailable = true;
760 $updateinfo .= $this->heading(get_string('updateavailable', 'core_admin'), 3);
761 foreach ($updates['core'] as $update) {
762 $updateinfo .= $this->moodle_available_update_info($update);
764 $updateinfo .= html_writer
::tag('p', get_string('updateavailablerecommendation', 'core_admin'),
765 array('class' => 'updateavailablerecommendation'));
767 unset($updates['core']);
768 // If something has left in the $updates array now, it is updates for plugins.
769 if (!empty($updates)) {
770 $someupdateavailable = true;
771 $updateinfo .= $this->heading(get_string('updateavailableforplugin', 'core_admin'), 3);
772 $pluginsoverviewurl = new moodle_url('/admin/plugins.php', array('updatesonly' => 1));
773 $updateinfo .= $this->container(get_string('pluginsoverviewsee', 'core_admin',
774 array('url' => $pluginsoverviewurl->out())));
778 if (!$someupdateavailable) {
780 if ($fetch and ($fetch <= $now) and ($now - $fetch < HOURSECS
)) {
781 $updateinfo .= $this->heading(get_string('updateavailablenot', 'core_admin'), 3);
785 $updateinfo .= $this->container_start('checkforupdates');
786 $fetchurl = new moodle_url('/admin/index.php', array('fetchupdates' => 1, 'sesskey' => sesskey(), 'cache' => 0));
787 $updateinfo .= $this->single_button($fetchurl, get_string('checkforupdates', 'core_plugin'));
789 $updateinfo .= $this->container(get_string('checkforupdateslast', 'core_plugin',
790 userdate($fetch, get_string('strftimedatetime', 'core_langconfig'))));
792 $updateinfo .= $this->container_end();
794 return $this->warning($updateinfo);
798 * Display a warning about not being registered on Moodle.org if necesary.
800 * @param boolean $registered true if the site is registered on Moodle.org
801 * @return string HTML to output.
803 protected function registration_warning($registered) {
807 if (has_capability('moodle/site:config', context_system
::instance())) {
808 $registerbutton = $this->single_button(new moodle_url('/admin/registration/index.php'),
809 get_string('register', 'admin'));
810 $str = 'registrationwarning';
812 $registerbutton = '';
813 $str = 'registrationwarningcontactadmin';
816 return $this->warning( get_string($str, 'admin')
817 . ' ' . $this->help_icon('registration', 'admin') . $registerbutton ,
818 'error alert alert-danger');
825 * Return an admin page warning if site is not registered with moodle.org
829 public function warn_if_not_registered() {
830 return $this->registration_warning(\core\hub\registration
::is_registered());
834 * Helper method to render the information about the available Moodle update
836 * @param \core\update\info $updateinfo information about the available Moodle core update
838 protected function moodle_available_update_info(\core\update\info
$updateinfo) {
840 $boxclasses = 'moodleupdateinfo';
843 if (isset($updateinfo->release
)) {
844 $info[] = html_writer
::tag('span', get_string('updateavailable_release', 'core_admin', $updateinfo->release
),
845 array('class' => 'info release'));
848 if (isset($updateinfo->version
)) {
849 $info[] = html_writer
::tag('span', get_string('updateavailable_version', 'core_admin', $updateinfo->version
),
850 array('class' => 'info version'));
853 if (isset($updateinfo->maturity
)) {
854 $info[] = html_writer
::tag('span', get_string('maturity'.$updateinfo->maturity
, 'core_admin'),
855 array('class' => 'info maturity'));
856 $boxclasses .= ' maturity'.$updateinfo->maturity
;
859 if (isset($updateinfo->download
)) {
860 $info[] = html_writer
::link($updateinfo->download
, get_string('download'), array('class' => 'info download'));
863 if (isset($updateinfo->url
)) {
864 $info[] = html_writer
::link($updateinfo->url
, get_string('updateavailable_moreinfo', 'core_plugin'),
865 array('class' => 'info more'));
868 $box = $this->output
->box_start($boxclasses);
869 $box .= $this->output
->box(implode(html_writer
::tag('span', ' ', array('class' => 'separator')), $info), '');
870 $box .= $this->output
->box_end();
876 * Display a link to the release notes.
877 * @return string HTML to output.
879 protected function release_notes_link() {
880 $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/dev/Releases');
881 $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
882 return $this->box($releasenoteslink, 'generalbox releasenoteslink');
886 * Display the reload link that appears on several upgrade/install pages.
887 * @return string HTML to output.
889 function upgrade_reload($url) {
890 return html_writer
::empty_tag('br') .
891 html_writer
::tag('div',
892 html_writer
::link($url, $this->pix_icon('i/reload', '', '', array('class' => 'icon icon-pre')) .
893 get_string('reload'), array('title' => get_string('reload'))),
894 array('class' => 'continuebutton')) . html_writer
::empty_tag('br');
898 * Displays all known plugins and information about their installation or upgrade
900 * This default implementation renders all plugins into one big table. The rendering
902 * (bool)full = false: whether to display up-to-date plugins, too
903 * (bool)xdep = false: display the plugins with unsatisified dependecies only
905 * @param core_plugin_manager $pluginman provides information about the plugins.
906 * @param int $version the version of the Moodle code from version.php.
907 * @param array $options rendering options
908 * @return string HTML code
910 public function plugins_check_table(core_plugin_manager
$pluginman, $version, array $options = array()) {
912 $plugininfo = $pluginman->get_plugins();
914 if (empty($plugininfo)) {
918 $options['full'] = isset($options['full']) ?
(bool)$options['full'] : false;
919 $options['xdep'] = isset($options['xdep']) ?
(bool)$options['xdep'] : false;
921 $table = new html_table();
922 $table->id
= 'plugins-check';
923 $table->head
= array(
924 get_string('displayname', 'core_plugin').' / '.get_string('rootdir', 'core_plugin'),
925 get_string('versiondb', 'core_plugin'),
926 get_string('versiondisk', 'core_plugin'),
927 get_string('requires', 'core_plugin'),
928 get_string('source', 'core_plugin').' / '.get_string('status', 'core_plugin'),
930 $table->colclasses
= array(
931 'displayname', 'versiondb', 'versiondisk', 'requires', 'status',
933 $table->data
= array();
935 // Number of displayed plugins per type.
936 $numdisplayed = array();
937 // Number of plugins known to the plugin manager.
939 // Number of plugins requiring attention.
941 // List of all components we can cancel installation of.
942 $installabortable = $pluginman->list_cancellable_installations();
943 // List of all components we can cancel upgrade of.
944 $upgradeabortable = $pluginman->list_restorable_archives();
946 foreach ($plugininfo as $type => $plugins) {
948 $header = new html_table_cell($pluginman->plugintype_name_plural($type));
949 $header->header
= true;
950 $header->colspan
= count($table->head
);
951 $header = new html_table_row(array($header));
952 $header->attributes
['class'] = 'plugintypeheader type-' . $type;
954 $numdisplayed[$type] = 0;
956 if (empty($plugins) and $options['full']) {
957 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
958 $msg->colspan
= count($table->head
);
959 $row = new html_table_row(array($msg));
960 $row->attributes
['class'] .= 'msg msg-noneinstalled';
961 $table->data
[] = $header;
962 $table->data
[] = $row;
966 $plugintyperows = array();
968 foreach ($plugins as $name => $plugin) {
970 $row = new html_table_row();
971 $row->attributes
['class'] = 'type-' . $plugin->type
. ' name-' . $plugin->type
. '_' . $plugin->name
;
973 if ($this->page
->theme
->resolve_image_location('icon', $plugin->type
. '_' . $plugin->name
, null)) {
974 $icon = $this->output
->pix_icon('icon', '', $plugin->type
. '_' . $plugin->name
, array('class' => 'smallicon pluginicon'));
979 $displayname = new html_table_cell(
981 html_writer
::span($plugin->displayname
, 'pluginname').
982 html_writer
::div($plugin->get_dir(), 'plugindir')
985 $versiondb = new html_table_cell($plugin->versiondb
);
986 $versiondisk = new html_table_cell($plugin->versiondisk
);
988 if ($isstandard = $plugin->is_standard()) {
989 $row->attributes
['class'] .= ' standard';
990 $sourcelabel = html_writer
::span(get_string('sourcestd', 'core_plugin'), 'sourcetext label');
992 $row->attributes
['class'] .= ' extension';
993 $sourcelabel = html_writer
::span(get_string('sourceext', 'core_plugin'), 'sourcetext label label-info');
996 $coredependency = $plugin->is_core_dependency_satisfied($version);
997 $otherpluginsdependencies = $pluginman->are_dependencies_satisfied($plugin->get_other_required_plugins());
998 $dependenciesok = $coredependency && $otherpluginsdependencies;
1000 $statuscode = $plugin->get_status();
1001 $row->attributes
['class'] .= ' status-' . $statuscode;
1002 $statusclass = 'statustext label ';
1003 switch ($statuscode) {
1004 case core_plugin_manager
::PLUGIN_STATUS_NEW
:
1005 $statusclass .= $dependenciesok ?
'label-success' : 'label-warning';
1007 case core_plugin_manager
::PLUGIN_STATUS_UPGRADE
:
1008 $statusclass .= $dependenciesok ?
'label-info' : 'label-warning';
1010 case core_plugin_manager
::PLUGIN_STATUS_MISSING
:
1011 case core_plugin_manager
::PLUGIN_STATUS_DOWNGRADE
:
1012 case core_plugin_manager
::PLUGIN_STATUS_DELETE
:
1013 $statusclass .= 'label-important';
1015 case core_plugin_manager
::PLUGIN_STATUS_NODB
:
1016 case core_plugin_manager
::PLUGIN_STATUS_UPTODATE
:
1017 $statusclass .= $dependenciesok ?
'' : 'label-warning';
1020 $status = html_writer
::span(get_string('status_' . $statuscode, 'core_plugin'), $statusclass);
1022 if (!empty($installabortable[$plugin->component
])) {
1023 $status .= $this->output
->single_button(
1024 new moodle_url($this->page
->url
, array('abortinstall' => $plugin->component
)),
1025 get_string('cancelinstallone', 'core_plugin'),
1027 array('class' => 'actionbutton cancelinstallone')
1031 if (!empty($upgradeabortable[$plugin->component
])) {
1032 $status .= $this->output
->single_button(
1033 new moodle_url($this->page
->url
, array('abortupgrade' => $plugin->component
)),
1034 get_string('cancelupgradeone', 'core_plugin'),
1036 array('class' => 'actionbutton cancelupgradeone')
1040 $availableupdates = $plugin->available_updates();
1041 if (!empty($availableupdates)) {
1042 foreach ($availableupdates as $availableupdate) {
1043 $status .= $this->plugin_available_update_info($pluginman, $availableupdate);
1047 $status = new html_table_cell($sourcelabel.' '.$status);
1049 $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version));
1051 $statusisboring = in_array($statuscode, array(
1052 core_plugin_manager
::PLUGIN_STATUS_NODB
, core_plugin_manager
::PLUGIN_STATUS_UPTODATE
));
1054 if ($options['xdep']) {
1055 // we want to see only plugins with failed dependencies
1056 if ($dependenciesok) {
1060 } else if ($statusisboring and $dependenciesok and empty($availableupdates)) {
1061 // no change is going to happen to the plugin - display it only
1062 // if the user wants to see the full list
1063 if (empty($options['full'])) {
1071 // The plugin should be displayed.
1072 $numdisplayed[$type]++
;
1073 $row->cells
= array($displayname, $versiondb, $versiondisk, $requires, $status);
1074 $plugintyperows[] = $row;
1077 if (empty($numdisplayed[$type]) and empty($options['full'])) {
1081 $table->data
[] = $header;
1082 $table->data
= array_merge($table->data
, $plugintyperows);
1085 // Total number of displayed plugins.
1086 $sumdisplayed = array_sum($numdisplayed);
1088 if ($options['xdep']) {
1089 // At the plugins dependencies check page, display the table only.
1090 return html_writer
::table($table);
1093 $out = $this->output
->container_start('', 'plugins-check-info');
1095 if ($sumdisplayed == 0) {
1096 $out .= $this->output
->heading(get_string('pluginchecknone', 'core_plugin'));
1099 if (empty($options['full'])) {
1100 $out .= $this->output
->heading(get_string('plugincheckattention', 'core_plugin'));
1102 $out .= $this->output
->heading(get_string('plugincheckall', 'core_plugin'));
1106 $out .= $this->output
->container_start('actions');
1108 $installableupdates = $pluginman->filter_installable($pluginman->available_updates());
1109 if ($installableupdates) {
1110 $out .= $this->output
->single_button(
1111 new moodle_url($this->page
->url
, array('installupdatex' => 1)),
1112 get_string('updateavailableinstallall', 'core_admin', count($installableupdates)),
1114 array('class' => 'singlebutton updateavailableinstallall')
1118 if ($installabortable) {
1119 $out .= $this->output
->single_button(
1120 new moodle_url($this->page
->url
, array('abortinstallx' => 1)),
1121 get_string('cancelinstallall', 'core_plugin', count($installabortable)),
1123 array('class' => 'singlebutton cancelinstallall')
1127 if ($upgradeabortable) {
1128 $out .= $this->output
->single_button(
1129 new moodle_url($this->page
->url
, array('abortupgradex' => 1)),
1130 get_string('cancelupgradeall', 'core_plugin', count($upgradeabortable)),
1132 array('class' => 'singlebutton cancelupgradeall')
1136 $out .= html_writer
::div(html_writer
::link(new moodle_url($this->page
->url
, array('showallplugins' => 0)),
1137 get_string('plugincheckattention', 'core_plugin')).' '.html_writer
::span($sumattention, 'badge'));
1139 $out .= html_writer
::div(html_writer
::link(new moodle_url($this->page
->url
, array('showallplugins' => 1)),
1140 get_string('plugincheckall', 'core_plugin')).' '.html_writer
::span($sumtotal, 'badge'));
1142 $out .= $this->output
->container_end(); // End of .actions container.
1143 $out .= $this->output
->container_end(); // End of #plugins-check-info container.
1145 if ($sumdisplayed > 0 or $options['full']) {
1146 $out .= html_writer
::table($table);
1153 * Display the continue / cancel widgets for the plugins management pages.
1155 * @param null|moodle_url $continue URL for the continue button, should it be displayed
1156 * @param null|moodle_url $cancel URL for the cancel link, defaults to the current page
1157 * @return string HTML
1159 public function plugins_management_confirm_buttons(moodle_url
$continue=null, moodle_url
$cancel=null) {
1161 $out = html_writer
::start_div('plugins-management-confirm-buttons');
1163 if (!empty($continue)) {
1164 $out .= $this->output
->single_button($continue, get_string('continue'), 'post', array('class' => 'continue'));
1167 if (empty($cancel)) {
1168 $cancel = $this->page
->url
;
1170 $out .= html_writer
::div(html_writer
::link($cancel, get_string('cancel')), 'cancel');
1176 * Displays the information about missing dependencies
1178 * @param core_plugin_manager $pluginman
1181 protected function missing_dependencies(core_plugin_manager
$pluginman) {
1183 $dependencies = $pluginman->missing_dependencies();
1185 if (empty($dependencies)) {
1189 $available = array();
1190 $unavailable = array();
1193 foreach ($dependencies as $component => $remoteinfo) {
1194 if ($remoteinfo === false) {
1195 // The required version is not available. Let us check if there
1196 // is at least some version in the plugins directory.
1197 $remoteinfoanyversion = $pluginman->get_remote_plugin_info($component, ANY_VERSION
, false);
1198 if ($remoteinfoanyversion === false) {
1199 $unknown[$component] = $component;
1201 $unavailable[$component] = $remoteinfoanyversion;
1204 $available[$component] = $remoteinfo;
1208 $out = $this->output
->container_start('plugins-check-dependencies');
1210 if ($unavailable or $unknown) {
1211 $out .= $this->output
->heading(get_string('misdepsunavail', 'core_plugin'));
1213 $out .= $this->output
->notification(get_string('misdepsunknownlist', 'core_plugin', implode($unknown, ', ')));
1216 $unavailablelist = array();
1217 foreach ($unavailable as $component => $remoteinfoanyversion) {
1218 $unavailablelistitem = html_writer
::link('https://moodle.org/plugins/view.php?plugin='.$component,
1219 '<strong>'.$remoteinfoanyversion->name
.'</strong>');
1220 if ($remoteinfoanyversion->version
) {
1221 $unavailablelistitem .= ' ('.$component.' > '.$remoteinfoanyversion->version
->version
.')';
1223 $unavailablelistitem .= ' ('.$component.')';
1225 $unavailablelist[] = $unavailablelistitem;
1227 $out .= $this->output
->notification(get_string('misdepsunavaillist', 'core_plugin',
1228 implode($unavailablelist, ', ')));
1230 $out .= $this->output
->container_start('plugins-check-dependencies-actions');
1231 $out .= ' '.html_writer
::link(new moodle_url('/admin/tool/installaddon/'),
1232 get_string('dependencyuploadmissing', 'core_plugin'));
1233 $out .= $this->output
->container_end(); // End of .plugins-check-dependencies-actions container.
1237 $out .= $this->output
->heading(get_string('misdepsavail', 'core_plugin'));
1238 $out .= $this->output
->container_start('plugins-check-dependencies-actions');
1240 $installable = $pluginman->filter_installable($available);
1242 $out .= $this->output
->single_button(
1243 new moodle_url($this->page
->url
, array('installdepx' => 1)),
1244 get_string('dependencyinstallmissing', 'core_plugin', count($installable)),
1246 array('class' => 'singlebutton dependencyinstallmissing')
1250 $out .= html_writer
::div(html_writer
::link(new moodle_url('/admin/tool/installaddon/'),
1251 get_string('dependencyuploadmissing', 'core_plugin')), 'dependencyuploadmissing');
1253 $out .= $this->output
->container_end(); // End of .plugins-check-dependencies-actions container.
1255 $out .= $this->available_missing_dependencies_list($pluginman, $available);
1258 $out .= $this->output
->container_end(); // End of .plugins-check-dependencies container.
1264 * Displays the list if available missing dependencies.
1266 * @param core_plugin_manager $pluginman
1267 * @param array $dependencies
1270 protected function available_missing_dependencies_list(core_plugin_manager
$pluginman, array $dependencies) {
1273 $table = new html_table();
1274 $table->id
= 'plugins-check-available-dependencies';
1275 $table->head
= array(
1276 get_string('displayname', 'core_plugin'),
1277 get_string('release', 'core_plugin'),
1278 get_string('version', 'core_plugin'),
1279 get_string('supportedmoodleversions', 'core_plugin'),
1280 get_string('info', 'core'),
1282 $table->colclasses
= array('displayname', 'release', 'version', 'supportedmoodleversions', 'info');
1283 $table->data
= array();
1285 foreach ($dependencies as $plugin) {
1287 $supportedmoodles = array();
1288 foreach ($plugin->version
->supportedmoodles
as $moodle) {
1289 if ($CFG->branch
== str_replace('.', '', $moodle->release
)) {
1290 $supportedmoodles[] = html_writer
::span($moodle->release
, 'label label-success');
1292 $supportedmoodles[] = html_writer
::span($moodle->release
, 'label');
1296 $requriedby = $pluginman->other_plugins_that_require($plugin->component
);
1298 foreach ($requriedby as $ix => $val) {
1299 $inf = $pluginman->get_plugin_info($val);
1301 $requriedby[$ix] = $inf->displayname
.' ('.$inf->component
.')';
1304 $info = html_writer
::div(
1305 get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
1312 $info .= $this->output
->container_start('actions');
1314 $info .= html_writer
::div(
1315 html_writer
::link('https://moodle.org/plugins/view.php?plugin='.$plugin->component
,
1316 get_string('misdepinfoplugin', 'core_plugin')),
1320 $info .= html_writer
::div(
1321 html_writer
::link('https://moodle.org/plugins/pluginversion.php?id='.$plugin->version
->id
,
1322 get_string('misdepinfoversion', 'core_plugin')),
1326 $info .= html_writer
::div(html_writer
::link($plugin->version
->downloadurl
, get_string('download')), 'misdepdownload');
1328 if ($pluginman->is_remote_plugin_installable($plugin->component
, $plugin->version
->version
, $reason)) {
1329 $info .= $this->output
->single_button(
1330 new moodle_url($this->page
->url
, array('installdep' => $plugin->component
)),
1331 get_string('dependencyinstall', 'core_plugin'),
1333 array('class' => 'singlebutton dependencyinstall')
1336 $reasonhelp = $this->info_remote_plugin_not_installable($reason);
1338 $info .= html_writer
::div($reasonhelp, 'reasonhelp dependencyinstall');
1342 $info .= $this->output
->container_end(); // End of .actions container.
1344 $table->data
[] = array(
1345 html_writer
::div($plugin->name
, 'name').' '.html_writer
::div($plugin->component
, 'component'),
1346 $plugin->version
->release
,
1347 $plugin->version
->version
,
1348 implode($supportedmoodles, ' '),
1353 return html_writer
::table($table);
1357 * Explain why {@link core_plugin_manager::is_remote_plugin_installable()} returned false.
1359 * @param string $reason the reason code as returned by the plugin manager
1362 protected function info_remote_plugin_not_installable($reason) {
1364 if ($reason === 'notwritableplugintype' or $reason === 'notwritableplugin') {
1365 return $this->output
->help_icon('notwritable', 'core_plugin', get_string('notwritable', 'core_plugin'));
1368 if ($reason === 'remoteunavailable') {
1369 return $this->output
->help_icon('notdownloadable', 'core_plugin', get_string('notdownloadable', 'core_plugin'));
1376 * Formats the information that needs to go in the 'Requires' column.
1377 * @param \core\plugininfo\base $plugin the plugin we are rendering the row for.
1378 * @param core_plugin_manager $pluginman provides data on all the plugins.
1379 * @param string $version
1380 * @return string HTML code
1382 protected function required_column(\core\plugininfo\base
$plugin, core_plugin_manager
$pluginman, $version) {
1384 $requires = array();
1385 $displayuploadlink = false;
1386 $displayupdateslink = false;
1388 foreach ($pluginman->resolve_requirements($plugin, $version) as $reqname => $reqinfo) {
1389 if ($reqname === 'core') {
1390 if ($reqinfo->status
== $pluginman::REQUIREMENT_STATUS_OK
) {
1391 $class = 'requires-ok';
1394 $class = 'requires-failed';
1395 $label = html_writer
::span(get_string('dependencyfails', 'core_plugin'), 'label label-important');
1397 $requires[] = html_writer
::tag('li',
1398 html_writer
::span(get_string('moodleversion', 'core_plugin', $plugin->versionrequires
), 'dep dep-core').
1399 ' '.$label, array('class' => $class));
1404 if ($reqinfo->status
== $pluginman::REQUIREMENT_STATUS_OK
) {
1406 $class = 'requires-ok';
1408 } else if ($reqinfo->status
== $pluginman::REQUIREMENT_STATUS_MISSING
) {
1409 if ($reqinfo->availability
== $pluginman::REQUIREMENT_AVAILABLE
) {
1410 $label = html_writer
::span(get_string('dependencymissing', 'core_plugin'), 'label label-warning');
1411 $label .= ' '.html_writer
::span(get_string('dependencyavailable', 'core_plugin'), 'label label-warning');
1412 $class = 'requires-failed requires-missing requires-available';
1413 $actions[] = html_writer
::link(
1414 new moodle_url('https://moodle.org/plugins/view.php', array('plugin' => $reqname)),
1415 get_string('misdepinfoplugin', 'core_plugin')
1419 $label = html_writer
::span(get_string('dependencymissing', 'core_plugin'), 'label label-important');
1420 $label .= ' '.html_writer
::span(get_string('dependencyunavailable', 'core_plugin'),
1421 'label label-important');
1422 $class = 'requires-failed requires-missing requires-unavailable';
1424 $displayuploadlink = true;
1426 } else if ($reqinfo->status
== $pluginman::REQUIREMENT_STATUS_OUTDATED
) {
1427 if ($reqinfo->availability
== $pluginman::REQUIREMENT_AVAILABLE
) {
1428 $label = html_writer
::span(get_string('dependencyfails', 'core_plugin'), 'label label-warning');
1429 $label .= ' '.html_writer
::span(get_string('dependencyavailable', 'core_plugin'), 'label label-warning');
1430 $class = 'requires-failed requires-outdated requires-available';
1431 $displayupdateslink = true;
1434 $label = html_writer
::span(get_string('dependencyfails', 'core_plugin'), 'label label-important');
1435 $label .= ' '.html_writer
::span(get_string('dependencyunavailable', 'core_plugin'),
1436 'label label-important');
1437 $class = 'requires-failed requires-outdated requires-unavailable';
1439 $displayuploadlink = true;
1442 if ($reqinfo->reqver
!= ANY_VERSION
) {
1443 $str = 'otherpluginversion';
1445 $str = 'otherplugin';
1448 $requires[] = html_writer
::tag('li', html_writer
::span(
1449 get_string($str, 'core_plugin', array('component' => $reqname, 'version' => $reqinfo->reqver
)),
1450 'dep dep-plugin').' '.$label.' '.html_writer
::span(implode(' | ', $actions), 'actions'),
1451 array('class' => $class)
1460 $out = html_writer
::tag('ul', implode("\n", $requires));
1462 if ($displayuploadlink) {
1463 $out .= html_writer
::div(
1465 new moodle_url('/admin/tool/installaddon/'),
1466 get_string('dependencyuploadmissing', 'core_plugin')
1468 'dependencyuploadmissing'
1472 if ($displayupdateslink) {
1473 $out .= html_writer
::div(
1475 new moodle_url($this->page
->url
, array('sesskey' => sesskey(), 'fetchupdates' => 1)),
1476 get_string('checkforupdates', 'core_plugin')
1487 * Prints an overview about the plugins - number of installed, number of extensions etc.
1489 * @param core_plugin_manager $pluginman provides information about the plugins
1490 * @param array $options filtering options
1491 * @return string as usually
1493 public function plugins_overview_panel(core_plugin_manager
$pluginman, array $options = array()) {
1495 $plugininfo = $pluginman->get_plugins();
1497 $numtotal = $numextension = $numupdatable = 0;
1499 foreach ($plugininfo as $type => $plugins) {
1500 foreach ($plugins as $name => $plugin) {
1501 if ($plugin->available_updates()) {
1504 if ($plugin->get_status() === core_plugin_manager
::PLUGIN_STATUS_MISSING
) {
1508 if (!$plugin->is_standard()) {
1514 $infoall = html_writer
::link(
1515 new moodle_url($this->page
->url
, array('contribonly' => 0, 'updatesonly' => 0)),
1516 get_string('overviewall', 'core_plugin'),
1517 array('title' => get_string('filterall', 'core_plugin'))
1518 ).' '.html_writer
::span($numtotal, 'badge number number-all');
1520 $infoext = html_writer
::link(
1521 new moodle_url($this->page
->url
, array('contribonly' => 1, 'updatesonly' => 0)),
1522 get_string('overviewext', 'core_plugin'),
1523 array('title' => get_string('filtercontribonly', 'core_plugin'))
1524 ).' '.html_writer
::span($numextension, 'badge number number-additional');
1526 if ($numupdatable) {
1527 $infoupdatable = html_writer
::link(
1528 new moodle_url($this->page
->url
, array('contribonly' => 0, 'updatesonly' => 1)),
1529 get_string('overviewupdatable', 'core_plugin'),
1530 array('title' => get_string('filterupdatesonly', 'core_plugin'))
1531 ).' '.html_writer
::span($numupdatable, 'badge badge-info number number-updatable');
1533 // No updates, or the notifications disabled.
1534 $infoupdatable = '';
1537 $out = html_writer
::start_div('', array('id' => 'plugins-overview-panel'));
1539 if (!empty($options['updatesonly'])) {
1540 $out .= $this->output
->heading(get_string('overviewupdatable', 'core_plugin'), 3);
1541 } else if (!empty($options['contribonly'])) {
1542 $out .= $this->output
->heading(get_string('overviewext', 'core_plugin'), 3);
1545 if ($numupdatable) {
1546 $installableupdates = $pluginman->filter_installable($pluginman->available_updates());
1547 if ($installableupdates) {
1548 $out .= $this->output
->single_button(
1549 new moodle_url($this->page
->url
, array('installupdatex' => 1)),
1550 get_string('updateavailableinstallall', 'core_admin', count($installableupdates)),
1552 array('class' => 'singlebutton updateavailableinstallall')
1557 $out .= html_writer
::div($infoall, 'info info-all').
1558 html_writer
::div($infoext, 'info info-ext').
1559 html_writer
::div($infoupdatable, 'info info-updatable');
1561 $out .= html_writer
::end_div(); // End of #plugins-overview-panel block.
1567 * Displays all known plugins and links to manage them
1569 * This default implementation renders all plugins into one big table.
1571 * @param core_plugin_manager $pluginman provides information about the plugins.
1572 * @param array $options filtering options
1573 * @return string HTML code
1575 public function plugins_control_panel(core_plugin_manager
$pluginman, array $options = array()) {
1577 $plugininfo = $pluginman->get_plugins();
1579 // Filter the list of plugins according the options.
1580 if (!empty($options['updatesonly'])) {
1581 $updateable = array();
1582 foreach ($plugininfo as $plugintype => $pluginnames) {
1583 foreach ($pluginnames as $pluginname => $pluginfo) {
1584 $pluginavailableupdates = $pluginfo->available_updates();
1585 if (!empty($pluginavailableupdates)) {
1586 foreach ($pluginavailableupdates as $pluginavailableupdate) {
1587 $updateable[$plugintype][$pluginname] = $pluginfo;
1592 $plugininfo = $updateable;
1595 if (!empty($options['contribonly'])) {
1596 $contribs = array();
1597 foreach ($plugininfo as $plugintype => $pluginnames) {
1598 foreach ($pluginnames as $pluginname => $pluginfo) {
1599 if (!$pluginfo->is_standard()) {
1600 $contribs[$plugintype][$pluginname] = $pluginfo;
1604 $plugininfo = $contribs;
1607 if (empty($plugininfo)) {
1611 $table = new html_table();
1612 $table->id
= 'plugins-control-panel';
1613 $table->head
= array(
1614 get_string('displayname', 'core_plugin'),
1615 get_string('version', 'core_plugin'),
1616 get_string('availability', 'core_plugin'),
1617 get_string('actions', 'core_plugin'),
1618 get_string('notes','core_plugin'),
1620 $table->headspan
= array(1, 1, 1, 2, 1);
1621 $table->colclasses
= array(
1622 'pluginname', 'version', 'availability', 'settings', 'uninstall', 'notes'
1625 foreach ($plugininfo as $type => $plugins) {
1626 $heading = $pluginman->plugintype_name_plural($type);
1627 $pluginclass = core_plugin_manager
::resolve_plugininfo_class($type);
1628 if ($manageurl = $pluginclass::get_manage_url()) {
1629 $heading .= $this->output
->action_icon($manageurl, new pix_icon('i/settings',
1630 get_string('settings', 'core_plugin')));
1632 $header = new html_table_cell(html_writer
::tag('span', $heading, array('id'=>'plugin_type_cell_'.$type)));
1633 $header->header
= true;
1634 $header->colspan
= array_sum($table->headspan
);
1635 $header = new html_table_row(array($header));
1636 $header->attributes
['class'] = 'plugintypeheader type-' . $type;
1637 $table->data
[] = $header;
1639 if (empty($plugins)) {
1640 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
1641 $msg->colspan
= array_sum($table->headspan
);
1642 $row = new html_table_row(array($msg));
1643 $row->attributes
['class'] .= 'msg msg-noneinstalled';
1644 $table->data
[] = $row;
1648 foreach ($plugins as $name => $plugin) {
1649 $row = new html_table_row();
1650 $row->attributes
['class'] = 'type-' . $plugin->type
. ' name-' . $plugin->type
. '_' . $plugin->name
;
1652 if ($this->page
->theme
->resolve_image_location('icon', $plugin->type
. '_' . $plugin->name
, null)) {
1653 $icon = $this->output
->pix_icon('icon', '', $plugin->type
. '_' . $plugin->name
, array('class' => 'icon pluginicon'));
1655 $icon = $this->output
->spacer();
1657 $status = $plugin->get_status();
1658 $row->attributes
['class'] .= ' status-'.$status;
1659 $pluginname = html_writer
::tag('div', $icon.$plugin->displayname
, array('class' => 'displayname')).
1660 html_writer
::tag('div', $plugin->component
, array('class' => 'componentname'));
1661 $pluginname = new html_table_cell($pluginname);
1663 $version = html_writer
::div($plugin->versiondb
, 'versionnumber');
1664 if ((string)$plugin->release
!== '') {
1665 $version = html_writer
::div($plugin->release
, 'release').$version;
1667 $version = new html_table_cell($version);
1669 $isenabled = $plugin->is_enabled();
1670 if (is_null($isenabled)) {
1671 $availability = new html_table_cell('');
1672 } else if ($isenabled) {
1673 $row->attributes
['class'] .= ' enabled';
1674 $availability = new html_table_cell(get_string('pluginenabled', 'core_plugin'));
1676 $row->attributes
['class'] .= ' disabled';
1677 $availability = new html_table_cell(get_string('plugindisabled', 'core_plugin'));
1680 $settingsurl = $plugin->get_settings_url();
1681 if (!is_null($settingsurl)) {
1682 $settings = html_writer
::link($settingsurl, get_string('settings', 'core_plugin'), array('class' => 'settings'));
1686 $settings = new html_table_cell($settings);
1688 if ($uninstallurl = $pluginman->get_uninstall_url($plugin->component
, 'overview')) {
1689 $uninstall = html_writer
::link($uninstallurl, get_string('uninstall', 'core_plugin'));
1693 $uninstall = new html_table_cell($uninstall);
1695 if ($plugin->is_standard()) {
1696 $row->attributes
['class'] .= ' standard';
1699 $row->attributes
['class'] .= ' extension';
1700 $source = html_writer
::div(get_string('sourceext', 'core_plugin'), 'source label label-info');
1703 if ($status === core_plugin_manager
::PLUGIN_STATUS_MISSING
) {
1704 $msg = html_writer
::div(get_string('status_missing', 'core_plugin'), 'statusmsg label label-important');
1705 } else if ($status === core_plugin_manager
::PLUGIN_STATUS_NEW
) {
1706 $msg = html_writer
::div(get_string('status_new', 'core_plugin'), 'statusmsg label label-success');
1711 $requriedby = $pluginman->other_plugins_that_require($plugin->component
);
1713 $requiredby = html_writer
::tag('div', get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
1714 array('class' => 'requiredby'));
1720 if (is_array($plugin->available_updates())) {
1721 foreach ($plugin->available_updates() as $availableupdate) {
1722 $updateinfo .= $this->plugin_available_update_info($pluginman, $availableupdate);
1726 $notes = new html_table_cell($source.$msg.$requiredby.$updateinfo);
1728 $row->cells
= array(
1729 $pluginname, $version, $availability, $settings, $uninstall, $notes
1731 $table->data
[] = $row;
1735 return html_writer
::table($table);
1739 * Helper method to render the information about the available plugin update
1741 * @param core_plugin_manager $pluginman plugin manager instance
1742 * @param \core\update\info $updateinfo information about the available update for the plugin
1744 protected function plugin_available_update_info(core_plugin_manager
$pluginman, \core\update\info
$updateinfo) {
1746 $boxclasses = 'pluginupdateinfo';
1749 if (isset($updateinfo->release
)) {
1750 $info[] = html_writer
::div(
1751 get_string('updateavailable_release', 'core_plugin', $updateinfo->release
),
1756 if (isset($updateinfo->maturity
)) {
1757 $info[] = html_writer
::div(
1758 get_string('maturity'.$updateinfo->maturity
, 'core_admin'),
1761 $boxclasses .= ' maturity'.$updateinfo->maturity
;
1764 if (isset($updateinfo->download
)) {
1765 $info[] = html_writer
::div(
1766 html_writer
::link($updateinfo->download
, get_string('download')),
1771 if (isset($updateinfo->url
)) {
1772 $info[] = html_writer
::div(
1773 html_writer
::link($updateinfo->url
, get_string('updateavailable_moreinfo', 'core_plugin')),
1778 $box = html_writer
::start_div($boxclasses);
1779 $box .= html_writer
::div(
1780 get_string('updateavailable', 'core_plugin', $updateinfo->version
),
1783 $box .= html_writer
::div(
1784 implode(html_writer
::span(' ', 'separator'), $info),
1788 if ($pluginman->is_remote_plugin_installable($updateinfo->component
, $updateinfo->version
, $reason)) {
1789 $box .= $this->output
->single_button(
1790 new moodle_url($this->page
->url
, array('installupdate' => $updateinfo->component
,
1791 'installupdateversion' => $updateinfo->version
)),
1792 get_string('updateavailableinstall', 'core_admin'),
1794 array('class' => 'singlebutton updateavailableinstall')
1797 $reasonhelp = $this->info_remote_plugin_not_installable($reason);
1799 $box .= html_writer
::div($reasonhelp, 'reasonhelp updateavailableinstall');
1802 $box .= html_writer
::end_div();
1808 * This function will render one beautiful table with all the environmental
1809 * configuration and how it suits Moodle needs.
1811 * @param boolean $result final result of the check (true/false)
1812 * @param environment_results[] $environment_results array of results gathered
1813 * @return string HTML to output.
1815 public function environment_check_table($result, $environment_results) {
1819 $servertable = new html_table();//table for server checks
1820 $servertable->head
= array(
1823 get_string('report'),
1824 get_string('plugin'),
1825 get_string('status'),
1827 $servertable->colclasses
= array('centeralign name', 'centeralign info', 'leftalign report', 'leftalign plugin', 'centeralign status');
1828 $servertable->attributes
['class'] = 'admintable environmenttable generaltable';
1829 $servertable->id
= 'serverstatus';
1831 $serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
1833 $othertable = new html_table();//table for custom checks
1834 $othertable->head
= array(
1836 get_string('report'),
1837 get_string('plugin'),
1838 get_string('status'),
1840 $othertable->colclasses
= array('aligncenter info', 'alignleft report', 'alignleft plugin', 'aligncenter status');
1841 $othertable->attributes
['class'] = 'admintable environmenttable generaltable';
1842 $othertable->id
= 'otherserverstatus';
1844 $otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
1846 // Iterate over each environment_result
1848 foreach ($environment_results as $environment_result) {
1850 $warningline = false;
1853 $type = $environment_result->getPart();
1854 $info = $environment_result->getInfo();
1855 $status = $environment_result->getStatus();
1856 $plugin = $environment_result->getPluginName();
1857 $error_code = $environment_result->getErrorCode();
1858 // Process Report field
1859 $rec = new stdClass();
1860 // Something has gone wrong at parsing time
1862 $stringtouse = 'environmentxmlerror';
1863 $rec->error_code
= $error_code;
1864 $status = get_string('error');
1870 if ($rec->needed
= $environment_result->getNeededVersion()) {
1871 // We are comparing versions
1872 $rec->current
= $environment_result->getCurrentVersion();
1873 if ($environment_result->getLevel() == 'required') {
1874 $stringtouse = 'environmentrequireversion';
1876 $stringtouse = 'environmentrecommendversion';
1879 } else if ($environment_result->getPart() == 'custom_check') {
1880 // We are checking installed & enabled things
1881 if ($environment_result->getLevel() == 'required') {
1882 $stringtouse = 'environmentrequirecustomcheck';
1884 $stringtouse = 'environmentrecommendcustomcheck';
1887 } else if ($environment_result->getPart() == 'php_setting') {
1889 $stringtouse = 'environmentsettingok';
1890 } else if ($environment_result->getLevel() == 'required') {
1891 $stringtouse = 'environmentmustfixsetting';
1893 $stringtouse = 'environmentshouldfixsetting';
1897 if ($environment_result->getLevel() == 'required') {
1898 $stringtouse = 'environmentrequireinstall';
1900 $stringtouse = 'environmentrecommendinstall';
1904 // Calculate the status value
1905 if ($environment_result->getBypassStr() != '') { //Handle bypassed result (warning)
1906 $status = get_string('bypassed');
1907 $warningline = true;
1908 } else if ($environment_result->getRestrictStr() != '') { //Handle restricted result (error)
1909 $status = get_string('restricted');
1912 if ($status) { //Handle ok result (ok)
1913 $status = get_string('ok');
1915 if ($environment_result->getLevel() == 'optional') {//Handle check result (warning)
1916 $status = get_string('check');
1917 $warningline = true;
1918 } else { //Handle error result (error)
1919 $status = get_string('check');
1927 $linkparts = array();
1928 $linkparts[] = 'admin/environment';
1929 $linkparts[] = $type;
1931 $linkparts[] = $info;
1933 // Plugin environments do not have docs pages yet.
1934 if (empty($CFG->docroot
) or $environment_result->plugin
) {
1935 $report = get_string($stringtouse, 'admin', $rec);
1937 $report = $this->doc_link(join($linkparts, '/'), get_string($stringtouse, 'admin', $rec));
1939 // Enclose report text in div so feedback text will be displayed underneath it.
1940 $report = html_writer
::div($report);
1942 // Format error or warning line
1944 $messagetype = 'error';
1945 $statusclass = 'label-important';
1946 } else if ($warningline) {
1947 $messagetype = 'warn';
1948 $statusclass = 'label-warning';
1950 $messagetype = 'ok';
1951 $statusclass = 'label-success';
1953 $status = html_writer
::span($status, 'label ' . $statusclass);
1954 // Here we'll store all the feedback found
1956 // Append the feedback if there is some
1957 $feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), $messagetype);
1958 //Append the bypass if there is some
1959 $feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'warn');
1960 //Append the restrict if there is some
1961 $feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'error');
1963 $report .= $feedbacktext;
1965 // Add the row to the table
1966 if ($environment_result->getPart() == 'custom_check'){
1967 $otherdata[$messagetype][] = array ($info, $report, $plugin, $status);
1969 $serverdata[$messagetype][] = array ($type, $info, $report, $plugin, $status);
1974 //put errors first in
1975 $servertable->data
= array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']);
1976 $othertable->data
= array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']);
1980 $output .= $this->heading(get_string('serverchecks', 'admin'));
1981 $output .= html_writer
::table($servertable);
1982 if (count($othertable->data
)){
1983 $output .= $this->heading(get_string('customcheck', 'admin'));
1984 $output .= html_writer
::table($othertable);
1987 // Finally, if any error has happened, print the summary box
1989 $output .= $this->box(get_string('environmenterrortodo', 'admin'), 'environmentbox errorbox');
1996 * Render a simple page for providing the upgrade key.
1998 * @param moodle_url|string $url
2001 public function upgradekey_form_page($url) {
2004 $output .= $this->header();
2005 $output .= $this->container_start('upgradekeyreq');
2006 $output .= $this->heading(get_string('upgradekeyreq', 'core_admin'));
2007 $output .= html_writer
::start_tag('form', array('method' => 'POST', 'action' => $url));
2008 $output .= html_writer
::empty_tag('input', array('name' => 'upgradekey', 'type' => 'password'));
2009 $output .= html_writer
::empty_tag('input', array('value' => get_string('submit'), 'type' => 'submit'));
2010 $output .= html_writer
::end_tag('form');
2011 $output .= $this->container_end();
2012 $output .= $this->footer();
2018 * Check to see if writing to the deprecated legacy log store is enabled.
2020 * @return string An error message if writing to the legacy log store is enabled.
2022 protected function legacy_log_store_writing_error() {
2023 $enabled = get_config('logstore_legacy', 'loglegacy');
2024 $plugins = explode(',', get_config('tool_log', 'enabled_stores'));
2025 $enabled = $enabled && in_array('logstore_legacy', $plugins);
2028 return $this->warning(get_string('legacylogginginuse'));