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