MDL-20438 Refactoring pluginlib before adding anything new
[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
PS
167 * @param plugin_manager $pluginman provides information about the plugins.
168 * @param int $version the version of the Moodle code from version.php.
169 * @param bool $showallplugins
170 * @param moodle_url $reloadurl
171 * @param moodle_url $continueurl
cc359566
TH
172 * @return string HTML to output.
173 */
8d1da748 174 public function upgrade_plugin_check_page(plugin_manager $pluginman, $version, $showallplugins, $reloadurl, $continueurl) {
cc359566
TH
175 $output = '';
176
177 $output .= $this->header();
178 $output .= $this->box_start('generalbox');
179 $output .= $this->container(get_string('pluginchecknotice', 'core_plugin'), 'generalbox', 'notice');
faadd326 180 $output .= $this->plugins_check_table($pluginman, $version, array('full' => $showallplugins));
cc359566
TH
181 $output .= $this->box_end();
182 $output .= $this->upgrade_reload($reloadurl);
183
faadd326
TH
184 if ($pluginman->all_plugins_ok($version)) {
185 $button = new single_button($continueurl, get_string('upgradestart', 'admin'), 'get');
186 $button->class = 'continuebutton';
187 $output .= $this->render($button);
188 } else {
189 $output .= $this->box(get_string('pluginschecktodo', 'admin'), 'environmentbox errorbox');
190 }
cc359566
TH
191
192 $output .= $this->footer();
193
194 return $output;
195 }
196
197 /**
198 * Display the admin notifications page.
8d1da748
PS
199 * @param int $maturity
200 * @param bool $insecuredataroot warn dataroot is invalid
201 * @param bool $errorsdisplayed warn invalid dispaly error setting
202 * @param bool $cronoverdue warn cron not running
203 * @param bool $dbproblems warn db has problems
204 * @param bool $maintenancemode warn in maintenance mode
cc359566
TH
205 * @return string HTML to output.
206 */
207 public function admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed,
208 $cronoverdue, $dbproblems, $maintenancemode) {
209 $output = '';
210
211 $output .= $this->header();
212 $output .= $this->maturity_info($maturity);
213 $output .= $this->insecure_dataroot_warning($insecuredataroot);
214 $output .= $this->display_errors_warning($errorsdisplayed);
e3258164 215 $output .= $this->cron_overdue_warning($cronoverdue);
cc359566
TH
216 $output .= $this->db_problems($dbproblems);
217 $output .= $this->maintenance_mode_warning($maintenancemode);
218
219 //////////////////////////////////////////////////////////////////////////////////////////////////
220 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
221 $output .= $this->moodle_copyright();
222 //////////////////////////////////////////////////////////////////////////////////////////////////
223
224 $output .= $this->footer();
225
226 return $output;
227 }
228
229 /**
230 * Display the plugin management page (admin/plugins.php).
8d1da748 231 * @param plugin_manager $pluginman
cc359566
TH
232 * @return string HTML to output.
233 */
8d1da748 234 public function plugin_management_page(plugin_manager $pluginman) {
cc359566
TH
235 $output = '';
236
237 $output .= $this->header();
238 $output .= $this->heading(get_string('pluginsoverview', 'core_admin'));
239 $output .= $this->box_start('generalbox');
240 $output .= $this->plugins_control_panel($pluginman);
241 $output .= $this->box_end();
242 $output .= $this->footer();
243
244 return $output;
245 }
246
247 /**
248 * Display the plugin management page (admin/environment.php).
8d1da748
PS
249 * @param array $versions
250 * @param string $version
251 * @param boolean $envstatus final result of env check (true/false)
252 * @param array $environment_results array of results gathered
cc359566
TH
253 * @return string HTML to output.
254 */
255 public function environment_check_page($versions, $version, $envstatus, $environment_results) {
256 $output = '';
257 $output .= $this->header();
258
259 // Print the component download link
260 $output .= html_writer::tag('div', html_writer::link(
261 new moodle_url('/admin/environment.php', array('action' => 'updatecomponent', 'sesskey' => sesskey())),
262 get_string('updatecomponent', 'admin')),
263 array('class' => 'reportlink'));
264
265 // Heading.
266 $output .= $this->heading(get_string('environment', 'admin'));
267
268 // Box with info and a menu to choose the version.
269 $output .= $this->box_start();
270 $output .= html_writer::tag('div', get_string('adminhelpenvironment'));
271 $select = new single_select(new moodle_url('/admin/environment.php'), 'version', $versions, $version, null);
272 $select->label = get_string('moodleversion');
273 $output .= $this->render($select);
274 $output .= $this->box_end();
275
276 // The results
277 $output .= $this->environment_check_table($envstatus, $environment_results);
278
279 $output .= $this->footer();
280 return $output;
281 }
282
283 /**
284 * Output a warning message, of the type that appears on the admin notifications page.
285 * @param string $message the message to display.
8d1da748 286 * @param string $type type class
cc359566
TH
287 * @return string HTML to output.
288 */
289 protected function warning($message, $type = 'warning') {
290 return $this->box($message, 'generalbox admin' . $type);
291 }
292
293 /**
294 * Render an appropriate message if dataroot is insecure.
8d1da748 295 * @param bool $insecuredataroot
cc359566
TH
296 * @return string HTML to output.
297 */
298 protected function insecure_dataroot_warning($insecuredataroot) {
299 global $CFG;
300
301 if ($insecuredataroot == INSECURE_DATAROOT_WARNING) {
302 return $this->warning(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot));
303
304 } else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) {
305 return $this->warning(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'error');
306
307 } else {
308 return '';
309 }
310 }
311
312 /**
313 * Render an appropriate message if dataroot is insecure.
8d1da748 314 * @param bool $errorsdisplayed
cc359566
TH
315 * @return string HTML to output.
316 */
317 protected function display_errors_warning($errorsdisplayed) {
318 if (!$errorsdisplayed) {
319 return '';
320 }
321
322 return $this->warning(get_string('displayerrorswarning', 'admin'));
323 }
324
325 /**
326 * Render an appropriate message if cron has not been run recently.
8d1da748 327 * @param bool $cronoverdue
cc359566
TH
328 * @return string HTML to output.
329 */
330 public function cron_overdue_warning($cronoverdue) {
331 if (!$cronoverdue) {
332 return '';
333 }
334
335 return $this->warning(get_string('cronwarning', 'admin') . '&nbsp;' .
336 $this->help_icon('cron', 'admin'));
337 }
338
339 /**
340 * Render an appropriate message if there are any problems with the DB set-up.
8d1da748 341 * @param bool $dbproblems
cc359566
TH
342 * @return string HTML to output.
343 */
344 public function db_problems($dbproblems) {
345 if (!$dbproblems) {
346 return '';
347 }
348
349 return $this->warning($dbproblems);
350 }
351
352 /**
353 * Render an appropriate message if the site in in maintenance mode.
8d1da748 354 * @param bool $maintenancemode
cc359566
TH
355 * @return string HTML to output.
356 */
357 public function maintenance_mode_warning($maintenancemode) {
358 if (!$maintenancemode) {
359 return '';
360 }
361
ecc2897c
PS
362 $url = new moodle_url('/admin/settings.php', array('section' => 'maintenancemode'));
363 $url = $url->out(); // get_string() does not support objects in params
364
365 return $this->warning(get_string('sitemaintenancewarning2', 'admin', $url));
cc359566
TH
366 }
367
368 /**
369 * Display a warning about installing development code if necesary.
8d1da748 370 * @param int $maturity
cc359566
TH
371 * @return string HTML to output.
372 */
373 protected function maturity_warning($maturity) {
374 if ($maturity == MATURITY_STABLE) {
375 return ''; // No worries.
376 }
377
378 $maturitylevel = get_string('maturity' . $maturity, 'admin');
379 return $this->box(
380 $this->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
381 $this->container($this->doc_link('admin/versions', get_string('morehelp'))),
382 'generalbox maturitywarning');
383 }
384
385 /**
386 * Output the copyright notice.
387 * @return string HTML to output.
388 */
389 protected function moodle_copyright() {
390 global $CFG;
391
392 //////////////////////////////////////////////////////////////////////////////////////////////////
393 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
394 $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
395 '<a href="http://docs.moodle.org/dev/Releases" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
396 'Copyright &copy; 1999 onwards, Martin Dougiamas<br />'.
397 'and <a href="http://docs.moodle.org/dev/Credits">many other contributors</a>.<br />'.
398 '<a href="http://docs.moodle.org/dev/License">GNU Public License</a>';
399 //////////////////////////////////////////////////////////////////////////////////////////////////
400
401 return $this->box($copyrighttext, 'copyright');
402 }
403
404 /**
405 * Display a warning about installing development code if necesary.
8d1da748
PS
406 * @param int $maturity
407 * @return string HTML to output.
cc359566
TH
408 */
409 protected function maturity_info($maturity) {
410 if ($maturity == MATURITY_STABLE) {
411 return ''; // No worries.
412 }
413
414 $maturitylevel = get_string('maturity' . $maturity, 'admin');
415 return $this->box(
416 get_string('maturitycoreinfo', 'admin', $maturitylevel) . ' ' .
417 $this->doc_link('admin/versions', get_string('morehelp')),
418 'generalbox adminwarning maturityinfo');
419 }
420
421 /**
422 * Display a link to the release notes.
8d1da748 423 * @return string HTML to output.
cc359566
TH
424 */
425 protected function release_notes_link() {
426 $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/dev/Releases');
427 $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
428 return $this->box($releasenoteslink, 'generalbox releasenoteslink');
429 }
430
431 /**
432 * Display the reload link that appears on several upgrade/install pages.
8d1da748 433 * @return string HTML to output.
cc359566
TH
434 */
435 function upgrade_reload($url) {
436 return html_writer::empty_tag('br') .
437 html_writer::tag('div',
438 html_writer::link($url, $this->pix_icon('i/reload', '') .
439 get_string('reload'), array('title' => get_string('reload'))),
440 array('class' => 'continuebutton')) . html_writer::empty_tag('br');
441 }
442
b9934a17
DM
443 /**
444 * Displays all known plugins and information about their installation or upgrade
445 *
446 * This default implementation renders all plugins into one big table. The rendering
447 * options support:
448 * (bool)full = false: whether to display up-to-date plugins, too
449 *
36ca62ca 450 * @param plugin_manager $pluginman provides information about the plugins.
faadd326 451 * @param int $version the version of the Moodle code from version.php.
b9934a17
DM
452 * @param array $options rendering options
453 * @return string HTML code
454 */
faadd326 455 public function plugins_check_table(plugin_manager $pluginman, $version, array $options = null) {
36ca62ca 456 $plugininfo = $pluginman->get_plugins();
b9934a17
DM
457
458 if (empty($plugininfo)) {
459 return '';
460 }
461
462 if (empty($options)) {
463 $options = array(
464 'full' => false,
465 );
466 }
467
b9934a17
DM
468 $table = new html_table();
469 $table->id = 'plugins-check';
470 $table->head = array(
471 get_string('displayname', 'core_plugin'),
472 get_string('rootdir', 'core_plugin'),
473 get_string('source', 'core_plugin'),
474 get_string('versiondb', 'core_plugin'),
475 get_string('versiondisk', 'core_plugin'),
36ca62ca 476 get_string('requires', 'core_plugin'),
b9934a17
DM
477 get_string('status', 'core_plugin'),
478 );
479 $table->colclasses = array(
36ca62ca 480 'displayname', 'rootdir', 'source', 'versiondb', 'versiondisk', 'requires', 'status',
b9934a17
DM
481 );
482 $table->data = array();
483
484 $numofhighlighted = array(); // number of highlighted rows per this subsection
485
486 foreach ($plugininfo as $type => $plugins) {
487
488 $header = new html_table_cell($pluginman->plugintype_name_plural($type));
489 $header->header = true;
490 $header->colspan = count($table->head);
491 $header = new html_table_row(array($header));
492 $header->attributes['class'] = 'plugintypeheader type-' . $type;
493
494 $numofhighlighted[$type] = 0;
495
496 if (empty($plugins) and $options['full']) {
497 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
498 $msg->colspan = count($table->head);
499 $row = new html_table_row(array($msg));
500 $row->attributes['class'] .= 'msg msg-noneinstalled';
501 $table->data[] = $header;
502 $table->data[] = $row;
503 continue;
504 }
505
506 $plugintyperows = array();
507
508 foreach ($plugins as $name => $plugin) {
509 $row = new html_table_row();
510 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
511
512 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) {
513 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
514 } else {
515 $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon'));
516 }
517 $displayname = $icon . ' ' . $plugin->displayname;
518 $displayname = new html_table_cell($displayname);
519
520 $rootdir = new html_table_cell($plugin->get_dir());
521
522 if ($isstandard = $plugin->is_standard()) {
523 $row->attributes['class'] .= ' standard';
524 $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
525 } else {
526 $row->attributes['class'] .= ' extension';
527 $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
528 }
529
530 $versiondb = new html_table_cell($plugin->versiondb);
531 $versiondisk = new html_table_cell($plugin->versiondisk);
532
533 $statuscode = $plugin->get_status();
534 $row->attributes['class'] .= ' status-' . $statuscode;
535
536 $status = new html_table_cell(get_string('status_' . $statuscode, 'core_plugin'));
537
faadd326 538 $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version));
36ca62ca
TH
539
540 $statusisboring = in_array($statuscode, array(
541 plugin_manager::PLUGIN_STATUS_NODB, plugin_manager::PLUGIN_STATUS_UPTODATE));
777781d1 542 $dependenciesok = $pluginman->are_dependencies_satisfied(
36ca62ca 543 $plugin->get_other_required_plugins());
777781d1 544 if ($isstandard and $statusisboring and $dependenciesok) {
b9934a17
DM
545 if (empty($options['full'])) {
546 continue;
547 }
548 } else {
549 $numofhighlighted[$type]++;
550 }
551
36ca62ca
TH
552 $row->cells = array($displayname, $rootdir, $source,
553 $versiondb, $versiondisk, $requires, $status);
b9934a17
DM
554 $plugintyperows[] = $row;
555 }
556
557 if (empty($numofhighlighted[$type]) and empty($options['full'])) {
558 continue;
559 }
560
561 $table->data[] = $header;
562 $table->data = array_merge($table->data, $plugintyperows);
563 }
564
565 $sumofhighlighted = array_sum($numofhighlighted);
566
567 if ($sumofhighlighted == 0) {
568 $out = $this->output->container_start('nonehighlighted', 'plugins-check-info');
569 $out .= $this->output->heading(get_string('nonehighlighted', 'core_plugin'));
570 if (empty($options['full'])) {
571 $out .= html_writer::link(new moodle_url('/admin/index.php',
572 array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1)),
573 get_string('nonehighlightedinfo', 'core_plugin'));
574 }
575 $out .= $this->output->container_end();
576
577 } else {
578 $out = $this->output->container_start('somehighlighted', 'plugins-check-info');
579 $out .= $this->output->heading(get_string('somehighlighted', 'core_plugin', $sumofhighlighted));
580 if (empty($options['full'])) {
581 $out .= html_writer::link(new moodle_url('/admin/index.php',
582 array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1)),
583 get_string('somehighlightedinfo', 'core_plugin'));
584 }
585 $out .= $this->output->container_end();
586 }
587
588 if ($sumofhighlighted > 0 or $options['full']) {
589 $out .= html_writer::table($table);
590 }
591
592 return $out;
593 }
594
36ca62ca
TH
595 /**
596 * Formats the information that needs to go in the 'Requires' column.
b6ad8594 597 * @param plugininfo_base $plugin the plugin we are rendering the row for.
36ca62ca 598 * @param plugin_manager $pluginman provides data on all the plugins.
8d1da748
PS
599 * @param string $version
600 * @return string HTML code
36ca62ca 601 */
b6ad8594 602 protected function required_column(plugininfo_base $plugin, plugin_manager $pluginman, $version) {
36ca62ca
TH
603 $requires = array();
604
605 if (!empty($plugin->versionrequires)) {
faadd326 606 if ($plugin->versionrequires <= $version) {
36ca62ca
TH
607 $class = 'requires-ok';
608 } else {
609 $class = 'requires-failed';
610 }
611 $requires[] = html_writer::tag('li',
612 get_string('moodleversion', 'core_plugin', $plugin->versionrequires),
613 array('class' => $class));
614 }
615
616 foreach ($plugin->get_other_required_plugins() as $component => $requiredversion) {
617 $ok = true;
618 $otherplugin = $pluginman->get_plugin_info($component);
619
620 if (is_null($otherplugin)) {
621 $ok = false;
499ff0a9 622 } else if ($requiredversion != ANY_VERSION and $otherplugin->versiondisk < $requiredversion) {
36ca62ca
TH
623 $ok = false;
624 }
625
626 if ($ok) {
627 $class = 'requires-ok';
628 } else {
629 $class = 'requires-failed';
630 }
631
632 if ($requiredversion != ANY_VERSION) {
633 $str = 'otherpluginversion';
634 } else {
635 $str = 'otherplugin';
636 }
637 $requires[] = html_writer::tag('li',
638 get_string($str, 'core_plugin',
639 array('component' => $component, 'version' => $requiredversion)),
640 array('class' => $class));
641 }
642
643 if (!$requires) {
644 return '';
645 }
646 return html_writer::tag('ul', implode("\n", $requires));
647 }
648
b9934a17
DM
649 /**
650 * Displays all known plugins and links to manage them
651 *
652 * This default implementation renders all plugins into one big table.
653 *
36ca62ca 654 * @param plugin_manager $pluginman provides information about the plugins.
b9934a17
DM
655 * @return string HTML code
656 */
36ca62ca
TH
657 public function plugins_control_panel(plugin_manager $pluginman) {
658 $plugininfo = $pluginman->get_plugins();
b9934a17
DM
659
660 if (empty($plugininfo)) {
661 return '';
662 }
663
b9934a17
DM
664 $table = new html_table();
665 $table->id = 'plugins-control-panel';
666 $table->head = array(
667 get_string('displayname', 'core_plugin'),
668 get_string('systemname', 'core_plugin'),
669 get_string('source', 'core_plugin'),
670 get_string('version', 'core_plugin'),
671 get_string('availability', 'core_plugin'),
672 get_string('settings', 'core_plugin'),
673 get_string('uninstall','core_plugin'),
674 );
675 $table->colclasses = array(
676 'displayname', 'systemname', 'source', 'version', 'availability', 'settings', 'uninstall',
677 );
678
679 foreach ($plugininfo as $type => $plugins) {
680
681 $header = new html_table_cell($pluginman->plugintype_name_plural($type));
682 $header->header = true;
683 $header->colspan = count($table->head);
684 $header = new html_table_row(array($header));
685 $header->attributes['class'] = 'plugintypeheader type-' . $type;
686 $table->data[] = $header;
687
688 if (empty($plugins)) {
689 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
690 $msg->colspan = count($table->head);
691 $row = new html_table_row(array($msg));
692 $row->attributes['class'] .= 'msg msg-noneinstalled';
693 $table->data[] = $row;
694 continue;
695 }
696
697 foreach ($plugins as $name => $plugin) {
698 $row = new html_table_row();
699 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
700
701 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) {
702 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
703 } else {
704 $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon'));
705 }
706 if ($plugin->get_status() === plugin_manager::PLUGIN_STATUS_MISSING) {
707 $msg = html_writer::tag('span', get_string('status_missing', 'core_plugin'), array('class' => 'notifyproblem'));
708 $row->attributes['class'] .= ' missingfromdisk';
709 } else {
710 $msg = '';
711 }
712 $displayname = $icon . ' ' . $plugin->displayname . ' ' . $msg;
713 $displayname = new html_table_cell($displayname);
714
715 $systemname = new html_table_cell($plugin->type . '_' . $plugin->name);
716
717 if ($plugin->is_standard()) {
718 $row->attributes['class'] .= ' standard';
719 $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
720 } else {
721 $row->attributes['class'] .= ' extension';
722 $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
723 }
724
725 $version = new html_table_cell($plugin->versiondb);
726
727 $isenabled = $plugin->is_enabled();
728 if (is_null($isenabled)) {
729 $availability = new html_table_cell('');
730 } else if ($isenabled) {
731 $row->attributes['class'] .= ' enabled';
732 $icon = $this->output->pix_icon('i/hide', get_string('pluginenabled', 'core_plugin'));
733 $availability = new html_table_cell($icon . ' ' . get_string('pluginenabled', 'core_plugin'));
734 } else {
735 $row->attributes['class'] .= ' disabled';
736 $icon = $this->output->pix_icon('i/show', get_string('plugindisabled', 'core_plugin'));
737 $availability = new html_table_cell($icon . ' ' . get_string('plugindisabled', 'core_plugin'));
738 }
739
740 $settingsurl = $plugin->get_settings_url();
741 if (is_null($settingsurl)) {
742 $settings = new html_table_cell('');
743 } else {
744 $settings = html_writer::link($settingsurl, get_string('settings', 'core_plugin'));
745 $settings = new html_table_cell($settings);
746 }
747
748 $uninstallurl = $plugin->get_uninstall_url();
828788f0 749 $requriedby = $pluginman->other_plugins_that_require($plugin->component);
b9934a17
DM
750 if (is_null($uninstallurl)) {
751 $uninstall = new html_table_cell('');
828788f0
TH
752 } else if ($requriedby) {
753 $uninstall = new html_table_cell(get_string('requiredby', 'core_plugin', implode(', ', $requriedby)));
754 $uninstall->attributes['class'] = 'requiredby';
b9934a17
DM
755 } else {
756 $uninstall = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin'));
757 $uninstall = new html_table_cell($uninstall);
758 }
759
760 $row->cells = array(
761 $displayname, $systemname, $source, $version, $availability, $settings, $uninstall
762 );
763 $table->data[] = $row;
764 }
765 }
766
767 return html_writer::table($table);
768 }
da2fdc3f
TH
769
770 /**
cc359566
TH
771 * This function will render one beautiful table with all the environmental
772 * configuration and how it suits Moodle needs.
773 *
774 * @param boolean $result final result of the check (true/false)
775 * @param array $environment_results array of results gathered
776 * @return string HTML to output.
da2fdc3f 777 */
cc359566
TH
778 public function environment_check_table($result, $environment_results) {
779 global $CFG;
780
781 // Table headers
782 $servertable = new html_table();//table for server checks
783 $servertable->head = array(
784 get_string('name'),
785 get_string('info'),
786 get_string('report'),
787 get_string('status'),
788 );
789 $servertable->align = array('center', 'center', 'left', 'center');
790 $servertable->wrap = array('nowrap', '', '', 'nowrap');
791 $servertable->size = array('10', 10, '100%', '10');
792 $servertable->attributes['class'] = 'environmenttable generaltable';
793
794 $serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
795
796 $othertable = new html_table();//table for custom checks
797 $othertable->head = array(
798 get_string('info'),
799 get_string('report'),
800 get_string('status'),
801 );
802 $othertable->align = array('center', 'left', 'center');
803 $othertable->wrap = array('', '', 'nowrap');
804 $othertable->size = array(10, '100%', '10');
805 $othertable->attributes['class'] = 'environmenttable generaltable';
806
807 $otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
808
809 // Iterate over each environment_result
810 $continue = true;
811 foreach ($environment_results as $environment_result) {
812 $errorline = false;
813 $warningline = false;
814 $stringtouse = '';
815 if ($continue) {
816 $type = $environment_result->getPart();
817 $info = $environment_result->getInfo();
818 $status = $environment_result->getStatus();
819 $error_code = $environment_result->getErrorCode();
820 // Process Report field
821 $rec = new stdClass();
822 // Something has gone wrong at parsing time
823 if ($error_code) {
824 $stringtouse = 'environmentxmlerror';
825 $rec->error_code = $error_code;
826 $status = get_string('error');
827 $errorline = true;
828 $continue = false;
829 }
830
831 if ($continue) {
832 if ($rec->needed = $environment_result->getNeededVersion()) {
833 // We are comparing versions
834 $rec->current = $environment_result->getCurrentVersion();
835 if ($environment_result->getLevel() == 'required') {
836 $stringtouse = 'environmentrequireversion';
837 } else {
838 $stringtouse = 'environmentrecommendversion';
839 }
840
841 } else if ($environment_result->getPart() == 'custom_check') {
842 // We are checking installed & enabled things
843 if ($environment_result->getLevel() == 'required') {
844 $stringtouse = 'environmentrequirecustomcheck';
845 } else {
846 $stringtouse = 'environmentrecommendcustomcheck';
847 }
848
849 } else if ($environment_result->getPart() == 'php_setting') {
850 if ($status) {
851 $stringtouse = 'environmentsettingok';
852 } else if ($environment_result->getLevel() == 'required') {
853 $stringtouse = 'environmentmustfixsetting';
854 } else {
855 $stringtouse = 'environmentshouldfixsetting';
856 }
857
858 } else {
859 if ($environment_result->getLevel() == 'required') {
860 $stringtouse = 'environmentrequireinstall';
861 } else {
862 $stringtouse = 'environmentrecommendinstall';
863 }
864 }
865
866 // Calculate the status value
867 if ($environment_result->getBypassStr() != '') { //Handle bypassed result (warning)
868 $status = get_string('bypassed');
869 $warningline = true;
870 } else if ($environment_result->getRestrictStr() != '') { //Handle restricted result (error)
871 $status = get_string('restricted');
872 $errorline = true;
873 } else {
874 if ($status) { //Handle ok result (ok)
875 $status = get_string('ok');
876 } else {
877 if ($environment_result->getLevel() == 'optional') {//Handle check result (warning)
878 $status = get_string('check');
879 $warningline = true;
880 } else { //Handle error result (error)
881 $status = get_string('check');
882 $errorline = true;
883 }
884 }
885 }
886 }
887
888 // Build the text
889 $linkparts = array();
890 $linkparts[] = 'admin/environment';
891 $linkparts[] = $type;
892 if (!empty($info)){
893 $linkparts[] = $info;
894 }
895 if (empty($CFG->docroot)) {
896 $report = get_string($stringtouse, 'admin', $rec);
897 } else {
898 $report = $this->doc_link(join($linkparts, '/'), get_string($stringtouse, 'admin', $rec));
899 }
900
901 // Format error or warning line
902 if ($errorline || $warningline) {
903 $messagetype = $errorline? 'error':'warn';
904 } else {
905 $messagetype = 'ok';
906 }
907 $status = '<span class="'.$messagetype.'">'.$status.'</span>';
908 // Here we'll store all the feedback found
909 $feedbacktext = '';
910 // Append the feedback if there is some
911 $feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), $messagetype);
912 //Append the bypass if there is some
913 $feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'warn');
914 //Append the restrict if there is some
915 $feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'error');
916
917 $report .= $feedbacktext;
918
919 // Add the row to the table
920 if ($environment_result->getPart() == 'custom_check'){
921 $otherdata[$messagetype][] = array ($info, $report, $status);
922 } else {
923 $serverdata[$messagetype][] = array ($type, $info, $report, $status);
924 }
925 }
926 }
927
928 //put errors first in
929 $servertable->data = array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']);
930 $othertable->data = array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']);
931
932 // Print table
933 $output = '';
934 $output .= $this->heading(get_string('serverchecks', 'admin'));
935 $output .= html_writer::table($servertable);
936 if (count($othertable->data)){
937 $output .= $this->heading(get_string('customcheck', 'admin'));
938 $output .= html_writer::table($othertable);
939 }
940
941 // Finally, if any error has happened, print the summary box
942 if (!$result) {
943 $output .= $this->box(get_string('environmenterrortodo', 'admin'), 'environmentbox errorbox');
944 }
945
946 return $output;
da2fdc3f 947 }
b9934a17 948}