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