weekly release 2.3dev (blame stronk7 for 0202 mistake)
[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
342 return $this->warning(get_string('sitemaintenancewarning2', 'admin',
343 new moodle_url('/admin/settings.php', array('section' => 'maintenancemode'))));
344 }
345
346 /**
347 * Display a warning about installing development code if necesary.
8d1da748 348 * @param int $maturity
cc359566
TH
349 * @return string HTML to output.
350 */
351 protected function maturity_warning($maturity) {
352 if ($maturity == MATURITY_STABLE) {
353 return ''; // No worries.
354 }
355
356 $maturitylevel = get_string('maturity' . $maturity, 'admin');
357 return $this->box(
358 $this->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
359 $this->container($this->doc_link('admin/versions', get_string('morehelp'))),
360 'generalbox maturitywarning');
361 }
362
363 /**
364 * Output the copyright notice.
365 * @return string HTML to output.
366 */
367 protected function moodle_copyright() {
368 global $CFG;
369
370 //////////////////////////////////////////////////////////////////////////////////////////////////
371 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
372 $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
373 '<a href="http://docs.moodle.org/dev/Releases" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
374 'Copyright &copy; 1999 onwards, Martin Dougiamas<br />'.
375 'and <a href="http://docs.moodle.org/dev/Credits">many other contributors</a>.<br />'.
376 '<a href="http://docs.moodle.org/dev/License">GNU Public License</a>';
377 //////////////////////////////////////////////////////////////////////////////////////////////////
378
379 return $this->box($copyrighttext, 'copyright');
380 }
381
382 /**
383 * Display a warning about installing development code if necesary.
8d1da748
PS
384 * @param int $maturity
385 * @return string HTML to output.
cc359566
TH
386 */
387 protected function maturity_info($maturity) {
388 if ($maturity == MATURITY_STABLE) {
389 return ''; // No worries.
390 }
391
392 $maturitylevel = get_string('maturity' . $maturity, 'admin');
393 return $this->box(
394 get_string('maturitycoreinfo', 'admin', $maturitylevel) . ' ' .
395 $this->doc_link('admin/versions', get_string('morehelp')),
396 'generalbox adminwarning maturityinfo');
397 }
398
399 /**
400 * Display a link to the release notes.
8d1da748 401 * @return string HTML to output.
cc359566
TH
402 */
403 protected function release_notes_link() {
404 $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/dev/Releases');
405 $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
406 return $this->box($releasenoteslink, 'generalbox releasenoteslink');
407 }
408
409 /**
410 * Display the reload link that appears on several upgrade/install pages.
8d1da748 411 * @return string HTML to output.
cc359566
TH
412 */
413 function upgrade_reload($url) {
414 return html_writer::empty_tag('br') .
415 html_writer::tag('div',
416 html_writer::link($url, $this->pix_icon('i/reload', '') .
417 get_string('reload'), array('title' => get_string('reload'))),
418 array('class' => 'continuebutton')) . html_writer::empty_tag('br');
419 }
420
b9934a17
DM
421 /**
422 * Displays all known plugins and information about their installation or upgrade
423 *
424 * This default implementation renders all plugins into one big table. The rendering
425 * options support:
426 * (bool)full = false: whether to display up-to-date plugins, too
427 *
36ca62ca 428 * @param plugin_manager $pluginman provides information about the plugins.
faadd326 429 * @param int $version the version of the Moodle code from version.php.
b9934a17
DM
430 * @param array $options rendering options
431 * @return string HTML code
432 */
faadd326 433 public function plugins_check_table(plugin_manager $pluginman, $version, array $options = null) {
36ca62ca 434 $plugininfo = $pluginman->get_plugins();
b9934a17
DM
435
436 if (empty($plugininfo)) {
437 return '';
438 }
439
440 if (empty($options)) {
441 $options = array(
442 'full' => false,
443 );
444 }
445
b9934a17
DM
446 $table = new html_table();
447 $table->id = 'plugins-check';
448 $table->head = array(
449 get_string('displayname', 'core_plugin'),
450 get_string('rootdir', 'core_plugin'),
451 get_string('source', 'core_plugin'),
452 get_string('versiondb', 'core_plugin'),
453 get_string('versiondisk', 'core_plugin'),
36ca62ca 454 get_string('requires', 'core_plugin'),
b9934a17
DM
455 get_string('status', 'core_plugin'),
456 );
457 $table->colclasses = array(
36ca62ca 458 'displayname', 'rootdir', 'source', 'versiondb', 'versiondisk', 'requires', 'status',
b9934a17
DM
459 );
460 $table->data = array();
461
462 $numofhighlighted = array(); // number of highlighted rows per this subsection
463
464 foreach ($plugininfo as $type => $plugins) {
465
466 $header = new html_table_cell($pluginman->plugintype_name_plural($type));
467 $header->header = true;
468 $header->colspan = count($table->head);
469 $header = new html_table_row(array($header));
470 $header->attributes['class'] = 'plugintypeheader type-' . $type;
471
472 $numofhighlighted[$type] = 0;
473
474 if (empty($plugins) and $options['full']) {
475 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
476 $msg->colspan = count($table->head);
477 $row = new html_table_row(array($msg));
478 $row->attributes['class'] .= 'msg msg-noneinstalled';
479 $table->data[] = $header;
480 $table->data[] = $row;
481 continue;
482 }
483
484 $plugintyperows = array();
485
486 foreach ($plugins as $name => $plugin) {
487 $row = new html_table_row();
488 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
489
490 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) {
491 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
492 } else {
493 $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon'));
494 }
495 $displayname = $icon . ' ' . $plugin->displayname;
496 $displayname = new html_table_cell($displayname);
497
498 $rootdir = new html_table_cell($plugin->get_dir());
499
500 if ($isstandard = $plugin->is_standard()) {
501 $row->attributes['class'] .= ' standard';
502 $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
503 } else {
504 $row->attributes['class'] .= ' extension';
505 $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
506 }
507
508 $versiondb = new html_table_cell($plugin->versiondb);
509 $versiondisk = new html_table_cell($plugin->versiondisk);
510
511 $statuscode = $plugin->get_status();
512 $row->attributes['class'] .= ' status-' . $statuscode;
513
514 $status = new html_table_cell(get_string('status_' . $statuscode, 'core_plugin'));
515
faadd326 516 $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version));
36ca62ca
TH
517
518 $statusisboring = in_array($statuscode, array(
519 plugin_manager::PLUGIN_STATUS_NODB, plugin_manager::PLUGIN_STATUS_UPTODATE));
777781d1 520 $dependenciesok = $pluginman->are_dependencies_satisfied(
36ca62ca 521 $plugin->get_other_required_plugins());
777781d1 522 if ($isstandard and $statusisboring and $dependenciesok) {
b9934a17
DM
523 if (empty($options['full'])) {
524 continue;
525 }
526 } else {
527 $numofhighlighted[$type]++;
528 }
529
36ca62ca
TH
530 $row->cells = array($displayname, $rootdir, $source,
531 $versiondb, $versiondisk, $requires, $status);
b9934a17
DM
532 $plugintyperows[] = $row;
533 }
534
535 if (empty($numofhighlighted[$type]) and empty($options['full'])) {
536 continue;
537 }
538
539 $table->data[] = $header;
540 $table->data = array_merge($table->data, $plugintyperows);
541 }
542
543 $sumofhighlighted = array_sum($numofhighlighted);
544
545 if ($sumofhighlighted == 0) {
546 $out = $this->output->container_start('nonehighlighted', 'plugins-check-info');
547 $out .= $this->output->heading(get_string('nonehighlighted', 'core_plugin'));
548 if (empty($options['full'])) {
549 $out .= html_writer::link(new moodle_url('/admin/index.php',
550 array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1)),
551 get_string('nonehighlightedinfo', 'core_plugin'));
552 }
553 $out .= $this->output->container_end();
554
555 } else {
556 $out = $this->output->container_start('somehighlighted', 'plugins-check-info');
557 $out .= $this->output->heading(get_string('somehighlighted', 'core_plugin', $sumofhighlighted));
558 if (empty($options['full'])) {
559 $out .= html_writer::link(new moodle_url('/admin/index.php',
560 array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1)),
561 get_string('somehighlightedinfo', 'core_plugin'));
562 }
563 $out .= $this->output->container_end();
564 }
565
566 if ($sumofhighlighted > 0 or $options['full']) {
567 $out .= html_writer::table($table);
568 }
569
570 return $out;
571 }
572
36ca62ca
TH
573 /**
574 * Formats the information that needs to go in the 'Requires' column.
575 * @param plugin_information $plugin the plugin we are rendering the row for.
576 * @param plugin_manager $pluginman provides data on all the plugins.
8d1da748
PS
577 * @param string $version
578 * @return string HTML code
36ca62ca 579 */
8d1da748 580 protected function required_column(plugin_information $plugin, plugin_manager $pluginman, $version) {
36ca62ca
TH
581 $requires = array();
582
583 if (!empty($plugin->versionrequires)) {
faadd326 584 if ($plugin->versionrequires <= $version) {
36ca62ca
TH
585 $class = 'requires-ok';
586 } else {
587 $class = 'requires-failed';
588 }
589 $requires[] = html_writer::tag('li',
590 get_string('moodleversion', 'core_plugin', $plugin->versionrequires),
591 array('class' => $class));
592 }
593
594 foreach ($plugin->get_other_required_plugins() as $component => $requiredversion) {
595 $ok = true;
596 $otherplugin = $pluginman->get_plugin_info($component);
597
598 if (is_null($otherplugin)) {
599 $ok = false;
600 }
3f123d92 601 if ($requiredversion != ANY_VERSION and $otherplugin->versiondisk < $requiredversion) {
36ca62ca
TH
602 $ok = false;
603 }
604
605 if ($ok) {
606 $class = 'requires-ok';
607 } else {
608 $class = 'requires-failed';
609 }
610
611 if ($requiredversion != ANY_VERSION) {
612 $str = 'otherpluginversion';
613 } else {
614 $str = 'otherplugin';
615 }
616 $requires[] = html_writer::tag('li',
617 get_string($str, 'core_plugin',
618 array('component' => $component, 'version' => $requiredversion)),
619 array('class' => $class));
620 }
621
622 if (!$requires) {
623 return '';
624 }
625 return html_writer::tag('ul', implode("\n", $requires));
626 }
627
b9934a17
DM
628 /**
629 * Displays all known plugins and links to manage them
630 *
631 * This default implementation renders all plugins into one big table.
632 *
36ca62ca 633 * @param plugin_manager $pluginman provides information about the plugins.
b9934a17
DM
634 * @return string HTML code
635 */
36ca62ca
TH
636 public function plugins_control_panel(plugin_manager $pluginman) {
637 $plugininfo = $pluginman->get_plugins();
b9934a17
DM
638
639 if (empty($plugininfo)) {
640 return '';
641 }
642
b9934a17
DM
643 $table = new html_table();
644 $table->id = 'plugins-control-panel';
645 $table->head = array(
646 get_string('displayname', 'core_plugin'),
647 get_string('systemname', 'core_plugin'),
648 get_string('source', 'core_plugin'),
649 get_string('version', 'core_plugin'),
650 get_string('availability', 'core_plugin'),
651 get_string('settings', 'core_plugin'),
652 get_string('uninstall','core_plugin'),
653 );
654 $table->colclasses = array(
655 'displayname', 'systemname', 'source', 'version', 'availability', 'settings', 'uninstall',
656 );
657
658 foreach ($plugininfo as $type => $plugins) {
659
660 $header = new html_table_cell($pluginman->plugintype_name_plural($type));
661 $header->header = true;
662 $header->colspan = count($table->head);
663 $header = new html_table_row(array($header));
664 $header->attributes['class'] = 'plugintypeheader type-' . $type;
665 $table->data[] = $header;
666
667 if (empty($plugins)) {
668 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
669 $msg->colspan = count($table->head);
670 $row = new html_table_row(array($msg));
671 $row->attributes['class'] .= 'msg msg-noneinstalled';
672 $table->data[] = $row;
673 continue;
674 }
675
676 foreach ($plugins as $name => $plugin) {
677 $row = new html_table_row();
678 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
679
680 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) {
681 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
682 } else {
683 $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon'));
684 }
685 if ($plugin->get_status() === plugin_manager::PLUGIN_STATUS_MISSING) {
686 $msg = html_writer::tag('span', get_string('status_missing', 'core_plugin'), array('class' => 'notifyproblem'));
687 $row->attributes['class'] .= ' missingfromdisk';
688 } else {
689 $msg = '';
690 }
691 $displayname = $icon . ' ' . $plugin->displayname . ' ' . $msg;
692 $displayname = new html_table_cell($displayname);
693
694 $systemname = new html_table_cell($plugin->type . '_' . $plugin->name);
695
696 if ($plugin->is_standard()) {
697 $row->attributes['class'] .= ' standard';
698 $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
699 } else {
700 $row->attributes['class'] .= ' extension';
701 $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
702 }
703
704 $version = new html_table_cell($plugin->versiondb);
705
706 $isenabled = $plugin->is_enabled();
707 if (is_null($isenabled)) {
708 $availability = new html_table_cell('');
709 } else if ($isenabled) {
710 $row->attributes['class'] .= ' enabled';
711 $icon = $this->output->pix_icon('i/hide', get_string('pluginenabled', 'core_plugin'));
712 $availability = new html_table_cell($icon . ' ' . get_string('pluginenabled', 'core_plugin'));
713 } else {
714 $row->attributes['class'] .= ' disabled';
715 $icon = $this->output->pix_icon('i/show', get_string('plugindisabled', 'core_plugin'));
716 $availability = new html_table_cell($icon . ' ' . get_string('plugindisabled', 'core_plugin'));
717 }
718
719 $settingsurl = $plugin->get_settings_url();
720 if (is_null($settingsurl)) {
721 $settings = new html_table_cell('');
722 } else {
723 $settings = html_writer::link($settingsurl, get_string('settings', 'core_plugin'));
724 $settings = new html_table_cell($settings);
725 }
726
727 $uninstallurl = $plugin->get_uninstall_url();
828788f0 728 $requriedby = $pluginman->other_plugins_that_require($plugin->component);
b9934a17
DM
729 if (is_null($uninstallurl)) {
730 $uninstall = new html_table_cell('');
828788f0
TH
731 } else if ($requriedby) {
732 $uninstall = new html_table_cell(get_string('requiredby', 'core_plugin', implode(', ', $requriedby)));
733 $uninstall->attributes['class'] = 'requiredby';
b9934a17
DM
734 } else {
735 $uninstall = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin'));
736 $uninstall = new html_table_cell($uninstall);
737 }
738
739 $row->cells = array(
740 $displayname, $systemname, $source, $version, $availability, $settings, $uninstall
741 );
742 $table->data[] = $row;
743 }
744 }
745
746 return html_writer::table($table);
747 }
da2fdc3f
TH
748
749 /**
cc359566
TH
750 * This function will render one beautiful table with all the environmental
751 * configuration and how it suits Moodle needs.
752 *
753 * @param boolean $result final result of the check (true/false)
754 * @param array $environment_results array of results gathered
755 * @return string HTML to output.
da2fdc3f 756 */
cc359566
TH
757 public function environment_check_table($result, $environment_results) {
758 global $CFG;
759
760 // Table headers
761 $servertable = new html_table();//table for server checks
762 $servertable->head = array(
763 get_string('name'),
764 get_string('info'),
765 get_string('report'),
766 get_string('status'),
767 );
768 $servertable->align = array('center', 'center', 'left', 'center');
769 $servertable->wrap = array('nowrap', '', '', 'nowrap');
770 $servertable->size = array('10', 10, '100%', '10');
771 $servertable->attributes['class'] = 'environmenttable generaltable';
772
773 $serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
774
775 $othertable = new html_table();//table for custom checks
776 $othertable->head = array(
777 get_string('info'),
778 get_string('report'),
779 get_string('status'),
780 );
781 $othertable->align = array('center', 'left', 'center');
782 $othertable->wrap = array('', '', 'nowrap');
783 $othertable->size = array(10, '100%', '10');
784 $othertable->attributes['class'] = 'environmenttable generaltable';
785
786 $otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
787
788 // Iterate over each environment_result
789 $continue = true;
790 foreach ($environment_results as $environment_result) {
791 $errorline = false;
792 $warningline = false;
793 $stringtouse = '';
794 if ($continue) {
795 $type = $environment_result->getPart();
796 $info = $environment_result->getInfo();
797 $status = $environment_result->getStatus();
798 $error_code = $environment_result->getErrorCode();
799 // Process Report field
800 $rec = new stdClass();
801 // Something has gone wrong at parsing time
802 if ($error_code) {
803 $stringtouse = 'environmentxmlerror';
804 $rec->error_code = $error_code;
805 $status = get_string('error');
806 $errorline = true;
807 $continue = false;
808 }
809
810 if ($continue) {
811 if ($rec->needed = $environment_result->getNeededVersion()) {
812 // We are comparing versions
813 $rec->current = $environment_result->getCurrentVersion();
814 if ($environment_result->getLevel() == 'required') {
815 $stringtouse = 'environmentrequireversion';
816 } else {
817 $stringtouse = 'environmentrecommendversion';
818 }
819
820 } else if ($environment_result->getPart() == 'custom_check') {
821 // We are checking installed & enabled things
822 if ($environment_result->getLevel() == 'required') {
823 $stringtouse = 'environmentrequirecustomcheck';
824 } else {
825 $stringtouse = 'environmentrecommendcustomcheck';
826 }
827
828 } else if ($environment_result->getPart() == 'php_setting') {
829 if ($status) {
830 $stringtouse = 'environmentsettingok';
831 } else if ($environment_result->getLevel() == 'required') {
832 $stringtouse = 'environmentmustfixsetting';
833 } else {
834 $stringtouse = 'environmentshouldfixsetting';
835 }
836
837 } else {
838 if ($environment_result->getLevel() == 'required') {
839 $stringtouse = 'environmentrequireinstall';
840 } else {
841 $stringtouse = 'environmentrecommendinstall';
842 }
843 }
844
845 // Calculate the status value
846 if ($environment_result->getBypassStr() != '') { //Handle bypassed result (warning)
847 $status = get_string('bypassed');
848 $warningline = true;
849 } else if ($environment_result->getRestrictStr() != '') { //Handle restricted result (error)
850 $status = get_string('restricted');
851 $errorline = true;
852 } else {
853 if ($status) { //Handle ok result (ok)
854 $status = get_string('ok');
855 } else {
856 if ($environment_result->getLevel() == 'optional') {//Handle check result (warning)
857 $status = get_string('check');
858 $warningline = true;
859 } else { //Handle error result (error)
860 $status = get_string('check');
861 $errorline = true;
862 }
863 }
864 }
865 }
866
867 // Build the text
868 $linkparts = array();
869 $linkparts[] = 'admin/environment';
870 $linkparts[] = $type;
871 if (!empty($info)){
872 $linkparts[] = $info;
873 }
874 if (empty($CFG->docroot)) {
875 $report = get_string($stringtouse, 'admin', $rec);
876 } else {
877 $report = $this->doc_link(join($linkparts, '/'), get_string($stringtouse, 'admin', $rec));
878 }
879
880 // Format error or warning line
881 if ($errorline || $warningline) {
882 $messagetype = $errorline? 'error':'warn';
883 } else {
884 $messagetype = 'ok';
885 }
886 $status = '<span class="'.$messagetype.'">'.$status.'</span>';
887 // Here we'll store all the feedback found
888 $feedbacktext = '';
889 // Append the feedback if there is some
890 $feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), $messagetype);
891 //Append the bypass if there is some
892 $feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'warn');
893 //Append the restrict if there is some
894 $feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'error');
895
896 $report .= $feedbacktext;
897
898 // Add the row to the table
899 if ($environment_result->getPart() == 'custom_check'){
900 $otherdata[$messagetype][] = array ($info, $report, $status);
901 } else {
902 $serverdata[$messagetype][] = array ($type, $info, $report, $status);
903 }
904 }
905 }
906
907 //put errors first in
908 $servertable->data = array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']);
909 $othertable->data = array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']);
910
911 // Print table
912 $output = '';
913 $output .= $this->heading(get_string('serverchecks', 'admin'));
914 $output .= html_writer::table($servertable);
915 if (count($othertable->data)){
916 $output .= $this->heading(get_string('customcheck', 'admin'));
917 $output .= html_writer::table($othertable);
918 }
919
920 // Finally, if any error has happened, print the summary box
921 if (!$result) {
922 $output .= $this->box(get_string('environmenterrortodo', 'admin'), 'environmentbox errorbox');
923 }
924
925 return $output;
da2fdc3f 926 }
b9934a17 927}