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