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