MDL-49329 admin: Improve plugins overview page rendering
[moodle.git] / admin / renderer.php
CommitLineData
b9934a17
DM
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/>.
16
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 */
25
26defined('MOODLE_INTERNAL') || die();
27
b9934a17
DM
28
29/**
30 * Standard HTML output renderer for core_admin subsystem
31 */
32class core_admin_renderer extends plugin_renderer_base {
33
cc359566
TH
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 = '';
42
43 $copyrightnotice = text_to_html(get_string('gpl3'));
44 $copyrightnotice = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $copyrightnotice); // extremely ugly validation hack
45
98b32c9e
DM
46 $continue = new single_button(new moodle_url($this->page->url, array(
47 'lang' => $CFG->lang, 'agreelicense' => 1)), get_string('continue'), 'get');
cc359566
TH
48
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();
56
57 return $output;
58 }
59
9008ec16
PS
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');
774c42a8 71 $output .= format_text(get_string('upgradestalefilesinfo', 'admin', get_docs_url('Upgrading')), FORMAT_MARKDOWN);
9008ec16
PS
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();
cc359566
TH
76
77 return $output;
78 }
79
80 /**
81 * Display the 'environment check' page that is displayed during install.
8d1da748
PS
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
cc359566
TH
86 * @return string HTML to output.
87 */
8d1da748 88 public function install_environment_page($maturity, $envstatus, $environment_results, $release) {
cc359566
TH
89 global $CFG;
90 $output = '';
91
92 $output .= $this->header();
93 $output .= $this->maturity_warning($maturity);
94 $output .= $this->heading("Moodle $release");
95 $output .= $this->release_notes_link();
96
97 $output .= $this->environment_check_table($envstatus, $environment_results);
98
99 if (!$envstatus) {
98b32c9e 100 $output .= $this->upgrade_reload(new moodle_url($this->page->url, array('agreelicense' => 1, 'lang' => $CFG->lang)));
cc359566
TH
101 } else {
102 $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
98b32c9e
DM
103 $output .= $this->continue_button(new moodle_url($this->page->url, array(
104 'agreelicense' => 1, 'confirmrelease' => 1, 'lang' => $CFG->lang)));
cc359566
TH
105 }
106
107 $output .= $this->footer();
108 return $output;
109 }
110
39f15cc7
DM
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
e937c545 116 * @param moodle_url $reloadurl URL of the page to recheck the dependencies
39f15cc7
DM
117 * @return string HTML
118 */
119 public function unsatisfied_dependencies_page($version, array $failed, moodle_url $reloadurl) {
120 $output = '';
121
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)))));
e87214bd 125 $output .= $this->plugins_check_table(core_plugin_manager::instance(), $version, array('xdep' => true));
39f15cc7
DM
126 $output .= $this->warning(get_string('pluginschecktodo', 'admin'));
127 $output .= $this->continue_button($reloadurl);
128
129 $output .= $this->footer();
130
131 return $output;
132 }
133
cc359566
TH
134 /**
135 * Display the 'You are about to upgrade Moodle' page. The first page
136 * during upgrade.
8d1da748
PS
137 * @param string $strnewversion
138 * @param int $maturity
6e09cf98 139 * @param string $testsite
cc359566
TH
140 * @return string HTML to output.
141 */
6e09cf98 142 public function upgrade_confirm_page($strnewversion, $maturity, $testsite) {
cc359566
TH
143 $output = '';
144
98b32c9e 145 $continueurl = new moodle_url($this->page->url, array('confirmupgrade' => 1, 'cache' => 0));
82b1cf00
PS
146 $continue = new single_button($continueurl, get_string('continue'), 'get');
147 $cancelurl = new moodle_url('/admin/index.php');
cc359566
TH
148
149 $output .= $this->header();
150 $output .= $this->maturity_warning($maturity);
6e09cf98 151 $output .= $this->test_site_warning($testsite);
82b1cf00 152 $output .= $this->confirm(get_string('upgradesure', 'admin', $strnewversion), $continue, $cancelurl);
cc359566
TH
153 $output .= $this->footer();
154
155 return $output;
156 }
157
158 /**
159 * Display the environment page during the upgrade process.
8d1da748
PS
160 * @param string $release
161 * @param boolean $envstatus final result of env check (true/false)
162 * @param array $environment_results array of results gathered
cc359566
TH
163 * @return string HTML to output.
164 */
165 public function upgrade_environment_page($release, $envstatus, $environment_results) {
166 global $CFG;
167 $output = '';
168
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);
173
174 if (!$envstatus) {
98b32c9e 175 $output .= $this->upgrade_reload(new moodle_url($this->page->url, array('confirmupgrade' => 1, 'cache' => 0)));
cc359566
TH
176
177 } else {
faadd326 178 $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
cc359566
TH
179
180 if (empty($CFG->skiplangupgrade) and current_language() !== 'en') {
181 $output .= $this->box(get_string('langpackwillbeupdated', 'admin'), 'generalbox', 'notice');
182 }
183
98b32c9e
DM
184 $output .= $this->continue_button(new moodle_url($this->page->url, array(
185 'confirmupgrade' => 1, 'confirmrelease' => 1, 'cache' => 0)));
cc359566
TH
186 }
187
188 $output .= $this->footer();
189
190 return $output;
191 }
192
193 /**
194 * Display the upgrade page that lists all the plugins that require attention.
e87214bd
PS
195 * @param core_plugin_manager $pluginman provides information about the plugins.
196 * @param \core\update\checker $checker provides information about available updates.
8d1da748
PS
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
cc359566
TH
201 * @return string HTML to output.
202 */
e87214bd 203 public function upgrade_plugin_check_page(core_plugin_manager $pluginman, \core\update\checker $checker,
96dd9237
DM
204 $version, $showallplugins, $reloadurl, $continueurl) {
205
cc359566
TH
206 $output = '';
207
208 $output .= $this->header();
2f29cf6e
DM
209 $output .= $this->box_start('generalbox', 'plugins-check-page');
210 $output .= html_writer::tag('p', get_string('pluginchecknotice', 'core_plugin'), array('class' => 'page-description'));
44371554 211 $output .= $this->check_for_updates_button($checker, $reloadurl);
5a92cd0b 212 $output .= $this->missing_dependencies($pluginman);
faadd326 213 $output .= $this->plugins_check_table($pluginman, $version, array('full' => $showallplugins));
cc359566
TH
214 $output .= $this->box_end();
215 $output .= $this->upgrade_reload($reloadurl);
216
ead8ba3b
DM
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();
faadd326 221 }
cc359566 222
ead8ba3b
DM
223 $button = new single_button($continueurl, get_string('upgradestart', 'admin'), 'get');
224 $button->class = 'continuebutton';
225 $output .= $this->render($button);
cc359566
TH
226 $output .= $this->footer();
227
228 return $output;
229 }
230
231 /**
232 * Display the admin notifications page.
8d1da748
PS
233 * @param int $maturity
234 * @param bool $insecuredataroot warn dataroot is invalid
235 * @param bool $errorsdisplayed warn invalid dispaly error setting
236 * @param bool $cronoverdue warn cron not running
237 * @param bool $dbproblems warn db has problems
238 * @param bool $maintenancemode warn in maintenance mode
0aff15c2 239 * @param bool $buggyiconvnomb warn iconv problems
e87214bd 240 * @param array|null $availableupdates array of \core\update\info objects or null
55585f3a 241 * @param int|null $availableupdatesfetch timestamp of the most recent updates fetch or null (unknown)
915140c9 242 * @param string[] $cachewarnings An array containing warnings from the Cache API.
55585f3a 243 *
cc359566
TH
244 * @return string HTML to output.
245 */
246 public function admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed,
b3245b75 247 $cronoverdue, $dbproblems, $maintenancemode, $availableupdates, $availableupdatesfetch,
915140c9 248 $buggyiconvnomb, $registered, array $cachewarnings = array()) {
4db58f5f 249 global $CFG;
cc359566
TH
250 $output = '';
251
252 $output .= $this->header();
253 $output .= $this->maturity_info($maturity);
4db58f5f 254 $output .= empty($CFG->disableupdatenotifications) ? $this->available_updates($availableupdates, $availableupdatesfetch) : '';
cc359566
TH
255 $output .= $this->insecure_dataroot_warning($insecuredataroot);
256 $output .= $this->display_errors_warning($errorsdisplayed);
0aff15c2 257 $output .= $this->buggy_iconv_warning($buggyiconvnomb);
e3258164 258 $output .= $this->cron_overdue_warning($cronoverdue);
cc359566
TH
259 $output .= $this->db_problems($dbproblems);
260 $output .= $this->maintenance_mode_warning($maintenancemode);
915140c9 261 $output .= $this->cache_warnings($cachewarnings);
b3245b75 262 $output .= $this->registration_warning($registered);
cc359566
TH
263
264 //////////////////////////////////////////////////////////////////////////////////////////////////
265 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
266 $output .= $this->moodle_copyright();
267 //////////////////////////////////////////////////////////////////////////////////////////////////
268
269 $output .= $this->footer();
270
271 return $output;
272 }
273
8342171b
DM
274 /**
275 * Display the plugin management page (admin/plugins.php).
276 *
4df8bced
DM
277 * The filtering options array may contain following items:
278 * bool contribonly - show only contributed extensions
279 * bool updatesonly - show only plugins with an available update
280 *
e87214bd
PS
281 * @param core_plugin_manager $pluginman
282 * @param \core\update\checker $checker
4df8bced 283 * @param array $options filtering options
8342171b
DM
284 * @return string HTML to output.
285 */
e87214bd 286 public function plugin_management_page(core_plugin_manager $pluginman, \core\update\checker $checker, array $options = array()) {
7716057f 287
8342171b
DM
288 $output = '';
289
290 $output .= $this->header();
291 $output .= $this->heading(get_string('pluginsoverview', 'core_admin'));
4df8bced 292 $output .= $this->plugins_overview_panel($pluginman, $options);
44371554
DM
293 $output .= $this->check_for_updates_button($checker, $this->page->url);
294 $output .= $this->plugins_control_panel($pluginman, $options);
295 $output .= $this->footer();
296
297 return $output;
298 }
299
300 /**
301 * Renders a button to fetch for available updates.
302 *
303 * @param \core\update\checker $checker
304 * @param moodle_url $reloadurl
305 * @return string HTML
306 */
307 public function check_for_updates_button(\core\update\checker $checker, $reloadurl) {
308
309 $output = '';
8342171b 310
e9d3c212 311 if ($checker->enabled()) {
7716057f 312 $output .= $this->container_start('checkforupdates');
4df8bced 313 $output .= $this->single_button(
44371554 314 new moodle_url($reloadurl, array('fetchremote' => 1)),
4df8bced
DM
315 get_string('checkforupdates', 'core_plugin')
316 );
7716057f 317 if ($timefetched = $checker->get_last_timefetched()) {
44371554
DM
318 $timefetched = userdate($timefetched, get_string('strftimedatetime', 'core_langconfig'));
319 $output .= $this->container(get_string('checkforupdateslast', 'core_plugin', $timefetched), 'lasttimefetched');
7716057f
DM
320 }
321 $output .= $this->container_end();
8342171b 322 }
8342171b 323
8342171b
DM
324 return $output;
325 }
326
436d9447
DM
327 /**
328 * Display a page to confirm the plugin uninstallation.
329 *
e87214bd
PS
330 * @param core_plugin_manager $pluginman
331 * @param \core\plugininfo\base $pluginfo
436d9447 332 * @param moodle_url $continueurl URL to continue after confirmation
e87214bd 333 * @param moodle_url $cancelurl URL to to go if cancelled
436d9447
DM
334 * @return string
335 */
e87214bd 336 public function plugin_uninstall_confirm_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, moodle_url $continueurl, moodle_url $cancelurl) {
436d9447
DM
337 $output = '';
338
339 $pluginname = $pluginman->plugin_name($pluginfo->component);
340
2f87bb03
PS
341 $confirm = '<p>' . get_string('uninstallconfirm', 'core_plugin', array('name' => $pluginname)) . '</p>';
342 if ($extraconfirm = $pluginfo->get_uninstall_extra_warning()) {
343 $confirm .= $extraconfirm;
344 }
345
436d9447
DM
346 $output .= $this->output->header();
347 $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
e87214bd 348 $output .= $this->output->confirm($confirm, $continueurl, $cancelurl);
436d9447
DM
349 $output .= $this->output->footer();
350
351 return $output;
352 }
353
354 /**
355 * Display a page with results of plugin uninstallation and offer removal of plugin files.
356 *
e87214bd
PS
357 * @param core_plugin_manager $pluginman
358 * @param \core\plugininfo\base $pluginfo
3ca1b546 359 * @param progress_trace_buffer $progress
436d9447
DM
360 * @param moodle_url $continueurl URL to continue to remove the plugin folder
361 * @return string
362 */
e87214bd 363 public function plugin_uninstall_results_removable_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo,
3ca1b546 364 progress_trace_buffer $progress, moodle_url $continueurl) {
436d9447
DM
365 $output = '';
366
367 $pluginname = $pluginman->plugin_name($pluginfo->component);
368
82b1cf00
PS
369 // Do not show navigation here, they must click one of the buttons.
370 $this->page->set_pagelayout('maintenance');
371 $this->page->set_cacheable(false);
372
436d9447
DM
373 $output .= $this->output->header();
374 $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
375
3ca1b546 376 $output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
436d9447
DM
377
378 $confirm = $this->output->container(get_string('uninstalldeleteconfirm', 'core_plugin',
379 array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'uninstalldeleteconfirm');
380
381 if ($repotype = $pluginman->plugin_external_source($pluginfo->component)) {
382 $confirm .= $this->output->container(get_string('uninstalldeleteconfirmexternal', 'core_plugin', $repotype),
383 'uninstalldeleteconfirmexternal');
384 }
385
82b1cf00
PS
386 // After any uninstall we must execute full upgrade to finish the cleanup!
387 $output .= $this->output->confirm($confirm, $continueurl, new moodle_url('/admin/index.php'));
436d9447
DM
388 $output .= $this->output->footer();
389
390 return $output;
391 }
392
393 /**
394 * Display a page with results of plugin uninstallation and inform about the need to remove plugin files manually.
395 *
e87214bd
PS
396 * @param core_plugin_manager $pluginman
397 * @param \core\plugininfo\base $pluginfo
3ca1b546 398 * @param progress_trace_buffer $progress
436d9447
DM
399 * @return string
400 */
e87214bd 401 public function plugin_uninstall_results_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, progress_trace_buffer $progress) {
436d9447
DM
402 $output = '';
403
2612e75e 404 $pluginname = $pluginfo->component;
436d9447 405
436d9447
DM
406 $output .= $this->output->header();
407 $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
408
3ca1b546 409 $output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
436d9447
DM
410
411 $output .= $this->output->box(get_string('uninstalldelete', 'core_plugin',
412 array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'generalbox uninstalldelete');
2612e75e 413 $output .= $this->output->continue_button(new moodle_url('/admin/index.php'));
436d9447
DM
414 $output .= $this->output->footer();
415
416 return $output;
417 }
418
cc359566
TH
419 /**
420 * Display the plugin management page (admin/environment.php).
8d1da748
PS
421 * @param array $versions
422 * @param string $version
423 * @param boolean $envstatus final result of env check (true/false)
424 * @param array $environment_results array of results gathered
cc359566
TH
425 * @return string HTML to output.
426 */
427 public function environment_check_page($versions, $version, $envstatus, $environment_results) {
428 $output = '';
429 $output .= $this->header();
430
431 // Print the component download link
432 $output .= html_writer::tag('div', html_writer::link(
433 new moodle_url('/admin/environment.php', array('action' => 'updatecomponent', 'sesskey' => sesskey())),
434 get_string('updatecomponent', 'admin')),
435 array('class' => 'reportlink'));
436
437 // Heading.
438 $output .= $this->heading(get_string('environment', 'admin'));
439
440 // Box with info and a menu to choose the version.
441 $output .= $this->box_start();
442 $output .= html_writer::tag('div', get_string('adminhelpenvironment'));
443 $select = new single_select(new moodle_url('/admin/environment.php'), 'version', $versions, $version, null);
444 $select->label = get_string('moodleversion');
445 $output .= $this->render($select);
446 $output .= $this->box_end();
447
448 // The results
449 $output .= $this->environment_check_table($envstatus, $environment_results);
450
451 $output .= $this->footer();
452 return $output;
453 }
454
455 /**
456 * Output a warning message, of the type that appears on the admin notifications page.
457 * @param string $message the message to display.
8d1da748 458 * @param string $type type class
cc359566
TH
459 * @return string HTML to output.
460 */
461 protected function warning($message, $type = 'warning') {
462 return $this->box($message, 'generalbox admin' . $type);
463 }
464
465 /**
466 * Render an appropriate message if dataroot is insecure.
8d1da748 467 * @param bool $insecuredataroot
cc359566
TH
468 * @return string HTML to output.
469 */
470 protected function insecure_dataroot_warning($insecuredataroot) {
471 global $CFG;
472
473 if ($insecuredataroot == INSECURE_DATAROOT_WARNING) {
474 return $this->warning(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot));
475
476 } else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) {
477 return $this->warning(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'error');
478
479 } else {
480 return '';
481 }
482 }
483
484 /**
485 * Render an appropriate message if dataroot is insecure.
8d1da748 486 * @param bool $errorsdisplayed
cc359566
TH
487 * @return string HTML to output.
488 */
489 protected function display_errors_warning($errorsdisplayed) {
490 if (!$errorsdisplayed) {
491 return '';
492 }
493
494 return $this->warning(get_string('displayerrorswarning', 'admin'));
495 }
496
0aff15c2
PS
497 /**
498 * Render an appropriate message if iconv is buggy and mbstring missing.
499 * @param bool $buggyiconvnomb
500 * @return string HTML to output.
501 */
502 protected function buggy_iconv_warning($buggyiconvnomb) {
503 if (!$buggyiconvnomb) {
504 return '';
505 }
506
507 return $this->warning(get_string('warningiconvbuggy', 'admin'));
508 }
509
cc359566
TH
510 /**
511 * Render an appropriate message if cron has not been run recently.
8d1da748 512 * @param bool $cronoverdue
cc359566
TH
513 * @return string HTML to output.
514 */
515 public function cron_overdue_warning($cronoverdue) {
ed25d7c4 516 global $CFG;
cc359566
TH
517 if (!$cronoverdue) {
518 return '';
519 }
520
ed25d7c4
MS
521 if (empty($CFG->cronclionly)) {
522 $url = new moodle_url('/admin/cron.php');
523 if (!empty($CFG->cronremotepassword)) {
524 $url = new moodle_url('/admin/cron.php', array('password' => $CFG->cronremotepassword));
525 }
526
527 return $this->warning(get_string('cronwarning', 'admin', $url->out()) . '&nbsp;' .
528 $this->help_icon('cron', 'admin'));
529 }
530
531 // $CFG->cronclionly is not empty: cron can run only from CLI.
532 return $this->warning(get_string('cronwarningcli', 'admin') . '&nbsp;' .
cc359566
TH
533 $this->help_icon('cron', 'admin'));
534 }
535
536 /**
537 * Render an appropriate message if there are any problems with the DB set-up.
8d1da748 538 * @param bool $dbproblems
cc359566
TH
539 * @return string HTML to output.
540 */
541 public function db_problems($dbproblems) {
542 if (!$dbproblems) {
543 return '';
544 }
545
546 return $this->warning($dbproblems);
547 }
548
915140c9
SH
549 /**
550 * Renders cache warnings if there are any.
551 *
552 * @param string[] $cachewarnings
553 * @return string
554 */
555 public function cache_warnings(array $cachewarnings) {
556 if (!count($cachewarnings)) {
557 return '';
558 }
559 return join("\n", array_map(array($this, 'warning'), $cachewarnings));
560 }
561
cc359566
TH
562 /**
563 * Render an appropriate message if the site in in maintenance mode.
8d1da748 564 * @param bool $maintenancemode
cc359566
TH
565 * @return string HTML to output.
566 */
567 public function maintenance_mode_warning($maintenancemode) {
568 if (!$maintenancemode) {
569 return '';
570 }
571
ecc2897c
PS
572 $url = new moodle_url('/admin/settings.php', array('section' => 'maintenancemode'));
573 $url = $url->out(); // get_string() does not support objects in params
574
575 return $this->warning(get_string('sitemaintenancewarning2', 'admin', $url));
cc359566
TH
576 }
577
578 /**
579 * Display a warning about installing development code if necesary.
8d1da748 580 * @param int $maturity
cc359566
TH
581 * @return string HTML to output.
582 */
583 protected function maturity_warning($maturity) {
584 if ($maturity == MATURITY_STABLE) {
585 return ''; // No worries.
586 }
587
588 $maturitylevel = get_string('maturity' . $maturity, 'admin');
7f52dbd8 589 return $this->warning(
cc359566
TH
590 $this->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
591 $this->container($this->doc_link('admin/versions', get_string('morehelp'))),
7f52dbd8 592 'error');
cc359566
TH
593 }
594
6e09cf98
DM
595 /*
596 * If necessary, displays a warning about upgrading a test site.
597 *
598 * @param string $testsite
599 * @return string HTML
600 */
601 protected function test_site_warning($testsite) {
602
603 if (!$testsite) {
604 return '';
605 }
606
7f52dbd8
DS
607 $warning = (get_string('testsiteupgradewarning', 'admin', $testsite));
608 return $this->warning($warning, 'error');
6e09cf98
DM
609 }
610
cc359566
TH
611 /**
612 * Output the copyright notice.
613 * @return string HTML to output.
614 */
615 protected function moodle_copyright() {
616 global $CFG;
617
618 //////////////////////////////////////////////////////////////////////////////////////////////////
619 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
620 $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
621 '<a href="http://docs.moodle.org/dev/Releases" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
622 'Copyright &copy; 1999 onwards, Martin Dougiamas<br />'.
956082f1 623 'and <a href="http://moodle.org/dev">many other contributors</a>.<br />'.
cc359566
TH
624 '<a href="http://docs.moodle.org/dev/License">GNU Public License</a>';
625 //////////////////////////////////////////////////////////////////////////////////////////////////
626
627 return $this->box($copyrighttext, 'copyright');
628 }
629
630 /**
631 * Display a warning about installing development code if necesary.
8d1da748
PS
632 * @param int $maturity
633 * @return string HTML to output.
cc359566
TH
634 */
635 protected function maturity_info($maturity) {
636 if ($maturity == MATURITY_STABLE) {
637 return ''; // No worries.
638 }
639
7f52dbd8
DS
640 $level = 'warning';
641
642 if ($maturity == MATURITY_ALPHA) {
643 $level = 'error';
644 }
645
cc359566 646 $maturitylevel = get_string('maturity' . $maturity, 'admin');
7f52dbd8
DS
647 $warningtext = get_string('maturitycoreinfo', 'admin', $maturitylevel);
648 $warningtext .= ' ' . $this->doc_link('admin/versions', get_string('morehelp'));
649 return $this->warning($warningtext, $level);
cc359566
TH
650 }
651
55585f3a 652 /**
966bd785 653 * Displays the info about available Moodle core and plugin updates
55585f3a 654 *
966bd785
DM
655 * The structure of the $updates param has changed since 2.4. It contains not only updates
656 * for the core itself, but also for all other installed plugins.
657 *
e87214bd 658 * @param array|null $updates array of (string)component => array of \core\update\info objects or null
55585f3a
DM
659 * @param int|null $fetch timestamp of the most recent updates fetch or null (unknown)
660 * @return string
661 */
662 protected function available_updates($updates, $fetch) {
663
7f52dbd8 664 $updateinfo = '';
966bd785 665 $someupdateavailable = false;
55585f3a 666 if (is_array($updates)) {
966bd785
DM
667 if (is_array($updates['core'])) {
668 $someupdateavailable = true;
669 $updateinfo .= $this->heading(get_string('updateavailable', 'core_admin'), 3);
670 foreach ($updates['core'] as $update) {
671 $updateinfo .= $this->moodle_available_update_info($update);
672 }
657cb5ab
DM
673 $updateinfo .= html_writer::tag('p', get_string('updateavailablerecommendation', 'core_admin'),
674 array('class' => 'updateavailablerecommendation'));
55585f3a 675 }
966bd785
DM
676 unset($updates['core']);
677 // If something has left in the $updates array now, it is updates for plugins.
678 if (!empty($updates)) {
679 $someupdateavailable = true;
680 $updateinfo .= $this->heading(get_string('updateavailableforplugin', 'core_admin'), 3);
681 $pluginsoverviewurl = new moodle_url('/admin/plugins.php', array('updatesonly' => 1));
682 $updateinfo .= $this->container(get_string('pluginsoverviewsee', 'core_admin',
683 array('url' => $pluginsoverviewurl->out())));
684 }
685 }
686
687 if (!$someupdateavailable) {
cb1c3291
DM
688 $now = time();
689 if ($fetch and ($fetch <= $now) and ($now - $fetch < HOURSECS)) {
690 $updateinfo .= $this->heading(get_string('updateavailablenot', 'core_admin'), 3);
691 }
55585f3a
DM
692 }
693
694 $updateinfo .= $this->container_start('checkforupdates');
fc281113 695 $fetchurl = new moodle_url('/admin/index.php', array('fetchupdates' => 1, 'sesskey' => sesskey(), 'cache' => 0));
e2e35e71 696 $updateinfo .= $this->single_button($fetchurl, get_string('checkforupdates', 'core_plugin'));
55585f3a
DM
697 if ($fetch) {
698 $updateinfo .= $this->container(get_string('checkforupdateslast', 'core_plugin',
699 userdate($fetch, get_string('strftimedatetime', 'core_langconfig'))));
700 }
701 $updateinfo .= $this->container_end();
702
7f52dbd8 703 return $this->warning($updateinfo);
55585f3a
DM
704 }
705
b3245b75
DP
706 /**
707 * Display a warning about not being registered on Moodle.org if necesary.
708 *
709 * @param boolean $registered true if the site is registered on Moodle.org
710 * @return string HTML to output.
711 */
712 protected function registration_warning($registered) {
713
714 if (!$registered) {
715
82b1cf00 716 $registerbutton = $this->single_button(new moodle_url('/admin/registration/register.php',
b3245b75
DP
717 array('huburl' => HUB_MOODLEORGHUBURL, 'hubname' => 'Moodle.org')),
718 get_string('register', 'admin'));
719
720 return $this->warning( get_string('registrationwarning', 'admin')
721 . '&nbsp;' . $this->help_icon('registration', 'admin') . $registerbutton );
722 }
723
724 return '';
725 }
726
55585f3a
DM
727 /**
728 * Helper method to render the information about the available Moodle update
729 *
e87214bd 730 * @param \core\update\info $updateinfo information about the available Moodle core update
55585f3a 731 */
e87214bd 732 protected function moodle_available_update_info(\core\update\info $updateinfo) {
55585f3a
DM
733
734 $boxclasses = 'moodleupdateinfo';
735 $info = array();
736
737 if (isset($updateinfo->release)) {
738 $info[] = html_writer::tag('span', get_string('updateavailable_release', 'core_admin', $updateinfo->release),
739 array('class' => 'info release'));
740 }
741
742 if (isset($updateinfo->version)) {
743 $info[] = html_writer::tag('span', get_string('updateavailable_version', 'core_admin', $updateinfo->version),
744 array('class' => 'info version'));
745 }
746
747 if (isset($updateinfo->maturity)) {
748 $info[] = html_writer::tag('span', get_string('maturity'.$updateinfo->maturity, 'core_admin'),
749 array('class' => 'info maturity'));
750 $boxclasses .= ' maturity'.$updateinfo->maturity;
751 }
752
753 if (isset($updateinfo->download)) {
754 $info[] = html_writer::link($updateinfo->download, get_string('download'), array('class' => 'info download'));
755 }
756
757 if (isset($updateinfo->url)) {
758 $info[] = html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin'),
759 array('class' => 'info more'));
760 }
761
762 $box = $this->output->box_start($boxclasses);
763 $box .= $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $info), '');
764 $box .= $this->output->box_end();
765
766 return $box;
767 }
768
cc359566
TH
769 /**
770 * Display a link to the release notes.
8d1da748 771 * @return string HTML to output.
cc359566
TH
772 */
773 protected function release_notes_link() {
774 $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/dev/Releases');
775 $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
776 return $this->box($releasenoteslink, 'generalbox releasenoteslink');
777 }
778
779 /**
780 * Display the reload link that appears on several upgrade/install pages.
8d1da748 781 * @return string HTML to output.
cc359566
TH
782 */
783 function upgrade_reload($url) {
784 return html_writer::empty_tag('br') .
785 html_writer::tag('div',
c2e10ac0 786 html_writer::link($url, $this->pix_icon('i/reload', '', '', array('class' => 'icon icon-pre')) .
cc359566
TH
787 get_string('reload'), array('title' => get_string('reload'))),
788 array('class' => 'continuebutton')) . html_writer::empty_tag('br');
789 }
790
b9934a17
DM
791 /**
792 * Displays all known plugins and information about their installation or upgrade
793 *
794 * This default implementation renders all plugins into one big table. The rendering
795 * options support:
796 * (bool)full = false: whether to display up-to-date plugins, too
39f15cc7 797 * (bool)xdep = false: display the plugins with unsatisified dependecies only
b9934a17 798 *
e87214bd 799 * @param core_plugin_manager $pluginman provides information about the plugins.
faadd326 800 * @param int $version the version of the Moodle code from version.php.
b9934a17
DM
801 * @param array $options rendering options
802 * @return string HTML code
803 */
e87214bd 804 public function plugins_check_table(core_plugin_manager $pluginman, $version, array $options = array()) {
fa1d403f 805
36ca62ca 806 $plugininfo = $pluginman->get_plugins();
b9934a17
DM
807
808 if (empty($plugininfo)) {
809 return '';
810 }
811
39f15cc7
DM
812 $options['full'] = isset($options['full']) ? (bool)$options['full'] : false;
813 $options['xdep'] = isset($options['xdep']) ? (bool)$options['xdep'] : false;
b9934a17 814
b9934a17
DM
815 $table = new html_table();
816 $table->id = 'plugins-check';
817 $table->head = array(
fd17898c 818 get_string('displayname', 'core_plugin').' / '.get_string('rootdir', 'core_plugin'),
b9934a17
DM
819 get_string('versiondb', 'core_plugin'),
820 get_string('versiondisk', 'core_plugin'),
36ca62ca 821 get_string('requires', 'core_plugin'),
fd17898c 822 get_string('source', 'core_plugin').' / '.get_string('status', 'core_plugin'),
b9934a17
DM
823 );
824 $table->colclasses = array(
fd17898c 825 'displayname', 'versiondb', 'versiondisk', 'requires', 'status',
b9934a17
DM
826 );
827 $table->data = array();
828
0ec7d101
DM
829 // Number of displayed plugins per type.
830 $numdisplayed = array();
831 // Number of plugins known to the plugin manager.
832 $sumtotal = 0;
833 // Number of plugins requiring attention.
834 $sumattention = 0;
2f29cf6e
DM
835 // List of all components we can cancel installation of.
836 $installabortable = array();
b9934a17
DM
837
838 foreach ($plugininfo as $type => $plugins) {
839
840 $header = new html_table_cell($pluginman->plugintype_name_plural($type));
841 $header->header = true;
842 $header->colspan = count($table->head);
843 $header = new html_table_row(array($header));
844 $header->attributes['class'] = 'plugintypeheader type-' . $type;
845
0ec7d101 846 $numdisplayed[$type] = 0;
b9934a17
DM
847
848 if (empty($plugins) and $options['full']) {
849 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
850 $msg->colspan = count($table->head);
851 $row = new html_table_row(array($msg));
852 $row->attributes['class'] .= 'msg msg-noneinstalled';
853 $table->data[] = $header;
854 $table->data[] = $row;
855 continue;
856 }
857
858 $plugintyperows = array();
859
860 foreach ($plugins as $name => $plugin) {
0ec7d101 861 $sumtotal++;
b9934a17
DM
862 $row = new html_table_row();
863 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
864
436dbeec 865 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name, null)) {
b9934a17
DM
866 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
867 } else {
fd17898c 868 $icon = '';
b9934a17 869 }
b9934a17 870
fd17898c
DM
871 $displayname = new html_table_cell(
872 $icon.
873 html_writer::span($plugin->displayname, 'pluginname').
874 html_writer::div($plugin->get_dir(), 'plugindir')
875 );
876
877 $versiondb = new html_table_cell($plugin->versiondb);
878 $versiondisk = new html_table_cell($plugin->versiondisk);
b9934a17
DM
879
880 if ($isstandard = $plugin->is_standard()) {
881 $row->attributes['class'] .= ' standard';
fd17898c 882 $sourcelabel = html_writer::span(get_string('sourcestd', 'core_plugin'), 'sourcetext label');
b9934a17
DM
883 } else {
884 $row->attributes['class'] .= ' extension';
fd17898c 885 $sourcelabel = html_writer::span(get_string('sourceext', 'core_plugin'), 'sourcetext label label-info');
b9934a17
DM
886 }
887
fd17898c
DM
888 $coredependency = $plugin->is_core_dependency_satisfied($version);
889 $otherpluginsdependencies = $pluginman->are_dependencies_satisfied($plugin->get_other_required_plugins());
890 $dependenciesok = $coredependency && $otherpluginsdependencies;
b9934a17
DM
891
892 $statuscode = $plugin->get_status();
893 $row->attributes['class'] .= ' status-' . $statuscode;
fd17898c
DM
894 $statusclass = 'statustext label ';
895 switch ($statuscode) {
896 case core_plugin_manager::PLUGIN_STATUS_NEW:
897 $statusclass .= $dependenciesok ? 'label-success' : 'label-warning';
898 break;
899 case core_plugin_manager::PLUGIN_STATUS_UPGRADE:
900 $statusclass .= $dependenciesok ? 'label-info' : 'label-warning';
901 break;
902 case core_plugin_manager::PLUGIN_STATUS_MISSING:
903 case core_plugin_manager::PLUGIN_STATUS_DOWNGRADE:
904 case core_plugin_manager::PLUGIN_STATUS_DELETE:
905 $statusclass .= 'label-important';
906 break;
907 case core_plugin_manager::PLUGIN_STATUS_NODB:
908 case core_plugin_manager::PLUGIN_STATUS_UPTODATE:
909 $statusclass .= $dependenciesok ? '' : 'label-warning';
910 break;
911 }
912 $status = html_writer::span(get_string('status_' . $statuscode, 'core_plugin'), $statusclass);
96dd9237 913
2f29cf6e
DM
914 if ($statuscode == core_plugin_manager::PLUGIN_STATUS_NEW and !$plugin->is_standard()) {
915 if ($pluginman->is_plugin_folder_removable($plugin->component)) {
916 $installabortable[] = $plugin->component;
917 $status .= $this->output->single_button(
918 new moodle_url($this->page->url, array('abortinstall' => $plugin->component)),
919 get_string('cancelinstallone', 'core_plugin'),
920 'post',
921 array('class' => 'actionbutton')
922 );
923 }
924 }
925
96dd9237 926 $availableupdates = $plugin->available_updates();
e9d3c212 927 if (!empty($availableupdates)) {
96dd9237 928 foreach ($availableupdates as $availableupdate) {
3bca7dbf 929 $status .= $this->plugin_available_update_info($pluginman, $availableupdate);
96dd9237
DM
930 }
931 }
b9934a17 932
fd17898c 933 $status = new html_table_cell($sourcelabel.' '.$status);
b9934a17 934
faadd326 935 $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version));
36ca62ca
TH
936
937 $statusisboring = in_array($statuscode, array(
e87214bd 938 core_plugin_manager::PLUGIN_STATUS_NODB, core_plugin_manager::PLUGIN_STATUS_UPTODATE));
e937c545 939
39f15cc7
DM
940 if ($options['xdep']) {
941 // we want to see only plugins with failed dependencies
942 if ($dependenciesok) {
943 continue;
944 }
945
2f838a4e 946 } else if ($statusisboring and $dependenciesok and empty($availableupdates)) {
39f15cc7
DM
947 // no change is going to happen to the plugin - display it only
948 // if the user wants to see the full list
b9934a17
DM
949 if (empty($options['full'])) {
950 continue;
951 }
b9934a17 952
0ec7d101
DM
953 } else {
954 $sumattention++;
955 }
39f15cc7 956
0ec7d101
DM
957 // The plugin should be displayed.
958 $numdisplayed[$type]++;
fd17898c 959 $row->cells = array($displayname, $versiondb, $versiondisk, $requires, $status);
b9934a17
DM
960 $plugintyperows[] = $row;
961 }
962
0ec7d101 963 if (empty($numdisplayed[$type]) and empty($options['full'])) {
b9934a17
DM
964 continue;
965 }
966
967 $table->data[] = $header;
968 $table->data = array_merge($table->data, $plugintyperows);
969 }
970
0ec7d101
DM
971 // Total number of displayed plugins.
972 $sumdisplayed = array_sum($numdisplayed);
b9934a17 973
39f15cc7 974 if ($options['xdep']) {
0ec7d101
DM
975 // At the plugins dependencies check page, display the table only.
976 return html_writer::table($table);
977 }
978
979 $out = $this->output->container_start('', 'plugins-check-info');
39f15cc7 980
0ec7d101
DM
981 if ($sumdisplayed == 0) {
982 $out .= $this->output->heading(get_string('pluginchecknone', 'core_plugin'));
b9934a17
DM
983
984 } else {
b9934a17 985 if (empty($options['full'])) {
0ec7d101 986 $out .= $this->output->heading(get_string('plugincheckattention', 'core_plugin'));
a687fcac 987 } else {
0ec7d101 988 $out .= $this->output->heading(get_string('plugincheckall', 'core_plugin'));
b9934a17 989 }
228cbda3 990 }
2f29cf6e 991
228cbda3
DM
992 $out .= $this->output->container_start('actions');
993 if ($installabortable) {
994 $out .= $this->output->single_button(
995 new moodle_url($this->page->url, array('abortinstallx' => 1)),
996 get_string('cancelinstallall', 'core_plugin', count($installabortable)),
997 'post',
998 array('class' => 'singlebutton cancelinstallall')
999 );
1000 }
0ec7d101 1001
228cbda3
DM
1002 $out .= html_writer::div(html_writer::link(new moodle_url($this->page->url, array('showallplugins' => 0)),
1003 get_string('plugincheckattention', 'core_plugin')).' '.html_writer::span($sumattention, 'badge'));
2f29cf6e 1004
228cbda3
DM
1005 $out .= html_writer::div(html_writer::link(new moodle_url($this->page->url, array('showallplugins' => 1)),
1006 get_string('plugincheckall', 'core_plugin')).' '.html_writer::span($sumtotal, 'badge'));
b9934a17 1007
228cbda3 1008 $out .= $this->output->container_end(); // .actions
0ec7d101
DM
1009 $out .= $this->output->container_end(); // #plugins-check-info
1010
1011 if ($sumdisplayed > 0 or $options['full']) {
b9934a17
DM
1012 $out .= html_writer::table($table);
1013 }
1014
1015 return $out;
1016 }
1017
5a92cd0b
DM
1018 /**
1019 * Displays the information about missing dependencies
1020 *
1021 * @param core_plugin_manager $pluginman
1022 * @return string
1023 */
1024 protected function missing_dependencies(core_plugin_manager $pluginman) {
1025
1026 $dependencies = $pluginman->missing_dependencies();
1027
1028 if (empty($dependencies)) {
1029 return '';
1030 }
1031
1032 $available = array();
1033 $unavailable = array();
1034 $unknown = array();
1035
1036 foreach ($dependencies as $component => $remoteinfo) {
1037 if ($remoteinfo === false) {
35f2b674 1038 // The required version is not available. Let us check if there
5a92cd0b 1039 // is at least some version in the plugins directory.
35f2b674 1040 $remoteinfoanyversion = $pluginman->get_remote_plugin_info($component, ANY_VERSION, false);
5a92cd0b
DM
1041 if ($remoteinfoanyversion === false) {
1042 $unknown[$component] = $component;
1043 } else {
1044 $unavailable[$component] = $remoteinfoanyversion;
1045 }
1046 } else {
1047 $available[$component] = $remoteinfo;
1048 }
1049 }
1050
1051 $out = $this->output->container_start('plugins-check-dependencies');
1052
1053 if ($unavailable or $unknown) {
1054 $out .= $this->output->heading(get_string('misdepsunavail', 'core_plugin'));
1055 if ($unknown) {
1056 $out .= $this->output->notification(get_string('misdepsunknownlist', 'core_plugin', implode($unknown, ', ')));
1057 }
1058 if ($unavailable) {
1059 $unavailablelist = array();
1060 foreach ($unavailable as $component => $remoteinfoanyversion) {
1061 $unavailablelistitem = html_writer::link('https://moodle.org/plugins/view.php?plugin='.$component,
1062 '<strong>'.$remoteinfoanyversion->name.'</strong>');
1063 if ($remoteinfoanyversion->version) {
1064 $unavailablelistitem .= ' ('.$component.' &gt; '.$remoteinfoanyversion->version->version.')';
1065 } else {
1066 $unavailablelistitem .= ' ('.$component.')';
1067 }
1068 $unavailablelist[] = $unavailablelistitem;
1069 }
1070 $out .= $this->output->notification(get_string('misdepsunavaillist', 'core_plugin',
1071 implode($unavailablelist, ', ')));
1072 }
1073 $out .= $this->output->container_start('plugins-check-dependencies-actions');
1074 $out .= ' '.html_writer::link(new moodle_url('/admin/tool/installaddon/'),
1075 get_string('dependencyuploadmissing', 'core_plugin'));
1076 $out .= $this->output->container_end(); // .plugins-check-dependencies-actions
1077 }
1078
1079 if ($available) {
1080 $out .= $this->output->heading(get_string('misdepsavail', 'core_plugin'));
9137a89a
DM
1081 $installable = array();
1082 foreach ($available as $component => $remoteinfo) {
1083 if ($pluginman->is_remote_plugin_installable($component, $remoteinfo->version->version)) {
1084 $installable[$component] = $remoteinfo;
1085 }
1086 }
1087
5a92cd0b
DM
1088 $out .= $this->output->container_start('plugins-check-dependencies-actions');
1089
9137a89a
DM
1090 if ($installable) {
1091 $out .= $this->output->single_button(
1092 new moodle_url($this->page->url, array('installdepx' => 1)),
1093 get_string('dependencyinstallmissing', 'core_plugin', count($installable)),
1094 'post',
1095 array('class' => 'singlebutton dependencyinstallmissing')
1096 );
1097 }
1098
1099 $out.= html_writer::div(html_writer::link(new moodle_url('/admin/tool/installaddon/'),
1100 get_string('dependencyuploadmissing', 'core_plugin')), 'dependencyuploadmissing');
1101
5a92cd0b 1102 $out .= $this->output->container_end(); // .plugins-check-dependencies-actions
9137a89a
DM
1103
1104 $out .= $this->available_missing_dependencies_list($pluginman, $available);
5a92cd0b
DM
1105 }
1106
1107 $out .= $this->output->container_end(); // .plugins-check-dependencies
1108
1109 return $out;
1110 }
1111
1112 /**
1113 * Displays the list if available missing dependencies.
1114 *
1115 * @param core_plugin_manager $pluginman
1116 * @param array $dependencies
1117 * @return string
1118 */
1119 protected function available_missing_dependencies_list(core_plugin_manager $pluginman, array $dependencies) {
1120 global $CFG;
1121
1122 $table = new html_table();
1123 $table->id = 'plugins-check-available-dependencies';
1124 $table->head = array(
1125 get_string('displayname', 'core_plugin'),
1126 get_string('release', 'core_plugin'),
1127 get_string('version', 'core_plugin'),
1128 get_string('supportedmoodleversions', 'core_plugin'),
1129 get_string('info', 'core'),
1130 );
1131 $table->colclasses = array('displayname', 'release', 'version', 'supportedmoodleversions', 'info');
1132 $table->data = array();
1133
1134 foreach ($dependencies as $plugin) {
1135
1136 $supportedmoodles = array();
1137 foreach ($plugin->version->supportedmoodles as $moodle) {
1138 if ($CFG->branch == str_replace('.', '', $moodle->release)) {
1139 $supportedmoodles[] = html_writer::span($moodle->release, 'label label-success');
1140 } else {
1141 $supportedmoodles[] = html_writer::span($moodle->release, 'label');
1142 }
1143 }
1144
1145 $requriedby = $pluginman->other_plugins_that_require($plugin->component);
1146 if ($requriedby) {
1147 foreach ($requriedby as $ix => $val) {
1148 $inf = $pluginman->get_plugin_info($val);
1149 if ($inf) {
1150 $requriedby[$ix] = $inf->displayname.' ('.$inf->component.')';
1151 }
1152 }
1153 $info = html_writer::div(
1154 get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
1155 'requiredby'
1156 );
1157 } else {
1158 $info = '';
1159 }
1160
9137a89a
DM
1161 $info .= $this->output->container_start('actions');
1162
1163 $info .= html_writer::div(
5a92cd0b
DM
1164 html_writer::link('https://moodle.org/plugins/view.php?plugin='.$plugin->component,
1165 get_string('misdepinfoplugin', 'core_plugin')),
1166 'misdepinfoplugin'
1167 );
1168
9137a89a 1169 $info .= html_writer::div(
5a92cd0b
DM
1170 html_writer::link('https://moodle.org/plugins/pluginversion.php?id='.$plugin->version->id,
1171 get_string('misdepinfoversion', 'core_plugin')),
1172 'misdepinfoversion'
1173 );
1174
9137a89a
DM
1175 $info .= html_writer::div(html_writer::link($plugin->version->downloadurl, get_string('download')), 'misdepdownload');
1176
36977a6d 1177 if ($pluginman->is_remote_plugin_installable($plugin->component, $plugin->version->version, $reason)) {
9137a89a
DM
1178 $info .= $this->output->single_button(
1179 new moodle_url($this->page->url, array('installdep' => $plugin->component)),
1180 get_string('dependencyinstall', 'core_plugin'),
1181 'post',
1182 array('class' => 'singlebutton dependencyinstall')
1183 );
36977a6d
DM
1184 } else {
1185 $reasonhelp = $this->info_remote_plugin_not_installable($reason);
1186 if ($reasonhelp) {
1187 $info .= html_writer::div($reasonhelp, 'reasonhelp dependencyinstall');
1188 }
9137a89a 1189 }
5a92cd0b 1190
9137a89a 1191 $info .= $this->output->container_end(); // .actions
5a92cd0b
DM
1192
1193 $table->data[] = array(
1194 html_writer::div($plugin->name, 'name').' '.html_writer::div($plugin->component, 'component'),
1195 $plugin->version->release,
1196 $plugin->version->version,
1197 implode($supportedmoodles, ' '),
1198 $info
1199 );
1200 }
1201
1202 return html_writer::table($table);
1203 }
1204
36977a6d
DM
1205 /**
1206 * Explain why {@link core_plugin_manager::is_remote_plugin_installable()} returned false.
1207 *
1208 * @param string $reason the reason code as returned by the plugin manager
1209 * @return string
1210 */
1211 protected function info_remote_plugin_not_installable($reason) {
1212
1213 if ($reason === 'notwritableplugintype' or $reason === 'notwritableplugin') {
1214 return $this->output->help_icon('notwritable', 'core_plugin', get_string('notwritable', 'core_plugin'));
1215 }
1216
1217 if ($reason === 'remoteunavailable') {
1218 return $this->output->help_icon('notdownloadable', 'core_plugin', get_string('notdownloadable', 'core_plugin'));
1219 }
1220
1221 return false;
1222 }
1223
36ca62ca
TH
1224 /**
1225 * Formats the information that needs to go in the 'Requires' column.
e87214bd
PS
1226 * @param \core\plugininfo\base $plugin the plugin we are rendering the row for.
1227 * @param core_plugin_manager $pluginman provides data on all the plugins.
8d1da748
PS
1228 * @param string $version
1229 * @return string HTML code
36ca62ca 1230 */
e87214bd 1231 protected function required_column(\core\plugininfo\base $plugin, core_plugin_manager $pluginman, $version) {
7eb87eff 1232
36ca62ca 1233 $requires = array();
5a92cd0b
DM
1234 $displayuploadlink = false;
1235 $displayupdateslink = false;
36ca62ca 1236
7eb87eff
DM
1237 foreach ($pluginman->resolve_requirements($plugin, $version) as $reqname => $reqinfo) {
1238 if ($reqname === 'core') {
1239 if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OK) {
1240 $class = 'requires-ok';
1241 $label = '';
1242 } else {
1243 $class = 'requires-failed';
1244 $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'label label-important');
1245 }
1246 $requires[] = html_writer::tag('li',
1247 html_writer::span(get_string('moodleversion', 'core_plugin', $plugin->versionrequires), 'dep dep-core').
1248 ' '.$label, array('class' => $class));
36ca62ca 1249
7eb87eff
DM
1250 } else {
1251 $actions = array();
1252
1253 if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OK) {
1254 $label = '';
1255 $class = 'requires-ok';
1256
1257 } else if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_MISSING) {
5a92cd0b
DM
1258 if ($reqinfo->availability == $pluginman::REQUIREMENT_AVAILABLE) {
1259 $label = html_writer::span(get_string('dependencymissing', 'core_plugin'), 'label label-warning');
1260 $label .= ' '.html_writer::span(get_string('dependencyavailable', 'core_plugin'), 'label label-warning');
1261 $class = 'requires-failed requires-missing requires-available';
1262 $actions[] = html_writer::link(
1263 new moodle_url('https://moodle.org/plugins/view.php', array('plugin' => $reqname)),
1264 get_string('misdepinfoplugin', 'core_plugin')
1265 );
1266
1267 } else {
1268 $label = html_writer::span(get_string('dependencymissing', 'core_plugin'), 'label label-important');
1269 $label .= ' '.html_writer::span(get_string('dependencyunavailable', 'core_plugin'),
1270 'label label-important');
1271 $class = 'requires-failed requires-missing requires-unavailable';
1272 }
1273 $displayuploadlink = true;
7eb87eff
DM
1274
1275 } else if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OUTDATED) {
5a92cd0b
DM
1276 if ($reqinfo->availability == $pluginman::REQUIREMENT_AVAILABLE) {
1277 $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'label label-warning');
1278 $label .= ' '.html_writer::span(get_string('dependencyavailable', 'core_plugin'), 'label label-warning');
1279 $class = 'requires-failed requires-outdated requires-available';
1280 $displayupdateslink = true;
1281
1282 } else {
1283 $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'label label-important');
1284 $label .= ' '.html_writer::span(get_string('dependencyunavailable', 'core_plugin'),
1285 'label label-important');
1286 $class = 'requires-failed requires-outdated requires-unavailable';
1287 }
1288 $displayuploadlink = true;
2cdea9c7 1289 }
36ca62ca 1290
7eb87eff
DM
1291 if ($reqinfo->reqver != ANY_VERSION) {
1292 $str = 'otherpluginversion';
1293 } else {
1294 $str = 'otherplugin';
1295 }
36ca62ca 1296
7eb87eff
DM
1297 $requires[] = html_writer::tag('li', html_writer::span(
1298 get_string($str, 'core_plugin', array('component' => $reqname, 'version' => $reqinfo->reqver)),
1299 'dep dep-plugin').' '.$label.' '.html_writer::span(implode(' | ', $actions), 'actions'),
1300 array('class' => $class)
1301 );
36ca62ca 1302 }
36ca62ca
TH
1303 }
1304
1305 if (!$requires) {
1306 return '';
1307 }
5a92cd0b
DM
1308
1309 $out = html_writer::tag('ul', implode("\n", $requires));
1310
1311 if ($displayuploadlink) {
1312 $out .= html_writer::div(
1313 html_writer::link(
1314 new moodle_url('/admin/tool/installaddon/'),
1315 get_string('dependencyuploadmissing', 'core_plugin')
1316 ),
1317 'dependencyuploadmissing'
1318 );
1319 }
1320
1321 if ($displayupdateslink) {
1322 $out .= html_writer::div(
1323 html_writer::link(
1324 new moodle_url($this->page->url, array('sesskey' => sesskey(), 'fetchupdates' => 1)),
1325 get_string('checkforupdates', 'core_plugin')
1326 ),
1327 'checkforupdates'
1328 );
1329 }
1330
1331 return $out;
1332
36ca62ca
TH
1333 }
1334
d26f3ddd
DM
1335 /**
1336 * Prints an overview about the plugins - number of installed, number of extensions etc.
1337 *
e87214bd 1338 * @param core_plugin_manager $pluginman provides information about the plugins
4df8bced 1339 * @param array $options filtering options
d26f3ddd
DM
1340 * @return string as usually
1341 */
e87214bd 1342 public function plugins_overview_panel(core_plugin_manager $pluginman, array $options = array()) {
7716057f 1343
d26f3ddd
DM
1344 $plugininfo = $pluginman->get_plugins();
1345
44371554 1346 $numtotal = $numextension = $numupdatable = 0;
d26f3ddd
DM
1347
1348 foreach ($plugininfo as $type => $plugins) {
1349 foreach ($plugins as $name => $plugin) {
44371554
DM
1350 if ($plugin->available_updates()) {
1351 $numupdatable++;
1352 }
e87214bd 1353 if ($plugin->get_status() === core_plugin_manager::PLUGIN_STATUS_MISSING) {
d26f3ddd
DM
1354 continue;
1355 }
1356 $numtotal++;
d26f3ddd
DM
1357 if (!$plugin->is_standard()) {
1358 $numextension++;
1359 }
d26f3ddd
DM
1360 }
1361 }
1362
44371554
DM
1363 $infoall = html_writer::link(
1364 new moodle_url($this->page->url, array('contribonly' => 0, 'updatesonly' => 0)),
1365 get_string('overviewall', 'core_plugin'),
1366 array('title' => get_string('filterall', 'core_plugin'))
1367 ).' '.html_writer::span($numtotal, 'badge number number-all');
1368
1369 $infoext = html_writer::link(
1370 new moodle_url($this->page->url, array('contribonly' => 1, 'updatesonly' => 0)),
1371 get_string('overviewext', 'core_plugin'),
1372 array('title' => get_string('filtercontribonly', 'core_plugin'))
1373 ).' '.html_writer::span($numextension, 'badge number number-additional');
1374
1375 if ($numupdatable) {
1376 $infoupdatable = html_writer::link(
1377 new moodle_url($this->page->url, array('contribonly' => 0, 'updatesonly' => 1)),
1378 get_string('overviewupdatable', 'core_plugin'),
1379 array('title' => get_string('filterupdatesonly', 'core_plugin'))
1380 ).' '.html_writer::span($numupdatable, 'badge badge-info number number-updatable');
1381 } else {
1382 // No updates, or the notifications disabled.
1383 $infoupdatable = '';
4df8bced
DM
1384 }
1385
44371554 1386 $out = html_writer::start_div('', array('id' => 'plugins-overview-panel'));
d26f3ddd 1387
44371554
DM
1388 if (!empty($options['updatesonly'])) {
1389 $out .= $this->output->heading(get_string('overviewupdatable', 'core_plugin'), 3);
1390 } else if (!empty($options['contribonly'])) {
1391 $out .= $this->output->heading(get_string('overviewext', 'core_plugin'), 3);
4df8bced
DM
1392 }
1393
44371554
DM
1394 $out .= html_writer::div($infoall, 'info info-all').
1395 html_writer::div($infoext, 'info info-ext').
1396 html_writer::div($infoupdatable, 'info info-updatable');
1397
1398 $out .= html_writer::end_div(); // #plugins-overview-panel
1399
1400 return $out;
d26f3ddd
DM
1401 }
1402
b9934a17
DM
1403 /**
1404 * Displays all known plugins and links to manage them
1405 *
1406 * This default implementation renders all plugins into one big table.
1407 *
e87214bd 1408 * @param core_plugin_manager $pluginman provides information about the plugins.
4df8bced 1409 * @param array $options filtering options
b9934a17
DM
1410 * @return string HTML code
1411 */
e87214bd 1412 public function plugins_control_panel(core_plugin_manager $pluginman, array $options = array()) {
7716057f 1413
36ca62ca 1414 $plugininfo = $pluginman->get_plugins();
b9934a17 1415
4df8bced
DM
1416 // Filter the list of plugins according the options.
1417 if (!empty($options['updatesonly'])) {
1418 $updateable = array();
1419 foreach ($plugininfo as $plugintype => $pluginnames) {
1420 foreach ($pluginnames as $pluginname => $pluginfo) {
30d8bc5f
DM
1421 $pluginavailableupdates = $pluginfo->available_updates();
1422 if (!empty($pluginavailableupdates)) {
1423 foreach ($pluginavailableupdates as $pluginavailableupdate) {
1424 $updateable[$plugintype][$pluginname] = $pluginfo;
4df8bced
DM
1425 }
1426 }
1427 }
1428 }
1429 $plugininfo = $updateable;
1430 }
1431
1432 if (!empty($options['contribonly'])) {
1433 $contribs = array();
1434 foreach ($plugininfo as $plugintype => $pluginnames) {
1435 foreach ($pluginnames as $pluginname => $pluginfo) {
1436 if (!$pluginfo->is_standard()) {
1437 $contribs[$plugintype][$pluginname] = $pluginfo;
1438 }
1439 }
1440 }
1441 $plugininfo = $contribs;
1442 }
1443
b9934a17
DM
1444 if (empty($plugininfo)) {
1445 return '';
1446 }
1447
b9934a17
DM
1448 $table = new html_table();
1449 $table->id = 'plugins-control-panel';
1450 $table->head = array(
1451 get_string('displayname', 'core_plugin'),
b9934a17
DM
1452 get_string('version', 'core_plugin'),
1453 get_string('availability', 'core_plugin'),
2b135b05
DM
1454 get_string('actions', 'core_plugin'),
1455 get_string('notes','core_plugin'),
b9934a17 1456 );
44371554 1457 $table->headspan = array(1, 1, 1, 2, 1);
b9934a17 1458 $table->colclasses = array(
44371554 1459 'pluginname', 'version', 'availability', 'settings', 'uninstall', 'notes'
b9934a17
DM
1460 );
1461
1462 foreach ($plugininfo as $type => $plugins) {
e87214bd
PS
1463 $heading = $pluginman->plugintype_name_plural($type);
1464 $pluginclass = core_plugin_manager::resolve_plugininfo_class($type);
1465 if ($manageurl = $pluginclass::get_manage_url()) {
44371554
DM
1466 $heading .= $this->output->action_icon($manageurl, new pix_icon('i/settings',
1467 get_string('settings', 'core_plugin')));
e87214bd
PS
1468 }
1469 $header = new html_table_cell(html_writer::tag('span', $heading, array('id'=>'plugin_type_cell_'.$type)));
b9934a17 1470 $header->header = true;
54d75893 1471 $header->colspan = array_sum($table->headspan);
b9934a17
DM
1472 $header = new html_table_row(array($header));
1473 $header->attributes['class'] = 'plugintypeheader type-' . $type;
1474 $table->data[] = $header;
1475
1476 if (empty($plugins)) {
1477 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
54d75893 1478 $msg->colspan = array_sum($table->headspan);
b9934a17
DM
1479 $row = new html_table_row(array($msg));
1480 $row->attributes['class'] .= 'msg msg-noneinstalled';
1481 $table->data[] = $row;
1482 continue;
1483 }
1484
1485 foreach ($plugins as $name => $plugin) {
1486 $row = new html_table_row();
1487 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
1488
1489 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) {
fa9c0aab 1490 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'icon pluginicon'));
b9934a17 1491 } else {
fa9c0aab 1492 $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'icon pluginicon noicon'));
b9934a17 1493 }
9074e478
DM
1494 $status = $plugin->get_status();
1495 $row->attributes['class'] .= ' status-'.$status;
44371554 1496 $pluginname = html_writer::tag('div', $icon.$plugin->displayname, array('class' => 'displayname')).
2b135b05
DM
1497 html_writer::tag('div', $plugin->component, array('class' => 'componentname'));
1498 $pluginname = new html_table_cell($pluginname);
b9934a17 1499
44371554
DM
1500 $version = html_writer::div($plugin->versiondb, 'versionnumber');
1501 if ((string)$plugin->release !== '') {
1502 $version = html_writer::div($plugin->release, 'release').$version;
b9934a17 1503 }
44371554 1504 $version = new html_table_cell($version);
b9934a17
DM
1505
1506 $isenabled = $plugin->is_enabled();
1507 if (is_null($isenabled)) {
1508 $availability = new html_table_cell('');
1509 } else if ($isenabled) {
1510 $row->attributes['class'] .= ' enabled';
7bc759bd 1511 $availability = new html_table_cell(get_string('pluginenabled', 'core_plugin'));
b9934a17
DM
1512 } else {
1513 $row->attributes['class'] .= ' disabled';
7bc759bd 1514 $availability = new html_table_cell(get_string('plugindisabled', 'core_plugin'));
b9934a17
DM
1515 }
1516
1517 $settingsurl = $plugin->get_settings_url();
2b135b05 1518 if (!is_null($settingsurl)) {
54d75893
DM
1519 $settings = html_writer::link($settingsurl, get_string('settings', 'core_plugin'), array('class' => 'settings'));
1520 } else {
1521 $settings = '';
b9934a17 1522 }
54d75893 1523 $settings = new html_table_cell($settings);
b9934a17 1524
e87214bd 1525 if ($uninstallurl = $pluginman->get_uninstall_url($plugin->component, 'overview')) {
54d75893
DM
1526 $uninstall = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin'));
1527 } else {
1528 $uninstall = '';
2b135b05 1529 }
54d75893 1530 $uninstall = new html_table_cell($uninstall);
2b135b05 1531
44371554
DM
1532 if ($plugin->is_standard()) {
1533 $row->attributes['class'] .= ' standard';
1534 //$source = html_writer::div(get_string('sourcestd', 'core_plugin'), 'source label');
1535 $source = '';
1536 } else {
1537 $row->attributes['class'] .= ' extension';
1538 $source = html_writer::div(get_string('sourceext', 'core_plugin'), 'source label label-info');
1539 }
1540
1541 if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) {
1542 $msg = html_writer::div(get_string('status_missing', 'core_plugin'), 'statusmsg label label-important');
1543 } else if ($status === core_plugin_manager::PLUGIN_STATUS_NEW) {
1544 $msg = html_writer::div(get_string('status_new', 'core_plugin'), 'statusmsg label label-success');
1545 } else {
1546 $msg = '';
1547 }
1548
828788f0 1549 $requriedby = $pluginman->other_plugins_that_require($plugin->component);
2b135b05
DM
1550 if ($requriedby) {
1551 $requiredby = html_writer::tag('div', get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
1552 array('class' => 'requiredby'));
b9934a17 1553 } else {
2b135b05 1554 $requiredby = '';
b9934a17
DM
1555 }
1556
7d8de6d8 1557 $updateinfo = '';
e9d3c212 1558 if (is_array($plugin->available_updates())) {
7d8de6d8 1559 foreach ($plugin->available_updates() as $availableupdate) {
3bca7dbf 1560 $updateinfo .= $this->plugin_available_update_info($pluginman, $availableupdate);
7d8de6d8 1561 }
3204daea
DM
1562 }
1563
44371554 1564 $notes = new html_table_cell($source.$msg.$requiredby.$updateinfo);
2b135b05 1565
b9934a17 1566 $row->cells = array(
44371554 1567 $pluginname, $version, $availability, $settings, $uninstall, $notes
b9934a17
DM
1568 );
1569 $table->data[] = $row;
1570 }
1571 }
1572
1573 return html_writer::table($table);
1574 }
da2fdc3f 1575
3204daea 1576 /**
e7611389 1577 * Helper method to render the information about the available plugin update
3204daea 1578 *
3bca7dbf 1579 * @param core_plugin_manager $pluginman plugin manager instance
e87214bd 1580 * @param \core\update\info $updateinfo information about the available update for the plugin
3204daea 1581 */
3bca7dbf 1582 protected function plugin_available_update_info(core_plugin_manager $pluginman, \core\update\info $updateinfo) {
3204daea 1583
e7611389 1584 $boxclasses = 'pluginupdateinfo';
3204daea
DM
1585 $info = array();
1586
1587 if (isset($updateinfo->release)) {
44371554
DM
1588 $info[] = html_writer::div(
1589 get_string('updateavailable_release', 'core_plugin', $updateinfo->release),
1590 'info release'
1591 );
3204daea
DM
1592 }
1593
1594 if (isset($updateinfo->maturity)) {
44371554
DM
1595 $info[] = html_writer::div(
1596 get_string('maturity'.$updateinfo->maturity, 'core_admin'),
1597 'info maturity'
1598 );
e7611389 1599 $boxclasses .= ' maturity'.$updateinfo->maturity;
3204daea
DM
1600 }
1601
1602 if (isset($updateinfo->download)) {
44371554
DM
1603 $info[] = html_writer::div(
1604 html_writer::link($updateinfo->download, get_string('download')),
1605 'info download'
1606 );
3204daea
DM
1607 }
1608
1609 if (isset($updateinfo->url)) {
44371554
DM
1610 $info[] = html_writer::div(
1611 html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin')),
1612 'info more'
1613 );
3204daea
DM
1614 }
1615
44371554
DM
1616 $box = html_writer::start_div($boxclasses);
1617 $box .= html_writer::div(
1618 get_string('updateavailable', 'core_plugin', $updateinfo->version),
1619 'version'
1620 );
1621 $box .= html_writer::div(
1622 implode(html_writer::span(' ', 'separator'), $info),
1623 'infos'
1624 );
fa3feafb 1625
3bca7dbf
DM
1626 if ($pluginman->is_remote_plugin_installable($updateinfo->component, $updateinfo->version, $reason)) {
1627 $box .= $this->output->single_button(
1628 new moodle_url($this->page->url, array('installupdate' => $updateinfo->component,
1629 'installupdateversion' => $updateinfo->version)),
1630 get_string('updateavailableinstall', 'core_admin'),
1631 'post',
1632 array('class' => 'singlebutton updateavailableinstall')
1633 );
1634 } else {
1635 $reasonhelp = $this->info_remote_plugin_not_installable($reason);
1636 if ($reasonhelp) {
1637 $box .= html_writer::div($reasonhelp, 'reasonhelp updateavailableinstall');
0daa6428 1638 }
fa3feafb 1639 }
44371554 1640 $box .= html_writer::end_div();
3204daea
DM
1641
1642 return $box;
1643 }
1644
da2fdc3f 1645 /**
cc359566
TH
1646 * This function will render one beautiful table with all the environmental
1647 * configuration and how it suits Moodle needs.
1648 *
1649 * @param boolean $result final result of the check (true/false)
40cba608 1650 * @param environment_results[] $environment_results array of results gathered
cc359566 1651 * @return string HTML to output.
da2fdc3f 1652 */
cc359566
TH
1653 public function environment_check_table($result, $environment_results) {
1654 global $CFG;
1655
1656 // Table headers
1657 $servertable = new html_table();//table for server checks
1658 $servertable->head = array(
1659 get_string('name'),
1660 get_string('info'),
1661 get_string('report'),
40cba608 1662 get_string('plugin'),
cc359566
TH
1663 get_string('status'),
1664 );
40cba608 1665 $servertable->colclasses = array('centeralign name', 'centeralign info', 'leftalign report', 'leftalign plugin', 'centeralign status');
6fc61f2d
RW
1666 $servertable->attributes['class'] = 'admintable environmenttable generaltable';
1667 $servertable->id = 'serverstatus';
cc359566
TH
1668
1669 $serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
1670
1671 $othertable = new html_table();//table for custom checks
1672 $othertable->head = array(
1673 get_string('info'),
1674 get_string('report'),
40cba608 1675 get_string('plugin'),
cc359566
TH
1676 get_string('status'),
1677 );
40cba608 1678 $othertable->colclasses = array('aligncenter info', 'alignleft report', 'alignleft plugin', 'aligncenter status');
6fc61f2d
RW
1679 $othertable->attributes['class'] = 'admintable environmenttable generaltable';
1680 $othertable->id = 'otherserverstatus';
cc359566
TH
1681
1682 $otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
1683
1684 // Iterate over each environment_result
1685 $continue = true;
1686 foreach ($environment_results as $environment_result) {
1687 $errorline = false;
1688 $warningline = false;
1689 $stringtouse = '';
1690 if ($continue) {
1691 $type = $environment_result->getPart();
1692 $info = $environment_result->getInfo();
1693 $status = $environment_result->getStatus();
40cba608 1694 $plugin = $environment_result->getPluginName();
cc359566
TH
1695 $error_code = $environment_result->getErrorCode();
1696 // Process Report field
1697 $rec = new stdClass();
1698 // Something has gone wrong at parsing time
1699 if ($error_code) {
1700 $stringtouse = 'environmentxmlerror';
1701 $rec->error_code = $error_code;
1702 $status = get_string('error');
1703 $errorline = true;
1704 $continue = false;
1705 }
1706
1707 if ($continue) {
1708 if ($rec->needed = $environment_result->getNeededVersion()) {
1709 // We are comparing versions
1710 $rec->current = $environment_result->getCurrentVersion();
1711 if ($environment_result->getLevel() == 'required') {
1712 $stringtouse = 'environmentrequireversion';
1713 } else {
1714 $stringtouse = 'environmentrecommendversion';
1715 }
1716
1717 } else if ($environment_result->getPart() == 'custom_check') {
1718 // We are checking installed & enabled things
1719 if ($environment_result->getLevel() == 'required') {
1720 $stringtouse = 'environmentrequirecustomcheck';
1721 } else {
1722 $stringtouse = 'environmentrecommendcustomcheck';
1723 }
1724
1725 } else if ($environment_result->getPart() == 'php_setting') {
1726 if ($status) {
1727 $stringtouse = 'environmentsettingok';
1728 } else if ($environment_result->getLevel() == 'required') {
1729 $stringtouse = 'environmentmustfixsetting';
1730 } else {
1731 $stringtouse = 'environmentshouldfixsetting';
1732 }
1733
1734 } else {
1735 if ($environment_result->getLevel() == 'required') {
1736 $stringtouse = 'environmentrequireinstall';
1737 } else {
1738 $stringtouse = 'environmentrecommendinstall';
1739 }
1740 }
1741
1742 // Calculate the status value
1743 if ($environment_result->getBypassStr() != '') { //Handle bypassed result (warning)
1744 $status = get_string('bypassed');
1745 $warningline = true;
1746 } else if ($environment_result->getRestrictStr() != '') { //Handle restricted result (error)
1747 $status = get_string('restricted');
1748 $errorline = true;
1749 } else {
1750 if ($status) { //Handle ok result (ok)
1751 $status = get_string('ok');
1752 } else {
1753 if ($environment_result->getLevel() == 'optional') {//Handle check result (warning)
1754 $status = get_string('check');
1755 $warningline = true;
1756 } else { //Handle error result (error)
1757 $status = get_string('check');
1758 $errorline = true;
1759 }
1760 }
1761 }
1762 }
1763
1764 // Build the text
1765 $linkparts = array();
1766 $linkparts[] = 'admin/environment';
1767 $linkparts[] = $type;
1768 if (!empty($info)){
1769 $linkparts[] = $info;
1770 }
40cba608
PS
1771 // Plugin environments do not have docs pages yet.
1772 if (empty($CFG->docroot) or $environment_result->plugin) {
cc359566
TH
1773 $report = get_string($stringtouse, 'admin', $rec);
1774 } else {
1775 $report = $this->doc_link(join($linkparts, '/'), get_string($stringtouse, 'admin', $rec));
1776 }
1777
1778 // Format error or warning line
1779 if ($errorline || $warningline) {
1780 $messagetype = $errorline? 'error':'warn';
1781 } else {
1782 $messagetype = 'ok';
1783 }
1784 $status = '<span class="'.$messagetype.'">'.$status.'</span>';
1785 // Here we'll store all the feedback found
1786 $feedbacktext = '';
1787 // Append the feedback if there is some
1788 $feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), $messagetype);
1789 //Append the bypass if there is some
1790 $feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'warn');
1791 //Append the restrict if there is some
1792 $feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'error');
1793
1794 $report .= $feedbacktext;
1795
1796 // Add the row to the table
1797 if ($environment_result->getPart() == 'custom_check'){
40cba608 1798 $otherdata[$messagetype][] = array ($info, $report, $plugin, $status);
cc359566 1799 } else {
40cba608 1800 $serverdata[$messagetype][] = array ($type, $info, $report, $plugin, $status);
cc359566
TH
1801 }
1802 }
1803 }
1804
1805 //put errors first in
1806 $servertable->data = array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']);
1807 $othertable->data = array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']);
1808
1809 // Print table
1810 $output = '';
1811 $output .= $this->heading(get_string('serverchecks', 'admin'));
1812 $output .= html_writer::table($servertable);
1813 if (count($othertable->data)){
1814 $output .= $this->heading(get_string('customcheck', 'admin'));
1815 $output .= html_writer::table($othertable);
1816 }
1817
1818 // Finally, if any error has happened, print the summary box
1819 if (!$result) {
1820 $output .= $this->box(get_string('environmenterrortodo', 'admin'), 'environmentbox errorbox');
1821 }
1822
1823 return $output;
da2fdc3f 1824 }
98b32c9e
DM
1825
1826 /**
1827 * Render a simple page for providing the upgrade key.
1828 *
1829 * @param moodle_url|string $url
1830 * @return string
1831 */
1832 public function upgradekey_form_page($url) {
1833
1834 $output = '';
1835 $output .= $this->header();
1836 $output .= $this->container_start('upgradekeyreq');
1837 $output .= $this->heading(get_string('upgradekeyreq', 'core_admin'));
1838 $output .= html_writer::start_tag('form', array('method' => 'POST', 'action' => $url));
1839 $output .= html_writer::empty_tag('input', array('name' => 'upgradekey', 'type' => 'password'));
1840 $output .= html_writer::empty_tag('input', array('value' => get_string('submit'), 'type' => 'submit'));
1841 $output .= html_writer::end_tag('form');
1842 $output .= $this->container_end();
1843 $output .= $this->footer();
1844
1845 return $output;
1846 }
b9934a17 1847}