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