MDL-49329 admin: Add plugin manager method for installing remote packs
[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
c948b813
DM
1002 $installableupdates = $pluginman->filter_installable($pluginman->available_updates());
1003 if ($installableupdates) {
1004 $out .= $this->output->single_button(
1005 new moodle_url($this->page->url, array('installupdatex' => 1)),
1006 get_string('updateavailableinstallall', 'core_admin', count($installableupdates)),
1007 'post',
1008 array('class' => 'singlebutton updateavailableinstallall')
1009 );
1010 }
1011
228cbda3
DM
1012 $out .= html_writer::div(html_writer::link(new moodle_url($this->page->url, array('showallplugins' => 0)),
1013 get_string('plugincheckattention', 'core_plugin')).' '.html_writer::span($sumattention, 'badge'));
2f29cf6e 1014
228cbda3
DM
1015 $out .= html_writer::div(html_writer::link(new moodle_url($this->page->url, array('showallplugins' => 1)),
1016 get_string('plugincheckall', 'core_plugin')).' '.html_writer::span($sumtotal, 'badge'));
b9934a17 1017
228cbda3 1018 $out .= $this->output->container_end(); // .actions
0ec7d101
DM
1019 $out .= $this->output->container_end(); // #plugins-check-info
1020
1021 if ($sumdisplayed > 0 or $options['full']) {
b9934a17
DM
1022 $out .= html_writer::table($table);
1023 }
1024
1025 return $out;
1026 }
1027
c948b813
DM
1028 /**
1029 * Display the continue / cancel widgets for the plugins validation page.
1030 *
1031 * @param null|moodle_url $continue URL for the continue button, should it be displayed
1032 * @param string $label explicit label for the continue button
1033 * @param moodle_url $cancel URL for the cancel link, defaults to the current page
1034 * @return string HTML
1035 */
1036 public function install_remote_plugins_buttons(moodle_url $continue=null, $label=null, moodle_url $cancel=null) {
1037
1038 $out = html_writer::start_div('install-remote-plugins-buttons');
1039
1040 if (!empty($continue)) {
1041 if (empty($label)) {
1042 $label = get_string('continue');
1043 }
1044 $out .= $this->output->single_button($continue, $label, 'post', array('class' => 'continue'));
1045 }
1046
1047 if (empty($cancel)) {
1048 $cancel = $this->page->url;
1049 }
1050 $out .= html_writer::div(html_writer::link($cancel, get_string('cancel')), 'cancel');
1051
1052 return $out;
1053 }
1054
5a92cd0b
DM
1055 /**
1056 * Displays the information about missing dependencies
1057 *
1058 * @param core_plugin_manager $pluginman
1059 * @return string
1060 */
1061 protected function missing_dependencies(core_plugin_manager $pluginman) {
1062
1063 $dependencies = $pluginman->missing_dependencies();
1064
1065 if (empty($dependencies)) {
1066 return '';
1067 }
1068
1069 $available = array();
1070 $unavailable = array();
1071 $unknown = array();
1072
1073 foreach ($dependencies as $component => $remoteinfo) {
1074 if ($remoteinfo === false) {
35f2b674 1075 // The required version is not available. Let us check if there
5a92cd0b 1076 // is at least some version in the plugins directory.
35f2b674 1077 $remoteinfoanyversion = $pluginman->get_remote_plugin_info($component, ANY_VERSION, false);
5a92cd0b
DM
1078 if ($remoteinfoanyversion === false) {
1079 $unknown[$component] = $component;
1080 } else {
1081 $unavailable[$component] = $remoteinfoanyversion;
1082 }
1083 } else {
1084 $available[$component] = $remoteinfo;
1085 }
1086 }
1087
1088 $out = $this->output->container_start('plugins-check-dependencies');
1089
1090 if ($unavailable or $unknown) {
1091 $out .= $this->output->heading(get_string('misdepsunavail', 'core_plugin'));
1092 if ($unknown) {
1093 $out .= $this->output->notification(get_string('misdepsunknownlist', 'core_plugin', implode($unknown, ', ')));
1094 }
1095 if ($unavailable) {
1096 $unavailablelist = array();
1097 foreach ($unavailable as $component => $remoteinfoanyversion) {
1098 $unavailablelistitem = html_writer::link('https://moodle.org/plugins/view.php?plugin='.$component,
1099 '<strong>'.$remoteinfoanyversion->name.'</strong>');
1100 if ($remoteinfoanyversion->version) {
1101 $unavailablelistitem .= ' ('.$component.' &gt; '.$remoteinfoanyversion->version->version.')';
1102 } else {
1103 $unavailablelistitem .= ' ('.$component.')';
1104 }
1105 $unavailablelist[] = $unavailablelistitem;
1106 }
1107 $out .= $this->output->notification(get_string('misdepsunavaillist', 'core_plugin',
1108 implode($unavailablelist, ', ')));
1109 }
1110 $out .= $this->output->container_start('plugins-check-dependencies-actions');
1111 $out .= ' '.html_writer::link(new moodle_url('/admin/tool/installaddon/'),
1112 get_string('dependencyuploadmissing', 'core_plugin'));
1113 $out .= $this->output->container_end(); // .plugins-check-dependencies-actions
1114 }
1115
1116 if ($available) {
1117 $out .= $this->output->heading(get_string('misdepsavail', 'core_plugin'));
5a92cd0b
DM
1118 $out .= $this->output->container_start('plugins-check-dependencies-actions');
1119
c948b813 1120 $installable = $pluginman->filter_installable($available);
9137a89a
DM
1121 if ($installable) {
1122 $out .= $this->output->single_button(
1123 new moodle_url($this->page->url, array('installdepx' => 1)),
1124 get_string('dependencyinstallmissing', 'core_plugin', count($installable)),
1125 'post',
1126 array('class' => 'singlebutton dependencyinstallmissing')
1127 );
1128 }
1129
1130 $out.= html_writer::div(html_writer::link(new moodle_url('/admin/tool/installaddon/'),
1131 get_string('dependencyuploadmissing', 'core_plugin')), 'dependencyuploadmissing');
1132
5a92cd0b 1133 $out .= $this->output->container_end(); // .plugins-check-dependencies-actions
9137a89a
DM
1134
1135 $out .= $this->available_missing_dependencies_list($pluginman, $available);
5a92cd0b
DM
1136 }
1137
1138 $out .= $this->output->container_end(); // .plugins-check-dependencies
1139
1140 return $out;
1141 }
1142
1143 /**
1144 * Displays the list if available missing dependencies.
1145 *
1146 * @param core_plugin_manager $pluginman
1147 * @param array $dependencies
1148 * @return string
1149 */
1150 protected function available_missing_dependencies_list(core_plugin_manager $pluginman, array $dependencies) {
1151 global $CFG;
1152
1153 $table = new html_table();
1154 $table->id = 'plugins-check-available-dependencies';
1155 $table->head = array(
1156 get_string('displayname', 'core_plugin'),
1157 get_string('release', 'core_plugin'),
1158 get_string('version', 'core_plugin'),
1159 get_string('supportedmoodleversions', 'core_plugin'),
1160 get_string('info', 'core'),
1161 );
1162 $table->colclasses = array('displayname', 'release', 'version', 'supportedmoodleversions', 'info');
1163 $table->data = array();
1164
1165 foreach ($dependencies as $plugin) {
1166
1167 $supportedmoodles = array();
1168 foreach ($plugin->version->supportedmoodles as $moodle) {
1169 if ($CFG->branch == str_replace('.', '', $moodle->release)) {
1170 $supportedmoodles[] = html_writer::span($moodle->release, 'label label-success');
1171 } else {
1172 $supportedmoodles[] = html_writer::span($moodle->release, 'label');
1173 }
1174 }
1175
1176 $requriedby = $pluginman->other_plugins_that_require($plugin->component);
1177 if ($requriedby) {
1178 foreach ($requriedby as $ix => $val) {
1179 $inf = $pluginman->get_plugin_info($val);
1180 if ($inf) {
1181 $requriedby[$ix] = $inf->displayname.' ('.$inf->component.')';
1182 }
1183 }
1184 $info = html_writer::div(
1185 get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
1186 'requiredby'
1187 );
1188 } else {
1189 $info = '';
1190 }
1191
9137a89a
DM
1192 $info .= $this->output->container_start('actions');
1193
1194 $info .= html_writer::div(
5a92cd0b
DM
1195 html_writer::link('https://moodle.org/plugins/view.php?plugin='.$plugin->component,
1196 get_string('misdepinfoplugin', 'core_plugin')),
1197 'misdepinfoplugin'
1198 );
1199
9137a89a 1200 $info .= html_writer::div(
5a92cd0b
DM
1201 html_writer::link('https://moodle.org/plugins/pluginversion.php?id='.$plugin->version->id,
1202 get_string('misdepinfoversion', 'core_plugin')),
1203 'misdepinfoversion'
1204 );
1205
9137a89a
DM
1206 $info .= html_writer::div(html_writer::link($plugin->version->downloadurl, get_string('download')), 'misdepdownload');
1207
36977a6d 1208 if ($pluginman->is_remote_plugin_installable($plugin->component, $plugin->version->version, $reason)) {
9137a89a
DM
1209 $info .= $this->output->single_button(
1210 new moodle_url($this->page->url, array('installdep' => $plugin->component)),
1211 get_string('dependencyinstall', 'core_plugin'),
1212 'post',
1213 array('class' => 'singlebutton dependencyinstall')
1214 );
36977a6d
DM
1215 } else {
1216 $reasonhelp = $this->info_remote_plugin_not_installable($reason);
1217 if ($reasonhelp) {
1218 $info .= html_writer::div($reasonhelp, 'reasonhelp dependencyinstall');
1219 }
9137a89a 1220 }
5a92cd0b 1221
9137a89a 1222 $info .= $this->output->container_end(); // .actions
5a92cd0b
DM
1223
1224 $table->data[] = array(
1225 html_writer::div($plugin->name, 'name').' '.html_writer::div($plugin->component, 'component'),
1226 $plugin->version->release,
1227 $plugin->version->version,
1228 implode($supportedmoodles, ' '),
1229 $info
1230 );
1231 }
1232
1233 return html_writer::table($table);
1234 }
1235
36977a6d
DM
1236 /**
1237 * Explain why {@link core_plugin_manager::is_remote_plugin_installable()} returned false.
1238 *
1239 * @param string $reason the reason code as returned by the plugin manager
1240 * @return string
1241 */
1242 protected function info_remote_plugin_not_installable($reason) {
1243
1244 if ($reason === 'notwritableplugintype' or $reason === 'notwritableplugin') {
1245 return $this->output->help_icon('notwritable', 'core_plugin', get_string('notwritable', 'core_plugin'));
1246 }
1247
1248 if ($reason === 'remoteunavailable') {
1249 return $this->output->help_icon('notdownloadable', 'core_plugin', get_string('notdownloadable', 'core_plugin'));
1250 }
1251
1252 return false;
1253 }
1254
36ca62ca
TH
1255 /**
1256 * Formats the information that needs to go in the 'Requires' column.
e87214bd
PS
1257 * @param \core\plugininfo\base $plugin the plugin we are rendering the row for.
1258 * @param core_plugin_manager $pluginman provides data on all the plugins.
8d1da748
PS
1259 * @param string $version
1260 * @return string HTML code
36ca62ca 1261 */
e87214bd 1262 protected function required_column(\core\plugininfo\base $plugin, core_plugin_manager $pluginman, $version) {
7eb87eff 1263
36ca62ca 1264 $requires = array();
5a92cd0b
DM
1265 $displayuploadlink = false;
1266 $displayupdateslink = false;
36ca62ca 1267
7eb87eff
DM
1268 foreach ($pluginman->resolve_requirements($plugin, $version) as $reqname => $reqinfo) {
1269 if ($reqname === 'core') {
1270 if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OK) {
1271 $class = 'requires-ok';
1272 $label = '';
1273 } else {
1274 $class = 'requires-failed';
1275 $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'label label-important');
1276 }
1277 $requires[] = html_writer::tag('li',
1278 html_writer::span(get_string('moodleversion', 'core_plugin', $plugin->versionrequires), 'dep dep-core').
1279 ' '.$label, array('class' => $class));
36ca62ca 1280
7eb87eff
DM
1281 } else {
1282 $actions = array();
1283
1284 if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OK) {
1285 $label = '';
1286 $class = 'requires-ok';
1287
1288 } else if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_MISSING) {
5a92cd0b
DM
1289 if ($reqinfo->availability == $pluginman::REQUIREMENT_AVAILABLE) {
1290 $label = html_writer::span(get_string('dependencymissing', 'core_plugin'), 'label label-warning');
1291 $label .= ' '.html_writer::span(get_string('dependencyavailable', 'core_plugin'), 'label label-warning');
1292 $class = 'requires-failed requires-missing requires-available';
1293 $actions[] = html_writer::link(
1294 new moodle_url('https://moodle.org/plugins/view.php', array('plugin' => $reqname)),
1295 get_string('misdepinfoplugin', 'core_plugin')
1296 );
1297
1298 } else {
1299 $label = html_writer::span(get_string('dependencymissing', 'core_plugin'), 'label label-important');
1300 $label .= ' '.html_writer::span(get_string('dependencyunavailable', 'core_plugin'),
1301 'label label-important');
1302 $class = 'requires-failed requires-missing requires-unavailable';
1303 }
1304 $displayuploadlink = true;
7eb87eff
DM
1305
1306 } else if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OUTDATED) {
5a92cd0b
DM
1307 if ($reqinfo->availability == $pluginman::REQUIREMENT_AVAILABLE) {
1308 $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'label label-warning');
1309 $label .= ' '.html_writer::span(get_string('dependencyavailable', 'core_plugin'), 'label label-warning');
1310 $class = 'requires-failed requires-outdated requires-available';
1311 $displayupdateslink = true;
1312
1313 } else {
1314 $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'label label-important');
1315 $label .= ' '.html_writer::span(get_string('dependencyunavailable', 'core_plugin'),
1316 'label label-important');
1317 $class = 'requires-failed requires-outdated requires-unavailable';
1318 }
1319 $displayuploadlink = true;
2cdea9c7 1320 }
36ca62ca 1321
7eb87eff
DM
1322 if ($reqinfo->reqver != ANY_VERSION) {
1323 $str = 'otherpluginversion';
1324 } else {
1325 $str = 'otherplugin';
1326 }
36ca62ca 1327
7eb87eff
DM
1328 $requires[] = html_writer::tag('li', html_writer::span(
1329 get_string($str, 'core_plugin', array('component' => $reqname, 'version' => $reqinfo->reqver)),
1330 'dep dep-plugin').' '.$label.' '.html_writer::span(implode(' | ', $actions), 'actions'),
1331 array('class' => $class)
1332 );
36ca62ca 1333 }
36ca62ca
TH
1334 }
1335
1336 if (!$requires) {
1337 return '';
1338 }
5a92cd0b
DM
1339
1340 $out = html_writer::tag('ul', implode("\n", $requires));
1341
1342 if ($displayuploadlink) {
1343 $out .= html_writer::div(
1344 html_writer::link(
1345 new moodle_url('/admin/tool/installaddon/'),
1346 get_string('dependencyuploadmissing', 'core_plugin')
1347 ),
1348 'dependencyuploadmissing'
1349 );
1350 }
1351
1352 if ($displayupdateslink) {
1353 $out .= html_writer::div(
1354 html_writer::link(
1355 new moodle_url($this->page->url, array('sesskey' => sesskey(), 'fetchupdates' => 1)),
1356 get_string('checkforupdates', 'core_plugin')
1357 ),
1358 'checkforupdates'
1359 );
1360 }
1361
1362 return $out;
1363
36ca62ca
TH
1364 }
1365
d26f3ddd
DM
1366 /**
1367 * Prints an overview about the plugins - number of installed, number of extensions etc.
1368 *
e87214bd 1369 * @param core_plugin_manager $pluginman provides information about the plugins
4df8bced 1370 * @param array $options filtering options
d26f3ddd
DM
1371 * @return string as usually
1372 */
e87214bd 1373 public function plugins_overview_panel(core_plugin_manager $pluginman, array $options = array()) {
7716057f 1374
d26f3ddd
DM
1375 $plugininfo = $pluginman->get_plugins();
1376
44371554 1377 $numtotal = $numextension = $numupdatable = 0;
d26f3ddd
DM
1378
1379 foreach ($plugininfo as $type => $plugins) {
1380 foreach ($plugins as $name => $plugin) {
44371554
DM
1381 if ($plugin->available_updates()) {
1382 $numupdatable++;
1383 }
e87214bd 1384 if ($plugin->get_status() === core_plugin_manager::PLUGIN_STATUS_MISSING) {
d26f3ddd
DM
1385 continue;
1386 }
1387 $numtotal++;
d26f3ddd
DM
1388 if (!$plugin->is_standard()) {
1389 $numextension++;
1390 }
d26f3ddd
DM
1391 }
1392 }
1393
44371554
DM
1394 $infoall = html_writer::link(
1395 new moodle_url($this->page->url, array('contribonly' => 0, 'updatesonly' => 0)),
1396 get_string('overviewall', 'core_plugin'),
1397 array('title' => get_string('filterall', 'core_plugin'))
1398 ).' '.html_writer::span($numtotal, 'badge number number-all');
1399
1400 $infoext = html_writer::link(
1401 new moodle_url($this->page->url, array('contribonly' => 1, 'updatesonly' => 0)),
1402 get_string('overviewext', 'core_plugin'),
1403 array('title' => get_string('filtercontribonly', 'core_plugin'))
1404 ).' '.html_writer::span($numextension, 'badge number number-additional');
1405
1406 if ($numupdatable) {
1407 $infoupdatable = html_writer::link(
1408 new moodle_url($this->page->url, array('contribonly' => 0, 'updatesonly' => 1)),
1409 get_string('overviewupdatable', 'core_plugin'),
1410 array('title' => get_string('filterupdatesonly', 'core_plugin'))
1411 ).' '.html_writer::span($numupdatable, 'badge badge-info number number-updatable');
1412 } else {
1413 // No updates, or the notifications disabled.
1414 $infoupdatable = '';
4df8bced
DM
1415 }
1416
44371554 1417 $out = html_writer::start_div('', array('id' => 'plugins-overview-panel'));
d26f3ddd 1418
44371554
DM
1419 if (!empty($options['updatesonly'])) {
1420 $out .= $this->output->heading(get_string('overviewupdatable', 'core_plugin'), 3);
1421 } else if (!empty($options['contribonly'])) {
1422 $out .= $this->output->heading(get_string('overviewext', 'core_plugin'), 3);
4df8bced
DM
1423 }
1424
44371554
DM
1425 $out .= html_writer::div($infoall, 'info info-all').
1426 html_writer::div($infoext, 'info info-ext').
1427 html_writer::div($infoupdatable, 'info info-updatable');
1428
1429 $out .= html_writer::end_div(); // #plugins-overview-panel
1430
1431 return $out;
d26f3ddd
DM
1432 }
1433
b9934a17
DM
1434 /**
1435 * Displays all known plugins and links to manage them
1436 *
1437 * This default implementation renders all plugins into one big table.
1438 *
e87214bd 1439 * @param core_plugin_manager $pluginman provides information about the plugins.
4df8bced 1440 * @param array $options filtering options
b9934a17
DM
1441 * @return string HTML code
1442 */
e87214bd 1443 public function plugins_control_panel(core_plugin_manager $pluginman, array $options = array()) {
7716057f 1444
36ca62ca 1445 $plugininfo = $pluginman->get_plugins();
b9934a17 1446
4df8bced
DM
1447 // Filter the list of plugins according the options.
1448 if (!empty($options['updatesonly'])) {
1449 $updateable = array();
1450 foreach ($plugininfo as $plugintype => $pluginnames) {
1451 foreach ($pluginnames as $pluginname => $pluginfo) {
30d8bc5f
DM
1452 $pluginavailableupdates = $pluginfo->available_updates();
1453 if (!empty($pluginavailableupdates)) {
1454 foreach ($pluginavailableupdates as $pluginavailableupdate) {
1455 $updateable[$plugintype][$pluginname] = $pluginfo;
4df8bced
DM
1456 }
1457 }
1458 }
1459 }
1460 $plugininfo = $updateable;
1461 }
1462
1463 if (!empty($options['contribonly'])) {
1464 $contribs = array();
1465 foreach ($plugininfo as $plugintype => $pluginnames) {
1466 foreach ($pluginnames as $pluginname => $pluginfo) {
1467 if (!$pluginfo->is_standard()) {
1468 $contribs[$plugintype][$pluginname] = $pluginfo;
1469 }
1470 }
1471 }
1472 $plugininfo = $contribs;
1473 }
1474
b9934a17
DM
1475 if (empty($plugininfo)) {
1476 return '';
1477 }
1478
b9934a17
DM
1479 $table = new html_table();
1480 $table->id = 'plugins-control-panel';
1481 $table->head = array(
1482 get_string('displayname', 'core_plugin'),
b9934a17
DM
1483 get_string('version', 'core_plugin'),
1484 get_string('availability', 'core_plugin'),
2b135b05
DM
1485 get_string('actions', 'core_plugin'),
1486 get_string('notes','core_plugin'),
b9934a17 1487 );
44371554 1488 $table->headspan = array(1, 1, 1, 2, 1);
b9934a17 1489 $table->colclasses = array(
44371554 1490 'pluginname', 'version', 'availability', 'settings', 'uninstall', 'notes'
b9934a17
DM
1491 );
1492
1493 foreach ($plugininfo as $type => $plugins) {
e87214bd
PS
1494 $heading = $pluginman->plugintype_name_plural($type);
1495 $pluginclass = core_plugin_manager::resolve_plugininfo_class($type);
1496 if ($manageurl = $pluginclass::get_manage_url()) {
44371554
DM
1497 $heading .= $this->output->action_icon($manageurl, new pix_icon('i/settings',
1498 get_string('settings', 'core_plugin')));
e87214bd
PS
1499 }
1500 $header = new html_table_cell(html_writer::tag('span', $heading, array('id'=>'plugin_type_cell_'.$type)));
b9934a17 1501 $header->header = true;
54d75893 1502 $header->colspan = array_sum($table->headspan);
b9934a17
DM
1503 $header = new html_table_row(array($header));
1504 $header->attributes['class'] = 'plugintypeheader type-' . $type;
1505 $table->data[] = $header;
1506
1507 if (empty($plugins)) {
1508 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
54d75893 1509 $msg->colspan = array_sum($table->headspan);
b9934a17
DM
1510 $row = new html_table_row(array($msg));
1511 $row->attributes['class'] .= 'msg msg-noneinstalled';
1512 $table->data[] = $row;
1513 continue;
1514 }
1515
1516 foreach ($plugins as $name => $plugin) {
1517 $row = new html_table_row();
1518 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
1519
1520 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) {
fa9c0aab 1521 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'icon pluginicon'));
b9934a17 1522 } else {
fa9c0aab 1523 $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'icon pluginicon noicon'));
b9934a17 1524 }
9074e478
DM
1525 $status = $plugin->get_status();
1526 $row->attributes['class'] .= ' status-'.$status;
44371554 1527 $pluginname = html_writer::tag('div', $icon.$plugin->displayname, array('class' => 'displayname')).
2b135b05
DM
1528 html_writer::tag('div', $plugin->component, array('class' => 'componentname'));
1529 $pluginname = new html_table_cell($pluginname);
b9934a17 1530
44371554
DM
1531 $version = html_writer::div($plugin->versiondb, 'versionnumber');
1532 if ((string)$plugin->release !== '') {
1533 $version = html_writer::div($plugin->release, 'release').$version;
b9934a17 1534 }
44371554 1535 $version = new html_table_cell($version);
b9934a17
DM
1536
1537 $isenabled = $plugin->is_enabled();
1538 if (is_null($isenabled)) {
1539 $availability = new html_table_cell('');
1540 } else if ($isenabled) {
1541 $row->attributes['class'] .= ' enabled';
7bc759bd 1542 $availability = new html_table_cell(get_string('pluginenabled', 'core_plugin'));
b9934a17
DM
1543 } else {
1544 $row->attributes['class'] .= ' disabled';
7bc759bd 1545 $availability = new html_table_cell(get_string('plugindisabled', 'core_plugin'));
b9934a17
DM
1546 }
1547
1548 $settingsurl = $plugin->get_settings_url();
2b135b05 1549 if (!is_null($settingsurl)) {
54d75893
DM
1550 $settings = html_writer::link($settingsurl, get_string('settings', 'core_plugin'), array('class' => 'settings'));
1551 } else {
1552 $settings = '';
b9934a17 1553 }
54d75893 1554 $settings = new html_table_cell($settings);
b9934a17 1555
e87214bd 1556 if ($uninstallurl = $pluginman->get_uninstall_url($plugin->component, 'overview')) {
54d75893
DM
1557 $uninstall = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin'));
1558 } else {
1559 $uninstall = '';
2b135b05 1560 }
54d75893 1561 $uninstall = new html_table_cell($uninstall);
2b135b05 1562
44371554
DM
1563 if ($plugin->is_standard()) {
1564 $row->attributes['class'] .= ' standard';
1565 //$source = html_writer::div(get_string('sourcestd', 'core_plugin'), 'source label');
1566 $source = '';
1567 } else {
1568 $row->attributes['class'] .= ' extension';
1569 $source = html_writer::div(get_string('sourceext', 'core_plugin'), 'source label label-info');
1570 }
1571
1572 if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) {
1573 $msg = html_writer::div(get_string('status_missing', 'core_plugin'), 'statusmsg label label-important');
1574 } else if ($status === core_plugin_manager::PLUGIN_STATUS_NEW) {
1575 $msg = html_writer::div(get_string('status_new', 'core_plugin'), 'statusmsg label label-success');
1576 } else {
1577 $msg = '';
1578 }
1579
828788f0 1580 $requriedby = $pluginman->other_plugins_that_require($plugin->component);
2b135b05
DM
1581 if ($requriedby) {
1582 $requiredby = html_writer::tag('div', get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
1583 array('class' => 'requiredby'));
b9934a17 1584 } else {
2b135b05 1585 $requiredby = '';
b9934a17
DM
1586 }
1587
7d8de6d8 1588 $updateinfo = '';
e9d3c212 1589 if (is_array($plugin->available_updates())) {
7d8de6d8 1590 foreach ($plugin->available_updates() as $availableupdate) {
3bca7dbf 1591 $updateinfo .= $this->plugin_available_update_info($pluginman, $availableupdate);
7d8de6d8 1592 }
3204daea
DM
1593 }
1594
44371554 1595 $notes = new html_table_cell($source.$msg.$requiredby.$updateinfo);
2b135b05 1596
b9934a17 1597 $row->cells = array(
44371554 1598 $pluginname, $version, $availability, $settings, $uninstall, $notes
b9934a17
DM
1599 );
1600 $table->data[] = $row;
1601 }
1602 }
1603
1604 return html_writer::table($table);
1605 }
da2fdc3f 1606
3204daea 1607 /**
e7611389 1608 * Helper method to render the information about the available plugin update
3204daea 1609 *
3bca7dbf 1610 * @param core_plugin_manager $pluginman plugin manager instance
e87214bd 1611 * @param \core\update\info $updateinfo information about the available update for the plugin
3204daea 1612 */
3bca7dbf 1613 protected function plugin_available_update_info(core_plugin_manager $pluginman, \core\update\info $updateinfo) {
3204daea 1614
e7611389 1615 $boxclasses = 'pluginupdateinfo';
3204daea
DM
1616 $info = array();
1617
1618 if (isset($updateinfo->release)) {
44371554
DM
1619 $info[] = html_writer::div(
1620 get_string('updateavailable_release', 'core_plugin', $updateinfo->release),
1621 'info release'
1622 );
3204daea
DM
1623 }
1624
1625 if (isset($updateinfo->maturity)) {
44371554
DM
1626 $info[] = html_writer::div(
1627 get_string('maturity'.$updateinfo->maturity, 'core_admin'),
1628 'info maturity'
1629 );
e7611389 1630 $boxclasses .= ' maturity'.$updateinfo->maturity;
3204daea
DM
1631 }
1632
1633 if (isset($updateinfo->download)) {
44371554
DM
1634 $info[] = html_writer::div(
1635 html_writer::link($updateinfo->download, get_string('download')),
1636 'info download'
1637 );
3204daea
DM
1638 }
1639
1640 if (isset($updateinfo->url)) {
44371554
DM
1641 $info[] = html_writer::div(
1642 html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin')),
1643 'info more'
1644 );
3204daea
DM
1645 }
1646
44371554
DM
1647 $box = html_writer::start_div($boxclasses);
1648 $box .= html_writer::div(
1649 get_string('updateavailable', 'core_plugin', $updateinfo->version),
1650 'version'
1651 );
1652 $box .= html_writer::div(
1653 implode(html_writer::span(' ', 'separator'), $info),
1654 'infos'
1655 );
fa3feafb 1656
3bca7dbf
DM
1657 if ($pluginman->is_remote_plugin_installable($updateinfo->component, $updateinfo->version, $reason)) {
1658 $box .= $this->output->single_button(
1659 new moodle_url($this->page->url, array('installupdate' => $updateinfo->component,
1660 'installupdateversion' => $updateinfo->version)),
1661 get_string('updateavailableinstall', 'core_admin'),
1662 'post',
1663 array('class' => 'singlebutton updateavailableinstall')
1664 );
1665 } else {
1666 $reasonhelp = $this->info_remote_plugin_not_installable($reason);
1667 if ($reasonhelp) {
1668 $box .= html_writer::div($reasonhelp, 'reasonhelp updateavailableinstall');
0daa6428 1669 }
fa3feafb 1670 }
44371554 1671 $box .= html_writer::end_div();
3204daea
DM
1672
1673 return $box;
1674 }
1675
da2fdc3f 1676 /**
cc359566
TH
1677 * This function will render one beautiful table with all the environmental
1678 * configuration and how it suits Moodle needs.
1679 *
1680 * @param boolean $result final result of the check (true/false)
40cba608 1681 * @param environment_results[] $environment_results array of results gathered
cc359566 1682 * @return string HTML to output.
da2fdc3f 1683 */
cc359566
TH
1684 public function environment_check_table($result, $environment_results) {
1685 global $CFG;
1686
1687 // Table headers
1688 $servertable = new html_table();//table for server checks
1689 $servertable->head = array(
1690 get_string('name'),
1691 get_string('info'),
1692 get_string('report'),
40cba608 1693 get_string('plugin'),
cc359566
TH
1694 get_string('status'),
1695 );
40cba608 1696 $servertable->colclasses = array('centeralign name', 'centeralign info', 'leftalign report', 'leftalign plugin', 'centeralign status');
6fc61f2d
RW
1697 $servertable->attributes['class'] = 'admintable environmenttable generaltable';
1698 $servertable->id = 'serverstatus';
cc359566
TH
1699
1700 $serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
1701
1702 $othertable = new html_table();//table for custom checks
1703 $othertable->head = array(
1704 get_string('info'),
1705 get_string('report'),
40cba608 1706 get_string('plugin'),
cc359566
TH
1707 get_string('status'),
1708 );
40cba608 1709 $othertable->colclasses = array('aligncenter info', 'alignleft report', 'alignleft plugin', 'aligncenter status');
6fc61f2d
RW
1710 $othertable->attributes['class'] = 'admintable environmenttable generaltable';
1711 $othertable->id = 'otherserverstatus';
cc359566
TH
1712
1713 $otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
1714
1715 // Iterate over each environment_result
1716 $continue = true;
1717 foreach ($environment_results as $environment_result) {
1718 $errorline = false;
1719 $warningline = false;
1720 $stringtouse = '';
1721 if ($continue) {
1722 $type = $environment_result->getPart();
1723 $info = $environment_result->getInfo();
1724 $status = $environment_result->getStatus();
40cba608 1725 $plugin = $environment_result->getPluginName();
cc359566
TH
1726 $error_code = $environment_result->getErrorCode();
1727 // Process Report field
1728 $rec = new stdClass();
1729 // Something has gone wrong at parsing time
1730 if ($error_code) {
1731 $stringtouse = 'environmentxmlerror';
1732 $rec->error_code = $error_code;
1733 $status = get_string('error');
1734 $errorline = true;
1735 $continue = false;
1736 }
1737
1738 if ($continue) {
1739 if ($rec->needed = $environment_result->getNeededVersion()) {
1740 // We are comparing versions
1741 $rec->current = $environment_result->getCurrentVersion();
1742 if ($environment_result->getLevel() == 'required') {
1743 $stringtouse = 'environmentrequireversion';
1744 } else {
1745 $stringtouse = 'environmentrecommendversion';
1746 }
1747
1748 } else if ($environment_result->getPart() == 'custom_check') {
1749 // We are checking installed & enabled things
1750 if ($environment_result->getLevel() == 'required') {
1751 $stringtouse = 'environmentrequirecustomcheck';
1752 } else {
1753 $stringtouse = 'environmentrecommendcustomcheck';
1754 }
1755
1756 } else if ($environment_result->getPart() == 'php_setting') {
1757 if ($status) {
1758 $stringtouse = 'environmentsettingok';
1759 } else if ($environment_result->getLevel() == 'required') {
1760 $stringtouse = 'environmentmustfixsetting';
1761 } else {
1762 $stringtouse = 'environmentshouldfixsetting';
1763 }
1764
1765 } else {
1766 if ($environment_result->getLevel() == 'required') {
1767 $stringtouse = 'environmentrequireinstall';
1768 } else {
1769 $stringtouse = 'environmentrecommendinstall';
1770 }
1771 }
1772
1773 // Calculate the status value
1774 if ($environment_result->getBypassStr() != '') { //Handle bypassed result (warning)
1775 $status = get_string('bypassed');
1776 $warningline = true;
1777 } else if ($environment_result->getRestrictStr() != '') { //Handle restricted result (error)
1778 $status = get_string('restricted');
1779 $errorline = true;
1780 } else {
1781 if ($status) { //Handle ok result (ok)
1782 $status = get_string('ok');
1783 } else {
1784 if ($environment_result->getLevel() == 'optional') {//Handle check result (warning)
1785 $status = get_string('check');
1786 $warningline = true;
1787 } else { //Handle error result (error)
1788 $status = get_string('check');
1789 $errorline = true;
1790 }
1791 }
1792 }
1793 }
1794
1795 // Build the text
1796 $linkparts = array();
1797 $linkparts[] = 'admin/environment';
1798 $linkparts[] = $type;
1799 if (!empty($info)){
1800 $linkparts[] = $info;
1801 }
40cba608
PS
1802 // Plugin environments do not have docs pages yet.
1803 if (empty($CFG->docroot) or $environment_result->plugin) {
cc359566
TH
1804 $report = get_string($stringtouse, 'admin', $rec);
1805 } else {
1806 $report = $this->doc_link(join($linkparts, '/'), get_string($stringtouse, 'admin', $rec));
1807 }
1808
1809 // Format error or warning line
1810 if ($errorline || $warningline) {
1811 $messagetype = $errorline? 'error':'warn';
1812 } else {
1813 $messagetype = 'ok';
1814 }
1815 $status = '<span class="'.$messagetype.'">'.$status.'</span>';
1816 // Here we'll store all the feedback found
1817 $feedbacktext = '';
1818 // Append the feedback if there is some
1819 $feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), $messagetype);
1820 //Append the bypass if there is some
1821 $feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'warn');
1822 //Append the restrict if there is some
1823 $feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'error');
1824
1825 $report .= $feedbacktext;
1826
1827 // Add the row to the table
1828 if ($environment_result->getPart() == 'custom_check'){
40cba608 1829 $otherdata[$messagetype][] = array ($info, $report, $plugin, $status);
cc359566 1830 } else {
40cba608 1831 $serverdata[$messagetype][] = array ($type, $info, $report, $plugin, $status);
cc359566
TH
1832 }
1833 }
1834 }
1835
1836 //put errors first in
1837 $servertable->data = array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']);
1838 $othertable->data = array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']);
1839
1840 // Print table
1841 $output = '';
1842 $output .= $this->heading(get_string('serverchecks', 'admin'));
1843 $output .= html_writer::table($servertable);
1844 if (count($othertable->data)){
1845 $output .= $this->heading(get_string('customcheck', 'admin'));
1846 $output .= html_writer::table($othertable);
1847 }
1848
1849 // Finally, if any error has happened, print the summary box
1850 if (!$result) {
1851 $output .= $this->box(get_string('environmenterrortodo', 'admin'), 'environmentbox errorbox');
1852 }
1853
1854 return $output;
da2fdc3f 1855 }
98b32c9e
DM
1856
1857 /**
1858 * Render a simple page for providing the upgrade key.
1859 *
1860 * @param moodle_url|string $url
1861 * @return string
1862 */
1863 public function upgradekey_form_page($url) {
1864
1865 $output = '';
1866 $output .= $this->header();
1867 $output .= $this->container_start('upgradekeyreq');
1868 $output .= $this->heading(get_string('upgradekeyreq', 'core_admin'));
1869 $output .= html_writer::start_tag('form', array('method' => 'POST', 'action' => $url));
1870 $output .= html_writer::empty_tag('input', array('name' => 'upgradekey', 'type' => 'password'));
1871 $output .= html_writer::empty_tag('input', array('value' => get_string('submit'), 'type' => 'submit'));
1872 $output .= html_writer::end_tag('form');
1873 $output .= $this->container_end();
1874 $output .= $this->footer();
1875
1876 return $output;
1877 }
b9934a17 1878}