MDL-77046 availability: validate profile field in condition.
[moodle.git] / admin / renderer.php
blob0c66010ed7305597b0701e5276c8383ce0014deb
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', true);
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 .= $this->legacy_log_store_writing_error();
300 $output .= empty($CFG->disableupdatenotifications) ? $this->available_updates($availableupdates, $availableupdatesfetch) : '';
301 $output .= $this->insecure_dataroot_warning($insecuredataroot);
302 $output .= $this->development_libs_directories_warning($devlibdir);
303 $output .= $this->themedesignermode_warning($themedesignermode);
304 $output .= $this->display_errors_warning($errorsdisplayed);
305 $output .= $this->buggy_iconv_warning($buggyiconvnomb);
306 $output .= $this->cron_overdue_warning($cronoverdue);
307 $output .= $this->cron_infrequent_warning($croninfrequent);
308 $output .= $this->db_problems($dbproblems);
309 $output .= $this->maintenance_mode_warning($maintenancemode);
310 $output .= $this->overridetossl_warning($overridetossl);
311 $output .= $this->cache_warnings($cachewarnings);
312 $output .= $this->events_handlers($eventshandlers);
313 $output .= $this->registration_warning($registered);
314 $output .= $this->mobile_configuration_warning($mobileconfigured);
315 $output .= $this->forgotten_password_url_warning($invalidforgottenpasswordurl);
316 $output .= $this->mnet_deprecation_warning($xmlrpcwarning);
317 $output .= $this->userfeedback_encouragement($showfeedbackencouragement);
318 $output .= $this->services_and_support_content($showservicesandsupport);
319 $output .= $this->campaign_content($showcampaigncontent);
321 //////////////////////////////////////////////////////////////////////////////////////////////////
322 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
323 $output .= $this->moodle_copyright();
324 //////////////////////////////////////////////////////////////////////////////////////////////////
326 $output .= $this->footer();
328 return $output;
332 * Display the plugin management page (admin/plugins.php).
334 * The filtering options array may contain following items:
335 * bool contribonly - show only contributed extensions
336 * bool updatesonly - show only plugins with an available update
338 * @param core_plugin_manager $pluginman
339 * @param \core\update\checker $checker
340 * @param array $options filtering options
341 * @return string HTML to output.
343 public function plugin_management_page(core_plugin_manager $pluginman, \core\update\checker $checker, array $options = array()) {
345 $output = '';
347 $output .= $this->header();
348 $output .= $this->heading(get_string('pluginsoverview', 'core_admin'));
349 $output .= $this->check_for_updates_button($checker, $this->page->url);
350 $output .= $this->plugins_overview_panel($pluginman, $options);
351 $output .= $this->plugins_control_panel($pluginman, $options);
352 $output .= $this->footer();
354 return $output;
358 * Renders a button to fetch for available updates.
360 * @param \core\update\checker $checker
361 * @param moodle_url $reloadurl
362 * @return string HTML
364 public function check_for_updates_button(\core\update\checker $checker, $reloadurl) {
366 $output = '';
368 if ($checker->enabled()) {
369 $output .= $this->container_start('checkforupdates mb-4');
370 $output .= $this->single_button(
371 new moodle_url($reloadurl, array('fetchupdates' => 1)),
372 get_string('checkforupdates', 'core_plugin')
374 if ($timefetched = $checker->get_last_timefetched()) {
375 $timefetched = userdate($timefetched, get_string('strftimedatetime', 'core_langconfig'));
376 $output .= $this->container(get_string('checkforupdateslast', 'core_plugin', $timefetched),
377 'lasttimefetched small text-muted mt-1');
379 $output .= $this->container_end();
382 return $output;
386 * Display a page to confirm the plugin uninstallation.
388 * @param core_plugin_manager $pluginman
389 * @param \core\plugininfo\base $pluginfo
390 * @param moodle_url $continueurl URL to continue after confirmation
391 * @param moodle_url $cancelurl URL to to go if cancelled
392 * @return string
394 public function plugin_uninstall_confirm_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, moodle_url $continueurl, moodle_url $cancelurl) {
395 $output = '';
397 $pluginname = $pluginman->plugin_name($pluginfo->component);
399 $confirm = '<p>' . get_string('uninstallconfirm', 'core_plugin', array('name' => $pluginname)) . '</p>';
400 if ($extraconfirm = $pluginfo->get_uninstall_extra_warning()) {
401 $confirm .= $extraconfirm;
404 $output .= $this->output->header();
405 $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
406 $output .= $this->output->confirm($confirm, $continueurl, $cancelurl);
407 $output .= $this->output->footer();
409 return $output;
413 * Display a page with results of plugin uninstallation and offer removal of plugin files.
415 * @param core_plugin_manager $pluginman
416 * @param \core\plugininfo\base $pluginfo
417 * @param progress_trace_buffer $progress
418 * @param moodle_url $continueurl URL to continue to remove the plugin folder
419 * @return string
421 public function plugin_uninstall_results_removable_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo,
422 progress_trace_buffer $progress, moodle_url $continueurl) {
423 $output = '';
425 $pluginname = $pluginman->plugin_name($pluginfo->component);
427 // Do not show navigation here, they must click one of the buttons.
428 $this->page->set_pagelayout('maintenance');
429 $this->page->set_cacheable(false);
431 $output .= $this->output->header();
432 $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
434 $output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
436 $confirm = $this->output->container(get_string('uninstalldeleteconfirm', 'core_plugin',
437 array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'uninstalldeleteconfirm');
439 if ($repotype = $pluginman->plugin_external_source($pluginfo->component)) {
440 $confirm .= $this->output->container(get_string('uninstalldeleteconfirmexternal', 'core_plugin', $repotype),
441 'alert alert-warning mt-2');
444 // After any uninstall we must execute full upgrade to finish the cleanup!
445 $output .= $this->output->confirm($confirm, $continueurl, new moodle_url('/admin/index.php'));
446 $output .= $this->output->footer();
448 return $output;
452 * Display a page with results of plugin uninstallation and inform about the need to remove plugin files manually.
454 * @param core_plugin_manager $pluginman
455 * @param \core\plugininfo\base $pluginfo
456 * @param progress_trace_buffer $progress
457 * @return string
459 public function plugin_uninstall_results_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, progress_trace_buffer $progress) {
460 $output = '';
462 $pluginname = $pluginfo->component;
464 $output .= $this->output->header();
465 $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
467 $output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
469 $output .= $this->output->box(get_string('uninstalldelete', 'core_plugin',
470 array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'generalbox uninstalldelete');
471 $output .= $this->output->continue_button(new moodle_url('/admin/index.php'));
472 $output .= $this->output->footer();
474 return $output;
478 * Display the plugin management page (admin/environment.php).
479 * @param array $versions
480 * @param string $version
481 * @param boolean $envstatus final result of env check (true/false)
482 * @param array $environment_results array of results gathered
483 * @return string HTML to output.
485 public function environment_check_page($versions, $version, $envstatus, $environment_results) {
486 $output = '';
487 $output .= $this->header();
489 // Print the component download link
490 $output .= html_writer::tag('div', html_writer::link(
491 new moodle_url('/admin/environment.php', array('action' => 'updatecomponent', 'sesskey' => sesskey())),
492 get_string('updatecomponent', 'admin')),
493 array('class' => 'reportlink'));
495 // Heading.
496 $output .= $this->heading(get_string('environment', 'admin'));
498 // Box with info and a menu to choose the version.
499 $output .= $this->box_start();
500 $output .= html_writer::tag('div', get_string('adminhelpenvironment'));
501 $select = new single_select(new moodle_url('/admin/environment.php'), 'version', $versions, $version, null);
502 $select->label = get_string('moodleversion');
503 $output .= $this->render($select);
504 $output .= $this->box_end();
506 // The results
507 $output .= $this->environment_check_table($envstatus, $environment_results);
509 $output .= $this->footer();
510 return $output;
514 * Output a warning message, of the type that appears on the admin notifications page.
515 * @param string $message the message to display.
516 * @param string $type type class
517 * @return string HTML to output.
519 protected function warning($message, $type = 'warning') {
520 return $this->box($message, 'generalbox alert alert-' . $type);
524 * Render an appropriate message if dataroot is insecure.
525 * @param bool $insecuredataroot
526 * @return string HTML to output.
528 protected function insecure_dataroot_warning($insecuredataroot) {
529 global $CFG;
531 if ($insecuredataroot == INSECURE_DATAROOT_WARNING) {
532 return $this->warning(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot));
534 } else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) {
535 return $this->warning(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'danger');
537 } else {
538 return '';
543 * Render a warning that a directory with development libs is present.
545 * @param bool $devlibdir True if the warning should be displayed.
546 * @return string
548 protected function development_libs_directories_warning($devlibdir) {
550 if ($devlibdir) {
551 $moreinfo = new moodle_url('/report/security/index.php');
552 $warning = get_string('devlibdirpresent', 'core_admin', ['moreinfourl' => $moreinfo->out()]);
553 return $this->warning($warning, 'danger');
555 } else {
556 return '';
561 * Render an appropriate message if dataroot is insecure.
562 * @param bool $errorsdisplayed
563 * @return string HTML to output.
565 protected function display_errors_warning($errorsdisplayed) {
566 if (!$errorsdisplayed) {
567 return '';
570 return $this->warning(get_string('displayerrorswarning', 'admin'));
574 * Render an appropriate message if themdesignermode is enabled.
575 * @param bool $themedesignermode true if enabled
576 * @return string HTML to output.
578 protected function themedesignermode_warning($themedesignermode) {
579 if (!$themedesignermode) {
580 return '';
583 return $this->warning(get_string('themedesignermodewarning', 'admin'));
587 * Render an appropriate message if iconv is buggy and mbstring missing.
588 * @param bool $buggyiconvnomb
589 * @return string HTML to output.
591 protected function buggy_iconv_warning($buggyiconvnomb) {
592 if (!$buggyiconvnomb) {
593 return '';
596 return $this->warning(get_string('warningiconvbuggy', 'admin'));
600 * Render an appropriate message if cron has not been run recently.
601 * @param bool $cronoverdue
602 * @return string HTML to output.
604 public function cron_overdue_warning($cronoverdue) {
605 global $CFG;
606 if (!$cronoverdue) {
607 return '';
610 $check = new \tool_task\check\cronrunning();
611 $result = $check->get_result();
612 return $this->warning($result->get_summary() . '&nbsp;' . $this->help_icon('cron', 'admin'));
616 * Render an appropriate message if cron is not being run frequently (recommended every minute).
618 * @param bool $croninfrequent
619 * @return string HTML to output.
621 public function cron_infrequent_warning(bool $croninfrequent) : string {
622 global $CFG;
624 if (!$croninfrequent) {
625 return '';
628 $check = new \tool_task\check\cronrunning();
629 $result = $check->get_result();
630 return $this->warning($result->get_summary() . '&nbsp;' . $this->help_icon('cron', 'admin'));
634 * Render an appropriate message if there are any problems with the DB set-up.
635 * @param bool $dbproblems
636 * @return string HTML to output.
638 public function db_problems($dbproblems) {
639 if (!$dbproblems) {
640 return '';
643 return $this->warning($dbproblems);
647 * Renders cache warnings if there are any.
649 * @param string[] $cachewarnings
650 * @return string
652 public function cache_warnings(array $cachewarnings) {
653 if (!count($cachewarnings)) {
654 return '';
656 return join("\n", array_map(array($this, 'warning'), $cachewarnings));
660 * Renders events 1 API handlers warning.
662 * @param array $eventshandlers
663 * @return string
665 public function events_handlers($eventshandlers) {
666 if ($eventshandlers) {
667 $components = '';
668 foreach ($eventshandlers as $eventhandler) {
669 $components .= $eventhandler->component . ', ';
671 $components = rtrim($components, ', ');
672 return $this->warning(get_string('eventshandlersinuse', 'admin', $components));
677 * Render an appropriate message if the site in in maintenance mode.
678 * @param bool $maintenancemode
679 * @return string HTML to output.
681 public function maintenance_mode_warning($maintenancemode) {
682 if (!$maintenancemode) {
683 return '';
686 $url = new moodle_url('/admin/settings.php', array('section' => 'maintenancemode'));
687 $url = $url->out(); // get_string() does not support objects in params
689 return $this->warning(get_string('sitemaintenancewarning2', 'admin', $url));
693 * Render a warning that ssl is forced because the site was on loginhttps.
695 * @param bool $overridetossl Whether or not ssl is being forced.
696 * @return string
698 protected function overridetossl_warning($overridetossl) {
699 if (!$overridetossl) {
700 return '';
702 $warning = get_string('overridetossl', 'core_admin');
703 return $this->warning($warning, 'warning');
707 * Display a warning about installing development code if necesary.
708 * @param int $maturity
709 * @return string HTML to output.
711 protected function maturity_warning($maturity) {
712 if ($maturity == MATURITY_STABLE) {
713 return ''; // No worries.
716 $maturitylevel = get_string('maturity' . $maturity, 'admin');
717 return $this->warning(
718 $this->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
719 $this->container($this->doc_link('admin/versions', get_string('morehelp'))),
720 'danger');
724 * If necessary, displays a warning about upgrading a test site.
726 * @param string $testsite
727 * @return string HTML
729 protected function test_site_warning($testsite) {
731 if (!$testsite) {
732 return '';
735 $warning = (get_string('testsiteupgradewarning', 'admin', $testsite));
736 return $this->warning($warning, 'danger');
740 * Output the copyright notice.
741 * @return string HTML to output.
743 protected function moodle_copyright() {
744 global $CFG;
746 //////////////////////////////////////////////////////////////////////////////////////////////////
747 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
748 $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
749 '<a href="http://docs.moodle.org/dev/Releases" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
750 'Copyright &copy; 1999 onwards, Martin Dougiamas<br />'.
751 'and <a href="http://moodle.org/dev">many other contributors</a>.<br />'.
752 '<a href="http://docs.moodle.org/dev/License">GNU Public License</a>';
753 //////////////////////////////////////////////////////////////////////////////////////////////////
755 return $this->box($copyrighttext, 'copyright');
759 * Display a warning about installing development code if necesary.
760 * @param int $maturity
761 * @return string HTML to output.
763 protected function maturity_info($maturity) {
764 if ($maturity == MATURITY_STABLE) {
765 return ''; // No worries.
768 $level = 'warning';
770 if ($maturity == MATURITY_ALPHA) {
771 $level = 'danger';
774 $maturitylevel = get_string('maturity' . $maturity, 'admin');
775 $warningtext = get_string('maturitycoreinfo', 'admin', $maturitylevel);
776 $warningtext .= ' ' . $this->doc_link('admin/versions', get_string('morehelp'));
777 return $this->warning($warningtext, $level);
781 * Displays the info about available Moodle core and plugin updates
783 * The structure of the $updates param has changed since 2.4. It contains not only updates
784 * for the core itself, but also for all other installed plugins.
786 * @param array|null $updates array of (string)component => array of \core\update\info objects or null
787 * @param int|null $fetch timestamp of the most recent updates fetch or null (unknown)
788 * @return string
790 protected function available_updates($updates, $fetch) {
792 $updateinfo = '';
793 $someupdateavailable = false;
794 if (is_array($updates)) {
795 if (is_array($updates['core'])) {
796 $someupdateavailable = true;
797 $updateinfo .= $this->heading(get_string('updateavailable', 'core_admin'), 3);
798 foreach ($updates['core'] as $update) {
799 $updateinfo .= $this->moodle_available_update_info($update);
801 $updateinfo .= html_writer::tag('p', get_string('updateavailablerecommendation', 'core_admin'),
802 array('class' => 'updateavailablerecommendation'));
804 unset($updates['core']);
805 // If something has left in the $updates array now, it is updates for plugins.
806 if (!empty($updates)) {
807 $someupdateavailable = true;
808 $updateinfo .= $this->heading(get_string('updateavailableforplugin', 'core_admin'), 3);
809 $pluginsoverviewurl = new moodle_url('/admin/plugins.php', array('updatesonly' => 1));
810 $updateinfo .= $this->container(get_string('pluginsoverviewsee', 'core_admin',
811 array('url' => $pluginsoverviewurl->out())));
815 if (!$someupdateavailable) {
816 $now = time();
817 if ($fetch and ($fetch <= $now) and ($now - $fetch < HOURSECS)) {
818 $updateinfo .= $this->heading(get_string('updateavailablenot', 'core_admin'), 3);
822 $updateinfo .= $this->container_start('checkforupdates mt-1');
823 $fetchurl = new moodle_url('/admin/index.php', array('fetchupdates' => 1, 'sesskey' => sesskey(), 'cache' => 0));
824 $updateinfo .= $this->single_button($fetchurl, get_string('checkforupdates', 'core_plugin'));
825 if ($fetch) {
826 $updateinfo .= $this->container(get_string('checkforupdateslast', 'core_plugin',
827 userdate($fetch, get_string('strftimedatetime', 'core_langconfig'))));
829 $updateinfo .= $this->container_end();
831 return $this->warning($updateinfo);
835 * Display a warning about not being registered on Moodle.org if necesary.
837 * @param boolean $registered true if the site is registered on Moodle.org
838 * @return string HTML to output.
840 protected function registration_warning($registered) {
842 if (!$registered && site_is_public()) {
843 if (has_capability('moodle/site:config', context_system::instance())) {
844 $registerbutton = $this->single_button(new moodle_url('/admin/registration/index.php'),
845 get_string('register', 'admin'));
846 $str = 'registrationwarning';
847 } else {
848 $registerbutton = '';
849 $str = 'registrationwarningcontactadmin';
852 return $this->warning( get_string($str, 'admin')
853 . '&nbsp;' . $this->help_icon('registration', 'admin') . $registerbutton ,
854 'error alert alert-danger');
857 return '';
861 * Return an admin page warning if site is not registered with moodle.org
863 * @return string
865 public function warn_if_not_registered() {
866 return $this->registration_warning(\core\hub\registration::is_registered());
870 * Display a warning about the Mobile Web Services being disabled.
872 * @param boolean $mobileconfigured true if mobile web services are enabled
873 * @return string HTML to output.
875 protected function mobile_configuration_warning($mobileconfigured) {
876 $output = '';
877 if (!$mobileconfigured) {
878 $settingslink = new moodle_url('/admin/settings.php', ['section' => 'mobilesettings']);
879 $configurebutton = $this->single_button($settingslink, get_string('enablemobilewebservice', 'admin'));
880 $output .= $this->warning(get_string('mobilenotconfiguredwarning', 'admin') . '&nbsp;' . $configurebutton);
883 return $output;
887 * Display campaign content.
889 * @param bool $showcampaigncontent Whether the campaign content should be visible or not.
890 * @return string the campaign content raw html.
892 protected function campaign_content(bool $showcampaigncontent): string {
893 if (!$showcampaigncontent) {
894 return '';
897 $lang = current_language();
898 $url = "https://campaign.moodle.org/current/lms/{$lang}/install/";
899 $params = [
900 'url' => $url,
901 'iframeid' => 'campaign-content'
904 return $this->render_from_template('core/external_content_banner', $params);
908 * Display services and support content.
910 * @param bool $showservicesandsupport Whether the services and support content should be visible or not.
911 * @return string the campaign content raw html.
913 protected function services_and_support_content(bool $showservicesandsupport): string {
914 if (!$showservicesandsupport) {
915 return '';
918 $lang = current_language();
919 $url = "https://campaign.moodle.org/current/lms/{$lang}/servicesandsupport/";
920 $params = [
921 'url' => $url,
922 'iframeid' => 'services-support-content'
925 return $this->render_from_template('core/external_content_banner', $params);
929 * Display a warning about the forgotten password URL not linking to a valid URL.
931 * @param boolean $invalidforgottenpasswordurl true if the forgotten password URL is not valid
932 * @return string HTML to output.
934 protected function forgotten_password_url_warning($invalidforgottenpasswordurl) {
935 $output = '';
936 if ($invalidforgottenpasswordurl) {
937 $settingslink = new moodle_url('/admin/settings.php', ['section' => 'manageauths']);
938 $configurebutton = $this->single_button($settingslink, get_string('check', 'moodle'));
939 $output .= $this->warning(get_string('invalidforgottenpasswordurl', 'admin') . '&nbsp;' . $configurebutton,
940 'error alert alert-danger');
943 return $output;
947 * Helper method to render the information about the available Moodle update
949 * @param \core\update\info $updateinfo information about the available Moodle core update
951 protected function moodle_available_update_info(\core\update\info $updateinfo) {
953 $boxclasses = 'moodleupdateinfo mb-2';
954 $info = array();
956 if (isset($updateinfo->release)) {
957 $info[] = html_writer::tag('span', get_string('updateavailable_release', 'core_admin', $updateinfo->release),
958 array('class' => 'info release'));
961 if (isset($updateinfo->version)) {
962 $info[] = html_writer::tag('span', get_string('updateavailable_version', 'core_admin', $updateinfo->version),
963 array('class' => 'info version'));
966 if (isset($updateinfo->maturity)) {
967 $info[] = html_writer::tag('span', get_string('maturity'.$updateinfo->maturity, 'core_admin'),
968 array('class' => 'info maturity'));
969 $boxclasses .= ' maturity'.$updateinfo->maturity;
972 if (isset($updateinfo->download)) {
973 $info[] = html_writer::link($updateinfo->download, get_string('download'),
974 array('class' => 'info download btn btn-secondary'));
977 if (isset($updateinfo->url)) {
978 $info[] = html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin'),
979 array('class' => 'info more'));
982 $box = $this->output->container_start($boxclasses);
983 $box .= $this->output->container(implode(html_writer::tag('span', ' | ', array('class' => 'separator')), $info), '');
984 $box .= $this->output->container_end();
986 return $box;
990 * Display a link to the release notes.
991 * @return string HTML to output.
993 protected function release_notes_link() {
994 $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/dev/Releases');
995 $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
996 return $this->box($releasenoteslink, 'generalbox alert alert-info');
1000 * Display the reload link that appears on several upgrade/install pages.
1001 * @return string HTML to output.
1003 function upgrade_reload($url) {
1004 return html_writer::empty_tag('br') .
1005 html_writer::tag('div',
1006 html_writer::link($url, $this->pix_icon('i/reload', '', '', array('class' => 'icon icon-pre')) .
1007 get_string('reload'), array('title' => get_string('reload'))),
1008 array('class' => 'continuebutton')) . html_writer::empty_tag('br');
1012 * Displays all known plugins and information about their installation or upgrade
1014 * This default implementation renders all plugins into one big table. The rendering
1015 * options support:
1016 * (bool)full = false: whether to display up-to-date plugins, too
1017 * (bool)xdep = false: display the plugins with unsatisified dependecies only
1019 * @param core_plugin_manager $pluginman provides information about the plugins.
1020 * @param int $version the version of the Moodle code from version.php.
1021 * @param array $options rendering options
1022 * @return string HTML code
1024 public function plugins_check_table(core_plugin_manager $pluginman, $version, array $options = array()) {
1025 global $CFG;
1026 $plugininfo = $pluginman->get_plugins();
1028 if (empty($plugininfo)) {
1029 return '';
1032 $options['full'] = isset($options['full']) ? (bool)$options['full'] : false;
1033 $options['xdep'] = isset($options['xdep']) ? (bool)$options['xdep'] : false;
1035 $table = new html_table();
1036 $table->id = 'plugins-check';
1037 $table->head = array(
1038 get_string('displayname', 'core_plugin').' / '.get_string('rootdir', 'core_plugin'),
1039 get_string('versiondb', 'core_plugin'),
1040 get_string('versiondisk', 'core_plugin'),
1041 get_string('requires', 'core_plugin'),
1042 get_string('source', 'core_plugin').' / '.get_string('status', 'core_plugin'),
1044 $table->colclasses = array(
1045 'displayname', 'versiondb', 'versiondisk', 'requires', 'status',
1047 $table->data = array();
1049 // Number of displayed plugins per type.
1050 $numdisplayed = array();
1051 // Number of plugins known to the plugin manager.
1052 $sumtotal = 0;
1053 // Number of plugins requiring attention.
1054 $sumattention = 0;
1055 // List of all components we can cancel installation of.
1056 $installabortable = $pluginman->list_cancellable_installations();
1057 // List of all components we can cancel upgrade of.
1058 $upgradeabortable = $pluginman->list_restorable_archives();
1060 foreach ($plugininfo as $type => $plugins) {
1062 $header = new html_table_cell($pluginman->plugintype_name_plural($type));
1063 $header->header = true;
1064 $header->colspan = count($table->head);
1065 $header = new html_table_row(array($header));
1066 $header->attributes['class'] = 'plugintypeheader type-' . $type;
1068 $numdisplayed[$type] = 0;
1070 if (empty($plugins) and $options['full']) {
1071 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
1072 $msg->colspan = count($table->head);
1073 $row = new html_table_row(array($msg));
1074 $row->attributes['class'] .= 'msg msg-noneinstalled';
1075 $table->data[] = $header;
1076 $table->data[] = $row;
1077 continue;
1080 $plugintyperows = array();
1082 foreach ($plugins as $name => $plugin) {
1083 $component = "{$plugin->type}_{$plugin->name}";
1085 $sumtotal++;
1086 $row = new html_table_row();
1087 $row->attributes['class'] = "type-{$plugin->type} name-{$component}";
1089 $iconidentifier = 'icon';
1090 if ($plugin->type === 'mod') {
1091 $iconidentifier = 'monologo';
1094 if ($this->page->theme->resolve_image_location($iconidentifier, $component, null)) {
1095 $icon = $this->output->pix_icon($iconidentifier, '', $component, [
1096 'class' => 'smallicon pluginicon',
1098 } else {
1099 $icon = '';
1102 $displayname = new html_table_cell(
1103 $icon.
1104 html_writer::span($plugin->displayname, 'pluginname').
1105 html_writer::div($plugin->get_dir(), 'plugindir text-muted small')
1108 $versiondb = new html_table_cell($plugin->versiondb);
1109 $versiondisk = new html_table_cell($plugin->versiondisk);
1111 if ($isstandard = $plugin->is_standard()) {
1112 $row->attributes['class'] .= ' standard';
1113 $sourcelabel = html_writer::span(get_string('sourcestd', 'core_plugin'), 'sourcetext badge badge-secondary');
1114 } else {
1115 $row->attributes['class'] .= ' extension';
1116 $sourcelabel = html_writer::span(get_string('sourceext', 'core_plugin'), 'sourcetext badge badge-info');
1119 $coredependency = $plugin->is_core_dependency_satisfied($version);
1120 $incompatibledependency = $plugin->is_core_compatible_satisfied($CFG->branch);
1122 $otherpluginsdependencies = $pluginman->are_dependencies_satisfied($plugin->get_other_required_plugins());
1123 $dependenciesok = $coredependency && $otherpluginsdependencies && $incompatibledependency;
1125 $statuscode = $plugin->get_status();
1126 $row->attributes['class'] .= ' status-' . $statuscode;
1127 $statusclass = 'statustext badge ';
1128 switch ($statuscode) {
1129 case core_plugin_manager::PLUGIN_STATUS_NEW:
1130 $statusclass .= $dependenciesok ? 'badge-success' : 'badge-warning';
1131 break;
1132 case core_plugin_manager::PLUGIN_STATUS_UPGRADE:
1133 $statusclass .= $dependenciesok ? 'badge-info' : 'badge-warning';
1134 break;
1135 case core_plugin_manager::PLUGIN_STATUS_MISSING:
1136 case core_plugin_manager::PLUGIN_STATUS_DOWNGRADE:
1137 case core_plugin_manager::PLUGIN_STATUS_DELETE:
1138 $statusclass .= 'badge-danger';
1139 break;
1140 case core_plugin_manager::PLUGIN_STATUS_NODB:
1141 case core_plugin_manager::PLUGIN_STATUS_UPTODATE:
1142 $statusclass .= $dependenciesok ? 'badge-light' : 'badge-warning';
1143 break;
1145 $status = html_writer::span(get_string('status_' . $statuscode, 'core_plugin'), $statusclass);
1147 if (!empty($installabortable[$plugin->component])) {
1148 $status .= $this->output->single_button(
1149 new moodle_url($this->page->url, array('abortinstall' => $plugin->component, 'confirmplugincheck' => 0)),
1150 get_string('cancelinstallone', 'core_plugin'),
1151 'post',
1152 array('class' => 'actionbutton cancelinstallone d-block mt-1')
1156 if (!empty($upgradeabortable[$plugin->component])) {
1157 $status .= $this->output->single_button(
1158 new moodle_url($this->page->url, array('abortupgrade' => $plugin->component)),
1159 get_string('cancelupgradeone', 'core_plugin'),
1160 'post',
1161 array('class' => 'actionbutton cancelupgradeone d-block mt-1')
1165 $availableupdates = $plugin->available_updates();
1166 if (!empty($availableupdates)) {
1167 foreach ($availableupdates as $availableupdate) {
1168 $status .= $this->plugin_available_update_info($pluginman, $availableupdate);
1172 $status = new html_table_cell($sourcelabel.' '.$status);
1173 if ($plugin->pluginsupported != null) {
1174 $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version, $CFG->branch));
1175 } else {
1176 $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version));
1179 $statusisboring = in_array($statuscode, array(
1180 core_plugin_manager::PLUGIN_STATUS_NODB, core_plugin_manager::PLUGIN_STATUS_UPTODATE));
1182 if ($options['xdep']) {
1183 // we want to see only plugins with failed dependencies
1184 if ($dependenciesok) {
1185 continue;
1188 } else if ($statusisboring and $dependenciesok and empty($availableupdates)) {
1189 // no change is going to happen to the plugin - display it only
1190 // if the user wants to see the full list
1191 if (empty($options['full'])) {
1192 continue;
1195 } else {
1196 $sumattention++;
1199 // The plugin should be displayed.
1200 $numdisplayed[$type]++;
1201 $row->cells = array($displayname, $versiondb, $versiondisk, $requires, $status);
1202 $plugintyperows[] = $row;
1205 if (empty($numdisplayed[$type]) and empty($options['full'])) {
1206 continue;
1209 $table->data[] = $header;
1210 $table->data = array_merge($table->data, $plugintyperows);
1213 // Total number of displayed plugins.
1214 $sumdisplayed = array_sum($numdisplayed);
1216 if ($options['xdep']) {
1217 // At the plugins dependencies check page, display the table only.
1218 return html_writer::table($table);
1221 $out = $this->output->container_start('', 'plugins-check-info');
1223 if ($sumdisplayed == 0) {
1224 $out .= $this->output->heading(get_string('pluginchecknone', 'core_plugin'));
1226 } else {
1227 if (empty($options['full'])) {
1228 $out .= $this->output->heading(get_string('plugincheckattention', 'core_plugin'));
1229 } else {
1230 $out .= $this->output->heading(get_string('plugincheckall', 'core_plugin'));
1234 $out .= $this->output->container_start('actions mb-2');
1236 $installableupdates = $pluginman->filter_installable($pluginman->available_updates());
1237 if ($installableupdates) {
1238 $out .= $this->output->single_button(
1239 new moodle_url($this->page->url, array('installupdatex' => 1)),
1240 get_string('updateavailableinstallall', 'core_admin', count($installableupdates)),
1241 'post',
1242 array('class' => 'singlebutton updateavailableinstallall mr-1')
1246 if ($installabortable) {
1247 $out .= $this->output->single_button(
1248 new moodle_url($this->page->url, array('abortinstallx' => 1, 'confirmplugincheck' => 0)),
1249 get_string('cancelinstallall', 'core_plugin', count($installabortable)),
1250 'post',
1251 array('class' => 'singlebutton cancelinstallall mr-1')
1255 if ($upgradeabortable) {
1256 $out .= $this->output->single_button(
1257 new moodle_url($this->page->url, array('abortupgradex' => 1)),
1258 get_string('cancelupgradeall', 'core_plugin', count($upgradeabortable)),
1259 'post',
1260 array('class' => 'singlebutton cancelupgradeall mr-1')
1264 $out .= html_writer::div(html_writer::link(new moodle_url($this->page->url, array('showallplugins' => 0)),
1265 get_string('plugincheckattention', 'core_plugin')).' '.html_writer::span($sumattention, 'badge badge-light'),
1266 'btn btn-link mr-1');
1268 $out .= html_writer::div(html_writer::link(new moodle_url($this->page->url, array('showallplugins' => 1)),
1269 get_string('plugincheckall', 'core_plugin')).' '.html_writer::span($sumtotal, 'badge badge-light'),
1270 'btn btn-link mr-1');
1272 $out .= $this->output->container_end(); // End of .actions container.
1273 $out .= $this->output->container_end(); // End of #plugins-check-info container.
1275 if ($sumdisplayed > 0 or $options['full']) {
1276 $out .= html_writer::table($table);
1279 return $out;
1283 * Display the continue / cancel widgets for the plugins management pages.
1285 * @param null|moodle_url $continue URL for the continue button, should it be displayed
1286 * @param null|moodle_url $cancel URL for the cancel link, defaults to the current page
1287 * @return string HTML
1289 public function plugins_management_confirm_buttons(moodle_url $continue=null, moodle_url $cancel=null) {
1291 $out = html_writer::start_div('plugins-management-confirm-buttons');
1293 if (!empty($continue)) {
1294 $out .= $this->output->single_button($continue, get_string('continue'), 'post', array('class' => 'continue'));
1297 if (empty($cancel)) {
1298 $cancel = $this->page->url;
1300 $out .= html_writer::div(html_writer::link($cancel, get_string('cancel')), 'cancel');
1302 return $out;
1306 * Displays the information about missing dependencies
1308 * @param core_plugin_manager $pluginman
1309 * @return string
1311 protected function missing_dependencies(core_plugin_manager $pluginman) {
1313 $dependencies = $pluginman->missing_dependencies();
1315 if (empty($dependencies)) {
1316 return '';
1319 $available = array();
1320 $unavailable = array();
1321 $unknown = array();
1323 foreach ($dependencies as $component => $remoteinfo) {
1324 if ($remoteinfo === false) {
1325 // The required version is not available. Let us check if there
1326 // is at least some version in the plugins directory.
1327 $remoteinfoanyversion = $pluginman->get_remote_plugin_info($component, ANY_VERSION, false);
1328 if ($remoteinfoanyversion === false) {
1329 $unknown[$component] = $component;
1330 } else {
1331 $unavailable[$component] = $remoteinfoanyversion;
1333 } else {
1334 $available[$component] = $remoteinfo;
1338 $out = $this->output->container_start('plugins-check-dependencies mb-4');
1340 if ($unavailable or $unknown) {
1341 $out .= $this->output->heading(get_string('misdepsunavail', 'core_plugin'));
1342 if ($unknown) {
1343 $out .= $this->output->render((new \core\output\notification(get_string('misdepsunknownlist', 'core_plugin',
1344 implode(', ', $unknown))))->set_show_closebutton(false));
1346 if ($unavailable) {
1347 $unavailablelist = array();
1348 foreach ($unavailable as $component => $remoteinfoanyversion) {
1349 $unavailablelistitem = html_writer::link('https://moodle.org/plugins/view.php?plugin='.$component,
1350 '<strong>'.$remoteinfoanyversion->name.'</strong>');
1351 if ($remoteinfoanyversion->version) {
1352 $unavailablelistitem .= ' ('.$component.' &gt; '.$remoteinfoanyversion->version->version.')';
1353 } else {
1354 $unavailablelistitem .= ' ('.$component.')';
1356 $unavailablelist[] = $unavailablelistitem;
1358 $out .= $this->output->render((new \core\output\notification(get_string('misdepsunavaillist', 'core_plugin',
1359 implode(', ', $unavailablelist))))->set_show_closebutton(false));
1361 $out .= $this->output->container_start('plugins-check-dependencies-actions mb-4');
1362 $out .= ' '.html_writer::link(new moodle_url('/admin/tool/installaddon/'),
1363 get_string('dependencyuploadmissing', 'core_plugin'), array('class' => 'btn btn-secondary'));
1364 $out .= $this->output->container_end(); // End of .plugins-check-dependencies-actions container.
1367 if ($available) {
1368 $out .= $this->output->heading(get_string('misdepsavail', 'core_plugin'));
1369 $out .= $this->output->container_start('plugins-check-dependencies-actions mb-2');
1371 $installable = $pluginman->filter_installable($available);
1372 if ($installable) {
1373 $out .= $this->output->single_button(
1374 new moodle_url($this->page->url, array('installdepx' => 1)),
1375 get_string('dependencyinstallmissing', 'core_plugin', count($installable)),
1376 'post',
1377 array('class' => 'singlebutton dependencyinstallmissing d-inline-block mr-1')
1381 $out .= html_writer::div(html_writer::link(new moodle_url('/admin/tool/installaddon/'),
1382 get_string('dependencyuploadmissing', 'core_plugin'), array('class' => 'btn btn-link')),
1383 'dependencyuploadmissing d-inline-block mr-1');
1385 $out .= $this->output->container_end(); // End of .plugins-check-dependencies-actions container.
1387 $out .= $this->available_missing_dependencies_list($pluginman, $available);
1390 $out .= $this->output->container_end(); // End of .plugins-check-dependencies container.
1392 return $out;
1396 * Displays the list if available missing dependencies.
1398 * @param core_plugin_manager $pluginman
1399 * @param array $dependencies
1400 * @return string
1402 protected function available_missing_dependencies_list(core_plugin_manager $pluginman, array $dependencies) {
1403 global $CFG;
1405 $table = new html_table();
1406 $table->id = 'plugins-check-available-dependencies';
1407 $table->head = array(
1408 get_string('displayname', 'core_plugin'),
1409 get_string('release', 'core_plugin'),
1410 get_string('version', 'core_plugin'),
1411 get_string('supportedmoodleversions', 'core_plugin'),
1412 get_string('info', 'core'),
1414 $table->colclasses = array('displayname', 'release', 'version', 'supportedmoodleversions', 'info');
1415 $table->data = array();
1417 foreach ($dependencies as $plugin) {
1419 $supportedmoodles = array();
1420 foreach ($plugin->version->supportedmoodles as $moodle) {
1421 if ($CFG->branch == str_replace('.', '', $moodle->release)) {
1422 $supportedmoodles[] = html_writer::span($moodle->release, 'badge badge-success');
1423 } else {
1424 $supportedmoodles[] = html_writer::span($moodle->release, 'badge badge-light');
1428 $requriedby = $pluginman->other_plugins_that_require($plugin->component);
1429 if ($requriedby) {
1430 foreach ($requriedby as $ix => $val) {
1431 $inf = $pluginman->get_plugin_info($val);
1432 if ($inf) {
1433 $requriedby[$ix] = $inf->displayname.' ('.$inf->component.')';
1436 $info = html_writer::div(
1437 get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
1438 'requiredby mb-1'
1440 } else {
1441 $info = '';
1444 $info .= $this->output->container_start('actions');
1446 $info .= html_writer::div(
1447 html_writer::link('https://moodle.org/plugins/view.php?plugin='.$plugin->component,
1448 get_string('misdepinfoplugin', 'core_plugin')),
1449 'misdepinfoplugin d-inline-block mr-3 mb-1'
1452 $info .= html_writer::div(
1453 html_writer::link('https://moodle.org/plugins/pluginversion.php?id='.$plugin->version->id,
1454 get_string('misdepinfoversion', 'core_plugin')),
1455 'misdepinfoversion d-inline-block mr-3 mb-1'
1458 $info .= html_writer::div(html_writer::link($plugin->version->downloadurl, get_string('download')),
1459 'misdepdownload d-inline-block mr-3 mb-1');
1461 if ($pluginman->is_remote_plugin_installable($plugin->component, $plugin->version->version, $reason)) {
1462 $info .= $this->output->single_button(
1463 new moodle_url($this->page->url, array('installdep' => $plugin->component)),
1464 get_string('dependencyinstall', 'core_plugin'),
1465 'post',
1466 array('class' => 'singlebutton dependencyinstall mr-3 mb-1')
1468 } else {
1469 $reasonhelp = $this->info_remote_plugin_not_installable($reason);
1470 if ($reasonhelp) {
1471 $info .= html_writer::div($reasonhelp, 'reasonhelp dependencyinstall d-inline-block mr-3 mb-1');
1475 $info .= $this->output->container_end(); // End of .actions container.
1477 $table->data[] = array(
1478 html_writer::div($plugin->name, 'name').' '.html_writer::div($plugin->component, 'component text-muted small'),
1479 $plugin->version->release,
1480 $plugin->version->version,
1481 implode(' ', $supportedmoodles),
1482 $info
1486 return html_writer::table($table);
1490 * Explain why {@link core_plugin_manager::is_remote_plugin_installable()} returned false.
1492 * @param string $reason the reason code as returned by the plugin manager
1493 * @return string
1495 protected function info_remote_plugin_not_installable($reason) {
1497 if ($reason === 'notwritableplugintype' or $reason === 'notwritableplugin') {
1498 return $this->output->help_icon('notwritable', 'core_plugin', get_string('notwritable', 'core_plugin'));
1501 if ($reason === 'remoteunavailable') {
1502 return $this->output->help_icon('notdownloadable', 'core_plugin', get_string('notdownloadable', 'core_plugin'));
1505 return false;
1509 * Formats the information that needs to go in the 'Requires' column.
1510 * @param \core\plugininfo\base $plugin the plugin we are rendering the row for.
1511 * @param core_plugin_manager $pluginman provides data on all the plugins.
1512 * @param string $version
1513 * @param int $branch the current Moodle branch
1514 * @return string HTML code
1516 protected function required_column(\core\plugininfo\base $plugin, core_plugin_manager $pluginman, $version, $branch = null) {
1518 $requires = array();
1519 $displayuploadlink = false;
1520 $displayupdateslink = false;
1522 $requirements = $pluginman->resolve_requirements($plugin, $version, $branch);
1523 foreach ($requirements as $reqname => $reqinfo) {
1524 if ($reqname === 'core') {
1525 if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OK) {
1526 $class = 'requires-ok text-muted';
1527 $label = '';
1528 } else {
1529 $class = 'requires-failed';
1530 $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'badge badge-danger');
1533 if ($branch != null && !$plugin->is_core_compatible_satisfied($branch)) {
1534 $requires[] = html_writer::tag('li',
1535 html_writer::span(get_string('incompatibleversion', 'core_plugin', $branch), 'dep dep-core').
1536 ' '.$label, array('class' => $class));
1538 } else if ($branch != null && $plugin->pluginsupported != null) {
1539 $requires[] = html_writer::tag('li',
1540 html_writer::span(get_string('moodlebranch', 'core_plugin',
1541 array('min' => $plugin->pluginsupported[0], 'max' => $plugin->pluginsupported[1])), 'dep dep-core').
1542 ' '.$label, array('class' => $class));
1544 } else if ($reqinfo->reqver != ANY_VERSION) {
1545 $requires[] = html_writer::tag('li',
1546 html_writer::span(get_string('moodleversion', 'core_plugin', $plugin->versionrequires), 'dep dep-core').
1547 ' '.$label, array('class' => $class));
1550 } else {
1551 $actions = array();
1553 if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OK) {
1554 $label = '';
1555 $class = 'requires-ok text-muted';
1557 } else if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_MISSING) {
1558 if ($reqinfo->availability == $pluginman::REQUIREMENT_AVAILABLE) {
1559 $label = html_writer::span(get_string('dependencymissing', 'core_plugin'), 'badge badge-warning');
1560 $label .= ' '.html_writer::span(get_string('dependencyavailable', 'core_plugin'), 'badge badge-warning');
1561 $class = 'requires-failed requires-missing requires-available';
1562 $actions[] = html_writer::link(
1563 new moodle_url('https://moodle.org/plugins/view.php', array('plugin' => $reqname)),
1564 get_string('misdepinfoplugin', 'core_plugin')
1567 } else {
1568 $label = html_writer::span(get_string('dependencymissing', 'core_plugin'), 'badge badge-danger');
1569 $label .= ' '.html_writer::span(get_string('dependencyunavailable', 'core_plugin'),
1570 'badge badge-danger');
1571 $class = 'requires-failed requires-missing requires-unavailable';
1573 $displayuploadlink = true;
1575 } else if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OUTDATED) {
1576 if ($reqinfo->availability == $pluginman::REQUIREMENT_AVAILABLE) {
1577 $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'badge badge-warning');
1578 $label .= ' '.html_writer::span(get_string('dependencyavailable', 'core_plugin'), 'badge badge-warning');
1579 $class = 'requires-failed requires-outdated requires-available';
1580 $displayupdateslink = true;
1582 } else {
1583 $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'badge badge-danger');
1584 $label .= ' '.html_writer::span(get_string('dependencyunavailable', 'core_plugin'),
1585 'badge badge-danger');
1586 $class = 'requires-failed requires-outdated requires-unavailable';
1588 $displayuploadlink = true;
1591 if ($reqinfo->reqver != ANY_VERSION) {
1592 $str = 'otherpluginversion';
1593 } else {
1594 $str = 'otherplugin';
1597 $requires[] = html_writer::tag('li', html_writer::span(
1598 get_string($str, 'core_plugin', array('component' => $reqname, 'version' => $reqinfo->reqver)),
1599 'dep dep-plugin').' '.$label.' '.html_writer::span(implode(' | ', $actions), 'actions'),
1600 array('class' => $class)
1605 if (!$requires) {
1606 return '';
1609 $out = html_writer::tag('ul', implode("\n", $requires), array('class' => 'm-0'));
1611 if ($displayuploadlink) {
1612 $out .= html_writer::div(
1613 html_writer::link(
1614 new moodle_url('/admin/tool/installaddon/'),
1615 get_string('dependencyuploadmissing', 'core_plugin'),
1616 array('class' => 'btn btn-secondary btn-sm m-1')
1618 'dependencyuploadmissing'
1622 if ($displayupdateslink) {
1623 $out .= html_writer::div(
1624 html_writer::link(
1625 new moodle_url($this->page->url, array('sesskey' => sesskey(), 'fetchupdates' => 1)),
1626 get_string('checkforupdates', 'core_plugin'),
1627 array('class' => 'btn btn-secondary btn-sm m-1')
1629 'checkforupdates'
1633 // Check if supports is present, and $branch is not in, only if $incompatible check was ok.
1634 if ($plugin->pluginsupported != null && $class == 'requires-ok' && $branch != null) {
1635 if ($pluginman->check_explicitly_supported($plugin, $branch) == $pluginman::VERSION_NOT_SUPPORTED) {
1636 $out .= html_writer::div(get_string('notsupported', 'core_plugin', $branch));
1640 return $out;
1645 * Prints an overview about the plugins - number of installed, number of extensions etc.
1647 * @param core_plugin_manager $pluginman provides information about the plugins
1648 * @param array $options filtering options
1649 * @return string as usually
1651 public function plugins_overview_panel(core_plugin_manager $pluginman, array $options = array()) {
1653 $plugininfo = $pluginman->get_plugins();
1655 $numtotal = $numextension = $numupdatable = $numinstallable = 0;
1657 foreach ($plugininfo as $type => $plugins) {
1658 foreach ($plugins as $name => $plugin) {
1659 if ($res = $plugin->available_updates()) {
1660 $numupdatable++;
1661 foreach ($res as $updateinfo) {
1662 if ($pluginman->is_remote_plugin_installable($updateinfo->component, $updateinfo->version, $reason, false)) {
1663 $numinstallable++;
1664 break;
1668 if ($plugin->get_status() === core_plugin_manager::PLUGIN_STATUS_MISSING) {
1669 continue;
1671 $numtotal++;
1672 if (!$plugin->is_standard()) {
1673 $numextension++;
1678 $infoall = html_writer::link(
1679 new moodle_url($this->page->url, array('contribonly' => 0, 'updatesonly' => 0)),
1680 get_string('overviewall', 'core_plugin'),
1681 array('title' => get_string('filterall', 'core_plugin'))
1682 ).' '.html_writer::span($numtotal, 'badge number number-all');
1684 $infoext = html_writer::link(
1685 new moodle_url($this->page->url, array('contribonly' => 1, 'updatesonly' => 0)),
1686 get_string('overviewext', 'core_plugin'),
1687 array('title' => get_string('filtercontribonly', 'core_plugin'))
1688 ).' '.html_writer::span($numextension, 'badge number number-additional');
1690 if ($numupdatable) {
1691 $infoupdatable = html_writer::link(
1692 new moodle_url($this->page->url, array('contribonly' => 0, 'updatesonly' => 1)),
1693 get_string('overviewupdatable', 'core_plugin'),
1694 array('title' => get_string('filterupdatesonly', 'core_plugin'))
1695 ).' '.html_writer::span($numupdatable, 'badge badge-info number number-updatable');
1696 } else {
1697 // No updates, or the notifications disabled.
1698 $infoupdatable = '';
1701 $out = html_writer::start_div('', array('id' => 'plugins-overview-panel'));
1703 if (!empty($options['updatesonly'])) {
1704 $out .= $this->output->heading(get_string('overviewupdatable', 'core_plugin'), 3);
1705 } else if (!empty($options['contribonly'])) {
1706 $out .= $this->output->heading(get_string('overviewext', 'core_plugin'), 3);
1709 if ($numinstallable) {
1710 $out .= $this->output->single_button(
1711 new moodle_url($this->page->url, array('installupdatex' => 1)),
1712 get_string('updateavailableinstallall', 'core_admin', $numinstallable),
1713 'post',
1714 array('class' => 'singlebutton updateavailableinstallall')
1718 $out .= html_writer::div($infoall, 'info info-all').
1719 html_writer::div($infoext, 'info info-ext').
1720 html_writer::div($infoupdatable, 'info info-updatable');
1722 $out .= html_writer::end_div(); // End of #plugins-overview-panel block.
1724 return $out;
1728 * Displays all known plugins and links to manage them
1730 * This default implementation renders all plugins into one big table.
1732 * @param core_plugin_manager $pluginman provides information about the plugins.
1733 * @param array $options filtering options
1734 * @return string HTML code
1736 public function plugins_control_panel(core_plugin_manager $pluginman, array $options = array()) {
1738 $plugininfo = $pluginman->get_plugins();
1740 // Filter the list of plugins according the options.
1741 if (!empty($options['updatesonly'])) {
1742 $updateable = array();
1743 foreach ($plugininfo as $plugintype => $pluginnames) {
1744 foreach ($pluginnames as $pluginname => $pluginfo) {
1745 $pluginavailableupdates = $pluginfo->available_updates();
1746 if (!empty($pluginavailableupdates)) {
1747 foreach ($pluginavailableupdates as $pluginavailableupdate) {
1748 $updateable[$plugintype][$pluginname] = $pluginfo;
1753 $plugininfo = $updateable;
1756 if (!empty($options['contribonly'])) {
1757 $contribs = array();
1758 foreach ($plugininfo as $plugintype => $pluginnames) {
1759 foreach ($pluginnames as $pluginname => $pluginfo) {
1760 if (!$pluginfo->is_standard()) {
1761 $contribs[$plugintype][$pluginname] = $pluginfo;
1765 $plugininfo = $contribs;
1768 if (empty($plugininfo)) {
1769 return '';
1772 $table = new html_table();
1773 $table->id = 'plugins-control-panel';
1774 $table->head = array(
1775 get_string('displayname', 'core_plugin'),
1776 get_string('version', 'core_plugin'),
1777 get_string('availability', 'core_plugin'),
1778 get_string('actions', 'core_plugin'),
1779 get_string('notes','core_plugin'),
1781 $table->headspan = array(1, 1, 1, 2, 1);
1782 $table->colclasses = array(
1783 'pluginname', 'version', 'availability', 'settings', 'uninstall', 'notes'
1786 foreach ($plugininfo as $type => $plugins) {
1787 $heading = $pluginman->plugintype_name_plural($type);
1788 $pluginclass = core_plugin_manager::resolve_plugininfo_class($type);
1789 if ($manageurl = $pluginclass::get_manage_url()) {
1790 $heading .= $this->output->action_icon($manageurl, new pix_icon('i/settings',
1791 get_string('settings', 'core_plugin')));
1793 $header = new html_table_cell(html_writer::tag('span', $heading, array('id'=>'plugin_type_cell_'.$type)));
1794 $header->header = true;
1795 $header->colspan = array_sum($table->headspan);
1796 $header = new html_table_row(array($header));
1797 $header->attributes['class'] = 'plugintypeheader type-' . $type;
1798 $table->data[] = $header;
1800 if (empty($plugins)) {
1801 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
1802 $msg->colspan = array_sum($table->headspan);
1803 $row = new html_table_row(array($msg));
1804 $row->attributes['class'] .= 'msg msg-noneinstalled';
1805 $table->data[] = $row;
1806 continue;
1809 foreach ($plugins as $name => $plugin) {
1810 $component = "{$plugin->type}_{$plugin->name}";
1812 $row = new html_table_row();
1813 $row->attributes['class'] = "type-{$plugin->type} name-{$component}";
1815 $iconidentifier = 'icon';
1816 if ($plugin->type === 'mod') {
1817 $iconidentifier = 'monologo';
1820 if ($this->page->theme->resolve_image_location($iconidentifier, $component, null)) {
1821 $icon = $this->output->pix_icon($iconidentifier, '', $component, [
1822 'class' => 'icon pluginicon',
1824 } else {
1825 $icon = $this->output->spacer();
1827 $status = $plugin->get_status();
1828 $row->attributes['class'] .= ' status-'.$status;
1829 $pluginname = html_writer::tag('div', $icon.$plugin->displayname, array('class' => 'displayname')).
1830 html_writer::tag('div', $plugin->component, array('class' => 'componentname'));
1831 $pluginname = new html_table_cell($pluginname);
1833 $version = html_writer::div($plugin->versiondb, 'versionnumber');
1834 if ((string)$plugin->release !== '') {
1835 $version = html_writer::div($plugin->release, 'release').$version;
1837 $version = new html_table_cell($version);
1839 $isenabled = $plugin->is_enabled();
1840 if (is_null($isenabled)) {
1841 $availability = new html_table_cell('');
1842 } else if ($isenabled) {
1843 $row->attributes['class'] .= ' enabled';
1844 $availability = new html_table_cell(get_string('pluginenabled', 'core_plugin'));
1845 } else {
1846 $row->attributes['class'] .= ' disabled';
1847 $availability = new html_table_cell(get_string('plugindisabled', 'core_plugin'));
1850 $settingsurl = $plugin->get_settings_url();
1851 if (!is_null($settingsurl)) {
1852 $settings = html_writer::link($settingsurl, get_string('settings', 'core_plugin'), array('class' => 'settings'));
1853 } else {
1854 $settings = '';
1856 $settings = new html_table_cell($settings);
1858 if ($uninstallurl = $pluginman->get_uninstall_url($plugin->component, 'overview')) {
1859 $uninstall = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin'));
1860 } else {
1861 $uninstall = '';
1863 $uninstall = new html_table_cell($uninstall);
1865 if ($plugin->is_standard()) {
1866 $row->attributes['class'] .= ' standard';
1867 $source = '';
1868 } else {
1869 $row->attributes['class'] .= ' extension';
1870 $source = html_writer::div(get_string('sourceext', 'core_plugin'), 'source badge badge-info');
1873 if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) {
1874 $msg = html_writer::div(get_string('status_missing', 'core_plugin'), 'statusmsg badge badge-danger');
1875 } else if ($status === core_plugin_manager::PLUGIN_STATUS_NEW) {
1876 $msg = html_writer::div(get_string('status_new', 'core_plugin'), 'statusmsg badge badge-success');
1877 } else {
1878 $msg = '';
1881 $requriedby = $pluginman->other_plugins_that_require($plugin->component);
1882 if ($requriedby) {
1883 $requiredby = html_writer::tag('div', get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
1884 array('class' => 'requiredby'));
1885 } else {
1886 $requiredby = '';
1889 $updateinfo = '';
1890 if (is_array($plugin->available_updates())) {
1891 foreach ($plugin->available_updates() as $availableupdate) {
1892 $updateinfo .= $this->plugin_available_update_info($pluginman, $availableupdate);
1896 $notes = new html_table_cell($source.$msg.$requiredby.$updateinfo);
1898 $row->cells = array(
1899 $pluginname, $version, $availability, $settings, $uninstall, $notes
1901 $table->data[] = $row;
1905 return html_writer::table($table);
1909 * Helper method to render the information about the available plugin update
1911 * @param core_plugin_manager $pluginman plugin manager instance
1912 * @param \core\update\info $updateinfo information about the available update for the plugin
1914 protected function plugin_available_update_info(core_plugin_manager $pluginman, \core\update\info $updateinfo) {
1916 $boxclasses = 'pluginupdateinfo';
1917 $info = array();
1919 if (isset($updateinfo->release)) {
1920 $info[] = html_writer::div(
1921 get_string('updateavailable_release', 'core_plugin', $updateinfo->release),
1922 'info release'
1926 if (isset($updateinfo->maturity)) {
1927 $info[] = html_writer::div(
1928 get_string('maturity'.$updateinfo->maturity, 'core_admin'),
1929 'info maturity'
1931 $boxclasses .= ' maturity'.$updateinfo->maturity;
1934 if (isset($updateinfo->download)) {
1935 $info[] = html_writer::div(
1936 html_writer::link($updateinfo->download, get_string('download')),
1937 'info download'
1941 if (isset($updateinfo->url)) {
1942 $info[] = html_writer::div(
1943 html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin')),
1944 'info more'
1948 $box = html_writer::start_div($boxclasses);
1949 $box .= html_writer::div(
1950 get_string('updateavailable', 'core_plugin', $updateinfo->version),
1951 'version'
1953 $box .= html_writer::div(
1954 implode(html_writer::span(' ', 'separator'), $info),
1955 'infos'
1958 if ($pluginman->is_remote_plugin_installable($updateinfo->component, $updateinfo->version, $reason, false)) {
1959 $box .= $this->output->single_button(
1960 new moodle_url($this->page->url, array('installupdate' => $updateinfo->component,
1961 'installupdateversion' => $updateinfo->version)),
1962 get_string('updateavailableinstall', 'core_admin'),
1963 'post',
1964 array('class' => 'singlebutton updateavailableinstall')
1966 } else {
1967 $reasonhelp = $this->info_remote_plugin_not_installable($reason);
1968 if ($reasonhelp) {
1969 $box .= html_writer::div($reasonhelp, 'reasonhelp updateavailableinstall');
1972 $box .= html_writer::end_div();
1974 return $box;
1978 * This function will render one beautiful table with all the environmental
1979 * configuration and how it suits Moodle needs.
1981 * @param boolean $result final result of the check (true/false)
1982 * @param environment_results[] $environment_results array of results gathered
1983 * @return string HTML to output.
1985 public function environment_check_table($result, $environment_results) {
1986 global $CFG;
1988 // Table headers
1989 $servertable = new html_table();//table for server checks
1990 $servertable->head = array(
1991 get_string('name'),
1992 get_string('info'),
1993 get_string('report'),
1994 get_string('plugin'),
1995 get_string('status'),
1997 $servertable->colclasses = array('centeralign name', 'centeralign info', 'leftalign report', 'leftalign plugin', 'centeralign status');
1998 $servertable->attributes['class'] = 'admintable environmenttable generaltable table-sm';
1999 $servertable->id = 'serverstatus';
2001 $serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
2003 $othertable = new html_table();//table for custom checks
2004 $othertable->head = array(
2005 get_string('info'),
2006 get_string('report'),
2007 get_string('plugin'),
2008 get_string('status'),
2010 $othertable->colclasses = array('aligncenter info', 'alignleft report', 'alignleft plugin', 'aligncenter status');
2011 $othertable->attributes['class'] = 'admintable environmenttable generaltable table-sm';
2012 $othertable->id = 'otherserverstatus';
2014 $otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
2016 // Iterate over each environment_result
2017 $continue = true;
2018 foreach ($environment_results as $environment_result) {
2019 $errorline = false;
2020 $warningline = false;
2021 $stringtouse = '';
2022 if ($continue) {
2023 $type = $environment_result->getPart();
2024 $info = $environment_result->getInfo();
2025 $status = $environment_result->getStatus();
2026 $plugin = $environment_result->getPluginName();
2027 $error_code = $environment_result->getErrorCode();
2028 // Process Report field
2029 $rec = new stdClass();
2030 // Something has gone wrong at parsing time
2031 if ($error_code) {
2032 $stringtouse = 'environmentxmlerror';
2033 $rec->error_code = $error_code;
2034 $status = get_string('error');
2035 $errorline = true;
2036 $continue = false;
2039 if ($continue) {
2040 if ($rec->needed = $environment_result->getNeededVersion()) {
2041 // We are comparing versions
2042 $rec->current = $environment_result->getCurrentVersion();
2043 if ($environment_result->getLevel() == 'required') {
2044 $stringtouse = 'environmentrequireversion';
2045 } else {
2046 $stringtouse = 'environmentrecommendversion';
2049 } else if ($environment_result->getPart() == 'custom_check') {
2050 // We are checking installed & enabled things
2051 if ($environment_result->getLevel() == 'required') {
2052 $stringtouse = 'environmentrequirecustomcheck';
2053 } else {
2054 $stringtouse = 'environmentrecommendcustomcheck';
2057 } else if ($environment_result->getPart() == 'php_setting') {
2058 if ($status) {
2059 $stringtouse = 'environmentsettingok';
2060 } else if ($environment_result->getLevel() == 'required') {
2061 $stringtouse = 'environmentmustfixsetting';
2062 } else {
2063 $stringtouse = 'environmentshouldfixsetting';
2066 } else {
2067 if ($environment_result->getLevel() == 'required') {
2068 $stringtouse = 'environmentrequireinstall';
2069 } else {
2070 $stringtouse = 'environmentrecommendinstall';
2074 // Calculate the status value
2075 if ($environment_result->getBypassStr() != '') { //Handle bypassed result (warning)
2076 $status = get_string('bypassed');
2077 $warningline = true;
2078 } else if ($environment_result->getRestrictStr() != '') { //Handle restricted result (error)
2079 $status = get_string('restricted');
2080 $errorline = true;
2081 } else {
2082 if ($status) { //Handle ok result (ok)
2083 $status = get_string('statusok');
2084 } else {
2085 if ($environment_result->getLevel() == 'optional') {//Handle check result (warning)
2086 $status = get_string('check');
2087 $warningline = true;
2088 } else { //Handle error result (error)
2089 $status = get_string('check');
2090 $errorline = true;
2096 // Build the text
2097 $linkparts = array();
2098 $linkparts[] = 'admin/environment';
2099 $linkparts[] = $type;
2100 if (!empty($info)){
2101 $linkparts[] = $info;
2103 // Plugin environments do not have docs pages yet.
2104 if (empty($CFG->docroot) or $environment_result->plugin) {
2105 $report = get_string($stringtouse, 'admin', $rec);
2106 } else {
2107 $report = $this->doc_link(join('/', $linkparts), get_string($stringtouse, 'admin', $rec), true);
2109 // Enclose report text in div so feedback text will be displayed underneath it.
2110 $report = html_writer::div($report);
2112 // Format error or warning line
2113 if ($errorline) {
2114 $messagetype = 'error';
2115 $statusclass = 'badge-danger';
2116 } else if ($warningline) {
2117 $messagetype = 'warn';
2118 $statusclass = 'badge-warning';
2119 } else {
2120 $messagetype = 'ok';
2121 $statusclass = 'badge-success';
2123 $status = html_writer::span($status, 'badge ' . $statusclass);
2124 // Here we'll store all the feedback found
2125 $feedbacktext = '';
2126 // Append the feedback if there is some
2127 $feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), $messagetype);
2128 //Append the bypass if there is some
2129 $feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'warn');
2130 //Append the restrict if there is some
2131 $feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'error');
2133 $report .= $feedbacktext;
2135 // Add the row to the table
2136 if ($environment_result->getPart() == 'custom_check'){
2137 $otherdata[$messagetype][] = array ($info, $report, $plugin, $status);
2138 } else {
2139 $serverdata[$messagetype][] = array ($type, $info, $report, $plugin, $status);
2144 //put errors first in
2145 $servertable->data = array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']);
2146 $othertable->data = array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']);
2148 // Print table
2149 $output = '';
2150 $output .= $this->heading(get_string('serverchecks', 'admin'));
2151 $output .= html_writer::table($servertable);
2152 if (count($othertable->data)){
2153 $output .= $this->heading(get_string('customcheck', 'admin'));
2154 $output .= html_writer::table($othertable);
2157 // Finally, if any error has happened, print the summary box
2158 if (!$result) {
2159 $output .= $this->box(get_string('environmenterrortodo', 'admin'), 'environmentbox errorbox');
2162 return $output;
2166 * Render a simple page for providing the upgrade key.
2168 * @param moodle_url|string $url
2169 * @return string
2171 public function upgradekey_form_page($url) {
2173 $output = '';
2174 $output .= $this->header();
2175 $output .= $this->container_start('upgradekeyreq');
2176 $output .= $this->heading(get_string('upgradekeyreq', 'core_admin'));
2177 $output .= html_writer::start_tag('form', array('method' => 'POST', 'action' => $url));
2178 $output .= html_writer::empty_tag('input', [
2179 'name' => 'upgradekey',
2180 'type' => 'password',
2181 'class' => 'form-control w-auto',
2183 $output .= html_writer::empty_tag('input', [
2184 'type' => 'submit',
2185 'value' => get_string('submit'),
2186 'class' => 'btn btn-primary mt-3',
2188 $output .= html_writer::end_tag('form');
2189 $output .= $this->container_end();
2190 $output .= $this->footer();
2192 return $output;
2196 * Check to see if writing to the deprecated legacy log store is enabled.
2198 * @return string An error message if writing to the legacy log store is enabled.
2200 protected function legacy_log_store_writing_error() {
2201 $enabled = get_config('logstore_legacy', 'loglegacy');
2202 $plugins = explode(',', get_config('tool_log', 'enabled_stores'));
2203 $enabled = $enabled && in_array('logstore_legacy', $plugins);
2205 if ($enabled) {
2206 return $this->warning(get_string('legacylogginginuse'));
2211 * Display message about the benefits of registering on Moodle.org
2213 * @return string
2215 public function moodleorg_registration_message() {
2217 $out = format_text(get_string('registerwithmoodleorginfo', 'core_hub'), FORMAT_MARKDOWN);
2219 $out .= html_writer::link(
2220 new moodle_url('/admin/settings.php', ['section' => 'moodleservices']),
2221 $this->output->pix_icon('i/info', '').' '.get_string('registerwithmoodleorginfoapp', 'core_hub'),
2222 ['class' => 'btn btn-link', 'role' => 'opener', 'target' => '_href']
2225 $out .= html_writer::link(
2226 HUB_MOODLEORGHUBURL,
2227 $this->output->pix_icon('i/stats', '').' '.get_string('registerwithmoodleorginfostats', 'core_hub'),
2228 ['class' => 'btn btn-link', 'role' => 'opener', 'target' => '_href']
2231 $out .= html_writer::link(
2232 HUB_MOODLEORGHUBURL.'/sites',
2233 $this->output->pix_icon('i/location', '').' '.get_string('registerwithmoodleorginfosites', 'core_hub'),
2234 ['class' => 'btn btn-link', 'role' => 'opener', 'target' => '_href']
2237 return $this->output->box($out);
2241 * Display message about benefits of enabling the user feedback feature.
2243 * @param bool $showfeedbackencouragement Whether the encouragement content should be displayed or not
2244 * @return string
2246 protected function userfeedback_encouragement(bool $showfeedbackencouragement): string {
2247 $output = '';
2249 if ($showfeedbackencouragement) {
2250 $settingslink = new moodle_url('/admin/settings.php', ['section' => 'userfeedback']);
2251 $output .= $this->warning(get_string('userfeedbackencouragement', 'admin', $settingslink->out()), 'info');
2254 return $output;
2258 * Display a warning about the deprecation of Mnet.
2260 * @param string $xmlrpcwarning The warning message
2261 * @return string HTML to output.
2263 protected function mnet_deprecation_warning($xmlrpcwarning) {
2264 if (empty($xmlrpcwarning)) {
2265 return '';
2268 return $this->warning($xmlrpcwarning);