2d6c362e0e94aa4cd3dddd76d334599303a35c53
[moodle.git] / admin / renderer.php
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.
13 //
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
19  *
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
24  */
26 defined('MOODLE_INTERNAL') || die();
29 /**
30  * Standard HTML output renderer for core_admin subsystem
31  */
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.
38      */
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;
58     }
60     /**
61      * Display page explaining proper upgrade process,
62      * there can not be any PHP file leftovers...
63      *
64      * @return string HTML to output.
65      */
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;
78     }
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.
87      */
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)));
105         }
107         $output .= $this->footer();
108         return $output;
109     }
111     /**
112      * Displays the list of plugins with unsatisfied dependencies
113      *
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
118      */
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;
132     }
134     /**
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.
141      */
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;
156     }
158     /**
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.
164      */
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');
182             }
184             $output .= $this->continue_button(new moodle_url($this->page->url, array(
185                 'confirmupgrade' => 1, 'confirmrelease' => 1, 'cache' => 0)));
186         }
188         $output .= $this->footer();
190         return $output;
191     }
193     /**
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.
202      */
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();
221         }
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;
229     }
231     /**
232      * Display a page to confirm plugin installation cancelation.
233      *
234      * @param array $abortable list of \core\update\plugininfo
235      * @param moodle_url $continue
236      * @return string
237      */
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');
245         }
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');
257             }
258         }
260         $out .= $this->plugins_management_confirm_buttons($continue, $this->page->url);
261         $out .= $this->output->footer();
263         return $out;
264     }
266     /**
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      *
280      * @return string HTML to output.
281      */
282     public function admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed,
283             $cronoverdue, $dbproblems, $maintenancemode, $availableupdates, $availableupdatesfetch,
284             $buggyiconvnomb, $registered, array $cachewarnings = array(), $eventshandlers = 0, $themedesignermode = false) {
285         global $CFG;
286         $output = '';
288         $output .= $this->header();
289         $output .= $this->maturity_info($maturity);
290         $output .= $this->legacy_log_store_writing_error();
291         $output .= empty($CFG->disableupdatenotifications) ? $this->available_updates($availableupdates, $availableupdatesfetch) : '';
292         $output .= $this->insecure_dataroot_warning($insecuredataroot);
293         $output .= $this->themedesignermode_warning($themedesignermode);
294         $output .= $this->display_errors_warning($errorsdisplayed);
295         $output .= $this->buggy_iconv_warning($buggyiconvnomb);
296         $output .= $this->cron_overdue_warning($cronoverdue);
297         $output .= $this->db_problems($dbproblems);
298         $output .= $this->maintenance_mode_warning($maintenancemode);
299         $output .= $this->cache_warnings($cachewarnings);
300         $output .= $this->events_handlers($eventshandlers);
301         $output .= $this->registration_warning($registered);
303         //////////////////////////////////////////////////////////////////////////////////////////////////
304         ////  IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
305         $output .= $this->moodle_copyright();
306         //////////////////////////////////////////////////////////////////////////////////////////////////
308         $output .= $this->footer();
310         return $output;
311     }
313     /**
314      * Display the plugin management page (admin/plugins.php).
315      *
316      * The filtering options array may contain following items:
317      *  bool contribonly - show only contributed extensions
318      *  bool updatesonly - show only plugins with an available update
319      *
320      * @param core_plugin_manager $pluginman
321      * @param \core\update\checker $checker
322      * @param array $options filtering options
323      * @return string HTML to output.
324      */
325     public function plugin_management_page(core_plugin_manager $pluginman, \core\update\checker $checker, array $options = array()) {
327         $output = '';
329         $output .= $this->header();
330         $output .= $this->heading(get_string('pluginsoverview', 'core_admin'));
331         $output .= $this->check_for_updates_button($checker, $this->page->url);
332         $output .= $this->plugins_overview_panel($pluginman, $options);
333         $output .= $this->plugins_control_panel($pluginman, $options);
334         $output .= $this->footer();
336         return $output;
337     }
339     /**
340      * Renders a button to fetch for available updates.
341      *
342      * @param \core\update\checker $checker
343      * @param moodle_url $reloadurl
344      * @return string HTML
345      */
346     public function check_for_updates_button(\core\update\checker $checker, $reloadurl) {
348         $output = '';
350         if ($checker->enabled()) {
351             $output .= $this->container_start('checkforupdates');
352             $output .= $this->single_button(
353                 new moodle_url($reloadurl, array('fetchupdates' => 1)),
354                 get_string('checkforupdates', 'core_plugin')
355             );
356             if ($timefetched = $checker->get_last_timefetched()) {
357                 $timefetched = userdate($timefetched, get_string('strftimedatetime', 'core_langconfig'));
358                 $output .= $this->container(get_string('checkforupdateslast', 'core_plugin', $timefetched), 'lasttimefetched');
359             }
360             $output .= $this->container_end();
361         }
363         return $output;
364     }
366     /**
367      * Display a page to confirm the plugin uninstallation.
368      *
369      * @param core_plugin_manager $pluginman
370      * @param \core\plugininfo\base $pluginfo
371      * @param moodle_url $continueurl URL to continue after confirmation
372      * @param moodle_url $cancelurl URL to to go if cancelled
373      * @return string
374      */
375     public function plugin_uninstall_confirm_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, moodle_url $continueurl, moodle_url $cancelurl) {
376         $output = '';
378         $pluginname = $pluginman->plugin_name($pluginfo->component);
380         $confirm = '<p>' . get_string('uninstallconfirm', 'core_plugin', array('name' => $pluginname)) . '</p>';
381         if ($extraconfirm = $pluginfo->get_uninstall_extra_warning()) {
382             $confirm .= $extraconfirm;
383         }
385         $output .= $this->output->header();
386         $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
387         $output .= $this->output->confirm($confirm, $continueurl, $cancelurl);
388         $output .= $this->output->footer();
390         return $output;
391     }
393     /**
394      * Display a page with results of plugin uninstallation and offer removal of plugin files.
395      *
396      * @param core_plugin_manager $pluginman
397      * @param \core\plugininfo\base $pluginfo
398      * @param progress_trace_buffer $progress
399      * @param moodle_url $continueurl URL to continue to remove the plugin folder
400      * @return string
401      */
402     public function plugin_uninstall_results_removable_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo,
403                                                             progress_trace_buffer $progress, moodle_url $continueurl) {
404         $output = '';
406         $pluginname = $pluginman->plugin_name($pluginfo->component);
408         // Do not show navigation here, they must click one of the buttons.
409         $this->page->set_pagelayout('maintenance');
410         $this->page->set_cacheable(false);
412         $output .= $this->output->header();
413         $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
415         $output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
417         $confirm = $this->output->container(get_string('uninstalldeleteconfirm', 'core_plugin',
418             array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'uninstalldeleteconfirm');
420         if ($repotype = $pluginman->plugin_external_source($pluginfo->component)) {
421             $confirm .= $this->output->container(get_string('uninstalldeleteconfirmexternal', 'core_plugin', $repotype),
422                 'uninstalldeleteconfirmexternal');
423         }
425         // After any uninstall we must execute full upgrade to finish the cleanup!
426         $output .= $this->output->confirm($confirm, $continueurl, new moodle_url('/admin/index.php'));
427         $output .= $this->output->footer();
429         return $output;
430     }
432     /**
433      * Display a page with results of plugin uninstallation and inform about the need to remove plugin files manually.
434      *
435      * @param core_plugin_manager $pluginman
436      * @param \core\plugininfo\base $pluginfo
437      * @param progress_trace_buffer $progress
438      * @return string
439      */
440     public function plugin_uninstall_results_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, progress_trace_buffer $progress) {
441         $output = '';
443         $pluginname = $pluginfo->component;
445         $output .= $this->output->header();
446         $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
448         $output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
450         $output .= $this->output->box(get_string('uninstalldelete', 'core_plugin',
451             array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'generalbox uninstalldelete');
452         $output .= $this->output->continue_button(new moodle_url('/admin/index.php'));
453         $output .= $this->output->footer();
455         return $output;
456     }
458     /**
459      * Display the plugin management page (admin/environment.php).
460      * @param array $versions
461      * @param string $version
462      * @param boolean $envstatus final result of env check (true/false)
463      * @param array $environment_results array of results gathered
464      * @return string HTML to output.
465      */
466     public function environment_check_page($versions, $version, $envstatus, $environment_results) {
467         $output = '';
468         $output .= $this->header();
470         // Print the component download link
471         $output .= html_writer::tag('div', html_writer::link(
472                     new moodle_url('/admin/environment.php', array('action' => 'updatecomponent', 'sesskey' => sesskey())),
473                     get_string('updatecomponent', 'admin')),
474                 array('class' => 'reportlink'));
476         // Heading.
477         $output .= $this->heading(get_string('environment', 'admin'));
479         // Box with info and a menu to choose the version.
480         $output .= $this->box_start();
481         $output .= html_writer::tag('div', get_string('adminhelpenvironment'));
482         $select = new single_select(new moodle_url('/admin/environment.php'), 'version', $versions, $version, null);
483         $select->label = get_string('moodleversion');
484         $output .= $this->render($select);
485         $output .= $this->box_end();
487         // The results
488         $output .= $this->environment_check_table($envstatus, $environment_results);
490         $output .= $this->footer();
491         return $output;
492     }
494     /**
495      * Output a warning message, of the type that appears on the admin notifications page.
496      * @param string $message the message to display.
497      * @param string $type type class
498      * @return string HTML to output.
499      */
500     protected function warning($message, $type = 'warning') {
501         return $this->box($message, 'generalbox admin' . $type);
502     }
504     /**
505      * Render an appropriate message if dataroot is insecure.
506      * @param bool $insecuredataroot
507      * @return string HTML to output.
508      */
509     protected function insecure_dataroot_warning($insecuredataroot) {
510         global $CFG;
512         if ($insecuredataroot == INSECURE_DATAROOT_WARNING) {
513             return $this->warning(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot));
515         } else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) {
516             return $this->warning(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'error');
518         } else {
519             return '';
520         }
521     }
523     /**
524      * Render an appropriate message if dataroot is insecure.
525      * @param bool $errorsdisplayed
526      * @return string HTML to output.
527      */
528     protected function display_errors_warning($errorsdisplayed) {
529         if (!$errorsdisplayed) {
530             return '';
531         }
533         return $this->warning(get_string('displayerrorswarning', 'admin'));
534     }
536     /**
537      * Render an appropriate message if themdesignermode is enabled.
538      * @param bool $themedesignermode true if enabled
539      * @return string HTML to output.
540      */
541     protected function themedesignermode_warning($themedesignermode) {
542         if (!$themedesignermode) {
543             return '';
544         }
546         return $this->warning(get_string('themedesignermodewarning', 'admin'));
547     }
549     /**
550      * Render an appropriate message if iconv is buggy and mbstring missing.
551      * @param bool $buggyiconvnomb
552      * @return string HTML to output.
553      */
554     protected function buggy_iconv_warning($buggyiconvnomb) {
555         if (!$buggyiconvnomb) {
556             return '';
557         }
559         return $this->warning(get_string('warningiconvbuggy', 'admin'));
560     }
562     /**
563      * Render an appropriate message if cron has not been run recently.
564      * @param bool $cronoverdue
565      * @return string HTML to output.
566      */
567     public function cron_overdue_warning($cronoverdue) {
568         global $CFG;
569         if (!$cronoverdue) {
570             return '';
571         }
573         if (empty($CFG->cronclionly)) {
574             $url = new moodle_url('/admin/cron.php');
575             if (!empty($CFG->cronremotepassword)) {
576                 $url = new moodle_url('/admin/cron.php', array('password' => $CFG->cronremotepassword));
577             }
579             return $this->warning(get_string('cronwarning', 'admin', $url->out()) . '&nbsp;' .
580                     $this->help_icon('cron', 'admin'));
581         }
583         // $CFG->cronclionly is not empty: cron can run only from CLI.
584         return $this->warning(get_string('cronwarningcli', 'admin') . '&nbsp;' .
585                 $this->help_icon('cron', 'admin'));
586     }
588     /**
589      * Render an appropriate message if there are any problems with the DB set-up.
590      * @param bool $dbproblems
591      * @return string HTML to output.
592      */
593     public function db_problems($dbproblems) {
594         if (!$dbproblems) {
595             return '';
596         }
598         return $this->warning($dbproblems);
599     }
601     /**
602      * Renders cache warnings if there are any.
603      *
604      * @param string[] $cachewarnings
605      * @return string
606      */
607     public function cache_warnings(array $cachewarnings) {
608         if (!count($cachewarnings)) {
609             return '';
610         }
611         return join("\n", array_map(array($this, 'warning'), $cachewarnings));
612     }
614     /**
615      * Renders events 1 API handlers warning.
616      *
617      * @param array $eventshandlers
618      * @return string
619      */
620     public function events_handlers($eventshandlers) {
621         if ($eventshandlers) {
622             $components = '';
623             foreach ($eventshandlers as $eventhandler) {
624                 $components .= $eventhandler->component . ', ';
625             }
626             $components = rtrim($components, ', ');
627             return $this->warning(get_string('eventshandlersinuse', 'admin', $components));
628         }
629     }
631     /**
632      * Render an appropriate message if the site in in maintenance mode.
633      * @param bool $maintenancemode
634      * @return string HTML to output.
635      */
636     public function maintenance_mode_warning($maintenancemode) {
637         if (!$maintenancemode) {
638             return '';
639         }
641         $url = new moodle_url('/admin/settings.php', array('section' => 'maintenancemode'));
642         $url = $url->out(); // get_string() does not support objects in params
644         return $this->warning(get_string('sitemaintenancewarning2', 'admin', $url));
645     }
647     /**
648      * Display a warning about installing development code if necesary.
649      * @param int $maturity
650      * @return string HTML to output.
651      */
652     protected function maturity_warning($maturity) {
653         if ($maturity == MATURITY_STABLE) {
654             return ''; // No worries.
655         }
657         $maturitylevel = get_string('maturity' . $maturity, 'admin');
658         return $this->warning(
659                     $this->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
660                     $this->container($this->doc_link('admin/versions', get_string('morehelp'))),
661                 'error');
662     }
664     /*
665      * If necessary, displays a warning about upgrading a test site.
666      *
667      * @param string $testsite
668      * @return string HTML
669      */
670     protected function test_site_warning($testsite) {
672         if (!$testsite) {
673             return '';
674         }
676         $warning = (get_string('testsiteupgradewarning', 'admin', $testsite));
677         return $this->warning($warning, 'error');
678     }
680     /**
681      * Output the copyright notice.
682      * @return string HTML to output.
683      */
684     protected function moodle_copyright() {
685         global $CFG;
687         //////////////////////////////////////////////////////////////////////////////////////////////////
688         ////  IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
689         $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
690                          '<a href="http://docs.moodle.org/dev/Releases" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
691                          'Copyright &copy; 1999 onwards, Martin Dougiamas<br />'.
692                          'and <a href="http://moodle.org/dev">many other contributors</a>.<br />'.
693                          '<a href="http://docs.moodle.org/dev/License">GNU Public License</a>';
694         //////////////////////////////////////////////////////////////////////////////////////////////////
696         return $this->box($copyrighttext, 'copyright');
697     }
699     /**
700      * Display a warning about installing development code if necesary.
701      * @param int $maturity
702      * @return string HTML to output.
703      */
704     protected function maturity_info($maturity) {
705         if ($maturity == MATURITY_STABLE) {
706             return ''; // No worries.
707         }
709         $level = 'warning';
711         if ($maturity == MATURITY_ALPHA) {
712             $level = 'error';
713         }
715         $maturitylevel = get_string('maturity' . $maturity, 'admin');
716         $warningtext = get_string('maturitycoreinfo', 'admin', $maturitylevel);
717         $warningtext .= ' ' . $this->doc_link('admin/versions', get_string('morehelp'));
718         return $this->warning($warningtext, $level);
719     }
721     /**
722      * Displays the info about available Moodle core and plugin updates
723      *
724      * The structure of the $updates param has changed since 2.4. It contains not only updates
725      * for the core itself, but also for all other installed plugins.
726      *
727      * @param array|null $updates array of (string)component => array of \core\update\info objects or null
728      * @param int|null $fetch timestamp of the most recent updates fetch or null (unknown)
729      * @return string
730      */
731     protected function available_updates($updates, $fetch) {
733         $updateinfo = '';
734         $someupdateavailable = false;
735         if (is_array($updates)) {
736             if (is_array($updates['core'])) {
737                 $someupdateavailable = true;
738                 $updateinfo .= $this->heading(get_string('updateavailable', 'core_admin'), 3);
739                 foreach ($updates['core'] as $update) {
740                     $updateinfo .= $this->moodle_available_update_info($update);
741                 }
742                 $updateinfo .= html_writer::tag('p', get_string('updateavailablerecommendation', 'core_admin'),
743                     array('class' => 'updateavailablerecommendation'));
744             }
745             unset($updates['core']);
746             // If something has left in the $updates array now, it is updates for plugins.
747             if (!empty($updates)) {
748                 $someupdateavailable = true;
749                 $updateinfo .= $this->heading(get_string('updateavailableforplugin', 'core_admin'), 3);
750                 $pluginsoverviewurl = new moodle_url('/admin/plugins.php', array('updatesonly' => 1));
751                 $updateinfo .= $this->container(get_string('pluginsoverviewsee', 'core_admin',
752                     array('url' => $pluginsoverviewurl->out())));
753             }
754         }
756         if (!$someupdateavailable) {
757             $now = time();
758             if ($fetch and ($fetch <= $now) and ($now - $fetch < HOURSECS)) {
759                 $updateinfo .= $this->heading(get_string('updateavailablenot', 'core_admin'), 3);
760             }
761         }
763         $updateinfo .= $this->container_start('checkforupdates');
764         $fetchurl = new moodle_url('/admin/index.php', array('fetchupdates' => 1, 'sesskey' => sesskey(), 'cache' => 0));
765         $updateinfo .= $this->single_button($fetchurl, get_string('checkforupdates', 'core_plugin'));
766         if ($fetch) {
767             $updateinfo .= $this->container(get_string('checkforupdateslast', 'core_plugin',
768                 userdate($fetch, get_string('strftimedatetime', 'core_langconfig'))));
769         }
770         $updateinfo .= $this->container_end();
772         return $this->warning($updateinfo);
773     }
775     /**
776      * Display a warning about not being registered on Moodle.org if necesary.
777      *
778      * @param boolean $registered true if the site is registered on Moodle.org
779      * @return string HTML to output.
780      */
781     protected function registration_warning($registered) {
783         if (!$registered) {
785             $registerbutton = $this->single_button(new moodle_url('/admin/registration/register.php',
786                     array('huburl' =>  HUB_MOODLEORGHUBURL, 'hubname' => 'Moodle.org')),
787                     get_string('register', 'admin'));
789             return $this->warning( get_string('registrationwarning', 'admin')
790                     . '&nbsp;' . $this->help_icon('registration', 'admin') . $registerbutton );
791         }
793         return '';
794     }
796     /**
797      * Helper method to render the information about the available Moodle update
798      *
799      * @param \core\update\info $updateinfo information about the available Moodle core update
800      */
801     protected function moodle_available_update_info(\core\update\info $updateinfo) {
803         $boxclasses = 'moodleupdateinfo';
804         $info = array();
806         if (isset($updateinfo->release)) {
807             $info[] = html_writer::tag('span', get_string('updateavailable_release', 'core_admin', $updateinfo->release),
808                 array('class' => 'info release'));
809         }
811         if (isset($updateinfo->version)) {
812             $info[] = html_writer::tag('span', get_string('updateavailable_version', 'core_admin', $updateinfo->version),
813                 array('class' => 'info version'));
814         }
816         if (isset($updateinfo->maturity)) {
817             $info[] = html_writer::tag('span', get_string('maturity'.$updateinfo->maturity, 'core_admin'),
818                 array('class' => 'info maturity'));
819             $boxclasses .= ' maturity'.$updateinfo->maturity;
820         }
822         if (isset($updateinfo->download)) {
823             $info[] = html_writer::link($updateinfo->download, get_string('download'), array('class' => 'info download'));
824         }
826         if (isset($updateinfo->url)) {
827             $info[] = html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin'),
828                 array('class' => 'info more'));
829         }
831         $box  = $this->output->box_start($boxclasses);
832         $box .= $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $info), '');
833         $box .= $this->output->box_end();
835         return $box;
836     }
838     /**
839      * Display a link to the release notes.
840      * @return string HTML to output.
841      */
842     protected function release_notes_link() {
843         $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/dev/Releases');
844         $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
845         return $this->box($releasenoteslink, 'generalbox releasenoteslink');
846     }
848     /**
849      * Display the reload link that appears on several upgrade/install pages.
850      * @return string HTML to output.
851      */
852     function upgrade_reload($url) {
853         return html_writer::empty_tag('br') .
854                 html_writer::tag('div',
855                     html_writer::link($url, $this->pix_icon('i/reload', '', '', array('class' => 'icon icon-pre')) .
856                             get_string('reload'), array('title' => get_string('reload'))),
857                 array('class' => 'continuebutton')) . html_writer::empty_tag('br');
858     }
860     /**
861      * Displays all known plugins and information about their installation or upgrade
862      *
863      * This default implementation renders all plugins into one big table. The rendering
864      * options support:
865      *     (bool)full = false: whether to display up-to-date plugins, too
866      *     (bool)xdep = false: display the plugins with unsatisified dependecies only
867      *
868      * @param core_plugin_manager $pluginman provides information about the plugins.
869      * @param int $version the version of the Moodle code from version.php.
870      * @param array $options rendering options
871      * @return string HTML code
872      */
873     public function plugins_check_table(core_plugin_manager $pluginman, $version, array $options = array()) {
875         $plugininfo = $pluginman->get_plugins();
877         if (empty($plugininfo)) {
878             return '';
879         }
881         $options['full'] = isset($options['full']) ? (bool)$options['full'] : false;
882         $options['xdep'] = isset($options['xdep']) ? (bool)$options['xdep'] : false;
884         $table = new html_table();
885         $table->id = 'plugins-check';
886         $table->head = array(
887             get_string('displayname', 'core_plugin').' / '.get_string('rootdir', 'core_plugin'),
888             get_string('versiondb', 'core_plugin'),
889             get_string('versiondisk', 'core_plugin'),
890             get_string('requires', 'core_plugin'),
891             get_string('source', 'core_plugin').' / '.get_string('status', 'core_plugin'),
892         );
893         $table->colclasses = array(
894             'displayname', 'versiondb', 'versiondisk', 'requires', 'status',
895         );
896         $table->data = array();
898         // Number of displayed plugins per type.
899         $numdisplayed = array();
900         // Number of plugins known to the plugin manager.
901         $sumtotal = 0;
902         // Number of plugins requiring attention.
903         $sumattention = 0;
904         // List of all components we can cancel installation of.
905         $installabortable = $pluginman->list_cancellable_installations();
906         // List of all components we can cancel upgrade of.
907         $upgradeabortable = $pluginman->list_restorable_archives();
909         foreach ($plugininfo as $type => $plugins) {
911             $header = new html_table_cell($pluginman->plugintype_name_plural($type));
912             $header->header = true;
913             $header->colspan = count($table->head);
914             $header = new html_table_row(array($header));
915             $header->attributes['class'] = 'plugintypeheader type-' . $type;
917             $numdisplayed[$type] = 0;
919             if (empty($plugins) and $options['full']) {
920                 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
921                 $msg->colspan = count($table->head);
922                 $row = new html_table_row(array($msg));
923                 $row->attributes['class'] .= 'msg msg-noneinstalled';
924                 $table->data[] = $header;
925                 $table->data[] = $row;
926                 continue;
927             }
929             $plugintyperows = array();
931             foreach ($plugins as $name => $plugin) {
932                 $sumtotal++;
933                 $row = new html_table_row();
934                 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
936                 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name, null)) {
937                     $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
938                 } else {
939                     $icon = '';
940                 }
942                 $displayname = new html_table_cell(
943                     $icon.
944                     html_writer::span($plugin->displayname, 'pluginname').
945                     html_writer::div($plugin->get_dir(), 'plugindir')
946                 );
948                 $versiondb = new html_table_cell($plugin->versiondb);
949                 $versiondisk = new html_table_cell($plugin->versiondisk);
951                 if ($isstandard = $plugin->is_standard()) {
952                     $row->attributes['class'] .= ' standard';
953                     $sourcelabel = html_writer::span(get_string('sourcestd', 'core_plugin'), 'sourcetext label');
954                 } else {
955                     $row->attributes['class'] .= ' extension';
956                     $sourcelabel = html_writer::span(get_string('sourceext', 'core_plugin'), 'sourcetext label label-info');
957                 }
959                 $coredependency = $plugin->is_core_dependency_satisfied($version);
960                 $otherpluginsdependencies = $pluginman->are_dependencies_satisfied($plugin->get_other_required_plugins());
961                 $dependenciesok = $coredependency && $otherpluginsdependencies;
963                 $statuscode = $plugin->get_status();
964                 $row->attributes['class'] .= ' status-' . $statuscode;
965                 $statusclass = 'statustext label ';
966                 switch ($statuscode) {
967                     case core_plugin_manager::PLUGIN_STATUS_NEW:
968                         $statusclass .= $dependenciesok ? 'label-success' : 'label-warning';
969                         break;
970                     case core_plugin_manager::PLUGIN_STATUS_UPGRADE:
971                         $statusclass .= $dependenciesok ? 'label-info' : 'label-warning';
972                         break;
973                     case core_plugin_manager::PLUGIN_STATUS_MISSING:
974                     case core_plugin_manager::PLUGIN_STATUS_DOWNGRADE:
975                     case core_plugin_manager::PLUGIN_STATUS_DELETE:
976                         $statusclass .= 'label-important';
977                         break;
978                     case core_plugin_manager::PLUGIN_STATUS_NODB:
979                     case core_plugin_manager::PLUGIN_STATUS_UPTODATE:
980                         $statusclass .= $dependenciesok ? '' : 'label-warning';
981                         break;
982                 }
983                 $status = html_writer::span(get_string('status_' . $statuscode, 'core_plugin'), $statusclass);
985                 if (!empty($installabortable[$plugin->component])) {
986                     $status .= $this->output->single_button(
987                         new moodle_url($this->page->url, array('abortinstall' => $plugin->component)),
988                         get_string('cancelinstallone', 'core_plugin'),
989                         'post',
990                         array('class' => 'actionbutton cancelinstallone')
991                     );
992                 }
994                 if (!empty($upgradeabortable[$plugin->component])) {
995                     $status .= $this->output->single_button(
996                         new moodle_url($this->page->url, array('abortupgrade' => $plugin->component)),
997                         get_string('cancelupgradeone', 'core_plugin'),
998                         'post',
999                         array('class' => 'actionbutton cancelupgradeone')
1000                     );
1001                 }
1003                 $availableupdates = $plugin->available_updates();
1004                 if (!empty($availableupdates)) {
1005                     foreach ($availableupdates as $availableupdate) {
1006                         $status .= $this->plugin_available_update_info($pluginman, $availableupdate);
1007                     }
1008                 }
1010                 $status = new html_table_cell($sourcelabel.' '.$status);
1012                 $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version));
1014                 $statusisboring = in_array($statuscode, array(
1015                         core_plugin_manager::PLUGIN_STATUS_NODB, core_plugin_manager::PLUGIN_STATUS_UPTODATE));
1017                 if ($options['xdep']) {
1018                     // we want to see only plugins with failed dependencies
1019                     if ($dependenciesok) {
1020                         continue;
1021                     }
1023                 } else if ($statusisboring and $dependenciesok and empty($availableupdates)) {
1024                     // no change is going to happen to the plugin - display it only
1025                     // if the user wants to see the full list
1026                     if (empty($options['full'])) {
1027                         continue;
1028                     }
1030                 } else {
1031                     $sumattention++;
1032                 }
1034                 // The plugin should be displayed.
1035                 $numdisplayed[$type]++;
1036                 $row->cells = array($displayname, $versiondb, $versiondisk, $requires, $status);
1037                 $plugintyperows[] = $row;
1038             }
1040             if (empty($numdisplayed[$type]) and empty($options['full'])) {
1041                 continue;
1042             }
1044             $table->data[] = $header;
1045             $table->data = array_merge($table->data, $plugintyperows);
1046         }
1048         // Total number of displayed plugins.
1049         $sumdisplayed = array_sum($numdisplayed);
1051         if ($options['xdep']) {
1052             // At the plugins dependencies check page, display the table only.
1053             return html_writer::table($table);
1054         }
1056         $out = $this->output->container_start('', 'plugins-check-info');
1058         if ($sumdisplayed == 0) {
1059             $out .= $this->output->heading(get_string('pluginchecknone', 'core_plugin'));
1061         } else {
1062             if (empty($options['full'])) {
1063                 $out .= $this->output->heading(get_string('plugincheckattention', 'core_plugin'));
1064             } else {
1065                 $out .= $this->output->heading(get_string('plugincheckall', 'core_plugin'));
1066             }
1067         }
1069         $out .= $this->output->container_start('actions');
1071         $installableupdates = $pluginman->filter_installable($pluginman->available_updates());
1072         if ($installableupdates) {
1073             $out .= $this->output->single_button(
1074                 new moodle_url($this->page->url, array('installupdatex' => 1)),
1075                 get_string('updateavailableinstallall', 'core_admin', count($installableupdates)),
1076                 'post',
1077                 array('class' => 'singlebutton updateavailableinstallall')
1078             );
1079         }
1081         if ($installabortable) {
1082             $out .= $this->output->single_button(
1083                 new moodle_url($this->page->url, array('abortinstallx' => 1)),
1084                 get_string('cancelinstallall', 'core_plugin', count($installabortable)),
1085                 'post',
1086                 array('class' => 'singlebutton cancelinstallall')
1087             );
1088         }
1090         if ($upgradeabortable) {
1091             $out .= $this->output->single_button(
1092                 new moodle_url($this->page->url, array('abortupgradex' => 1)),
1093                 get_string('cancelupgradeall', 'core_plugin', count($upgradeabortable)),
1094                 'post',
1095                 array('class' => 'singlebutton cancelupgradeall')
1096             );
1097         }
1099         $out .= html_writer::div(html_writer::link(new moodle_url($this->page->url, array('showallplugins' => 0)),
1100             get_string('plugincheckattention', 'core_plugin')).' '.html_writer::span($sumattention, 'badge'));
1102         $out .= html_writer::div(html_writer::link(new moodle_url($this->page->url, array('showallplugins' => 1)),
1103             get_string('plugincheckall', 'core_plugin')).' '.html_writer::span($sumtotal, 'badge'));
1105         $out .= $this->output->container_end(); // End of .actions container.
1106         $out .= $this->output->container_end(); // End of #plugins-check-info container.
1108         if ($sumdisplayed > 0 or $options['full']) {
1109             $out .= html_writer::table($table);
1110         }
1112         return $out;
1113     }
1115     /**
1116      * Display the continue / cancel widgets for the plugins management pages.
1117      *
1118      * @param null|moodle_url $continue URL for the continue button, should it be displayed
1119      * @param null|moodle_url $cancel URL for the cancel link, defaults to the current page
1120      * @return string HTML
1121      */
1122     public function plugins_management_confirm_buttons(moodle_url $continue=null, moodle_url $cancel=null) {
1124         $out = html_writer::start_div('plugins-management-confirm-buttons');
1126         if (!empty($continue)) {
1127             $out .= $this->output->single_button($continue, get_string('continue'), 'post', array('class' => 'continue'));
1128         }
1130         if (empty($cancel)) {
1131             $cancel = $this->page->url;
1132         }
1133         $out .= html_writer::div(html_writer::link($cancel, get_string('cancel')), 'cancel');
1135         return $out;
1136     }
1138     /**
1139      * Displays the information about missing dependencies
1140      *
1141      * @param core_plugin_manager $pluginman
1142      * @return string
1143      */
1144     protected function missing_dependencies(core_plugin_manager $pluginman) {
1146         $dependencies = $pluginman->missing_dependencies();
1148         if (empty($dependencies)) {
1149             return '';
1150         }
1152         $available = array();
1153         $unavailable = array();
1154         $unknown = array();
1156         foreach ($dependencies as $component => $remoteinfo) {
1157             if ($remoteinfo === false) {
1158                 // The required version is not available. Let us check if there
1159                 // is at least some version in the plugins directory.
1160                 $remoteinfoanyversion = $pluginman->get_remote_plugin_info($component, ANY_VERSION, false);
1161                 if ($remoteinfoanyversion === false) {
1162                     $unknown[$component] = $component;
1163                 } else {
1164                     $unavailable[$component] = $remoteinfoanyversion;
1165                 }
1166             } else {
1167                 $available[$component] = $remoteinfo;
1168             }
1169         }
1171         $out  = $this->output->container_start('plugins-check-dependencies');
1173         if ($unavailable or $unknown) {
1174             $out .= $this->output->heading(get_string('misdepsunavail', 'core_plugin'));
1175             if ($unknown) {
1176                 $out .= $this->output->notification(get_string('misdepsunknownlist', 'core_plugin', implode($unknown, ', ')));
1177             }
1178             if ($unavailable) {
1179                 $unavailablelist = array();
1180                 foreach ($unavailable as $component => $remoteinfoanyversion) {
1181                     $unavailablelistitem = html_writer::link('https://moodle.org/plugins/view.php?plugin='.$component,
1182                         '<strong>'.$remoteinfoanyversion->name.'</strong>');
1183                     if ($remoteinfoanyversion->version) {
1184                         $unavailablelistitem .= ' ('.$component.' &gt; '.$remoteinfoanyversion->version->version.')';
1185                     } else {
1186                         $unavailablelistitem .= ' ('.$component.')';
1187                     }
1188                     $unavailablelist[] = $unavailablelistitem;
1189                 }
1190                 $out .= $this->output->notification(get_string('misdepsunavaillist', 'core_plugin',
1191                     implode($unavailablelist, ', ')));
1192             }
1193             $out .= $this->output->container_start('plugins-check-dependencies-actions');
1194             $out .= ' '.html_writer::link(new moodle_url('/admin/tool/installaddon/'),
1195                 get_string('dependencyuploadmissing', 'core_plugin'));
1196             $out .= $this->output->container_end(); // End of .plugins-check-dependencies-actions container.
1197         }
1199         if ($available) {
1200             $out .= $this->output->heading(get_string('misdepsavail', 'core_plugin'));
1201             $out .= $this->output->container_start('plugins-check-dependencies-actions');
1203             $installable = $pluginman->filter_installable($available);
1204             if ($installable) {
1205                 $out .= $this->output->single_button(
1206                     new moodle_url($this->page->url, array('installdepx' => 1)),
1207                     get_string('dependencyinstallmissing', 'core_plugin', count($installable)),
1208                     'post',
1209                     array('class' => 'singlebutton dependencyinstallmissing')
1210                 );
1211             }
1213             $out .= html_writer::div(html_writer::link(new moodle_url('/admin/tool/installaddon/'),
1214                 get_string('dependencyuploadmissing', 'core_plugin')), 'dependencyuploadmissing');
1216             $out .= $this->output->container_end(); // End of .plugins-check-dependencies-actions container.
1218             $out .= $this->available_missing_dependencies_list($pluginman, $available);
1219         }
1221         $out .= $this->output->container_end(); // End of .plugins-check-dependencies container.
1223         return $out;
1224     }
1226     /**
1227      * Displays the list if available missing dependencies.
1228      *
1229      * @param core_plugin_manager $pluginman
1230      * @param array $dependencies
1231      * @return string
1232      */
1233     protected function available_missing_dependencies_list(core_plugin_manager $pluginman, array $dependencies) {
1234         global $CFG;
1236         $table = new html_table();
1237         $table->id = 'plugins-check-available-dependencies';
1238         $table->head = array(
1239             get_string('displayname', 'core_plugin'),
1240             get_string('release', 'core_plugin'),
1241             get_string('version', 'core_plugin'),
1242             get_string('supportedmoodleversions', 'core_plugin'),
1243             get_string('info', 'core'),
1244         );
1245         $table->colclasses = array('displayname', 'release', 'version', 'supportedmoodleversions', 'info');
1246         $table->data = array();
1248         foreach ($dependencies as $plugin) {
1250             $supportedmoodles = array();
1251             foreach ($plugin->version->supportedmoodles as $moodle) {
1252                 if ($CFG->branch == str_replace('.', '', $moodle->release)) {
1253                     $supportedmoodles[] = html_writer::span($moodle->release, 'label label-success');
1254                 } else {
1255                     $supportedmoodles[] = html_writer::span($moodle->release, 'label');
1256                 }
1257             }
1259             $requriedby = $pluginman->other_plugins_that_require($plugin->component);
1260             if ($requriedby) {
1261                 foreach ($requriedby as $ix => $val) {
1262                     $inf = $pluginman->get_plugin_info($val);
1263                     if ($inf) {
1264                         $requriedby[$ix] = $inf->displayname.' ('.$inf->component.')';
1265                     }
1266                 }
1267                 $info = html_writer::div(
1268                     get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
1269                     'requiredby'
1270                 );
1271             } else {
1272                 $info = '';
1273             }
1275             $info .= $this->output->container_start('actions');
1277             $info .= html_writer::div(
1278                 html_writer::link('https://moodle.org/plugins/view.php?plugin='.$plugin->component,
1279                     get_string('misdepinfoplugin', 'core_plugin')),
1280                 'misdepinfoplugin'
1281             );
1283             $info .= html_writer::div(
1284                 html_writer::link('https://moodle.org/plugins/pluginversion.php?id='.$plugin->version->id,
1285                     get_string('misdepinfoversion', 'core_plugin')),
1286                 'misdepinfoversion'
1287             );
1289             $info .= html_writer::div(html_writer::link($plugin->version->downloadurl, get_string('download')), 'misdepdownload');
1291             if ($pluginman->is_remote_plugin_installable($plugin->component, $plugin->version->version, $reason)) {
1292                 $info .= $this->output->single_button(
1293                     new moodle_url($this->page->url, array('installdep' => $plugin->component)),
1294                     get_string('dependencyinstall', 'core_plugin'),
1295                     'post',
1296                     array('class' => 'singlebutton dependencyinstall')
1297                 );
1298             } else {
1299                 $reasonhelp = $this->info_remote_plugin_not_installable($reason);
1300                 if ($reasonhelp) {
1301                     $info .= html_writer::div($reasonhelp, 'reasonhelp dependencyinstall');
1302                 }
1303             }
1305             $info .= $this->output->container_end(); // End of .actions container.
1307             $table->data[] = array(
1308                 html_writer::div($plugin->name, 'name').' '.html_writer::div($plugin->component, 'component'),
1309                 $plugin->version->release,
1310                 $plugin->version->version,
1311                 implode($supportedmoodles, ' '),
1312                 $info
1313             );
1314         }
1316         return html_writer::table($table);
1317     }
1319     /**
1320      * Explain why {@link core_plugin_manager::is_remote_plugin_installable()} returned false.
1321      *
1322      * @param string $reason the reason code as returned by the plugin manager
1323      * @return string
1324      */
1325     protected function info_remote_plugin_not_installable($reason) {
1327         if ($reason === 'notwritableplugintype' or $reason === 'notwritableplugin') {
1328             return $this->output->help_icon('notwritable', 'core_plugin', get_string('notwritable', 'core_plugin'));
1329         }
1331         if ($reason === 'remoteunavailable') {
1332             return $this->output->help_icon('notdownloadable', 'core_plugin', get_string('notdownloadable', 'core_plugin'));
1333         }
1335         return false;
1336     }
1338     /**
1339      * Formats the information that needs to go in the 'Requires' column.
1340      * @param \core\plugininfo\base $plugin the plugin we are rendering the row for.
1341      * @param core_plugin_manager $pluginman provides data on all the plugins.
1342      * @param string $version
1343      * @return string HTML code
1344      */
1345     protected function required_column(\core\plugininfo\base $plugin, core_plugin_manager $pluginman, $version) {
1347         $requires = array();
1348         $displayuploadlink = false;
1349         $displayupdateslink = false;
1351         foreach ($pluginman->resolve_requirements($plugin, $version) as $reqname => $reqinfo) {
1352             if ($reqname === 'core') {
1353                 if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OK) {
1354                     $class = 'requires-ok';
1355                     $label = '';
1356                 } else {
1357                     $class = 'requires-failed';
1358                     $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'label label-important');
1359                 }
1360                 $requires[] = html_writer::tag('li',
1361                     html_writer::span(get_string('moodleversion', 'core_plugin', $plugin->versionrequires), 'dep dep-core').
1362                     ' '.$label, array('class' => $class));
1364             } else {
1365                 $actions = array();
1367                 if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OK) {
1368                     $label = '';
1369                     $class = 'requires-ok';
1371                 } else if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_MISSING) {
1372                     if ($reqinfo->availability == $pluginman::REQUIREMENT_AVAILABLE) {
1373                         $label = html_writer::span(get_string('dependencymissing', 'core_plugin'), 'label label-warning');
1374                         $label .= ' '.html_writer::span(get_string('dependencyavailable', 'core_plugin'), 'label label-warning');
1375                         $class = 'requires-failed requires-missing requires-available';
1376                         $actions[] = html_writer::link(
1377                             new moodle_url('https://moodle.org/plugins/view.php', array('plugin' => $reqname)),
1378                             get_string('misdepinfoplugin', 'core_plugin')
1379                         );
1381                     } else {
1382                         $label = html_writer::span(get_string('dependencymissing', 'core_plugin'), 'label label-important');
1383                         $label .= ' '.html_writer::span(get_string('dependencyunavailable', 'core_plugin'),
1384                             'label label-important');
1385                         $class = 'requires-failed requires-missing requires-unavailable';
1386                     }
1387                     $displayuploadlink = true;
1389                 } else if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OUTDATED) {
1390                     if ($reqinfo->availability == $pluginman::REQUIREMENT_AVAILABLE) {
1391                         $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'label label-warning');
1392                         $label .= ' '.html_writer::span(get_string('dependencyavailable', 'core_plugin'), 'label label-warning');
1393                         $class = 'requires-failed requires-outdated requires-available';
1394                         $displayupdateslink = true;
1396                     } else {
1397                         $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'label label-important');
1398                         $label .= ' '.html_writer::span(get_string('dependencyunavailable', 'core_plugin'),
1399                             'label label-important');
1400                         $class = 'requires-failed requires-outdated requires-unavailable';
1401                     }
1402                     $displayuploadlink = true;
1403                 }
1405                 if ($reqinfo->reqver != ANY_VERSION) {
1406                     $str = 'otherpluginversion';
1407                 } else {
1408                     $str = 'otherplugin';
1409                 }
1411                 $requires[] = html_writer::tag('li', html_writer::span(
1412                     get_string($str, 'core_plugin', array('component' => $reqname, 'version' => $reqinfo->reqver)),
1413                     'dep dep-plugin').' '.$label.' '.html_writer::span(implode(' | ', $actions), 'actions'),
1414                     array('class' => $class)
1415                 );
1416             }
1417         }
1419         if (!$requires) {
1420             return '';
1421         }
1423         $out = html_writer::tag('ul', implode("\n", $requires));
1425         if ($displayuploadlink) {
1426             $out .= html_writer::div(
1427                 html_writer::link(
1428                     new moodle_url('/admin/tool/installaddon/'),
1429                     get_string('dependencyuploadmissing', 'core_plugin')
1430                 ),
1431                 'dependencyuploadmissing'
1432             );
1433         }
1435         if ($displayupdateslink) {
1436             $out .= html_writer::div(
1437                 html_writer::link(
1438                     new moodle_url($this->page->url, array('sesskey' => sesskey(), 'fetchupdates' => 1)),
1439                     get_string('checkforupdates', 'core_plugin')
1440                 ),
1441                 'checkforupdates'
1442             );
1443         }
1445         return $out;
1447     }
1449     /**
1450      * Prints an overview about the plugins - number of installed, number of extensions etc.
1451      *
1452      * @param core_plugin_manager $pluginman provides information about the plugins
1453      * @param array $options filtering options
1454      * @return string as usually
1455      */
1456     public function plugins_overview_panel(core_plugin_manager $pluginman, array $options = array()) {
1458         $plugininfo = $pluginman->get_plugins();
1460         $numtotal = $numextension = $numupdatable = 0;
1462         foreach ($plugininfo as $type => $plugins) {
1463             foreach ($plugins as $name => $plugin) {
1464                 if ($plugin->available_updates()) {
1465                     $numupdatable++;
1466                 }
1467                 if ($plugin->get_status() === core_plugin_manager::PLUGIN_STATUS_MISSING) {
1468                     continue;
1469                 }
1470                 $numtotal++;
1471                 if (!$plugin->is_standard()) {
1472                     $numextension++;
1473                 }
1474             }
1475         }
1477         $infoall = html_writer::link(
1478             new moodle_url($this->page->url, array('contribonly' => 0, 'updatesonly' => 0)),
1479             get_string('overviewall', 'core_plugin'),
1480             array('title' => get_string('filterall', 'core_plugin'))
1481         ).' '.html_writer::span($numtotal, 'badge number number-all');
1483         $infoext = html_writer::link(
1484             new moodle_url($this->page->url, array('contribonly' => 1, 'updatesonly' => 0)),
1485             get_string('overviewext', 'core_plugin'),
1486             array('title' => get_string('filtercontribonly', 'core_plugin'))
1487         ).' '.html_writer::span($numextension, 'badge number number-additional');
1489         if ($numupdatable) {
1490             $infoupdatable = html_writer::link(
1491                 new moodle_url($this->page->url, array('contribonly' => 0, 'updatesonly' => 1)),
1492                 get_string('overviewupdatable', 'core_plugin'),
1493                 array('title' => get_string('filterupdatesonly', 'core_plugin'))
1494             ).' '.html_writer::span($numupdatable, 'badge badge-info number number-updatable');
1495         } else {
1496             // No updates, or the notifications disabled.
1497             $infoupdatable = '';
1498         }
1500         $out = html_writer::start_div('', array('id' => 'plugins-overview-panel'));
1502         if (!empty($options['updatesonly'])) {
1503             $out .= $this->output->heading(get_string('overviewupdatable', 'core_plugin'), 3);
1504         } else if (!empty($options['contribonly'])) {
1505             $out .= $this->output->heading(get_string('overviewext', 'core_plugin'), 3);
1506         }
1508         if ($numupdatable) {
1509             $installableupdates = $pluginman->filter_installable($pluginman->available_updates());
1510             if ($installableupdates) {
1511                 $out .= $this->output->single_button(
1512                     new moodle_url($this->page->url, array('installupdatex' => 1)),
1513                     get_string('updateavailableinstallall', 'core_admin', count($installableupdates)),
1514                     'post',
1515                     array('class' => 'singlebutton updateavailableinstallall')
1516                 );
1517             }
1518         }
1520         $out .= html_writer::div($infoall, 'info info-all').
1521             html_writer::div($infoext, 'info info-ext').
1522             html_writer::div($infoupdatable, 'info info-updatable');
1524         $out .= html_writer::end_div(); // End of #plugins-overview-panel block.
1526         return $out;
1527     }
1529     /**
1530      * Displays all known plugins and links to manage them
1531      *
1532      * This default implementation renders all plugins into one big table.
1533      *
1534      * @param core_plugin_manager $pluginman provides information about the plugins.
1535      * @param array $options filtering options
1536      * @return string HTML code
1537      */
1538     public function plugins_control_panel(core_plugin_manager $pluginman, array $options = array()) {
1540         $plugininfo = $pluginman->get_plugins();
1542         // Filter the list of plugins according the options.
1543         if (!empty($options['updatesonly'])) {
1544             $updateable = array();
1545             foreach ($plugininfo as $plugintype => $pluginnames) {
1546                 foreach ($pluginnames as $pluginname => $pluginfo) {
1547                     $pluginavailableupdates = $pluginfo->available_updates();
1548                     if (!empty($pluginavailableupdates)) {
1549                         foreach ($pluginavailableupdates as $pluginavailableupdate) {
1550                             $updateable[$plugintype][$pluginname] = $pluginfo;
1551                         }
1552                     }
1553                 }
1554             }
1555             $plugininfo = $updateable;
1556         }
1558         if (!empty($options['contribonly'])) {
1559             $contribs = array();
1560             foreach ($plugininfo as $plugintype => $pluginnames) {
1561                 foreach ($pluginnames as $pluginname => $pluginfo) {
1562                     if (!$pluginfo->is_standard()) {
1563                         $contribs[$plugintype][$pluginname] = $pluginfo;
1564                     }
1565                 }
1566             }
1567             $plugininfo = $contribs;
1568         }
1570         if (empty($plugininfo)) {
1571             return '';
1572         }
1574         $table = new html_table();
1575         $table->id = 'plugins-control-panel';
1576         $table->head = array(
1577             get_string('displayname', 'core_plugin'),
1578             get_string('version', 'core_plugin'),
1579             get_string('availability', 'core_plugin'),
1580             get_string('actions', 'core_plugin'),
1581             get_string('notes','core_plugin'),
1582         );
1583         $table->headspan = array(1, 1, 1, 2, 1);
1584         $table->colclasses = array(
1585             'pluginname', 'version', 'availability', 'settings', 'uninstall', 'notes'
1586         );
1588         foreach ($plugininfo as $type => $plugins) {
1589             $heading = $pluginman->plugintype_name_plural($type);
1590             $pluginclass = core_plugin_manager::resolve_plugininfo_class($type);
1591             if ($manageurl = $pluginclass::get_manage_url()) {
1592                 $heading .= $this->output->action_icon($manageurl, new pix_icon('i/settings',
1593                     get_string('settings', 'core_plugin')));
1594             }
1595             $header = new html_table_cell(html_writer::tag('span', $heading, array('id'=>'plugin_type_cell_'.$type)));
1596             $header->header = true;
1597             $header->colspan = array_sum($table->headspan);
1598             $header = new html_table_row(array($header));
1599             $header->attributes['class'] = 'plugintypeheader type-' . $type;
1600             $table->data[] = $header;
1602             if (empty($plugins)) {
1603                 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
1604                 $msg->colspan = array_sum($table->headspan);
1605                 $row = new html_table_row(array($msg));
1606                 $row->attributes['class'] .= 'msg msg-noneinstalled';
1607                 $table->data[] = $row;
1608                 continue;
1609             }
1611             foreach ($plugins as $name => $plugin) {
1612                 $row = new html_table_row();
1613                 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
1615                 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name, null)) {
1616                     $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'icon pluginicon'));
1617                 } else {
1618                     $icon = $this->output->spacer();
1619                 }
1620                 $status = $plugin->get_status();
1621                 $row->attributes['class'] .= ' status-'.$status;
1622                 $pluginname  = html_writer::tag('div', $icon.$plugin->displayname, array('class' => 'displayname')).
1623                                html_writer::tag('div', $plugin->component, array('class' => 'componentname'));
1624                 $pluginname  = new html_table_cell($pluginname);
1626                 $version = html_writer::div($plugin->versiondb, 'versionnumber');
1627                 if ((string)$plugin->release !== '') {
1628                     $version = html_writer::div($plugin->release, 'release').$version;
1629                 }
1630                 $version = new html_table_cell($version);
1632                 $isenabled = $plugin->is_enabled();
1633                 if (is_null($isenabled)) {
1634                     $availability = new html_table_cell('');
1635                 } else if ($isenabled) {
1636                     $row->attributes['class'] .= ' enabled';
1637                     $availability = new html_table_cell(get_string('pluginenabled', 'core_plugin'));
1638                 } else {
1639                     $row->attributes['class'] .= ' disabled';
1640                     $availability = new html_table_cell(get_string('plugindisabled', 'core_plugin'));
1641                 }
1643                 $settingsurl = $plugin->get_settings_url();
1644                 if (!is_null($settingsurl)) {
1645                     $settings = html_writer::link($settingsurl, get_string('settings', 'core_plugin'), array('class' => 'settings'));
1646                 } else {
1647                     $settings = '';
1648                 }
1649                 $settings = new html_table_cell($settings);
1651                 if ($uninstallurl = $pluginman->get_uninstall_url($plugin->component, 'overview')) {
1652                     $uninstall = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin'));
1653                 } else {
1654                     $uninstall = '';
1655                 }
1656                 $uninstall = new html_table_cell($uninstall);
1658                 if ($plugin->is_standard()) {
1659                     $row->attributes['class'] .= ' standard';
1660                     $source = '';
1661                 } else {
1662                     $row->attributes['class'] .= ' extension';
1663                     $source = html_writer::div(get_string('sourceext', 'core_plugin'), 'source label label-info');
1664                 }
1666                 if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) {
1667                     $msg = html_writer::div(get_string('status_missing', 'core_plugin'), 'statusmsg label label-important');
1668                 } else if ($status === core_plugin_manager::PLUGIN_STATUS_NEW) {
1669                     $msg = html_writer::div(get_string('status_new', 'core_plugin'), 'statusmsg label label-success');
1670                 } else {
1671                     $msg = '';
1672                 }
1674                 $requriedby = $pluginman->other_plugins_that_require($plugin->component);
1675                 if ($requriedby) {
1676                     $requiredby = html_writer::tag('div', get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
1677                         array('class' => 'requiredby'));
1678                 } else {
1679                     $requiredby = '';
1680                 }
1682                 $updateinfo = '';
1683                 if (is_array($plugin->available_updates())) {
1684                     foreach ($plugin->available_updates() as $availableupdate) {
1685                         $updateinfo .= $this->plugin_available_update_info($pluginman, $availableupdate);
1686                     }
1687                 }
1689                 $notes = new html_table_cell($source.$msg.$requiredby.$updateinfo);
1691                 $row->cells = array(
1692                     $pluginname, $version, $availability, $settings, $uninstall, $notes
1693                 );
1694                 $table->data[] = $row;
1695             }
1696         }
1698         return html_writer::table($table);
1699     }
1701     /**
1702      * Helper method to render the information about the available plugin update
1703      *
1704      * @param core_plugin_manager $pluginman plugin manager instance
1705      * @param \core\update\info $updateinfo information about the available update for the plugin
1706      */
1707     protected function plugin_available_update_info(core_plugin_manager $pluginman, \core\update\info $updateinfo) {
1709         $boxclasses = 'pluginupdateinfo';
1710         $info = array();
1712         if (isset($updateinfo->release)) {
1713             $info[] = html_writer::div(
1714                 get_string('updateavailable_release', 'core_plugin', $updateinfo->release),
1715                 'info release'
1716             );
1717         }
1719         if (isset($updateinfo->maturity)) {
1720             $info[] = html_writer::div(
1721                 get_string('maturity'.$updateinfo->maturity, 'core_admin'),
1722                 'info maturity'
1723             );
1724             $boxclasses .= ' maturity'.$updateinfo->maturity;
1725         }
1727         if (isset($updateinfo->download)) {
1728             $info[] = html_writer::div(
1729                 html_writer::link($updateinfo->download, get_string('download')),
1730                 'info download'
1731             );
1732         }
1734         if (isset($updateinfo->url)) {
1735             $info[] = html_writer::div(
1736                 html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin')),
1737                 'info more'
1738             );
1739         }
1741         $box = html_writer::start_div($boxclasses);
1742         $box .= html_writer::div(
1743             get_string('updateavailable', 'core_plugin', $updateinfo->version),
1744             'version'
1745         );
1746         $box .= html_writer::div(
1747             implode(html_writer::span(' ', 'separator'), $info),
1748             'infos'
1749         );
1751         if ($pluginman->is_remote_plugin_installable($updateinfo->component, $updateinfo->version, $reason)) {
1752             $box .= $this->output->single_button(
1753                 new moodle_url($this->page->url, array('installupdate' => $updateinfo->component,
1754                     'installupdateversion' => $updateinfo->version)),
1755                 get_string('updateavailableinstall', 'core_admin'),
1756                 'post',
1757                 array('class' => 'singlebutton updateavailableinstall')
1758             );
1759         } else {
1760             $reasonhelp = $this->info_remote_plugin_not_installable($reason);
1761             if ($reasonhelp) {
1762                 $box .= html_writer::div($reasonhelp, 'reasonhelp updateavailableinstall');
1763             }
1764         }
1765         $box .= html_writer::end_div();
1767         return $box;
1768     }
1770     /**
1771      * This function will render one beautiful table with all the environmental
1772      * configuration and how it suits Moodle needs.
1773      *
1774      * @param boolean $result final result of the check (true/false)
1775      * @param environment_results[] $environment_results array of results gathered
1776      * @return string HTML to output.
1777      */
1778     public function environment_check_table($result, $environment_results) {
1779         global $CFG;
1781         // Table headers
1782         $servertable = new html_table();//table for server checks
1783         $servertable->head  = array(
1784             get_string('name'),
1785             get_string('info'),
1786             get_string('report'),
1787             get_string('plugin'),
1788             get_string('status'),
1789         );
1790         $servertable->colclasses = array('centeralign name', 'centeralign info', 'leftalign report', 'leftalign plugin', 'centeralign status');
1791         $servertable->attributes['class'] = 'admintable environmenttable generaltable';
1792         $servertable->id = 'serverstatus';
1794         $serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
1796         $othertable = new html_table();//table for custom checks
1797         $othertable->head  = array(
1798             get_string('info'),
1799             get_string('report'),
1800             get_string('plugin'),
1801             get_string('status'),
1802         );
1803         $othertable->colclasses = array('aligncenter info', 'alignleft report', 'alignleft plugin', 'aligncenter status');
1804         $othertable->attributes['class'] = 'admintable environmenttable generaltable';
1805         $othertable->id = 'otherserverstatus';
1807         $otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
1809         // Iterate over each environment_result
1810         $continue = true;
1811         foreach ($environment_results as $environment_result) {
1812             $errorline   = false;
1813             $warningline = false;
1814             $stringtouse = '';
1815             if ($continue) {
1816                 $type = $environment_result->getPart();
1817                 $info = $environment_result->getInfo();
1818                 $status = $environment_result->getStatus();
1819                 $plugin = $environment_result->getPluginName();
1820                 $error_code = $environment_result->getErrorCode();
1821                 // Process Report field
1822                 $rec = new stdClass();
1823                 // Something has gone wrong at parsing time
1824                 if ($error_code) {
1825                     $stringtouse = 'environmentxmlerror';
1826                     $rec->error_code = $error_code;
1827                     $status = get_string('error');
1828                     $errorline = true;
1829                     $continue = false;
1830                 }
1832                 if ($continue) {
1833                     if ($rec->needed = $environment_result->getNeededVersion()) {
1834                         // We are comparing versions
1835                         $rec->current = $environment_result->getCurrentVersion();
1836                         if ($environment_result->getLevel() == 'required') {
1837                             $stringtouse = 'environmentrequireversion';
1838                         } else {
1839                             $stringtouse = 'environmentrecommendversion';
1840                         }
1842                     } else if ($environment_result->getPart() == 'custom_check') {
1843                         // We are checking installed & enabled things
1844                         if ($environment_result->getLevel() == 'required') {
1845                             $stringtouse = 'environmentrequirecustomcheck';
1846                         } else {
1847                             $stringtouse = 'environmentrecommendcustomcheck';
1848                         }
1850                     } else if ($environment_result->getPart() == 'php_setting') {
1851                         if ($status) {
1852                             $stringtouse = 'environmentsettingok';
1853                         } else if ($environment_result->getLevel() == 'required') {
1854                             $stringtouse = 'environmentmustfixsetting';
1855                         } else {
1856                             $stringtouse = 'environmentshouldfixsetting';
1857                         }
1859                     } else {
1860                         if ($environment_result->getLevel() == 'required') {
1861                             $stringtouse = 'environmentrequireinstall';
1862                         } else {
1863                             $stringtouse = 'environmentrecommendinstall';
1864                         }
1865                     }
1867                     // Calculate the status value
1868                     if ($environment_result->getBypassStr() != '') {            //Handle bypassed result (warning)
1869                         $status = get_string('bypassed');
1870                         $warningline = true;
1871                     } else if ($environment_result->getRestrictStr() != '') {   //Handle restricted result (error)
1872                         $status = get_string('restricted');
1873                         $errorline = true;
1874                     } else {
1875                         if ($status) {                                          //Handle ok result (ok)
1876                             $status = get_string('ok');
1877                         } else {
1878                             if ($environment_result->getLevel() == 'optional') {//Handle check result (warning)
1879                                 $status = get_string('check');
1880                                 $warningline = true;
1881                             } else {                                            //Handle error result (error)
1882                                 $status = get_string('check');
1883                                 $errorline = true;
1884                             }
1885                         }
1886                     }
1887                 }
1889                 // Build the text
1890                 $linkparts = array();
1891                 $linkparts[] = 'admin/environment';
1892                 $linkparts[] = $type;
1893                 if (!empty($info)){
1894                    $linkparts[] = $info;
1895                 }
1896                 // Plugin environments do not have docs pages yet.
1897                 if (empty($CFG->docroot) or $environment_result->plugin) {
1898                     $report = get_string($stringtouse, 'admin', $rec);
1899                 } else {
1900                     $report = $this->doc_link(join($linkparts, '/'), get_string($stringtouse, 'admin', $rec));
1901                 }
1902                 // Enclose report text in div so feedback text will be displayed underneath it.
1903                 $report = html_writer::div($report);
1905                 // Format error or warning line
1906                 if ($errorline) {
1907                     $messagetype = 'error';
1908                     $statusclass = 'label-important';
1909                 } else if ($warningline) {
1910                     $messagetype = 'warn';
1911                     $statusclass = 'label-warning';
1912                 } else {
1913                     $messagetype = 'ok';
1914                     $statusclass = 'label-success';
1915                 }
1916                 $status = html_writer::span($status, 'label ' . $statusclass);
1917                 // Here we'll store all the feedback found
1918                 $feedbacktext = '';
1919                 // Append the feedback if there is some
1920                 $feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), $messagetype);
1921                 //Append the bypass if there is some
1922                 $feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'warn');
1923                 //Append the restrict if there is some
1924                 $feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'error');
1926                 $report .= $feedbacktext;
1928                 // Add the row to the table
1929                 if ($environment_result->getPart() == 'custom_check'){
1930                     $otherdata[$messagetype][] = array ($info, $report, $plugin, $status);
1931                 } else {
1932                     $serverdata[$messagetype][] = array ($type, $info, $report, $plugin, $status);
1933                 }
1934             }
1935         }
1937         //put errors first in
1938         $servertable->data = array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']);
1939         $othertable->data = array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']);
1941         // Print table
1942         $output = '';
1943         $output .= $this->heading(get_string('serverchecks', 'admin'));
1944         $output .= html_writer::table($servertable);
1945         if (count($othertable->data)){
1946             $output .= $this->heading(get_string('customcheck', 'admin'));
1947             $output .= html_writer::table($othertable);
1948         }
1950         // Finally, if any error has happened, print the summary box
1951         if (!$result) {
1952             $output .= $this->box(get_string('environmenterrortodo', 'admin'), 'environmentbox errorbox');
1953         }
1955         return $output;
1956     }
1958     /**
1959      * Render a simple page for providing the upgrade key.
1960      *
1961      * @param moodle_url|string $url
1962      * @return string
1963      */
1964     public function upgradekey_form_page($url) {
1966         $output = '';
1967         $output .= $this->header();
1968         $output .= $this->container_start('upgradekeyreq');
1969         $output .= $this->heading(get_string('upgradekeyreq', 'core_admin'));
1970         $output .= html_writer::start_tag('form', array('method' => 'POST', 'action' => $url));
1971         $output .= html_writer::empty_tag('input', array('name' => 'upgradekey', 'type' => 'password'));
1972         $output .= html_writer::empty_tag('input', array('value' => get_string('submit'), 'type' => 'submit'));
1973         $output .= html_writer::end_tag('form');
1974         $output .= $this->container_end();
1975         $output .= $this->footer();
1977         return $output;
1978     }
1980     /**
1981      * Check to see if writing to the deprecated legacy log store is enabled.
1982      *
1983      * @return string An error message if writing to the legacy log store is enabled.
1984      */
1985     protected function legacy_log_store_writing_error() {
1986         $enabled = get_config('logstore_legacy', 'loglegacy');
1987         $plugins = explode(',', get_config('tool_log', 'enabled_stores'));
1988         $enabled = $enabled && in_array('logstore_legacy', $plugins);
1990         if ($enabled) {
1991             return $this->warning(get_string('legacylogginginuse'));
1992         }
1993     }