MDL-78714 editor_tiny: Add xss_sanitize option to TinyMCE
[moodle.git] / admin / renderer.php
blob80cf7d408b463f3e4180b1d617ae6bdd4cf0894b
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * Standard HTML output renderer for core_admin subsystem.
20 * @package core
21 * @subpackage admin
22 * @copyright 2011 David Mudrak <david@moodle.com>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 class core_admin_renderer extends plugin_renderer_base {
27 /**
28 * Display the 'Do you acknowledge the terms of the GPL' page. The first page
29 * during install.
30 * @return string HTML to output.
32 public function install_licence_page() {
33 global $CFG;
34 $output = '';
36 $copyrightnotice = text_to_html(get_string('gpl3'));
37 $copyrightnotice = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $copyrightnotice); // extremely ugly validation hack
39 $continue = new single_button(new moodle_url($this->page->url, array(
40 'lang' => $CFG->lang, 'agreelicense' => 1)), get_string('continue'), 'get');
42 $output .= $this->header();
43 $output .= $this->heading('<a href="http://moodle.org">Moodle</a> - Modular Object-Oriented Dynamic Learning Environment');
44 $output .= $this->heading(get_string('copyrightnotice'));
45 $output .= $this->box($copyrightnotice, 'copyrightnotice');
46 $output .= html_writer::empty_tag('br');
47 $output .= $this->confirm(get_string('doyouagree'), $continue, "http://docs.moodle.org/dev/License");
48 $output .= $this->footer();
50 return $output;
53 /**
54 * Display page explaining proper upgrade process,
55 * there can not be any PHP file leftovers...
57 * @return string HTML to output.
59 public function upgrade_stale_php_files_page() {
60 $output = '';
61 $output .= $this->header();
62 $output .= $this->heading(get_string('upgradestalefiles', 'admin'));
63 $output .= $this->box_start('generalbox', 'notice');
64 $output .= format_text(get_string('upgradestalefilesinfo', 'admin', get_docs_url('Upgrading')), FORMAT_MARKDOWN);
65 $output .= html_writer::empty_tag('br');
66 $output .= html_writer::tag('div', $this->single_button($this->page->url, get_string('reload'), 'get'), array('class' => 'buttons'));
67 $output .= $this->box_end();
68 $output .= $this->footer();
70 return $output;
73 /**
74 * Display the 'environment check' page that is displayed during install.
75 * @param int $maturity
76 * @param boolean $envstatus final result of the check (true/false)
77 * @param array $environment_results array of results gathered
78 * @param string $release moodle release
79 * @return string HTML to output.
81 public function install_environment_page($maturity, $envstatus, $environment_results, $release) {
82 global $CFG;
83 $output = '';
85 $output .= $this->header();
86 $output .= $this->maturity_warning($maturity);
87 $output .= $this->heading("Moodle $release");
88 $output .= $this->release_notes_link();
90 $output .= $this->environment_check_table($envstatus, $environment_results);
92 if (!$envstatus) {
93 $output .= $this->upgrade_reload(new moodle_url($this->page->url, array('agreelicense' => 1, 'lang' => $CFG->lang)));
94 } else {
95 $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
96 $output .= $this->continue_button(new moodle_url($this->page->url, array(
97 'agreelicense' => 1, 'confirmrelease' => 1, 'lang' => $CFG->lang)));
100 $output .= $this->footer();
101 return $output;
105 * Displays the list of plugins with unsatisfied dependencies
107 * @param double|string|int $version Moodle on-disk version
108 * @param array $failed list of plugins with unsatisfied dependecies
109 * @param moodle_url $reloadurl URL of the page to recheck the dependencies
110 * @return string HTML
112 public function unsatisfied_dependencies_page($version, array $failed, moodle_url $reloadurl) {
113 $output = '';
115 $output .= $this->header();
116 $output .= $this->heading(get_string('pluginscheck', 'admin'));
117 $output .= $this->warning(get_string('pluginscheckfailed', 'admin', array('pluginslist' => implode(', ', array_unique($failed)))));
118 $output .= $this->plugins_check_table(core_plugin_manager::instance(), $version, array('xdep' => true));
119 $output .= $this->warning(get_string('pluginschecktodo', 'admin'));
120 $output .= $this->continue_button($reloadurl);
122 $output .= $this->footer();
124 return $output;
128 * Display the 'You are about to upgrade Moodle' page. The first page
129 * during upgrade.
130 * @param string $strnewversion
131 * @param int $maturity
132 * @param string $testsite
133 * @return string HTML to output.
135 public function upgrade_confirm_page($strnewversion, $maturity, $testsite) {
136 $output = '';
138 $continueurl = new moodle_url($this->page->url, array('confirmupgrade' => 1, 'cache' => 0));
139 $continue = new single_button($continueurl, get_string('continue'), 'get');
140 $cancelurl = new moodle_url('/admin/index.php');
142 $output .= $this->header();
143 $output .= $this->maturity_warning($maturity);
144 $output .= $this->test_site_warning($testsite);
145 $output .= $this->confirm(get_string('upgradesure', 'admin', $strnewversion), $continue, $cancelurl);
146 $output .= $this->footer();
148 return $output;
152 * Display the environment page during the upgrade process.
153 * @param string $release
154 * @param boolean $envstatus final result of env check (true/false)
155 * @param array $environment_results array of results gathered
156 * @return string HTML to output.
158 public function upgrade_environment_page($release, $envstatus, $environment_results) {
159 global $CFG;
160 $output = '';
162 $output .= $this->header();
163 $output .= $this->heading("Moodle $release");
164 $output .= $this->release_notes_link();
165 $output .= $this->environment_check_table($envstatus, $environment_results);
167 if (!$envstatus) {
168 $output .= $this->upgrade_reload(new moodle_url($this->page->url, array('confirmupgrade' => 1, 'cache' => 0)));
170 } else {
171 $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
173 if (empty($CFG->skiplangupgrade) and current_language() !== 'en') {
174 $output .= $this->box(get_string('langpackwillbeupdated', 'admin'), 'generalbox', 'notice');
177 $output .= $this->continue_button(new moodle_url($this->page->url, array(
178 'confirmupgrade' => 1, 'confirmrelease' => 1, 'cache' => 0)));
181 $output .= $this->footer();
183 return $output;
187 * Display the upgrade page that lists all the plugins that require attention.
188 * @param core_plugin_manager $pluginman provides information about the plugins.
189 * @param \core\update\checker $checker provides information about available updates.
190 * @param int $version the version of the Moodle code from version.php.
191 * @param bool $showallplugins
192 * @param moodle_url $reloadurl
193 * @param moodle_url $continueurl
194 * @return string HTML to output.
196 public function upgrade_plugin_check_page(core_plugin_manager $pluginman, \core\update\checker $checker,
197 $version, $showallplugins, $reloadurl, $continueurl) {
199 $output = '';
201 $output .= $this->header();
202 $output .= $this->box_start('generalbox', 'plugins-check-page');
203 $output .= html_writer::tag('p', get_string('pluginchecknotice', 'core_plugin'), array('class' => 'page-description'));
204 $output .= $this->check_for_updates_button($checker, $reloadurl);
205 $output .= $this->missing_dependencies($pluginman);
206 $output .= $this->plugins_check_table($pluginman, $version, array('full' => $showallplugins));
207 $output .= $this->box_end();
208 $output .= $this->upgrade_reload($reloadurl);
210 if ($pluginman->some_plugins_updatable()) {
211 $output .= $this->container_start('upgradepluginsinfo');
212 $output .= $this->help_icon('upgradepluginsinfo', 'core_admin', get_string('upgradepluginsfirst', 'core_admin'));
213 $output .= $this->container_end();
216 $button = new single_button($continueurl, get_string('upgradestart', 'admin'), 'get', single_button::BUTTON_PRIMARY);
217 $button->class = 'continuebutton';
218 $output .= $this->render($button);
219 $output .= $this->footer();
221 return $output;
225 * Display a page to confirm plugin installation cancelation.
227 * @param array $abortable list of \core\update\plugininfo
228 * @param moodle_url $continue
229 * @return string
231 public function upgrade_confirm_abort_install_page(array $abortable, moodle_url $continue) {
233 $pluginman = core_plugin_manager::instance();
235 if (empty($abortable)) {
236 // The UI should not allow this.
237 throw new moodle_exception('err_no_plugin_install_abortable', 'core_plugin');
240 $out = $this->output->header();
241 $out .= $this->output->heading(get_string('cancelinstallhead', 'core_plugin'), 3);
242 $out .= $this->output->container(get_string('cancelinstallinfo', 'core_plugin'), 'cancelinstallinfo');
244 foreach ($abortable as $pluginfo) {
245 $out .= $this->output->heading($pluginfo->displayname.' ('.$pluginfo->component.')', 4);
246 $out .= $this->output->container(get_string('cancelinstallinfodir', 'core_plugin', $pluginfo->rootdir));
247 if ($repotype = $pluginman->plugin_external_source($pluginfo->component)) {
248 $out .= $this->output->container(get_string('uninstalldeleteconfirmexternal', 'core_plugin', $repotype),
249 'alert alert-warning mt-2');
253 $out .= $this->plugins_management_confirm_buttons($continue, $this->page->url);
254 $out .= $this->output->footer();
256 return $out;
260 * Display the admin notifications page.
261 * @param int $maturity
262 * @param bool $insecuredataroot warn dataroot is invalid
263 * @param bool $errorsdisplayed warn invalid dispaly error setting
264 * @param bool $cronoverdue warn cron not running
265 * @param bool $dbproblems warn db has problems
266 * @param bool $maintenancemode warn in maintenance mode
267 * @param bool $buggyiconvnomb warn iconv problems
268 * @param array|null $availableupdates array of \core\update\info objects or null
269 * @param int|null $availableupdatesfetch timestamp of the most recent updates fetch or null (unknown)
270 * @param string[] $cachewarnings An array containing warnings from the Cache API.
271 * @param array $eventshandlers Events 1 API handlers.
272 * @param bool $themedesignermode Warn about the theme designer mode.
273 * @param bool $devlibdir Warn about development libs directory presence.
274 * @param bool $mobileconfigured Whether the mobile web services have been enabled
275 * @param bool $overridetossl Whether or not ssl is being forced.
276 * @param bool $invalidforgottenpasswordurl Whether the forgotten password URL does not link to a valid URL.
277 * @param bool $croninfrequent If true, warn that cron hasn't run in the past few minutes
278 * @param bool $showcampaigncontent Whether the campaign content should be visible or not.
279 * @param bool $showfeedbackencouragement Whether the feedback encouragement content should be displayed or not.
280 * @param bool $showservicesandsupport Whether the services and support content should be displayed or not.
281 * @param string $xmlrpcwarning XML-RPC deprecation warning message.
283 * @return string HTML to output.
285 public function admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed,
286 $cronoverdue, $dbproblems, $maintenancemode, $availableupdates, $availableupdatesfetch,
287 $buggyiconvnomb, $registered, array $cachewarnings = array(), $eventshandlers = 0,
288 $themedesignermode = false, $devlibdir = false, $mobileconfigured = false,
289 $overridetossl = false, $invalidforgottenpasswordurl = false, $croninfrequent = false,
290 $showcampaigncontent = false, bool $showfeedbackencouragement = false, bool $showservicesandsupport = false,
291 $xmlrpcwarning = '') {
293 global $CFG;
294 $output = '';
296 $output .= $this->header();
297 $output .= $this->output->heading(get_string('notifications', 'admin'));
298 $output .= $this->maturity_info($maturity);
299 $output .= empty($CFG->disableupdatenotifications) ? $this->available_updates($availableupdates, $availableupdatesfetch) : '';
300 $output .= $this->insecure_dataroot_warning($insecuredataroot);
301 $output .= $this->development_libs_directories_warning($devlibdir);
302 $output .= $this->themedesignermode_warning($themedesignermode);
303 $output .= $this->display_errors_warning($errorsdisplayed);
304 $output .= $this->buggy_iconv_warning($buggyiconvnomb);
305 $output .= $this->cron_overdue_warning($cronoverdue);
306 $output .= $this->cron_infrequent_warning($croninfrequent);
307 $output .= $this->db_problems($dbproblems);
308 $output .= $this->maintenance_mode_warning($maintenancemode);
309 $output .= $this->overridetossl_warning($overridetossl);
310 $output .= $this->cache_warnings($cachewarnings);
311 $output .= $this->events_handlers($eventshandlers);
312 $output .= $this->registration_warning($registered);
313 $output .= $this->mobile_configuration_warning($mobileconfigured);
314 $output .= $this->forgotten_password_url_warning($invalidforgottenpasswordurl);
315 $output .= $this->mnet_deprecation_warning($xmlrpcwarning);
316 $output .= $this->userfeedback_encouragement($showfeedbackencouragement);
317 $output .= $this->services_and_support_content($showservicesandsupport);
318 $output .= $this->campaign_content($showcampaigncontent);
320 //////////////////////////////////////////////////////////////////////////////////////////////////
321 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
322 $output .= $this->moodle_copyright();
323 //////////////////////////////////////////////////////////////////////////////////////////////////
325 $output .= $this->footer();
327 return $output;
331 * Display the plugin management page (admin/plugins.php).
333 * The filtering options array may contain following items:
334 * bool contribonly - show only contributed extensions
335 * bool updatesonly - show only plugins with an available update
337 * @param core_plugin_manager $pluginman
338 * @param \core\update\checker $checker
339 * @param array $options filtering options
340 * @return string HTML to output.
342 public function plugin_management_page(core_plugin_manager $pluginman, \core\update\checker $checker, array $options = array()) {
344 $output = '';
346 $output .= $this->header();
347 $output .= $this->heading(get_string('pluginsoverview', 'core_admin'));
348 $output .= $this->check_for_updates_button($checker, $this->page->url);
349 $output .= $this->plugins_overview_panel($pluginman, $options);
350 $output .= $this->plugins_control_panel($pluginman, $options);
351 $output .= $this->footer();
353 return $output;
357 * Renders a button to fetch for available updates.
359 * @param \core\update\checker $checker
360 * @param moodle_url $reloadurl
361 * @return string HTML
363 public function check_for_updates_button(\core\update\checker $checker, $reloadurl) {
365 $output = '';
367 if ($checker->enabled()) {
368 $output .= $this->container_start('checkforupdates mb-4');
369 $output .= $this->single_button(
370 new moodle_url($reloadurl, array('fetchupdates' => 1)),
371 get_string('checkforupdates', 'core_plugin')
373 if ($timefetched = $checker->get_last_timefetched()) {
374 $timefetched = userdate($timefetched, get_string('strftimedatetime', 'core_langconfig'));
375 $output .= $this->container(get_string('checkforupdateslast', 'core_plugin', $timefetched),
376 'lasttimefetched small text-muted mt-1');
378 $output .= $this->container_end();
381 return $output;
385 * Display a page to confirm the plugin uninstallation.
387 * @param core_plugin_manager $pluginman
388 * @param \core\plugininfo\base $pluginfo
389 * @param moodle_url $continueurl URL to continue after confirmation
390 * @param moodle_url $cancelurl URL to to go if cancelled
391 * @return string
393 public function plugin_uninstall_confirm_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, moodle_url $continueurl, moodle_url $cancelurl) {
394 $output = '';
396 $pluginname = $pluginman->plugin_name($pluginfo->component);
398 $confirm = '<p>' . get_string('uninstallconfirm', 'core_plugin', array('name' => $pluginname)) . '</p>';
399 if ($extraconfirm = $pluginfo->get_uninstall_extra_warning()) {
400 $confirm .= $extraconfirm;
403 $output .= $this->output->header();
404 $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
405 $output .= $this->output->confirm($confirm, $continueurl, $cancelurl);
406 $output .= $this->output->footer();
408 return $output;
412 * Display a page with results of plugin uninstallation and offer removal of plugin files.
414 * @param core_plugin_manager $pluginman
415 * @param \core\plugininfo\base $pluginfo
416 * @param progress_trace_buffer $progress
417 * @param moodle_url $continueurl URL to continue to remove the plugin folder
418 * @return string
420 public function plugin_uninstall_results_removable_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo,
421 progress_trace_buffer $progress, moodle_url $continueurl) {
422 $output = '';
424 $pluginname = $pluginman->plugin_name($pluginfo->component);
426 // Do not show navigation here, they must click one of the buttons.
427 $this->page->set_pagelayout('maintenance');
428 $this->page->set_cacheable(false);
430 $output .= $this->output->header();
431 $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
433 $output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
435 $confirm = $this->output->container(get_string('uninstalldeleteconfirm', 'core_plugin',
436 array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'uninstalldeleteconfirm');
438 if ($repotype = $pluginman->plugin_external_source($pluginfo->component)) {
439 $confirm .= $this->output->container(get_string('uninstalldeleteconfirmexternal', 'core_plugin', $repotype),
440 'alert alert-warning mt-2');
443 // After any uninstall we must execute full upgrade to finish the cleanup!
444 $output .= $this->output->confirm($confirm, $continueurl, new moodle_url('/admin/index.php'));
445 $output .= $this->output->footer();
447 return $output;
451 * Display a page with results of plugin uninstallation and inform about the need to remove plugin files manually.
453 * @param core_plugin_manager $pluginman
454 * @param \core\plugininfo\base $pluginfo
455 * @param progress_trace_buffer $progress
456 * @return string
458 public function plugin_uninstall_results_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, progress_trace_buffer $progress) {
459 $output = '';
461 $pluginname = $pluginfo->component;
463 $output .= $this->output->header();
464 $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
466 $output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
468 $output .= $this->output->box(get_string('uninstalldelete', 'core_plugin',
469 array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'generalbox uninstalldelete');
470 $output .= $this->output->continue_button(new moodle_url('/admin/index.php'));
471 $output .= $this->output->footer();
473 return $output;
477 * Display the plugin management page (admin/environment.php).
478 * @param array $versions
479 * @param string $version
480 * @param boolean $envstatus final result of env check (true/false)
481 * @param array $environment_results array of results gathered
482 * @return string HTML to output.
484 public function environment_check_page($versions, $version, $envstatus, $environment_results) {
485 $output = '';
486 $output .= $this->header();
488 // Print the component download link
489 $output .= html_writer::tag('div', html_writer::link(
490 new moodle_url('/admin/environment.php', array('action' => 'updatecomponent', 'sesskey' => sesskey())),
491 get_string('updatecomponent', 'admin')),
492 array('class' => 'reportlink'));
494 // Heading.
495 $output .= $this->heading(get_string('environment', 'admin'));
497 // Box with info and a menu to choose the version.
498 $output .= $this->box_start();
499 $output .= html_writer::tag('div', get_string('adminhelpenvironment'));
500 $select = new single_select(new moodle_url('/admin/environment.php'), 'version', $versions, $version, null);
501 $select->label = get_string('moodleversion');
502 $output .= $this->render($select);
503 $output .= $this->box_end();
505 // The results
506 $output .= $this->environment_check_table($envstatus, $environment_results);
508 $output .= $this->footer();
509 return $output;
513 * Output a warning message, of the type that appears on the admin notifications page.
514 * @param string $message the message to display.
515 * @param string $type type class
516 * @return string HTML to output.
518 protected function warning($message, $type = 'warning') {
519 return $this->box($message, 'generalbox alert alert-' . $type);
523 * Render an appropriate message if dataroot is insecure.
524 * @param bool $insecuredataroot
525 * @return string HTML to output.
527 protected function insecure_dataroot_warning($insecuredataroot) {
528 global $CFG;
530 if ($insecuredataroot == INSECURE_DATAROOT_WARNING) {
531 return $this->warning(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot));
533 } else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) {
534 return $this->warning(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'danger');
536 } else {
537 return '';
542 * Render a warning that a directory with development libs is present.
544 * @param bool $devlibdir True if the warning should be displayed.
545 * @return string
547 protected function development_libs_directories_warning($devlibdir) {
549 if ($devlibdir) {
550 $moreinfo = new moodle_url('/report/security/index.php');
551 $warning = get_string('devlibdirpresent', 'core_admin', ['moreinfourl' => $moreinfo->out()]);
552 return $this->warning($warning, 'danger');
554 } else {
555 return '';
560 * Render an appropriate message if dataroot is insecure.
561 * @param bool $errorsdisplayed
562 * @return string HTML to output.
564 protected function display_errors_warning($errorsdisplayed) {
565 if (!$errorsdisplayed) {
566 return '';
569 return $this->warning(get_string('displayerrorswarning', 'admin'));
573 * Render an appropriate message if themdesignermode is enabled.
574 * @param bool $themedesignermode true if enabled
575 * @return string HTML to output.
577 protected function themedesignermode_warning($themedesignermode) {
578 if (!$themedesignermode) {
579 return '';
582 return $this->warning(get_string('themedesignermodewarning', 'admin'));
586 * Render an appropriate message if iconv is buggy and mbstring missing.
587 * @param bool $buggyiconvnomb
588 * @return string HTML to output.
590 protected function buggy_iconv_warning($buggyiconvnomb) {
591 if (!$buggyiconvnomb) {
592 return '';
595 return $this->warning(get_string('warningiconvbuggy', 'admin'));
599 * Render an appropriate message if cron has not been run recently.
600 * @param bool $cronoverdue
601 * @return string HTML to output.
603 public function cron_overdue_warning($cronoverdue) {
604 global $CFG;
605 if (!$cronoverdue) {
606 return '';
609 $check = new \tool_task\check\cronrunning();
610 $result = $check->get_result();
611 return $this->warning($result->get_summary() . '&nbsp;' . $this->help_icon('cron', 'admin'));
615 * Render an appropriate message if cron is not being run frequently (recommended every minute).
617 * @param bool $croninfrequent
618 * @return string HTML to output.
620 public function cron_infrequent_warning(bool $croninfrequent) : string {
621 global $CFG;
623 if (!$croninfrequent) {
624 return '';
627 $check = new \tool_task\check\cronrunning();
628 $result = $check->get_result();
629 return $this->warning($result->get_summary() . '&nbsp;' . $this->help_icon('cron', 'admin'));
633 * Render an appropriate message if there are any problems with the DB set-up.
634 * @param bool $dbproblems
635 * @return string HTML to output.
637 public function db_problems($dbproblems) {
638 if (!$dbproblems) {
639 return '';
642 return $this->warning($dbproblems);
646 * Renders cache warnings if there are any.
648 * @param string[] $cachewarnings
649 * @return string
651 public function cache_warnings(array $cachewarnings) {
652 if (!count($cachewarnings)) {
653 return '';
655 return join("\n", array_map(array($this, 'warning'), $cachewarnings));
659 * Renders events 1 API handlers warning.
661 * @param array $eventshandlers
662 * @return string
664 public function events_handlers($eventshandlers) {
665 if ($eventshandlers) {
666 $components = '';
667 foreach ($eventshandlers as $eventhandler) {
668 $components .= $eventhandler->component . ', ';
670 $components = rtrim($components, ', ');
671 return $this->warning(get_string('eventshandlersinuse', 'admin', $components));
676 * Render an appropriate message if the site in in maintenance mode.
677 * @param bool $maintenancemode
678 * @return string HTML to output.
680 public function maintenance_mode_warning($maintenancemode) {
681 if (!$maintenancemode) {
682 return '';
685 $url = new moodle_url('/admin/settings.php', array('section' => 'maintenancemode'));
686 $url = $url->out(); // get_string() does not support objects in params
688 return $this->warning(get_string('sitemaintenancewarning2', 'admin', $url));
692 * Render a warning that ssl is forced because the site was on loginhttps.
694 * @param bool $overridetossl Whether or not ssl is being forced.
695 * @return string
697 protected function overridetossl_warning($overridetossl) {
698 if (!$overridetossl) {
699 return '';
701 $warning = get_string('overridetossl', 'core_admin');
702 return $this->warning($warning, 'warning');
706 * Display a warning about installing development code if necesary.
707 * @param int $maturity
708 * @return string HTML to output.
710 protected function maturity_warning($maturity) {
711 if ($maturity == MATURITY_STABLE) {
712 return ''; // No worries.
715 $maturitylevel = get_string('maturity' . $maturity, 'admin');
716 return $this->warning(
717 $this->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
718 $this->container($this->doc_link('admin/versions', get_string('morehelp'))),
719 'danger');
723 * If necessary, displays a warning about upgrading a test site.
725 * @param string $testsite
726 * @return string HTML
728 protected function test_site_warning($testsite) {
730 if (!$testsite) {
731 return '';
734 $warning = (get_string('testsiteupgradewarning', 'admin', $testsite));
735 return $this->warning($warning, 'danger');
739 * Output the copyright notice.
740 * @return string HTML to output.
742 protected function moodle_copyright() {
743 global $CFG;
745 //////////////////////////////////////////////////////////////////////////////////////////////////
746 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
747 $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
748 '<a href="http://docs.moodle.org/dev/Releases" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
749 'Copyright &copy; 1999 onwards, Martin Dougiamas<br />'.
750 'and <a href="http://moodle.org/dev">many other contributors</a>.<br />'.
751 '<a href="http://docs.moodle.org/dev/License">GNU Public License</a>';
752 //////////////////////////////////////////////////////////////////////////////////////////////////
754 return $this->box($copyrighttext, 'copyright');
758 * Display a warning about installing development code if necesary.
759 * @param int $maturity
760 * @return string HTML to output.
762 protected function maturity_info($maturity) {
763 if ($maturity == MATURITY_STABLE) {
764 return ''; // No worries.
767 $level = 'warning';
769 if ($maturity == MATURITY_ALPHA) {
770 $level = 'danger';
773 $maturitylevel = get_string('maturity' . $maturity, 'admin');
774 $warningtext = get_string('maturitycoreinfo', 'admin', $maturitylevel);
775 $warningtext .= ' ' . $this->doc_link('admin/versions', get_string('morehelp'));
776 return $this->warning($warningtext, $level);
780 * Displays the info about available Moodle core and plugin updates
782 * The structure of the $updates param has changed since 2.4. It contains not only updates
783 * for the core itself, but also for all other installed plugins.
785 * @param array|null $updates array of (string)component => array of \core\update\info objects or null
786 * @param int|null $fetch timestamp of the most recent updates fetch or null (unknown)
787 * @return string
789 protected function available_updates($updates, $fetch) {
791 $updateinfo = '';
792 $someupdateavailable = false;
793 if (is_array($updates)) {
794 if (is_array($updates['core'])) {
795 $someupdateavailable = true;
796 $updateinfo .= $this->heading(get_string('updateavailable', 'core_admin'), 3);
797 foreach ($updates['core'] as $update) {
798 $updateinfo .= $this->moodle_available_update_info($update);
800 $updateinfo .= html_writer::tag('p', get_string('updateavailablerecommendation', 'core_admin'),
801 array('class' => 'updateavailablerecommendation'));
803 unset($updates['core']);
804 // If something has left in the $updates array now, it is updates for plugins.
805 if (!empty($updates)) {
806 $someupdateavailable = true;
807 $updateinfo .= $this->heading(get_string('updateavailableforplugin', 'core_admin'), 3);
808 $pluginsoverviewurl = new moodle_url('/admin/plugins.php', array('updatesonly' => 1));
809 $updateinfo .= $this->container(get_string('pluginsoverviewsee', 'core_admin',
810 array('url' => $pluginsoverviewurl->out())));
814 if (!$someupdateavailable) {
815 $now = time();
816 if ($fetch and ($fetch <= $now) and ($now - $fetch < HOURSECS)) {
817 $updateinfo .= $this->heading(get_string('updateavailablenot', 'core_admin'), 3);
821 $updateinfo .= $this->container_start('checkforupdates mt-1');
822 $fetchurl = new moodle_url('/admin/index.php', array('fetchupdates' => 1, 'sesskey' => sesskey(), 'cache' => 0));
823 $updateinfo .= $this->single_button($fetchurl, get_string('checkforupdates', 'core_plugin'));
824 if ($fetch) {
825 $updateinfo .= $this->container(get_string('checkforupdateslast', 'core_plugin',
826 userdate($fetch, get_string('strftimedatetime', 'core_langconfig'))));
828 $updateinfo .= $this->container_end();
830 return $this->warning($updateinfo);
834 * Display a warning about not being registered on Moodle.org if necesary.
836 * @param boolean $registered true if the site is registered on Moodle.org
837 * @return string HTML to output.
839 protected function registration_warning($registered) {
841 if (!$registered && site_is_public()) {
842 if (has_capability('moodle/site:config', context_system::instance())) {
843 $registerbutton = $this->single_button(new moodle_url('/admin/registration/index.php'),
844 get_string('register', 'admin'));
845 $str = 'registrationwarning';
846 } else {
847 $registerbutton = '';
848 $str = 'registrationwarningcontactadmin';
851 return $this->warning( get_string($str, 'admin')
852 . '&nbsp;' . $this->help_icon('registration', 'admin') . $registerbutton ,
853 'error alert alert-danger');
856 return '';
860 * Return an admin page warning if site is not registered with moodle.org
862 * @return string
864 public function warn_if_not_registered() {
865 return $this->registration_warning(\core\hub\registration::is_registered());
869 * Display a warning about the Mobile Web Services being disabled.
871 * @param boolean $mobileconfigured true if mobile web services are enabled
872 * @return string HTML to output.
874 protected function mobile_configuration_warning($mobileconfigured) {
875 $output = '';
876 if (!$mobileconfigured) {
877 $settingslink = new moodle_url('/admin/settings.php', ['section' => 'mobilesettings']);
878 $configurebutton = $this->single_button($settingslink, get_string('enablemobilewebservice', 'admin'));
879 $output .= $this->warning(get_string('mobilenotconfiguredwarning', 'admin') . '&nbsp;' . $configurebutton);
882 return $output;
886 * Display campaign content.
888 * @param bool $showcampaigncontent Whether the campaign content should be visible or not.
889 * @return string the campaign content raw html.
891 protected function campaign_content(bool $showcampaigncontent): string {
892 if (!$showcampaigncontent) {
893 return '';
896 $lang = current_language();
897 $url = "https://campaign.moodle.org/current/lms/{$lang}/install/";
898 $params = [
899 'url' => $url,
900 'iframeid' => 'campaign-content'
903 return $this->render_from_template('core/external_content_banner', $params);
907 * Display services and support content.
909 * @param bool $showservicesandsupport Whether the services and support content should be visible or not.
910 * @return string the campaign content raw html.
912 protected function services_and_support_content(bool $showservicesandsupport): string {
913 if (!$showservicesandsupport) {
914 return '';
917 $lang = current_language();
918 $url = "https://campaign.moodle.org/current/lms/{$lang}/servicesandsupport/";
919 $params = [
920 'url' => $url,
921 'iframeid' => 'services-support-content'
924 return $this->render_from_template('core/external_content_banner', $params);
928 * Display a warning about the forgotten password URL not linking to a valid URL.
930 * @param boolean $invalidforgottenpasswordurl true if the forgotten password URL is not valid
931 * @return string HTML to output.
933 protected function forgotten_password_url_warning($invalidforgottenpasswordurl) {
934 $output = '';
935 if ($invalidforgottenpasswordurl) {
936 $settingslink = new moodle_url('/admin/settings.php', ['section' => 'manageauths']);
937 $configurebutton = $this->single_button($settingslink, get_string('check', 'moodle'));
938 $output .= $this->warning(get_string('invalidforgottenpasswordurl', 'admin') . '&nbsp;' . $configurebutton,
939 'error alert alert-danger');
942 return $output;
946 * Helper method to render the information about the available Moodle update
948 * @param \core\update\info $updateinfo information about the available Moodle core update
950 protected function moodle_available_update_info(\core\update\info $updateinfo) {
952 $boxclasses = 'moodleupdateinfo mb-2';
953 $info = array();
955 if (isset($updateinfo->release)) {
956 $info[] = html_writer::tag('span', get_string('updateavailable_release', 'core_admin', $updateinfo->release),
957 array('class' => 'info release'));
960 if (isset($updateinfo->version)) {
961 $info[] = html_writer::tag('span', get_string('updateavailable_version', 'core_admin', $updateinfo->version),
962 array('class' => 'info version'));
965 if (isset($updateinfo->maturity)) {
966 $info[] = html_writer::tag('span', get_string('maturity'.$updateinfo->maturity, 'core_admin'),
967 array('class' => 'info maturity'));
968 $boxclasses .= ' maturity'.$updateinfo->maturity;
971 if (isset($updateinfo->download)) {
972 $info[] = html_writer::link($updateinfo->download, get_string('download'),
973 array('class' => 'info download btn btn-secondary'));
976 if (isset($updateinfo->url)) {
977 $info[] = html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin'),
978 array('class' => 'info more'));
981 $box = $this->output->container_start($boxclasses);
982 $box .= $this->output->container(implode(html_writer::tag('span', ' | ', array('class' => 'separator')), $info), '');
983 $box .= $this->output->container_end();
985 return $box;
989 * Display a link to the release notes.
990 * @return string HTML to output.
992 protected function release_notes_link() {
993 $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/dev/Releases');
994 $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
995 return $this->box($releasenoteslink, 'generalbox alert alert-info');
999 * Display the reload link that appears on several upgrade/install pages.
1000 * @return string HTML to output.
1002 function upgrade_reload($url) {
1003 return html_writer::empty_tag('br') .
1004 html_writer::tag('div',
1005 html_writer::link($url, $this->pix_icon('i/reload', '', '', array('class' => 'icon icon-pre')) .
1006 get_string('reload'), array('title' => get_string('reload'))),
1007 array('class' => 'continuebutton')) . html_writer::empty_tag('br');
1011 * Displays all known plugins and information about their installation or upgrade
1013 * This default implementation renders all plugins into one big table. The rendering
1014 * options support:
1015 * (bool)full = false: whether to display up-to-date plugins, too
1016 * (bool)xdep = false: display the plugins with unsatisified dependecies only
1018 * @param core_plugin_manager $pluginman provides information about the plugins.
1019 * @param int $version the version of the Moodle code from version.php.
1020 * @param array $options rendering options
1021 * @return string HTML code
1023 public function plugins_check_table(core_plugin_manager $pluginman, $version, array $options = array()) {
1024 global $CFG;
1025 $plugininfo = $pluginman->get_plugins();
1027 if (empty($plugininfo)) {
1028 return '';
1031 $options['full'] = isset($options['full']) ? (bool)$options['full'] : false;
1032 $options['xdep'] = isset($options['xdep']) ? (bool)$options['xdep'] : false;
1034 $table = new html_table();
1035 $table->id = 'plugins-check';
1036 $table->head = array(
1037 get_string('displayname', 'core_plugin').' / '.get_string('rootdir', 'core_plugin'),
1038 get_string('versiondb', 'core_plugin'),
1039 get_string('versiondisk', 'core_plugin'),
1040 get_string('requires', 'core_plugin'),
1041 get_string('source', 'core_plugin').' / '.get_string('status', 'core_plugin'),
1043 $table->colclasses = array(
1044 'displayname', 'versiondb', 'versiondisk', 'requires', 'status',
1046 $table->data = array();
1048 // Number of displayed plugins per type.
1049 $numdisplayed = array();
1050 // Number of plugins known to the plugin manager.
1051 $sumtotal = 0;
1052 // Number of plugins requiring attention.
1053 $sumattention = 0;
1054 // List of all components we can cancel installation of.
1055 $installabortable = $pluginman->list_cancellable_installations();
1056 // List of all components we can cancel upgrade of.
1057 $upgradeabortable = $pluginman->list_restorable_archives();
1059 foreach ($plugininfo as $type => $plugins) {
1061 $header = new html_table_cell($pluginman->plugintype_name_plural($type));
1062 $header->header = true;
1063 $header->colspan = count($table->head);
1064 $header = new html_table_row(array($header));
1065 $header->attributes['class'] = 'plugintypeheader type-' . $type;
1067 $numdisplayed[$type] = 0;
1069 if (empty($plugins) and $options['full']) {
1070 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
1071 $msg->colspan = count($table->head);
1072 $row = new html_table_row(array($msg));
1073 $row->attributes['class'] .= 'msg msg-noneinstalled';
1074 $table->data[] = $header;
1075 $table->data[] = $row;
1076 continue;
1079 $plugintyperows = array();
1081 foreach ($plugins as $name => $plugin) {
1082 $component = "{$plugin->type}_{$plugin->name}";
1084 $sumtotal++;
1085 $row = new html_table_row();
1086 $row->attributes['class'] = "type-{$plugin->type} name-{$component}";
1088 $iconidentifier = 'icon';
1089 if ($plugin->type === 'mod') {
1090 $iconidentifier = 'monologo';
1093 if ($this->page->theme->resolve_image_location($iconidentifier, $component, null)) {
1094 $icon = $this->output->pix_icon($iconidentifier, '', $component, [
1095 'class' => 'smallicon pluginicon',
1097 } else {
1098 $icon = '';
1101 $displayname = new html_table_cell(
1102 $icon.
1103 html_writer::span($plugin->displayname, 'pluginname').
1104 html_writer::div($plugin->get_dir(), 'plugindir text-muted small')
1107 $versiondb = new html_table_cell($plugin->versiondb);
1108 $versiondisk = new html_table_cell($plugin->versiondisk);
1110 if ($isstandard = $plugin->is_standard()) {
1111 $row->attributes['class'] .= ' standard';
1112 $sourcelabel = html_writer::span(get_string('sourcestd', 'core_plugin'), 'sourcetext badge badge-secondary');
1113 } else {
1114 $row->attributes['class'] .= ' extension';
1115 $sourcelabel = html_writer::span(get_string('sourceext', 'core_plugin'), 'sourcetext badge badge-info');
1118 $coredependency = $plugin->is_core_dependency_satisfied($version);
1119 $incompatibledependency = $plugin->is_core_compatible_satisfied($CFG->branch);
1121 $otherpluginsdependencies = $pluginman->are_dependencies_satisfied($plugin->get_other_required_plugins());
1122 $dependenciesok = $coredependency && $otherpluginsdependencies && $incompatibledependency;
1124 $statuscode = $plugin->get_status();
1125 $row->attributes['class'] .= ' status-' . $statuscode;
1126 $statusclass = 'statustext badge ';
1127 switch ($statuscode) {
1128 case core_plugin_manager::PLUGIN_STATUS_NEW:
1129 $statusclass .= $dependenciesok ? 'badge-success' : 'badge-warning';
1130 break;
1131 case core_plugin_manager::PLUGIN_STATUS_UPGRADE:
1132 $statusclass .= $dependenciesok ? 'badge-info' : 'badge-warning';
1133 break;
1134 case core_plugin_manager::PLUGIN_STATUS_MISSING:
1135 case core_plugin_manager::PLUGIN_STATUS_DOWNGRADE:
1136 case core_plugin_manager::PLUGIN_STATUS_DELETE:
1137 $statusclass .= 'badge-danger';
1138 break;
1139 case core_plugin_manager::PLUGIN_STATUS_NODB:
1140 case core_plugin_manager::PLUGIN_STATUS_UPTODATE:
1141 $statusclass .= $dependenciesok ? 'badge-light' : 'badge-warning';
1142 break;
1144 $status = html_writer::span(get_string('status_' . $statuscode, 'core_plugin'), $statusclass);
1146 if (!empty($installabortable[$plugin->component])) {
1147 $status .= $this->output->single_button(
1148 new moodle_url($this->page->url, array('abortinstall' => $plugin->component, 'confirmplugincheck' => 0)),
1149 get_string('cancelinstallone', 'core_plugin'),
1150 'post',
1151 array('class' => 'actionbutton cancelinstallone d-block mt-1')
1155 if (!empty($upgradeabortable[$plugin->component])) {
1156 $status .= $this->output->single_button(
1157 new moodle_url($this->page->url, array('abortupgrade' => $plugin->component)),
1158 get_string('cancelupgradeone', 'core_plugin'),
1159 'post',
1160 array('class' => 'actionbutton cancelupgradeone d-block mt-1')
1164 $availableupdates = $plugin->available_updates();
1165 if (!empty($availableupdates)) {
1166 foreach ($availableupdates as $availableupdate) {
1167 $status .= $this->plugin_available_update_info($pluginman, $availableupdate);
1171 $status = new html_table_cell($sourcelabel.' '.$status);
1172 if ($plugin->pluginsupported != null) {
1173 $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version, $CFG->branch));
1174 } else {
1175 $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version));
1178 $statusisboring = in_array($statuscode, array(
1179 core_plugin_manager::PLUGIN_STATUS_NODB, core_plugin_manager::PLUGIN_STATUS_UPTODATE));
1181 if ($options['xdep']) {
1182 // we want to see only plugins with failed dependencies
1183 if ($dependenciesok) {
1184 continue;
1187 } else if ($statusisboring and $dependenciesok and empty($availableupdates)) {
1188 // no change is going to happen to the plugin - display it only
1189 // if the user wants to see the full list
1190 if (empty($options['full'])) {
1191 continue;
1194 } else {
1195 $sumattention++;
1198 // The plugin should be displayed.
1199 $numdisplayed[$type]++;
1200 $row->cells = array($displayname, $versiondb, $versiondisk, $requires, $status);
1201 $plugintyperows[] = $row;
1204 if (empty($numdisplayed[$type]) and empty($options['full'])) {
1205 continue;
1208 $table->data[] = $header;
1209 $table->data = array_merge($table->data, $plugintyperows);
1212 // Total number of displayed plugins.
1213 $sumdisplayed = array_sum($numdisplayed);
1215 if ($options['xdep']) {
1216 // At the plugins dependencies check page, display the table only.
1217 return html_writer::table($table);
1220 $out = $this->output->container_start('', 'plugins-check-info');
1222 if ($sumdisplayed == 0) {
1223 $out .= $this->output->heading(get_string('pluginchecknone', 'core_plugin'));
1225 } else {
1226 if (empty($options['full'])) {
1227 $out .= $this->output->heading(get_string('plugincheckattention', 'core_plugin'));
1228 } else {
1229 $out .= $this->output->heading(get_string('plugincheckall', 'core_plugin'));
1233 $out .= $this->output->container_start('actions mb-2');
1235 $installableupdates = $pluginman->filter_installable($pluginman->available_updates());
1236 if ($installableupdates) {
1237 $out .= $this->output->single_button(
1238 new moodle_url($this->page->url, array('installupdatex' => 1)),
1239 get_string('updateavailableinstallall', 'core_admin', count($installableupdates)),
1240 'post',
1241 array('class' => 'singlebutton updateavailableinstallall mr-1')
1245 if ($installabortable) {
1246 $out .= $this->output->single_button(
1247 new moodle_url($this->page->url, array('abortinstallx' => 1, 'confirmplugincheck' => 0)),
1248 get_string('cancelinstallall', 'core_plugin', count($installabortable)),
1249 'post',
1250 array('class' => 'singlebutton cancelinstallall mr-1')
1254 if ($upgradeabortable) {
1255 $out .= $this->output->single_button(
1256 new moodle_url($this->page->url, array('abortupgradex' => 1)),
1257 get_string('cancelupgradeall', 'core_plugin', count($upgradeabortable)),
1258 'post',
1259 array('class' => 'singlebutton cancelupgradeall mr-1')
1263 $out .= html_writer::div(html_writer::link(new moodle_url($this->page->url, array('showallplugins' => 0)),
1264 get_string('plugincheckattention', 'core_plugin')).' '.html_writer::span($sumattention, 'badge badge-light'),
1265 'btn btn-link mr-1');
1267 $out .= html_writer::div(html_writer::link(new moodle_url($this->page->url, array('showallplugins' => 1)),
1268 get_string('plugincheckall', 'core_plugin')).' '.html_writer::span($sumtotal, 'badge badge-light'),
1269 'btn btn-link mr-1');
1271 $out .= $this->output->container_end(); // End of .actions container.
1272 $out .= $this->output->container_end(); // End of #plugins-check-info container.
1274 if ($sumdisplayed > 0 or $options['full']) {
1275 $out .= html_writer::table($table);
1278 return $out;
1282 * Display the continue / cancel widgets for the plugins management pages.
1284 * @param null|moodle_url $continue URL for the continue button, should it be displayed
1285 * @param null|moodle_url $cancel URL for the cancel link, defaults to the current page
1286 * @return string HTML
1288 public function plugins_management_confirm_buttons(moodle_url $continue=null, moodle_url $cancel=null) {
1290 $out = html_writer::start_div('plugins-management-confirm-buttons');
1292 if (!empty($continue)) {
1293 $out .= $this->output->single_button($continue, get_string('continue'), 'post', array('class' => 'continue'));
1296 if (empty($cancel)) {
1297 $cancel = $this->page->url;
1299 $out .= html_writer::div(html_writer::link($cancel, get_string('cancel')), 'cancel');
1301 return $out;
1305 * Displays the information about missing dependencies
1307 * @param core_plugin_manager $pluginman
1308 * @return string
1310 protected function missing_dependencies(core_plugin_manager $pluginman) {
1312 $dependencies = $pluginman->missing_dependencies();
1314 if (empty($dependencies)) {
1315 return '';
1318 $available = array();
1319 $unavailable = array();
1320 $unknown = array();
1322 foreach ($dependencies as $component => $remoteinfo) {
1323 if ($remoteinfo === false) {
1324 // The required version is not available. Let us check if there
1325 // is at least some version in the plugins directory.
1326 $remoteinfoanyversion = $pluginman->get_remote_plugin_info($component, ANY_VERSION, false);
1327 if ($remoteinfoanyversion === false) {
1328 $unknown[$component] = $component;
1329 } else {
1330 $unavailable[$component] = $remoteinfoanyversion;
1332 } else {
1333 $available[$component] = $remoteinfo;
1337 $out = $this->output->container_start('plugins-check-dependencies mb-4');
1339 if ($unavailable or $unknown) {
1340 $out .= $this->output->heading(get_string('misdepsunavail', 'core_plugin'));
1341 if ($unknown) {
1342 $out .= $this->output->render((new \core\output\notification(get_string('misdepsunknownlist', 'core_plugin',
1343 implode(', ', $unknown))))->set_show_closebutton(false));
1345 if ($unavailable) {
1346 $unavailablelist = array();
1347 foreach ($unavailable as $component => $remoteinfoanyversion) {
1348 $unavailablelistitem = html_writer::link('https://moodle.org/plugins/view.php?plugin='.$component,
1349 '<strong>'.$remoteinfoanyversion->name.'</strong>');
1350 if ($remoteinfoanyversion->version) {
1351 $unavailablelistitem .= ' ('.$component.' &gt; '.$remoteinfoanyversion->version->version.')';
1352 } else {
1353 $unavailablelistitem .= ' ('.$component.')';
1355 $unavailablelist[] = $unavailablelistitem;
1357 $out .= $this->output->render((new \core\output\notification(get_string('misdepsunavaillist', 'core_plugin',
1358 implode(', ', $unavailablelist))))->set_show_closebutton(false));
1360 $out .= $this->output->container_start('plugins-check-dependencies-actions mb-4');
1361 $out .= ' '.html_writer::link(new moodle_url('/admin/tool/installaddon/'),
1362 get_string('dependencyuploadmissing', 'core_plugin'), array('class' => 'btn btn-secondary'));
1363 $out .= $this->output->container_end(); // End of .plugins-check-dependencies-actions container.
1366 if ($available) {
1367 $out .= $this->output->heading(get_string('misdepsavail', 'core_plugin'));
1368 $out .= $this->output->container_start('plugins-check-dependencies-actions mb-2');
1370 $installable = $pluginman->filter_installable($available);
1371 if ($installable) {
1372 $out .= $this->output->single_button(
1373 new moodle_url($this->page->url, array('installdepx' => 1)),
1374 get_string('dependencyinstallmissing', 'core_plugin', count($installable)),
1375 'post',
1376 array('class' => 'singlebutton dependencyinstallmissing d-inline-block mr-1')
1380 $out .= html_writer::div(html_writer::link(new moodle_url('/admin/tool/installaddon/'),
1381 get_string('dependencyuploadmissing', 'core_plugin'), array('class' => 'btn btn-link')),
1382 'dependencyuploadmissing d-inline-block mr-1');
1384 $out .= $this->output->container_end(); // End of .plugins-check-dependencies-actions container.
1386 $out .= $this->available_missing_dependencies_list($pluginman, $available);
1389 $out .= $this->output->container_end(); // End of .plugins-check-dependencies container.
1391 return $out;
1395 * Displays the list if available missing dependencies.
1397 * @param core_plugin_manager $pluginman
1398 * @param array $dependencies
1399 * @return string
1401 protected function available_missing_dependencies_list(core_plugin_manager $pluginman, array $dependencies) {
1402 global $CFG;
1404 $table = new html_table();
1405 $table->id = 'plugins-check-available-dependencies';
1406 $table->head = array(
1407 get_string('displayname', 'core_plugin'),
1408 get_string('release', 'core_plugin'),
1409 get_string('version', 'core_plugin'),
1410 get_string('supportedmoodleversions', 'core_plugin'),
1411 get_string('info', 'core'),
1413 $table->colclasses = array('displayname', 'release', 'version', 'supportedmoodleversions', 'info');
1414 $table->data = array();
1416 foreach ($dependencies as $plugin) {
1418 $supportedmoodles = array();
1419 foreach ($plugin->version->supportedmoodles as $moodle) {
1420 if ($CFG->branch == str_replace('.', '', $moodle->release)) {
1421 $supportedmoodles[] = html_writer::span($moodle->release, 'badge badge-success');
1422 } else {
1423 $supportedmoodles[] = html_writer::span($moodle->release, 'badge badge-light');
1427 $requriedby = $pluginman->other_plugins_that_require($plugin->component);
1428 if ($requriedby) {
1429 foreach ($requriedby as $ix => $val) {
1430 $inf = $pluginman->get_plugin_info($val);
1431 if ($inf) {
1432 $requriedby[$ix] = $inf->displayname.' ('.$inf->component.')';
1435 $info = html_writer::div(
1436 get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
1437 'requiredby mb-1'
1439 } else {
1440 $info = '';
1443 $info .= $this->output->container_start('actions');
1445 $info .= html_writer::div(
1446 html_writer::link('https://moodle.org/plugins/view.php?plugin='.$plugin->component,
1447 get_string('misdepinfoplugin', 'core_plugin')),
1448 'misdepinfoplugin d-inline-block mr-3 mb-1'
1451 $info .= html_writer::div(
1452 html_writer::link('https://moodle.org/plugins/pluginversion.php?id='.$plugin->version->id,
1453 get_string('misdepinfoversion', 'core_plugin')),
1454 'misdepinfoversion d-inline-block mr-3 mb-1'
1457 $info .= html_writer::div(html_writer::link($plugin->version->downloadurl, get_string('download')),
1458 'misdepdownload d-inline-block mr-3 mb-1');
1460 if ($pluginman->is_remote_plugin_installable($plugin->component, $plugin->version->version, $reason)) {
1461 $info .= $this->output->single_button(
1462 new moodle_url($this->page->url, array('installdep' => $plugin->component)),
1463 get_string('dependencyinstall', 'core_plugin'),
1464 'post',
1465 array('class' => 'singlebutton dependencyinstall mr-3 mb-1')
1467 } else {
1468 $reasonhelp = $this->info_remote_plugin_not_installable($reason);
1469 if ($reasonhelp) {
1470 $info .= html_writer::div($reasonhelp, 'reasonhelp dependencyinstall d-inline-block mr-3 mb-1');
1474 $info .= $this->output->container_end(); // End of .actions container.
1476 $table->data[] = array(
1477 html_writer::div($plugin->name, 'name').' '.html_writer::div($plugin->component, 'component text-muted small'),
1478 $plugin->version->release,
1479 $plugin->version->version,
1480 implode(' ', $supportedmoodles),
1481 $info
1485 return html_writer::table($table);
1489 * Explain why {@link core_plugin_manager::is_remote_plugin_installable()} returned false.
1491 * @param string $reason the reason code as returned by the plugin manager
1492 * @return string
1494 protected function info_remote_plugin_not_installable($reason) {
1496 if ($reason === 'notwritableplugintype' or $reason === 'notwritableplugin') {
1497 return $this->output->help_icon('notwritable', 'core_plugin', get_string('notwritable', 'core_plugin'));
1500 if ($reason === 'remoteunavailable') {
1501 return $this->output->help_icon('notdownloadable', 'core_plugin', get_string('notdownloadable', 'core_plugin'));
1504 return false;
1508 * Formats the information that needs to go in the 'Requires' column.
1509 * @param \core\plugininfo\base $plugin the plugin we are rendering the row for.
1510 * @param core_plugin_manager $pluginman provides data on all the plugins.
1511 * @param string $version
1512 * @param int $branch the current Moodle branch
1513 * @return string HTML code
1515 protected function required_column(\core\plugininfo\base $plugin, core_plugin_manager $pluginman, $version, $branch = null) {
1517 $requires = array();
1518 $displayuploadlink = false;
1519 $displayupdateslink = false;
1521 $requirements = $pluginman->resolve_requirements($plugin, $version, $branch);
1522 foreach ($requirements as $reqname => $reqinfo) {
1523 if ($reqname === 'core') {
1524 if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OK) {
1525 $class = 'requires-ok text-muted';
1526 $label = '';
1527 } else {
1528 $class = 'requires-failed';
1529 $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'badge badge-danger');
1532 if ($branch != null && !$plugin->is_core_compatible_satisfied($branch)) {
1533 $requires[] = html_writer::tag('li',
1534 html_writer::span(get_string('incompatibleversion', 'core_plugin', $branch), 'dep dep-core').
1535 ' '.$label, array('class' => $class));
1537 } else if ($branch != null && $plugin->pluginsupported != null) {
1538 $requires[] = html_writer::tag('li',
1539 html_writer::span(get_string('moodlebranch', 'core_plugin',
1540 array('min' => $plugin->pluginsupported[0], 'max' => $plugin->pluginsupported[1])), 'dep dep-core').
1541 ' '.$label, array('class' => $class));
1543 } else if ($reqinfo->reqver != ANY_VERSION) {
1544 $requires[] = html_writer::tag('li',
1545 html_writer::span(get_string('moodleversion', 'core_plugin', $plugin->versionrequires), 'dep dep-core').
1546 ' '.$label, array('class' => $class));
1549 } else {
1550 $actions = array();
1552 if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OK) {
1553 $label = '';
1554 $class = 'requires-ok text-muted';
1556 } else if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_MISSING) {
1557 if ($reqinfo->availability == $pluginman::REQUIREMENT_AVAILABLE) {
1558 $label = html_writer::span(get_string('dependencymissing', 'core_plugin'), 'badge badge-warning');
1559 $label .= ' '.html_writer::span(get_string('dependencyavailable', 'core_plugin'), 'badge badge-warning');
1560 $class = 'requires-failed requires-missing requires-available';
1561 $actions[] = html_writer::link(
1562 new moodle_url('https://moodle.org/plugins/view.php', array('plugin' => $reqname)),
1563 get_string('misdepinfoplugin', 'core_plugin')
1566 } else {
1567 $label = html_writer::span(get_string('dependencymissing', 'core_plugin'), 'badge badge-danger');
1568 $label .= ' '.html_writer::span(get_string('dependencyunavailable', 'core_plugin'),
1569 'badge badge-danger');
1570 $class = 'requires-failed requires-missing requires-unavailable';
1572 $displayuploadlink = true;
1574 } else if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OUTDATED) {
1575 if ($reqinfo->availability == $pluginman::REQUIREMENT_AVAILABLE) {
1576 $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'badge badge-warning');
1577 $label .= ' '.html_writer::span(get_string('dependencyavailable', 'core_plugin'), 'badge badge-warning');
1578 $class = 'requires-failed requires-outdated requires-available';
1579 $displayupdateslink = true;
1581 } else {
1582 $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'badge badge-danger');
1583 $label .= ' '.html_writer::span(get_string('dependencyunavailable', 'core_plugin'),
1584 'badge badge-danger');
1585 $class = 'requires-failed requires-outdated requires-unavailable';
1587 $displayuploadlink = true;
1590 if ($reqinfo->reqver != ANY_VERSION) {
1591 $str = 'otherpluginversion';
1592 } else {
1593 $str = 'otherplugin';
1596 $requires[] = html_writer::tag('li', html_writer::span(
1597 get_string($str, 'core_plugin', array('component' => $reqname, 'version' => $reqinfo->reqver)),
1598 'dep dep-plugin').' '.$label.' '.html_writer::span(implode(' | ', $actions), 'actions'),
1599 array('class' => $class)
1604 if (!$requires) {
1605 return '';
1608 $out = html_writer::tag('ul', implode("\n", $requires), array('class' => 'm-0'));
1610 if ($displayuploadlink) {
1611 $out .= html_writer::div(
1612 html_writer::link(
1613 new moodle_url('/admin/tool/installaddon/'),
1614 get_string('dependencyuploadmissing', 'core_plugin'),
1615 array('class' => 'btn btn-secondary btn-sm m-1')
1617 'dependencyuploadmissing'
1621 if ($displayupdateslink) {
1622 $out .= html_writer::div(
1623 html_writer::link(
1624 new moodle_url($this->page->url, array('sesskey' => sesskey(), 'fetchupdates' => 1)),
1625 get_string('checkforupdates', 'core_plugin'),
1626 array('class' => 'btn btn-secondary btn-sm m-1')
1628 'checkforupdates'
1632 // Check if supports is present, and $branch is not in, only if $incompatible check was ok.
1633 if ($plugin->pluginsupported != null && $class == 'requires-ok' && $branch != null) {
1634 if ($pluginman->check_explicitly_supported($plugin, $branch) == $pluginman::VERSION_NOT_SUPPORTED) {
1635 $out .= html_writer::div(get_string('notsupported', 'core_plugin', $branch));
1639 return $out;
1644 * Prints an overview about the plugins - number of installed, number of extensions etc.
1646 * @param core_plugin_manager $pluginman provides information about the plugins
1647 * @param array $options filtering options
1648 * @return string as usually
1650 public function plugins_overview_panel(core_plugin_manager $pluginman, array $options = array()) {
1652 $plugininfo = $pluginman->get_plugins();
1654 $numtotal = $numextension = $numupdatable = $numinstallable = 0;
1656 foreach ($plugininfo as $type => $plugins) {
1657 foreach ($plugins as $name => $plugin) {
1658 if ($res = $plugin->available_updates()) {
1659 $numupdatable++;
1660 foreach ($res as $updateinfo) {
1661 if ($pluginman->is_remote_plugin_installable($updateinfo->component, $updateinfo->version, $reason, false)) {
1662 $numinstallable++;
1663 break;
1667 if ($plugin->get_status() === core_plugin_manager::PLUGIN_STATUS_MISSING) {
1668 continue;
1670 $numtotal++;
1671 if (!$plugin->is_standard()) {
1672 $numextension++;
1677 $infoall = html_writer::link(
1678 new moodle_url($this->page->url, array('contribonly' => 0, 'updatesonly' => 0)),
1679 get_string('overviewall', 'core_plugin'),
1680 array('title' => get_string('filterall', 'core_plugin'))
1681 ).' '.html_writer::span($numtotal, 'badge number number-all');
1683 $infoext = html_writer::link(
1684 new moodle_url($this->page->url, array('contribonly' => 1, 'updatesonly' => 0)),
1685 get_string('overviewext', 'core_plugin'),
1686 array('title' => get_string('filtercontribonly', 'core_plugin'))
1687 ).' '.html_writer::span($numextension, 'badge number number-additional');
1689 if ($numupdatable) {
1690 $infoupdatable = html_writer::link(
1691 new moodle_url($this->page->url, array('contribonly' => 0, 'updatesonly' => 1)),
1692 get_string('overviewupdatable', 'core_plugin'),
1693 array('title' => get_string('filterupdatesonly', 'core_plugin'))
1694 ).' '.html_writer::span($numupdatable, 'badge badge-info number number-updatable');
1695 } else {
1696 // No updates, or the notifications disabled.
1697 $infoupdatable = '';
1700 $out = html_writer::start_div('', array('id' => 'plugins-overview-panel'));
1702 if (!empty($options['updatesonly'])) {
1703 $out .= $this->output->heading(get_string('overviewupdatable', 'core_plugin'), 3);
1704 } else if (!empty($options['contribonly'])) {
1705 $out .= $this->output->heading(get_string('overviewext', 'core_plugin'), 3);
1708 if ($numinstallable) {
1709 $out .= $this->output->single_button(
1710 new moodle_url($this->page->url, array('installupdatex' => 1)),
1711 get_string('updateavailableinstallall', 'core_admin', $numinstallable),
1712 'post',
1713 array('class' => 'singlebutton updateavailableinstallall')
1717 $out .= html_writer::div($infoall, 'info info-all').
1718 html_writer::div($infoext, 'info info-ext').
1719 html_writer::div($infoupdatable, 'info info-updatable');
1721 $out .= html_writer::end_div(); // End of #plugins-overview-panel block.
1723 return $out;
1727 * Displays all known plugins and links to manage them
1729 * This default implementation renders all plugins into one big table.
1731 * @param core_plugin_manager $pluginman provides information about the plugins.
1732 * @param array $options filtering options
1733 * @return string HTML code
1735 public function plugins_control_panel(core_plugin_manager $pluginman, array $options = array()) {
1737 $plugininfo = $pluginman->get_plugins();
1739 // Filter the list of plugins according the options.
1740 if (!empty($options['updatesonly'])) {
1741 $updateable = array();
1742 foreach ($plugininfo as $plugintype => $pluginnames) {
1743 foreach ($pluginnames as $pluginname => $pluginfo) {
1744 $pluginavailableupdates = $pluginfo->available_updates();
1745 if (!empty($pluginavailableupdates)) {
1746 foreach ($pluginavailableupdates as $pluginavailableupdate) {
1747 $updateable[$plugintype][$pluginname] = $pluginfo;
1752 $plugininfo = $updateable;
1755 if (!empty($options['contribonly'])) {
1756 $contribs = array();
1757 foreach ($plugininfo as $plugintype => $pluginnames) {
1758 foreach ($pluginnames as $pluginname => $pluginfo) {
1759 if (!$pluginfo->is_standard()) {
1760 $contribs[$plugintype][$pluginname] = $pluginfo;
1764 $plugininfo = $contribs;
1767 if (empty($plugininfo)) {
1768 return '';
1771 $table = new html_table();
1772 $table->id = 'plugins-control-panel';
1773 $table->head = array(
1774 get_string('displayname', 'core_plugin'),
1775 get_string('version', 'core_plugin'),
1776 get_string('availability', 'core_plugin'),
1777 get_string('actions', 'core_plugin'),
1778 get_string('notes','core_plugin'),
1780 $table->headspan = array(1, 1, 1, 2, 1);
1781 $table->colclasses = array(
1782 'pluginname', 'version', 'availability', 'settings', 'uninstall', 'notes'
1785 foreach ($plugininfo as $type => $plugins) {
1786 $heading = $pluginman->plugintype_name_plural($type);
1787 $pluginclass = core_plugin_manager::resolve_plugininfo_class($type);
1788 if ($manageurl = $pluginclass::get_manage_url()) {
1789 $heading .= $this->output->action_icon($manageurl, new pix_icon('i/settings',
1790 get_string('settings', 'core_plugin')));
1792 $header = new html_table_cell(html_writer::tag('span', $heading, array('id'=>'plugin_type_cell_'.$type)));
1793 $header->header = true;
1794 $header->colspan = array_sum($table->headspan);
1795 $header = new html_table_row(array($header));
1796 $header->attributes['class'] = 'plugintypeheader type-' . $type;
1797 $table->data[] = $header;
1799 if (empty($plugins)) {
1800 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
1801 $msg->colspan = array_sum($table->headspan);
1802 $row = new html_table_row(array($msg));
1803 $row->attributes['class'] .= 'msg msg-noneinstalled';
1804 $table->data[] = $row;
1805 continue;
1808 foreach ($plugins as $name => $plugin) {
1809 $component = "{$plugin->type}_{$plugin->name}";
1811 $row = new html_table_row();
1812 $row->attributes['class'] = "type-{$plugin->type} name-{$component}";
1814 $iconidentifier = 'icon';
1815 if ($plugin->type === 'mod') {
1816 $iconidentifier = 'monologo';
1819 if ($this->page->theme->resolve_image_location($iconidentifier, $component, null)) {
1820 $icon = $this->output->pix_icon($iconidentifier, '', $component, [
1821 'class' => 'icon pluginicon',
1823 } else {
1824 $icon = $this->output->spacer();
1826 $status = $plugin->get_status();
1827 $row->attributes['class'] .= ' status-'.$status;
1828 $pluginname = html_writer::tag('div', $icon.$plugin->displayname, array('class' => 'displayname')).
1829 html_writer::tag('div', $plugin->component, array('class' => 'componentname'));
1830 $pluginname = new html_table_cell($pluginname);
1832 $version = html_writer::div($plugin->versiondb, 'versionnumber');
1833 if ((string)$plugin->release !== '') {
1834 $version = html_writer::div($plugin->release, 'release').$version;
1836 $version = new html_table_cell($version);
1838 $isenabled = $plugin->is_enabled();
1839 if (is_null($isenabled)) {
1840 $availability = new html_table_cell('');
1841 } else if ($isenabled) {
1842 $row->attributes['class'] .= ' enabled';
1843 $availability = new html_table_cell(get_string('pluginenabled', 'core_plugin'));
1844 } else {
1845 $row->attributes['class'] .= ' disabled';
1846 $availability = new html_table_cell(get_string('plugindisabled', 'core_plugin'));
1849 $settingsurl = $plugin->get_settings_url();
1850 if (!is_null($settingsurl)) {
1851 $settings = html_writer::link($settingsurl, get_string('settings', 'core_plugin'), array('class' => 'settings'));
1852 } else {
1853 $settings = '';
1855 $settings = new html_table_cell($settings);
1857 if ($uninstallurl = $pluginman->get_uninstall_url($plugin->component, 'overview')) {
1858 $uninstall = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin'));
1859 } else {
1860 $uninstall = '';
1862 $uninstall = new html_table_cell($uninstall);
1864 if ($plugin->is_standard()) {
1865 $row->attributes['class'] .= ' standard';
1866 $source = '';
1867 } else {
1868 $row->attributes['class'] .= ' extension';
1869 $source = html_writer::div(get_string('sourceext', 'core_plugin'), 'source badge badge-info');
1872 if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) {
1873 $msg = html_writer::div(get_string('status_missing', 'core_plugin'), 'statusmsg badge badge-danger');
1874 } else if ($status === core_plugin_manager::PLUGIN_STATUS_NEW) {
1875 $msg = html_writer::div(get_string('status_new', 'core_plugin'), 'statusmsg badge badge-success');
1876 } else {
1877 $msg = '';
1880 $requriedby = $pluginman->other_plugins_that_require($plugin->component);
1881 if ($requriedby) {
1882 $requiredby = html_writer::tag('div', get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
1883 array('class' => 'requiredby'));
1884 } else {
1885 $requiredby = '';
1888 $updateinfo = '';
1889 if (is_array($plugin->available_updates())) {
1890 foreach ($plugin->available_updates() as $availableupdate) {
1891 $updateinfo .= $this->plugin_available_update_info($pluginman, $availableupdate);
1895 $notes = new html_table_cell($source.$msg.$requiredby.$updateinfo);
1897 $row->cells = array(
1898 $pluginname, $version, $availability, $settings, $uninstall, $notes
1900 $table->data[] = $row;
1904 return html_writer::table($table);
1908 * Helper method to render the information about the available plugin update
1910 * @param core_plugin_manager $pluginman plugin manager instance
1911 * @param \core\update\info $updateinfo information about the available update for the plugin
1913 protected function plugin_available_update_info(core_plugin_manager $pluginman, \core\update\info $updateinfo) {
1915 $boxclasses = 'pluginupdateinfo';
1916 $info = array();
1918 if (isset($updateinfo->release)) {
1919 $info[] = html_writer::div(
1920 get_string('updateavailable_release', 'core_plugin', $updateinfo->release),
1921 'info release'
1925 if (isset($updateinfo->maturity)) {
1926 $info[] = html_writer::div(
1927 get_string('maturity'.$updateinfo->maturity, 'core_admin'),
1928 'info maturity'
1930 $boxclasses .= ' maturity'.$updateinfo->maturity;
1933 if (isset($updateinfo->download)) {
1934 $info[] = html_writer::div(
1935 html_writer::link($updateinfo->download, get_string('download')),
1936 'info download'
1940 if (isset($updateinfo->url)) {
1941 $info[] = html_writer::div(
1942 html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin')),
1943 'info more'
1947 $box = html_writer::start_div($boxclasses);
1948 $box .= html_writer::div(
1949 get_string('updateavailable', 'core_plugin', $updateinfo->version),
1950 'version'
1952 $box .= html_writer::div(
1953 implode(html_writer::span(' ', 'separator'), $info),
1954 'infos'
1957 if ($pluginman->is_remote_plugin_installable($updateinfo->component, $updateinfo->version, $reason, false)) {
1958 $box .= $this->output->single_button(
1959 new moodle_url($this->page->url, array('installupdate' => $updateinfo->component,
1960 'installupdateversion' => $updateinfo->version)),
1961 get_string('updateavailableinstall', 'core_admin'),
1962 'post',
1963 array('class' => 'singlebutton updateavailableinstall')
1965 } else {
1966 $reasonhelp = $this->info_remote_plugin_not_installable($reason);
1967 if ($reasonhelp) {
1968 $box .= html_writer::div($reasonhelp, 'reasonhelp updateavailableinstall');
1971 $box .= html_writer::end_div();
1973 return $box;
1977 * This function will render one beautiful table with all the environmental
1978 * configuration and how it suits Moodle needs.
1980 * @param boolean $result final result of the check (true/false)
1981 * @param environment_results[] $environment_results array of results gathered
1982 * @return string HTML to output.
1984 public function environment_check_table($result, $environment_results) {
1985 global $CFG;
1987 // Table headers
1988 $servertable = new html_table();//table for server checks
1989 $servertable->head = array(
1990 get_string('name'),
1991 get_string('info'),
1992 get_string('report'),
1993 get_string('plugin'),
1994 get_string('status'),
1996 $servertable->colclasses = array('centeralign name', 'centeralign info', 'leftalign report', 'leftalign plugin', 'centeralign status');
1997 $servertable->attributes['class'] = 'admintable environmenttable generaltable table-sm';
1998 $servertable->id = 'serverstatus';
2000 $serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
2002 $othertable = new html_table();//table for custom checks
2003 $othertable->head = array(
2004 get_string('info'),
2005 get_string('report'),
2006 get_string('plugin'),
2007 get_string('status'),
2009 $othertable->colclasses = array('aligncenter info', 'alignleft report', 'alignleft plugin', 'aligncenter status');
2010 $othertable->attributes['class'] = 'admintable environmenttable generaltable table-sm';
2011 $othertable->id = 'otherserverstatus';
2013 $otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
2015 // Iterate over each environment_result
2016 $continue = true;
2017 foreach ($environment_results as $environment_result) {
2018 $errorline = false;
2019 $warningline = false;
2020 $stringtouse = '';
2021 if ($continue) {
2022 $type = $environment_result->getPart();
2023 $info = $environment_result->getInfo();
2024 $status = $environment_result->getStatus();
2025 $plugin = $environment_result->getPluginName();
2026 $error_code = $environment_result->getErrorCode();
2027 // Process Report field
2028 $rec = new stdClass();
2029 // Something has gone wrong at parsing time
2030 if ($error_code) {
2031 $stringtouse = 'environmentxmlerror';
2032 $rec->error_code = $error_code;
2033 $status = get_string('error');
2034 $errorline = true;
2035 $continue = false;
2038 if ($continue) {
2039 if ($rec->needed = $environment_result->getNeededVersion()) {
2040 // We are comparing versions
2041 $rec->current = $environment_result->getCurrentVersion();
2042 if ($environment_result->getLevel() == 'required') {
2043 $stringtouse = 'environmentrequireversion';
2044 } else {
2045 $stringtouse = 'environmentrecommendversion';
2048 } else if ($environment_result->getPart() == 'custom_check') {
2049 // We are checking installed & enabled things
2050 if ($environment_result->getLevel() == 'required') {
2051 $stringtouse = 'environmentrequirecustomcheck';
2052 } else {
2053 $stringtouse = 'environmentrecommendcustomcheck';
2056 } else if ($environment_result->getPart() == 'php_setting') {
2057 if ($status) {
2058 $stringtouse = 'environmentsettingok';
2059 } else if ($environment_result->getLevel() == 'required') {
2060 $stringtouse = 'environmentmustfixsetting';
2061 } else {
2062 $stringtouse = 'environmentshouldfixsetting';
2065 } else {
2066 if ($environment_result->getLevel() == 'required') {
2067 $stringtouse = 'environmentrequireinstall';
2068 } else {
2069 $stringtouse = 'environmentrecommendinstall';
2073 // Calculate the status value
2074 if ($environment_result->getBypassStr() != '') { //Handle bypassed result (warning)
2075 $status = get_string('bypassed');
2076 $warningline = true;
2077 } else if ($environment_result->getRestrictStr() != '') { //Handle restricted result (error)
2078 $status = get_string('restricted');
2079 $errorline = true;
2080 } else {
2081 if ($status) { //Handle ok result (ok)
2082 $status = get_string('statusok');
2083 } else {
2084 if ($environment_result->getLevel() == 'optional') {//Handle check result (warning)
2085 $status = get_string('check');
2086 $warningline = true;
2087 } else { //Handle error result (error)
2088 $status = get_string('check');
2089 $errorline = true;
2095 // Build the text
2096 $linkparts = array();
2097 $linkparts[] = 'admin/environment';
2098 $linkparts[] = $type;
2099 if (!empty($info)){
2100 $linkparts[] = $info;
2102 // Plugin environments do not have docs pages yet.
2103 if (empty($CFG->docroot) or $environment_result->plugin) {
2104 $report = get_string($stringtouse, 'admin', $rec);
2105 } else {
2106 $report = $this->doc_link(join('/', $linkparts), get_string($stringtouse, 'admin', $rec), true);
2108 // Enclose report text in div so feedback text will be displayed underneath it.
2109 $report = html_writer::div($report);
2111 // Format error or warning line
2112 if ($errorline) {
2113 $messagetype = 'error';
2114 $statusclass = 'badge-danger';
2115 } else if ($warningline) {
2116 $messagetype = 'warn';
2117 $statusclass = 'badge-warning';
2118 } else {
2119 $messagetype = 'ok';
2120 $statusclass = 'badge-success';
2122 $status = html_writer::span($status, 'badge ' . $statusclass);
2123 // Here we'll store all the feedback found
2124 $feedbacktext = '';
2125 // Append the feedback if there is some
2126 $feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), $messagetype);
2127 //Append the bypass if there is some
2128 $feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'warn');
2129 //Append the restrict if there is some
2130 $feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'error');
2132 $report .= $feedbacktext;
2134 // Add the row to the table
2135 if ($environment_result->getPart() == 'custom_check'){
2136 $otherdata[$messagetype][] = array ($info, $report, $plugin, $status);
2137 } else {
2138 $serverdata[$messagetype][] = array ($type, $info, $report, $plugin, $status);
2143 //put errors first in
2144 $servertable->data = array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']);
2145 $othertable->data = array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']);
2147 // Print table
2148 $output = '';
2149 $output .= $this->heading(get_string('serverchecks', 'admin'));
2150 $output .= html_writer::table($servertable);
2151 if (count($othertable->data)){
2152 $output .= $this->heading(get_string('customcheck', 'admin'));
2153 $output .= html_writer::table($othertable);
2156 // Finally, if any error has happened, print the summary box
2157 if (!$result) {
2158 $output .= $this->box(get_string('environmenterrortodo', 'admin'), 'environmentbox errorbox');
2161 return $output;
2165 * Render a simple page for providing the upgrade key.
2167 * @param moodle_url|string $url
2168 * @return string
2170 public function upgradekey_form_page($url) {
2172 $output = '';
2173 $output .= $this->header();
2174 $output .= $this->container_start('upgradekeyreq');
2175 $output .= $this->heading(get_string('upgradekeyreq', 'core_admin'));
2176 $output .= html_writer::start_tag('form', array('method' => 'POST', 'action' => $url));
2177 $output .= html_writer::empty_tag('input', [
2178 'name' => 'upgradekey',
2179 'type' => 'password',
2180 'class' => 'form-control w-auto',
2182 $output .= html_writer::empty_tag('input', [
2183 'type' => 'submit',
2184 'value' => get_string('submit'),
2185 'class' => 'btn btn-primary mt-3',
2187 $output .= html_writer::end_tag('form');
2188 $output .= $this->container_end();
2189 $output .= $this->footer();
2191 return $output;
2195 * Display message about the benefits of registering on Moodle.org
2197 * @return string
2199 public function moodleorg_registration_message() {
2201 $out = format_text(get_string('registerwithmoodleorginfo', 'core_hub'), FORMAT_MARKDOWN);
2203 $out .= html_writer::link(
2204 new moodle_url('/admin/settings.php', ['section' => 'moodleservices']),
2205 $this->output->pix_icon('i/info', '').' '.get_string('registerwithmoodleorginfoapp', 'core_hub'),
2206 ['class' => 'btn btn-link', 'role' => 'opener', 'target' => '_href']
2209 $out .= html_writer::link(
2210 HUB_MOODLEORGHUBURL,
2211 $this->output->pix_icon('i/stats', '').' '.get_string('registerwithmoodleorginfostats', 'core_hub'),
2212 ['class' => 'btn btn-link', 'role' => 'opener', 'target' => '_href']
2215 $out .= html_writer::link(
2216 HUB_MOODLEORGHUBURL.'/sites',
2217 $this->output->pix_icon('i/location', '').' '.get_string('registerwithmoodleorginfosites', 'core_hub'),
2218 ['class' => 'btn btn-link', 'role' => 'opener', 'target' => '_href']
2221 return $this->output->box($out);
2225 * Display message about benefits of enabling the user feedback feature.
2227 * @param bool $showfeedbackencouragement Whether the encouragement content should be displayed or not
2228 * @return string
2230 protected function userfeedback_encouragement(bool $showfeedbackencouragement): string {
2231 $output = '';
2233 if ($showfeedbackencouragement) {
2234 $settingslink = new moodle_url('/admin/settings.php', ['section' => 'userfeedback']);
2235 $output .= $this->warning(get_string('userfeedbackencouragement', 'admin', $settingslink->out()), 'info');
2238 return $output;
2242 * Display a warning about the deprecation of Mnet.
2244 * @param string $xmlrpcwarning The warning message
2245 * @return string HTML to output.
2247 protected function mnet_deprecation_warning($xmlrpcwarning) {
2248 if (empty($xmlrpcwarning)) {
2249 return '';
2252 return $this->warning($xmlrpcwarning);