MDL-35275 - Left align INPUT boxes and TEXT boxes during Install process, when in...
[moodle.git] / admin / renderer.php
blob3a3c2bd2ffde6dad496dd90b29161e79aeb8afb0
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.
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/>.
17 /**
18 * Renderer for core_admin subsystem
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
26 defined('MOODLE_INTERNAL') || die();
28 require_once($CFG->libdir . '/pluginlib.php');
30 /**
31 * Standard HTML output renderer for core_admin subsystem
33 class core_admin_renderer extends plugin_renderer_base {
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.
40 public function install_licence_page() {
41 global $CFG;
42 $output = '';
44 $copyrightnotice = text_to_html(get_string('gpl3'));
45 $copyrightnotice = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $copyrightnotice); // extremely ugly validation hack
47 $continue = new single_button(new moodle_url('/admin/index.php', array('lang'=>$CFG->lang, 'agreelicense'=>1)), get_string('continue'), 'get');
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();
57 return $output;
60 /**
61 * Display page explaining proper upgrade process,
62 * there can not be any PHP file leftovers...
64 * @return string HTML to output.
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 .= format_text(get_string('upgradestalefilesinfo', 'admin', get_docs_url('Upgrading')), FORMAT_MARKDOWN);
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();
77 return $output;
80 /**
81 * Display the 'environment check' page that is displayed during install.
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
86 * @return string HTML to output.
88 public function install_environment_page($maturity, $envstatus, $environment_results, $release) {
89 global $CFG;
90 $output = '';
92 $output .= $this->header();
93 $output .= $this->maturity_warning($maturity);
94 $output .= $this->heading("Moodle $release");
95 $output .= $this->release_notes_link();
97 $output .= $this->environment_check_table($envstatus, $environment_results);
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)));
106 $output .= $this->footer();
107 return $output;
111 * Displays the list of plugins with unsatisfied dependencies
113 * @param double|string|int $version Moodle on-disk version
114 * @param array $failed list of plugins with unsatisfied dependecies
115 * @param moodle_url $reloadurl URL of the page to recheck the dependencies
116 * @return string HTML
118 public function unsatisfied_dependencies_page($version, array $failed, moodle_url $reloadurl) {
119 $output = '';
121 $output .= $this->header();
122 $output .= $this->heading(get_string('pluginscheck', 'admin'));
123 $output .= $this->warning(get_string('pluginscheckfailed', 'admin', array('pluginslist' => implode(', ', array_unique($failed)))));
124 $output .= $this->plugins_check_table(plugin_manager::instance(), $version, array('xdep' => true));
125 $output .= $this->warning(get_string('pluginschecktodo', 'admin'));
126 $output .= $this->continue_button($reloadurl);
128 $output .= $this->footer();
130 return $output;
134 * Display the 'You are about to upgrade Moodle' page. The first page
135 * during upgrade.
136 * @param string $strnewversion
137 * @param int $maturity
138 * @return string HTML to output.
140 public function upgrade_confirm_page($strnewversion, $maturity) {
141 $output = '';
143 $continueurl = new moodle_url('index.php', array('confirmupgrade' => 1));
144 $cancelurl = new moodle_url('index.php');
146 $output .= $this->header();
147 $output .= $this->maturity_warning($maturity);
148 $output .= $this->confirm(get_string('upgradesure', 'admin', $strnewversion), $continueurl, $cancelurl);
149 $output .= $this->footer();
151 return $output;
155 * Display the environment page during the upgrade process.
156 * @param string $release
157 * @param boolean $envstatus final result of env check (true/false)
158 * @param array $environment_results array of results gathered
159 * @return string HTML to output.
161 public function upgrade_environment_page($release, $envstatus, $environment_results) {
162 global $CFG;
163 $output = '';
165 $output .= $this->header();
166 $output .= $this->heading("Moodle $release");
167 $output .= $this->release_notes_link();
168 $output .= $this->environment_check_table($envstatus, $environment_results);
170 if (!$envstatus) {
171 $output .= $this->upgrade_reload(new moodle_url('/admin/index.php'), array('confirmupgrade' => 1));
173 } else {
174 $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
176 if (empty($CFG->skiplangupgrade) and current_language() !== 'en') {
177 $output .= $this->box(get_string('langpackwillbeupdated', 'admin'), 'generalbox', 'notice');
180 $output .= $this->continue_button(new moodle_url('/admin/index.php', array('confirmupgrade' => 1, 'confirmrelease' => 1)));
183 $output .= $this->footer();
185 return $output;
189 * Display the upgrade page that lists all the plugins that require attention.
190 * @param plugin_manager $pluginman provides information about the plugins.
191 * @param available_update_checker $checker provides information about available updates.
192 * @param int $version the version of the Moodle code from version.php.
193 * @param bool $showallplugins
194 * @param moodle_url $reloadurl
195 * @param moodle_url $continueurl
196 * @return string HTML to output.
198 public function upgrade_plugin_check_page(plugin_manager $pluginman, available_update_checker $checker,
199 $version, $showallplugins, $reloadurl, $continueurl) {
200 global $CFG;
202 $output = '';
204 $output .= $this->header();
205 $output .= $this->box_start('generalbox');
206 $output .= $this->container_start('generalbox', 'notice');
207 $output .= html_writer::tag('p', get_string('pluginchecknotice', 'core_plugin'));
208 if (empty($CFG->disableupdatenotifications)) {
209 $output .= $this->container_start('checkforupdates');
210 $output .= $this->single_button(new moodle_url($reloadurl, array('fetchupdates' => 1)), get_string('checkforupdates', 'core_plugin'));
211 if ($timefetched = $checker->get_last_timefetched()) {
212 $output .= $this->container(get_string('checkforupdateslast', 'core_plugin',
213 userdate($timefetched, get_string('strftimedatetime', 'core_langconfig'))));
215 $output .= $this->container_end();
217 $output .= $this->container_end();
219 $output .= $this->plugins_check_table($pluginman, $version, array('full' => $showallplugins));
220 $output .= $this->box_end();
221 $output .= $this->upgrade_reload($reloadurl);
223 if ($pluginman->some_plugins_updatable()) {
224 $output .= $this->container_start('upgradepluginsinfo');
225 $output .= $this->help_icon('upgradepluginsinfo', 'core_admin', get_string('upgradepluginsfirst', 'core_admin'));
226 $output .= $this->container_end();
229 $button = new single_button($continueurl, get_string('upgradestart', 'admin'), 'get');
230 $button->class = 'continuebutton';
231 $output .= $this->render($button);
232 $output .= $this->footer();
234 return $output;
238 * Display the admin notifications page.
239 * @param int $maturity
240 * @param bool $insecuredataroot warn dataroot is invalid
241 * @param bool $errorsdisplayed warn invalid dispaly error setting
242 * @param bool $cronoverdue warn cron not running
243 * @param bool $dbproblems warn db has problems
244 * @param bool $maintenancemode warn in maintenance mode
245 * @param bool $buggyiconvnomb warn iconv problems
246 * @param array|null $availableupdates array of available_update_info objects or null
247 * @param int|null $availableupdatesfetch timestamp of the most recent updates fetch or null (unknown)
249 * @return string HTML to output.
251 public function admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed,
252 $cronoverdue, $dbproblems, $maintenancemode, $availableupdates, $availableupdatesfetch,
253 $buggyiconvnomb, $registered) {
254 global $CFG;
255 $output = '';
257 $output .= $this->header();
258 $output .= $this->maturity_info($maturity);
259 $output .= empty($CFG->disableupdatenotifications) ? $this->available_updates($availableupdates, $availableupdatesfetch) : '';
260 $output .= $this->insecure_dataroot_warning($insecuredataroot);
261 $output .= $this->display_errors_warning($errorsdisplayed);
262 $output .= $this->buggy_iconv_warning($buggyiconvnomb);
263 $output .= $this->cron_overdue_warning($cronoverdue);
264 $output .= $this->db_problems($dbproblems);
265 $output .= $this->maintenance_mode_warning($maintenancemode);
266 $output .= $this->registration_warning($registered);
268 //////////////////////////////////////////////////////////////////////////////////////////////////
269 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
270 $output .= $this->moodle_copyright();
271 //////////////////////////////////////////////////////////////////////////////////////////////////
273 $output .= $this->footer();
275 return $output;
279 * Display the plugin management page (admin/plugins.php).
281 * @param plugin_manager $pluginman
282 * @param available_update_checker $checker
283 * @return string HTML to output.
285 public function plugin_management_page(plugin_manager $pluginman, available_update_checker $checker) {
286 global $CFG;
288 $output = '';
290 $output .= $this->header();
291 $output .= $this->heading(get_string('pluginsoverview', 'core_admin'));
292 $output .= $this->plugins_overview_panel($pluginman);
294 if (empty($CFG->disableupdatenotifications)) {
295 $output .= $this->container_start('checkforupdates');
296 $output .= $this->single_button(new moodle_url($this->page->url, array('fetchremote' => 1)), get_string('checkforupdates', 'core_plugin'));
297 if ($timefetched = $checker->get_last_timefetched()) {
298 $output .= $this->container(get_string('checkforupdateslast', 'core_plugin',
299 userdate($timefetched, get_string('strftimedatetime', 'core_langconfig'))));
301 $output .= $this->container_end();
304 $output .= $this->box($this->plugins_control_panel($pluginman), 'generalbox');
305 $output .= $this->footer();
307 return $output;
311 * Display the plugin management page (admin/environment.php).
312 * @param array $versions
313 * @param string $version
314 * @param boolean $envstatus final result of env check (true/false)
315 * @param array $environment_results array of results gathered
316 * @return string HTML to output.
318 public function environment_check_page($versions, $version, $envstatus, $environment_results) {
319 $output = '';
320 $output .= $this->header();
322 // Print the component download link
323 $output .= html_writer::tag('div', html_writer::link(
324 new moodle_url('/admin/environment.php', array('action' => 'updatecomponent', 'sesskey' => sesskey())),
325 get_string('updatecomponent', 'admin')),
326 array('class' => 'reportlink'));
328 // Heading.
329 $output .= $this->heading(get_string('environment', 'admin'));
331 // Box with info and a menu to choose the version.
332 $output .= $this->box_start();
333 $output .= html_writer::tag('div', get_string('adminhelpenvironment'));
334 $select = new single_select(new moodle_url('/admin/environment.php'), 'version', $versions, $version, null);
335 $select->label = get_string('moodleversion');
336 $output .= $this->render($select);
337 $output .= $this->box_end();
339 // The results
340 $output .= $this->environment_check_table($envstatus, $environment_results);
342 $output .= $this->footer();
343 return $output;
347 * Output a warning message, of the type that appears on the admin notifications page.
348 * @param string $message the message to display.
349 * @param string $type type class
350 * @return string HTML to output.
352 protected function warning($message, $type = 'warning') {
353 return $this->box($message, 'generalbox admin' . $type);
357 * Render an appropriate message if dataroot is insecure.
358 * @param bool $insecuredataroot
359 * @return string HTML to output.
361 protected function insecure_dataroot_warning($insecuredataroot) {
362 global $CFG;
364 if ($insecuredataroot == INSECURE_DATAROOT_WARNING) {
365 return $this->warning(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot));
367 } else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) {
368 return $this->warning(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'error');
370 } else {
371 return '';
376 * Render an appropriate message if dataroot is insecure.
377 * @param bool $errorsdisplayed
378 * @return string HTML to output.
380 protected function display_errors_warning($errorsdisplayed) {
381 if (!$errorsdisplayed) {
382 return '';
385 return $this->warning(get_string('displayerrorswarning', 'admin'));
389 * Render an appropriate message if iconv is buggy and mbstring missing.
390 * @param bool $buggyiconvnomb
391 * @return string HTML to output.
393 protected function buggy_iconv_warning($buggyiconvnomb) {
394 if (!$buggyiconvnomb) {
395 return '';
398 return $this->warning(get_string('warningiconvbuggy', 'admin'));
402 * Render an appropriate message if cron has not been run recently.
403 * @param bool $cronoverdue
404 * @return string HTML to output.
406 public function cron_overdue_warning($cronoverdue) {
407 if (!$cronoverdue) {
408 return '';
411 return $this->warning(get_string('cronwarning', 'admin') . '&nbsp;' .
412 $this->help_icon('cron', 'admin'));
416 * Render an appropriate message if there are any problems with the DB set-up.
417 * @param bool $dbproblems
418 * @return string HTML to output.
420 public function db_problems($dbproblems) {
421 if (!$dbproblems) {
422 return '';
425 return $this->warning($dbproblems);
429 * Render an appropriate message if the site in in maintenance mode.
430 * @param bool $maintenancemode
431 * @return string HTML to output.
433 public function maintenance_mode_warning($maintenancemode) {
434 if (!$maintenancemode) {
435 return '';
438 $url = new moodle_url('/admin/settings.php', array('section' => 'maintenancemode'));
439 $url = $url->out(); // get_string() does not support objects in params
441 return $this->warning(get_string('sitemaintenancewarning2', 'admin', $url));
445 * Display a warning about installing development code if necesary.
446 * @param int $maturity
447 * @return string HTML to output.
449 protected function maturity_warning($maturity) {
450 if ($maturity == MATURITY_STABLE) {
451 return ''; // No worries.
454 $maturitylevel = get_string('maturity' . $maturity, 'admin');
455 return $this->box(
456 $this->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
457 $this->container($this->doc_link('admin/versions', get_string('morehelp'))),
458 'generalbox maturitywarning');
462 * Output the copyright notice.
463 * @return string HTML to output.
465 protected function moodle_copyright() {
466 global $CFG;
468 //////////////////////////////////////////////////////////////////////////////////////////////////
469 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
470 $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
471 '<a href="http://docs.moodle.org/dev/Releases" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
472 'Copyright &copy; 1999 onwards, Martin Dougiamas<br />'.
473 'and <a href="http://docs.moodle.org/dev/Credits">many other contributors</a>.<br />'.
474 '<a href="http://docs.moodle.org/dev/License">GNU Public License</a>';
475 //////////////////////////////////////////////////////////////////////////////////////////////////
477 return $this->box($copyrighttext, 'copyright');
481 * Display a warning about installing development code if necesary.
482 * @param int $maturity
483 * @return string HTML to output.
485 protected function maturity_info($maturity) {
486 if ($maturity == MATURITY_STABLE) {
487 return ''; // No worries.
490 $maturitylevel = get_string('maturity' . $maturity, 'admin');
491 return $this->box(
492 get_string('maturitycoreinfo', 'admin', $maturitylevel) . ' ' .
493 $this->doc_link('admin/versions', get_string('morehelp')),
494 'generalbox adminwarning maturityinfo maturity'.$maturity);
498 * Displays the info about available Moodle updates
500 * @param array|null $updates array of available_update_info objects or null
501 * @param int|null $fetch timestamp of the most recent updates fetch or null (unknown)
502 * @return string
504 protected function available_updates($updates, $fetch) {
506 $updateinfo = $this->box_start('generalbox adminwarning availableupdatesinfo');
507 if (is_array($updates)) {
508 $updateinfo .= $this->heading(get_string('updateavailable', 'core_admin'), 3);
509 foreach ($updates as $update) {
510 $updateinfo .= $this->moodle_available_update_info($update);
512 } else {
513 $now = time();
514 if ($fetch and ($fetch <= $now) and ($now - $fetch < HOURSECS)) {
515 $updateinfo .= $this->heading(get_string('updateavailablenot', 'core_admin'), 3);
519 $updateinfo .= $this->container_start('checkforupdates');
520 $updateinfo .= $this->single_button(new moodle_url($this->page->url, array('fetchupdates' => 1)), get_string('checkforupdates', 'core_plugin'));
521 if ($fetch) {
522 $updateinfo .= $this->container(get_string('checkforupdateslast', 'core_plugin',
523 userdate($fetch, get_string('strftimedatetime', 'core_langconfig'))));
525 $updateinfo .= $this->container_end();
527 $updateinfo .= $this->box_end();
529 return $updateinfo;
533 * Display a warning about not being registered on Moodle.org if necesary.
535 * @param boolean $registered true if the site is registered on Moodle.org
536 * @return string HTML to output.
538 protected function registration_warning($registered) {
540 if (!$registered) {
542 $registerbutton = $this->single_button(new moodle_url('registration/register.php',
543 array('huburl' => HUB_MOODLEORGHUBURL, 'hubname' => 'Moodle.org')),
544 get_string('register', 'admin'));
546 return $this->warning( get_string('registrationwarning', 'admin')
547 . '&nbsp;' . $this->help_icon('registration', 'admin') . $registerbutton );
550 return '';
554 * Helper method to render the information about the available Moodle update
556 * @param available_update_info $updateinfo information about the available Moodle core update
558 protected function moodle_available_update_info(available_update_info $updateinfo) {
560 $boxclasses = 'moodleupdateinfo';
561 $info = array();
563 if (isset($updateinfo->release)) {
564 $info[] = html_writer::tag('span', get_string('updateavailable_release', 'core_admin', $updateinfo->release),
565 array('class' => 'info release'));
568 if (isset($updateinfo->version)) {
569 $info[] = html_writer::tag('span', get_string('updateavailable_version', 'core_admin', $updateinfo->version),
570 array('class' => 'info version'));
573 if (isset($updateinfo->maturity)) {
574 $info[] = html_writer::tag('span', get_string('maturity'.$updateinfo->maturity, 'core_admin'),
575 array('class' => 'info maturity'));
576 $boxclasses .= ' maturity'.$updateinfo->maturity;
579 if (isset($updateinfo->download)) {
580 $info[] = html_writer::link($updateinfo->download, get_string('download'), array('class' => 'info download'));
583 if (isset($updateinfo->url)) {
584 $info[] = html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin'),
585 array('class' => 'info more'));
588 $box = $this->output->box_start($boxclasses);
589 $box .= $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $info), '');
590 $box .= $this->output->box_end();
592 return $box;
596 * Display a link to the release notes.
597 * @return string HTML to output.
599 protected function release_notes_link() {
600 $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/dev/Releases');
601 $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
602 return $this->box($releasenoteslink, 'generalbox releasenoteslink');
606 * Display the reload link that appears on several upgrade/install pages.
607 * @return string HTML to output.
609 function upgrade_reload($url) {
610 return html_writer::empty_tag('br') .
611 html_writer::tag('div',
612 html_writer::link($url, $this->pix_icon('i/reload', '') .
613 get_string('reload'), array('title' => get_string('reload'))),
614 array('class' => 'continuebutton')) . html_writer::empty_tag('br');
618 * Displays all known plugins and information about their installation or upgrade
620 * This default implementation renders all plugins into one big table. The rendering
621 * options support:
622 * (bool)full = false: whether to display up-to-date plugins, too
623 * (bool)xdep = false: display the plugins with unsatisified dependecies only
625 * @param plugin_manager $pluginman provides information about the plugins.
626 * @param int $version the version of the Moodle code from version.php.
627 * @param array $options rendering options
628 * @return string HTML code
630 public function plugins_check_table(plugin_manager $pluginman, $version, array $options = array()) {
631 global $CFG;
633 $plugininfo = $pluginman->get_plugins();
635 if (empty($plugininfo)) {
636 return '';
639 $options['full'] = isset($options['full']) ? (bool)$options['full'] : false;
640 $options['xdep'] = isset($options['xdep']) ? (bool)$options['xdep'] : false;
642 $table = new html_table();
643 $table->id = 'plugins-check';
644 $table->head = array(
645 get_string('displayname', 'core_plugin'),
646 get_string('rootdir', 'core_plugin'),
647 get_string('source', 'core_plugin'),
648 get_string('versiondb', 'core_plugin'),
649 get_string('versiondisk', 'core_plugin'),
650 get_string('requires', 'core_plugin'),
651 get_string('status', 'core_plugin'),
653 $table->colclasses = array(
654 'displayname', 'rootdir', 'source', 'versiondb', 'versiondisk', 'requires', 'status',
656 $table->data = array();
658 $numofhighlighted = array(); // number of highlighted rows per this subsection
660 foreach ($plugininfo as $type => $plugins) {
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;
668 $numofhighlighted[$type] = 0;
670 if (empty($plugins) and $options['full']) {
671 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
672 $msg->colspan = count($table->head);
673 $row = new html_table_row(array($msg));
674 $row->attributes['class'] .= 'msg msg-noneinstalled';
675 $table->data[] = $header;
676 $table->data[] = $row;
677 continue;
680 $plugintyperows = array();
682 foreach ($plugins as $name => $plugin) {
683 $row = new html_table_row();
684 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
686 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) {
687 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
688 } else {
689 $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon'));
691 $displayname = $icon . ' ' . $plugin->displayname;
692 $displayname = new html_table_cell($displayname);
694 $rootdir = new html_table_cell($plugin->get_dir());
696 if ($isstandard = $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'));
704 $versiondb = new html_table_cell($plugin->versiondb);
705 $versiondisk = new html_table_cell($plugin->versiondisk);
707 $statuscode = $plugin->get_status();
708 $row->attributes['class'] .= ' status-' . $statuscode;
709 $status = get_string('status_' . $statuscode, 'core_plugin');
711 $availableupdates = $plugin->available_updates();
712 if (!empty($availableupdates) and empty($CFG->disableupdatenotifications)) {
713 foreach ($availableupdates as $availableupdate) {
714 $status .= $this->plugin_available_update_info($availableupdate);
718 $status = new html_table_cell($status);
720 $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version));
722 $statusisboring = in_array($statuscode, array(
723 plugin_manager::PLUGIN_STATUS_NODB, plugin_manager::PLUGIN_STATUS_UPTODATE));
725 $coredependency = $plugin->is_core_dependency_satisfied($version);
726 $otherpluginsdependencies = $pluginman->are_dependencies_satisfied($plugin->get_other_required_plugins());
727 $dependenciesok = $coredependency && $otherpluginsdependencies;
729 if ($options['xdep']) {
730 // we want to see only plugins with failed dependencies
731 if ($dependenciesok) {
732 continue;
735 } else if ($isstandard and $statusisboring and $dependenciesok and empty($availableupdates)) {
736 // no change is going to happen to the plugin - display it only
737 // if the user wants to see the full list
738 if (empty($options['full'])) {
739 continue;
743 // ok, the plugin should be displayed
744 $numofhighlighted[$type]++;
746 $row->cells = array($displayname, $rootdir, $source,
747 $versiondb, $versiondisk, $requires, $status);
748 $plugintyperows[] = $row;
751 if (empty($numofhighlighted[$type]) and empty($options['full'])) {
752 continue;
755 $table->data[] = $header;
756 $table->data = array_merge($table->data, $plugintyperows);
759 $sumofhighlighted = array_sum($numofhighlighted);
761 if ($options['xdep']) {
762 // we do not want to display no heading and links in this mode
763 $out = '';
765 } else if ($sumofhighlighted == 0) {
766 $out = $this->output->container_start('nonehighlighted', 'plugins-check-info');
767 $out .= $this->output->heading(get_string('nonehighlighted', 'core_plugin'));
768 if (empty($options['full'])) {
769 $out .= html_writer::link(new moodle_url('/admin/index.php',
770 array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1)),
771 get_string('nonehighlightedinfo', 'core_plugin'));
773 $out .= $this->output->container_end();
775 } else {
776 $out = $this->output->container_start('somehighlighted', 'plugins-check-info');
777 $out .= $this->output->heading(get_string('somehighlighted', 'core_plugin', $sumofhighlighted));
778 if (empty($options['full'])) {
779 $out .= html_writer::link(new moodle_url('/admin/index.php',
780 array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1)),
781 get_string('somehighlightedinfo', 'core_plugin'));
782 } else {
783 $out .= html_writer::link(new moodle_url('/admin/index.php',
784 array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 0)),
785 get_string('somehighlightedonly', 'core_plugin'));
787 $out .= $this->output->container_end();
790 if ($sumofhighlighted > 0 or $options['full']) {
791 $out .= html_writer::table($table);
794 return $out;
798 * Formats the information that needs to go in the 'Requires' column.
799 * @param plugininfo_base $plugin the plugin we are rendering the row for.
800 * @param plugin_manager $pluginman provides data on all the plugins.
801 * @param string $version
802 * @return string HTML code
804 protected function required_column(plugininfo_base $plugin, plugin_manager $pluginman, $version) {
805 $requires = array();
807 if (!empty($plugin->versionrequires)) {
808 if ($plugin->versionrequires <= $version) {
809 $class = 'requires-ok';
810 } else {
811 $class = 'requires-failed';
813 $requires[] = html_writer::tag('li',
814 get_string('moodleversion', 'core_plugin', $plugin->versionrequires),
815 array('class' => $class));
818 foreach ($plugin->get_other_required_plugins() as $component => $requiredversion) {
819 $ok = true;
820 $otherplugin = $pluginman->get_plugin_info($component);
822 if (is_null($otherplugin)) {
823 $ok = false;
824 } else if ($requiredversion != ANY_VERSION and $otherplugin->versiondisk < $requiredversion) {
825 $ok = false;
828 if ($ok) {
829 $class = 'requires-ok';
830 } else {
831 $class = 'requires-failed';
834 if ($requiredversion != ANY_VERSION) {
835 $str = 'otherpluginversion';
836 } else {
837 $str = 'otherplugin';
839 $requires[] = html_writer::tag('li',
840 get_string($str, 'core_plugin',
841 array('component' => $component, 'version' => $requiredversion)),
842 array('class' => $class));
845 if (!$requires) {
846 return '';
848 return html_writer::tag('ul', implode("\n", $requires));
852 * Prints an overview about the plugins - number of installed, number of extensions etc.
854 * @param plugin_manager $pluginman provides information about the plugins
855 * @return string as usually
857 public function plugins_overview_panel(plugin_manager $pluginman) {
858 global $CFG;
860 $plugininfo = $pluginman->get_plugins();
862 $numtotal = $numdisabled = $numextension = $numupdatable = 0;
864 foreach ($plugininfo as $type => $plugins) {
865 foreach ($plugins as $name => $plugin) {
866 if ($plugin->get_status() === plugin_manager::PLUGIN_STATUS_MISSING) {
867 continue;
869 $numtotal++;
870 if ($plugin->is_enabled() === false) {
871 $numdisabled++;
873 if (!$plugin->is_standard()) {
874 $numextension++;
876 if (empty($CFG->disableupdatenotifications) and $plugin->available_updates()) {
877 $numupdatable++;
882 $info = array();
883 $info[] = html_writer::tag('span', get_string('numtotal', 'core_plugin', $numtotal), array('class' => 'info total'));
884 $info[] = html_writer::tag('span', get_string('numdisabled', 'core_plugin', $numdisabled), array('class' => 'info disabled'));
885 $info[] = html_writer::tag('span', get_string('numextension', 'core_plugin', $numextension), array('class' => 'info extension'));
886 if ($numupdatable > 0) {
887 $info[] = html_writer::tag('span', get_string('numupdatable', 'core_plugin', $numupdatable), array('class' => 'info updatable'));
890 return $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $info), '', 'plugins-overview-panel');
894 * Displays all known plugins and links to manage them
896 * This default implementation renders all plugins into one big table.
898 * @param plugin_manager $pluginman provides information about the plugins.
899 * @return string HTML code
901 public function plugins_control_panel(plugin_manager $pluginman) {
902 global $CFG;
904 $plugininfo = $pluginman->get_plugins();
906 if (empty($plugininfo)) {
907 return '';
910 $table = new html_table();
911 $table->id = 'plugins-control-panel';
912 $table->head = array(
913 get_string('displayname', 'core_plugin'),
914 get_string('source', 'core_plugin'),
915 get_string('version', 'core_plugin'),
916 get_string('availability', 'core_plugin'),
917 get_string('actions', 'core_plugin'),
918 get_string('notes','core_plugin'),
920 $table->colclasses = array(
921 'pluginname', 'source', 'version', 'availability', 'actions', 'notes'
924 foreach ($plugininfo as $type => $plugins) {
926 $header = new html_table_cell($pluginman->plugintype_name_plural($type));
927 $header->header = true;
928 $header->colspan = count($table->head);
929 $header = new html_table_row(array($header));
930 $header->attributes['class'] = 'plugintypeheader type-' . $type;
931 $table->data[] = $header;
933 if (empty($plugins)) {
934 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
935 $msg->colspan = count($table->head);
936 $row = new html_table_row(array($msg));
937 $row->attributes['class'] .= 'msg msg-noneinstalled';
938 $table->data[] = $row;
939 continue;
942 foreach ($plugins as $name => $plugin) {
943 $row = new html_table_row();
944 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
946 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) {
947 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
948 } else {
949 $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon'));
951 if ($plugin->get_status() === plugin_manager::PLUGIN_STATUS_MISSING) {
952 $msg = html_writer::tag('span', get_string('status_missing', 'core_plugin'), array('class' => 'notifyproblem'));
953 $row->attributes['class'] .= ' missingfromdisk';
954 } else {
955 $msg = '';
957 $pluginname = html_writer::tag('div', $icon . ' ' . $plugin->displayname . ' ' . $msg, array('class' => 'displayname')).
958 html_writer::tag('div', $plugin->component, array('class' => 'componentname'));
959 $pluginname = new html_table_cell($pluginname);
961 if ($plugin->is_standard()) {
962 $row->attributes['class'] .= ' standard';
963 $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
964 } else {
965 $row->attributes['class'] .= ' extension';
966 $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
969 $version = new html_table_cell($plugin->versiondb);
971 $isenabled = $plugin->is_enabled();
972 if (is_null($isenabled)) {
973 $availability = new html_table_cell('');
974 } else if ($isenabled) {
975 $row->attributes['class'] .= ' enabled';
976 $icon = $this->output->pix_icon('i/hide', get_string('pluginenabled', 'core_plugin'));
977 $availability = new html_table_cell($icon . ' ' . get_string('pluginenabled', 'core_plugin'));
978 } else {
979 $row->attributes['class'] .= ' disabled';
980 $icon = $this->output->pix_icon('i/show', get_string('plugindisabled', 'core_plugin'));
981 $availability = new html_table_cell($icon . ' ' . get_string('plugindisabled', 'core_plugin'));
984 $actions = array();
986 $settingsurl = $plugin->get_settings_url();
987 if (!is_null($settingsurl)) {
988 $actions[] = html_writer::link($settingsurl, get_string('settings', 'core_plugin'), array('class' => 'settings'));
991 $uninstallurl = $plugin->get_uninstall_url();
992 if (!is_null($uninstallurl)) {
993 $actions[] = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin'), array('class' => 'uninstall'));
996 $actions = new html_table_cell(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $actions));
998 $requriedby = $pluginman->other_plugins_that_require($plugin->component);
999 if ($requriedby) {
1000 $requiredby = html_writer::tag('div', get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
1001 array('class' => 'requiredby'));
1002 } else {
1003 $requiredby = '';
1006 $updateinfo = '';
1007 if (empty($CFG->disableupdatenotifications) and is_array($plugin->available_updates())) {
1008 foreach ($plugin->available_updates() as $availableupdate) {
1009 $updateinfo .= $this->plugin_available_update_info($availableupdate);
1013 $notes = new html_table_cell($requiredby.$updateinfo);
1015 $row->cells = array(
1016 $pluginname, $source, $version, $availability, $actions, $notes
1018 $table->data[] = $row;
1022 return html_writer::table($table);
1026 * Helper method to render the information about the available plugin update
1028 * The passed objects always provides at least the 'version' property containing
1029 * the (higher) version of the plugin available.
1031 * @param available_update_info $updateinfo information about the available update for the plugin
1033 protected function plugin_available_update_info(available_update_info $updateinfo) {
1035 $boxclasses = 'pluginupdateinfo';
1036 $info = array();
1038 if (isset($updateinfo->release)) {
1039 $info[] = html_writer::tag('span', get_string('updateavailable_release', 'core_plugin', $updateinfo->release),
1040 array('class' => 'info release'));
1043 if (isset($updateinfo->maturity)) {
1044 $info[] = html_writer::tag('span', get_string('maturity'.$updateinfo->maturity, 'core_admin'),
1045 array('class' => 'info maturity'));
1046 $boxclasses .= ' maturity'.$updateinfo->maturity;
1049 if (isset($updateinfo->download)) {
1050 $info[] = html_writer::link($updateinfo->download, get_string('download'), array('class' => 'info download'));
1053 if (isset($updateinfo->url)) {
1054 $info[] = html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin'),
1055 array('class' => 'info more'));
1058 $box = $this->output->box_start($boxclasses);
1059 $box .= html_writer::tag('div', get_string('updateavailable', 'core_plugin', $updateinfo->version), array('class' => 'version'));
1060 $box .= $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $info), '');
1061 $box .= $this->output->box_end();
1063 return $box;
1067 * This function will render one beautiful table with all the environmental
1068 * configuration and how it suits Moodle needs.
1070 * @param boolean $result final result of the check (true/false)
1071 * @param array $environment_results array of results gathered
1072 * @return string HTML to output.
1074 public function environment_check_table($result, $environment_results) {
1075 global $CFG;
1077 // Table headers
1078 $servertable = new html_table();//table for server checks
1079 $servertable->head = array(
1080 get_string('name'),
1081 get_string('info'),
1082 get_string('report'),
1083 get_string('status'),
1085 $servertable->align = array('center', 'center', 'left', 'center');
1086 $servertable->wrap = array('nowrap', '', '', 'nowrap');
1087 $servertable->size = array('10', 10, '100%', '10');
1088 $servertable->attributes['class'] = 'environmenttable generaltable';
1090 $serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
1092 $othertable = new html_table();//table for custom checks
1093 $othertable->head = array(
1094 get_string('info'),
1095 get_string('report'),
1096 get_string('status'),
1098 $othertable->align = array('center', 'left', 'center');
1099 $othertable->wrap = array('', '', 'nowrap');
1100 $othertable->size = array(10, '100%', '10');
1101 $othertable->attributes['class'] = 'environmenttable generaltable';
1103 $otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
1105 // Iterate over each environment_result
1106 $continue = true;
1107 foreach ($environment_results as $environment_result) {
1108 $errorline = false;
1109 $warningline = false;
1110 $stringtouse = '';
1111 if ($continue) {
1112 $type = $environment_result->getPart();
1113 $info = $environment_result->getInfo();
1114 $status = $environment_result->getStatus();
1115 $error_code = $environment_result->getErrorCode();
1116 // Process Report field
1117 $rec = new stdClass();
1118 // Something has gone wrong at parsing time
1119 if ($error_code) {
1120 $stringtouse = 'environmentxmlerror';
1121 $rec->error_code = $error_code;
1122 $status = get_string('error');
1123 $errorline = true;
1124 $continue = false;
1127 if ($continue) {
1128 if ($rec->needed = $environment_result->getNeededVersion()) {
1129 // We are comparing versions
1130 $rec->current = $environment_result->getCurrentVersion();
1131 if ($environment_result->getLevel() == 'required') {
1132 $stringtouse = 'environmentrequireversion';
1133 } else {
1134 $stringtouse = 'environmentrecommendversion';
1137 } else if ($environment_result->getPart() == 'custom_check') {
1138 // We are checking installed & enabled things
1139 if ($environment_result->getLevel() == 'required') {
1140 $stringtouse = 'environmentrequirecustomcheck';
1141 } else {
1142 $stringtouse = 'environmentrecommendcustomcheck';
1145 } else if ($environment_result->getPart() == 'php_setting') {
1146 if ($status) {
1147 $stringtouse = 'environmentsettingok';
1148 } else if ($environment_result->getLevel() == 'required') {
1149 $stringtouse = 'environmentmustfixsetting';
1150 } else {
1151 $stringtouse = 'environmentshouldfixsetting';
1154 } else {
1155 if ($environment_result->getLevel() == 'required') {
1156 $stringtouse = 'environmentrequireinstall';
1157 } else {
1158 $stringtouse = 'environmentrecommendinstall';
1162 // Calculate the status value
1163 if ($environment_result->getBypassStr() != '') { //Handle bypassed result (warning)
1164 $status = get_string('bypassed');
1165 $warningline = true;
1166 } else if ($environment_result->getRestrictStr() != '') { //Handle restricted result (error)
1167 $status = get_string('restricted');
1168 $errorline = true;
1169 } else {
1170 if ($status) { //Handle ok result (ok)
1171 $status = get_string('ok');
1172 } else {
1173 if ($environment_result->getLevel() == 'optional') {//Handle check result (warning)
1174 $status = get_string('check');
1175 $warningline = true;
1176 } else { //Handle error result (error)
1177 $status = get_string('check');
1178 $errorline = true;
1184 // Build the text
1185 $linkparts = array();
1186 $linkparts[] = 'admin/environment';
1187 $linkparts[] = $type;
1188 if (!empty($info)){
1189 $linkparts[] = $info;
1191 if (empty($CFG->docroot)) {
1192 $report = get_string($stringtouse, 'admin', $rec);
1193 } else {
1194 $report = $this->doc_link(join($linkparts, '/'), get_string($stringtouse, 'admin', $rec));
1197 // Format error or warning line
1198 if ($errorline || $warningline) {
1199 $messagetype = $errorline? 'error':'warn';
1200 } else {
1201 $messagetype = 'ok';
1203 $status = '<span class="'.$messagetype.'">'.$status.'</span>';
1204 // Here we'll store all the feedback found
1205 $feedbacktext = '';
1206 // Append the feedback if there is some
1207 $feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), $messagetype);
1208 //Append the bypass if there is some
1209 $feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'warn');
1210 //Append the restrict if there is some
1211 $feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'error');
1213 $report .= $feedbacktext;
1215 // Add the row to the table
1216 if ($environment_result->getPart() == 'custom_check'){
1217 $otherdata[$messagetype][] = array ($info, $report, $status);
1218 } else {
1219 $serverdata[$messagetype][] = array ($type, $info, $report, $status);
1224 //put errors first in
1225 $servertable->data = array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']);
1226 $othertable->data = array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']);
1228 // Print table
1229 $output = '';
1230 $output .= $this->heading(get_string('serverchecks', 'admin'));
1231 $output .= html_writer::table($servertable);
1232 if (count($othertable->data)){
1233 $output .= $this->heading(get_string('customcheck', 'admin'));
1234 $output .= html_writer::table($othertable);
1237 // Finally, if any error has happened, print the summary box
1238 if (!$result) {
1239 $output .= $this->box(get_string('environmenterrortodo', 'admin'), 'environmentbox errorbox');
1242 return $output;