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