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