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