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