weekly release 3.0dev
[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(
873 get_string('displayname', 'core_plugin'),
874 get_string('rootdir', 'core_plugin'),
875 get_string('source', 'core_plugin'),
876 get_string('versiondb', 'core_plugin'),
877 get_string('versiondisk', 'core_plugin'),
36ca62ca 878 get_string('requires', 'core_plugin'),
b9934a17
DM
879 get_string('status', 'core_plugin'),
880 );
881 $table->colclasses = array(
36ca62ca 882 'displayname', 'rootdir', 'source', 'versiondb', 'versiondisk', 'requires', 'status',
b9934a17
DM
883 );
884 $table->data = array();
885
886 $numofhighlighted = array(); // number of highlighted rows per this subsection
887
888 foreach ($plugininfo as $type => $plugins) {
889
890 $header = new html_table_cell($pluginman->plugintype_name_plural($type));
891 $header->header = true;
892 $header->colspan = count($table->head);
893 $header = new html_table_row(array($header));
894 $header->attributes['class'] = 'plugintypeheader type-' . $type;
895
896 $numofhighlighted[$type] = 0;
897
898 if (empty($plugins) and $options['full']) {
899 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
900 $msg->colspan = count($table->head);
901 $row = new html_table_row(array($msg));
902 $row->attributes['class'] .= 'msg msg-noneinstalled';
903 $table->data[] = $header;
904 $table->data[] = $row;
905 continue;
906 }
907
908 $plugintyperows = array();
909
910 foreach ($plugins as $name => $plugin) {
911 $row = new html_table_row();
912 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
913
436dbeec 914 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name, null)) {
b9934a17
DM
915 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
916 } else {
917 $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon'));
918 }
919 $displayname = $icon . ' ' . $plugin->displayname;
920 $displayname = new html_table_cell($displayname);
921
922 $rootdir = new html_table_cell($plugin->get_dir());
923
924 if ($isstandard = $plugin->is_standard()) {
925 $row->attributes['class'] .= ' standard';
926 $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
927 } else {
928 $row->attributes['class'] .= ' extension';
929 $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
930 }
931
932 $versiondb = new html_table_cell($plugin->versiondb);
933 $versiondisk = new html_table_cell($plugin->versiondisk);
934
935 $statuscode = $plugin->get_status();
936 $row->attributes['class'] .= ' status-' . $statuscode;
96dd9237
DM
937 $status = get_string('status_' . $statuscode, 'core_plugin');
938
939 $availableupdates = $plugin->available_updates();
fa1d403f 940 if (!empty($availableupdates) and empty($CFG->disableupdatenotifications)) {
96dd9237
DM
941 foreach ($availableupdates as $availableupdate) {
942 $status .= $this->plugin_available_update_info($availableupdate);
943 }
944 }
b9934a17 945
96dd9237 946 $status = new html_table_cell($status);
b9934a17 947
faadd326 948 $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version));
36ca62ca
TH
949
950 $statusisboring = in_array($statuscode, array(
e87214bd 951 core_plugin_manager::PLUGIN_STATUS_NODB, core_plugin_manager::PLUGIN_STATUS_UPTODATE));
e937c545
DM
952
953 $coredependency = $plugin->is_core_dependency_satisfied($version);
954 $otherpluginsdependencies = $pluginman->are_dependencies_satisfied($plugin->get_other_required_plugins());
955 $dependenciesok = $coredependency && $otherpluginsdependencies;
39f15cc7
DM
956
957 if ($options['xdep']) {
958 // we want to see only plugins with failed dependencies
959 if ($dependenciesok) {
960 continue;
961 }
962
2f838a4e 963 } else if ($statusisboring and $dependenciesok and empty($availableupdates)) {
39f15cc7
DM
964 // no change is going to happen to the plugin - display it only
965 // if the user wants to see the full list
b9934a17
DM
966 if (empty($options['full'])) {
967 continue;
968 }
b9934a17
DM
969 }
970
39f15cc7
DM
971 // ok, the plugin should be displayed
972 $numofhighlighted[$type]++;
973
36ca62ca
TH
974 $row->cells = array($displayname, $rootdir, $source,
975 $versiondb, $versiondisk, $requires, $status);
b9934a17
DM
976 $plugintyperows[] = $row;
977 }
978
979 if (empty($numofhighlighted[$type]) and empty($options['full'])) {
980 continue;
981 }
982
983 $table->data[] = $header;
984 $table->data = array_merge($table->data, $plugintyperows);
985 }
986
987 $sumofhighlighted = array_sum($numofhighlighted);
988
39f15cc7
DM
989 if ($options['xdep']) {
990 // we do not want to display no heading and links in this mode
991 $out = '';
992
993 } else if ($sumofhighlighted == 0) {
b9934a17
DM
994 $out = $this->output->container_start('nonehighlighted', 'plugins-check-info');
995 $out .= $this->output->heading(get_string('nonehighlighted', 'core_plugin'));
996 if (empty($options['full'])) {
98b32c9e 997 $out .= html_writer::link(new moodle_url($this->page->url,
fc281113 998 array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1, 'cache' => 0)),
b9934a17
DM
999 get_string('nonehighlightedinfo', 'core_plugin'));
1000 }
1001 $out .= $this->output->container_end();
1002
1003 } else {
1004 $out = $this->output->container_start('somehighlighted', 'plugins-check-info');
b9934a17 1005 if (empty($options['full'])) {
a277654f
DM
1006 $out .= $this->output->heading(get_string('somehighlighted', 'core_plugin', $sumofhighlighted));
1007 $out .= html_writer::link(new moodle_url($this->page->url,
fc281113 1008 array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1, 'cache' => 0)),
b9934a17 1009 get_string('somehighlightedinfo', 'core_plugin'));
a687fcac 1010 } else {
a277654f
DM
1011 $out .= $this->output->heading(get_string('somehighlightedall', 'core_plugin', $sumofhighlighted));
1012 $out .= html_writer::link(new moodle_url($this->page->url,
fc281113 1013 array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 0, 'cache' => 0)),
a687fcac 1014 get_string('somehighlightedonly', 'core_plugin'));
b9934a17
DM
1015 }
1016 $out .= $this->output->container_end();
1017 }
1018
1019 if ($sumofhighlighted > 0 or $options['full']) {
1020 $out .= html_writer::table($table);
1021 }
1022
1023 return $out;
1024 }
1025
36ca62ca
TH
1026 /**
1027 * Formats the information that needs to go in the 'Requires' column.
e87214bd
PS
1028 * @param \core\plugininfo\base $plugin the plugin we are rendering the row for.
1029 * @param core_plugin_manager $pluginman provides data on all the plugins.
8d1da748
PS
1030 * @param string $version
1031 * @return string HTML code
36ca62ca 1032 */
e87214bd 1033 protected function required_column(\core\plugininfo\base $plugin, core_plugin_manager $pluginman, $version) {
36ca62ca
TH
1034 $requires = array();
1035
1036 if (!empty($plugin->versionrequires)) {
faadd326 1037 if ($plugin->versionrequires <= $version) {
36ca62ca
TH
1038 $class = 'requires-ok';
1039 } else {
1040 $class = 'requires-failed';
1041 }
1042 $requires[] = html_writer::tag('li',
1043 get_string('moodleversion', 'core_plugin', $plugin->versionrequires),
1044 array('class' => $class));
1045 }
1046
1047 foreach ($plugin->get_other_required_plugins() as $component => $requiredversion) {
36ca62ca 1048 $otherplugin = $pluginman->get_plugin_info($component);
2cdea9c7 1049 $actions = array();
36ca62ca
TH
1050
1051 if (is_null($otherplugin)) {
2cdea9c7
DM
1052 // The required plugin is not installed.
1053 $class = 'requires-failed requires-missing';
1054 $installurl = new moodle_url('https://moodle.org/plugins/view.php', array('plugin' => $component));
1055 $uploadurl = new moodle_url('/admin/tool/installaddon/');
1056 $actions[] = html_writer::link($installurl, get_string('dependencyinstall', 'core_plugin'));
1057 $actions[] = html_writer::link($uploadurl, get_string('dependencyupload', 'core_plugin'));
1058
499ff0a9 1059 } else if ($requiredversion != ANY_VERSION and $otherplugin->versiondisk < $requiredversion) {
2cdea9c7
DM
1060 // The required plugin is installed but needs to be updated.
1061 $class = 'requires-failed requires-outdated';
1062 if (!$otherplugin->is_standard()) {
1063 $updateurl = new moodle_url($this->page->url, array('sesskey' => sesskey(), 'fetchupdates' => 1));
1064 $actions[] = html_writer::link($updateurl, get_string('checkforupdates', 'core_plugin'));
1065 }
36ca62ca 1066
36ca62ca 1067 } else {
2cdea9c7
DM
1068 // Already installed plugin with sufficient version.
1069 $class = 'requires-ok';
36ca62ca
TH
1070 }
1071
1072 if ($requiredversion != ANY_VERSION) {
1073 $str = 'otherpluginversion';
1074 } else {
1075 $str = 'otherplugin';
1076 }
2cdea9c7 1077
36ca62ca 1078 $requires[] = html_writer::tag('li',
2cdea9c7
DM
1079 html_writer::div(get_string($str, 'core_plugin',
1080 array('component' => $component, 'version' => $requiredversion)), 'component').
1081 html_writer::div(implode(' | ', $actions), 'actions'),
36ca62ca
TH
1082 array('class' => $class));
1083 }
1084
1085 if (!$requires) {
1086 return '';
1087 }
1088 return html_writer::tag('ul', implode("\n", $requires));
1089 }
1090
d26f3ddd
DM
1091 /**
1092 * Prints an overview about the plugins - number of installed, number of extensions etc.
1093 *
e87214bd 1094 * @param core_plugin_manager $pluginman provides information about the plugins
4df8bced 1095 * @param array $options filtering options
d26f3ddd
DM
1096 * @return string as usually
1097 */
e87214bd 1098 public function plugins_overview_panel(core_plugin_manager $pluginman, array $options = array()) {
7716057f
DM
1099 global $CFG;
1100
d26f3ddd
DM
1101 $plugininfo = $pluginman->get_plugins();
1102
1103 $numtotal = $numdisabled = $numextension = $numupdatable = 0;
1104
1105 foreach ($plugininfo as $type => $plugins) {
1106 foreach ($plugins as $name => $plugin) {
e87214bd 1107 if ($plugin->get_status() === core_plugin_manager::PLUGIN_STATUS_MISSING) {
d26f3ddd
DM
1108 continue;
1109 }
1110 $numtotal++;
1111 if ($plugin->is_enabled() === false) {
1112 $numdisabled++;
1113 }
1114 if (!$plugin->is_standard()) {
1115 $numextension++;
1116 }
7716057f 1117 if (empty($CFG->disableupdatenotifications) and $plugin->available_updates()) {
d26f3ddd
DM
1118 $numupdatable++;
1119 }
1120 }
1121 }
1122
1123 $info = array();
4df8bced
DM
1124 $filter = array();
1125 $somefilteractive = false;
d26f3ddd
DM
1126 $info[] = html_writer::tag('span', get_string('numtotal', 'core_plugin', $numtotal), array('class' => 'info total'));
1127 $info[] = html_writer::tag('span', get_string('numdisabled', 'core_plugin', $numdisabled), array('class' => 'info disabled'));
1128 $info[] = html_writer::tag('span', get_string('numextension', 'core_plugin', $numextension), array('class' => 'info extension'));
4df8bced
DM
1129 if ($numextension > 0) {
1130 if (empty($options['contribonly'])) {
1131 $filter[] = html_writer::link(
1132 new moodle_url($this->page->url, array('contribonly' => 1)),
1133 get_string('filtercontribonly', 'core_plugin'),
1134 array('class' => 'filter-item show-contribonly')
1135 );
1136 } else {
1137 $filter[] = html_writer::tag('span', get_string('filtercontribonlyactive', 'core_plugin'),
1138 array('class' => 'filter-item active show-contribonly'));
1139 $somefilteractive = true;
1140 }
1141 }
d26f3ddd
DM
1142 if ($numupdatable > 0) {
1143 $info[] = html_writer::tag('span', get_string('numupdatable', 'core_plugin', $numupdatable), array('class' => 'info updatable'));
4df8bced
DM
1144 if (empty($options['updatesonly'])) {
1145 $filter[] = html_writer::link(
1146 new moodle_url($this->page->url, array('updatesonly' => 1)),
1147 get_string('filterupdatesonly', 'core_plugin'),
1148 array('class' => 'filter-item show-updatesonly')
1149 );
1150 } else {
1151 $filter[] = html_writer::tag('span', get_string('filterupdatesonlyactive', 'core_plugin'),
1152 array('class' => 'filter-item active show-updatesonly'));
1153 $somefilteractive = true;
1154 }
d26f3ddd 1155 }
4df8bced
DM
1156 if ($somefilteractive) {
1157 $filter[] = html_writer::link($this->page->url, get_string('filterall', 'core_plugin'), array('class' => 'filter-item show-all'));
1158 }
1159
1160 $output = $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $info), '', 'plugins-overview-panel');
d26f3ddd 1161
4df8bced
DM
1162 if (!empty($filter)) {
1163 $output .= $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $filter), '', 'plugins-overview-filter');
1164 }
1165
1166 return $output;
d26f3ddd
DM
1167 }
1168
b9934a17
DM
1169 /**
1170 * Displays all known plugins and links to manage them
1171 *
1172 * This default implementation renders all plugins into one big table.
1173 *
e87214bd 1174 * @param core_plugin_manager $pluginman provides information about the plugins.
4df8bced 1175 * @param array $options filtering options
b9934a17
DM
1176 * @return string HTML code
1177 */
e87214bd 1178 public function plugins_control_panel(core_plugin_manager $pluginman, array $options = array()) {
7716057f
DM
1179 global $CFG;
1180
36ca62ca 1181 $plugininfo = $pluginman->get_plugins();
b9934a17 1182
4df8bced
DM
1183 // Filter the list of plugins according the options.
1184 if (!empty($options['updatesonly'])) {
1185 $updateable = array();
1186 foreach ($plugininfo as $plugintype => $pluginnames) {
1187 foreach ($pluginnames as $pluginname => $pluginfo) {
1188 if (!empty($pluginfo->availableupdates)) {
1189 foreach ($pluginfo->availableupdates as $pluginavailableupdate) {
1190 if ($pluginavailableupdate->version > $pluginfo->versiondisk) {
1191 $updateable[$plugintype][$pluginname] = $pluginfo;
1192 }
1193 }
1194 }
1195 }
1196 }
1197 $plugininfo = $updateable;
1198 }
1199
1200 if (!empty($options['contribonly'])) {
1201 $contribs = array();
1202 foreach ($plugininfo as $plugintype => $pluginnames) {
1203 foreach ($pluginnames as $pluginname => $pluginfo) {
1204 if (!$pluginfo->is_standard()) {
1205 $contribs[$plugintype][$pluginname] = $pluginfo;
1206 }
1207 }
1208 }
1209 $plugininfo = $contribs;
1210 }
1211
b9934a17
DM
1212 if (empty($plugininfo)) {
1213 return '';
1214 }
1215
b9934a17
DM
1216 $table = new html_table();
1217 $table->id = 'plugins-control-panel';
1218 $table->head = array(
1219 get_string('displayname', 'core_plugin'),
b9934a17
DM
1220 get_string('source', 'core_plugin'),
1221 get_string('version', 'core_plugin'),
2f98f5d5 1222 get_string('release', 'core_plugin'),
b9934a17 1223 get_string('availability', 'core_plugin'),
2b135b05
DM
1224 get_string('actions', 'core_plugin'),
1225 get_string('notes','core_plugin'),
b9934a17 1226 );
2f98f5d5 1227 $table->headspan = array(1, 1, 1, 1, 1, 2, 1);
b9934a17 1228 $table->colclasses = array(
2f98f5d5 1229 'pluginname', 'source', 'version', 'release', 'availability', 'settings', 'uninstall', 'notes'
b9934a17
DM
1230 );
1231
1232 foreach ($plugininfo as $type => $plugins) {
e87214bd
PS
1233 $heading = $pluginman->plugintype_name_plural($type);
1234 $pluginclass = core_plugin_manager::resolve_plugininfo_class($type);
1235 if ($manageurl = $pluginclass::get_manage_url()) {
1236 $heading = html_writer::link($manageurl, $heading);
1237 }
1238 $header = new html_table_cell(html_writer::tag('span', $heading, array('id'=>'plugin_type_cell_'.$type)));
b9934a17 1239 $header->header = true;
54d75893 1240 $header->colspan = array_sum($table->headspan);
b9934a17
DM
1241 $header = new html_table_row(array($header));
1242 $header->attributes['class'] = 'plugintypeheader type-' . $type;
1243 $table->data[] = $header;
1244
1245 if (empty($plugins)) {
1246 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
54d75893 1247 $msg->colspan = array_sum($table->headspan);
b9934a17
DM
1248 $row = new html_table_row(array($msg));
1249 $row->attributes['class'] .= 'msg msg-noneinstalled';
1250 $table->data[] = $row;
1251 continue;
1252 }
1253
1254 foreach ($plugins as $name => $plugin) {
1255 $row = new html_table_row();
1256 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
1257
1258 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) {
fa9c0aab 1259 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'icon pluginicon'));
b9934a17 1260 } else {
fa9c0aab 1261 $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'icon pluginicon noicon'));
b9934a17 1262 }
9074e478
DM
1263 $status = $plugin->get_status();
1264 $row->attributes['class'] .= ' status-'.$status;
e87214bd 1265 if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) {
9074e478 1266 $msg = html_writer::tag('span', get_string('status_missing', 'core_plugin'), array('class' => 'statusmsg'));
e87214bd 1267 } else if ($status === core_plugin_manager::PLUGIN_STATUS_NEW) {
9074e478 1268 $msg = html_writer::tag('span', get_string('status_new', 'core_plugin'), array('class' => 'statusmsg'));
b9934a17
DM
1269 } else {
1270 $msg = '';
1271 }
fa9c0aab 1272 $pluginname = html_writer::tag('div', $icon . '' . $plugin->displayname . ' ' . $msg, array('class' => 'displayname')).
2b135b05
DM
1273 html_writer::tag('div', $plugin->component, array('class' => 'componentname'));
1274 $pluginname = new html_table_cell($pluginname);
b9934a17
DM
1275
1276 if ($plugin->is_standard()) {
1277 $row->attributes['class'] .= ' standard';
1278 $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
1279 } else {
1280 $row->attributes['class'] .= ' extension';
1281 $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
1282 }
1283
1284 $version = new html_table_cell($plugin->versiondb);
2f98f5d5 1285 $release = new html_table_cell($plugin->release);
b9934a17
DM
1286
1287 $isenabled = $plugin->is_enabled();
1288 if (is_null($isenabled)) {
1289 $availability = new html_table_cell('');
1290 } else if ($isenabled) {
1291 $row->attributes['class'] .= ' enabled';
7bc759bd 1292 $availability = new html_table_cell(get_string('pluginenabled', 'core_plugin'));
b9934a17
DM
1293 } else {
1294 $row->attributes['class'] .= ' disabled';
7bc759bd 1295 $availability = new html_table_cell(get_string('plugindisabled', 'core_plugin'));
b9934a17
DM
1296 }
1297
1298 $settingsurl = $plugin->get_settings_url();
2b135b05 1299 if (!is_null($settingsurl)) {
54d75893
DM
1300 $settings = html_writer::link($settingsurl, get_string('settings', 'core_plugin'), array('class' => 'settings'));
1301 } else {
1302 $settings = '';
b9934a17 1303 }
54d75893 1304 $settings = new html_table_cell($settings);
b9934a17 1305
e87214bd 1306 if ($uninstallurl = $pluginman->get_uninstall_url($plugin->component, 'overview')) {
54d75893
DM
1307 $uninstall = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin'));
1308 } else {
1309 $uninstall = '';
2b135b05 1310 }
54d75893 1311 $uninstall = new html_table_cell($uninstall);
2b135b05 1312
828788f0 1313 $requriedby = $pluginman->other_plugins_that_require($plugin->component);
2b135b05
DM
1314 if ($requriedby) {
1315 $requiredby = html_writer::tag('div', get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
1316 array('class' => 'requiredby'));
b9934a17 1317 } else {
2b135b05 1318 $requiredby = '';
b9934a17
DM
1319 }
1320
7d8de6d8 1321 $updateinfo = '';
7716057f 1322 if (empty($CFG->disableupdatenotifications) and is_array($plugin->available_updates())) {
7d8de6d8
DM
1323 foreach ($plugin->available_updates() as $availableupdate) {
1324 $updateinfo .= $this->plugin_available_update_info($availableupdate);
1325 }
3204daea
DM
1326 }
1327
1328 $notes = new html_table_cell($requiredby.$updateinfo);
2b135b05 1329
b9934a17 1330 $row->cells = array(
2f98f5d5 1331 $pluginname, $source, $version, $release, $availability, $settings, $uninstall, $notes
b9934a17
DM
1332 );
1333 $table->data[] = $row;
1334 }
1335 }
1336
1337 return html_writer::table($table);
1338 }
da2fdc3f 1339
3204daea 1340 /**
e7611389 1341 * Helper method to render the information about the available plugin update
3204daea
DM
1342 *
1343 * The passed objects always provides at least the 'version' property containing
7d8de6d8 1344 * the (higher) version of the plugin available.
3204daea 1345 *
e87214bd 1346 * @param \core\update\info $updateinfo information about the available update for the plugin
3204daea 1347 */
e87214bd 1348 protected function plugin_available_update_info(\core\update\info $updateinfo) {
3204daea 1349
e7611389 1350 $boxclasses = 'pluginupdateinfo';
3204daea
DM
1351 $info = array();
1352
1353 if (isset($updateinfo->release)) {
1354 $info[] = html_writer::tag('span', get_string('updateavailable_release', 'core_plugin', $updateinfo->release),
1355 array('class' => 'info release'));
1356 }
1357
1358 if (isset($updateinfo->maturity)) {
1359 $info[] = html_writer::tag('span', get_string('maturity'.$updateinfo->maturity, 'core_admin'),
1360 array('class' => 'info maturity'));
e7611389 1361 $boxclasses .= ' maturity'.$updateinfo->maturity;
3204daea
DM
1362 }
1363
1364 if (isset($updateinfo->download)) {
1365 $info[] = html_writer::link($updateinfo->download, get_string('download'), array('class' => 'info download'));
1366 }
1367
1368 if (isset($updateinfo->url)) {
1369 $info[] = html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin'),
1370 array('class' => 'info more'));
1371 }
1372
e7611389
DM
1373 $box = $this->output->box_start($boxclasses);
1374 $box .= html_writer::tag('div', get_string('updateavailable', 'core_plugin', $updateinfo->version), array('class' => 'version'));
1375 $box .= $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $info), '');
fa3feafb 1376
e87214bd 1377 $deployer = \core\update\deployer::instance();
0daa6428
DM
1378 if ($deployer->initialized()) {
1379 $impediments = $deployer->deployment_impediments($updateinfo);
1380 if (empty($impediments)) {
1381 $widget = $deployer->make_confirm_widget($updateinfo);
1382 $box .= $this->output->render($widget);
30e26827
DM
1383 } else {
1384 if (isset($impediments['notwritable'])) {
1385 $box .= $this->output->help_icon('notwritable', 'core_plugin', get_string('notwritable', 'core_plugin'));
1386 }
1387 if (isset($impediments['notdownloadable'])) {
1388 $box .= $this->output->help_icon('notdownloadable', 'core_plugin', get_string('notdownloadable', 'core_plugin'));
1389 }
0daa6428 1390 }
fa3feafb
DM
1391 }
1392
3204daea
DM
1393 $box .= $this->output->box_end();
1394
1395 return $box;
1396 }
1397
da2fdc3f 1398 /**
cc359566
TH
1399 * This function will render one beautiful table with all the environmental
1400 * configuration and how it suits Moodle needs.
1401 *
1402 * @param boolean $result final result of the check (true/false)
40cba608 1403 * @param environment_results[] $environment_results array of results gathered
cc359566 1404 * @return string HTML to output.
da2fdc3f 1405 */
cc359566
TH
1406 public function environment_check_table($result, $environment_results) {
1407 global $CFG;
1408
1409 // Table headers
1410 $servertable = new html_table();//table for server checks
1411 $servertable->head = array(
1412 get_string('name'),
1413 get_string('info'),
1414 get_string('report'),
40cba608 1415 get_string('plugin'),
cc359566
TH
1416 get_string('status'),
1417 );
40cba608 1418 $servertable->colclasses = array('centeralign name', 'centeralign info', 'leftalign report', 'leftalign plugin', 'centeralign status');
6fc61f2d
RW
1419 $servertable->attributes['class'] = 'admintable environmenttable generaltable';
1420 $servertable->id = 'serverstatus';
cc359566
TH
1421
1422 $serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
1423
1424 $othertable = new html_table();//table for custom checks
1425 $othertable->head = array(
1426 get_string('info'),
1427 get_string('report'),
40cba608 1428 get_string('plugin'),
cc359566
TH
1429 get_string('status'),
1430 );
40cba608 1431 $othertable->colclasses = array('aligncenter info', 'alignleft report', 'alignleft plugin', 'aligncenter status');
6fc61f2d
RW
1432 $othertable->attributes['class'] = 'admintable environmenttable generaltable';
1433 $othertable->id = 'otherserverstatus';
cc359566
TH
1434
1435 $otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
1436
1437 // Iterate over each environment_result
1438 $continue = true;
1439 foreach ($environment_results as $environment_result) {
1440 $errorline = false;
1441 $warningline = false;
1442 $stringtouse = '';
1443 if ($continue) {
1444 $type = $environment_result->getPart();
1445 $info = $environment_result->getInfo();
1446 $status = $environment_result->getStatus();
40cba608 1447 $plugin = $environment_result->getPluginName();
cc359566
TH
1448 $error_code = $environment_result->getErrorCode();
1449 // Process Report field
1450 $rec = new stdClass();
1451 // Something has gone wrong at parsing time
1452 if ($error_code) {
1453 $stringtouse = 'environmentxmlerror';
1454 $rec->error_code = $error_code;
1455 $status = get_string('error');
1456 $errorline = true;
1457 $continue = false;
1458 }
1459
1460 if ($continue) {
1461 if ($rec->needed = $environment_result->getNeededVersion()) {
1462 // We are comparing versions
1463 $rec->current = $environment_result->getCurrentVersion();
1464 if ($environment_result->getLevel() == 'required') {
1465 $stringtouse = 'environmentrequireversion';
1466 } else {
1467 $stringtouse = 'environmentrecommendversion';
1468 }
1469
1470 } else if ($environment_result->getPart() == 'custom_check') {
1471 // We are checking installed & enabled things
1472 if ($environment_result->getLevel() == 'required') {
1473 $stringtouse = 'environmentrequirecustomcheck';
1474 } else {
1475 $stringtouse = 'environmentrecommendcustomcheck';
1476 }
1477
1478 } else if ($environment_result->getPart() == 'php_setting') {
1479 if ($status) {
1480 $stringtouse = 'environmentsettingok';
1481 } else if ($environment_result->getLevel() == 'required') {
1482 $stringtouse = 'environmentmustfixsetting';
1483 } else {
1484 $stringtouse = 'environmentshouldfixsetting';
1485 }
1486
1487 } else {
1488 if ($environment_result->getLevel() == 'required') {
1489 $stringtouse = 'environmentrequireinstall';
1490 } else {
1491 $stringtouse = 'environmentrecommendinstall';
1492 }
1493 }
1494
1495 // Calculate the status value
1496 if ($environment_result->getBypassStr() != '') { //Handle bypassed result (warning)
1497 $status = get_string('bypassed');
1498 $warningline = true;
1499 } else if ($environment_result->getRestrictStr() != '') { //Handle restricted result (error)
1500 $status = get_string('restricted');
1501 $errorline = true;
1502 } else {
1503 if ($status) { //Handle ok result (ok)
1504 $status = get_string('ok');
1505 } else {
1506 if ($environment_result->getLevel() == 'optional') {//Handle check result (warning)
1507 $status = get_string('check');
1508 $warningline = true;
1509 } else { //Handle error result (error)
1510 $status = get_string('check');
1511 $errorline = true;
1512 }
1513 }
1514 }
1515 }
1516
1517 // Build the text
1518 $linkparts = array();
1519 $linkparts[] = 'admin/environment';
1520 $linkparts[] = $type;
1521 if (!empty($info)){
1522 $linkparts[] = $info;
1523 }
40cba608
PS
1524 // Plugin environments do not have docs pages yet.
1525 if (empty($CFG->docroot) or $environment_result->plugin) {
cc359566
TH
1526 $report = get_string($stringtouse, 'admin', $rec);
1527 } else {
1528 $report = $this->doc_link(join($linkparts, '/'), get_string($stringtouse, 'admin', $rec));
1529 }
1530
1531 // Format error or warning line
1532 if ($errorline || $warningline) {
1533 $messagetype = $errorline? 'error':'warn';
1534 } else {
1535 $messagetype = 'ok';
1536 }
1537 $status = '<span class="'.$messagetype.'">'.$status.'</span>';
1538 // Here we'll store all the feedback found
1539 $feedbacktext = '';
1540 // Append the feedback if there is some
1541 $feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), $messagetype);
1542 //Append the bypass if there is some
1543 $feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'warn');
1544 //Append the restrict if there is some
1545 $feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'error');
1546
1547 $report .= $feedbacktext;
1548
1549 // Add the row to the table
1550 if ($environment_result->getPart() == 'custom_check'){
40cba608 1551 $otherdata[$messagetype][] = array ($info, $report, $plugin, $status);
cc359566 1552 } else {
40cba608 1553 $serverdata[$messagetype][] = array ($type, $info, $report, $plugin, $status);
cc359566
TH
1554 }
1555 }
1556 }
1557
1558 //put errors first in
1559 $servertable->data = array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']);
1560 $othertable->data = array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']);
1561
1562 // Print table
1563 $output = '';
1564 $output .= $this->heading(get_string('serverchecks', 'admin'));
1565 $output .= html_writer::table($servertable);
1566 if (count($othertable->data)){
1567 $output .= $this->heading(get_string('customcheck', 'admin'));
1568 $output .= html_writer::table($othertable);
1569 }
1570
1571 // Finally, if any error has happened, print the summary box
1572 if (!$result) {
1573 $output .= $this->box(get_string('environmenterrortodo', 'admin'), 'environmentbox errorbox');
1574 }
1575
1576 return $output;
da2fdc3f 1577 }
98b32c9e
DM
1578
1579 /**
1580 * Render a simple page for providing the upgrade key.
1581 *
1582 * @param moodle_url|string $url
1583 * @return string
1584 */
1585 public function upgradekey_form_page($url) {
1586
1587 $output = '';
1588 $output .= $this->header();
1589 $output .= $this->container_start('upgradekeyreq');
1590 $output .= $this->heading(get_string('upgradekeyreq', 'core_admin'));
1591 $output .= html_writer::start_tag('form', array('method' => 'POST', 'action' => $url));
1592 $output .= html_writer::empty_tag('input', array('name' => 'upgradekey', 'type' => 'password'));
1593 $output .= html_writer::empty_tag('input', array('value' => get_string('submit'), 'type' => 'submit'));
1594 $output .= html_writer::end_tag('form');
1595 $output .= $this->container_end();
1596 $output .= $this->footer();
1597
1598 return $output;
1599 }
b9934a17 1600}