MDL-35238 Handle the update installation request - display the confirmation page
[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');
774c42a8 71 $output .= format_text(get_string('upgradestalefilesinfo', 'admin', get_docs_url('Upgrading')), FORMAT_MARKDOWN);
9008ec16
PS
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
39f15cc7
DM
110 /**
111 * Displays the list of plugins with unsatisfied dependencies
112 *
113 * @param double|string|int $version Moodle on-disk version
114 * @param array $failed list of plugins with unsatisfied dependecies
e937c545 115 * @param moodle_url $reloadurl URL of the page to recheck the dependencies
39f15cc7
DM
116 * @return string HTML
117 */
118 public function unsatisfied_dependencies_page($version, array $failed, moodle_url $reloadurl) {
119 $output = '';
120
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);
127
128 $output .= $this->footer();
129
130 return $output;
131 }
132
cc359566
TH
133 /**
134 * Display the 'You are about to upgrade Moodle' page. The first page
135 * during upgrade.
8d1da748
PS
136 * @param string $strnewversion
137 * @param int $maturity
cc359566
TH
138 * @return string HTML to output.
139 */
140 public function upgrade_confirm_page($strnewversion, $maturity) {
141 $output = '';
142
143 $continueurl = new moodle_url('index.php', array('confirmupgrade' => 1));
144 $cancelurl = new moodle_url('index.php');
145
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();
150
151 return $output;
152 }
153
154 /**
155 * Display the environment page during the upgrade process.
8d1da748
PS
156 * @param string $release
157 * @param boolean $envstatus final result of env check (true/false)
158 * @param array $environment_results array of results gathered
cc359566
TH
159 * @return string HTML to output.
160 */
161 public function upgrade_environment_page($release, $envstatus, $environment_results) {
162 global $CFG;
163 $output = '';
164
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);
169
170 if (!$envstatus) {
171 $output .= $this->upgrade_reload(new moodle_url('/admin/index.php'), array('confirmupgrade' => 1));
172
173 } else {
faadd326 174 $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
cc359566
TH
175
176 if (empty($CFG->skiplangupgrade) and current_language() !== 'en') {
177 $output .= $this->box(get_string('langpackwillbeupdated', 'admin'), 'generalbox', 'notice');
178 }
179
180 $output .= $this->continue_button(new moodle_url('/admin/index.php', array('confirmupgrade' => 1, 'confirmrelease' => 1)));
181 }
182
183 $output .= $this->footer();
184
185 return $output;
186 }
187
188 /**
189 * Display the upgrade page that lists all the plugins that require attention.
8d1da748 190 * @param plugin_manager $pluginman provides information about the plugins.
96dd9237 191 * @param available_update_checker $checker provides information about available updates.
8d1da748
PS
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
cc359566
TH
196 * @return string HTML to output.
197 */
96dd9237
DM
198 public function upgrade_plugin_check_page(plugin_manager $pluginman, available_update_checker $checker,
199 $version, $showallplugins, $reloadurl, $continueurl) {
fa1d403f 200 global $CFG;
96dd9237 201
cc359566
TH
202 $output = '';
203
204 $output .= $this->header();
205 $output .= $this->box_start('generalbox');
96dd9237
DM
206 $output .= $this->container_start('generalbox', 'notice');
207 $output .= html_writer::tag('p', get_string('pluginchecknotice', 'core_plugin'));
fa1d403f
DM
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'))));
214 }
215 $output .= $this->container_end();
96dd9237
DM
216 }
217 $output .= $this->container_end();
96dd9237 218
faadd326 219 $output .= $this->plugins_check_table($pluginman, $version, array('full' => $showallplugins));
cc359566
TH
220 $output .= $this->box_end();
221 $output .= $this->upgrade_reload($reloadurl);
222
ead8ba3b
DM
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();
faadd326 227 }
cc359566 228
ead8ba3b
DM
229 $button = new single_button($continueurl, get_string('upgradestart', 'admin'), 'get');
230 $button->class = 'continuebutton';
231 $output .= $this->render($button);
cc359566
TH
232 $output .= $this->footer();
233
234 return $output;
235 }
236
237 /**
238 * Display the admin notifications page.
8d1da748
PS
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
0aff15c2 245 * @param bool $buggyiconvnomb warn iconv problems
55585f3a
DM
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)
248 *
cc359566
TH
249 * @return string HTML to output.
250 */
251 public function admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed,
b3245b75
DP
252 $cronoverdue, $dbproblems, $maintenancemode, $availableupdates, $availableupdatesfetch,
253 $buggyiconvnomb, $registered) {
4db58f5f 254 global $CFG;
cc359566
TH
255 $output = '';
256
257 $output .= $this->header();
258 $output .= $this->maturity_info($maturity);
4db58f5f 259 $output .= empty($CFG->disableupdatenotifications) ? $this->available_updates($availableupdates, $availableupdatesfetch) : '';
cc359566
TH
260 $output .= $this->insecure_dataroot_warning($insecuredataroot);
261 $output .= $this->display_errors_warning($errorsdisplayed);
0aff15c2 262 $output .= $this->buggy_iconv_warning($buggyiconvnomb);
e3258164 263 $output .= $this->cron_overdue_warning($cronoverdue);
cc359566
TH
264 $output .= $this->db_problems($dbproblems);
265 $output .= $this->maintenance_mode_warning($maintenancemode);
b3245b75 266 $output .= $this->registration_warning($registered);
cc359566
TH
267
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 //////////////////////////////////////////////////////////////////////////////////////////////////
272
273 $output .= $this->footer();
274
275 return $output;
276 }
277
8342171b
DM
278 /**
279 * Display the plugin management page (admin/plugins.php).
280 *
4df8bced
DM
281 * The filtering options array may contain following items:
282 * bool contribonly - show only contributed extensions
283 * bool updatesonly - show only plugins with an available update
284 *
8342171b
DM
285 * @param plugin_manager $pluginman
286 * @param available_update_checker $checker
4df8bced 287 * @param array $options filtering options
8342171b
DM
288 * @return string HTML to output.
289 */
4df8bced 290 public function plugin_management_page(plugin_manager $pluginman, available_update_checker $checker, array $options = array()) {
7716057f
DM
291 global $CFG;
292
8342171b
DM
293 $output = '';
294
295 $output .= $this->header();
296 $output .= $this->heading(get_string('pluginsoverview', 'core_admin'));
4df8bced 297 $output .= $this->plugins_overview_panel($pluginman, $options);
8342171b 298
7716057f
DM
299 if (empty($CFG->disableupdatenotifications)) {
300 $output .= $this->container_start('checkforupdates');
4df8bced
DM
301 $output .= $this->single_button(
302 new moodle_url($this->page->url, array_merge($options, array('fetchremote' => 1))),
303 get_string('checkforupdates', 'core_plugin')
304 );
7716057f
DM
305 if ($timefetched = $checker->get_last_timefetched()) {
306 $output .= $this->container(get_string('checkforupdateslast', 'core_plugin',
307 userdate($timefetched, get_string('strftimedatetime', 'core_langconfig'))));
308 }
309 $output .= $this->container_end();
8342171b 310 }
8342171b 311
4df8bced 312 $output .= $this->box($this->plugins_control_panel($pluginman, $options), 'generalbox');
8342171b
DM
313 $output .= $this->footer();
314
315 return $output;
316 }
317
cc359566
TH
318 /**
319 * Display the plugin management page (admin/environment.php).
8d1da748
PS
320 * @param array $versions
321 * @param string $version
322 * @param boolean $envstatus final result of env check (true/false)
323 * @param array $environment_results array of results gathered
cc359566
TH
324 * @return string HTML to output.
325 */
326 public function environment_check_page($versions, $version, $envstatus, $environment_results) {
327 $output = '';
328 $output .= $this->header();
329
330 // Print the component download link
331 $output .= html_writer::tag('div', html_writer::link(
332 new moodle_url('/admin/environment.php', array('action' => 'updatecomponent', 'sesskey' => sesskey())),
333 get_string('updatecomponent', 'admin')),
334 array('class' => 'reportlink'));
335
336 // Heading.
337 $output .= $this->heading(get_string('environment', 'admin'));
338
339 // Box with info and a menu to choose the version.
340 $output .= $this->box_start();
341 $output .= html_writer::tag('div', get_string('adminhelpenvironment'));
342 $select = new single_select(new moodle_url('/admin/environment.php'), 'version', $versions, $version, null);
343 $select->label = get_string('moodleversion');
344 $output .= $this->render($select);
345 $output .= $this->box_end();
346
347 // The results
348 $output .= $this->environment_check_table($envstatus, $environment_results);
349
350 $output .= $this->footer();
351 return $output;
352 }
353
354 /**
355 * Output a warning message, of the type that appears on the admin notifications page.
356 * @param string $message the message to display.
8d1da748 357 * @param string $type type class
cc359566
TH
358 * @return string HTML to output.
359 */
360 protected function warning($message, $type = 'warning') {
361 return $this->box($message, 'generalbox admin' . $type);
362 }
363
364 /**
365 * Render an appropriate message if dataroot is insecure.
8d1da748 366 * @param bool $insecuredataroot
cc359566
TH
367 * @return string HTML to output.
368 */
369 protected function insecure_dataroot_warning($insecuredataroot) {
370 global $CFG;
371
372 if ($insecuredataroot == INSECURE_DATAROOT_WARNING) {
373 return $this->warning(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot));
374
375 } else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) {
376 return $this->warning(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'error');
377
378 } else {
379 return '';
380 }
381 }
382
383 /**
384 * Render an appropriate message if dataroot is insecure.
8d1da748 385 * @param bool $errorsdisplayed
cc359566
TH
386 * @return string HTML to output.
387 */
388 protected function display_errors_warning($errorsdisplayed) {
389 if (!$errorsdisplayed) {
390 return '';
391 }
392
393 return $this->warning(get_string('displayerrorswarning', 'admin'));
394 }
395
0aff15c2
PS
396 /**
397 * Render an appropriate message if iconv is buggy and mbstring missing.
398 * @param bool $buggyiconvnomb
399 * @return string HTML to output.
400 */
401 protected function buggy_iconv_warning($buggyiconvnomb) {
402 if (!$buggyiconvnomb) {
403 return '';
404 }
405
406 return $this->warning(get_string('warningiconvbuggy', 'admin'));
407 }
408
cc359566
TH
409 /**
410 * Render an appropriate message if cron has not been run recently.
8d1da748 411 * @param bool $cronoverdue
cc359566
TH
412 * @return string HTML to output.
413 */
414 public function cron_overdue_warning($cronoverdue) {
415 if (!$cronoverdue) {
416 return '';
417 }
418
419 return $this->warning(get_string('cronwarning', 'admin') . '&nbsp;' .
420 $this->help_icon('cron', 'admin'));
421 }
422
423 /**
424 * Render an appropriate message if there are any problems with the DB set-up.
8d1da748 425 * @param bool $dbproblems
cc359566
TH
426 * @return string HTML to output.
427 */
428 public function db_problems($dbproblems) {
429 if (!$dbproblems) {
430 return '';
431 }
432
433 return $this->warning($dbproblems);
434 }
435
436 /**
437 * Render an appropriate message if the site in in maintenance mode.
8d1da748 438 * @param bool $maintenancemode
cc359566
TH
439 * @return string HTML to output.
440 */
441 public function maintenance_mode_warning($maintenancemode) {
442 if (!$maintenancemode) {
443 return '';
444 }
445
ecc2897c
PS
446 $url = new moodle_url('/admin/settings.php', array('section' => 'maintenancemode'));
447 $url = $url->out(); // get_string() does not support objects in params
448
449 return $this->warning(get_string('sitemaintenancewarning2', 'admin', $url));
cc359566
TH
450 }
451
452 /**
453 * Display a warning about installing development code if necesary.
8d1da748 454 * @param int $maturity
cc359566
TH
455 * @return string HTML to output.
456 */
457 protected function maturity_warning($maturity) {
458 if ($maturity == MATURITY_STABLE) {
459 return ''; // No worries.
460 }
461
462 $maturitylevel = get_string('maturity' . $maturity, 'admin');
463 return $this->box(
464 $this->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
465 $this->container($this->doc_link('admin/versions', get_string('morehelp'))),
466 'generalbox maturitywarning');
467 }
468
469 /**
470 * Output the copyright notice.
471 * @return string HTML to output.
472 */
473 protected function moodle_copyright() {
474 global $CFG;
475
476 //////////////////////////////////////////////////////////////////////////////////////////////////
477 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
478 $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
479 '<a href="http://docs.moodle.org/dev/Releases" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
480 'Copyright &copy; 1999 onwards, Martin Dougiamas<br />'.
956082f1 481 'and <a href="http://moodle.org/dev">many other contributors</a>.<br />'.
cc359566
TH
482 '<a href="http://docs.moodle.org/dev/License">GNU Public License</a>';
483 //////////////////////////////////////////////////////////////////////////////////////////////////
484
485 return $this->box($copyrighttext, 'copyright');
486 }
487
488 /**
489 * Display a warning about installing development code if necesary.
8d1da748
PS
490 * @param int $maturity
491 * @return string HTML to output.
cc359566
TH
492 */
493 protected function maturity_info($maturity) {
494 if ($maturity == MATURITY_STABLE) {
495 return ''; // No worries.
496 }
497
498 $maturitylevel = get_string('maturity' . $maturity, 'admin');
499 return $this->box(
500 get_string('maturitycoreinfo', 'admin', $maturitylevel) . ' ' .
501 $this->doc_link('admin/versions', get_string('morehelp')),
37f75ad4 502 'generalbox adminwarning maturityinfo maturity'.$maturity);
cc359566
TH
503 }
504
55585f3a 505 /**
966bd785 506 * Displays the info about available Moodle core and plugin updates
55585f3a 507 *
966bd785
DM
508 * The structure of the $updates param has changed since 2.4. It contains not only updates
509 * for the core itself, but also for all other installed plugins.
510 *
511 * @param array|null $updates array of (string)component => array of available_update_info objects or null
55585f3a
DM
512 * @param int|null $fetch timestamp of the most recent updates fetch or null (unknown)
513 * @return string
514 */
515 protected function available_updates($updates, $fetch) {
516
517 $updateinfo = $this->box_start('generalbox adminwarning availableupdatesinfo');
966bd785 518 $someupdateavailable = false;
55585f3a 519 if (is_array($updates)) {
966bd785
DM
520 if (is_array($updates['core'])) {
521 $someupdateavailable = true;
522 $updateinfo .= $this->heading(get_string('updateavailable', 'core_admin'), 3);
523 foreach ($updates['core'] as $update) {
524 $updateinfo .= $this->moodle_available_update_info($update);
525 }
55585f3a 526 }
966bd785
DM
527 unset($updates['core']);
528 // If something has left in the $updates array now, it is updates for plugins.
529 if (!empty($updates)) {
530 $someupdateavailable = true;
531 $updateinfo .= $this->heading(get_string('updateavailableforplugin', 'core_admin'), 3);
532 $pluginsoverviewurl = new moodle_url('/admin/plugins.php', array('updatesonly' => 1));
533 $updateinfo .= $this->container(get_string('pluginsoverviewsee', 'core_admin',
534 array('url' => $pluginsoverviewurl->out())));
535 }
536 }
537
538 if (!$someupdateavailable) {
cb1c3291
DM
539 $now = time();
540 if ($fetch and ($fetch <= $now) and ($now - $fetch < HOURSECS)) {
541 $updateinfo .= $this->heading(get_string('updateavailablenot', 'core_admin'), 3);
542 }
55585f3a
DM
543 }
544
545 $updateinfo .= $this->container_start('checkforupdates');
546 $updateinfo .= $this->single_button(new moodle_url($this->page->url, array('fetchupdates' => 1)), get_string('checkforupdates', 'core_plugin'));
547 if ($fetch) {
548 $updateinfo .= $this->container(get_string('checkforupdateslast', 'core_plugin',
549 userdate($fetch, get_string('strftimedatetime', 'core_langconfig'))));
550 }
551 $updateinfo .= $this->container_end();
552
553 $updateinfo .= $this->box_end();
554
555 return $updateinfo;
556 }
557
b3245b75
DP
558 /**
559 * Display a warning about not being registered on Moodle.org if necesary.
560 *
561 * @param boolean $registered true if the site is registered on Moodle.org
562 * @return string HTML to output.
563 */
564 protected function registration_warning($registered) {
565
566 if (!$registered) {
567
568 $registerbutton = $this->single_button(new moodle_url('registration/register.php',
569 array('huburl' => HUB_MOODLEORGHUBURL, 'hubname' => 'Moodle.org')),
570 get_string('register', 'admin'));
571
572 return $this->warning( get_string('registrationwarning', 'admin')
573 . '&nbsp;' . $this->help_icon('registration', 'admin') . $registerbutton );
574 }
575
576 return '';
577 }
578
55585f3a
DM
579 /**
580 * Helper method to render the information about the available Moodle update
581 *
582 * @param available_update_info $updateinfo information about the available Moodle core update
583 */
584 protected function moodle_available_update_info(available_update_info $updateinfo) {
585
586 $boxclasses = 'moodleupdateinfo';
587 $info = array();
588
589 if (isset($updateinfo->release)) {
590 $info[] = html_writer::tag('span', get_string('updateavailable_release', 'core_admin', $updateinfo->release),
591 array('class' => 'info release'));
592 }
593
594 if (isset($updateinfo->version)) {
595 $info[] = html_writer::tag('span', get_string('updateavailable_version', 'core_admin', $updateinfo->version),
596 array('class' => 'info version'));
597 }
598
599 if (isset($updateinfo->maturity)) {
600 $info[] = html_writer::tag('span', get_string('maturity'.$updateinfo->maturity, 'core_admin'),
601 array('class' => 'info maturity'));
602 $boxclasses .= ' maturity'.$updateinfo->maturity;
603 }
604
605 if (isset($updateinfo->download)) {
606 $info[] = html_writer::link($updateinfo->download, get_string('download'), array('class' => 'info download'));
607 }
608
609 if (isset($updateinfo->url)) {
610 $info[] = html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin'),
611 array('class' => 'info more'));
612 }
613
614 $box = $this->output->box_start($boxclasses);
615 $box .= $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $info), '');
616 $box .= $this->output->box_end();
617
618 return $box;
619 }
620
cc359566
TH
621 /**
622 * Display a link to the release notes.
8d1da748 623 * @return string HTML to output.
cc359566
TH
624 */
625 protected function release_notes_link() {
626 $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/dev/Releases');
627 $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
628 return $this->box($releasenoteslink, 'generalbox releasenoteslink');
629 }
630
631 /**
632 * Display the reload link that appears on several upgrade/install pages.
8d1da748 633 * @return string HTML to output.
cc359566
TH
634 */
635 function upgrade_reload($url) {
636 return html_writer::empty_tag('br') .
637 html_writer::tag('div',
638 html_writer::link($url, $this->pix_icon('i/reload', '') .
639 get_string('reload'), array('title' => get_string('reload'))),
640 array('class' => 'continuebutton')) . html_writer::empty_tag('br');
641 }
642
b9934a17
DM
643 /**
644 * Displays all known plugins and information about their installation or upgrade
645 *
646 * This default implementation renders all plugins into one big table. The rendering
647 * options support:
648 * (bool)full = false: whether to display up-to-date plugins, too
39f15cc7 649 * (bool)xdep = false: display the plugins with unsatisified dependecies only
b9934a17 650 *
36ca62ca 651 * @param plugin_manager $pluginman provides information about the plugins.
faadd326 652 * @param int $version the version of the Moodle code from version.php.
b9934a17
DM
653 * @param array $options rendering options
654 * @return string HTML code
655 */
39f15cc7 656 public function plugins_check_table(plugin_manager $pluginman, $version, array $options = array()) {
fa1d403f
DM
657 global $CFG;
658
36ca62ca 659 $plugininfo = $pluginman->get_plugins();
b9934a17
DM
660
661 if (empty($plugininfo)) {
662 return '';
663 }
664
39f15cc7
DM
665 $options['full'] = isset($options['full']) ? (bool)$options['full'] : false;
666 $options['xdep'] = isset($options['xdep']) ? (bool)$options['xdep'] : false;
b9934a17 667
b9934a17
DM
668 $table = new html_table();
669 $table->id = 'plugins-check';
670 $table->head = array(
671 get_string('displayname', 'core_plugin'),
672 get_string('rootdir', 'core_plugin'),
673 get_string('source', 'core_plugin'),
674 get_string('versiondb', 'core_plugin'),
675 get_string('versiondisk', 'core_plugin'),
36ca62ca 676 get_string('requires', 'core_plugin'),
b9934a17
DM
677 get_string('status', 'core_plugin'),
678 );
679 $table->colclasses = array(
36ca62ca 680 'displayname', 'rootdir', 'source', 'versiondb', 'versiondisk', 'requires', 'status',
b9934a17
DM
681 );
682 $table->data = array();
683
684 $numofhighlighted = array(); // number of highlighted rows per this subsection
685
686 foreach ($plugininfo as $type => $plugins) {
687
688 $header = new html_table_cell($pluginman->plugintype_name_plural($type));
689 $header->header = true;
690 $header->colspan = count($table->head);
691 $header = new html_table_row(array($header));
692 $header->attributes['class'] = 'plugintypeheader type-' . $type;
693
694 $numofhighlighted[$type] = 0;
695
696 if (empty($plugins) and $options['full']) {
697 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
698 $msg->colspan = count($table->head);
699 $row = new html_table_row(array($msg));
700 $row->attributes['class'] .= 'msg msg-noneinstalled';
701 $table->data[] = $header;
702 $table->data[] = $row;
703 continue;
704 }
705
706 $plugintyperows = array();
707
708 foreach ($plugins as $name => $plugin) {
709 $row = new html_table_row();
710 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
711
436dbeec 712 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name, null)) {
b9934a17
DM
713 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
714 } else {
715 $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon'));
716 }
717 $displayname = $icon . ' ' . $plugin->displayname;
718 $displayname = new html_table_cell($displayname);
719
720 $rootdir = new html_table_cell($plugin->get_dir());
721
722 if ($isstandard = $plugin->is_standard()) {
723 $row->attributes['class'] .= ' standard';
724 $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
725 } else {
726 $row->attributes['class'] .= ' extension';
727 $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
728 }
729
730 $versiondb = new html_table_cell($plugin->versiondb);
731 $versiondisk = new html_table_cell($plugin->versiondisk);
732
733 $statuscode = $plugin->get_status();
734 $row->attributes['class'] .= ' status-' . $statuscode;
96dd9237
DM
735 $status = get_string('status_' . $statuscode, 'core_plugin');
736
737 $availableupdates = $plugin->available_updates();
fa1d403f 738 if (!empty($availableupdates) and empty($CFG->disableupdatenotifications)) {
96dd9237
DM
739 foreach ($availableupdates as $availableupdate) {
740 $status .= $this->plugin_available_update_info($availableupdate);
741 }
742 }
b9934a17 743
96dd9237 744 $status = new html_table_cell($status);
b9934a17 745
faadd326 746 $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version));
36ca62ca
TH
747
748 $statusisboring = in_array($statuscode, array(
749 plugin_manager::PLUGIN_STATUS_NODB, plugin_manager::PLUGIN_STATUS_UPTODATE));
e937c545
DM
750
751 $coredependency = $plugin->is_core_dependency_satisfied($version);
752 $otherpluginsdependencies = $pluginman->are_dependencies_satisfied($plugin->get_other_required_plugins());
753 $dependenciesok = $coredependency && $otherpluginsdependencies;
39f15cc7
DM
754
755 if ($options['xdep']) {
756 // we want to see only plugins with failed dependencies
757 if ($dependenciesok) {
758 continue;
759 }
760
761 } else if ($isstandard and $statusisboring and $dependenciesok and empty($availableupdates)) {
762 // no change is going to happen to the plugin - display it only
763 // if the user wants to see the full list
b9934a17
DM
764 if (empty($options['full'])) {
765 continue;
766 }
b9934a17
DM
767 }
768
39f15cc7
DM
769 // ok, the plugin should be displayed
770 $numofhighlighted[$type]++;
771
36ca62ca
TH
772 $row->cells = array($displayname, $rootdir, $source,
773 $versiondb, $versiondisk, $requires, $status);
b9934a17
DM
774 $plugintyperows[] = $row;
775 }
776
777 if (empty($numofhighlighted[$type]) and empty($options['full'])) {
778 continue;
779 }
780
781 $table->data[] = $header;
782 $table->data = array_merge($table->data, $plugintyperows);
783 }
784
785 $sumofhighlighted = array_sum($numofhighlighted);
786
39f15cc7
DM
787 if ($options['xdep']) {
788 // we do not want to display no heading and links in this mode
789 $out = '';
790
791 } else if ($sumofhighlighted == 0) {
b9934a17
DM
792 $out = $this->output->container_start('nonehighlighted', 'plugins-check-info');
793 $out .= $this->output->heading(get_string('nonehighlighted', 'core_plugin'));
794 if (empty($options['full'])) {
795 $out .= html_writer::link(new moodle_url('/admin/index.php',
796 array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1)),
797 get_string('nonehighlightedinfo', 'core_plugin'));
798 }
799 $out .= $this->output->container_end();
800
801 } else {
802 $out = $this->output->container_start('somehighlighted', 'plugins-check-info');
803 $out .= $this->output->heading(get_string('somehighlighted', 'core_plugin', $sumofhighlighted));
804 if (empty($options['full'])) {
805 $out .= html_writer::link(new moodle_url('/admin/index.php',
806 array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1)),
807 get_string('somehighlightedinfo', 'core_plugin'));
a687fcac
DM
808 } else {
809 $out .= html_writer::link(new moodle_url('/admin/index.php',
810 array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 0)),
811 get_string('somehighlightedonly', 'core_plugin'));
b9934a17
DM
812 }
813 $out .= $this->output->container_end();
814 }
815
816 if ($sumofhighlighted > 0 or $options['full']) {
817 $out .= html_writer::table($table);
818 }
819
820 return $out;
821 }
822
36ca62ca
TH
823 /**
824 * Formats the information that needs to go in the 'Requires' column.
b6ad8594 825 * @param plugininfo_base $plugin the plugin we are rendering the row for.
36ca62ca 826 * @param plugin_manager $pluginman provides data on all the plugins.
8d1da748
PS
827 * @param string $version
828 * @return string HTML code
36ca62ca 829 */
b6ad8594 830 protected function required_column(plugininfo_base $plugin, plugin_manager $pluginman, $version) {
36ca62ca
TH
831 $requires = array();
832
833 if (!empty($plugin->versionrequires)) {
faadd326 834 if ($plugin->versionrequires <= $version) {
36ca62ca
TH
835 $class = 'requires-ok';
836 } else {
837 $class = 'requires-failed';
838 }
839 $requires[] = html_writer::tag('li',
840 get_string('moodleversion', 'core_plugin', $plugin->versionrequires),
841 array('class' => $class));
842 }
843
844 foreach ($plugin->get_other_required_plugins() as $component => $requiredversion) {
845 $ok = true;
846 $otherplugin = $pluginman->get_plugin_info($component);
847
848 if (is_null($otherplugin)) {
849 $ok = false;
499ff0a9 850 } else if ($requiredversion != ANY_VERSION and $otherplugin->versiondisk < $requiredversion) {
36ca62ca
TH
851 $ok = false;
852 }
853
854 if ($ok) {
855 $class = 'requires-ok';
856 } else {
857 $class = 'requires-failed';
858 }
859
860 if ($requiredversion != ANY_VERSION) {
861 $str = 'otherpluginversion';
862 } else {
863 $str = 'otherplugin';
864 }
865 $requires[] = html_writer::tag('li',
866 get_string($str, 'core_plugin',
867 array('component' => $component, 'version' => $requiredversion)),
868 array('class' => $class));
869 }
870
871 if (!$requires) {
872 return '';
873 }
874 return html_writer::tag('ul', implode("\n", $requires));
875 }
876
d26f3ddd
DM
877 /**
878 * Prints an overview about the plugins - number of installed, number of extensions etc.
879 *
880 * @param plugin_manager $pluginman provides information about the plugins
4df8bced 881 * @param array $options filtering options
d26f3ddd
DM
882 * @return string as usually
883 */
4df8bced 884 public function plugins_overview_panel(plugin_manager $pluginman, array $options = array()) {
7716057f
DM
885 global $CFG;
886
d26f3ddd
DM
887 $plugininfo = $pluginman->get_plugins();
888
889 $numtotal = $numdisabled = $numextension = $numupdatable = 0;
890
891 foreach ($plugininfo as $type => $plugins) {
892 foreach ($plugins as $name => $plugin) {
893 if ($plugin->get_status() === plugin_manager::PLUGIN_STATUS_MISSING) {
894 continue;
895 }
896 $numtotal++;
897 if ($plugin->is_enabled() === false) {
898 $numdisabled++;
899 }
900 if (!$plugin->is_standard()) {
901 $numextension++;
902 }
7716057f 903 if (empty($CFG->disableupdatenotifications) and $plugin->available_updates()) {
d26f3ddd
DM
904 $numupdatable++;
905 }
906 }
907 }
908
909 $info = array();
4df8bced
DM
910 $filter = array();
911 $somefilteractive = false;
d26f3ddd
DM
912 $info[] = html_writer::tag('span', get_string('numtotal', 'core_plugin', $numtotal), array('class' => 'info total'));
913 $info[] = html_writer::tag('span', get_string('numdisabled', 'core_plugin', $numdisabled), array('class' => 'info disabled'));
914 $info[] = html_writer::tag('span', get_string('numextension', 'core_plugin', $numextension), array('class' => 'info extension'));
4df8bced
DM
915 if ($numextension > 0) {
916 if (empty($options['contribonly'])) {
917 $filter[] = html_writer::link(
918 new moodle_url($this->page->url, array('contribonly' => 1)),
919 get_string('filtercontribonly', 'core_plugin'),
920 array('class' => 'filter-item show-contribonly')
921 );
922 } else {
923 $filter[] = html_writer::tag('span', get_string('filtercontribonlyactive', 'core_plugin'),
924 array('class' => 'filter-item active show-contribonly'));
925 $somefilteractive = true;
926 }
927 }
d26f3ddd
DM
928 if ($numupdatable > 0) {
929 $info[] = html_writer::tag('span', get_string('numupdatable', 'core_plugin', $numupdatable), array('class' => 'info updatable'));
4df8bced
DM
930 if (empty($options['updatesonly'])) {
931 $filter[] = html_writer::link(
932 new moodle_url($this->page->url, array('updatesonly' => 1)),
933 get_string('filterupdatesonly', 'core_plugin'),
934 array('class' => 'filter-item show-updatesonly')
935 );
936 } else {
937 $filter[] = html_writer::tag('span', get_string('filterupdatesonlyactive', 'core_plugin'),
938 array('class' => 'filter-item active show-updatesonly'));
939 $somefilteractive = true;
940 }
d26f3ddd 941 }
4df8bced
DM
942 if ($somefilteractive) {
943 $filter[] = html_writer::link($this->page->url, get_string('filterall', 'core_plugin'), array('class' => 'filter-item show-all'));
944 }
945
946 $output = $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $info), '', 'plugins-overview-panel');
d26f3ddd 947
4df8bced
DM
948 if (!empty($filter)) {
949 $output .= $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $filter), '', 'plugins-overview-filter');
950 }
951
952 return $output;
d26f3ddd
DM
953 }
954
b9934a17
DM
955 /**
956 * Displays all known plugins and links to manage them
957 *
958 * This default implementation renders all plugins into one big table.
959 *
36ca62ca 960 * @param plugin_manager $pluginman provides information about the plugins.
4df8bced 961 * @param array $options filtering options
b9934a17
DM
962 * @return string HTML code
963 */
4df8bced 964 public function plugins_control_panel(plugin_manager $pluginman, array $options = array()) {
7716057f
DM
965 global $CFG;
966
36ca62ca 967 $plugininfo = $pluginman->get_plugins();
b9934a17 968
4df8bced
DM
969 // Filter the list of plugins according the options.
970 if (!empty($options['updatesonly'])) {
971 $updateable = array();
972 foreach ($plugininfo as $plugintype => $pluginnames) {
973 foreach ($pluginnames as $pluginname => $pluginfo) {
974 if (!empty($pluginfo->availableupdates)) {
975 foreach ($pluginfo->availableupdates as $pluginavailableupdate) {
976 if ($pluginavailableupdate->version > $pluginfo->versiondisk) {
977 $updateable[$plugintype][$pluginname] = $pluginfo;
978 }
979 }
980 }
981 }
982 }
983 $plugininfo = $updateable;
984 }
985
986 if (!empty($options['contribonly'])) {
987 $contribs = array();
988 foreach ($plugininfo as $plugintype => $pluginnames) {
989 foreach ($pluginnames as $pluginname => $pluginfo) {
990 if (!$pluginfo->is_standard()) {
991 $contribs[$plugintype][$pluginname] = $pluginfo;
992 }
993 }
994 }
995 $plugininfo = $contribs;
996 }
997
b9934a17
DM
998 if (empty($plugininfo)) {
999 return '';
1000 }
1001
b9934a17
DM
1002 $table = new html_table();
1003 $table->id = 'plugins-control-panel';
1004 $table->head = array(
1005 get_string('displayname', 'core_plugin'),
b9934a17
DM
1006 get_string('source', 'core_plugin'),
1007 get_string('version', 'core_plugin'),
1008 get_string('availability', 'core_plugin'),
2b135b05
DM
1009 get_string('actions', 'core_plugin'),
1010 get_string('notes','core_plugin'),
b9934a17
DM
1011 );
1012 $table->colclasses = array(
2b135b05 1013 'pluginname', 'source', 'version', 'availability', 'actions', 'notes'
b9934a17
DM
1014 );
1015
1016 foreach ($plugininfo as $type => $plugins) {
1017
1018 $header = new html_table_cell($pluginman->plugintype_name_plural($type));
1019 $header->header = true;
1020 $header->colspan = count($table->head);
1021 $header = new html_table_row(array($header));
1022 $header->attributes['class'] = 'plugintypeheader type-' . $type;
1023 $table->data[] = $header;
1024
1025 if (empty($plugins)) {
1026 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
1027 $msg->colspan = count($table->head);
1028 $row = new html_table_row(array($msg));
1029 $row->attributes['class'] .= 'msg msg-noneinstalled';
1030 $table->data[] = $row;
1031 continue;
1032 }
1033
1034 foreach ($plugins as $name => $plugin) {
1035 $row = new html_table_row();
1036 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
1037
1038 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) {
1039 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
1040 } else {
1041 $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon'));
1042 }
1043 if ($plugin->get_status() === plugin_manager::PLUGIN_STATUS_MISSING) {
1044 $msg = html_writer::tag('span', get_string('status_missing', 'core_plugin'), array('class' => 'notifyproblem'));
1045 $row->attributes['class'] .= ' missingfromdisk';
1046 } else {
1047 $msg = '';
1048 }
2b135b05
DM
1049 $pluginname = html_writer::tag('div', $icon . ' ' . $plugin->displayname . ' ' . $msg, array('class' => 'displayname')).
1050 html_writer::tag('div', $plugin->component, array('class' => 'componentname'));
1051 $pluginname = new html_table_cell($pluginname);
b9934a17
DM
1052
1053 if ($plugin->is_standard()) {
1054 $row->attributes['class'] .= ' standard';
1055 $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
1056 } else {
1057 $row->attributes['class'] .= ' extension';
1058 $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
1059 }
1060
1061 $version = new html_table_cell($plugin->versiondb);
1062
1063 $isenabled = $plugin->is_enabled();
1064 if (is_null($isenabled)) {
1065 $availability = new html_table_cell('');
1066 } else if ($isenabled) {
1067 $row->attributes['class'] .= ' enabled';
7bc759bd 1068 $availability = new html_table_cell(get_string('pluginenabled', 'core_plugin'));
b9934a17
DM
1069 } else {
1070 $row->attributes['class'] .= ' disabled';
7bc759bd 1071 $availability = new html_table_cell(get_string('plugindisabled', 'core_plugin'));
b9934a17
DM
1072 }
1073
2b135b05
DM
1074 $actions = array();
1075
b9934a17 1076 $settingsurl = $plugin->get_settings_url();
2b135b05
DM
1077 if (!is_null($settingsurl)) {
1078 $actions[] = html_writer::link($settingsurl, get_string('settings', 'core_plugin'), array('class' => 'settings'));
b9934a17
DM
1079 }
1080
1081 $uninstallurl = $plugin->get_uninstall_url();
2b135b05
DM
1082 if (!is_null($uninstallurl)) {
1083 $actions[] = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin'), array('class' => 'uninstall'));
1084 }
1085
1086 $actions = new html_table_cell(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $actions));
1087
828788f0 1088 $requriedby = $pluginman->other_plugins_that_require($plugin->component);
2b135b05
DM
1089 if ($requriedby) {
1090 $requiredby = html_writer::tag('div', get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
1091 array('class' => 'requiredby'));
b9934a17 1092 } else {
2b135b05 1093 $requiredby = '';
b9934a17
DM
1094 }
1095
7d8de6d8 1096 $updateinfo = '';
7716057f 1097 if (empty($CFG->disableupdatenotifications) and is_array($plugin->available_updates())) {
7d8de6d8
DM
1098 foreach ($plugin->available_updates() as $availableupdate) {
1099 $updateinfo .= $this->plugin_available_update_info($availableupdate);
1100 }
3204daea
DM
1101 }
1102
1103 $notes = new html_table_cell($requiredby.$updateinfo);
2b135b05 1104
b9934a17 1105 $row->cells = array(
2b135b05 1106 $pluginname, $source, $version, $availability, $actions, $notes
b9934a17
DM
1107 );
1108 $table->data[] = $row;
1109 }
1110 }
1111
1112 return html_writer::table($table);
1113 }
da2fdc3f 1114
3204daea 1115 /**
e7611389 1116 * Helper method to render the information about the available plugin update
3204daea
DM
1117 *
1118 * The passed objects always provides at least the 'version' property containing
7d8de6d8 1119 * the (higher) version of the plugin available.
3204daea 1120 *
7d8de6d8 1121 * @param available_update_info $updateinfo information about the available update for the plugin
3204daea 1122 */
7d8de6d8 1123 protected function plugin_available_update_info(available_update_info $updateinfo) {
3204daea 1124
e7611389 1125 $boxclasses = 'pluginupdateinfo';
3204daea
DM
1126 $info = array();
1127
1128 if (isset($updateinfo->release)) {
1129 $info[] = html_writer::tag('span', get_string('updateavailable_release', 'core_plugin', $updateinfo->release),
1130 array('class' => 'info release'));
1131 }
1132
1133 if (isset($updateinfo->maturity)) {
1134 $info[] = html_writer::tag('span', get_string('maturity'.$updateinfo->maturity, 'core_admin'),
1135 array('class' => 'info maturity'));
e7611389 1136 $boxclasses .= ' maturity'.$updateinfo->maturity;
3204daea
DM
1137 }
1138
1139 if (isset($updateinfo->download)) {
1140 $info[] = html_writer::link($updateinfo->download, get_string('download'), array('class' => 'info download'));
1141 }
1142
1143 if (isset($updateinfo->url)) {
1144 $info[] = html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin'),
1145 array('class' => 'info more'));
1146 }
1147
e7611389
DM
1148 $box = $this->output->box_start($boxclasses);
1149 $box .= html_writer::tag('div', get_string('updateavailable', 'core_plugin', $updateinfo->version), array('class' => 'version'));
1150 $box .= $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $info), '');
fa3feafb
DM
1151
1152 $deployer = available_update_deployer::instance();
1153 if ($deployer->initialized() and $deployer->can_deploy($updateinfo)) {
1154 $widget = $deployer->make_confirm_widget($updateinfo);
1155 $box .= $this->output->render($widget);
1156 }
1157
3204daea
DM
1158 $box .= $this->output->box_end();
1159
1160 return $box;
1161 }
1162
da2fdc3f 1163 /**
cc359566
TH
1164 * This function will render one beautiful table with all the environmental
1165 * configuration and how it suits Moodle needs.
1166 *
1167 * @param boolean $result final result of the check (true/false)
1168 * @param array $environment_results array of results gathered
1169 * @return string HTML to output.
da2fdc3f 1170 */
cc359566
TH
1171 public function environment_check_table($result, $environment_results) {
1172 global $CFG;
1173
1174 // Table headers
1175 $servertable = new html_table();//table for server checks
1176 $servertable->head = array(
1177 get_string('name'),
1178 get_string('info'),
1179 get_string('report'),
1180 get_string('status'),
1181 );
1182 $servertable->align = array('center', 'center', 'left', 'center');
1183 $servertable->wrap = array('nowrap', '', '', 'nowrap');
1184 $servertable->size = array('10', 10, '100%', '10');
1185 $servertable->attributes['class'] = 'environmenttable generaltable';
1186
1187 $serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
1188
1189 $othertable = new html_table();//table for custom checks
1190 $othertable->head = array(
1191 get_string('info'),
1192 get_string('report'),
1193 get_string('status'),
1194 );
1195 $othertable->align = array('center', 'left', 'center');
1196 $othertable->wrap = array('', '', 'nowrap');
1197 $othertable->size = array(10, '100%', '10');
1198 $othertable->attributes['class'] = 'environmenttable generaltable';
1199
1200 $otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
1201
1202 // Iterate over each environment_result
1203 $continue = true;
1204 foreach ($environment_results as $environment_result) {
1205 $errorline = false;
1206 $warningline = false;
1207 $stringtouse = '';
1208 if ($continue) {
1209 $type = $environment_result->getPart();
1210 $info = $environment_result->getInfo();
1211 $status = $environment_result->getStatus();
1212 $error_code = $environment_result->getErrorCode();
1213 // Process Report field
1214 $rec = new stdClass();
1215 // Something has gone wrong at parsing time
1216 if ($error_code) {
1217 $stringtouse = 'environmentxmlerror';
1218 $rec->error_code = $error_code;
1219 $status = get_string('error');
1220 $errorline = true;
1221 $continue = false;
1222 }
1223
1224 if ($continue) {
1225 if ($rec->needed = $environment_result->getNeededVersion()) {
1226 // We are comparing versions
1227 $rec->current = $environment_result->getCurrentVersion();
1228 if ($environment_result->getLevel() == 'required') {
1229 $stringtouse = 'environmentrequireversion';
1230 } else {
1231 $stringtouse = 'environmentrecommendversion';
1232 }
1233
1234 } else if ($environment_result->getPart() == 'custom_check') {
1235 // We are checking installed & enabled things
1236 if ($environment_result->getLevel() == 'required') {
1237 $stringtouse = 'environmentrequirecustomcheck';
1238 } else {
1239 $stringtouse = 'environmentrecommendcustomcheck';
1240 }
1241
1242 } else if ($environment_result->getPart() == 'php_setting') {
1243 if ($status) {
1244 $stringtouse = 'environmentsettingok';
1245 } else if ($environment_result->getLevel() == 'required') {
1246 $stringtouse = 'environmentmustfixsetting';
1247 } else {
1248 $stringtouse = 'environmentshouldfixsetting';
1249 }
1250
1251 } else {
1252 if ($environment_result->getLevel() == 'required') {
1253 $stringtouse = 'environmentrequireinstall';
1254 } else {
1255 $stringtouse = 'environmentrecommendinstall';
1256 }
1257 }
1258
1259 // Calculate the status value
1260 if ($environment_result->getBypassStr() != '') { //Handle bypassed result (warning)
1261 $status = get_string('bypassed');
1262 $warningline = true;
1263 } else if ($environment_result->getRestrictStr() != '') { //Handle restricted result (error)
1264 $status = get_string('restricted');
1265 $errorline = true;
1266 } else {
1267 if ($status) { //Handle ok result (ok)
1268 $status = get_string('ok');
1269 } else {
1270 if ($environment_result->getLevel() == 'optional') {//Handle check result (warning)
1271 $status = get_string('check');
1272 $warningline = true;
1273 } else { //Handle error result (error)
1274 $status = get_string('check');
1275 $errorline = true;
1276 }
1277 }
1278 }
1279 }
1280
1281 // Build the text
1282 $linkparts = array();
1283 $linkparts[] = 'admin/environment';
1284 $linkparts[] = $type;
1285 if (!empty($info)){
1286 $linkparts[] = $info;
1287 }
1288 if (empty($CFG->docroot)) {
1289 $report = get_string($stringtouse, 'admin', $rec);
1290 } else {
1291 $report = $this->doc_link(join($linkparts, '/'), get_string($stringtouse, 'admin', $rec));
1292 }
1293
1294 // Format error or warning line
1295 if ($errorline || $warningline) {
1296 $messagetype = $errorline? 'error':'warn';
1297 } else {
1298 $messagetype = 'ok';
1299 }
1300 $status = '<span class="'.$messagetype.'">'.$status.'</span>';
1301 // Here we'll store all the feedback found
1302 $feedbacktext = '';
1303 // Append the feedback if there is some
1304 $feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), $messagetype);
1305 //Append the bypass if there is some
1306 $feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'warn');
1307 //Append the restrict if there is some
1308 $feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'error');
1309
1310 $report .= $feedbacktext;
1311
1312 // Add the row to the table
1313 if ($environment_result->getPart() == 'custom_check'){
1314 $otherdata[$messagetype][] = array ($info, $report, $status);
1315 } else {
1316 $serverdata[$messagetype][] = array ($type, $info, $report, $status);
1317 }
1318 }
1319 }
1320
1321 //put errors first in
1322 $servertable->data = array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']);
1323 $othertable->data = array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']);
1324
1325 // Print table
1326 $output = '';
1327 $output .= $this->heading(get_string('serverchecks', 'admin'));
1328 $output .= html_writer::table($servertable);
1329 if (count($othertable->data)){
1330 $output .= $this->heading(get_string('customcheck', 'admin'));
1331 $output .= html_writer::table($othertable);
1332 }
1333
1334 // Finally, if any error has happened, print the summary box
1335 if (!$result) {
1336 $output .= $this->box(get_string('environmenterrortodo', 'admin'), 'environmentbox errorbox');
1337 }
1338
1339 return $output;
da2fdc3f 1340 }
b9934a17 1341}