MDL-67795 contentbank: new external for deleting content
[moodle.git] / admin / renderer.php
blobf9043524f9153f0b85db53207c99710c09a576e8
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 '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
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');
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), 'lasttimefetched');
373 $output .= $this->container_end();
376 return $output;
380 * Display a page to confirm the plugin uninstallation.
382 * @param core_plugin_manager $pluginman
383 * @param \core\plugininfo\base $pluginfo
384 * @param moodle_url $continueurl URL to continue after confirmation
385 * @param moodle_url $cancelurl URL to to go if cancelled
386 * @return string
388 public function plugin_uninstall_confirm_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, moodle_url $continueurl, moodle_url $cancelurl) {
389 $output = '';
391 $pluginname = $pluginman->plugin_name($pluginfo->component);
393 $confirm = '<p>' . get_string('uninstallconfirm', 'core_plugin', array('name' => $pluginname)) . '</p>';
394 if ($extraconfirm = $pluginfo->get_uninstall_extra_warning()) {
395 $confirm .= $extraconfirm;
398 $output .= $this->output->header();
399 $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
400 $output .= $this->output->confirm($confirm, $continueurl, $cancelurl);
401 $output .= $this->output->footer();
403 return $output;
407 * Display a page with results of plugin uninstallation and offer removal of plugin files.
409 * @param core_plugin_manager $pluginman
410 * @param \core\plugininfo\base $pluginfo
411 * @param progress_trace_buffer $progress
412 * @param moodle_url $continueurl URL to continue to remove the plugin folder
413 * @return string
415 public function plugin_uninstall_results_removable_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo,
416 progress_trace_buffer $progress, moodle_url $continueurl) {
417 $output = '';
419 $pluginname = $pluginman->plugin_name($pluginfo->component);
421 // Do not show navigation here, they must click one of the buttons.
422 $this->page->set_pagelayout('maintenance');
423 $this->page->set_cacheable(false);
425 $output .= $this->output->header();
426 $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
428 $output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
430 $confirm = $this->output->container(get_string('uninstalldeleteconfirm', 'core_plugin',
431 array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'uninstalldeleteconfirm');
433 if ($repotype = $pluginman->plugin_external_source($pluginfo->component)) {
434 $confirm .= $this->output->container(get_string('uninstalldeleteconfirmexternal', 'core_plugin', $repotype),
435 'alert alert-warning mt-2');
438 // After any uninstall we must execute full upgrade to finish the cleanup!
439 $output .= $this->output->confirm($confirm, $continueurl, new moodle_url('/admin/index.php'));
440 $output .= $this->output->footer();
442 return $output;
446 * Display a page with results of plugin uninstallation and inform about the need to remove plugin files manually.
448 * @param core_plugin_manager $pluginman
449 * @param \core\plugininfo\base $pluginfo
450 * @param progress_trace_buffer $progress
451 * @return string
453 public function plugin_uninstall_results_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, progress_trace_buffer $progress) {
454 $output = '';
456 $pluginname = $pluginfo->component;
458 $output .= $this->output->header();
459 $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
461 $output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
463 $output .= $this->output->box(get_string('uninstalldelete', 'core_plugin',
464 array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'generalbox uninstalldelete');
465 $output .= $this->output->continue_button(new moodle_url('/admin/index.php'));
466 $output .= $this->output->footer();
468 return $output;
472 * Display the plugin management page (admin/environment.php).
473 * @param array $versions
474 * @param string $version
475 * @param boolean $envstatus final result of env check (true/false)
476 * @param array $environment_results array of results gathered
477 * @return string HTML to output.
479 public function environment_check_page($versions, $version, $envstatus, $environment_results) {
480 $output = '';
481 $output .= $this->header();
483 // Print the component download link
484 $output .= html_writer::tag('div', html_writer::link(
485 new moodle_url('/admin/environment.php', array('action' => 'updatecomponent', 'sesskey' => sesskey())),
486 get_string('updatecomponent', 'admin')),
487 array('class' => 'reportlink'));
489 // Heading.
490 $output .= $this->heading(get_string('environment', 'admin'));
492 // Box with info and a menu to choose the version.
493 $output .= $this->box_start();
494 $output .= html_writer::tag('div', get_string('adminhelpenvironment'));
495 $select = new single_select(new moodle_url('/admin/environment.php'), 'version', $versions, $version, null);
496 $select->label = get_string('moodleversion');
497 $output .= $this->render($select);
498 $output .= $this->box_end();
500 // The results
501 $output .= $this->environment_check_table($envstatus, $environment_results);
503 $output .= $this->footer();
504 return $output;
508 * Output a warning message, of the type that appears on the admin notifications page.
509 * @param string $message the message to display.
510 * @param string $type type class
511 * @return string HTML to output.
513 protected function warning($message, $type = 'warning') {
514 return $this->box($message, 'generalbox alert alert-' . $type);
518 * Render an appropriate message if dataroot is insecure.
519 * @param bool $insecuredataroot
520 * @return string HTML to output.
522 protected function insecure_dataroot_warning($insecuredataroot) {
523 global $CFG;
525 if ($insecuredataroot == INSECURE_DATAROOT_WARNING) {
526 return $this->warning(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot));
528 } else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) {
529 return $this->warning(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'danger');
531 } else {
532 return '';
537 * Render a warning that a directory with development libs is present.
539 * @param bool $devlibdir True if the warning should be displayed.
540 * @return string
542 protected function development_libs_directories_warning($devlibdir) {
544 if ($devlibdir) {
545 $moreinfo = new moodle_url('/report/security/index.php');
546 $warning = get_string('devlibdirpresent', 'core_admin', ['moreinfourl' => $moreinfo->out()]);
547 return $this->warning($warning, 'danger');
549 } else {
550 return '';
555 * Render an appropriate message if dataroot is insecure.
556 * @param bool $errorsdisplayed
557 * @return string HTML to output.
559 protected function display_errors_warning($errorsdisplayed) {
560 if (!$errorsdisplayed) {
561 return '';
564 return $this->warning(get_string('displayerrorswarning', 'admin'));
568 * Render an appropriate message if themdesignermode is enabled.
569 * @param bool $themedesignermode true if enabled
570 * @return string HTML to output.
572 protected function themedesignermode_warning($themedesignermode) {
573 if (!$themedesignermode) {
574 return '';
577 return $this->warning(get_string('themedesignermodewarning', 'admin'));
581 * Render an appropriate message if iconv is buggy and mbstring missing.
582 * @param bool $buggyiconvnomb
583 * @return string HTML to output.
585 protected function buggy_iconv_warning($buggyiconvnomb) {
586 if (!$buggyiconvnomb) {
587 return '';
590 return $this->warning(get_string('warningiconvbuggy', 'admin'));
594 * Render an appropriate message if cron has not been run recently.
595 * @param bool $cronoverdue
596 * @return string HTML to output.
598 public function cron_overdue_warning($cronoverdue) {
599 global $CFG;
600 if (!$cronoverdue) {
601 return '';
604 $check = new \tool_task\check\cronrunning();
605 $result = $check->get_result();
606 return $this->warning($result->get_summary() . '&nbsp;' . $this->help_icon('cron', 'admin'));
610 * Render an appropriate message if cron is not being run frequently (recommended every minute).
612 * @param bool $croninfrequent
613 * @return string HTML to output.
615 public function cron_infrequent_warning(bool $croninfrequent) : string {
616 global $CFG;
618 if (!$croninfrequent) {
619 return '';
622 $check = new \tool_task\check\cronrunning();
623 $result = $check->get_result();
624 return $this->warning($result->get_summary() . '&nbsp;' . $this->help_icon('cron', 'admin'));
628 * Render an appropriate message if there are any problems with the DB set-up.
629 * @param bool $dbproblems
630 * @return string HTML to output.
632 public function db_problems($dbproblems) {
633 if (!$dbproblems) {
634 return '';
637 return $this->warning($dbproblems);
641 * Renders cache warnings if there are any.
643 * @param string[] $cachewarnings
644 * @return string
646 public function cache_warnings(array $cachewarnings) {
647 if (!count($cachewarnings)) {
648 return '';
650 return join("\n", array_map(array($this, 'warning'), $cachewarnings));
654 * Renders events 1 API handlers warning.
656 * @param array $eventshandlers
657 * @return string
659 public function events_handlers($eventshandlers) {
660 if ($eventshandlers) {
661 $components = '';
662 foreach ($eventshandlers as $eventhandler) {
663 $components .= $eventhandler->component . ', ';
665 $components = rtrim($components, ', ');
666 return $this->warning(get_string('eventshandlersinuse', 'admin', $components));
671 * Render an appropriate message if the site in in maintenance mode.
672 * @param bool $maintenancemode
673 * @return string HTML to output.
675 public function maintenance_mode_warning($maintenancemode) {
676 if (!$maintenancemode) {
677 return '';
680 $url = new moodle_url('/admin/settings.php', array('section' => 'maintenancemode'));
681 $url = $url->out(); // get_string() does not support objects in params
683 return $this->warning(get_string('sitemaintenancewarning2', 'admin', $url));
687 * Render a warning that ssl is forced because the site was on loginhttps.
689 * @param bool $overridetossl Whether or not ssl is being forced.
690 * @return string
692 protected function overridetossl_warning($overridetossl) {
693 if (!$overridetossl) {
694 return '';
696 $warning = get_string('overridetossl', 'core_admin');
697 return $this->warning($warning, 'warning');
701 * Display a warning about installing development code if necesary.
702 * @param int $maturity
703 * @return string HTML to output.
705 protected function maturity_warning($maturity) {
706 if ($maturity == MATURITY_STABLE) {
707 return ''; // No worries.
710 $maturitylevel = get_string('maturity' . $maturity, 'admin');
711 return $this->warning(
712 $this->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
713 $this->container($this->doc_link('admin/versions', get_string('morehelp'))),
714 'danger');
718 * If necessary, displays a warning about upgrading a test site.
720 * @param string $testsite
721 * @return string HTML
723 protected function test_site_warning($testsite) {
725 if (!$testsite) {
726 return '';
729 $warning = (get_string('testsiteupgradewarning', 'admin', $testsite));
730 return $this->warning($warning, 'danger');
734 * Output the copyright notice.
735 * @return string HTML to output.
737 protected function moodle_copyright() {
738 global $CFG;
740 //////////////////////////////////////////////////////////////////////////////////////////////////
741 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
742 $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
743 '<a href="http://docs.moodle.org/dev/Releases" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
744 'Copyright &copy; 1999 onwards, Martin Dougiamas<br />'.
745 'and <a href="http://moodle.org/dev">many other contributors</a>.<br />'.
746 '<a href="http://docs.moodle.org/dev/License">GNU Public License</a>';
747 //////////////////////////////////////////////////////////////////////////////////////////////////
749 return $this->box($copyrighttext, 'copyright');
753 * Display a warning about installing development code if necesary.
754 * @param int $maturity
755 * @return string HTML to output.
757 protected function maturity_info($maturity) {
758 if ($maturity == MATURITY_STABLE) {
759 return ''; // No worries.
762 $level = 'warning';
764 if ($maturity == MATURITY_ALPHA) {
765 $level = 'danger';
768 $maturitylevel = get_string('maturity' . $maturity, 'admin');
769 $warningtext = get_string('maturitycoreinfo', 'admin', $maturitylevel);
770 $warningtext .= ' ' . $this->doc_link('admin/versions', get_string('morehelp'));
771 return $this->warning($warningtext, $level);
775 * Displays the info about available Moodle core and plugin updates
777 * The structure of the $updates param has changed since 2.4. It contains not only updates
778 * for the core itself, but also for all other installed plugins.
780 * @param array|null $updates array of (string)component => array of \core\update\info objects or null
781 * @param int|null $fetch timestamp of the most recent updates fetch or null (unknown)
782 * @return string
784 protected function available_updates($updates, $fetch) {
786 $updateinfo = '';
787 $someupdateavailable = false;
788 if (is_array($updates)) {
789 if (is_array($updates['core'])) {
790 $someupdateavailable = true;
791 $updateinfo .= $this->heading(get_string('updateavailable', 'core_admin'), 3);
792 foreach ($updates['core'] as $update) {
793 $updateinfo .= $this->moodle_available_update_info($update);
795 $updateinfo .= html_writer::tag('p', get_string('updateavailablerecommendation', 'core_admin'),
796 array('class' => 'updateavailablerecommendation'));
798 unset($updates['core']);
799 // If something has left in the $updates array now, it is updates for plugins.
800 if (!empty($updates)) {
801 $someupdateavailable = true;
802 $updateinfo .= $this->heading(get_string('updateavailableforplugin', 'core_admin'), 3);
803 $pluginsoverviewurl = new moodle_url('/admin/plugins.php', array('updatesonly' => 1));
804 $updateinfo .= $this->container(get_string('pluginsoverviewsee', 'core_admin',
805 array('url' => $pluginsoverviewurl->out())));
809 if (!$someupdateavailable) {
810 $now = time();
811 if ($fetch and ($fetch <= $now) and ($now - $fetch < HOURSECS)) {
812 $updateinfo .= $this->heading(get_string('updateavailablenot', 'core_admin'), 3);
816 $updateinfo .= $this->container_start('checkforupdates');
817 $fetchurl = new moodle_url('/admin/index.php', array('fetchupdates' => 1, 'sesskey' => sesskey(), 'cache' => 0));
818 $updateinfo .= $this->single_button($fetchurl, get_string('checkforupdates', 'core_plugin'));
819 if ($fetch) {
820 $updateinfo .= $this->container(get_string('checkforupdateslast', 'core_plugin',
821 userdate($fetch, get_string('strftimedatetime', 'core_langconfig'))));
823 $updateinfo .= $this->container_end();
825 return $this->warning($updateinfo);
829 * Display a warning about not being registered on Moodle.org if necesary.
831 * @param boolean $registered true if the site is registered on Moodle.org
832 * @return string HTML to output.
834 protected function registration_warning($registered) {
836 if (!$registered && site_is_public()) {
837 if (has_capability('moodle/site:config', context_system::instance())) {
838 $registerbutton = $this->single_button(new moodle_url('/admin/registration/index.php'),
839 get_string('register', 'admin'));
840 $str = 'registrationwarning';
841 } else {
842 $registerbutton = '';
843 $str = 'registrationwarningcontactadmin';
846 return $this->warning( get_string($str, 'admin')
847 . '&nbsp;' . $this->help_icon('registration', 'admin') . $registerbutton ,
848 'error alert alert-danger');
851 return '';
855 * Return an admin page warning if site is not registered with moodle.org
857 * @return string
859 public function warn_if_not_registered() {
860 return $this->registration_warning(\core\hub\registration::is_registered());
864 * Display a warning about the Mobile Web Services being disabled.
866 * @param boolean $mobileconfigured true if mobile web services are enabled
867 * @return string HTML to output.
869 protected function mobile_configuration_warning($mobileconfigured) {
870 $output = '';
871 if (!$mobileconfigured) {
872 $settingslink = new moodle_url('/admin/settings.php', ['section' => 'mobilesettings']);
873 $configurebutton = $this->single_button($settingslink, get_string('enablemobilewebservice', 'admin'));
874 $output .= $this->warning(get_string('mobilenotconfiguredwarning', 'admin') . '&nbsp;' . $configurebutton);
877 return $output;
881 * Display a warning about the forgotten password URL not linking to a valid URL.
883 * @param boolean $invalidforgottenpasswordurl true if the forgotten password URL is not valid
884 * @return string HTML to output.
886 protected function forgotten_password_url_warning($invalidforgottenpasswordurl) {
887 $output = '';
888 if ($invalidforgottenpasswordurl) {
889 $settingslink = new moodle_url('/admin/settings.php', ['section' => 'manageauths']);
890 $configurebutton = $this->single_button($settingslink, get_string('check', 'moodle'));
891 $output .= $this->warning(get_string('invalidforgottenpasswordurl', 'admin') . '&nbsp;' . $configurebutton,
892 'error alert alert-danger');
895 return $output;
899 * Helper method to render the information about the available Moodle update
901 * @param \core\update\info $updateinfo information about the available Moodle core update
903 protected function moodle_available_update_info(\core\update\info $updateinfo) {
905 $boxclasses = 'moodleupdateinfo';
906 $info = array();
908 if (isset($updateinfo->release)) {
909 $info[] = html_writer::tag('span', get_string('updateavailable_release', 'core_admin', $updateinfo->release),
910 array('class' => 'info release'));
913 if (isset($updateinfo->version)) {
914 $info[] = html_writer::tag('span', get_string('updateavailable_version', 'core_admin', $updateinfo->version),
915 array('class' => 'info version'));
918 if (isset($updateinfo->maturity)) {
919 $info[] = html_writer::tag('span', get_string('maturity'.$updateinfo->maturity, 'core_admin'),
920 array('class' => 'info maturity'));
921 $boxclasses .= ' maturity'.$updateinfo->maturity;
924 if (isset($updateinfo->download)) {
925 $info[] = html_writer::link($updateinfo->download, get_string('download'), array('class' => 'info download'));
928 if (isset($updateinfo->url)) {
929 $info[] = html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin'),
930 array('class' => 'info more'));
933 $box = $this->output->box_start($boxclasses);
934 $box .= $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $info), '');
935 $box .= $this->output->box_end();
937 return $box;
941 * Display a link to the release notes.
942 * @return string HTML to output.
944 protected function release_notes_link() {
945 $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/dev/Releases');
946 $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
947 return $this->box($releasenoteslink, 'generalbox alert alert-info');
951 * Display the reload link that appears on several upgrade/install pages.
952 * @return string HTML to output.
954 function upgrade_reload($url) {
955 return html_writer::empty_tag('br') .
956 html_writer::tag('div',
957 html_writer::link($url, $this->pix_icon('i/reload', '', '', array('class' => 'icon icon-pre')) .
958 get_string('reload'), array('title' => get_string('reload'))),
959 array('class' => 'continuebutton')) . html_writer::empty_tag('br');
963 * Displays all known plugins and information about their installation or upgrade
965 * This default implementation renders all plugins into one big table. The rendering
966 * options support:
967 * (bool)full = false: whether to display up-to-date plugins, too
968 * (bool)xdep = false: display the plugins with unsatisified dependecies only
970 * @param core_plugin_manager $pluginman provides information about the plugins.
971 * @param int $version the version of the Moodle code from version.php.
972 * @param array $options rendering options
973 * @return string HTML code
975 public function plugins_check_table(core_plugin_manager $pluginman, $version, array $options = array()) {
976 global $CFG;
977 $plugininfo = $pluginman->get_plugins();
979 if (empty($plugininfo)) {
980 return '';
983 $options['full'] = isset($options['full']) ? (bool)$options['full'] : false;
984 $options['xdep'] = isset($options['xdep']) ? (bool)$options['xdep'] : false;
986 $table = new html_table();
987 $table->id = 'plugins-check';
988 $table->head = array(
989 get_string('displayname', 'core_plugin').' / '.get_string('rootdir', 'core_plugin'),
990 get_string('versiondb', 'core_plugin'),
991 get_string('versiondisk', 'core_plugin'),
992 get_string('requires', 'core_plugin'),
993 get_string('source', 'core_plugin').' / '.get_string('status', 'core_plugin'),
995 $table->colclasses = array(
996 'displayname', 'versiondb', 'versiondisk', 'requires', 'status',
998 $table->data = array();
1000 // Number of displayed plugins per type.
1001 $numdisplayed = array();
1002 // Number of plugins known to the plugin manager.
1003 $sumtotal = 0;
1004 // Number of plugins requiring attention.
1005 $sumattention = 0;
1006 // List of all components we can cancel installation of.
1007 $installabortable = $pluginman->list_cancellable_installations();
1008 // List of all components we can cancel upgrade of.
1009 $upgradeabortable = $pluginman->list_restorable_archives();
1011 foreach ($plugininfo as $type => $plugins) {
1013 $header = new html_table_cell($pluginman->plugintype_name_plural($type));
1014 $header->header = true;
1015 $header->colspan = count($table->head);
1016 $header = new html_table_row(array($header));
1017 $header->attributes['class'] = 'plugintypeheader type-' . $type;
1019 $numdisplayed[$type] = 0;
1021 if (empty($plugins) and $options['full']) {
1022 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
1023 $msg->colspan = count($table->head);
1024 $row = new html_table_row(array($msg));
1025 $row->attributes['class'] .= 'msg msg-noneinstalled';
1026 $table->data[] = $header;
1027 $table->data[] = $row;
1028 continue;
1031 $plugintyperows = array();
1033 foreach ($plugins as $name => $plugin) {
1034 $sumtotal++;
1035 $row = new html_table_row();
1036 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
1038 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name, null)) {
1039 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
1040 } else {
1041 $icon = '';
1044 $displayname = new html_table_cell(
1045 $icon.
1046 html_writer::span($plugin->displayname, 'pluginname').
1047 html_writer::div($plugin->get_dir(), 'plugindir')
1050 $versiondb = new html_table_cell($plugin->versiondb);
1051 $versiondisk = new html_table_cell($plugin->versiondisk);
1053 if ($isstandard = $plugin->is_standard()) {
1054 $row->attributes['class'] .= ' standard';
1055 $sourcelabel = html_writer::span(get_string('sourcestd', 'core_plugin'), 'sourcetext badge badge-secondary');
1056 } else {
1057 $row->attributes['class'] .= ' extension';
1058 $sourcelabel = html_writer::span(get_string('sourceext', 'core_plugin'), 'sourcetext badge badge-info');
1061 $coredependency = $plugin->is_core_dependency_satisfied($version);
1062 $incompatibledependency = $plugin->is_core_compatible_satisfied($CFG->branch);
1064 $otherpluginsdependencies = $pluginman->are_dependencies_satisfied($plugin->get_other_required_plugins());
1065 $dependenciesok = $coredependency && $otherpluginsdependencies && $incompatibledependency;
1067 $statuscode = $plugin->get_status();
1068 $row->attributes['class'] .= ' status-' . $statuscode;
1069 $statusclass = 'statustext badge ';
1070 switch ($statuscode) {
1071 case core_plugin_manager::PLUGIN_STATUS_NEW:
1072 $statusclass .= $dependenciesok ? 'badge-success' : 'badge-warning';
1073 break;
1074 case core_plugin_manager::PLUGIN_STATUS_UPGRADE:
1075 $statusclass .= $dependenciesok ? 'badge-info' : 'badge-warning';
1076 break;
1077 case core_plugin_manager::PLUGIN_STATUS_MISSING:
1078 case core_plugin_manager::PLUGIN_STATUS_DOWNGRADE:
1079 case core_plugin_manager::PLUGIN_STATUS_DELETE:
1080 $statusclass .= 'badge-danger';
1081 break;
1082 case core_plugin_manager::PLUGIN_STATUS_NODB:
1083 case core_plugin_manager::PLUGIN_STATUS_UPTODATE:
1084 $statusclass .= $dependenciesok ? '' : 'badge-warning';
1085 break;
1087 $status = html_writer::span(get_string('status_' . $statuscode, 'core_plugin'), $statusclass);
1089 if (!empty($installabortable[$plugin->component])) {
1090 $status .= $this->output->single_button(
1091 new moodle_url($this->page->url, array('abortinstall' => $plugin->component)),
1092 get_string('cancelinstallone', 'core_plugin'),
1093 'post',
1094 array('class' => 'actionbutton cancelinstallone')
1098 if (!empty($upgradeabortable[$plugin->component])) {
1099 $status .= $this->output->single_button(
1100 new moodle_url($this->page->url, array('abortupgrade' => $plugin->component)),
1101 get_string('cancelupgradeone', 'core_plugin'),
1102 'post',
1103 array('class' => 'actionbutton cancelupgradeone')
1107 $availableupdates = $plugin->available_updates();
1108 if (!empty($availableupdates)) {
1109 foreach ($availableupdates as $availableupdate) {
1110 $status .= $this->plugin_available_update_info($pluginman, $availableupdate);
1114 $status = new html_table_cell($sourcelabel.' '.$status);
1115 if ($plugin->pluginsupported != null) {
1116 $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version, $CFG->branch));
1117 } else {
1118 $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version));
1121 $statusisboring = in_array($statuscode, array(
1122 core_plugin_manager::PLUGIN_STATUS_NODB, core_plugin_manager::PLUGIN_STATUS_UPTODATE));
1124 if ($options['xdep']) {
1125 // we want to see only plugins with failed dependencies
1126 if ($dependenciesok) {
1127 continue;
1130 } else if ($statusisboring and $dependenciesok and empty($availableupdates)) {
1131 // no change is going to happen to the plugin - display it only
1132 // if the user wants to see the full list
1133 if (empty($options['full'])) {
1134 continue;
1137 } else {
1138 $sumattention++;
1141 // The plugin should be displayed.
1142 $numdisplayed[$type]++;
1143 $row->cells = array($displayname, $versiondb, $versiondisk, $requires, $status);
1144 $plugintyperows[] = $row;
1147 if (empty($numdisplayed[$type]) and empty($options['full'])) {
1148 continue;
1151 $table->data[] = $header;
1152 $table->data = array_merge($table->data, $plugintyperows);
1155 // Total number of displayed plugins.
1156 $sumdisplayed = array_sum($numdisplayed);
1158 if ($options['xdep']) {
1159 // At the plugins dependencies check page, display the table only.
1160 return html_writer::table($table);
1163 $out = $this->output->container_start('', 'plugins-check-info');
1165 if ($sumdisplayed == 0) {
1166 $out .= $this->output->heading(get_string('pluginchecknone', 'core_plugin'));
1168 } else {
1169 if (empty($options['full'])) {
1170 $out .= $this->output->heading(get_string('plugincheckattention', 'core_plugin'));
1171 } else {
1172 $out .= $this->output->heading(get_string('plugincheckall', 'core_plugin'));
1176 $out .= $this->output->container_start('actions');
1178 $installableupdates = $pluginman->filter_installable($pluginman->available_updates());
1179 if ($installableupdates) {
1180 $out .= $this->output->single_button(
1181 new moodle_url($this->page->url, array('installupdatex' => 1)),
1182 get_string('updateavailableinstallall', 'core_admin', count($installableupdates)),
1183 'post',
1184 array('class' => 'singlebutton updateavailableinstallall')
1188 if ($installabortable) {
1189 $out .= $this->output->single_button(
1190 new moodle_url($this->page->url, array('abortinstallx' => 1)),
1191 get_string('cancelinstallall', 'core_plugin', count($installabortable)),
1192 'post',
1193 array('class' => 'singlebutton cancelinstallall')
1197 if ($upgradeabortable) {
1198 $out .= $this->output->single_button(
1199 new moodle_url($this->page->url, array('abortupgradex' => 1)),
1200 get_string('cancelupgradeall', 'core_plugin', count($upgradeabortable)),
1201 'post',
1202 array('class' => 'singlebutton cancelupgradeall')
1206 $out .= html_writer::div(html_writer::link(new moodle_url($this->page->url, array('showallplugins' => 0)),
1207 get_string('plugincheckattention', 'core_plugin')).' '.html_writer::span($sumattention, 'badge'));
1209 $out .= html_writer::div(html_writer::link(new moodle_url($this->page->url, array('showallplugins' => 1)),
1210 get_string('plugincheckall', 'core_plugin')).' '.html_writer::span($sumtotal, 'badge'));
1212 $out .= $this->output->container_end(); // End of .actions container.
1213 $out .= $this->output->container_end(); // End of #plugins-check-info container.
1215 if ($sumdisplayed > 0 or $options['full']) {
1216 $out .= html_writer::table($table);
1219 return $out;
1223 * Display the continue / cancel widgets for the plugins management pages.
1225 * @param null|moodle_url $continue URL for the continue button, should it be displayed
1226 * @param null|moodle_url $cancel URL for the cancel link, defaults to the current page
1227 * @return string HTML
1229 public function plugins_management_confirm_buttons(moodle_url $continue=null, moodle_url $cancel=null) {
1231 $out = html_writer::start_div('plugins-management-confirm-buttons');
1233 if (!empty($continue)) {
1234 $out .= $this->output->single_button($continue, get_string('continue'), 'post', array('class' => 'continue'));
1237 if (empty($cancel)) {
1238 $cancel = $this->page->url;
1240 $out .= html_writer::div(html_writer::link($cancel, get_string('cancel')), 'cancel');
1242 return $out;
1246 * Displays the information about missing dependencies
1248 * @param core_plugin_manager $pluginman
1249 * @return string
1251 protected function missing_dependencies(core_plugin_manager $pluginman) {
1253 $dependencies = $pluginman->missing_dependencies();
1255 if (empty($dependencies)) {
1256 return '';
1259 $available = array();
1260 $unavailable = array();
1261 $unknown = array();
1263 foreach ($dependencies as $component => $remoteinfo) {
1264 if ($remoteinfo === false) {
1265 // The required version is not available. Let us check if there
1266 // is at least some version in the plugins directory.
1267 $remoteinfoanyversion = $pluginman->get_remote_plugin_info($component, ANY_VERSION, false);
1268 if ($remoteinfoanyversion === false) {
1269 $unknown[$component] = $component;
1270 } else {
1271 $unavailable[$component] = $remoteinfoanyversion;
1273 } else {
1274 $available[$component] = $remoteinfo;
1278 $out = $this->output->container_start('plugins-check-dependencies');
1280 if ($unavailable or $unknown) {
1281 $out .= $this->output->heading(get_string('misdepsunavail', 'core_plugin'));
1282 if ($unknown) {
1283 $out .= $this->output->notification(get_string('misdepsunknownlist', 'core_plugin', implode(', ', $unknown)));
1285 if ($unavailable) {
1286 $unavailablelist = array();
1287 foreach ($unavailable as $component => $remoteinfoanyversion) {
1288 $unavailablelistitem = html_writer::link('https://moodle.org/plugins/view.php?plugin='.$component,
1289 '<strong>'.$remoteinfoanyversion->name.'</strong>');
1290 if ($remoteinfoanyversion->version) {
1291 $unavailablelistitem .= ' ('.$component.' &gt; '.$remoteinfoanyversion->version->version.')';
1292 } else {
1293 $unavailablelistitem .= ' ('.$component.')';
1295 $unavailablelist[] = $unavailablelistitem;
1297 $out .= $this->output->notification(get_string('misdepsunavaillist', 'core_plugin',
1298 implode(', ', $unavailablelist)));
1300 $out .= $this->output->container_start('plugins-check-dependencies-actions');
1301 $out .= ' '.html_writer::link(new moodle_url('/admin/tool/installaddon/'),
1302 get_string('dependencyuploadmissing', 'core_plugin'));
1303 $out .= $this->output->container_end(); // End of .plugins-check-dependencies-actions container.
1306 if ($available) {
1307 $out .= $this->output->heading(get_string('misdepsavail', 'core_plugin'));
1308 $out .= $this->output->container_start('plugins-check-dependencies-actions');
1310 $installable = $pluginman->filter_installable($available);
1311 if ($installable) {
1312 $out .= $this->output->single_button(
1313 new moodle_url($this->page->url, array('installdepx' => 1)),
1314 get_string('dependencyinstallmissing', 'core_plugin', count($installable)),
1315 'post',
1316 array('class' => 'singlebutton dependencyinstallmissing')
1320 $out .= html_writer::div(html_writer::link(new moodle_url('/admin/tool/installaddon/'),
1321 get_string('dependencyuploadmissing', 'core_plugin')), 'dependencyuploadmissing');
1323 $out .= $this->output->container_end(); // End of .plugins-check-dependencies-actions container.
1325 $out .= $this->available_missing_dependencies_list($pluginman, $available);
1328 $out .= $this->output->container_end(); // End of .plugins-check-dependencies container.
1330 return $out;
1334 * Displays the list if available missing dependencies.
1336 * @param core_plugin_manager $pluginman
1337 * @param array $dependencies
1338 * @return string
1340 protected function available_missing_dependencies_list(core_plugin_manager $pluginman, array $dependencies) {
1341 global $CFG;
1343 $table = new html_table();
1344 $table->id = 'plugins-check-available-dependencies';
1345 $table->head = array(
1346 get_string('displayname', 'core_plugin'),
1347 get_string('release', 'core_plugin'),
1348 get_string('version', 'core_plugin'),
1349 get_string('supportedmoodleversions', 'core_plugin'),
1350 get_string('info', 'core'),
1352 $table->colclasses = array('displayname', 'release', 'version', 'supportedmoodleversions', 'info');
1353 $table->data = array();
1355 foreach ($dependencies as $plugin) {
1357 $supportedmoodles = array();
1358 foreach ($plugin->version->supportedmoodles as $moodle) {
1359 if ($CFG->branch == str_replace('.', '', $moodle->release)) {
1360 $supportedmoodles[] = html_writer::span($moodle->release, 'badge badge-success');
1361 } else {
1362 $supportedmoodles[] = html_writer::span($moodle->release, 'label');
1366 $requriedby = $pluginman->other_plugins_that_require($plugin->component);
1367 if ($requriedby) {
1368 foreach ($requriedby as $ix => $val) {
1369 $inf = $pluginman->get_plugin_info($val);
1370 if ($inf) {
1371 $requriedby[$ix] = $inf->displayname.' ('.$inf->component.')';
1374 $info = html_writer::div(
1375 get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
1376 'requiredby'
1378 } else {
1379 $info = '';
1382 $info .= $this->output->container_start('actions');
1384 $info .= html_writer::div(
1385 html_writer::link('https://moodle.org/plugins/view.php?plugin='.$plugin->component,
1386 get_string('misdepinfoplugin', 'core_plugin')),
1387 'misdepinfoplugin'
1390 $info .= html_writer::div(
1391 html_writer::link('https://moodle.org/plugins/pluginversion.php?id='.$plugin->version->id,
1392 get_string('misdepinfoversion', 'core_plugin')),
1393 'misdepinfoversion'
1396 $info .= html_writer::div(html_writer::link($plugin->version->downloadurl, get_string('download')), 'misdepdownload');
1398 if ($pluginman->is_remote_plugin_installable($plugin->component, $plugin->version->version, $reason)) {
1399 $info .= $this->output->single_button(
1400 new moodle_url($this->page->url, array('installdep' => $plugin->component)),
1401 get_string('dependencyinstall', 'core_plugin'),
1402 'post',
1403 array('class' => 'singlebutton dependencyinstall')
1405 } else {
1406 $reasonhelp = $this->info_remote_plugin_not_installable($reason);
1407 if ($reasonhelp) {
1408 $info .= html_writer::div($reasonhelp, 'reasonhelp dependencyinstall');
1412 $info .= $this->output->container_end(); // End of .actions container.
1414 $table->data[] = array(
1415 html_writer::div($plugin->name, 'name').' '.html_writer::div($plugin->component, 'component'),
1416 $plugin->version->release,
1417 $plugin->version->version,
1418 implode(' ', $supportedmoodles),
1419 $info
1423 return html_writer::table($table);
1427 * Explain why {@link core_plugin_manager::is_remote_plugin_installable()} returned false.
1429 * @param string $reason the reason code as returned by the plugin manager
1430 * @return string
1432 protected function info_remote_plugin_not_installable($reason) {
1434 if ($reason === 'notwritableplugintype' or $reason === 'notwritableplugin') {
1435 return $this->output->help_icon('notwritable', 'core_plugin', get_string('notwritable', 'core_plugin'));
1438 if ($reason === 'remoteunavailable') {
1439 return $this->output->help_icon('notdownloadable', 'core_plugin', get_string('notdownloadable', 'core_plugin'));
1442 return false;
1446 * Formats the information that needs to go in the 'Requires' column.
1447 * @param \core\plugininfo\base $plugin the plugin we are rendering the row for.
1448 * @param core_plugin_manager $pluginman provides data on all the plugins.
1449 * @param string $version
1450 * @param int $branch the current Moodle branch
1451 * @return string HTML code
1453 protected function required_column(\core\plugininfo\base $plugin, core_plugin_manager $pluginman, $version, $branch = null) {
1455 $requires = array();
1456 $displayuploadlink = false;
1457 $displayupdateslink = false;
1459 $requirements = $pluginman->resolve_requirements($plugin, $version, $branch);
1460 foreach ($requirements as $reqname => $reqinfo) {
1461 if ($reqname === 'core') {
1462 if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OK) {
1463 $class = 'requires-ok';
1464 $label = '';
1465 } else {
1466 $class = 'requires-failed';
1467 $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'badge badge-danger');
1470 if ($branch != null && !$plugin->is_core_compatible_satisfied($branch)) {
1471 $requires[] = html_writer::tag('li',
1472 html_writer::span(get_string('incompatibleversion', 'core_plugin', $branch), 'dep dep-core').
1473 ' '.$label, array('class' => $class));
1475 } else if ($branch != null && $plugin->pluginsupported != null) {
1476 $requires[] = html_writer::tag('li',
1477 html_writer::span(get_string('moodlebranch', 'core_plugin',
1478 array('min' => $plugin->pluginsupported[0], 'max' => $plugin->pluginsupported[1])), 'dep dep-core').
1479 ' '.$label, array('class' => $class));
1481 } else if ($reqinfo->reqver != ANY_VERSION) {
1482 $requires[] = html_writer::tag('li',
1483 html_writer::span(get_string('moodleversion', 'core_plugin', $plugin->versionrequires), 'dep dep-core').
1484 ' '.$label, array('class' => $class));
1487 } else {
1488 $actions = array();
1490 if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OK) {
1491 $label = '';
1492 $class = 'requires-ok';
1494 } else if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_MISSING) {
1495 if ($reqinfo->availability == $pluginman::REQUIREMENT_AVAILABLE) {
1496 $label = html_writer::span(get_string('dependencymissing', 'core_plugin'), 'badge badge-warning');
1497 $label .= ' '.html_writer::span(get_string('dependencyavailable', 'core_plugin'), 'badge badge-warning');
1498 $class = 'requires-failed requires-missing requires-available';
1499 $actions[] = html_writer::link(
1500 new moodle_url('https://moodle.org/plugins/view.php', array('plugin' => $reqname)),
1501 get_string('misdepinfoplugin', 'core_plugin')
1504 } else {
1505 $label = html_writer::span(get_string('dependencymissing', 'core_plugin'), 'badge badge-danger');
1506 $label .= ' '.html_writer::span(get_string('dependencyunavailable', 'core_plugin'),
1507 'badge badge-danger');
1508 $class = 'requires-failed requires-missing requires-unavailable';
1510 $displayuploadlink = true;
1512 } else if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OUTDATED) {
1513 if ($reqinfo->availability == $pluginman::REQUIREMENT_AVAILABLE) {
1514 $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'badge badge-warning');
1515 $label .= ' '.html_writer::span(get_string('dependencyavailable', 'core_plugin'), 'badge badge-warning');
1516 $class = 'requires-failed requires-outdated requires-available';
1517 $displayupdateslink = true;
1519 } else {
1520 $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'badge badge-danger');
1521 $label .= ' '.html_writer::span(get_string('dependencyunavailable', 'core_plugin'),
1522 'badge badge-danger');
1523 $class = 'requires-failed requires-outdated requires-unavailable';
1525 $displayuploadlink = true;
1528 if ($reqinfo->reqver != ANY_VERSION) {
1529 $str = 'otherpluginversion';
1530 } else {
1531 $str = 'otherplugin';
1534 $requires[] = html_writer::tag('li', html_writer::span(
1535 get_string($str, 'core_plugin', array('component' => $reqname, 'version' => $reqinfo->reqver)),
1536 'dep dep-plugin').' '.$label.' '.html_writer::span(implode(' | ', $actions), 'actions'),
1537 array('class' => $class)
1542 if (!$requires) {
1543 return '';
1546 $out = html_writer::tag('ul', implode("\n", $requires));
1548 if ($displayuploadlink) {
1549 $out .= html_writer::div(
1550 html_writer::link(
1551 new moodle_url('/admin/tool/installaddon/'),
1552 get_string('dependencyuploadmissing', 'core_plugin')
1554 'dependencyuploadmissing'
1558 if ($displayupdateslink) {
1559 $out .= html_writer::div(
1560 html_writer::link(
1561 new moodle_url($this->page->url, array('sesskey' => sesskey(), 'fetchupdates' => 1)),
1562 get_string('checkforupdates', 'core_plugin')
1564 'checkforupdates'
1568 // Check if supports is present, and $branch is not in, only if $incompatible check was ok.
1569 if ($plugin->pluginsupported != null && $class == 'requires-ok' && $branch != null) {
1570 if ($pluginman->check_explicitly_supported($plugin, $branch) == $pluginman::VERSION_NOT_SUPPORTED) {
1571 $out .= html_writer::div(get_string('notsupported', 'core_plugin', $branch));
1575 return $out;
1580 * Prints an overview about the plugins - number of installed, number of extensions etc.
1582 * @param core_plugin_manager $pluginman provides information about the plugins
1583 * @param array $options filtering options
1584 * @return string as usually
1586 public function plugins_overview_panel(core_plugin_manager $pluginman, array $options = array()) {
1588 $plugininfo = $pluginman->get_plugins();
1590 $numtotal = $numextension = $numupdatable = 0;
1592 foreach ($plugininfo as $type => $plugins) {
1593 foreach ($plugins as $name => $plugin) {
1594 if ($plugin->available_updates()) {
1595 $numupdatable++;
1597 if ($plugin->get_status() === core_plugin_manager::PLUGIN_STATUS_MISSING) {
1598 continue;
1600 $numtotal++;
1601 if (!$plugin->is_standard()) {
1602 $numextension++;
1607 $infoall = html_writer::link(
1608 new moodle_url($this->page->url, array('contribonly' => 0, 'updatesonly' => 0)),
1609 get_string('overviewall', 'core_plugin'),
1610 array('title' => get_string('filterall', 'core_plugin'))
1611 ).' '.html_writer::span($numtotal, 'badge number number-all');
1613 $infoext = html_writer::link(
1614 new moodle_url($this->page->url, array('contribonly' => 1, 'updatesonly' => 0)),
1615 get_string('overviewext', 'core_plugin'),
1616 array('title' => get_string('filtercontribonly', 'core_plugin'))
1617 ).' '.html_writer::span($numextension, 'badge number number-additional');
1619 if ($numupdatable) {
1620 $infoupdatable = html_writer::link(
1621 new moodle_url($this->page->url, array('contribonly' => 0, 'updatesonly' => 1)),
1622 get_string('overviewupdatable', 'core_plugin'),
1623 array('title' => get_string('filterupdatesonly', 'core_plugin'))
1624 ).' '.html_writer::span($numupdatable, 'badge badge-info number number-updatable');
1625 } else {
1626 // No updates, or the notifications disabled.
1627 $infoupdatable = '';
1630 $out = html_writer::start_div('', array('id' => 'plugins-overview-panel'));
1632 if (!empty($options['updatesonly'])) {
1633 $out .= $this->output->heading(get_string('overviewupdatable', 'core_plugin'), 3);
1634 } else if (!empty($options['contribonly'])) {
1635 $out .= $this->output->heading(get_string('overviewext', 'core_plugin'), 3);
1638 if ($numupdatable) {
1639 $installableupdates = $pluginman->filter_installable($pluginman->available_updates());
1640 if ($installableupdates) {
1641 $out .= $this->output->single_button(
1642 new moodle_url($this->page->url, array('installupdatex' => 1)),
1643 get_string('updateavailableinstallall', 'core_admin', count($installableupdates)),
1644 'post',
1645 array('class' => 'singlebutton updateavailableinstallall')
1650 $out .= html_writer::div($infoall, 'info info-all').
1651 html_writer::div($infoext, 'info info-ext').
1652 html_writer::div($infoupdatable, 'info info-updatable');
1654 $out .= html_writer::end_div(); // End of #plugins-overview-panel block.
1656 return $out;
1660 * Displays all known plugins and links to manage them
1662 * This default implementation renders all plugins into one big table.
1664 * @param core_plugin_manager $pluginman provides information about the plugins.
1665 * @param array $options filtering options
1666 * @return string HTML code
1668 public function plugins_control_panel(core_plugin_manager $pluginman, array $options = array()) {
1670 $plugininfo = $pluginman->get_plugins();
1672 // Filter the list of plugins according the options.
1673 if (!empty($options['updatesonly'])) {
1674 $updateable = array();
1675 foreach ($plugininfo as $plugintype => $pluginnames) {
1676 foreach ($pluginnames as $pluginname => $pluginfo) {
1677 $pluginavailableupdates = $pluginfo->available_updates();
1678 if (!empty($pluginavailableupdates)) {
1679 foreach ($pluginavailableupdates as $pluginavailableupdate) {
1680 $updateable[$plugintype][$pluginname] = $pluginfo;
1685 $plugininfo = $updateable;
1688 if (!empty($options['contribonly'])) {
1689 $contribs = array();
1690 foreach ($plugininfo as $plugintype => $pluginnames) {
1691 foreach ($pluginnames as $pluginname => $pluginfo) {
1692 if (!$pluginfo->is_standard()) {
1693 $contribs[$plugintype][$pluginname] = $pluginfo;
1697 $plugininfo = $contribs;
1700 if (empty($plugininfo)) {
1701 return '';
1704 $table = new html_table();
1705 $table->id = 'plugins-control-panel';
1706 $table->head = array(
1707 get_string('displayname', 'core_plugin'),
1708 get_string('version', 'core_plugin'),
1709 get_string('availability', 'core_plugin'),
1710 get_string('actions', 'core_plugin'),
1711 get_string('notes','core_plugin'),
1713 $table->headspan = array(1, 1, 1, 2, 1);
1714 $table->colclasses = array(
1715 'pluginname', 'version', 'availability', 'settings', 'uninstall', 'notes'
1718 foreach ($plugininfo as $type => $plugins) {
1719 $heading = $pluginman->plugintype_name_plural($type);
1720 $pluginclass = core_plugin_manager::resolve_plugininfo_class($type);
1721 if ($manageurl = $pluginclass::get_manage_url()) {
1722 $heading .= $this->output->action_icon($manageurl, new pix_icon('i/settings',
1723 get_string('settings', 'core_plugin')));
1725 $header = new html_table_cell(html_writer::tag('span', $heading, array('id'=>'plugin_type_cell_'.$type)));
1726 $header->header = true;
1727 $header->colspan = array_sum($table->headspan);
1728 $header = new html_table_row(array($header));
1729 $header->attributes['class'] = 'plugintypeheader type-' . $type;
1730 $table->data[] = $header;
1732 if (empty($plugins)) {
1733 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
1734 $msg->colspan = array_sum($table->headspan);
1735 $row = new html_table_row(array($msg));
1736 $row->attributes['class'] .= 'msg msg-noneinstalled';
1737 $table->data[] = $row;
1738 continue;
1741 foreach ($plugins as $name => $plugin) {
1742 $row = new html_table_row();
1743 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
1745 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name, null)) {
1746 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'icon pluginicon'));
1747 } else {
1748 $icon = $this->output->spacer();
1750 $status = $plugin->get_status();
1751 $row->attributes['class'] .= ' status-'.$status;
1752 $pluginname = html_writer::tag('div', $icon.$plugin->displayname, array('class' => 'displayname')).
1753 html_writer::tag('div', $plugin->component, array('class' => 'componentname'));
1754 $pluginname = new html_table_cell($pluginname);
1756 $version = html_writer::div($plugin->versiondb, 'versionnumber');
1757 if ((string)$plugin->release !== '') {
1758 $version = html_writer::div($plugin->release, 'release').$version;
1760 $version = new html_table_cell($version);
1762 $isenabled = $plugin->is_enabled();
1763 if (is_null($isenabled)) {
1764 $availability = new html_table_cell('');
1765 } else if ($isenabled) {
1766 $row->attributes['class'] .= ' enabled';
1767 $availability = new html_table_cell(get_string('pluginenabled', 'core_plugin'));
1768 } else {
1769 $row->attributes['class'] .= ' disabled';
1770 $availability = new html_table_cell(get_string('plugindisabled', 'core_plugin'));
1773 $settingsurl = $plugin->get_settings_url();
1774 if (!is_null($settingsurl)) {
1775 $settings = html_writer::link($settingsurl, get_string('settings', 'core_plugin'), array('class' => 'settings'));
1776 } else {
1777 $settings = '';
1779 $settings = new html_table_cell($settings);
1781 if ($uninstallurl = $pluginman->get_uninstall_url($plugin->component, 'overview')) {
1782 $uninstall = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin'));
1783 } else {
1784 $uninstall = '';
1786 $uninstall = new html_table_cell($uninstall);
1788 if ($plugin->is_standard()) {
1789 $row->attributes['class'] .= ' standard';
1790 $source = '';
1791 } else {
1792 $row->attributes['class'] .= ' extension';
1793 $source = html_writer::div(get_string('sourceext', 'core_plugin'), 'source badge badge-info');
1796 if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) {
1797 $msg = html_writer::div(get_string('status_missing', 'core_plugin'), 'statusmsg badge badge-danger');
1798 } else if ($status === core_plugin_manager::PLUGIN_STATUS_NEW) {
1799 $msg = html_writer::div(get_string('status_new', 'core_plugin'), 'statusmsg badge badge-success');
1800 } else {
1801 $msg = '';
1804 $requriedby = $pluginman->other_plugins_that_require($plugin->component);
1805 if ($requriedby) {
1806 $requiredby = html_writer::tag('div', get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
1807 array('class' => 'requiredby'));
1808 } else {
1809 $requiredby = '';
1812 $updateinfo = '';
1813 if (is_array($plugin->available_updates())) {
1814 foreach ($plugin->available_updates() as $availableupdate) {
1815 $updateinfo .= $this->plugin_available_update_info($pluginman, $availableupdate);
1819 $notes = new html_table_cell($source.$msg.$requiredby.$updateinfo);
1821 $row->cells = array(
1822 $pluginname, $version, $availability, $settings, $uninstall, $notes
1824 $table->data[] = $row;
1828 return html_writer::table($table);
1832 * Helper method to render the information about the available plugin update
1834 * @param core_plugin_manager $pluginman plugin manager instance
1835 * @param \core\update\info $updateinfo information about the available update for the plugin
1837 protected function plugin_available_update_info(core_plugin_manager $pluginman, \core\update\info $updateinfo) {
1839 $boxclasses = 'pluginupdateinfo';
1840 $info = array();
1842 if (isset($updateinfo->release)) {
1843 $info[] = html_writer::div(
1844 get_string('updateavailable_release', 'core_plugin', $updateinfo->release),
1845 'info release'
1849 if (isset($updateinfo->maturity)) {
1850 $info[] = html_writer::div(
1851 get_string('maturity'.$updateinfo->maturity, 'core_admin'),
1852 'info maturity'
1854 $boxclasses .= ' maturity'.$updateinfo->maturity;
1857 if (isset($updateinfo->download)) {
1858 $info[] = html_writer::div(
1859 html_writer::link($updateinfo->download, get_string('download')),
1860 'info download'
1864 if (isset($updateinfo->url)) {
1865 $info[] = html_writer::div(
1866 html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin')),
1867 'info more'
1871 $box = html_writer::start_div($boxclasses);
1872 $box .= html_writer::div(
1873 get_string('updateavailable', 'core_plugin', $updateinfo->version),
1874 'version'
1876 $box .= html_writer::div(
1877 implode(html_writer::span(' ', 'separator'), $info),
1878 'infos'
1881 if ($pluginman->is_remote_plugin_installable($updateinfo->component, $updateinfo->version, $reason)) {
1882 $box .= $this->output->single_button(
1883 new moodle_url($this->page->url, array('installupdate' => $updateinfo->component,
1884 'installupdateversion' => $updateinfo->version)),
1885 get_string('updateavailableinstall', 'core_admin'),
1886 'post',
1887 array('class' => 'singlebutton updateavailableinstall')
1889 } else {
1890 $reasonhelp = $this->info_remote_plugin_not_installable($reason);
1891 if ($reasonhelp) {
1892 $box .= html_writer::div($reasonhelp, 'reasonhelp updateavailableinstall');
1895 $box .= html_writer::end_div();
1897 return $box;
1901 * This function will render one beautiful table with all the environmental
1902 * configuration and how it suits Moodle needs.
1904 * @param boolean $result final result of the check (true/false)
1905 * @param environment_results[] $environment_results array of results gathered
1906 * @return string HTML to output.
1908 public function environment_check_table($result, $environment_results) {
1909 global $CFG;
1911 // Table headers
1912 $servertable = new html_table();//table for server checks
1913 $servertable->head = array(
1914 get_string('name'),
1915 get_string('info'),
1916 get_string('report'),
1917 get_string('plugin'),
1918 get_string('status'),
1920 $servertable->colclasses = array('centeralign name', 'centeralign info', 'leftalign report', 'leftalign plugin', 'centeralign status');
1921 $servertable->attributes['class'] = 'admintable environmenttable generaltable table-sm';
1922 $servertable->id = 'serverstatus';
1924 $serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
1926 $othertable = new html_table();//table for custom checks
1927 $othertable->head = array(
1928 get_string('info'),
1929 get_string('report'),
1930 get_string('plugin'),
1931 get_string('status'),
1933 $othertable->colclasses = array('aligncenter info', 'alignleft report', 'alignleft plugin', 'aligncenter status');
1934 $othertable->attributes['class'] = 'admintable environmenttable generaltable table-sm';
1935 $othertable->id = 'otherserverstatus';
1937 $otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
1939 // Iterate over each environment_result
1940 $continue = true;
1941 foreach ($environment_results as $environment_result) {
1942 $errorline = false;
1943 $warningline = false;
1944 $stringtouse = '';
1945 if ($continue) {
1946 $type = $environment_result->getPart();
1947 $info = $environment_result->getInfo();
1948 $status = $environment_result->getStatus();
1949 $plugin = $environment_result->getPluginName();
1950 $error_code = $environment_result->getErrorCode();
1951 // Process Report field
1952 $rec = new stdClass();
1953 // Something has gone wrong at parsing time
1954 if ($error_code) {
1955 $stringtouse = 'environmentxmlerror';
1956 $rec->error_code = $error_code;
1957 $status = get_string('error');
1958 $errorline = true;
1959 $continue = false;
1962 if ($continue) {
1963 if ($rec->needed = $environment_result->getNeededVersion()) {
1964 // We are comparing versions
1965 $rec->current = $environment_result->getCurrentVersion();
1966 if ($environment_result->getLevel() == 'required') {
1967 $stringtouse = 'environmentrequireversion';
1968 } else {
1969 $stringtouse = 'environmentrecommendversion';
1972 } else if ($environment_result->getPart() == 'custom_check') {
1973 // We are checking installed & enabled things
1974 if ($environment_result->getLevel() == 'required') {
1975 $stringtouse = 'environmentrequirecustomcheck';
1976 } else {
1977 $stringtouse = 'environmentrecommendcustomcheck';
1980 } else if ($environment_result->getPart() == 'php_setting') {
1981 if ($status) {
1982 $stringtouse = 'environmentsettingok';
1983 } else if ($environment_result->getLevel() == 'required') {
1984 $stringtouse = 'environmentmustfixsetting';
1985 } else {
1986 $stringtouse = 'environmentshouldfixsetting';
1989 } else {
1990 if ($environment_result->getLevel() == 'required') {
1991 $stringtouse = 'environmentrequireinstall';
1992 } else {
1993 $stringtouse = 'environmentrecommendinstall';
1997 // Calculate the status value
1998 if ($environment_result->getBypassStr() != '') { //Handle bypassed result (warning)
1999 $status = get_string('bypassed');
2000 $warningline = true;
2001 } else if ($environment_result->getRestrictStr() != '') { //Handle restricted result (error)
2002 $status = get_string('restricted');
2003 $errorline = true;
2004 } else {
2005 if ($status) { //Handle ok result (ok)
2006 $status = get_string('ok');
2007 } else {
2008 if ($environment_result->getLevel() == 'optional') {//Handle check result (warning)
2009 $status = get_string('check');
2010 $warningline = true;
2011 } else { //Handle error result (error)
2012 $status = get_string('check');
2013 $errorline = true;
2019 // Build the text
2020 $linkparts = array();
2021 $linkparts[] = 'admin/environment';
2022 $linkparts[] = $type;
2023 if (!empty($info)){
2024 $linkparts[] = $info;
2026 // Plugin environments do not have docs pages yet.
2027 if (empty($CFG->docroot) or $environment_result->plugin) {
2028 $report = get_string($stringtouse, 'admin', $rec);
2029 } else {
2030 $report = $this->doc_link(join('/', $linkparts), get_string($stringtouse, 'admin', $rec), true);
2032 // Enclose report text in div so feedback text will be displayed underneath it.
2033 $report = html_writer::div($report);
2035 // Format error or warning line
2036 if ($errorline) {
2037 $messagetype = 'error';
2038 $statusclass = 'badge-danger';
2039 } else if ($warningline) {
2040 $messagetype = 'warn';
2041 $statusclass = 'badge-warning';
2042 } else {
2043 $messagetype = 'ok';
2044 $statusclass = 'badge-success';
2046 $status = html_writer::span($status, 'badge ' . $statusclass);
2047 // Here we'll store all the feedback found
2048 $feedbacktext = '';
2049 // Append the feedback if there is some
2050 $feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), $messagetype);
2051 //Append the bypass if there is some
2052 $feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'warn');
2053 //Append the restrict if there is some
2054 $feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'error');
2056 $report .= $feedbacktext;
2058 // Add the row to the table
2059 if ($environment_result->getPart() == 'custom_check'){
2060 $otherdata[$messagetype][] = array ($info, $report, $plugin, $status);
2061 } else {
2062 $serverdata[$messagetype][] = array ($type, $info, $report, $plugin, $status);
2067 //put errors first in
2068 $servertable->data = array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']);
2069 $othertable->data = array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']);
2071 // Print table
2072 $output = '';
2073 $output .= $this->heading(get_string('serverchecks', 'admin'));
2074 $output .= html_writer::table($servertable);
2075 if (count($othertable->data)){
2076 $output .= $this->heading(get_string('customcheck', 'admin'));
2077 $output .= html_writer::table($othertable);
2080 // Finally, if any error has happened, print the summary box
2081 if (!$result) {
2082 $output .= $this->box(get_string('environmenterrortodo', 'admin'), 'environmentbox errorbox');
2085 return $output;
2089 * Render a simple page for providing the upgrade key.
2091 * @param moodle_url|string $url
2092 * @return string
2094 public function upgradekey_form_page($url) {
2096 $output = '';
2097 $output .= $this->header();
2098 $output .= $this->container_start('upgradekeyreq');
2099 $output .= $this->heading(get_string('upgradekeyreq', 'core_admin'));
2100 $output .= html_writer::start_tag('form', array('method' => 'POST', 'action' => $url));
2101 $output .= html_writer::empty_tag('input', array('name' => 'upgradekey', 'type' => 'password'));
2102 $output .= html_writer::empty_tag('input', array('value' => get_string('submit'), 'type' => 'submit'));
2103 $output .= html_writer::end_tag('form');
2104 $output .= $this->container_end();
2105 $output .= $this->footer();
2107 return $output;
2111 * Check to see if writing to the deprecated legacy log store is enabled.
2113 * @return string An error message if writing to the legacy log store is enabled.
2115 protected function legacy_log_store_writing_error() {
2116 $enabled = get_config('logstore_legacy', 'loglegacy');
2117 $plugins = explode(',', get_config('tool_log', 'enabled_stores'));
2118 $enabled = $enabled && in_array('logstore_legacy', $plugins);
2120 if ($enabled) {
2121 return $this->warning(get_string('legacylogginginuse'));
2126 * Display message about the benefits of registering on Moodle.org
2128 * @return string
2130 public function moodleorg_registration_message() {
2132 $out = format_text(get_string('registerwithmoodleorginfo', 'core_hub'), FORMAT_MARKDOWN);
2134 $out .= html_writer::link(
2135 new moodle_url('/admin/settings.php', ['section' => 'moodleservices']),
2136 $this->output->pix_icon('i/info', '').' '.get_string('registerwithmoodleorginfoapp', 'core_hub'),
2137 ['class' => 'btn btn-link', 'role' => 'opener', 'target' => '_href']
2140 $out .= html_writer::link(
2141 HUB_MOODLEORGHUBURL,
2142 $this->output->pix_icon('i/stats', '').' '.get_string('registerwithmoodleorginfostats', 'core_hub'),
2143 ['class' => 'btn btn-link', 'role' => 'opener', 'target' => '_href']
2146 $out .= html_writer::link(
2147 HUB_MOODLEORGHUBURL.'/sites',
2148 $this->output->pix_icon('i/location', '').' '.get_string('registerwithmoodleorginfosites', 'core_hub'),
2149 ['class' => 'btn btn-link', 'role' => 'opener', 'target' => '_href']
2152 return $this->output->box($out);