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