weekly release 3.8.5+
[moodle.git] / admin / renderer.php
blob82f03d3d7379fd391621e44541bb471e1cb54aa5
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');
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 'uninstalldeleteconfirmexternal');
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
286 * @return string HTML to output.
288 public function admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed,
289 $cronoverdue, $dbproblems, $maintenancemode, $availableupdates, $availableupdatesfetch,
290 $buggyiconvnomb, $registered, array $cachewarnings = array(), $eventshandlers = 0,
291 $themedesignermode = false, $devlibdir = false, $mobileconfigured = false,
292 $overridetossl = false, $invalidforgottenpasswordurl = false, $croninfrequent = false) {
293 global $CFG;
294 $output = '';
296 $output .= $this->header();
297 $output .= $this->maturity_info($maturity);
298 $output .= $this->legacy_log_store_writing_error();
299 $output .= empty($CFG->disableupdatenotifications) ? $this->available_updates($availableupdates, $availableupdatesfetch) : '';
300 $output .= $this->insecure_dataroot_warning($insecuredataroot);
301 $output .= $this->development_libs_directories_warning($devlibdir);
302 $output .= $this->themedesignermode_warning($themedesignermode);
303 $output .= $this->display_errors_warning($errorsdisplayed);
304 $output .= $this->buggy_iconv_warning($buggyiconvnomb);
305 $output .= $this->cron_overdue_warning($cronoverdue);
306 $output .= $this->cron_infrequent_warning($croninfrequent);
307 $output .= $this->db_problems($dbproblems);
308 $output .= $this->maintenance_mode_warning($maintenancemode);
309 $output .= $this->overridetossl_warning($overridetossl);
310 $output .= $this->cache_warnings($cachewarnings);
311 $output .= $this->events_handlers($eventshandlers);
312 $output .= $this->registration_warning($registered);
313 $output .= $this->mobile_configuration_warning($mobileconfigured);
314 $output .= $this->forgotten_password_url_warning($invalidforgottenpasswordurl);
316 //////////////////////////////////////////////////////////////////////////////////////////////////
317 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
318 $output .= $this->moodle_copyright();
319 //////////////////////////////////////////////////////////////////////////////////////////////////
321 $output .= $this->footer();
323 return $output;
327 * Display the plugin management page (admin/plugins.php).
329 * The filtering options array may contain following items:
330 * bool contribonly - show only contributed extensions
331 * bool updatesonly - show only plugins with an available update
333 * @param core_plugin_manager $pluginman
334 * @param \core\update\checker $checker
335 * @param array $options filtering options
336 * @return string HTML to output.
338 public function plugin_management_page(core_plugin_manager $pluginman, \core\update\checker $checker, array $options = array()) {
340 $output = '';
342 $output .= $this->header();
343 $output .= $this->heading(get_string('pluginsoverview', 'core_admin'));
344 $output .= $this->check_for_updates_button($checker, $this->page->url);
345 $output .= $this->plugins_overview_panel($pluginman, $options);
346 $output .= $this->plugins_control_panel($pluginman, $options);
347 $output .= $this->footer();
349 return $output;
353 * Renders a button to fetch for available updates.
355 * @param \core\update\checker $checker
356 * @param moodle_url $reloadurl
357 * @return string HTML
359 public function check_for_updates_button(\core\update\checker $checker, $reloadurl) {
361 $output = '';
363 if ($checker->enabled()) {
364 $output .= $this->container_start('checkforupdates mb-4');
365 $output .= $this->single_button(
366 new moodle_url($reloadurl, array('fetchupdates' => 1)),
367 get_string('checkforupdates', 'core_plugin')
369 if ($timefetched = $checker->get_last_timefetched()) {
370 $timefetched = userdate($timefetched, get_string('strftimedatetime', 'core_langconfig'));
371 $output .= $this->container(get_string('checkforupdateslast', 'core_plugin', $timefetched),
372 'lasttimefetched small text-muted mt-1');
374 $output .= $this->container_end();
377 return $output;
381 * Display a page to confirm the plugin uninstallation.
383 * @param core_plugin_manager $pluginman
384 * @param \core\plugininfo\base $pluginfo
385 * @param moodle_url $continueurl URL to continue after confirmation
386 * @param moodle_url $cancelurl URL to to go if cancelled
387 * @return string
389 public function plugin_uninstall_confirm_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, moodle_url $continueurl, moodle_url $cancelurl) {
390 $output = '';
392 $pluginname = $pluginman->plugin_name($pluginfo->component);
394 $confirm = '<p>' . get_string('uninstallconfirm', 'core_plugin', array('name' => $pluginname)) . '</p>';
395 if ($extraconfirm = $pluginfo->get_uninstall_extra_warning()) {
396 $confirm .= $extraconfirm;
399 $output .= $this->output->header();
400 $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
401 $output .= $this->output->confirm($confirm, $continueurl, $cancelurl);
402 $output .= $this->output->footer();
404 return $output;
408 * Display a page with results of plugin uninstallation and offer removal of plugin files.
410 * @param core_plugin_manager $pluginman
411 * @param \core\plugininfo\base $pluginfo
412 * @param progress_trace_buffer $progress
413 * @param moodle_url $continueurl URL to continue to remove the plugin folder
414 * @return string
416 public function plugin_uninstall_results_removable_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo,
417 progress_trace_buffer $progress, moodle_url $continueurl) {
418 $output = '';
420 $pluginname = $pluginman->plugin_name($pluginfo->component);
422 // Do not show navigation here, they must click one of the buttons.
423 $this->page->set_pagelayout('maintenance');
424 $this->page->set_cacheable(false);
426 $output .= $this->output->header();
427 $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
429 $output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
431 $confirm = $this->output->container(get_string('uninstalldeleteconfirm', 'core_plugin',
432 array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'uninstalldeleteconfirm');
434 if ($repotype = $pluginman->plugin_external_source($pluginfo->component)) {
435 $confirm .= $this->output->container(get_string('uninstalldeleteconfirmexternal', 'core_plugin', $repotype),
436 'uninstalldeleteconfirmexternal');
439 // After any uninstall we must execute full upgrade to finish the cleanup!
440 $output .= $this->output->confirm($confirm, $continueurl, new moodle_url('/admin/index.php'));
441 $output .= $this->output->footer();
443 return $output;
447 * Display a page with results of plugin uninstallation and inform about the need to remove plugin files manually.
449 * @param core_plugin_manager $pluginman
450 * @param \core\plugininfo\base $pluginfo
451 * @param progress_trace_buffer $progress
452 * @return string
454 public function plugin_uninstall_results_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, progress_trace_buffer $progress) {
455 $output = '';
457 $pluginname = $pluginfo->component;
459 $output .= $this->output->header();
460 $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
462 $output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
464 $output .= $this->output->box(get_string('uninstalldelete', 'core_plugin',
465 array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'generalbox uninstalldelete');
466 $output .= $this->output->continue_button(new moodle_url('/admin/index.php'));
467 $output .= $this->output->footer();
469 return $output;
473 * Display the plugin management page (admin/environment.php).
474 * @param array $versions
475 * @param string $version
476 * @param boolean $envstatus final result of env check (true/false)
477 * @param array $environment_results array of results gathered
478 * @return string HTML to output.
480 public function environment_check_page($versions, $version, $envstatus, $environment_results) {
481 $output = '';
482 $output .= $this->header();
484 // Print the component download link
485 $output .= html_writer::tag('div', html_writer::link(
486 new moodle_url('/admin/environment.php', array('action' => 'updatecomponent', 'sesskey' => sesskey())),
487 get_string('updatecomponent', 'admin')),
488 array('class' => 'reportlink'));
490 // Heading.
491 $output .= $this->heading(get_string('environment', 'admin'));
493 // Box with info and a menu to choose the version.
494 $output .= $this->box_start();
495 $output .= html_writer::tag('div', get_string('adminhelpenvironment'));
496 $select = new single_select(new moodle_url('/admin/environment.php'), 'version', $versions, $version, null);
497 $select->label = get_string('moodleversion');
498 $output .= $this->render($select);
499 $output .= $this->box_end();
501 // The results
502 $output .= $this->environment_check_table($envstatus, $environment_results);
504 $output .= $this->footer();
505 return $output;
509 * Output a warning message, of the type that appears on the admin notifications page.
510 * @param string $message the message to display.
511 * @param string $type type class
512 * @return string HTML to output.
514 protected function warning($message, $type = 'warning') {
515 return $this->box($message, 'generalbox admin' . $type);
519 * Render an appropriate message if dataroot is insecure.
520 * @param bool $insecuredataroot
521 * @return string HTML to output.
523 protected function insecure_dataroot_warning($insecuredataroot) {
524 global $CFG;
526 if ($insecuredataroot == INSECURE_DATAROOT_WARNING) {
527 return $this->warning(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot));
529 } else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) {
530 return $this->warning(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'error');
532 } else {
533 return '';
538 * Render a warning that a directory with development libs is present.
540 * @param bool $devlibdir True if the warning should be displayed.
541 * @return string
543 protected function development_libs_directories_warning($devlibdir) {
545 if ($devlibdir) {
546 $moreinfo = new moodle_url('/report/security/index.php');
547 $warning = get_string('devlibdirpresent', 'core_admin', ['moreinfourl' => $moreinfo->out()]);
548 return $this->warning($warning, 'error');
550 } else {
551 return '';
556 * Render an appropriate message if dataroot is insecure.
557 * @param bool $errorsdisplayed
558 * @return string HTML to output.
560 protected function display_errors_warning($errorsdisplayed) {
561 if (!$errorsdisplayed) {
562 return '';
565 return $this->warning(get_string('displayerrorswarning', 'admin'));
569 * Render an appropriate message if themdesignermode is enabled.
570 * @param bool $themedesignermode true if enabled
571 * @return string HTML to output.
573 protected function themedesignermode_warning($themedesignermode) {
574 if (!$themedesignermode) {
575 return '';
578 return $this->warning(get_string('themedesignermodewarning', 'admin'));
582 * Render an appropriate message if iconv is buggy and mbstring missing.
583 * @param bool $buggyiconvnomb
584 * @return string HTML to output.
586 protected function buggy_iconv_warning($buggyiconvnomb) {
587 if (!$buggyiconvnomb) {
588 return '';
591 return $this->warning(get_string('warningiconvbuggy', 'admin'));
595 * Render an appropriate message if cron has not been run recently.
596 * @param bool $cronoverdue
597 * @return string HTML to output.
599 public function cron_overdue_warning($cronoverdue) {
600 global $CFG;
601 if (!$cronoverdue) {
602 return '';
605 if (empty($CFG->cronclionly)) {
606 $url = new moodle_url('/admin/cron.php');
607 if (!empty($CFG->cronremotepassword)) {
608 $url = new moodle_url('/admin/cron.php', array('password' => $CFG->cronremotepassword));
611 return $this->warning(get_string('cronwarning', 'admin', $url->out()) . '&nbsp;' .
612 $this->help_icon('cron', 'admin'));
615 // $CFG->cronclionly is not empty: cron can run only from CLI.
616 return $this->warning(get_string('cronwarningcli', 'admin') . '&nbsp;' .
617 $this->help_icon('cron', 'admin'));
621 * Render an appropriate message if cron is not being run frequently (recommended every minute).
623 * @param bool $croninfrequent
624 * @return string HTML to output.
626 public function cron_infrequent_warning(bool $croninfrequent) : string {
627 global $CFG;
629 if (!$croninfrequent) {
630 return '';
633 $expectedfrequency = $CFG->expectedcronfrequency ?? 200;
634 return $this->warning(get_string('croninfrequent', 'admin', $expectedfrequency) . '&nbsp;' .
635 $this->help_icon('cron', 'admin'));
639 * Render an appropriate message if there are any problems with the DB set-up.
640 * @param bool $dbproblems
641 * @return string HTML to output.
643 public function db_problems($dbproblems) {
644 if (!$dbproblems) {
645 return '';
648 return $this->warning($dbproblems);
652 * Renders cache warnings if there are any.
654 * @param string[] $cachewarnings
655 * @return string
657 public function cache_warnings(array $cachewarnings) {
658 if (!count($cachewarnings)) {
659 return '';
661 return join("\n", array_map(array($this, 'warning'), $cachewarnings));
665 * Renders events 1 API handlers warning.
667 * @param array $eventshandlers
668 * @return string
670 public function events_handlers($eventshandlers) {
671 if ($eventshandlers) {
672 $components = '';
673 foreach ($eventshandlers as $eventhandler) {
674 $components .= $eventhandler->component . ', ';
676 $components = rtrim($components, ', ');
677 return $this->warning(get_string('eventshandlersinuse', 'admin', $components));
682 * Render an appropriate message if the site in in maintenance mode.
683 * @param bool $maintenancemode
684 * @return string HTML to output.
686 public function maintenance_mode_warning($maintenancemode) {
687 if (!$maintenancemode) {
688 return '';
691 $url = new moodle_url('/admin/settings.php', array('section' => 'maintenancemode'));
692 $url = $url->out(); // get_string() does not support objects in params
694 return $this->warning(get_string('sitemaintenancewarning2', 'admin', $url));
698 * Render a warning that ssl is forced because the site was on loginhttps.
700 * @param bool $overridetossl Whether or not ssl is being forced.
701 * @return string
703 protected function overridetossl_warning($overridetossl) {
704 if (!$overridetossl) {
705 return '';
707 $warning = get_string('overridetossl', 'core_admin');
708 return $this->warning($warning, 'warning');
712 * Display a warning about installing development code if necesary.
713 * @param int $maturity
714 * @return string HTML to output.
716 protected function maturity_warning($maturity) {
717 if ($maturity == MATURITY_STABLE) {
718 return ''; // No worries.
721 $maturitylevel = get_string('maturity' . $maturity, 'admin');
722 return $this->warning(
723 $this->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
724 $this->container($this->doc_link('admin/versions', get_string('morehelp'))),
725 'error');
729 * If necessary, displays a warning about upgrading a test site.
731 * @param string $testsite
732 * @return string HTML
734 protected function test_site_warning($testsite) {
736 if (!$testsite) {
737 return '';
740 $warning = (get_string('testsiteupgradewarning', 'admin', $testsite));
741 return $this->warning($warning, 'error');
745 * Output the copyright notice.
746 * @return string HTML to output.
748 protected function moodle_copyright() {
749 global $CFG;
751 //////////////////////////////////////////////////////////////////////////////////////////////////
752 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
753 $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
754 '<a href="http://docs.moodle.org/dev/Releases" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
755 'Copyright &copy; 1999 onwards, Martin Dougiamas<br />'.
756 'and <a href="http://moodle.org/dev">many other contributors</a>.<br />'.
757 '<a href="http://docs.moodle.org/dev/License">GNU Public License</a>';
758 //////////////////////////////////////////////////////////////////////////////////////////////////
760 return $this->box($copyrighttext, 'copyright');
764 * Display a warning about installing development code if necesary.
765 * @param int $maturity
766 * @return string HTML to output.
768 protected function maturity_info($maturity) {
769 if ($maturity == MATURITY_STABLE) {
770 return ''; // No worries.
773 $level = 'warning';
775 if ($maturity == MATURITY_ALPHA) {
776 $level = 'error';
779 $maturitylevel = get_string('maturity' . $maturity, 'admin');
780 $warningtext = get_string('maturitycoreinfo', 'admin', $maturitylevel);
781 $warningtext .= ' ' . $this->doc_link('admin/versions', get_string('morehelp'));
782 return $this->warning($warningtext, $level);
786 * Displays the info about available Moodle core and plugin updates
788 * The structure of the $updates param has changed since 2.4. It contains not only updates
789 * for the core itself, but also for all other installed plugins.
791 * @param array|null $updates array of (string)component => array of \core\update\info objects or null
792 * @param int|null $fetch timestamp of the most recent updates fetch or null (unknown)
793 * @return string
795 protected function available_updates($updates, $fetch) {
797 $updateinfo = '';
798 $someupdateavailable = false;
799 if (is_array($updates)) {
800 if (is_array($updates['core'])) {
801 $someupdateavailable = true;
802 $updateinfo .= $this->heading(get_string('updateavailable', 'core_admin'), 3);
803 foreach ($updates['core'] as $update) {
804 $updateinfo .= $this->moodle_available_update_info($update);
806 $updateinfo .= html_writer::tag('p', get_string('updateavailablerecommendation', 'core_admin'),
807 array('class' => 'updateavailablerecommendation'));
809 unset($updates['core']);
810 // If something has left in the $updates array now, it is updates for plugins.
811 if (!empty($updates)) {
812 $someupdateavailable = true;
813 $updateinfo .= $this->heading(get_string('updateavailableforplugin', 'core_admin'), 3);
814 $pluginsoverviewurl = new moodle_url('/admin/plugins.php', array('updatesonly' => 1));
815 $updateinfo .= $this->container(get_string('pluginsoverviewsee', 'core_admin',
816 array('url' => $pluginsoverviewurl->out())));
820 if (!$someupdateavailable) {
821 $now = time();
822 if ($fetch and ($fetch <= $now) and ($now - $fetch < HOURSECS)) {
823 $updateinfo .= $this->heading(get_string('updateavailablenot', 'core_admin'), 3);
827 $updateinfo .= $this->container_start('checkforupdates mt-1');
828 $fetchurl = new moodle_url('/admin/index.php', array('fetchupdates' => 1, 'sesskey' => sesskey(), 'cache' => 0));
829 $updateinfo .= $this->single_button($fetchurl, get_string('checkforupdates', 'core_plugin'));
830 if ($fetch) {
831 $updateinfo .= $this->container(get_string('checkforupdateslast', 'core_plugin',
832 userdate($fetch, get_string('strftimedatetime', 'core_langconfig'))));
834 $updateinfo .= $this->container_end();
836 return $this->warning($updateinfo);
840 * Display a warning about not being registered on Moodle.org if necesary.
842 * @param boolean $registered true if the site is registered on Moodle.org
843 * @return string HTML to output.
845 protected function registration_warning($registered) {
847 if (!$registered && site_is_public()) {
848 if (has_capability('moodle/site:config', context_system::instance())) {
849 $registerbutton = $this->single_button(new moodle_url('/admin/registration/index.php'),
850 get_string('register', 'admin'));
851 $str = 'registrationwarning';
852 } else {
853 $registerbutton = '';
854 $str = 'registrationwarningcontactadmin';
857 return $this->warning( get_string($str, 'admin')
858 . '&nbsp;' . $this->help_icon('registration', 'admin') . $registerbutton ,
859 'error alert alert-danger');
862 return '';
866 * Return an admin page warning if site is not registered with moodle.org
868 * @return string
870 public function warn_if_not_registered() {
871 return $this->registration_warning(\core\hub\registration::is_registered());
875 * Display a warning about the Mobile Web Services being disabled.
877 * @param boolean $mobileconfigured true if mobile web services are enabled
878 * @return string HTML to output.
880 protected function mobile_configuration_warning($mobileconfigured) {
881 $output = '';
882 if (!$mobileconfigured) {
883 $settingslink = new moodle_url('/admin/settings.php', ['section' => 'mobilesettings']);
884 $configurebutton = $this->single_button($settingslink, get_string('enablemobilewebservice', 'admin'));
885 $output .= $this->warning(get_string('mobilenotconfiguredwarning', 'admin') . '&nbsp;' . $configurebutton);
888 return $output;
892 * Display a warning about the forgotten password URL not linking to a valid URL.
894 * @param boolean $invalidforgottenpasswordurl true if the forgotten password URL is not valid
895 * @return string HTML to output.
897 protected function forgotten_password_url_warning($invalidforgottenpasswordurl) {
898 $output = '';
899 if ($invalidforgottenpasswordurl) {
900 $settingslink = new moodle_url('/admin/settings.php', ['section' => 'manageauths']);
901 $configurebutton = $this->single_button($settingslink, get_string('check', 'moodle'));
902 $output .= $this->warning(get_string('invalidforgottenpasswordurl', 'admin') . '&nbsp;' . $configurebutton,
903 'error alert alert-danger');
906 return $output;
910 * Helper method to render the information about the available Moodle update
912 * @param \core\update\info $updateinfo information about the available Moodle core update
914 protected function moodle_available_update_info(\core\update\info $updateinfo) {
916 $boxclasses = 'moodleupdateinfo mb-2';
917 $info = array();
919 if (isset($updateinfo->release)) {
920 $info[] = html_writer::tag('span', get_string('updateavailable_release', 'core_admin', $updateinfo->release),
921 array('class' => 'info release'));
924 if (isset($updateinfo->version)) {
925 $info[] = html_writer::tag('span', get_string('updateavailable_version', 'core_admin', $updateinfo->version),
926 array('class' => 'info version'));
929 if (isset($updateinfo->maturity)) {
930 $info[] = html_writer::tag('span', get_string('maturity'.$updateinfo->maturity, 'core_admin'),
931 array('class' => 'info maturity'));
932 $boxclasses .= ' maturity'.$updateinfo->maturity;
935 if (isset($updateinfo->download)) {
936 $info[] = html_writer::link($updateinfo->download, get_string('download'),
937 array('class' => 'info download btn btn-secondary'));
940 if (isset($updateinfo->url)) {
941 $info[] = html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin'),
942 array('class' => 'info more'));
945 $box = $this->output->container_start($boxclasses);
946 $box .= $this->output->container(implode(html_writer::tag('span', ' | ', array('class' => 'separator')), $info), '');
947 $box .= $this->output->container_end();
949 return $box;
953 * Display a link to the release notes.
954 * @return string HTML to output.
956 protected function release_notes_link() {
957 $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/dev/Releases');
958 $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
959 return $this->box($releasenoteslink, 'generalbox releasenoteslink');
963 * Display the reload link that appears on several upgrade/install pages.
964 * @return string HTML to output.
966 function upgrade_reload($url) {
967 return html_writer::empty_tag('br') .
968 html_writer::tag('div',
969 html_writer::link($url, $this->pix_icon('i/reload', '', '', array('class' => 'icon icon-pre')) .
970 get_string('reload'), array('title' => get_string('reload'))),
971 array('class' => 'continuebutton')) . html_writer::empty_tag('br');
975 * Displays all known plugins and information about their installation or upgrade
977 * This default implementation renders all plugins into one big table. The rendering
978 * options support:
979 * (bool)full = false: whether to display up-to-date plugins, too
980 * (bool)xdep = false: display the plugins with unsatisified dependecies only
982 * @param core_plugin_manager $pluginman provides information about the plugins.
983 * @param int $version the version of the Moodle code from version.php.
984 * @param array $options rendering options
985 * @return string HTML code
987 public function plugins_check_table(core_plugin_manager $pluginman, $version, array $options = array()) {
989 $plugininfo = $pluginman->get_plugins();
991 if (empty($plugininfo)) {
992 return '';
995 $options['full'] = isset($options['full']) ? (bool)$options['full'] : false;
996 $options['xdep'] = isset($options['xdep']) ? (bool)$options['xdep'] : false;
998 $table = new html_table();
999 $table->id = 'plugins-check';
1000 $table->head = array(
1001 get_string('displayname', 'core_plugin').' / '.get_string('rootdir', 'core_plugin'),
1002 get_string('versiondb', 'core_plugin'),
1003 get_string('versiondisk', 'core_plugin'),
1004 get_string('requires', 'core_plugin'),
1005 get_string('source', 'core_plugin').' / '.get_string('status', 'core_plugin'),
1007 $table->colclasses = array(
1008 'displayname', 'versiondb', 'versiondisk', 'requires', 'status',
1010 $table->data = array();
1012 // Number of displayed plugins per type.
1013 $numdisplayed = array();
1014 // Number of plugins known to the plugin manager.
1015 $sumtotal = 0;
1016 // Number of plugins requiring attention.
1017 $sumattention = 0;
1018 // List of all components we can cancel installation of.
1019 $installabortable = $pluginman->list_cancellable_installations();
1020 // List of all components we can cancel upgrade of.
1021 $upgradeabortable = $pluginman->list_restorable_archives();
1023 foreach ($plugininfo as $type => $plugins) {
1025 $header = new html_table_cell($pluginman->plugintype_name_plural($type));
1026 $header->header = true;
1027 $header->colspan = count($table->head);
1028 $header = new html_table_row(array($header));
1029 $header->attributes['class'] = 'plugintypeheader type-' . $type;
1031 $numdisplayed[$type] = 0;
1033 if (empty($plugins) and $options['full']) {
1034 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
1035 $msg->colspan = count($table->head);
1036 $row = new html_table_row(array($msg));
1037 $row->attributes['class'] .= 'msg msg-noneinstalled';
1038 $table->data[] = $header;
1039 $table->data[] = $row;
1040 continue;
1043 $plugintyperows = array();
1045 foreach ($plugins as $name => $plugin) {
1046 $sumtotal++;
1047 $row = new html_table_row();
1048 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
1050 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name, null)) {
1051 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
1052 } else {
1053 $icon = '';
1056 $displayname = new html_table_cell(
1057 $icon.
1058 html_writer::span($plugin->displayname, 'pluginname').
1059 html_writer::div($plugin->get_dir(), 'plugindir text-muted small')
1062 $versiondb = new html_table_cell($plugin->versiondb);
1063 $versiondisk = new html_table_cell($plugin->versiondisk);
1065 if ($isstandard = $plugin->is_standard()) {
1066 $row->attributes['class'] .= ' standard';
1067 $sourcelabel = html_writer::span(get_string('sourcestd', 'core_plugin'), 'sourcetext badge badge-secondary');
1068 } else {
1069 $row->attributes['class'] .= ' extension';
1070 $sourcelabel = html_writer::span(get_string('sourceext', 'core_plugin'), 'sourcetext badge badge-info');
1073 $coredependency = $plugin->is_core_dependency_satisfied($version);
1074 $otherpluginsdependencies = $pluginman->are_dependencies_satisfied($plugin->get_other_required_plugins());
1075 $dependenciesok = $coredependency && $otherpluginsdependencies;
1077 $statuscode = $plugin->get_status();
1078 $row->attributes['class'] .= ' status-' . $statuscode;
1079 $statusclass = 'statustext badge ';
1080 switch ($statuscode) {
1081 case core_plugin_manager::PLUGIN_STATUS_NEW:
1082 $statusclass .= $dependenciesok ? 'badge-success' : 'badge-warning';
1083 break;
1084 case core_plugin_manager::PLUGIN_STATUS_UPGRADE:
1085 $statusclass .= $dependenciesok ? 'badge-info' : 'badge-warning';
1086 break;
1087 case core_plugin_manager::PLUGIN_STATUS_MISSING:
1088 case core_plugin_manager::PLUGIN_STATUS_DOWNGRADE:
1089 case core_plugin_manager::PLUGIN_STATUS_DELETE:
1090 $statusclass .= 'badge-danger';
1091 break;
1092 case core_plugin_manager::PLUGIN_STATUS_NODB:
1093 case core_plugin_manager::PLUGIN_STATUS_UPTODATE:
1094 $statusclass .= $dependenciesok ? 'badge-light' : 'badge-warning';
1095 break;
1097 $status = html_writer::span(get_string('status_' . $statuscode, 'core_plugin'), $statusclass);
1099 if (!empty($installabortable[$plugin->component])) {
1100 $status .= $this->output->single_button(
1101 new moodle_url($this->page->url, array('abortinstall' => $plugin->component, 'confirmplugincheck' => 0)),
1102 get_string('cancelinstallone', 'core_plugin'),
1103 'post',
1104 array('class' => 'actionbutton cancelinstallone d-block mt-1')
1108 if (!empty($upgradeabortable[$plugin->component])) {
1109 $status .= $this->output->single_button(
1110 new moodle_url($this->page->url, array('abortupgrade' => $plugin->component)),
1111 get_string('cancelupgradeone', 'core_plugin'),
1112 'post',
1113 array('class' => 'actionbutton cancelupgradeone d-block mt-1')
1117 $availableupdates = $plugin->available_updates();
1118 if (!empty($availableupdates)) {
1119 foreach ($availableupdates as $availableupdate) {
1120 $status .= $this->plugin_available_update_info($pluginman, $availableupdate);
1124 $status = new html_table_cell($sourcelabel.' '.$status);
1126 $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version));
1128 $statusisboring = in_array($statuscode, array(
1129 core_plugin_manager::PLUGIN_STATUS_NODB, core_plugin_manager::PLUGIN_STATUS_UPTODATE));
1131 if ($options['xdep']) {
1132 // we want to see only plugins with failed dependencies
1133 if ($dependenciesok) {
1134 continue;
1137 } else if ($statusisboring and $dependenciesok and empty($availableupdates)) {
1138 // no change is going to happen to the plugin - display it only
1139 // if the user wants to see the full list
1140 if (empty($options['full'])) {
1141 continue;
1144 } else {
1145 $sumattention++;
1148 // The plugin should be displayed.
1149 $numdisplayed[$type]++;
1150 $row->cells = array($displayname, $versiondb, $versiondisk, $requires, $status);
1151 $plugintyperows[] = $row;
1154 if (empty($numdisplayed[$type]) and empty($options['full'])) {
1155 continue;
1158 $table->data[] = $header;
1159 $table->data = array_merge($table->data, $plugintyperows);
1162 // Total number of displayed plugins.
1163 $sumdisplayed = array_sum($numdisplayed);
1165 if ($options['xdep']) {
1166 // At the plugins dependencies check page, display the table only.
1167 return html_writer::table($table);
1170 $out = $this->output->container_start('', 'plugins-check-info');
1172 if ($sumdisplayed == 0) {
1173 $out .= $this->output->heading(get_string('pluginchecknone', 'core_plugin'));
1175 } else {
1176 if (empty($options['full'])) {
1177 $out .= $this->output->heading(get_string('plugincheckattention', 'core_plugin'));
1178 } else {
1179 $out .= $this->output->heading(get_string('plugincheckall', 'core_plugin'));
1183 $out .= $this->output->container_start('actions mb-2');
1185 $installableupdates = $pluginman->filter_installable($pluginman->available_updates());
1186 if ($installableupdates) {
1187 $out .= $this->output->single_button(
1188 new moodle_url($this->page->url, array('installupdatex' => 1)),
1189 get_string('updateavailableinstallall', 'core_admin', count($installableupdates)),
1190 'post',
1191 array('class' => 'singlebutton updateavailableinstallall mr-1')
1195 if ($installabortable) {
1196 $out .= $this->output->single_button(
1197 new moodle_url($this->page->url, array('abortinstallx' => 1, 'confirmplugincheck' => 0)),
1198 get_string('cancelinstallall', 'core_plugin', count($installabortable)),
1199 'post',
1200 array('class' => 'singlebutton cancelinstallall mr-1')
1204 if ($upgradeabortable) {
1205 $out .= $this->output->single_button(
1206 new moodle_url($this->page->url, array('abortupgradex' => 1)),
1207 get_string('cancelupgradeall', 'core_plugin', count($upgradeabortable)),
1208 'post',
1209 array('class' => 'singlebutton cancelupgradeall mr-1')
1213 $out .= html_writer::div(html_writer::link(new moodle_url($this->page->url, array('showallplugins' => 0)),
1214 get_string('plugincheckattention', 'core_plugin')).' '.html_writer::span($sumattention, 'badge badge-light'),
1215 'btn btn-link mr-1');
1217 $out .= html_writer::div(html_writer::link(new moodle_url($this->page->url, array('showallplugins' => 1)),
1218 get_string('plugincheckall', 'core_plugin')).' '.html_writer::span($sumtotal, 'badge badge-light'),
1219 'btn btn-link mr-1');
1221 $out .= $this->output->container_end(); // End of .actions container.
1222 $out .= $this->output->container_end(); // End of #plugins-check-info container.
1224 if ($sumdisplayed > 0 or $options['full']) {
1225 $out .= html_writer::table($table);
1228 return $out;
1232 * Display the continue / cancel widgets for the plugins management pages.
1234 * @param null|moodle_url $continue URL for the continue button, should it be displayed
1235 * @param null|moodle_url $cancel URL for the cancel link, defaults to the current page
1236 * @return string HTML
1238 public function plugins_management_confirm_buttons(moodle_url $continue=null, moodle_url $cancel=null) {
1240 $out = html_writer::start_div('plugins-management-confirm-buttons');
1242 if (!empty($continue)) {
1243 $out .= $this->output->single_button($continue, get_string('continue'), 'post', array('class' => 'continue'));
1246 if (empty($cancel)) {
1247 $cancel = $this->page->url;
1249 $out .= html_writer::div(html_writer::link($cancel, get_string('cancel')), 'cancel');
1251 return $out;
1255 * Displays the information about missing dependencies
1257 * @param core_plugin_manager $pluginman
1258 * @return string
1260 protected function missing_dependencies(core_plugin_manager $pluginman) {
1262 $dependencies = $pluginman->missing_dependencies();
1264 if (empty($dependencies)) {
1265 return '';
1268 $available = array();
1269 $unavailable = array();
1270 $unknown = array();
1272 foreach ($dependencies as $component => $remoteinfo) {
1273 if ($remoteinfo === false) {
1274 // The required version is not available. Let us check if there
1275 // is at least some version in the plugins directory.
1276 $remoteinfoanyversion = $pluginman->get_remote_plugin_info($component, ANY_VERSION, false);
1277 if ($remoteinfoanyversion === false) {
1278 $unknown[$component] = $component;
1279 } else {
1280 $unavailable[$component] = $remoteinfoanyversion;
1282 } else {
1283 $available[$component] = $remoteinfo;
1287 $out = $this->output->container_start('plugins-check-dependencies mb-4');
1289 if ($unavailable or $unknown) {
1290 $out .= $this->output->heading(get_string('misdepsunavail', 'core_plugin'));
1291 if ($unknown) {
1292 $out .= $this->output->render((new \core\output\notification(get_string('misdepsunknownlist', 'core_plugin',
1293 implode(', ', $unknown))))->set_show_closebutton(false));
1295 if ($unavailable) {
1296 $unavailablelist = array();
1297 foreach ($unavailable as $component => $remoteinfoanyversion) {
1298 $unavailablelistitem = html_writer::link('https://moodle.org/plugins/view.php?plugin='.$component,
1299 '<strong>'.$remoteinfoanyversion->name.'</strong>');
1300 if ($remoteinfoanyversion->version) {
1301 $unavailablelistitem .= ' ('.$component.' &gt; '.$remoteinfoanyversion->version->version.')';
1302 } else {
1303 $unavailablelistitem .= ' ('.$component.')';
1305 $unavailablelist[] = $unavailablelistitem;
1307 $out .= $this->output->render((new \core\output\notification(get_string('misdepsunavaillist', 'core_plugin',
1308 implode(', ', $unavailablelist))))->set_show_closebutton(false));
1310 $out .= $this->output->container_start('plugins-check-dependencies-actions mb-4');
1311 $out .= ' '.html_writer::link(new moodle_url('/admin/tool/installaddon/'),
1312 get_string('dependencyuploadmissing', 'core_plugin'), array('class' => 'btn btn-secondary'));
1313 $out .= $this->output->container_end(); // End of .plugins-check-dependencies-actions container.
1316 if ($available) {
1317 $out .= $this->output->heading(get_string('misdepsavail', 'core_plugin'));
1318 $out .= $this->output->container_start('plugins-check-dependencies-actions mb-2');
1320 $installable = $pluginman->filter_installable($available);
1321 if ($installable) {
1322 $out .= $this->output->single_button(
1323 new moodle_url($this->page->url, array('installdepx' => 1)),
1324 get_string('dependencyinstallmissing', 'core_plugin', count($installable)),
1325 'post',
1326 array('class' => 'singlebutton dependencyinstallmissing d-inline-block mr-1')
1330 $out .= html_writer::div(html_writer::link(new moodle_url('/admin/tool/installaddon/'),
1331 get_string('dependencyuploadmissing', 'core_plugin'), array('class' => 'btn btn-link')),
1332 'dependencyuploadmissing d-inline-block mr-1');
1334 $out .= $this->output->container_end(); // End of .plugins-check-dependencies-actions container.
1336 $out .= $this->available_missing_dependencies_list($pluginman, $available);
1339 $out .= $this->output->container_end(); // End of .plugins-check-dependencies container.
1341 return $out;
1345 * Displays the list if available missing dependencies.
1347 * @param core_plugin_manager $pluginman
1348 * @param array $dependencies
1349 * @return string
1351 protected function available_missing_dependencies_list(core_plugin_manager $pluginman, array $dependencies) {
1352 global $CFG;
1354 $table = new html_table();
1355 $table->id = 'plugins-check-available-dependencies';
1356 $table->head = array(
1357 get_string('displayname', 'core_plugin'),
1358 get_string('release', 'core_plugin'),
1359 get_string('version', 'core_plugin'),
1360 get_string('supportedmoodleversions', 'core_plugin'),
1361 get_string('info', 'core'),
1363 $table->colclasses = array('displayname', 'release', 'version', 'supportedmoodleversions', 'info');
1364 $table->data = array();
1366 foreach ($dependencies as $plugin) {
1368 $supportedmoodles = array();
1369 foreach ($plugin->version->supportedmoodles as $moodle) {
1370 if ($CFG->branch == str_replace('.', '', $moodle->release)) {
1371 $supportedmoodles[] = html_writer::span($moodle->release, 'badge badge-success');
1372 } else {
1373 $supportedmoodles[] = html_writer::span($moodle->release, 'badge badge-light');
1377 $requriedby = $pluginman->other_plugins_that_require($plugin->component);
1378 if ($requriedby) {
1379 foreach ($requriedby as $ix => $val) {
1380 $inf = $pluginman->get_plugin_info($val);
1381 if ($inf) {
1382 $requriedby[$ix] = $inf->displayname.' ('.$inf->component.')';
1385 $info = html_writer::div(
1386 get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
1387 'requiredby mb-1'
1389 } else {
1390 $info = '';
1393 $info .= $this->output->container_start('actions');
1395 $info .= html_writer::div(
1396 html_writer::link('https://moodle.org/plugins/view.php?plugin='.$plugin->component,
1397 get_string('misdepinfoplugin', 'core_plugin')),
1398 'misdepinfoplugin d-inline-block mr-3 mb-1'
1401 $info .= html_writer::div(
1402 html_writer::link('https://moodle.org/plugins/pluginversion.php?id='.$plugin->version->id,
1403 get_string('misdepinfoversion', 'core_plugin')),
1404 'misdepinfoversion d-inline-block mr-3 mb-1'
1407 $info .= html_writer::div(html_writer::link($plugin->version->downloadurl, get_string('download')),
1408 'misdepdownload d-inline-block mr-3 mb-1');
1410 if ($pluginman->is_remote_plugin_installable($plugin->component, $plugin->version->version, $reason)) {
1411 $info .= $this->output->single_button(
1412 new moodle_url($this->page->url, array('installdep' => $plugin->component)),
1413 get_string('dependencyinstall', 'core_plugin'),
1414 'post',
1415 array('class' => 'singlebutton dependencyinstall mr-3 mb-1')
1417 } else {
1418 $reasonhelp = $this->info_remote_plugin_not_installable($reason);
1419 if ($reasonhelp) {
1420 $info .= html_writer::div($reasonhelp, 'reasonhelp dependencyinstall d-inline-block mr-3 mb-1');
1424 $info .= $this->output->container_end(); // End of .actions container.
1426 $table->data[] = array(
1427 html_writer::div($plugin->name, 'name').' '.html_writer::div($plugin->component, 'component text-muted small'),
1428 $plugin->version->release,
1429 $plugin->version->version,
1430 implode(' ', $supportedmoodles),
1431 $info
1435 return html_writer::table($table);
1439 * Explain why {@link core_plugin_manager::is_remote_plugin_installable()} returned false.
1441 * @param string $reason the reason code as returned by the plugin manager
1442 * @return string
1444 protected function info_remote_plugin_not_installable($reason) {
1446 if ($reason === 'notwritableplugintype' or $reason === 'notwritableplugin') {
1447 return $this->output->help_icon('notwritable', 'core_plugin', get_string('notwritable', 'core_plugin'));
1450 if ($reason === 'remoteunavailable') {
1451 return $this->output->help_icon('notdownloadable', 'core_plugin', get_string('notdownloadable', 'core_plugin'));
1454 return false;
1458 * Formats the information that needs to go in the 'Requires' column.
1459 * @param \core\plugininfo\base $plugin the plugin we are rendering the row for.
1460 * @param core_plugin_manager $pluginman provides data on all the plugins.
1461 * @param string $version
1462 * @return string HTML code
1464 protected function required_column(\core\plugininfo\base $plugin, core_plugin_manager $pluginman, $version) {
1466 $requires = array();
1467 $displayuploadlink = false;
1468 $displayupdateslink = false;
1470 foreach ($pluginman->resolve_requirements($plugin, $version) as $reqname => $reqinfo) {
1471 if ($reqname === 'core') {
1472 if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OK) {
1473 $class = 'requires-ok text-muted';
1474 $label = '';
1475 } else {
1476 $class = 'requires-failed';
1477 $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'badge badge-danger');
1479 if ($reqinfo->reqver != ANY_VERSION) {
1480 $requires[] = html_writer::tag('li',
1481 html_writer::span(get_string('moodleversion', 'core_plugin', $plugin->versionrequires), 'dep dep-core').
1482 ' '.$label, array('class' => $class));
1485 } else {
1486 $actions = array();
1488 if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OK) {
1489 $label = '';
1490 $class = 'requires-ok text-muted';
1492 } else if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_MISSING) {
1493 if ($reqinfo->availability == $pluginman::REQUIREMENT_AVAILABLE) {
1494 $label = html_writer::span(get_string('dependencymissing', 'core_plugin'), 'badge badge-warning');
1495 $label .= ' '.html_writer::span(get_string('dependencyavailable', 'core_plugin'), 'badge badge-warning');
1496 $class = 'requires-failed requires-missing requires-available';
1497 $actions[] = html_writer::link(
1498 new moodle_url('https://moodle.org/plugins/view.php', array('plugin' => $reqname)),
1499 get_string('misdepinfoplugin', 'core_plugin')
1502 } else {
1503 $label = html_writer::span(get_string('dependencymissing', 'core_plugin'), 'badge badge-danger');
1504 $label .= ' '.html_writer::span(get_string('dependencyunavailable', 'core_plugin'),
1505 'badge badge-danger');
1506 $class = 'requires-failed requires-missing requires-unavailable';
1508 $displayuploadlink = true;
1510 } else if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OUTDATED) {
1511 if ($reqinfo->availability == $pluginman::REQUIREMENT_AVAILABLE) {
1512 $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'badge badge-warning');
1513 $label .= ' '.html_writer::span(get_string('dependencyavailable', 'core_plugin'), 'badge badge-warning');
1514 $class = 'requires-failed requires-outdated requires-available';
1515 $displayupdateslink = true;
1517 } else {
1518 $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'badge badge-danger');
1519 $label .= ' '.html_writer::span(get_string('dependencyunavailable', 'core_plugin'),
1520 'badge badge-danger');
1521 $class = 'requires-failed requires-outdated requires-unavailable';
1523 $displayuploadlink = true;
1526 if ($reqinfo->reqver != ANY_VERSION) {
1527 $str = 'otherpluginversion';
1528 } else {
1529 $str = 'otherplugin';
1532 $requires[] = html_writer::tag('li', html_writer::span(
1533 get_string($str, 'core_plugin', array('component' => $reqname, 'version' => $reqinfo->reqver)),
1534 'dep dep-plugin').' '.$label.' '.html_writer::span(implode(' | ', $actions), 'actions'),
1535 array('class' => $class)
1540 if (!$requires) {
1541 return '';
1544 $out = html_writer::tag('ul', implode("\n", $requires), array('class' => 'm-0'));
1546 if ($displayuploadlink) {
1547 $out .= html_writer::div(
1548 html_writer::link(
1549 new moodle_url('/admin/tool/installaddon/'),
1550 get_string('dependencyuploadmissing', 'core_plugin'),
1551 array('class' => 'btn btn-secondary btn-sm m-1')
1553 'dependencyuploadmissing'
1557 if ($displayupdateslink) {
1558 $out .= html_writer::div(
1559 html_writer::link(
1560 new moodle_url($this->page->url, array('sesskey' => sesskey(), 'fetchupdates' => 1)),
1561 get_string('checkforupdates', 'core_plugin'),
1562 array('class' => 'btn btn-secondary btn-sm m-1')
1564 'checkforupdates'
1568 return $out;
1573 * Prints an overview about the plugins - number of installed, number of extensions etc.
1575 * @param core_plugin_manager $pluginman provides information about the plugins
1576 * @param array $options filtering options
1577 * @return string as usually
1579 public function plugins_overview_panel(core_plugin_manager $pluginman, array $options = array()) {
1581 $plugininfo = $pluginman->get_plugins();
1583 $numtotal = $numextension = $numupdatable = 0;
1585 foreach ($plugininfo as $type => $plugins) {
1586 foreach ($plugins as $name => $plugin) {
1587 if ($plugin->available_updates()) {
1588 $numupdatable++;
1590 if ($plugin->get_status() === core_plugin_manager::PLUGIN_STATUS_MISSING) {
1591 continue;
1593 $numtotal++;
1594 if (!$plugin->is_standard()) {
1595 $numextension++;
1600 $infoall = html_writer::link(
1601 new moodle_url($this->page->url, array('contribonly' => 0, 'updatesonly' => 0)),
1602 get_string('overviewall', 'core_plugin'),
1603 array('title' => get_string('filterall', 'core_plugin'))
1604 ).' '.html_writer::span($numtotal, 'badge number number-all');
1606 $infoext = html_writer::link(
1607 new moodle_url($this->page->url, array('contribonly' => 1, 'updatesonly' => 0)),
1608 get_string('overviewext', 'core_plugin'),
1609 array('title' => get_string('filtercontribonly', 'core_plugin'))
1610 ).' '.html_writer::span($numextension, 'badge number number-additional');
1612 if ($numupdatable) {
1613 $infoupdatable = html_writer::link(
1614 new moodle_url($this->page->url, array('contribonly' => 0, 'updatesonly' => 1)),
1615 get_string('overviewupdatable', 'core_plugin'),
1616 array('title' => get_string('filterupdatesonly', 'core_plugin'))
1617 ).' '.html_writer::span($numupdatable, 'badge badge-info number number-updatable');
1618 } else {
1619 // No updates, or the notifications disabled.
1620 $infoupdatable = '';
1623 $out = html_writer::start_div('', array('id' => 'plugins-overview-panel'));
1625 if (!empty($options['updatesonly'])) {
1626 $out .= $this->output->heading(get_string('overviewupdatable', 'core_plugin'), 3);
1627 } else if (!empty($options['contribonly'])) {
1628 $out .= $this->output->heading(get_string('overviewext', 'core_plugin'), 3);
1631 if ($numupdatable) {
1632 $installableupdates = $pluginman->filter_installable($pluginman->available_updates());
1633 if ($installableupdates) {
1634 $out .= $this->output->single_button(
1635 new moodle_url($this->page->url, array('installupdatex' => 1)),
1636 get_string('updateavailableinstallall', 'core_admin', count($installableupdates)),
1637 'post',
1638 array('class' => 'singlebutton updateavailableinstallall')
1643 $out .= html_writer::div($infoall, 'info info-all').
1644 html_writer::div($infoext, 'info info-ext').
1645 html_writer::div($infoupdatable, 'info info-updatable');
1647 $out .= html_writer::end_div(); // End of #plugins-overview-panel block.
1649 return $out;
1653 * Displays all known plugins and links to manage them
1655 * This default implementation renders all plugins into one big table.
1657 * @param core_plugin_manager $pluginman provides information about the plugins.
1658 * @param array $options filtering options
1659 * @return string HTML code
1661 public function plugins_control_panel(core_plugin_manager $pluginman, array $options = array()) {
1663 $plugininfo = $pluginman->get_plugins();
1665 // Filter the list of plugins according the options.
1666 if (!empty($options['updatesonly'])) {
1667 $updateable = array();
1668 foreach ($plugininfo as $plugintype => $pluginnames) {
1669 foreach ($pluginnames as $pluginname => $pluginfo) {
1670 $pluginavailableupdates = $pluginfo->available_updates();
1671 if (!empty($pluginavailableupdates)) {
1672 foreach ($pluginavailableupdates as $pluginavailableupdate) {
1673 $updateable[$plugintype][$pluginname] = $pluginfo;
1678 $plugininfo = $updateable;
1681 if (!empty($options['contribonly'])) {
1682 $contribs = array();
1683 foreach ($plugininfo as $plugintype => $pluginnames) {
1684 foreach ($pluginnames as $pluginname => $pluginfo) {
1685 if (!$pluginfo->is_standard()) {
1686 $contribs[$plugintype][$pluginname] = $pluginfo;
1690 $plugininfo = $contribs;
1693 if (empty($plugininfo)) {
1694 return '';
1697 $table = new html_table();
1698 $table->id = 'plugins-control-panel';
1699 $table->head = array(
1700 get_string('displayname', 'core_plugin'),
1701 get_string('version', 'core_plugin'),
1702 get_string('availability', 'core_plugin'),
1703 get_string('actions', 'core_plugin'),
1704 get_string('notes','core_plugin'),
1706 $table->headspan = array(1, 1, 1, 2, 1);
1707 $table->colclasses = array(
1708 'pluginname', 'version', 'availability', 'settings', 'uninstall', 'notes'
1711 foreach ($plugininfo as $type => $plugins) {
1712 $heading = $pluginman->plugintype_name_plural($type);
1713 $pluginclass = core_plugin_manager::resolve_plugininfo_class($type);
1714 if ($manageurl = $pluginclass::get_manage_url()) {
1715 $heading .= $this->output->action_icon($manageurl, new pix_icon('i/settings',
1716 get_string('settings', 'core_plugin')));
1718 $header = new html_table_cell(html_writer::tag('span', $heading, array('id'=>'plugin_type_cell_'.$type)));
1719 $header->header = true;
1720 $header->colspan = array_sum($table->headspan);
1721 $header = new html_table_row(array($header));
1722 $header->attributes['class'] = 'plugintypeheader type-' . $type;
1723 $table->data[] = $header;
1725 if (empty($plugins)) {
1726 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
1727 $msg->colspan = array_sum($table->headspan);
1728 $row = new html_table_row(array($msg));
1729 $row->attributes['class'] .= 'msg msg-noneinstalled';
1730 $table->data[] = $row;
1731 continue;
1734 foreach ($plugins as $name => $plugin) {
1735 $row = new html_table_row();
1736 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
1738 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name, null)) {
1739 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'icon pluginicon'));
1740 } else {
1741 $icon = $this->output->spacer();
1743 $status = $plugin->get_status();
1744 $row->attributes['class'] .= ' status-'.$status;
1745 $pluginname = html_writer::tag('div', $icon.$plugin->displayname, array('class' => 'displayname')).
1746 html_writer::tag('div', $plugin->component, array('class' => 'componentname'));
1747 $pluginname = new html_table_cell($pluginname);
1749 $version = html_writer::div($plugin->versiondb, 'versionnumber');
1750 if ((string)$plugin->release !== '') {
1751 $version = html_writer::div($plugin->release, 'release').$version;
1753 $version = new html_table_cell($version);
1755 $isenabled = $plugin->is_enabled();
1756 if (is_null($isenabled)) {
1757 $availability = new html_table_cell('');
1758 } else if ($isenabled) {
1759 $row->attributes['class'] .= ' enabled';
1760 $availability = new html_table_cell(get_string('pluginenabled', 'core_plugin'));
1761 } else {
1762 $row->attributes['class'] .= ' disabled';
1763 $availability = new html_table_cell(get_string('plugindisabled', 'core_plugin'));
1766 $settingsurl = $plugin->get_settings_url();
1767 if (!is_null($settingsurl)) {
1768 $settings = html_writer::link($settingsurl, get_string('settings', 'core_plugin'), array('class' => 'settings'));
1769 } else {
1770 $settings = '';
1772 $settings = new html_table_cell($settings);
1774 if ($uninstallurl = $pluginman->get_uninstall_url($plugin->component, 'overview')) {
1775 $uninstall = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin'));
1776 } else {
1777 $uninstall = '';
1779 $uninstall = new html_table_cell($uninstall);
1781 if ($plugin->is_standard()) {
1782 $row->attributes['class'] .= ' standard';
1783 $source = '';
1784 } else {
1785 $row->attributes['class'] .= ' extension';
1786 $source = html_writer::div(get_string('sourceext', 'core_plugin'), 'source badge badge-info');
1789 if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) {
1790 $msg = html_writer::div(get_string('status_missing', 'core_plugin'), 'statusmsg badge badge-danger');
1791 } else if ($status === core_plugin_manager::PLUGIN_STATUS_NEW) {
1792 $msg = html_writer::div(get_string('status_new', 'core_plugin'), 'statusmsg badge badge-success');
1793 } else {
1794 $msg = '';
1797 $requriedby = $pluginman->other_plugins_that_require($plugin->component);
1798 if ($requriedby) {
1799 $requiredby = html_writer::tag('div', get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
1800 array('class' => 'requiredby'));
1801 } else {
1802 $requiredby = '';
1805 $updateinfo = '';
1806 if (is_array($plugin->available_updates())) {
1807 foreach ($plugin->available_updates() as $availableupdate) {
1808 $updateinfo .= $this->plugin_available_update_info($pluginman, $availableupdate);
1812 $notes = new html_table_cell($source.$msg.$requiredby.$updateinfo);
1814 $row->cells = array(
1815 $pluginname, $version, $availability, $settings, $uninstall, $notes
1817 $table->data[] = $row;
1821 return html_writer::table($table);
1825 * Helper method to render the information about the available plugin update
1827 * @param core_plugin_manager $pluginman plugin manager instance
1828 * @param \core\update\info $updateinfo information about the available update for the plugin
1830 protected function plugin_available_update_info(core_plugin_manager $pluginman, \core\update\info $updateinfo) {
1832 $boxclasses = 'pluginupdateinfo';
1833 $info = array();
1835 if (isset($updateinfo->release)) {
1836 $info[] = html_writer::div(
1837 get_string('updateavailable_release', 'core_plugin', $updateinfo->release),
1838 'info release'
1842 if (isset($updateinfo->maturity)) {
1843 $info[] = html_writer::div(
1844 get_string('maturity'.$updateinfo->maturity, 'core_admin'),
1845 'info maturity'
1847 $boxclasses .= ' maturity'.$updateinfo->maturity;
1850 if (isset($updateinfo->download)) {
1851 $info[] = html_writer::div(
1852 html_writer::link($updateinfo->download, get_string('download')),
1853 'info download'
1857 if (isset($updateinfo->url)) {
1858 $info[] = html_writer::div(
1859 html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin')),
1860 'info more'
1864 $box = html_writer::start_div($boxclasses);
1865 $box .= html_writer::div(
1866 get_string('updateavailable', 'core_plugin', $updateinfo->version),
1867 'version'
1869 $box .= html_writer::div(
1870 implode(html_writer::span(' ', 'separator'), $info),
1871 'infos'
1874 if ($pluginman->is_remote_plugin_installable($updateinfo->component, $updateinfo->version, $reason)) {
1875 $box .= $this->output->single_button(
1876 new moodle_url($this->page->url, array('installupdate' => $updateinfo->component,
1877 'installupdateversion' => $updateinfo->version)),
1878 get_string('updateavailableinstall', 'core_admin'),
1879 'post',
1880 array('class' => 'singlebutton updateavailableinstall')
1882 } else {
1883 $reasonhelp = $this->info_remote_plugin_not_installable($reason);
1884 if ($reasonhelp) {
1885 $box .= html_writer::div($reasonhelp, 'reasonhelp updateavailableinstall');
1888 $box .= html_writer::end_div();
1890 return $box;
1894 * This function will render one beautiful table with all the environmental
1895 * configuration and how it suits Moodle needs.
1897 * @param boolean $result final result of the check (true/false)
1898 * @param environment_results[] $environment_results array of results gathered
1899 * @return string HTML to output.
1901 public function environment_check_table($result, $environment_results) {
1902 global $CFG;
1904 // Table headers
1905 $servertable = new html_table();//table for server checks
1906 $servertable->head = array(
1907 get_string('name'),
1908 get_string('info'),
1909 get_string('report'),
1910 get_string('plugin'),
1911 get_string('status'),
1913 $servertable->colclasses = array('centeralign name', 'centeralign info', 'leftalign report', 'leftalign plugin', 'centeralign status');
1914 $servertable->attributes['class'] = 'admintable environmenttable generaltable';
1915 $servertable->id = 'serverstatus';
1917 $serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
1919 $othertable = new html_table();//table for custom checks
1920 $othertable->head = array(
1921 get_string('info'),
1922 get_string('report'),
1923 get_string('plugin'),
1924 get_string('status'),
1926 $othertable->colclasses = array('aligncenter info', 'alignleft report', 'alignleft plugin', 'aligncenter status');
1927 $othertable->attributes['class'] = 'admintable environmenttable generaltable';
1928 $othertable->id = 'otherserverstatus';
1930 $otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
1932 // Iterate over each environment_result
1933 $continue = true;
1934 foreach ($environment_results as $environment_result) {
1935 $errorline = false;
1936 $warningline = false;
1937 $stringtouse = '';
1938 if ($continue) {
1939 $type = $environment_result->getPart();
1940 $info = $environment_result->getInfo();
1941 $status = $environment_result->getStatus();
1942 $plugin = $environment_result->getPluginName();
1943 $error_code = $environment_result->getErrorCode();
1944 // Process Report field
1945 $rec = new stdClass();
1946 // Something has gone wrong at parsing time
1947 if ($error_code) {
1948 $stringtouse = 'environmentxmlerror';
1949 $rec->error_code = $error_code;
1950 $status = get_string('error');
1951 $errorline = true;
1952 $continue = false;
1955 if ($continue) {
1956 if ($rec->needed = $environment_result->getNeededVersion()) {
1957 // We are comparing versions
1958 $rec->current = $environment_result->getCurrentVersion();
1959 if ($environment_result->getLevel() == 'required') {
1960 $stringtouse = 'environmentrequireversion';
1961 } else {
1962 $stringtouse = 'environmentrecommendversion';
1965 } else if ($environment_result->getPart() == 'custom_check') {
1966 // We are checking installed & enabled things
1967 if ($environment_result->getLevel() == 'required') {
1968 $stringtouse = 'environmentrequirecustomcheck';
1969 } else {
1970 $stringtouse = 'environmentrecommendcustomcheck';
1973 } else if ($environment_result->getPart() == 'php_setting') {
1974 if ($status) {
1975 $stringtouse = 'environmentsettingok';
1976 } else if ($environment_result->getLevel() == 'required') {
1977 $stringtouse = 'environmentmustfixsetting';
1978 } else {
1979 $stringtouse = 'environmentshouldfixsetting';
1982 } else {
1983 if ($environment_result->getLevel() == 'required') {
1984 $stringtouse = 'environmentrequireinstall';
1985 } else {
1986 $stringtouse = 'environmentrecommendinstall';
1990 // Calculate the status value
1991 if ($environment_result->getBypassStr() != '') { //Handle bypassed result (warning)
1992 $status = get_string('bypassed');
1993 $warningline = true;
1994 } else if ($environment_result->getRestrictStr() != '') { //Handle restricted result (error)
1995 $status = get_string('restricted');
1996 $errorline = true;
1997 } else {
1998 if ($status) { //Handle ok result (ok)
1999 $status = get_string('ok');
2000 } else {
2001 if ($environment_result->getLevel() == 'optional') {//Handle check result (warning)
2002 $status = get_string('check');
2003 $warningline = true;
2004 } else { //Handle error result (error)
2005 $status = get_string('check');
2006 $errorline = true;
2012 // Build the text
2013 $linkparts = array();
2014 $linkparts[] = 'admin/environment';
2015 $linkparts[] = $type;
2016 if (!empty($info)){
2017 $linkparts[] = $info;
2019 // Plugin environments do not have docs pages yet.
2020 if (empty($CFG->docroot) or $environment_result->plugin) {
2021 $report = get_string($stringtouse, 'admin', $rec);
2022 } else {
2023 $report = $this->doc_link(join('/', $linkparts), get_string($stringtouse, 'admin', $rec), true);
2025 // Enclose report text in div so feedback text will be displayed underneath it.
2026 $report = html_writer::div($report);
2028 // Format error or warning line
2029 if ($errorline) {
2030 $messagetype = 'error';
2031 $statusclass = 'badge-danger';
2032 } else if ($warningline) {
2033 $messagetype = 'warn';
2034 $statusclass = 'badge-warning';
2035 } else {
2036 $messagetype = 'ok';
2037 $statusclass = 'badge-success';
2039 $status = html_writer::span($status, 'badge ' . $statusclass);
2040 // Here we'll store all the feedback found
2041 $feedbacktext = '';
2042 // Append the feedback if there is some
2043 $feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), $messagetype);
2044 //Append the bypass if there is some
2045 $feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'warn');
2046 //Append the restrict if there is some
2047 $feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'error');
2049 $report .= $feedbacktext;
2051 // Add the row to the table
2052 if ($environment_result->getPart() == 'custom_check'){
2053 $otherdata[$messagetype][] = array ($info, $report, $plugin, $status);
2054 } else {
2055 $serverdata[$messagetype][] = array ($type, $info, $report, $plugin, $status);
2060 //put errors first in
2061 $servertable->data = array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']);
2062 $othertable->data = array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']);
2064 // Print table
2065 $output = '';
2066 $output .= $this->heading(get_string('serverchecks', 'admin'));
2067 $output .= html_writer::table($servertable);
2068 if (count($othertable->data)){
2069 $output .= $this->heading(get_string('customcheck', 'admin'));
2070 $output .= html_writer::table($othertable);
2073 // Finally, if any error has happened, print the summary box
2074 if (!$result) {
2075 $output .= $this->box(get_string('environmenterrortodo', 'admin'), 'environmentbox errorbox');
2078 return $output;
2082 * Render a simple page for providing the upgrade key.
2084 * @param moodle_url|string $url
2085 * @return string
2087 public function upgradekey_form_page($url) {
2089 $output = '';
2090 $output .= $this->header();
2091 $output .= $this->container_start('upgradekeyreq');
2092 $output .= $this->heading(get_string('upgradekeyreq', 'core_admin'));
2093 $output .= html_writer::start_tag('form', array('method' => 'POST', 'action' => $url));
2094 $output .= html_writer::empty_tag('input', array('name' => 'upgradekey', 'type' => 'password'));
2095 $output .= html_writer::empty_tag('input', array('value' => get_string('submit'), 'type' => 'submit'));
2096 $output .= html_writer::end_tag('form');
2097 $output .= $this->container_end();
2098 $output .= $this->footer();
2100 return $output;
2104 * Check to see if writing to the deprecated legacy log store is enabled.
2106 * @return string An error message if writing to the legacy log store is enabled.
2108 protected function legacy_log_store_writing_error() {
2109 $enabled = get_config('logstore_legacy', 'loglegacy');
2110 $plugins = explode(',', get_config('tool_log', 'enabled_stores'));
2111 $enabled = $enabled && in_array('logstore_legacy', $plugins);
2113 if ($enabled) {
2114 return $this->warning(get_string('legacylogginginuse'));
2119 * Display message about the benefits of registering on Moodle.org
2121 * @return string
2123 public function moodleorg_registration_message() {
2125 $out = format_text(get_string('registerwithmoodleorginfo', 'core_hub'), FORMAT_MARKDOWN);
2127 $out .= html_writer::link(
2128 new moodle_url('/admin/settings.php', ['section' => 'moodleservices']),
2129 $this->output->pix_icon('i/info', '').' '.get_string('registerwithmoodleorginfoapp', 'core_hub'),
2130 ['class' => 'btn btn-link', 'role' => 'opener', 'target' => '_href']
2133 $out .= html_writer::link(
2134 HUB_MOODLEORGHUBURL,
2135 $this->output->pix_icon('i/stats', '').' '.get_string('registerwithmoodleorginfostats', 'core_hub'),
2136 ['class' => 'btn btn-link', 'role' => 'opener', 'target' => '_href']
2139 $out .= html_writer::link(
2140 HUB_MOODLEORGHUBURL.'/sites',
2141 $this->output->pix_icon('i/location', '').' '.get_string('registerwithmoodleorginfosites', 'core_hub'),
2142 ['class' => 'btn btn-link', 'role' => 'opener', 'target' => '_href']
2145 return $this->output->box($out);