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