MDL-32329 new plugininfo_base::is_core_dependency_satisfied() method
[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
28require_once($CFG->libdir . '/pluginlib.php');
29
30/**
31 * Standard HTML output renderer for core_admin subsystem
32 */
33class core_admin_renderer extends plugin_renderer_base {
34
cc359566
TH
35 /**
36 * Display the 'Do you acknowledge the terms of the GPL' page. The first page
37 * during install.
38 * @return string HTML to output.
39 */
40 public function install_licence_page() {
41 global $CFG;
42 $output = '';
43
44 $copyrightnotice = text_to_html(get_string('gpl3'));
45 $copyrightnotice = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $copyrightnotice); // extremely ugly validation hack
46
47 $continue = new single_button(new moodle_url('/admin/index.php', array('lang'=>$CFG->lang, 'agreelicense'=>1)), get_string('continue'), 'get');
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');
71 $output .= get_string('upgradestalefilesinfo', 'admin', get_docs_url('Upgrading'));
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) {
100 $output .= $this->upgrade_reload(new moodle_url('/admin/index.php', array('agreelicense' => 1, 'lang' => $CFG->lang)));
101 } else {
102 $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
103 $output .= $this->continue_button(new moodle_url('/admin/index.php', array('agreelicense'=>1, 'confirmrelease'=>1, 'lang'=>$CFG->lang)));
104 }
105
106 $output .= $this->footer();
107 return $output;
108 }
109
110 /**
111 * Display the 'You are about to upgrade Moodle' page. The first page
112 * during upgrade.
8d1da748
PS
113 * @param string $strnewversion
114 * @param int $maturity
cc359566
TH
115 * @return string HTML to output.
116 */
117 public function upgrade_confirm_page($strnewversion, $maturity) {
118 $output = '';
119
120 $continueurl = new moodle_url('index.php', array('confirmupgrade' => 1));
121 $cancelurl = new moodle_url('index.php');
122
123 $output .= $this->header();
124 $output .= $this->maturity_warning($maturity);
125 $output .= $this->confirm(get_string('upgradesure', 'admin', $strnewversion), $continueurl, $cancelurl);
126 $output .= $this->footer();
127
128 return $output;
129 }
130
131 /**
132 * Display the environment page during the upgrade process.
8d1da748
PS
133 * @param string $release
134 * @param boolean $envstatus final result of env check (true/false)
135 * @param array $environment_results array of results gathered
cc359566
TH
136 * @return string HTML to output.
137 */
138 public function upgrade_environment_page($release, $envstatus, $environment_results) {
139 global $CFG;
140 $output = '';
141
142 $output .= $this->header();
143 $output .= $this->heading("Moodle $release");
144 $output .= $this->release_notes_link();
145 $output .= $this->environment_check_table($envstatus, $environment_results);
146
147 if (!$envstatus) {
148 $output .= $this->upgrade_reload(new moodle_url('/admin/index.php'), array('confirmupgrade' => 1));
149
150 } else {
faadd326 151 $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
cc359566
TH
152
153 if (empty($CFG->skiplangupgrade) and current_language() !== 'en') {
154 $output .= $this->box(get_string('langpackwillbeupdated', 'admin'), 'generalbox', 'notice');
155 }
156
157 $output .= $this->continue_button(new moodle_url('/admin/index.php', array('confirmupgrade' => 1, 'confirmrelease' => 1)));
158 }
159
160 $output .= $this->footer();
161
162 return $output;
163 }
164
165 /**
166 * Display the upgrade page that lists all the plugins that require attention.
8d1da748 167 * @param plugin_manager $pluginman provides information about the plugins.
96dd9237 168 * @param available_update_checker $checker provides information about available updates.
8d1da748
PS
169 * @param int $version the version of the Moodle code from version.php.
170 * @param bool $showallplugins
171 * @param moodle_url $reloadurl
172 * @param moodle_url $continueurl
cc359566
TH
173 * @return string HTML to output.
174 */
96dd9237
DM
175 public function upgrade_plugin_check_page(plugin_manager $pluginman, available_update_checker $checker,
176 $version, $showallplugins, $reloadurl, $continueurl) {
fa1d403f 177 global $CFG;
96dd9237 178
cc359566
TH
179 $output = '';
180
181 $output .= $this->header();
182 $output .= $this->box_start('generalbox');
96dd9237
DM
183 $output .= $this->container_start('generalbox', 'notice');
184 $output .= html_writer::tag('p', get_string('pluginchecknotice', 'core_plugin'));
fa1d403f
DM
185 if (empty($CFG->disableupdatenotifications)) {
186 $output .= $this->container_start('checkforupdates');
187 $output .= $this->single_button(new moodle_url($reloadurl, array('fetchupdates' => 1)), get_string('checkforupdates', 'core_plugin'));
188 if ($timefetched = $checker->get_last_timefetched()) {
189 $output .= $this->container(get_string('checkforupdateslast', 'core_plugin',
190 userdate($timefetched, get_string('strftimedatetime', 'core_langconfig'))));
191 }
192 $output .= $this->container_end();
96dd9237
DM
193 }
194 $output .= $this->container_end();
96dd9237 195
faadd326 196 $output .= $this->plugins_check_table($pluginman, $version, array('full' => $showallplugins));
cc359566
TH
197 $output .= $this->box_end();
198 $output .= $this->upgrade_reload($reloadurl);
199
faadd326 200 if ($pluginman->all_plugins_ok($version)) {
5344ddd1
DM
201 if ($pluginman->some_plugins_updatable()) {
202 $output .= $this->container_start('upgradepluginsinfo');
203 $output .= $this->help_icon('upgradepluginsinfo', 'core_admin', get_string('upgradepluginsfirst', 'core_admin'));
204 $output .= $this->container_end();
205 }
faadd326
TH
206 $button = new single_button($continueurl, get_string('upgradestart', 'admin'), 'get');
207 $button->class = 'continuebutton';
208 $output .= $this->render($button);
209 } else {
210 $output .= $this->box(get_string('pluginschecktodo', 'admin'), 'environmentbox errorbox');
211 }
cc359566
TH
212
213 $output .= $this->footer();
214
215 return $output;
216 }
217
218 /**
219 * Display the admin notifications page.
8d1da748
PS
220 * @param int $maturity
221 * @param bool $insecuredataroot warn dataroot is invalid
222 * @param bool $errorsdisplayed warn invalid dispaly error setting
223 * @param bool $cronoverdue warn cron not running
224 * @param bool $dbproblems warn db has problems
225 * @param bool $maintenancemode warn in maintenance mode
55585f3a
DM
226 * @param array|null $availableupdates array of available_update_info objects or null
227 * @param int|null $availableupdatesfetch timestamp of the most recent updates fetch or null (unknown)
228 *
cc359566
TH
229 * @return string HTML to output.
230 */
231 public function admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed,
55585f3a 232 $cronoverdue, $dbproblems, $maintenancemode, $availableupdates, $availableupdatesfetch) {
4db58f5f 233 global $CFG;
cc359566
TH
234 $output = '';
235
236 $output .= $this->header();
237 $output .= $this->maturity_info($maturity);
4db58f5f 238 $output .= empty($CFG->disableupdatenotifications) ? $this->available_updates($availableupdates, $availableupdatesfetch) : '';
cc359566
TH
239 $output .= $this->insecure_dataroot_warning($insecuredataroot);
240 $output .= $this->display_errors_warning($errorsdisplayed);
e3258164 241 $output .= $this->cron_overdue_warning($cronoverdue);
cc359566
TH
242 $output .= $this->db_problems($dbproblems);
243 $output .= $this->maintenance_mode_warning($maintenancemode);
244
245 //////////////////////////////////////////////////////////////////////////////////////////////////
246 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
247 $output .= $this->moodle_copyright();
248 //////////////////////////////////////////////////////////////////////////////////////////////////
249
250 $output .= $this->footer();
251
252 return $output;
253 }
254
8342171b
DM
255 /**
256 * Display the plugin management page (admin/plugins.php).
257 *
258 * @param plugin_manager $pluginman
259 * @param available_update_checker $checker
260 * @return string HTML to output.
261 */
262 public function plugin_management_page(plugin_manager $pluginman, available_update_checker $checker) {
7716057f
DM
263 global $CFG;
264
8342171b
DM
265 $output = '';
266
267 $output .= $this->header();
268 $output .= $this->heading(get_string('pluginsoverview', 'core_admin'));
269 $output .= $this->plugins_overview_panel($pluginman);
270
7716057f
DM
271 if (empty($CFG->disableupdatenotifications)) {
272 $output .= $this->container_start('checkforupdates');
273 $output .= $this->single_button(new moodle_url($this->page->url, array('fetchremote' => 1)), get_string('checkforupdates', 'core_plugin'));
274 if ($timefetched = $checker->get_last_timefetched()) {
275 $output .= $this->container(get_string('checkforupdateslast', 'core_plugin',
276 userdate($timefetched, get_string('strftimedatetime', 'core_langconfig'))));
277 }
278 $output .= $this->container_end();
8342171b 279 }
8342171b
DM
280
281 $output .= $this->box($this->plugins_control_panel($pluginman), 'generalbox');
282 $output .= $this->footer();
283
284 return $output;
285 }
286
cc359566
TH
287 /**
288 * Display the plugin management page (admin/environment.php).
8d1da748
PS
289 * @param array $versions
290 * @param string $version
291 * @param boolean $envstatus final result of env check (true/false)
292 * @param array $environment_results array of results gathered
cc359566
TH
293 * @return string HTML to output.
294 */
295 public function environment_check_page($versions, $version, $envstatus, $environment_results) {
296 $output = '';
297 $output .= $this->header();
298
299 // Print the component download link
300 $output .= html_writer::tag('div', html_writer::link(
301 new moodle_url('/admin/environment.php', array('action' => 'updatecomponent', 'sesskey' => sesskey())),
302 get_string('updatecomponent', 'admin')),
303 array('class' => 'reportlink'));
304
305 // Heading.
306 $output .= $this->heading(get_string('environment', 'admin'));
307
308 // Box with info and a menu to choose the version.
309 $output .= $this->box_start();
310 $output .= html_writer::tag('div', get_string('adminhelpenvironment'));
311 $select = new single_select(new moodle_url('/admin/environment.php'), 'version', $versions, $version, null);
312 $select->label = get_string('moodleversion');
313 $output .= $this->render($select);
314 $output .= $this->box_end();
315
316 // The results
317 $output .= $this->environment_check_table($envstatus, $environment_results);
318
319 $output .= $this->footer();
320 return $output;
321 }
322
323 /**
324 * Output a warning message, of the type that appears on the admin notifications page.
325 * @param string $message the message to display.
8d1da748 326 * @param string $type type class
cc359566
TH
327 * @return string HTML to output.
328 */
329 protected function warning($message, $type = 'warning') {
330 return $this->box($message, 'generalbox admin' . $type);
331 }
332
333 /**
334 * Render an appropriate message if dataroot is insecure.
8d1da748 335 * @param bool $insecuredataroot
cc359566
TH
336 * @return string HTML to output.
337 */
338 protected function insecure_dataroot_warning($insecuredataroot) {
339 global $CFG;
340
341 if ($insecuredataroot == INSECURE_DATAROOT_WARNING) {
342 return $this->warning(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot));
343
344 } else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) {
345 return $this->warning(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'error');
346
347 } else {
348 return '';
349 }
350 }
351
352 /**
353 * Render an appropriate message if dataroot is insecure.
8d1da748 354 * @param bool $errorsdisplayed
cc359566
TH
355 * @return string HTML to output.
356 */
357 protected function display_errors_warning($errorsdisplayed) {
358 if (!$errorsdisplayed) {
359 return '';
360 }
361
362 return $this->warning(get_string('displayerrorswarning', 'admin'));
363 }
364
365 /**
366 * Render an appropriate message if cron has not been run recently.
8d1da748 367 * @param bool $cronoverdue
cc359566
TH
368 * @return string HTML to output.
369 */
370 public function cron_overdue_warning($cronoverdue) {
371 if (!$cronoverdue) {
372 return '';
373 }
374
375 return $this->warning(get_string('cronwarning', 'admin') . '&nbsp;' .
376 $this->help_icon('cron', 'admin'));
377 }
378
379 /**
380 * Render an appropriate message if there are any problems with the DB set-up.
8d1da748 381 * @param bool $dbproblems
cc359566
TH
382 * @return string HTML to output.
383 */
384 public function db_problems($dbproblems) {
385 if (!$dbproblems) {
386 return '';
387 }
388
389 return $this->warning($dbproblems);
390 }
391
392 /**
393 * Render an appropriate message if the site in in maintenance mode.
8d1da748 394 * @param bool $maintenancemode
cc359566
TH
395 * @return string HTML to output.
396 */
397 public function maintenance_mode_warning($maintenancemode) {
398 if (!$maintenancemode) {
399 return '';
400 }
401
ecc2897c
PS
402 $url = new moodle_url('/admin/settings.php', array('section' => 'maintenancemode'));
403 $url = $url->out(); // get_string() does not support objects in params
404
405 return $this->warning(get_string('sitemaintenancewarning2', 'admin', $url));
cc359566
TH
406 }
407
408 /**
409 * Display a warning about installing development code if necesary.
8d1da748 410 * @param int $maturity
cc359566
TH
411 * @return string HTML to output.
412 */
413 protected function maturity_warning($maturity) {
414 if ($maturity == MATURITY_STABLE) {
415 return ''; // No worries.
416 }
417
418 $maturitylevel = get_string('maturity' . $maturity, 'admin');
419 return $this->box(
420 $this->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
421 $this->container($this->doc_link('admin/versions', get_string('morehelp'))),
422 'generalbox maturitywarning');
423 }
424
425 /**
426 * Output the copyright notice.
427 * @return string HTML to output.
428 */
429 protected function moodle_copyright() {
430 global $CFG;
431
432 //////////////////////////////////////////////////////////////////////////////////////////////////
433 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
434 $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
435 '<a href="http://docs.moodle.org/dev/Releases" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
436 'Copyright &copy; 1999 onwards, Martin Dougiamas<br />'.
437 'and <a href="http://docs.moodle.org/dev/Credits">many other contributors</a>.<br />'.
438 '<a href="http://docs.moodle.org/dev/License">GNU Public License</a>';
439 //////////////////////////////////////////////////////////////////////////////////////////////////
440
441 return $this->box($copyrighttext, 'copyright');
442 }
443
444 /**
445 * Display a warning about installing development code if necesary.
8d1da748
PS
446 * @param int $maturity
447 * @return string HTML to output.
cc359566
TH
448 */
449 protected function maturity_info($maturity) {
450 if ($maturity == MATURITY_STABLE) {
451 return ''; // No worries.
452 }
453
454 $maturitylevel = get_string('maturity' . $maturity, 'admin');
455 return $this->box(
456 get_string('maturitycoreinfo', 'admin', $maturitylevel) . ' ' .
457 $this->doc_link('admin/versions', get_string('morehelp')),
37f75ad4 458 'generalbox adminwarning maturityinfo maturity'.$maturity);
cc359566
TH
459 }
460
55585f3a
DM
461 /**
462 * Displays the info about available Moodle updates
463 *
464 * @param array|null $updates array of available_update_info objects or null
465 * @param int|null $fetch timestamp of the most recent updates fetch or null (unknown)
466 * @return string
467 */
468 protected function available_updates($updates, $fetch) {
469
470 $updateinfo = $this->box_start('generalbox adminwarning availableupdatesinfo');
471 if (is_array($updates)) {
472 $updateinfo .= $this->heading(get_string('updateavailable', 'core_admin'), 3);
473 foreach ($updates as $update) {
474 $updateinfo .= $this->moodle_available_update_info($update);
475 }
476 } else {
cb1c3291
DM
477 $now = time();
478 if ($fetch and ($fetch <= $now) and ($now - $fetch < HOURSECS)) {
479 $updateinfo .= $this->heading(get_string('updateavailablenot', 'core_admin'), 3);
480 }
55585f3a
DM
481 }
482
483 $updateinfo .= $this->container_start('checkforupdates');
484 $updateinfo .= $this->single_button(new moodle_url($this->page->url, array('fetchupdates' => 1)), get_string('checkforupdates', 'core_plugin'));
485 if ($fetch) {
486 $updateinfo .= $this->container(get_string('checkforupdateslast', 'core_plugin',
487 userdate($fetch, get_string('strftimedatetime', 'core_langconfig'))));
488 }
489 $updateinfo .= $this->container_end();
490
491 $updateinfo .= $this->box_end();
492
493 return $updateinfo;
494 }
495
496 /**
497 * Helper method to render the information about the available Moodle update
498 *
499 * @param available_update_info $updateinfo information about the available Moodle core update
500 */
501 protected function moodle_available_update_info(available_update_info $updateinfo) {
502
503 $boxclasses = 'moodleupdateinfo';
504 $info = array();
505
506 if (isset($updateinfo->release)) {
507 $info[] = html_writer::tag('span', get_string('updateavailable_release', 'core_admin', $updateinfo->release),
508 array('class' => 'info release'));
509 }
510
511 if (isset($updateinfo->version)) {
512 $info[] = html_writer::tag('span', get_string('updateavailable_version', 'core_admin', $updateinfo->version),
513 array('class' => 'info version'));
514 }
515
516 if (isset($updateinfo->maturity)) {
517 $info[] = html_writer::tag('span', get_string('maturity'.$updateinfo->maturity, 'core_admin'),
518 array('class' => 'info maturity'));
519 $boxclasses .= ' maturity'.$updateinfo->maturity;
520 }
521
522 if (isset($updateinfo->download)) {
523 $info[] = html_writer::link($updateinfo->download, get_string('download'), array('class' => 'info download'));
524 }
525
526 if (isset($updateinfo->url)) {
527 $info[] = html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin'),
528 array('class' => 'info more'));
529 }
530
531 $box = $this->output->box_start($boxclasses);
532 $box .= $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $info), '');
533 $box .= $this->output->box_end();
534
535 return $box;
536 }
537
cc359566
TH
538 /**
539 * Display a link to the release notes.
8d1da748 540 * @return string HTML to output.
cc359566
TH
541 */
542 protected function release_notes_link() {
543 $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/dev/Releases');
544 $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
545 return $this->box($releasenoteslink, 'generalbox releasenoteslink');
546 }
547
548 /**
549 * Display the reload link that appears on several upgrade/install pages.
8d1da748 550 * @return string HTML to output.
cc359566
TH
551 */
552 function upgrade_reload($url) {
553 return html_writer::empty_tag('br') .
554 html_writer::tag('div',
555 html_writer::link($url, $this->pix_icon('i/reload', '') .
556 get_string('reload'), array('title' => get_string('reload'))),
557 array('class' => 'continuebutton')) . html_writer::empty_tag('br');
558 }
559
b9934a17
DM
560 /**
561 * Displays all known plugins and information about their installation or upgrade
562 *
563 * This default implementation renders all plugins into one big table. The rendering
564 * options support:
565 * (bool)full = false: whether to display up-to-date plugins, too
566 *
36ca62ca 567 * @param plugin_manager $pluginman provides information about the plugins.
faadd326 568 * @param int $version the version of the Moodle code from version.php.
b9934a17
DM
569 * @param array $options rendering options
570 * @return string HTML code
571 */
faadd326 572 public function plugins_check_table(plugin_manager $pluginman, $version, array $options = null) {
fa1d403f
DM
573 global $CFG;
574
36ca62ca 575 $plugininfo = $pluginman->get_plugins();
b9934a17
DM
576
577 if (empty($plugininfo)) {
578 return '';
579 }
580
581 if (empty($options)) {
582 $options = array(
583 'full' => false,
584 );
585 }
586
b9934a17
DM
587 $table = new html_table();
588 $table->id = 'plugins-check';
589 $table->head = array(
590 get_string('displayname', 'core_plugin'),
591 get_string('rootdir', 'core_plugin'),
592 get_string('source', 'core_plugin'),
593 get_string('versiondb', 'core_plugin'),
594 get_string('versiondisk', 'core_plugin'),
36ca62ca 595 get_string('requires', 'core_plugin'),
b9934a17
DM
596 get_string('status', 'core_plugin'),
597 );
598 $table->colclasses = array(
36ca62ca 599 'displayname', 'rootdir', 'source', 'versiondb', 'versiondisk', 'requires', 'status',
b9934a17
DM
600 );
601 $table->data = array();
602
603 $numofhighlighted = array(); // number of highlighted rows per this subsection
604
605 foreach ($plugininfo as $type => $plugins) {
606
607 $header = new html_table_cell($pluginman->plugintype_name_plural($type));
608 $header->header = true;
609 $header->colspan = count($table->head);
610 $header = new html_table_row(array($header));
611 $header->attributes['class'] = 'plugintypeheader type-' . $type;
612
613 $numofhighlighted[$type] = 0;
614
615 if (empty($plugins) and $options['full']) {
616 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
617 $msg->colspan = count($table->head);
618 $row = new html_table_row(array($msg));
619 $row->attributes['class'] .= 'msg msg-noneinstalled';
620 $table->data[] = $header;
621 $table->data[] = $row;
622 continue;
623 }
624
625 $plugintyperows = array();
626
627 foreach ($plugins as $name => $plugin) {
628 $row = new html_table_row();
629 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
630
631 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) {
632 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
633 } else {
634 $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon'));
635 }
636 $displayname = $icon . ' ' . $plugin->displayname;
637 $displayname = new html_table_cell($displayname);
638
639 $rootdir = new html_table_cell($plugin->get_dir());
640
641 if ($isstandard = $plugin->is_standard()) {
642 $row->attributes['class'] .= ' standard';
643 $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
644 } else {
645 $row->attributes['class'] .= ' extension';
646 $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
647 }
648
649 $versiondb = new html_table_cell($plugin->versiondb);
650 $versiondisk = new html_table_cell($plugin->versiondisk);
651
652 $statuscode = $plugin->get_status();
653 $row->attributes['class'] .= ' status-' . $statuscode;
96dd9237
DM
654 $status = get_string('status_' . $statuscode, 'core_plugin');
655
656 $availableupdates = $plugin->available_updates();
fa1d403f 657 if (!empty($availableupdates) and empty($CFG->disableupdatenotifications)) {
96dd9237
DM
658 foreach ($availableupdates as $availableupdate) {
659 $status .= $this->plugin_available_update_info($availableupdate);
660 }
661 }
b9934a17 662
96dd9237 663 $status = new html_table_cell($status);
b9934a17 664
faadd326 665 $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version));
36ca62ca
TH
666
667 $statusisboring = in_array($statuscode, array(
668 plugin_manager::PLUGIN_STATUS_NODB, plugin_manager::PLUGIN_STATUS_UPTODATE));
777781d1 669 $dependenciesok = $pluginman->are_dependencies_satisfied(
36ca62ca 670 $plugin->get_other_required_plugins());
96dd9237 671 if ($isstandard and $statusisboring and $dependenciesok and empty($availableupdates)) {
b9934a17
DM
672 if (empty($options['full'])) {
673 continue;
674 }
675 } else {
676 $numofhighlighted[$type]++;
677 }
678
36ca62ca
TH
679 $row->cells = array($displayname, $rootdir, $source,
680 $versiondb, $versiondisk, $requires, $status);
b9934a17
DM
681 $plugintyperows[] = $row;
682 }
683
684 if (empty($numofhighlighted[$type]) and empty($options['full'])) {
685 continue;
686 }
687
688 $table->data[] = $header;
689 $table->data = array_merge($table->data, $plugintyperows);
690 }
691
692 $sumofhighlighted = array_sum($numofhighlighted);
693
694 if ($sumofhighlighted == 0) {
695 $out = $this->output->container_start('nonehighlighted', 'plugins-check-info');
696 $out .= $this->output->heading(get_string('nonehighlighted', 'core_plugin'));
697 if (empty($options['full'])) {
698 $out .= html_writer::link(new moodle_url('/admin/index.php',
699 array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1)),
700 get_string('nonehighlightedinfo', 'core_plugin'));
701 }
702 $out .= $this->output->container_end();
703
704 } else {
705 $out = $this->output->container_start('somehighlighted', 'plugins-check-info');
706 $out .= $this->output->heading(get_string('somehighlighted', 'core_plugin', $sumofhighlighted));
707 if (empty($options['full'])) {
708 $out .= html_writer::link(new moodle_url('/admin/index.php',
709 array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1)),
710 get_string('somehighlightedinfo', 'core_plugin'));
a687fcac
DM
711 } else {
712 $out .= html_writer::link(new moodle_url('/admin/index.php',
713 array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 0)),
714 get_string('somehighlightedonly', 'core_plugin'));
b9934a17
DM
715 }
716 $out .= $this->output->container_end();
717 }
718
719 if ($sumofhighlighted > 0 or $options['full']) {
720 $out .= html_writer::table($table);
721 }
722
723 return $out;
724 }
725
36ca62ca
TH
726 /**
727 * Formats the information that needs to go in the 'Requires' column.
b6ad8594 728 * @param plugininfo_base $plugin the plugin we are rendering the row for.
36ca62ca 729 * @param plugin_manager $pluginman provides data on all the plugins.
8d1da748
PS
730 * @param string $version
731 * @return string HTML code
36ca62ca 732 */
b6ad8594 733 protected function required_column(plugininfo_base $plugin, plugin_manager $pluginman, $version) {
36ca62ca
TH
734 $requires = array();
735
736 if (!empty($plugin->versionrequires)) {
faadd326 737 if ($plugin->versionrequires <= $version) {
36ca62ca
TH
738 $class = 'requires-ok';
739 } else {
740 $class = 'requires-failed';
741 }
742 $requires[] = html_writer::tag('li',
743 get_string('moodleversion', 'core_plugin', $plugin->versionrequires),
744 array('class' => $class));
745 }
746
747 foreach ($plugin->get_other_required_plugins() as $component => $requiredversion) {
748 $ok = true;
749 $otherplugin = $pluginman->get_plugin_info($component);
750
751 if (is_null($otherplugin)) {
752 $ok = false;
499ff0a9 753 } else if ($requiredversion != ANY_VERSION and $otherplugin->versiondisk < $requiredversion) {
36ca62ca
TH
754 $ok = false;
755 }
756
757 if ($ok) {
758 $class = 'requires-ok';
759 } else {
760 $class = 'requires-failed';
761 }
762
763 if ($requiredversion != ANY_VERSION) {
764 $str = 'otherpluginversion';
765 } else {
766 $str = 'otherplugin';
767 }
768 $requires[] = html_writer::tag('li',
769 get_string($str, 'core_plugin',
770 array('component' => $component, 'version' => $requiredversion)),
771 array('class' => $class));
772 }
773
774 if (!$requires) {
775 return '';
776 }
777 return html_writer::tag('ul', implode("\n", $requires));
778 }
779
d26f3ddd
DM
780 /**
781 * Prints an overview about the plugins - number of installed, number of extensions etc.
782 *
783 * @param plugin_manager $pluginman provides information about the plugins
784 * @return string as usually
785 */
786 public function plugins_overview_panel(plugin_manager $pluginman) {
7716057f
DM
787 global $CFG;
788
d26f3ddd
DM
789 $plugininfo = $pluginman->get_plugins();
790
791 $numtotal = $numdisabled = $numextension = $numupdatable = 0;
792
793 foreach ($plugininfo as $type => $plugins) {
794 foreach ($plugins as $name => $plugin) {
795 if ($plugin->get_status() === plugin_manager::PLUGIN_STATUS_MISSING) {
796 continue;
797 }
798 $numtotal++;
799 if ($plugin->is_enabled() === false) {
800 $numdisabled++;
801 }
802 if (!$plugin->is_standard()) {
803 $numextension++;
804 }
7716057f 805 if (empty($CFG->disableupdatenotifications) and $plugin->available_updates()) {
d26f3ddd
DM
806 $numupdatable++;
807 }
808 }
809 }
810
811 $info = array();
812 $info[] = html_writer::tag('span', get_string('numtotal', 'core_plugin', $numtotal), array('class' => 'info total'));
813 $info[] = html_writer::tag('span', get_string('numdisabled', 'core_plugin', $numdisabled), array('class' => 'info disabled'));
814 $info[] = html_writer::tag('span', get_string('numextension', 'core_plugin', $numextension), array('class' => 'info extension'));
815 if ($numupdatable > 0) {
816 $info[] = html_writer::tag('span', get_string('numupdatable', 'core_plugin', $numupdatable), array('class' => 'info updatable'));
817 }
818
819 return $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $info), '', 'plugins-overview-panel');
820 }
821
b9934a17
DM
822 /**
823 * Displays all known plugins and links to manage them
824 *
825 * This default implementation renders all plugins into one big table.
826 *
36ca62ca 827 * @param plugin_manager $pluginman provides information about the plugins.
b9934a17
DM
828 * @return string HTML code
829 */
36ca62ca 830 public function plugins_control_panel(plugin_manager $pluginman) {
7716057f
DM
831 global $CFG;
832
36ca62ca 833 $plugininfo = $pluginman->get_plugins();
b9934a17
DM
834
835 if (empty($plugininfo)) {
836 return '';
837 }
838
b9934a17
DM
839 $table = new html_table();
840 $table->id = 'plugins-control-panel';
841 $table->head = array(
842 get_string('displayname', 'core_plugin'),
b9934a17
DM
843 get_string('source', 'core_plugin'),
844 get_string('version', 'core_plugin'),
845 get_string('availability', 'core_plugin'),
2b135b05
DM
846 get_string('actions', 'core_plugin'),
847 get_string('notes','core_plugin'),
b9934a17
DM
848 );
849 $table->colclasses = array(
2b135b05 850 'pluginname', 'source', 'version', 'availability', 'actions', 'notes'
b9934a17
DM
851 );
852
853 foreach ($plugininfo as $type => $plugins) {
854
855 $header = new html_table_cell($pluginman->plugintype_name_plural($type));
856 $header->header = true;
857 $header->colspan = count($table->head);
858 $header = new html_table_row(array($header));
859 $header->attributes['class'] = 'plugintypeheader type-' . $type;
860 $table->data[] = $header;
861
862 if (empty($plugins)) {
863 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
864 $msg->colspan = count($table->head);
865 $row = new html_table_row(array($msg));
866 $row->attributes['class'] .= 'msg msg-noneinstalled';
867 $table->data[] = $row;
868 continue;
869 }
870
871 foreach ($plugins as $name => $plugin) {
872 $row = new html_table_row();
873 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
874
875 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) {
876 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
877 } else {
878 $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon'));
879 }
880 if ($plugin->get_status() === plugin_manager::PLUGIN_STATUS_MISSING) {
881 $msg = html_writer::tag('span', get_string('status_missing', 'core_plugin'), array('class' => 'notifyproblem'));
882 $row->attributes['class'] .= ' missingfromdisk';
883 } else {
884 $msg = '';
885 }
2b135b05
DM
886 $pluginname = html_writer::tag('div', $icon . ' ' . $plugin->displayname . ' ' . $msg, array('class' => 'displayname')).
887 html_writer::tag('div', $plugin->component, array('class' => 'componentname'));
888 $pluginname = new html_table_cell($pluginname);
b9934a17
DM
889
890 if ($plugin->is_standard()) {
891 $row->attributes['class'] .= ' standard';
892 $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
893 } else {
894 $row->attributes['class'] .= ' extension';
895 $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
896 }
897
898 $version = new html_table_cell($plugin->versiondb);
899
900 $isenabled = $plugin->is_enabled();
901 if (is_null($isenabled)) {
902 $availability = new html_table_cell('');
903 } else if ($isenabled) {
904 $row->attributes['class'] .= ' enabled';
905 $icon = $this->output->pix_icon('i/hide', get_string('pluginenabled', 'core_plugin'));
906 $availability = new html_table_cell($icon . ' ' . get_string('pluginenabled', 'core_plugin'));
907 } else {
908 $row->attributes['class'] .= ' disabled';
909 $icon = $this->output->pix_icon('i/show', get_string('plugindisabled', 'core_plugin'));
910 $availability = new html_table_cell($icon . ' ' . get_string('plugindisabled', 'core_plugin'));
911 }
912
2b135b05
DM
913 $actions = array();
914
b9934a17 915 $settingsurl = $plugin->get_settings_url();
2b135b05
DM
916 if (!is_null($settingsurl)) {
917 $actions[] = html_writer::link($settingsurl, get_string('settings', 'core_plugin'), array('class' => 'settings'));
b9934a17
DM
918 }
919
920 $uninstallurl = $plugin->get_uninstall_url();
2b135b05
DM
921 if (!is_null($uninstallurl)) {
922 $actions[] = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin'), array('class' => 'uninstall'));
923 }
924
925 $actions = new html_table_cell(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $actions));
926
828788f0 927 $requriedby = $pluginman->other_plugins_that_require($plugin->component);
2b135b05
DM
928 if ($requriedby) {
929 $requiredby = html_writer::tag('div', get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
930 array('class' => 'requiredby'));
b9934a17 931 } else {
2b135b05 932 $requiredby = '';
b9934a17
DM
933 }
934
7d8de6d8 935 $updateinfo = '';
7716057f 936 if (empty($CFG->disableupdatenotifications) and is_array($plugin->available_updates())) {
7d8de6d8
DM
937 foreach ($plugin->available_updates() as $availableupdate) {
938 $updateinfo .= $this->plugin_available_update_info($availableupdate);
939 }
3204daea
DM
940 }
941
942 $notes = new html_table_cell($requiredby.$updateinfo);
2b135b05 943
b9934a17 944 $row->cells = array(
2b135b05 945 $pluginname, $source, $version, $availability, $actions, $notes
b9934a17
DM
946 );
947 $table->data[] = $row;
948 }
949 }
950
951 return html_writer::table($table);
952 }
da2fdc3f 953
3204daea 954 /**
e7611389 955 * Helper method to render the information about the available plugin update
3204daea
DM
956 *
957 * The passed objects always provides at least the 'version' property containing
7d8de6d8 958 * the (higher) version of the plugin available.
3204daea 959 *
7d8de6d8 960 * @param available_update_info $updateinfo information about the available update for the plugin
3204daea 961 */
7d8de6d8 962 protected function plugin_available_update_info(available_update_info $updateinfo) {
3204daea 963
e7611389 964 $boxclasses = 'pluginupdateinfo';
3204daea
DM
965 $info = array();
966
967 if (isset($updateinfo->release)) {
968 $info[] = html_writer::tag('span', get_string('updateavailable_release', 'core_plugin', $updateinfo->release),
969 array('class' => 'info release'));
970 }
971
972 if (isset($updateinfo->maturity)) {
973 $info[] = html_writer::tag('span', get_string('maturity'.$updateinfo->maturity, 'core_admin'),
974 array('class' => 'info maturity'));
e7611389 975 $boxclasses .= ' maturity'.$updateinfo->maturity;
3204daea
DM
976 }
977
978 if (isset($updateinfo->download)) {
979 $info[] = html_writer::link($updateinfo->download, get_string('download'), array('class' => 'info download'));
980 }
981
982 if (isset($updateinfo->url)) {
983 $info[] = html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin'),
984 array('class' => 'info more'));
985 }
986
e7611389
DM
987 $box = $this->output->box_start($boxclasses);
988 $box .= html_writer::tag('div', get_string('updateavailable', 'core_plugin', $updateinfo->version), array('class' => 'version'));
989 $box .= $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $info), '');
3204daea
DM
990 $box .= $this->output->box_end();
991
992 return $box;
993 }
994
da2fdc3f 995 /**
cc359566
TH
996 * This function will render one beautiful table with all the environmental
997 * configuration and how it suits Moodle needs.
998 *
999 * @param boolean $result final result of the check (true/false)
1000 * @param array $environment_results array of results gathered
1001 * @return string HTML to output.
da2fdc3f 1002 */
cc359566
TH
1003 public function environment_check_table($result, $environment_results) {
1004 global $CFG;
1005
1006 // Table headers
1007 $servertable = new html_table();//table for server checks
1008 $servertable->head = array(
1009 get_string('name'),
1010 get_string('info'),
1011 get_string('report'),
1012 get_string('status'),
1013 );
1014 $servertable->align = array('center', 'center', 'left', 'center');
1015 $servertable->wrap = array('nowrap', '', '', 'nowrap');
1016 $servertable->size = array('10', 10, '100%', '10');
1017 $servertable->attributes['class'] = 'environmenttable generaltable';
1018
1019 $serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
1020
1021 $othertable = new html_table();//table for custom checks
1022 $othertable->head = array(
1023 get_string('info'),
1024 get_string('report'),
1025 get_string('status'),
1026 );
1027 $othertable->align = array('center', 'left', 'center');
1028 $othertable->wrap = array('', '', 'nowrap');
1029 $othertable->size = array(10, '100%', '10');
1030 $othertable->attributes['class'] = 'environmenttable generaltable';
1031
1032 $otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
1033
1034 // Iterate over each environment_result
1035 $continue = true;
1036 foreach ($environment_results as $environment_result) {
1037 $errorline = false;
1038 $warningline = false;
1039 $stringtouse = '';
1040 if ($continue) {
1041 $type = $environment_result->getPart();
1042 $info = $environment_result->getInfo();
1043 $status = $environment_result->getStatus();
1044 $error_code = $environment_result->getErrorCode();
1045 // Process Report field
1046 $rec = new stdClass();
1047 // Something has gone wrong at parsing time
1048 if ($error_code) {
1049 $stringtouse = 'environmentxmlerror';
1050 $rec->error_code = $error_code;
1051 $status = get_string('error');
1052 $errorline = true;
1053 $continue = false;
1054 }
1055
1056 if ($continue) {
1057 if ($rec->needed = $environment_result->getNeededVersion()) {
1058 // We are comparing versions
1059 $rec->current = $environment_result->getCurrentVersion();
1060 if ($environment_result->getLevel() == 'required') {
1061 $stringtouse = 'environmentrequireversion';
1062 } else {
1063 $stringtouse = 'environmentrecommendversion';
1064 }
1065
1066 } else if ($environment_result->getPart() == 'custom_check') {
1067 // We are checking installed & enabled things
1068 if ($environment_result->getLevel() == 'required') {
1069 $stringtouse = 'environmentrequirecustomcheck';
1070 } else {
1071 $stringtouse = 'environmentrecommendcustomcheck';
1072 }
1073
1074 } else if ($environment_result->getPart() == 'php_setting') {
1075 if ($status) {
1076 $stringtouse = 'environmentsettingok';
1077 } else if ($environment_result->getLevel() == 'required') {
1078 $stringtouse = 'environmentmustfixsetting';
1079 } else {
1080 $stringtouse = 'environmentshouldfixsetting';
1081 }
1082
1083 } else {
1084 if ($environment_result->getLevel() == 'required') {
1085 $stringtouse = 'environmentrequireinstall';
1086 } else {
1087 $stringtouse = 'environmentrecommendinstall';
1088 }
1089 }
1090
1091 // Calculate the status value
1092 if ($environment_result->getBypassStr() != '') { //Handle bypassed result (warning)
1093 $status = get_string('bypassed');
1094 $warningline = true;
1095 } else if ($environment_result->getRestrictStr() != '') { //Handle restricted result (error)
1096 $status = get_string('restricted');
1097 $errorline = true;
1098 } else {
1099 if ($status) { //Handle ok result (ok)
1100 $status = get_string('ok');
1101 } else {
1102 if ($environment_result->getLevel() == 'optional') {//Handle check result (warning)
1103 $status = get_string('check');
1104 $warningline = true;
1105 } else { //Handle error result (error)
1106 $status = get_string('check');
1107 $errorline = true;
1108 }
1109 }
1110 }
1111 }
1112
1113 // Build the text
1114 $linkparts = array();
1115 $linkparts[] = 'admin/environment';
1116 $linkparts[] = $type;
1117 if (!empty($info)){
1118 $linkparts[] = $info;
1119 }
1120 if (empty($CFG->docroot)) {
1121 $report = get_string($stringtouse, 'admin', $rec);
1122 } else {
1123 $report = $this->doc_link(join($linkparts, '/'), get_string($stringtouse, 'admin', $rec));
1124 }
1125
1126 // Format error or warning line
1127 if ($errorline || $warningline) {
1128 $messagetype = $errorline? 'error':'warn';
1129 } else {
1130 $messagetype = 'ok';
1131 }
1132 $status = '<span class="'.$messagetype.'">'.$status.'</span>';
1133 // Here we'll store all the feedback found
1134 $feedbacktext = '';
1135 // Append the feedback if there is some
1136 $feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), $messagetype);
1137 //Append the bypass if there is some
1138 $feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'warn');
1139 //Append the restrict if there is some
1140 $feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'error');
1141
1142 $report .= $feedbacktext;
1143
1144 // Add the row to the table
1145 if ($environment_result->getPart() == 'custom_check'){
1146 $otherdata[$messagetype][] = array ($info, $report, $status);
1147 } else {
1148 $serverdata[$messagetype][] = array ($type, $info, $report, $status);
1149 }
1150 }
1151 }
1152
1153 //put errors first in
1154 $servertable->data = array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']);
1155 $othertable->data = array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']);
1156
1157 // Print table
1158 $output = '';
1159 $output .= $this->heading(get_string('serverchecks', 'admin'));
1160 $output .= html_writer::table($servertable);
1161 if (count($othertable->data)){
1162 $output .= $this->heading(get_string('customcheck', 'admin'));
1163 $output .= html_writer::table($othertable);
1164 }
1165
1166 // Finally, if any error has happened, print the summary box
1167 if (!$result) {
1168 $output .= $this->box(get_string('environmenterrortodo', 'admin'), 'environmentbox errorbox');
1169 }
1170
1171 return $output;
da2fdc3f 1172 }
b9934a17 1173}