Automatically generated installer lang files
[moodle.git] / admin / renderer.php
blob11fa0a16da53f0ccc7af23538486c99c1b39026b
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * Renderer for core_admin subsystem
20 * @package core
21 * @subpackage admin
22 * @copyright 2011 David Mudrak <david@moodle.com>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') || die();
29 /**
30 * Standard HTML output renderer for core_admin subsystem
32 class core_admin_renderer extends plugin_renderer_base {
34 /**
35 * Display the 'Do you acknowledge the terms of the GPL' page. The first page
36 * during install.
37 * @return string HTML to output.
39 public function install_licence_page() {
40 global $CFG;
41 $output = '';
43 $copyrightnotice = text_to_html(get_string('gpl3'));
44 $copyrightnotice = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $copyrightnotice); // extremely ugly validation hack
46 $continue = new single_button(new moodle_url($this->page->url, array(
47 'lang' => $CFG->lang, 'agreelicense' => 1)), get_string('continue'), 'get');
49 $output .= $this->header();
50 $output .= $this->heading('<a href="http://moodle.org">Moodle</a> - Modular Object-Oriented Dynamic Learning Environment');
51 $output .= $this->heading(get_string('copyrightnotice'));
52 $output .= $this->box($copyrightnotice, 'copyrightnotice');
53 $output .= html_writer::empty_tag('br');
54 $output .= $this->confirm(get_string('doyouagree'), $continue, "http://docs.moodle.org/dev/License");
55 $output .= $this->footer();
57 return $output;
60 /**
61 * Display page explaining proper upgrade process,
62 * there can not be any PHP file leftovers...
64 * @return string HTML to output.
66 public function upgrade_stale_php_files_page() {
67 $output = '';
68 $output .= $this->header();
69 $output .= $this->heading(get_string('upgradestalefiles', 'admin'));
70 $output .= $this->box_start('generalbox', 'notice');
71 $output .= format_text(get_string('upgradestalefilesinfo', 'admin', get_docs_url('Upgrading')), FORMAT_MARKDOWN);
72 $output .= html_writer::empty_tag('br');
73 $output .= html_writer::tag('div', $this->single_button($this->page->url, get_string('reload'), 'get'), array('class' => 'buttons'));
74 $output .= $this->box_end();
75 $output .= $this->footer();
77 return $output;
80 /**
81 * Display the 'environment check' page that is displayed during install.
82 * @param int $maturity
83 * @param boolean $envstatus final result of the check (true/false)
84 * @param array $environment_results array of results gathered
85 * @param string $release moodle release
86 * @return string HTML to output.
88 public function install_environment_page($maturity, $envstatus, $environment_results, $release) {
89 global $CFG;
90 $output = '';
92 $output .= $this->header();
93 $output .= $this->maturity_warning($maturity);
94 $output .= $this->heading("Moodle $release");
95 $output .= $this->release_notes_link();
97 $output .= $this->environment_check_table($envstatus, $environment_results);
99 if (!$envstatus) {
100 $output .= $this->upgrade_reload(new moodle_url($this->page->url, array('agreelicense' => 1, 'lang' => $CFG->lang)));
101 } else {
102 $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
103 $output .= $this->continue_button(new moodle_url($this->page->url, array(
104 'agreelicense' => 1, 'confirmrelease' => 1, 'lang' => $CFG->lang)));
107 $output .= $this->footer();
108 return $output;
112 * Displays the list of plugins with unsatisfied dependencies
114 * @param double|string|int $version Moodle on-disk version
115 * @param array $failed list of plugins with unsatisfied dependecies
116 * @param moodle_url $reloadurl URL of the page to recheck the dependencies
117 * @return string HTML
119 public function unsatisfied_dependencies_page($version, array $failed, moodle_url $reloadurl) {
120 $output = '';
122 $output .= $this->header();
123 $output .= $this->heading(get_string('pluginscheck', 'admin'));
124 $output .= $this->warning(get_string('pluginscheckfailed', 'admin', array('pluginslist' => implode(', ', array_unique($failed)))));
125 $output .= $this->plugins_check_table(core_plugin_manager::instance(), $version, array('xdep' => true));
126 $output .= $this->warning(get_string('pluginschecktodo', 'admin'));
127 $output .= $this->continue_button($reloadurl);
129 $output .= $this->footer();
131 return $output;
135 * Display the 'You are about to upgrade Moodle' page. The first page
136 * during upgrade.
137 * @param string $strnewversion
138 * @param int $maturity
139 * @param string $testsite
140 * @return string HTML to output.
142 public function upgrade_confirm_page($strnewversion, $maturity, $testsite) {
143 $output = '';
145 $continueurl = new moodle_url($this->page->url, array('confirmupgrade' => 1, 'cache' => 0));
146 $continue = new single_button($continueurl, get_string('continue'), 'get');
147 $cancelurl = new moodle_url('/admin/index.php');
149 $output .= $this->header();
150 $output .= $this->maturity_warning($maturity);
151 $output .= $this->test_site_warning($testsite);
152 $output .= $this->confirm(get_string('upgradesure', 'admin', $strnewversion), $continue, $cancelurl);
153 $output .= $this->footer();
155 return $output;
159 * Display the environment page during the upgrade process.
160 * @param string $release
161 * @param boolean $envstatus final result of env check (true/false)
162 * @param array $environment_results array of results gathered
163 * @return string HTML to output.
165 public function upgrade_environment_page($release, $envstatus, $environment_results) {
166 global $CFG;
167 $output = '';
169 $output .= $this->header();
170 $output .= $this->heading("Moodle $release");
171 $output .= $this->release_notes_link();
172 $output .= $this->environment_check_table($envstatus, $environment_results);
174 if (!$envstatus) {
175 $output .= $this->upgrade_reload(new moodle_url($this->page->url, array('confirmupgrade' => 1, 'cache' => 0)));
177 } else {
178 $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
180 if (empty($CFG->skiplangupgrade) and current_language() !== 'en') {
181 $output .= $this->box(get_string('langpackwillbeupdated', 'admin'), 'generalbox', 'notice');
184 $output .= $this->continue_button(new moodle_url($this->page->url, array(
185 'confirmupgrade' => 1, 'confirmrelease' => 1, 'cache' => 0)));
188 $output .= $this->footer();
190 return $output;
194 * Display the upgrade page that lists all the plugins that require attention.
195 * @param core_plugin_manager $pluginman provides information about the plugins.
196 * @param \core\update\checker $checker provides information about available updates.
197 * @param int $version the version of the Moodle code from version.php.
198 * @param bool $showallplugins
199 * @param moodle_url $reloadurl
200 * @param moodle_url $continueurl
201 * @return string HTML to output.
203 public function upgrade_plugin_check_page(core_plugin_manager $pluginman, \core\update\checker $checker,
204 $version, $showallplugins, $reloadurl, $continueurl) {
206 $output = '';
208 $output .= $this->header();
209 $output .= $this->box_start('generalbox', 'plugins-check-page');
210 $output .= html_writer::tag('p', get_string('pluginchecknotice', 'core_plugin'), array('class' => 'page-description'));
211 $output .= $this->check_for_updates_button($checker, $reloadurl);
212 $output .= $this->missing_dependencies($pluginman);
213 $output .= $this->plugins_check_table($pluginman, $version, array('full' => $showallplugins));
214 $output .= $this->box_end();
215 $output .= $this->upgrade_reload($reloadurl);
217 if ($pluginman->some_plugins_updatable()) {
218 $output .= $this->container_start('upgradepluginsinfo');
219 $output .= $this->help_icon('upgradepluginsinfo', 'core_admin', get_string('upgradepluginsfirst', 'core_admin'));
220 $output .= $this->container_end();
223 $button = new single_button($continueurl, get_string('upgradestart', 'admin'), 'get', true);
224 $button->class = 'continuebutton';
225 $output .= $this->render($button);
226 $output .= $this->footer();
228 return $output;
232 * Display a page to confirm plugin installation cancelation.
234 * @param array $abortable list of \core\update\plugininfo
235 * @param moodle_url $continue
236 * @return string
238 public function upgrade_confirm_abort_install_page(array $abortable, moodle_url $continue) {
240 $pluginman = core_plugin_manager::instance();
242 if (empty($abortable)) {
243 // The UI should not allow this.
244 throw new moodle_exception('err_no_plugin_install_abortable', 'core_plugin');
247 $out = $this->output->header();
248 $out .= $this->output->heading(get_string('cancelinstallhead', 'core_plugin'), 3);
249 $out .= $this->output->container(get_string('cancelinstallinfo', 'core_plugin'), 'cancelinstallinfo');
251 foreach ($abortable as $pluginfo) {
252 $out .= $this->output->heading($pluginfo->displayname.' ('.$pluginfo->component.')', 4);
253 $out .= $this->output->container(get_string('cancelinstallinfodir', 'core_plugin', $pluginfo->rootdir));
254 if ($repotype = $pluginman->plugin_external_source($pluginfo->component)) {
255 $out .= $this->output->container(get_string('uninstalldeleteconfirmexternal', 'core_plugin', $repotype),
256 'alert alert-warning mt-2');
260 $out .= $this->plugins_management_confirm_buttons($continue, $this->page->url);
261 $out .= $this->output->footer();
263 return $out;
267 * Display the admin notifications page.
268 * @param int $maturity
269 * @param bool $insecuredataroot warn dataroot is invalid
270 * @param bool $errorsdisplayed warn invalid dispaly error setting
271 * @param bool $cronoverdue warn cron not running
272 * @param bool $dbproblems warn db has problems
273 * @param bool $maintenancemode warn in maintenance mode
274 * @param bool $buggyiconvnomb warn iconv problems
275 * @param array|null $availableupdates array of \core\update\info objects or null
276 * @param int|null $availableupdatesfetch timestamp of the most recent updates fetch or null (unknown)
277 * @param string[] $cachewarnings An array containing warnings from the Cache API.
278 * @param array $eventshandlers Events 1 API handlers.
279 * @param bool $themedesignermode Warn about the theme designer mode.
280 * @param bool $devlibdir Warn about development libs directory presence.
281 * @param bool $mobileconfigured Whether the mobile web services have been enabled
282 * @param bool $overridetossl Whether or not ssl is being forced.
283 * @param bool $invalidforgottenpasswordurl Whether the forgotten password URL does not link to a valid URL.
284 * @param bool $croninfrequent If true, warn that cron hasn't run in the past few minutes
285 * @param bool $showcampaigncontent Whether the campaign content should be visible or not.
286 * @param bool $showfeedbackencouragement Whether the feedback encouragement content should be displayed or not.
287 * @param bool $showservicesandsupport Whether the services and support content should be displayed or not.
288 * @param string $xmlrpcwarning XML-RPC deprecation warning message.
290 * @return string HTML to output.
292 public function admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed,
293 $cronoverdue, $dbproblems, $maintenancemode, $availableupdates, $availableupdatesfetch,
294 $buggyiconvnomb, $registered, array $cachewarnings = array(), $eventshandlers = 0,
295 $themedesignermode = false, $devlibdir = false, $mobileconfigured = false,
296 $overridetossl = false, $invalidforgottenpasswordurl = false, $croninfrequent = false,
297 $showcampaigncontent = false, bool $showfeedbackencouragement = false, bool $showservicesandsupport = false,
298 $xmlrpcwarning = '') {
300 global $CFG;
301 $output = '';
303 $output .= $this->header();
304 $output .= $this->maturity_info($maturity);
305 $output .= $this->legacy_log_store_writing_error();
306 $output .= empty($CFG->disableupdatenotifications) ? $this->available_updates($availableupdates, $availableupdatesfetch) : '';
307 $output .= $this->insecure_dataroot_warning($insecuredataroot);
308 $output .= $this->development_libs_directories_warning($devlibdir);
309 $output .= $this->themedesignermode_warning($themedesignermode);
310 $output .= $this->display_errors_warning($errorsdisplayed);
311 $output .= $this->buggy_iconv_warning($buggyiconvnomb);
312 $output .= $this->cron_overdue_warning($cronoverdue);
313 $output .= $this->cron_infrequent_warning($croninfrequent);
314 $output .= $this->db_problems($dbproblems);
315 $output .= $this->maintenance_mode_warning($maintenancemode);
316 $output .= $this->overridetossl_warning($overridetossl);
317 $output .= $this->cache_warnings($cachewarnings);
318 $output .= $this->events_handlers($eventshandlers);
319 $output .= $this->registration_warning($registered);
320 $output .= $this->mobile_configuration_warning($mobileconfigured);
321 $output .= $this->forgotten_password_url_warning($invalidforgottenpasswordurl);
322 $output .= $this->mnet_deprecation_warning($xmlrpcwarning);
323 $output .= $this->userfeedback_encouragement($showfeedbackencouragement);
324 $output .= $this->services_and_support_content($showservicesandsupport);
325 $output .= $this->campaign_content($showcampaigncontent);
327 //////////////////////////////////////////////////////////////////////////////////////////////////
328 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
329 $output .= $this->moodle_copyright();
330 //////////////////////////////////////////////////////////////////////////////////////////////////
332 $output .= $this->footer();
334 return $output;
338 * Display the plugin management page (admin/plugins.php).
340 * The filtering options array may contain following items:
341 * bool contribonly - show only contributed extensions
342 * bool updatesonly - show only plugins with an available update
344 * @param core_plugin_manager $pluginman
345 * @param \core\update\checker $checker
346 * @param array $options filtering options
347 * @return string HTML to output.
349 public function plugin_management_page(core_plugin_manager $pluginman, \core\update\checker $checker, array $options = array()) {
351 $output = '';
353 $output .= $this->header();
354 $output .= $this->heading(get_string('pluginsoverview', 'core_admin'));
355 $output .= $this->check_for_updates_button($checker, $this->page->url);
356 $output .= $this->plugins_overview_panel($pluginman, $options);
357 $output .= $this->plugins_control_panel($pluginman, $options);
358 $output .= $this->footer();
360 return $output;
364 * Renders a button to fetch for available updates.
366 * @param \core\update\checker $checker
367 * @param moodle_url $reloadurl
368 * @return string HTML
370 public function check_for_updates_button(\core\update\checker $checker, $reloadurl) {
372 $output = '';
374 if ($checker->enabled()) {
375 $output .= $this->container_start('checkforupdates mb-4');
376 $output .= $this->single_button(
377 new moodle_url($reloadurl, array('fetchupdates' => 1)),
378 get_string('checkforupdates', 'core_plugin')
380 if ($timefetched = $checker->get_last_timefetched()) {
381 $timefetched = userdate($timefetched, get_string('strftimedatetime', 'core_langconfig'));
382 $output .= $this->container(get_string('checkforupdateslast', 'core_plugin', $timefetched),
383 'lasttimefetched small text-muted mt-1');
385 $output .= $this->container_end();
388 return $output;
392 * Display a page to confirm the plugin uninstallation.
394 * @param core_plugin_manager $pluginman
395 * @param \core\plugininfo\base $pluginfo
396 * @param moodle_url $continueurl URL to continue after confirmation
397 * @param moodle_url $cancelurl URL to to go if cancelled
398 * @return string
400 public function plugin_uninstall_confirm_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, moodle_url $continueurl, moodle_url $cancelurl) {
401 $output = '';
403 $pluginname = $pluginman->plugin_name($pluginfo->component);
405 $confirm = '<p>' . get_string('uninstallconfirm', 'core_plugin', array('name' => $pluginname)) . '</p>';
406 if ($extraconfirm = $pluginfo->get_uninstall_extra_warning()) {
407 $confirm .= $extraconfirm;
410 $output .= $this->output->header();
411 $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
412 $output .= $this->output->confirm($confirm, $continueurl, $cancelurl);
413 $output .= $this->output->footer();
415 return $output;
419 * Display a page with results of plugin uninstallation and offer removal of plugin files.
421 * @param core_plugin_manager $pluginman
422 * @param \core\plugininfo\base $pluginfo
423 * @param progress_trace_buffer $progress
424 * @param moodle_url $continueurl URL to continue to remove the plugin folder
425 * @return string
427 public function plugin_uninstall_results_removable_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo,
428 progress_trace_buffer $progress, moodle_url $continueurl) {
429 $output = '';
431 $pluginname = $pluginman->plugin_name($pluginfo->component);
433 // Do not show navigation here, they must click one of the buttons.
434 $this->page->set_pagelayout('maintenance');
435 $this->page->set_cacheable(false);
437 $output .= $this->output->header();
438 $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
440 $output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
442 $confirm = $this->output->container(get_string('uninstalldeleteconfirm', 'core_plugin',
443 array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'uninstalldeleteconfirm');
445 if ($repotype = $pluginman->plugin_external_source($pluginfo->component)) {
446 $confirm .= $this->output->container(get_string('uninstalldeleteconfirmexternal', 'core_plugin', $repotype),
447 'alert alert-warning mt-2');
450 // After any uninstall we must execute full upgrade to finish the cleanup!
451 $output .= $this->output->confirm($confirm, $continueurl, new moodle_url('/admin/index.php'));
452 $output .= $this->output->footer();
454 return $output;
458 * Display a page with results of plugin uninstallation and inform about the need to remove plugin files manually.
460 * @param core_plugin_manager $pluginman
461 * @param \core\plugininfo\base $pluginfo
462 * @param progress_trace_buffer $progress
463 * @return string
465 public function plugin_uninstall_results_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, progress_trace_buffer $progress) {
466 $output = '';
468 $pluginname = $pluginfo->component;
470 $output .= $this->output->header();
471 $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
473 $output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
475 $output .= $this->output->box(get_string('uninstalldelete', 'core_plugin',
476 array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'generalbox uninstalldelete');
477 $output .= $this->output->continue_button(new moodle_url('/admin/index.php'));
478 $output .= $this->output->footer();
480 return $output;
484 * Display the plugin management page (admin/environment.php).
485 * @param array $versions
486 * @param string $version
487 * @param boolean $envstatus final result of env check (true/false)
488 * @param array $environment_results array of results gathered
489 * @return string HTML to output.
491 public function environment_check_page($versions, $version, $envstatus, $environment_results) {
492 $output = '';
493 $output .= $this->header();
495 // Print the component download link
496 $output .= html_writer::tag('div', html_writer::link(
497 new moodle_url('/admin/environment.php', array('action' => 'updatecomponent', 'sesskey' => sesskey())),
498 get_string('updatecomponent', 'admin')),
499 array('class' => 'reportlink'));
501 // Heading.
502 $output .= $this->heading(get_string('environment', 'admin'));
504 // Box with info and a menu to choose the version.
505 $output .= $this->box_start();
506 $output .= html_writer::tag('div', get_string('adminhelpenvironment'));
507 $select = new single_select(new moodle_url('/admin/environment.php'), 'version', $versions, $version, null);
508 $select->label = get_string('moodleversion');
509 $output .= $this->render($select);
510 $output .= $this->box_end();
512 // The results
513 $output .= $this->environment_check_table($envstatus, $environment_results);
515 $output .= $this->footer();
516 return $output;
520 * Output a warning message, of the type that appears on the admin notifications page.
521 * @param string $message the message to display.
522 * @param string $type type class
523 * @return string HTML to output.
525 protected function warning($message, $type = 'warning') {
526 return $this->box($message, 'generalbox alert alert-' . $type);
530 * Render an appropriate message if dataroot is insecure.
531 * @param bool $insecuredataroot
532 * @return string HTML to output.
534 protected function insecure_dataroot_warning($insecuredataroot) {
535 global $CFG;
537 if ($insecuredataroot == INSECURE_DATAROOT_WARNING) {
538 return $this->warning(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot));
540 } else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) {
541 return $this->warning(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'danger');
543 } else {
544 return '';
549 * Render a warning that a directory with development libs is present.
551 * @param bool $devlibdir True if the warning should be displayed.
552 * @return string
554 protected function development_libs_directories_warning($devlibdir) {
556 if ($devlibdir) {
557 $moreinfo = new moodle_url('/report/security/index.php');
558 $warning = get_string('devlibdirpresent', 'core_admin', ['moreinfourl' => $moreinfo->out()]);
559 return $this->warning($warning, 'danger');
561 } else {
562 return '';
567 * Render an appropriate message if dataroot is insecure.
568 * @param bool $errorsdisplayed
569 * @return string HTML to output.
571 protected function display_errors_warning($errorsdisplayed) {
572 if (!$errorsdisplayed) {
573 return '';
576 return $this->warning(get_string('displayerrorswarning', 'admin'));
580 * Render an appropriate message if themdesignermode is enabled.
581 * @param bool $themedesignermode true if enabled
582 * @return string HTML to output.
584 protected function themedesignermode_warning($themedesignermode) {
585 if (!$themedesignermode) {
586 return '';
589 return $this->warning(get_string('themedesignermodewarning', 'admin'));
593 * Render an appropriate message if iconv is buggy and mbstring missing.
594 * @param bool $buggyiconvnomb
595 * @return string HTML to output.
597 protected function buggy_iconv_warning($buggyiconvnomb) {
598 if (!$buggyiconvnomb) {
599 return '';
602 return $this->warning(get_string('warningiconvbuggy', 'admin'));
606 * Render an appropriate message if cron has not been run recently.
607 * @param bool $cronoverdue
608 * @return string HTML to output.
610 public function cron_overdue_warning($cronoverdue) {
611 global $CFG;
612 if (!$cronoverdue) {
613 return '';
616 $check = new \tool_task\check\cronrunning();
617 $result = $check->get_result();
618 return $this->warning($result->get_summary() . '&nbsp;' . $this->help_icon('cron', 'admin'));
622 * Render an appropriate message if cron is not being run frequently (recommended every minute).
624 * @param bool $croninfrequent
625 * @return string HTML to output.
627 public function cron_infrequent_warning(bool $croninfrequent) : string {
628 global $CFG;
630 if (!$croninfrequent) {
631 return '';
634 $check = new \tool_task\check\cronrunning();
635 $result = $check->get_result();
636 return $this->warning($result->get_summary() . '&nbsp;' . $this->help_icon('cron', 'admin'));
640 * Render an appropriate message if there are any problems with the DB set-up.
641 * @param bool $dbproblems
642 * @return string HTML to output.
644 public function db_problems($dbproblems) {
645 if (!$dbproblems) {
646 return '';
649 return $this->warning($dbproblems);
653 * Renders cache warnings if there are any.
655 * @param string[] $cachewarnings
656 * @return string
658 public function cache_warnings(array $cachewarnings) {
659 if (!count($cachewarnings)) {
660 return '';
662 return join("\n", array_map(array($this, 'warning'), $cachewarnings));
666 * Renders events 1 API handlers warning.
668 * @param array $eventshandlers
669 * @return string
671 public function events_handlers($eventshandlers) {
672 if ($eventshandlers) {
673 $components = '';
674 foreach ($eventshandlers as $eventhandler) {
675 $components .= $eventhandler->component . ', ';
677 $components = rtrim($components, ', ');
678 return $this->warning(get_string('eventshandlersinuse', 'admin', $components));
683 * Render an appropriate message if the site in in maintenance mode.
684 * @param bool $maintenancemode
685 * @return string HTML to output.
687 public function maintenance_mode_warning($maintenancemode) {
688 if (!$maintenancemode) {
689 return '';
692 $url = new moodle_url('/admin/settings.php', array('section' => 'maintenancemode'));
693 $url = $url->out(); // get_string() does not support objects in params
695 return $this->warning(get_string('sitemaintenancewarning2', 'admin', $url));
699 * Render a warning that ssl is forced because the site was on loginhttps.
701 * @param bool $overridetossl Whether or not ssl is being forced.
702 * @return string
704 protected function overridetossl_warning($overridetossl) {
705 if (!$overridetossl) {
706 return '';
708 $warning = get_string('overridetossl', 'core_admin');
709 return $this->warning($warning, 'warning');
713 * Display a warning about installing development code if necesary.
714 * @param int $maturity
715 * @return string HTML to output.
717 protected function maturity_warning($maturity) {
718 if ($maturity == MATURITY_STABLE) {
719 return ''; // No worries.
722 $maturitylevel = get_string('maturity' . $maturity, 'admin');
723 return $this->warning(
724 $this->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
725 $this->container($this->doc_link('admin/versions', get_string('morehelp'))),
726 'danger');
730 * If necessary, displays a warning about upgrading a test site.
732 * @param string $testsite
733 * @return string HTML
735 protected function test_site_warning($testsite) {
737 if (!$testsite) {
738 return '';
741 $warning = (get_string('testsiteupgradewarning', 'admin', $testsite));
742 return $this->warning($warning, 'danger');
746 * Output the copyright notice.
747 * @return string HTML to output.
749 protected function moodle_copyright() {
750 global $CFG;
752 //////////////////////////////////////////////////////////////////////////////////////////////////
753 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
754 $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
755 '<a href="http://docs.moodle.org/dev/Releases" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
756 'Copyright &copy; 1999 onwards, Martin Dougiamas<br />'.
757 'and <a href="http://moodle.org/dev">many other contributors</a>.<br />'.
758 '<a href="http://docs.moodle.org/dev/License">GNU Public License</a>';
759 //////////////////////////////////////////////////////////////////////////////////////////////////
761 return $this->box($copyrighttext, 'copyright');
765 * Display a warning about installing development code if necesary.
766 * @param int $maturity
767 * @return string HTML to output.
769 protected function maturity_info($maturity) {
770 if ($maturity == MATURITY_STABLE) {
771 return ''; // No worries.
774 $level = 'warning';
776 if ($maturity == MATURITY_ALPHA) {
777 $level = 'danger';
780 $maturitylevel = get_string('maturity' . $maturity, 'admin');
781 $warningtext = get_string('maturitycoreinfo', 'admin', $maturitylevel);
782 $warningtext .= ' ' . $this->doc_link('admin/versions', get_string('morehelp'));
783 return $this->warning($warningtext, $level);
787 * Displays the info about available Moodle core and plugin updates
789 * The structure of the $updates param has changed since 2.4. It contains not only updates
790 * for the core itself, but also for all other installed plugins.
792 * @param array|null $updates array of (string)component => array of \core\update\info objects or null
793 * @param int|null $fetch timestamp of the most recent updates fetch or null (unknown)
794 * @return string
796 protected function available_updates($updates, $fetch) {
798 $updateinfo = '';
799 $someupdateavailable = false;
800 if (is_array($updates)) {
801 if (is_array($updates['core'])) {
802 $someupdateavailable = true;
803 $updateinfo .= $this->heading(get_string('updateavailable', 'core_admin'), 3);
804 foreach ($updates['core'] as $update) {
805 $updateinfo .= $this->moodle_available_update_info($update);
807 $updateinfo .= html_writer::tag('p', get_string('updateavailablerecommendation', 'core_admin'),
808 array('class' => 'updateavailablerecommendation'));
810 unset($updates['core']);
811 // If something has left in the $updates array now, it is updates for plugins.
812 if (!empty($updates)) {
813 $someupdateavailable = true;
814 $updateinfo .= $this->heading(get_string('updateavailableforplugin', 'core_admin'), 3);
815 $pluginsoverviewurl = new moodle_url('/admin/plugins.php', array('updatesonly' => 1));
816 $updateinfo .= $this->container(get_string('pluginsoverviewsee', 'core_admin',
817 array('url' => $pluginsoverviewurl->out())));
821 if (!$someupdateavailable) {
822 $now = time();
823 if ($fetch and ($fetch <= $now) and ($now - $fetch < HOURSECS)) {
824 $updateinfo .= $this->heading(get_string('updateavailablenot', 'core_admin'), 3);
828 $updateinfo .= $this->container_start('checkforupdates mt-1');
829 $fetchurl = new moodle_url('/admin/index.php', array('fetchupdates' => 1, 'sesskey' => sesskey(), 'cache' => 0));
830 $updateinfo .= $this->single_button($fetchurl, get_string('checkforupdates', 'core_plugin'));
831 if ($fetch) {
832 $updateinfo .= $this->container(get_string('checkforupdateslast', 'core_plugin',
833 userdate($fetch, get_string('strftimedatetime', 'core_langconfig'))));
835 $updateinfo .= $this->container_end();
837 return $this->warning($updateinfo);
841 * Display a warning about not being registered on Moodle.org if necesary.
843 * @param boolean $registered true if the site is registered on Moodle.org
844 * @return string HTML to output.
846 protected function registration_warning($registered) {
848 if (!$registered && site_is_public()) {
849 if (has_capability('moodle/site:config', context_system::instance())) {
850 $registerbutton = $this->single_button(new moodle_url('/admin/registration/index.php'),
851 get_string('register', 'admin'));
852 $str = 'registrationwarning';
853 } else {
854 $registerbutton = '';
855 $str = 'registrationwarningcontactadmin';
858 return $this->warning( get_string($str, 'admin')
859 . '&nbsp;' . $this->help_icon('registration', 'admin') . $registerbutton ,
860 'error alert alert-danger');
863 return '';
867 * Return an admin page warning if site is not registered with moodle.org
869 * @return string
871 public function warn_if_not_registered() {
872 return $this->registration_warning(\core\hub\registration::is_registered());
876 * Display a warning about the Mobile Web Services being disabled.
878 * @param boolean $mobileconfigured true if mobile web services are enabled
879 * @return string HTML to output.
881 protected function mobile_configuration_warning($mobileconfigured) {
882 $output = '';
883 if (!$mobileconfigured) {
884 $settingslink = new moodle_url('/admin/settings.php', ['section' => 'mobilesettings']);
885 $configurebutton = $this->single_button($settingslink, get_string('enablemobilewebservice', 'admin'));
886 $output .= $this->warning(get_string('mobilenotconfiguredwarning', 'admin') . '&nbsp;' . $configurebutton);
889 return $output;
893 * Display campaign content.
895 * @param bool $showcampaigncontent Whether the campaign content should be visible or not.
896 * @return string the campaign content raw html.
898 protected function campaign_content(bool $showcampaigncontent): string {
899 if (!$showcampaigncontent) {
900 return '';
903 $lang = current_language();
904 $url = "https://campaign.moodle.org/current/lms/{$lang}/install/";
905 $params = [
906 'url' => $url,
907 'iframeid' => 'campaign-content'
910 return $this->render_from_template('core/external_content_banner', $params);
914 * Display services and support content.
916 * @param bool $showservicesandsupport Whether the services and support content should be visible or not.
917 * @return string the campaign content raw html.
919 protected function services_and_support_content(bool $showservicesandsupport): string {
920 if (!$showservicesandsupport) {
921 return '';
924 $lang = current_language();
925 $url = "https://campaign.moodle.org/current/lms/{$lang}/servicesandsupport/";
926 $params = [
927 'url' => $url,
928 'iframeid' => 'services-support-content'
931 return $this->render_from_template('core/external_content_banner', $params);
935 * Display a warning about the forgotten password URL not linking to a valid URL.
937 * @param boolean $invalidforgottenpasswordurl true if the forgotten password URL is not valid
938 * @return string HTML to output.
940 protected function forgotten_password_url_warning($invalidforgottenpasswordurl) {
941 $output = '';
942 if ($invalidforgottenpasswordurl) {
943 $settingslink = new moodle_url('/admin/settings.php', ['section' => 'manageauths']);
944 $configurebutton = $this->single_button($settingslink, get_string('check', 'moodle'));
945 $output .= $this->warning(get_string('invalidforgottenpasswordurl', 'admin') . '&nbsp;' . $configurebutton,
946 'error alert alert-danger');
949 return $output;
953 * Helper method to render the information about the available Moodle update
955 * @param \core\update\info $updateinfo information about the available Moodle core update
957 protected function moodle_available_update_info(\core\update\info $updateinfo) {
959 $boxclasses = 'moodleupdateinfo mb-2';
960 $info = array();
962 if (isset($updateinfo->release)) {
963 $info[] = html_writer::tag('span', get_string('updateavailable_release', 'core_admin', $updateinfo->release),
964 array('class' => 'info release'));
967 if (isset($updateinfo->version)) {
968 $info[] = html_writer::tag('span', get_string('updateavailable_version', 'core_admin', $updateinfo->version),
969 array('class' => 'info version'));
972 if (isset($updateinfo->maturity)) {
973 $info[] = html_writer::tag('span', get_string('maturity'.$updateinfo->maturity, 'core_admin'),
974 array('class' => 'info maturity'));
975 $boxclasses .= ' maturity'.$updateinfo->maturity;
978 if (isset($updateinfo->download)) {
979 $info[] = html_writer::link($updateinfo->download, get_string('download'),
980 array('class' => 'info download btn btn-secondary'));
983 if (isset($updateinfo->url)) {
984 $info[] = html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin'),
985 array('class' => 'info more'));
988 $box = $this->output->container_start($boxclasses);
989 $box .= $this->output->container(implode(html_writer::tag('span', ' | ', array('class' => 'separator')), $info), '');
990 $box .= $this->output->container_end();
992 return $box;
996 * Display a link to the release notes.
997 * @return string HTML to output.
999 protected function release_notes_link() {
1000 $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/dev/Releases');
1001 $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
1002 return $this->box($releasenoteslink, 'generalbox alert alert-info');
1006 * Display the reload link that appears on several upgrade/install pages.
1007 * @return string HTML to output.
1009 function upgrade_reload($url) {
1010 return html_writer::empty_tag('br') .
1011 html_writer::tag('div',
1012 html_writer::link($url, $this->pix_icon('i/reload', '', '', array('class' => 'icon icon-pre')) .
1013 get_string('reload'), array('title' => get_string('reload'))),
1014 array('class' => 'continuebutton')) . html_writer::empty_tag('br');
1018 * Displays all known plugins and information about their installation or upgrade
1020 * This default implementation renders all plugins into one big table. The rendering
1021 * options support:
1022 * (bool)full = false: whether to display up-to-date plugins, too
1023 * (bool)xdep = false: display the plugins with unsatisified dependecies only
1025 * @param core_plugin_manager $pluginman provides information about the plugins.
1026 * @param int $version the version of the Moodle code from version.php.
1027 * @param array $options rendering options
1028 * @return string HTML code
1030 public function plugins_check_table(core_plugin_manager $pluginman, $version, array $options = array()) {
1031 global $CFG;
1032 $plugininfo = $pluginman->get_plugins();
1034 if (empty($plugininfo)) {
1035 return '';
1038 $options['full'] = isset($options['full']) ? (bool)$options['full'] : false;
1039 $options['xdep'] = isset($options['xdep']) ? (bool)$options['xdep'] : false;
1041 $table = new html_table();
1042 $table->id = 'plugins-check';
1043 $table->head = array(
1044 get_string('displayname', 'core_plugin').' / '.get_string('rootdir', 'core_plugin'),
1045 get_string('versiondb', 'core_plugin'),
1046 get_string('versiondisk', 'core_plugin'),
1047 get_string('requires', 'core_plugin'),
1048 get_string('source', 'core_plugin').' / '.get_string('status', 'core_plugin'),
1050 $table->colclasses = array(
1051 'displayname', 'versiondb', 'versiondisk', 'requires', 'status',
1053 $table->data = array();
1055 // Number of displayed plugins per type.
1056 $numdisplayed = array();
1057 // Number of plugins known to the plugin manager.
1058 $sumtotal = 0;
1059 // Number of plugins requiring attention.
1060 $sumattention = 0;
1061 // List of all components we can cancel installation of.
1062 $installabortable = $pluginman->list_cancellable_installations();
1063 // List of all components we can cancel upgrade of.
1064 $upgradeabortable = $pluginman->list_restorable_archives();
1066 foreach ($plugininfo as $type => $plugins) {
1068 $header = new html_table_cell($pluginman->plugintype_name_plural($type));
1069 $header->header = true;
1070 $header->colspan = count($table->head);
1071 $header = new html_table_row(array($header));
1072 $header->attributes['class'] = 'plugintypeheader type-' . $type;
1074 $numdisplayed[$type] = 0;
1076 if (empty($plugins) and $options['full']) {
1077 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
1078 $msg->colspan = count($table->head);
1079 $row = new html_table_row(array($msg));
1080 $row->attributes['class'] .= 'msg msg-noneinstalled';
1081 $table->data[] = $header;
1082 $table->data[] = $row;
1083 continue;
1086 $plugintyperows = array();
1088 foreach ($plugins as $name => $plugin) {
1089 $sumtotal++;
1090 $row = new html_table_row();
1091 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
1093 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name, null)) {
1094 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
1095 } else {
1096 $icon = '';
1099 $displayname = new html_table_cell(
1100 $icon.
1101 html_writer::span($plugin->displayname, 'pluginname').
1102 html_writer::div($plugin->get_dir(), 'plugindir text-muted small')
1105 $versiondb = new html_table_cell($plugin->versiondb);
1106 $versiondisk = new html_table_cell($plugin->versiondisk);
1108 if ($isstandard = $plugin->is_standard()) {
1109 $row->attributes['class'] .= ' standard';
1110 $sourcelabel = html_writer::span(get_string('sourcestd', 'core_plugin'), 'sourcetext badge badge-secondary');
1111 } else {
1112 $row->attributes['class'] .= ' extension';
1113 $sourcelabel = html_writer::span(get_string('sourceext', 'core_plugin'), 'sourcetext badge badge-info');
1116 $coredependency = $plugin->is_core_dependency_satisfied($version);
1117 $incompatibledependency = $plugin->is_core_compatible_satisfied($CFG->branch);
1119 $otherpluginsdependencies = $pluginman->are_dependencies_satisfied($plugin->get_other_required_plugins());
1120 $dependenciesok = $coredependency && $otherpluginsdependencies && $incompatibledependency;
1122 $statuscode = $plugin->get_status();
1123 $row->attributes['class'] .= ' status-' . $statuscode;
1124 $statusclass = 'statustext badge ';
1125 switch ($statuscode) {
1126 case core_plugin_manager::PLUGIN_STATUS_NEW:
1127 $statusclass .= $dependenciesok ? 'badge-success' : 'badge-warning';
1128 break;
1129 case core_plugin_manager::PLUGIN_STATUS_UPGRADE:
1130 $statusclass .= $dependenciesok ? 'badge-info' : 'badge-warning';
1131 break;
1132 case core_plugin_manager::PLUGIN_STATUS_MISSING:
1133 case core_plugin_manager::PLUGIN_STATUS_DOWNGRADE:
1134 case core_plugin_manager::PLUGIN_STATUS_DELETE:
1135 $statusclass .= 'badge-danger';
1136 break;
1137 case core_plugin_manager::PLUGIN_STATUS_NODB:
1138 case core_plugin_manager::PLUGIN_STATUS_UPTODATE:
1139 $statusclass .= $dependenciesok ? 'badge-light' : 'badge-warning';
1140 break;
1142 $status = html_writer::span(get_string('status_' . $statuscode, 'core_plugin'), $statusclass);
1144 if (!empty($installabortable[$plugin->component])) {
1145 $status .= $this->output->single_button(
1146 new moodle_url($this->page->url, array('abortinstall' => $plugin->component, 'confirmplugincheck' => 0)),
1147 get_string('cancelinstallone', 'core_plugin'),
1148 'post',
1149 array('class' => 'actionbutton cancelinstallone d-block mt-1')
1153 if (!empty($upgradeabortable[$plugin->component])) {
1154 $status .= $this->output->single_button(
1155 new moodle_url($this->page->url, array('abortupgrade' => $plugin->component)),
1156 get_string('cancelupgradeone', 'core_plugin'),
1157 'post',
1158 array('class' => 'actionbutton cancelupgradeone d-block mt-1')
1162 $availableupdates = $plugin->available_updates();
1163 if (!empty($availableupdates)) {
1164 foreach ($availableupdates as $availableupdate) {
1165 $status .= $this->plugin_available_update_info($pluginman, $availableupdate);
1169 $status = new html_table_cell($sourcelabel.' '.$status);
1170 if ($plugin->pluginsupported != null) {
1171 $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version, $CFG->branch));
1172 } else {
1173 $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version));
1176 $statusisboring = in_array($statuscode, array(
1177 core_plugin_manager::PLUGIN_STATUS_NODB, core_plugin_manager::PLUGIN_STATUS_UPTODATE));
1179 if ($options['xdep']) {
1180 // we want to see only plugins with failed dependencies
1181 if ($dependenciesok) {
1182 continue;
1185 } else if ($statusisboring and $dependenciesok and empty($availableupdates)) {
1186 // no change is going to happen to the plugin - display it only
1187 // if the user wants to see the full list
1188 if (empty($options['full'])) {
1189 continue;
1192 } else {
1193 $sumattention++;
1196 // The plugin should be displayed.
1197 $numdisplayed[$type]++;
1198 $row->cells = array($displayname, $versiondb, $versiondisk, $requires, $status);
1199 $plugintyperows[] = $row;
1202 if (empty($numdisplayed[$type]) and empty($options['full'])) {
1203 continue;
1206 $table->data[] = $header;
1207 $table->data = array_merge($table->data, $plugintyperows);
1210 // Total number of displayed plugins.
1211 $sumdisplayed = array_sum($numdisplayed);
1213 if ($options['xdep']) {
1214 // At the plugins dependencies check page, display the table only.
1215 return html_writer::table($table);
1218 $out = $this->output->container_start('', 'plugins-check-info');
1220 if ($sumdisplayed == 0) {
1221 $out .= $this->output->heading(get_string('pluginchecknone', 'core_plugin'));
1223 } else {
1224 if (empty($options['full'])) {
1225 $out .= $this->output->heading(get_string('plugincheckattention', 'core_plugin'));
1226 } else {
1227 $out .= $this->output->heading(get_string('plugincheckall', 'core_plugin'));
1231 $out .= $this->output->container_start('actions mb-2');
1233 $installableupdates = $pluginman->filter_installable($pluginman->available_updates());
1234 if ($installableupdates) {
1235 $out .= $this->output->single_button(
1236 new moodle_url($this->page->url, array('installupdatex' => 1)),
1237 get_string('updateavailableinstallall', 'core_admin', count($installableupdates)),
1238 'post',
1239 array('class' => 'singlebutton updateavailableinstallall mr-1')
1243 if ($installabortable) {
1244 $out .= $this->output->single_button(
1245 new moodle_url($this->page->url, array('abortinstallx' => 1, 'confirmplugincheck' => 0)),
1246 get_string('cancelinstallall', 'core_plugin', count($installabortable)),
1247 'post',
1248 array('class' => 'singlebutton cancelinstallall mr-1')
1252 if ($upgradeabortable) {
1253 $out .= $this->output->single_button(
1254 new moodle_url($this->page->url, array('abortupgradex' => 1)),
1255 get_string('cancelupgradeall', 'core_plugin', count($upgradeabortable)),
1256 'post',
1257 array('class' => 'singlebutton cancelupgradeall mr-1')
1261 $out .= html_writer::div(html_writer::link(new moodle_url($this->page->url, array('showallplugins' => 0)),
1262 get_string('plugincheckattention', 'core_plugin')).' '.html_writer::span($sumattention, 'badge badge-light'),
1263 'btn btn-link mr-1');
1265 $out .= html_writer::div(html_writer::link(new moodle_url($this->page->url, array('showallplugins' => 1)),
1266 get_string('plugincheckall', 'core_plugin')).' '.html_writer::span($sumtotal, 'badge badge-light'),
1267 'btn btn-link mr-1');
1269 $out .= $this->output->container_end(); // End of .actions container.
1270 $out .= $this->output->container_end(); // End of #plugins-check-info container.
1272 if ($sumdisplayed > 0 or $options['full']) {
1273 $out .= html_writer::table($table);
1276 return $out;
1280 * Display the continue / cancel widgets for the plugins management pages.
1282 * @param null|moodle_url $continue URL for the continue button, should it be displayed
1283 * @param null|moodle_url $cancel URL for the cancel link, defaults to the current page
1284 * @return string HTML
1286 public function plugins_management_confirm_buttons(moodle_url $continue=null, moodle_url $cancel=null) {
1288 $out = html_writer::start_div('plugins-management-confirm-buttons');
1290 if (!empty($continue)) {
1291 $out .= $this->output->single_button($continue, get_string('continue'), 'post', array('class' => 'continue'));
1294 if (empty($cancel)) {
1295 $cancel = $this->page->url;
1297 $out .= html_writer::div(html_writer::link($cancel, get_string('cancel')), 'cancel');
1299 return $out;
1303 * Displays the information about missing dependencies
1305 * @param core_plugin_manager $pluginman
1306 * @return string
1308 protected function missing_dependencies(core_plugin_manager $pluginman) {
1310 $dependencies = $pluginman->missing_dependencies();
1312 if (empty($dependencies)) {
1313 return '';
1316 $available = array();
1317 $unavailable = array();
1318 $unknown = array();
1320 foreach ($dependencies as $component => $remoteinfo) {
1321 if ($remoteinfo === false) {
1322 // The required version is not available. Let us check if there
1323 // is at least some version in the plugins directory.
1324 $remoteinfoanyversion = $pluginman->get_remote_plugin_info($component, ANY_VERSION, false);
1325 if ($remoteinfoanyversion === false) {
1326 $unknown[$component] = $component;
1327 } else {
1328 $unavailable[$component] = $remoteinfoanyversion;
1330 } else {
1331 $available[$component] = $remoteinfo;
1335 $out = $this->output->container_start('plugins-check-dependencies mb-4');
1337 if ($unavailable or $unknown) {
1338 $out .= $this->output->heading(get_string('misdepsunavail', 'core_plugin'));
1339 if ($unknown) {
1340 $out .= $this->output->render((new \core\output\notification(get_string('misdepsunknownlist', 'core_plugin',
1341 implode(', ', $unknown))))->set_show_closebutton(false));
1343 if ($unavailable) {
1344 $unavailablelist = array();
1345 foreach ($unavailable as $component => $remoteinfoanyversion) {
1346 $unavailablelistitem = html_writer::link('https://moodle.org/plugins/view.php?plugin='.$component,
1347 '<strong>'.$remoteinfoanyversion->name.'</strong>');
1348 if ($remoteinfoanyversion->version) {
1349 $unavailablelistitem .= ' ('.$component.' &gt; '.$remoteinfoanyversion->version->version.')';
1350 } else {
1351 $unavailablelistitem .= ' ('.$component.')';
1353 $unavailablelist[] = $unavailablelistitem;
1355 $out .= $this->output->render((new \core\output\notification(get_string('misdepsunavaillist', 'core_plugin',
1356 implode(', ', $unavailablelist))))->set_show_closebutton(false));
1358 $out .= $this->output->container_start('plugins-check-dependencies-actions mb-4');
1359 $out .= ' '.html_writer::link(new moodle_url('/admin/tool/installaddon/'),
1360 get_string('dependencyuploadmissing', 'core_plugin'), array('class' => 'btn btn-secondary'));
1361 $out .= $this->output->container_end(); // End of .plugins-check-dependencies-actions container.
1364 if ($available) {
1365 $out .= $this->output->heading(get_string('misdepsavail', 'core_plugin'));
1366 $out .= $this->output->container_start('plugins-check-dependencies-actions mb-2');
1368 $installable = $pluginman->filter_installable($available);
1369 if ($installable) {
1370 $out .= $this->output->single_button(
1371 new moodle_url($this->page->url, array('installdepx' => 1)),
1372 get_string('dependencyinstallmissing', 'core_plugin', count($installable)),
1373 'post',
1374 array('class' => 'singlebutton dependencyinstallmissing d-inline-block mr-1')
1378 $out .= html_writer::div(html_writer::link(new moodle_url('/admin/tool/installaddon/'),
1379 get_string('dependencyuploadmissing', 'core_plugin'), array('class' => 'btn btn-link')),
1380 'dependencyuploadmissing d-inline-block mr-1');
1382 $out .= $this->output->container_end(); // End of .plugins-check-dependencies-actions container.
1384 $out .= $this->available_missing_dependencies_list($pluginman, $available);
1387 $out .= $this->output->container_end(); // End of .plugins-check-dependencies container.
1389 return $out;
1393 * Displays the list if available missing dependencies.
1395 * @param core_plugin_manager $pluginman
1396 * @param array $dependencies
1397 * @return string
1399 protected function available_missing_dependencies_list(core_plugin_manager $pluginman, array $dependencies) {
1400 global $CFG;
1402 $table = new html_table();
1403 $table->id = 'plugins-check-available-dependencies';
1404 $table->head = array(
1405 get_string('displayname', 'core_plugin'),
1406 get_string('release', 'core_plugin'),
1407 get_string('version', 'core_plugin'),
1408 get_string('supportedmoodleversions', 'core_plugin'),
1409 get_string('info', 'core'),
1411 $table->colclasses = array('displayname', 'release', 'version', 'supportedmoodleversions', 'info');
1412 $table->data = array();
1414 foreach ($dependencies as $plugin) {
1416 $supportedmoodles = array();
1417 foreach ($plugin->version->supportedmoodles as $moodle) {
1418 if ($CFG->branch == str_replace('.', '', $moodle->release)) {
1419 $supportedmoodles[] = html_writer::span($moodle->release, 'badge badge-success');
1420 } else {
1421 $supportedmoodles[] = html_writer::span($moodle->release, 'badge badge-light');
1425 $requriedby = $pluginman->other_plugins_that_require($plugin->component);
1426 if ($requriedby) {
1427 foreach ($requriedby as $ix => $val) {
1428 $inf = $pluginman->get_plugin_info($val);
1429 if ($inf) {
1430 $requriedby[$ix] = $inf->displayname.' ('.$inf->component.')';
1433 $info = html_writer::div(
1434 get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
1435 'requiredby mb-1'
1437 } else {
1438 $info = '';
1441 $info .= $this->output->container_start('actions');
1443 $info .= html_writer::div(
1444 html_writer::link('https://moodle.org/plugins/view.php?plugin='.$plugin->component,
1445 get_string('misdepinfoplugin', 'core_plugin')),
1446 'misdepinfoplugin d-inline-block mr-3 mb-1'
1449 $info .= html_writer::div(
1450 html_writer::link('https://moodle.org/plugins/pluginversion.php?id='.$plugin->version->id,
1451 get_string('misdepinfoversion', 'core_plugin')),
1452 'misdepinfoversion d-inline-block mr-3 mb-1'
1455 $info .= html_writer::div(html_writer::link($plugin->version->downloadurl, get_string('download')),
1456 'misdepdownload d-inline-block mr-3 mb-1');
1458 if ($pluginman->is_remote_plugin_installable($plugin->component, $plugin->version->version, $reason)) {
1459 $info .= $this->output->single_button(
1460 new moodle_url($this->page->url, array('installdep' => $plugin->component)),
1461 get_string('dependencyinstall', 'core_plugin'),
1462 'post',
1463 array('class' => 'singlebutton dependencyinstall mr-3 mb-1')
1465 } else {
1466 $reasonhelp = $this->info_remote_plugin_not_installable($reason);
1467 if ($reasonhelp) {
1468 $info .= html_writer::div($reasonhelp, 'reasonhelp dependencyinstall d-inline-block mr-3 mb-1');
1472 $info .= $this->output->container_end(); // End of .actions container.
1474 $table->data[] = array(
1475 html_writer::div($plugin->name, 'name').' '.html_writer::div($plugin->component, 'component text-muted small'),
1476 $plugin->version->release,
1477 $plugin->version->version,
1478 implode(' ', $supportedmoodles),
1479 $info
1483 return html_writer::table($table);
1487 * Explain why {@link core_plugin_manager::is_remote_plugin_installable()} returned false.
1489 * @param string $reason the reason code as returned by the plugin manager
1490 * @return string
1492 protected function info_remote_plugin_not_installable($reason) {
1494 if ($reason === 'notwritableplugintype' or $reason === 'notwritableplugin') {
1495 return $this->output->help_icon('notwritable', 'core_plugin', get_string('notwritable', 'core_plugin'));
1498 if ($reason === 'remoteunavailable') {
1499 return $this->output->help_icon('notdownloadable', 'core_plugin', get_string('notdownloadable', 'core_plugin'));
1502 return false;
1506 * Formats the information that needs to go in the 'Requires' column.
1507 * @param \core\plugininfo\base $plugin the plugin we are rendering the row for.
1508 * @param core_plugin_manager $pluginman provides data on all the plugins.
1509 * @param string $version
1510 * @param int $branch the current Moodle branch
1511 * @return string HTML code
1513 protected function required_column(\core\plugininfo\base $plugin, core_plugin_manager $pluginman, $version, $branch = null) {
1515 $requires = array();
1516 $displayuploadlink = false;
1517 $displayupdateslink = false;
1519 $requirements = $pluginman->resolve_requirements($plugin, $version, $branch);
1520 foreach ($requirements as $reqname => $reqinfo) {
1521 if ($reqname === 'core') {
1522 if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OK) {
1523 $class = 'requires-ok text-muted';
1524 $label = '';
1525 } else {
1526 $class = 'requires-failed';
1527 $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'badge badge-danger');
1530 if ($branch != null && !$plugin->is_core_compatible_satisfied($branch)) {
1531 $requires[] = html_writer::tag('li',
1532 html_writer::span(get_string('incompatibleversion', 'core_plugin', $branch), 'dep dep-core').
1533 ' '.$label, array('class' => $class));
1535 } else if ($branch != null && $plugin->pluginsupported != null) {
1536 $requires[] = html_writer::tag('li',
1537 html_writer::span(get_string('moodlebranch', 'core_plugin',
1538 array('min' => $plugin->pluginsupported[0], 'max' => $plugin->pluginsupported[1])), 'dep dep-core').
1539 ' '.$label, array('class' => $class));
1541 } else if ($reqinfo->reqver != ANY_VERSION) {
1542 $requires[] = html_writer::tag('li',
1543 html_writer::span(get_string('moodleversion', 'core_plugin', $plugin->versionrequires), 'dep dep-core').
1544 ' '.$label, array('class' => $class));
1547 } else {
1548 $actions = array();
1550 if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OK) {
1551 $label = '';
1552 $class = 'requires-ok text-muted';
1554 } else if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_MISSING) {
1555 if ($reqinfo->availability == $pluginman::REQUIREMENT_AVAILABLE) {
1556 $label = html_writer::span(get_string('dependencymissing', 'core_plugin'), 'badge badge-warning');
1557 $label .= ' '.html_writer::span(get_string('dependencyavailable', 'core_plugin'), 'badge badge-warning');
1558 $class = 'requires-failed requires-missing requires-available';
1559 $actions[] = html_writer::link(
1560 new moodle_url('https://moodle.org/plugins/view.php', array('plugin' => $reqname)),
1561 get_string('misdepinfoplugin', 'core_plugin')
1564 } else {
1565 $label = html_writer::span(get_string('dependencymissing', 'core_plugin'), 'badge badge-danger');
1566 $label .= ' '.html_writer::span(get_string('dependencyunavailable', 'core_plugin'),
1567 'badge badge-danger');
1568 $class = 'requires-failed requires-missing requires-unavailable';
1570 $displayuploadlink = true;
1572 } else if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OUTDATED) {
1573 if ($reqinfo->availability == $pluginman::REQUIREMENT_AVAILABLE) {
1574 $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'badge badge-warning');
1575 $label .= ' '.html_writer::span(get_string('dependencyavailable', 'core_plugin'), 'badge badge-warning');
1576 $class = 'requires-failed requires-outdated requires-available';
1577 $displayupdateslink = true;
1579 } else {
1580 $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'badge badge-danger');
1581 $label .= ' '.html_writer::span(get_string('dependencyunavailable', 'core_plugin'),
1582 'badge badge-danger');
1583 $class = 'requires-failed requires-outdated requires-unavailable';
1585 $displayuploadlink = true;
1588 if ($reqinfo->reqver != ANY_VERSION) {
1589 $str = 'otherpluginversion';
1590 } else {
1591 $str = 'otherplugin';
1594 $requires[] = html_writer::tag('li', html_writer::span(
1595 get_string($str, 'core_plugin', array('component' => $reqname, 'version' => $reqinfo->reqver)),
1596 'dep dep-plugin').' '.$label.' '.html_writer::span(implode(' | ', $actions), 'actions'),
1597 array('class' => $class)
1602 if (!$requires) {
1603 return '';
1606 $out = html_writer::tag('ul', implode("\n", $requires), array('class' => 'm-0'));
1608 if ($displayuploadlink) {
1609 $out .= html_writer::div(
1610 html_writer::link(
1611 new moodle_url('/admin/tool/installaddon/'),
1612 get_string('dependencyuploadmissing', 'core_plugin'),
1613 array('class' => 'btn btn-secondary btn-sm m-1')
1615 'dependencyuploadmissing'
1619 if ($displayupdateslink) {
1620 $out .= html_writer::div(
1621 html_writer::link(
1622 new moodle_url($this->page->url, array('sesskey' => sesskey(), 'fetchupdates' => 1)),
1623 get_string('checkforupdates', 'core_plugin'),
1624 array('class' => 'btn btn-secondary btn-sm m-1')
1626 'checkforupdates'
1630 // Check if supports is present, and $branch is not in, only if $incompatible check was ok.
1631 if ($plugin->pluginsupported != null && $class == 'requires-ok' && $branch != null) {
1632 if ($pluginman->check_explicitly_supported($plugin, $branch) == $pluginman::VERSION_NOT_SUPPORTED) {
1633 $out .= html_writer::div(get_string('notsupported', 'core_plugin', $branch));
1637 return $out;
1642 * Prints an overview about the plugins - number of installed, number of extensions etc.
1644 * @param core_plugin_manager $pluginman provides information about the plugins
1645 * @param array $options filtering options
1646 * @return string as usually
1648 public function plugins_overview_panel(core_plugin_manager $pluginman, array $options = array()) {
1650 $plugininfo = $pluginman->get_plugins();
1652 $numtotal = $numextension = $numupdatable = $numinstallable = 0;
1654 foreach ($plugininfo as $type => $plugins) {
1655 foreach ($plugins as $name => $plugin) {
1656 if ($res = $plugin->available_updates()) {
1657 $numupdatable++;
1658 foreach ($res as $updateinfo) {
1659 if ($pluginman->is_remote_plugin_installable($updateinfo->component, $updateinfo->version, $reason, false)) {
1660 $numinstallable++;
1661 break;
1665 if ($plugin->get_status() === core_plugin_manager::PLUGIN_STATUS_MISSING) {
1666 continue;
1668 $numtotal++;
1669 if (!$plugin->is_standard()) {
1670 $numextension++;
1675 $infoall = html_writer::link(
1676 new moodle_url($this->page->url, array('contribonly' => 0, 'updatesonly' => 0)),
1677 get_string('overviewall', 'core_plugin'),
1678 array('title' => get_string('filterall', 'core_plugin'))
1679 ).' '.html_writer::span($numtotal, 'badge number number-all');
1681 $infoext = html_writer::link(
1682 new moodle_url($this->page->url, array('contribonly' => 1, 'updatesonly' => 0)),
1683 get_string('overviewext', 'core_plugin'),
1684 array('title' => get_string('filtercontribonly', 'core_plugin'))
1685 ).' '.html_writer::span($numextension, 'badge number number-additional');
1687 if ($numupdatable) {
1688 $infoupdatable = html_writer::link(
1689 new moodle_url($this->page->url, array('contribonly' => 0, 'updatesonly' => 1)),
1690 get_string('overviewupdatable', 'core_plugin'),
1691 array('title' => get_string('filterupdatesonly', 'core_plugin'))
1692 ).' '.html_writer::span($numupdatable, 'badge badge-info number number-updatable');
1693 } else {
1694 // No updates, or the notifications disabled.
1695 $infoupdatable = '';
1698 $out = html_writer::start_div('', array('id' => 'plugins-overview-panel'));
1700 if (!empty($options['updatesonly'])) {
1701 $out .= $this->output->heading(get_string('overviewupdatable', 'core_plugin'), 3);
1702 } else if (!empty($options['contribonly'])) {
1703 $out .= $this->output->heading(get_string('overviewext', 'core_plugin'), 3);
1706 if ($numinstallable) {
1707 $out .= $this->output->single_button(
1708 new moodle_url($this->page->url, array('installupdatex' => 1)),
1709 get_string('updateavailableinstallall', 'core_admin', $numinstallable),
1710 'post',
1711 array('class' => 'singlebutton updateavailableinstallall')
1715 $out .= html_writer::div($infoall, 'info info-all').
1716 html_writer::div($infoext, 'info info-ext').
1717 html_writer::div($infoupdatable, 'info info-updatable');
1719 $out .= html_writer::end_div(); // End of #plugins-overview-panel block.
1721 return $out;
1725 * Displays all known plugins and links to manage them
1727 * This default implementation renders all plugins into one big table.
1729 * @param core_plugin_manager $pluginman provides information about the plugins.
1730 * @param array $options filtering options
1731 * @return string HTML code
1733 public function plugins_control_panel(core_plugin_manager $pluginman, array $options = array()) {
1735 $plugininfo = $pluginman->get_plugins();
1737 // Filter the list of plugins according the options.
1738 if (!empty($options['updatesonly'])) {
1739 $updateable = array();
1740 foreach ($plugininfo as $plugintype => $pluginnames) {
1741 foreach ($pluginnames as $pluginname => $pluginfo) {
1742 $pluginavailableupdates = $pluginfo->available_updates();
1743 if (!empty($pluginavailableupdates)) {
1744 foreach ($pluginavailableupdates as $pluginavailableupdate) {
1745 $updateable[$plugintype][$pluginname] = $pluginfo;
1750 $plugininfo = $updateable;
1753 if (!empty($options['contribonly'])) {
1754 $contribs = array();
1755 foreach ($plugininfo as $plugintype => $pluginnames) {
1756 foreach ($pluginnames as $pluginname => $pluginfo) {
1757 if (!$pluginfo->is_standard()) {
1758 $contribs[$plugintype][$pluginname] = $pluginfo;
1762 $plugininfo = $contribs;
1765 if (empty($plugininfo)) {
1766 return '';
1769 $table = new html_table();
1770 $table->id = 'plugins-control-panel';
1771 $table->head = array(
1772 get_string('displayname', 'core_plugin'),
1773 get_string('version', 'core_plugin'),
1774 get_string('availability', 'core_plugin'),
1775 get_string('actions', 'core_plugin'),
1776 get_string('notes','core_plugin'),
1778 $table->headspan = array(1, 1, 1, 2, 1);
1779 $table->colclasses = array(
1780 'pluginname', 'version', 'availability', 'settings', 'uninstall', 'notes'
1783 foreach ($plugininfo as $type => $plugins) {
1784 $heading = $pluginman->plugintype_name_plural($type);
1785 $pluginclass = core_plugin_manager::resolve_plugininfo_class($type);
1786 if ($manageurl = $pluginclass::get_manage_url()) {
1787 $heading .= $this->output->action_icon($manageurl, new pix_icon('i/settings',
1788 get_string('settings', 'core_plugin')));
1790 $header = new html_table_cell(html_writer::tag('span', $heading, array('id'=>'plugin_type_cell_'.$type)));
1791 $header->header = true;
1792 $header->colspan = array_sum($table->headspan);
1793 $header = new html_table_row(array($header));
1794 $header->attributes['class'] = 'plugintypeheader type-' . $type;
1795 $table->data[] = $header;
1797 if (empty($plugins)) {
1798 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
1799 $msg->colspan = array_sum($table->headspan);
1800 $row = new html_table_row(array($msg));
1801 $row->attributes['class'] .= 'msg msg-noneinstalled';
1802 $table->data[] = $row;
1803 continue;
1806 foreach ($plugins as $name => $plugin) {
1807 $row = new html_table_row();
1808 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
1810 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name, null)) {
1811 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'icon pluginicon'));
1812 } else {
1813 $icon = $this->output->spacer();
1815 $status = $plugin->get_status();
1816 $row->attributes['class'] .= ' status-'.$status;
1817 $pluginname = html_writer::tag('div', $icon.$plugin->displayname, array('class' => 'displayname')).
1818 html_writer::tag('div', $plugin->component, array('class' => 'componentname'));
1819 $pluginname = new html_table_cell($pluginname);
1821 $version = html_writer::div($plugin->versiondb, 'versionnumber');
1822 if ((string)$plugin->release !== '') {
1823 $version = html_writer::div($plugin->release, 'release').$version;
1825 $version = new html_table_cell($version);
1827 $isenabled = $plugin->is_enabled();
1828 if (is_null($isenabled)) {
1829 $availability = new html_table_cell('');
1830 } else if ($isenabled) {
1831 $row->attributes['class'] .= ' enabled';
1832 $availability = new html_table_cell(get_string('pluginenabled', 'core_plugin'));
1833 } else {
1834 $row->attributes['class'] .= ' disabled';
1835 $availability = new html_table_cell(get_string('plugindisabled', 'core_plugin'));
1838 $settingsurl = $plugin->get_settings_url();
1839 if (!is_null($settingsurl)) {
1840 $settings = html_writer::link($settingsurl, get_string('settings', 'core_plugin'), array('class' => 'settings'));
1841 } else {
1842 $settings = '';
1844 $settings = new html_table_cell($settings);
1846 if ($uninstallurl = $pluginman->get_uninstall_url($plugin->component, 'overview')) {
1847 $uninstall = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin'));
1848 } else {
1849 $uninstall = '';
1851 $uninstall = new html_table_cell($uninstall);
1853 if ($plugin->is_standard()) {
1854 $row->attributes['class'] .= ' standard';
1855 $source = '';
1856 } else {
1857 $row->attributes['class'] .= ' extension';
1858 $source = html_writer::div(get_string('sourceext', 'core_plugin'), 'source badge badge-info');
1861 if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) {
1862 $msg = html_writer::div(get_string('status_missing', 'core_plugin'), 'statusmsg badge badge-danger');
1863 } else if ($status === core_plugin_manager::PLUGIN_STATUS_NEW) {
1864 $msg = html_writer::div(get_string('status_new', 'core_plugin'), 'statusmsg badge badge-success');
1865 } else {
1866 $msg = '';
1869 $requriedby = $pluginman->other_plugins_that_require($plugin->component);
1870 if ($requriedby) {
1871 $requiredby = html_writer::tag('div', get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
1872 array('class' => 'requiredby'));
1873 } else {
1874 $requiredby = '';
1877 $updateinfo = '';
1878 if (is_array($plugin->available_updates())) {
1879 foreach ($plugin->available_updates() as $availableupdate) {
1880 $updateinfo .= $this->plugin_available_update_info($pluginman, $availableupdate);
1884 $notes = new html_table_cell($source.$msg.$requiredby.$updateinfo);
1886 $row->cells = array(
1887 $pluginname, $version, $availability, $settings, $uninstall, $notes
1889 $table->data[] = $row;
1893 return html_writer::table($table);
1897 * Helper method to render the information about the available plugin update
1899 * @param core_plugin_manager $pluginman plugin manager instance
1900 * @param \core\update\info $updateinfo information about the available update for the plugin
1902 protected function plugin_available_update_info(core_plugin_manager $pluginman, \core\update\info $updateinfo) {
1904 $boxclasses = 'pluginupdateinfo';
1905 $info = array();
1907 if (isset($updateinfo->release)) {
1908 $info[] = html_writer::div(
1909 get_string('updateavailable_release', 'core_plugin', $updateinfo->release),
1910 'info release'
1914 if (isset($updateinfo->maturity)) {
1915 $info[] = html_writer::div(
1916 get_string('maturity'.$updateinfo->maturity, 'core_admin'),
1917 'info maturity'
1919 $boxclasses .= ' maturity'.$updateinfo->maturity;
1922 if (isset($updateinfo->download)) {
1923 $info[] = html_writer::div(
1924 html_writer::link($updateinfo->download, get_string('download')),
1925 'info download'
1929 if (isset($updateinfo->url)) {
1930 $info[] = html_writer::div(
1931 html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin')),
1932 'info more'
1936 $box = html_writer::start_div($boxclasses);
1937 $box .= html_writer::div(
1938 get_string('updateavailable', 'core_plugin', $updateinfo->version),
1939 'version'
1941 $box .= html_writer::div(
1942 implode(html_writer::span(' ', 'separator'), $info),
1943 'infos'
1946 if ($pluginman->is_remote_plugin_installable($updateinfo->component, $updateinfo->version, $reason, false)) {
1947 $box .= $this->output->single_button(
1948 new moodle_url($this->page->url, array('installupdate' => $updateinfo->component,
1949 'installupdateversion' => $updateinfo->version)),
1950 get_string('updateavailableinstall', 'core_admin'),
1951 'post',
1952 array('class' => 'singlebutton updateavailableinstall')
1954 } else {
1955 $reasonhelp = $this->info_remote_plugin_not_installable($reason);
1956 if ($reasonhelp) {
1957 $box .= html_writer::div($reasonhelp, 'reasonhelp updateavailableinstall');
1960 $box .= html_writer::end_div();
1962 return $box;
1966 * This function will render one beautiful table with all the environmental
1967 * configuration and how it suits Moodle needs.
1969 * @param boolean $result final result of the check (true/false)
1970 * @param environment_results[] $environment_results array of results gathered
1971 * @return string HTML to output.
1973 public function environment_check_table($result, $environment_results) {
1974 global $CFG;
1976 // Table headers
1977 $servertable = new html_table();//table for server checks
1978 $servertable->head = array(
1979 get_string('name'),
1980 get_string('info'),
1981 get_string('report'),
1982 get_string('plugin'),
1983 get_string('status'),
1985 $servertable->colclasses = array('centeralign name', 'centeralign info', 'leftalign report', 'leftalign plugin', 'centeralign status');
1986 $servertable->attributes['class'] = 'admintable environmenttable generaltable table-sm';
1987 $servertable->id = 'serverstatus';
1989 $serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
1991 $othertable = new html_table();//table for custom checks
1992 $othertable->head = array(
1993 get_string('info'),
1994 get_string('report'),
1995 get_string('plugin'),
1996 get_string('status'),
1998 $othertable->colclasses = array('aligncenter info', 'alignleft report', 'alignleft plugin', 'aligncenter status');
1999 $othertable->attributes['class'] = 'admintable environmenttable generaltable table-sm';
2000 $othertable->id = 'otherserverstatus';
2002 $otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
2004 // Iterate over each environment_result
2005 $continue = true;
2006 foreach ($environment_results as $environment_result) {
2007 $errorline = false;
2008 $warningline = false;
2009 $stringtouse = '';
2010 if ($continue) {
2011 $type = $environment_result->getPart();
2012 $info = $environment_result->getInfo();
2013 $status = $environment_result->getStatus();
2014 $plugin = $environment_result->getPluginName();
2015 $error_code = $environment_result->getErrorCode();
2016 // Process Report field
2017 $rec = new stdClass();
2018 // Something has gone wrong at parsing time
2019 if ($error_code) {
2020 $stringtouse = 'environmentxmlerror';
2021 $rec->error_code = $error_code;
2022 $status = get_string('error');
2023 $errorline = true;
2024 $continue = false;
2027 if ($continue) {
2028 if ($rec->needed = $environment_result->getNeededVersion()) {
2029 // We are comparing versions
2030 $rec->current = $environment_result->getCurrentVersion();
2031 if ($environment_result->getLevel() == 'required') {
2032 $stringtouse = 'environmentrequireversion';
2033 } else {
2034 $stringtouse = 'environmentrecommendversion';
2037 } else if ($environment_result->getPart() == 'custom_check') {
2038 // We are checking installed & enabled things
2039 if ($environment_result->getLevel() == 'required') {
2040 $stringtouse = 'environmentrequirecustomcheck';
2041 } else {
2042 $stringtouse = 'environmentrecommendcustomcheck';
2045 } else if ($environment_result->getPart() == 'php_setting') {
2046 if ($status) {
2047 $stringtouse = 'environmentsettingok';
2048 } else if ($environment_result->getLevel() == 'required') {
2049 $stringtouse = 'environmentmustfixsetting';
2050 } else {
2051 $stringtouse = 'environmentshouldfixsetting';
2054 } else {
2055 if ($environment_result->getLevel() == 'required') {
2056 $stringtouse = 'environmentrequireinstall';
2057 } else {
2058 $stringtouse = 'environmentrecommendinstall';
2062 // Calculate the status value
2063 if ($environment_result->getBypassStr() != '') { //Handle bypassed result (warning)
2064 $status = get_string('bypassed');
2065 $warningline = true;
2066 } else if ($environment_result->getRestrictStr() != '') { //Handle restricted result (error)
2067 $status = get_string('restricted');
2068 $errorline = true;
2069 } else {
2070 if ($status) { //Handle ok result (ok)
2071 $status = get_string('ok');
2072 } else {
2073 if ($environment_result->getLevel() == 'optional') {//Handle check result (warning)
2074 $status = get_string('check');
2075 $warningline = true;
2076 } else { //Handle error result (error)
2077 $status = get_string('check');
2078 $errorline = true;
2084 // Build the text
2085 $linkparts = array();
2086 $linkparts[] = 'admin/environment';
2087 $linkparts[] = $type;
2088 if (!empty($info)){
2089 $linkparts[] = $info;
2091 // Plugin environments do not have docs pages yet.
2092 if (empty($CFG->docroot) or $environment_result->plugin) {
2093 $report = get_string($stringtouse, 'admin', $rec);
2094 } else {
2095 $report = $this->doc_link(join('/', $linkparts), get_string($stringtouse, 'admin', $rec), true);
2097 // Enclose report text in div so feedback text will be displayed underneath it.
2098 $report = html_writer::div($report);
2100 // Format error or warning line
2101 if ($errorline) {
2102 $messagetype = 'error';
2103 $statusclass = 'badge-danger';
2104 } else if ($warningline) {
2105 $messagetype = 'warn';
2106 $statusclass = 'badge-warning';
2107 } else {
2108 $messagetype = 'ok';
2109 $statusclass = 'badge-success';
2111 $status = html_writer::span($status, 'badge ' . $statusclass);
2112 // Here we'll store all the feedback found
2113 $feedbacktext = '';
2114 // Append the feedback if there is some
2115 $feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), $messagetype);
2116 //Append the bypass if there is some
2117 $feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'warn');
2118 //Append the restrict if there is some
2119 $feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'error');
2121 $report .= $feedbacktext;
2123 // Add the row to the table
2124 if ($environment_result->getPart() == 'custom_check'){
2125 $otherdata[$messagetype][] = array ($info, $report, $plugin, $status);
2126 } else {
2127 $serverdata[$messagetype][] = array ($type, $info, $report, $plugin, $status);
2132 //put errors first in
2133 $servertable->data = array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']);
2134 $othertable->data = array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']);
2136 // Print table
2137 $output = '';
2138 $output .= $this->heading(get_string('serverchecks', 'admin'));
2139 $output .= html_writer::table($servertable);
2140 if (count($othertable->data)){
2141 $output .= $this->heading(get_string('customcheck', 'admin'));
2142 $output .= html_writer::table($othertable);
2145 // Finally, if any error has happened, print the summary box
2146 if (!$result) {
2147 $output .= $this->box(get_string('environmenterrortodo', 'admin'), 'environmentbox errorbox');
2150 return $output;
2154 * Render a simple page for providing the upgrade key.
2156 * @param moodle_url|string $url
2157 * @return string
2159 public function upgradekey_form_page($url) {
2161 $output = '';
2162 $output .= $this->header();
2163 $output .= $this->container_start('upgradekeyreq');
2164 $output .= $this->heading(get_string('upgradekeyreq', 'core_admin'));
2165 $output .= html_writer::start_tag('form', array('method' => 'POST', 'action' => $url));
2166 $output .= html_writer::empty_tag('input', [
2167 'name' => 'upgradekey',
2168 'type' => 'password',
2169 'class' => 'form-control w-auto',
2171 $output .= html_writer::empty_tag('input', [
2172 'type' => 'submit',
2173 'value' => get_string('submit'),
2174 'class' => 'btn btn-primary mt-3',
2176 $output .= html_writer::end_tag('form');
2177 $output .= $this->container_end();
2178 $output .= $this->footer();
2180 return $output;
2184 * Check to see if writing to the deprecated legacy log store is enabled.
2186 * @return string An error message if writing to the legacy log store is enabled.
2188 protected function legacy_log_store_writing_error() {
2189 $enabled = get_config('logstore_legacy', 'loglegacy');
2190 $plugins = explode(',', get_config('tool_log', 'enabled_stores'));
2191 $enabled = $enabled && in_array('logstore_legacy', $plugins);
2193 if ($enabled) {
2194 return $this->warning(get_string('legacylogginginuse'));
2199 * Display message about the benefits of registering on Moodle.org
2201 * @return string
2203 public function moodleorg_registration_message() {
2205 $out = format_text(get_string('registerwithmoodleorginfo', 'core_hub'), FORMAT_MARKDOWN);
2207 $out .= html_writer::link(
2208 new moodle_url('/admin/settings.php', ['section' => 'moodleservices']),
2209 $this->output->pix_icon('i/info', '').' '.get_string('registerwithmoodleorginfoapp', 'core_hub'),
2210 ['class' => 'btn btn-link', 'role' => 'opener', 'target' => '_href']
2213 $out .= html_writer::link(
2214 HUB_MOODLEORGHUBURL,
2215 $this->output->pix_icon('i/stats', '').' '.get_string('registerwithmoodleorginfostats', 'core_hub'),
2216 ['class' => 'btn btn-link', 'role' => 'opener', 'target' => '_href']
2219 $out .= html_writer::link(
2220 HUB_MOODLEORGHUBURL.'/sites',
2221 $this->output->pix_icon('i/location', '').' '.get_string('registerwithmoodleorginfosites', 'core_hub'),
2222 ['class' => 'btn btn-link', 'role' => 'opener', 'target' => '_href']
2225 return $this->output->box($out);
2229 * Display message about benefits of enabling the user feedback feature.
2231 * @param bool $showfeedbackencouragement Whether the encouragement content should be displayed or not
2232 * @return string
2234 protected function userfeedback_encouragement(bool $showfeedbackencouragement): string {
2235 $output = '';
2237 if ($showfeedbackencouragement) {
2238 $settingslink = new moodle_url('/admin/settings.php', ['section' => 'userfeedback']);
2239 $output .= $this->warning(get_string('userfeedbackencouragement', 'admin', $settingslink->out()), 'info');
2242 return $output;
2246 * Display a warning about the deprecation of Mnet.
2248 * @param string $xmlrpcwarning The warning message
2249 * @return string HTML to output.
2251 protected function mnet_deprecation_warning($xmlrpcwarning) {
2252 if (empty($xmlrpcwarning)) {
2253 return '';
2256 return $this->warning($xmlrpcwarning);