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