MDL-53492 registration: Moodle.net is more correct than Moodle.org
[moodle.git] / admin / renderer.php
CommitLineData
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
26defined('MOODLE_INTERNAL') || die();
27
b9934a17
DM
28
29/**
30 * Standard HTML output renderer for core_admin subsystem
31 */
32class core_admin_renderer extends plugin_renderer_base {
33
cc359566
TH
34 /**
35 * Display the 'Do you acknowledge the terms of the GPL' page. The first page
36 * during install.
37 * @return string HTML to output.
38 */
39 public function install_licence_page() {
40 global $CFG;
41 $output = '';
42
43 $copyrightnotice = text_to_html(get_string('gpl3'));
44 $copyrightnotice = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $copyrightnotice); // extremely ugly validation hack
45
98b32c9e
DM
46 $continue = new single_button(new moodle_url($this->page->url, array(
47 'lang' => $CFG->lang, 'agreelicense' => 1)), get_string('continue'), 'get');
cc359566
TH
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) {
98b32c9e 100 $output .= $this->upgrade_reload(new moodle_url($this->page->url, array('agreelicense' => 1, 'lang' => $CFG->lang)));
cc359566
TH
101 } else {
102 $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
98b32c9e
DM
103 $output .= $this->continue_button(new moodle_url($this->page->url, array(
104 'agreelicense' => 1, 'confirmrelease' => 1, 'lang' => $CFG->lang)));
cc359566
TH
105 }
106
107 $output .= $this->footer();
108 return $output;
109 }
110
39f15cc7
DM
111 /**
112 * Displays the list of plugins with unsatisfied dependencies
113 *
114 * @param double|string|int $version Moodle on-disk version
115 * @param array $failed list of plugins with unsatisfied dependecies
e937c545 116 * @param moodle_url $reloadurl URL of the page to recheck the dependencies
39f15cc7
DM
117 * @return string HTML
118 */
119 public function unsatisfied_dependencies_page($version, array $failed, moodle_url $reloadurl) {
120 $output = '';
121
122 $output .= $this->header();
123 $output .= $this->heading(get_string('pluginscheck', 'admin'));
124 $output .= $this->warning(get_string('pluginscheckfailed', 'admin', array('pluginslist' => implode(', ', array_unique($failed)))));
e87214bd 125 $output .= $this->plugins_check_table(core_plugin_manager::instance(), $version, array('xdep' => true));
39f15cc7
DM
126 $output .= $this->warning(get_string('pluginschecktodo', 'admin'));
127 $output .= $this->continue_button($reloadurl);
128
129 $output .= $this->footer();
130
131 return $output;
132 }
133
cc359566
TH
134 /**
135 * Display the 'You are about to upgrade Moodle' page. The first page
136 * during upgrade.
8d1da748
PS
137 * @param string $strnewversion
138 * @param int $maturity
6e09cf98 139 * @param string $testsite
cc359566
TH
140 * @return string HTML to output.
141 */
6e09cf98 142 public function upgrade_confirm_page($strnewversion, $maturity, $testsite) {
cc359566
TH
143 $output = '';
144
98b32c9e 145 $continueurl = new moodle_url($this->page->url, array('confirmupgrade' => 1, 'cache' => 0));
82b1cf00
PS
146 $continue = new single_button($continueurl, get_string('continue'), 'get');
147 $cancelurl = new moodle_url('/admin/index.php');
cc359566
TH
148
149 $output .= $this->header();
150 $output .= $this->maturity_warning($maturity);
6e09cf98 151 $output .= $this->test_site_warning($testsite);
82b1cf00 152 $output .= $this->confirm(get_string('upgradesure', 'admin', $strnewversion), $continue, $cancelurl);
cc359566
TH
153 $output .= $this->footer();
154
155 return $output;
156 }
157
158 /**
159 * Display the environment page during the upgrade process.
8d1da748
PS
160 * @param string $release
161 * @param boolean $envstatus final result of env check (true/false)
162 * @param array $environment_results array of results gathered
cc359566
TH
163 * @return string HTML to output.
164 */
165 public function upgrade_environment_page($release, $envstatus, $environment_results) {
166 global $CFG;
167 $output = '';
168
169 $output .= $this->header();
170 $output .= $this->heading("Moodle $release");
171 $output .= $this->release_notes_link();
172 $output .= $this->environment_check_table($envstatus, $environment_results);
173
174 if (!$envstatus) {
98b32c9e 175 $output .= $this->upgrade_reload(new moodle_url($this->page->url, array('confirmupgrade' => 1, 'cache' => 0)));
cc359566
TH
176
177 } else {
faadd326 178 $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
cc359566
TH
179
180 if (empty($CFG->skiplangupgrade) and current_language() !== 'en') {
181 $output .= $this->box(get_string('langpackwillbeupdated', 'admin'), 'generalbox', 'notice');
182 }
183
98b32c9e
DM
184 $output .= $this->continue_button(new moodle_url($this->page->url, array(
185 'confirmupgrade' => 1, 'confirmrelease' => 1, 'cache' => 0)));
cc359566
TH
186 }
187
188 $output .= $this->footer();
189
190 return $output;
191 }
192
193 /**
194 * Display the upgrade page that lists all the plugins that require attention.
e87214bd
PS
195 * @param core_plugin_manager $pluginman provides information about the plugins.
196 * @param \core\update\checker $checker provides information about available updates.
8d1da748
PS
197 * @param int $version the version of the Moodle code from version.php.
198 * @param bool $showallplugins
199 * @param moodle_url $reloadurl
200 * @param moodle_url $continueurl
cc359566
TH
201 * @return string HTML to output.
202 */
e87214bd 203 public function upgrade_plugin_check_page(core_plugin_manager $pluginman, \core\update\checker $checker,
96dd9237
DM
204 $version, $showallplugins, $reloadurl, $continueurl) {
205
cc359566
TH
206 $output = '';
207
208 $output .= $this->header();
2f29cf6e
DM
209 $output .= $this->box_start('generalbox', 'plugins-check-page');
210 $output .= html_writer::tag('p', get_string('pluginchecknotice', 'core_plugin'), array('class' => 'page-description'));
44371554 211 $output .= $this->check_for_updates_button($checker, $reloadurl);
5a92cd0b 212 $output .= $this->missing_dependencies($pluginman);
faadd326 213 $output .= $this->plugins_check_table($pluginman, $version, array('full' => $showallplugins));
cc359566
TH
214 $output .= $this->box_end();
215 $output .= $this->upgrade_reload($reloadurl);
216
ead8ba3b
DM
217 if ($pluginman->some_plugins_updatable()) {
218 $output .= $this->container_start('upgradepluginsinfo');
219 $output .= $this->help_icon('upgradepluginsinfo', 'core_admin', get_string('upgradepluginsfirst', 'core_admin'));
220 $output .= $this->container_end();
faadd326 221 }
cc359566 222
ead8ba3b
DM
223 $button = new single_button($continueurl, get_string('upgradestart', 'admin'), 'get');
224 $button->class = 'continuebutton';
225 $output .= $this->render($button);
cc359566
TH
226 $output .= $this->footer();
227
228 return $output;
229 }
230
4d7528f9
DM
231 /**
232 * Display a page to confirm plugin installation cancelation.
233 *
c20e9ae8 234 * @param array $abortable list of \core\update\plugininfo
4d7528f9
DM
235 * @param moodle_url $continue
236 * @return string
237 */
c20e9ae8 238 public function upgrade_confirm_abort_install_page(array $abortable, moodle_url $continue) {
4d7528f9
DM
239
240 $pluginman = core_plugin_manager::instance();
4d7528f9
DM
241
242 if (empty($abortable)) {
243 // The UI should not allow this.
244 throw new moodle_exception('err_no_plugin_install_abortable', 'core_plugin');
245 }
246
247 $out = $this->output->header();
248 $out .= $this->output->heading(get_string('cancelinstallhead', 'core_plugin'), 3);
249 $out .= $this->output->container(get_string('cancelinstallinfo', 'core_plugin'), 'cancelinstallinfo');
250
251 foreach ($abortable as $pluginfo) {
252 $out .= $this->output->heading($pluginfo->displayname.' ('.$pluginfo->component.')', 4);
253 $out .= $this->output->container(get_string('cancelinstallinfodir', 'core_plugin', $pluginfo->rootdir));
254 if ($repotype = $pluginman->plugin_external_source($pluginfo->component)) {
255 $out .= $this->output->container(get_string('uninstalldeleteconfirmexternal', 'core_plugin', $repotype),
256 'uninstalldeleteconfirmexternal');
257 }
258 }
259
260 $out .= $this->plugins_management_confirm_buttons($continue, $this->page->url);
261 $out .= $this->output->footer();
262
263 return $out;
264 }
265
cc359566
TH
266 /**
267 * Display the admin notifications page.
8d1da748
PS
268 * @param int $maturity
269 * @param bool $insecuredataroot warn dataroot is invalid
270 * @param bool $errorsdisplayed warn invalid dispaly error setting
271 * @param bool $cronoverdue warn cron not running
272 * @param bool $dbproblems warn db has problems
273 * @param bool $maintenancemode warn in maintenance mode
0aff15c2 274 * @param bool $buggyiconvnomb warn iconv problems
e87214bd 275 * @param array|null $availableupdates array of \core\update\info objects or null
55585f3a 276 * @param int|null $availableupdatesfetch timestamp of the most recent updates fetch or null (unknown)
915140c9 277 * @param string[] $cachewarnings An array containing warnings from the Cache API.
356e2354 278 * @param array $eventshandlers Events 1 API handlers.
55585f3a 279 *
cc359566
TH
280 * @return string HTML to output.
281 */
282 public function admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed,
b3245b75 283 $cronoverdue, $dbproblems, $maintenancemode, $availableupdates, $availableupdatesfetch,
586cf929 284 $buggyiconvnomb, $registered, array $cachewarnings = array(), $eventshandlers = 0, $themedesignermode = false) {
4db58f5f 285 global $CFG;
cc359566
TH
286 $output = '';
287
288 $output .= $this->header();
289 $output .= $this->maturity_info($maturity);
3f195ab7 290 $output .= $this->legacy_log_store_writing_error();
4db58f5f 291 $output .= empty($CFG->disableupdatenotifications) ? $this->available_updates($availableupdates, $availableupdatesfetch) : '';
cc359566 292 $output .= $this->insecure_dataroot_warning($insecuredataroot);
586cf929 293 $output .= $this->themedesignermode_warning($themedesignermode);
cc359566 294 $output .= $this->display_errors_warning($errorsdisplayed);
0aff15c2 295 $output .= $this->buggy_iconv_warning($buggyiconvnomb);
e3258164 296 $output .= $this->cron_overdue_warning($cronoverdue);
cc359566
TH
297 $output .= $this->db_problems($dbproblems);
298 $output .= $this->maintenance_mode_warning($maintenancemode);
915140c9 299 $output .= $this->cache_warnings($cachewarnings);
356e2354 300 $output .= $this->events_handlers($eventshandlers);
b3245b75 301 $output .= $this->registration_warning($registered);
cc359566
TH
302
303 //////////////////////////////////////////////////////////////////////////////////////////////////
304 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
305 $output .= $this->moodle_copyright();
306 //////////////////////////////////////////////////////////////////////////////////////////////////
307
308 $output .= $this->footer();
309
310 return $output;
311 }
312
8342171b
DM
313 /**
314 * Display the plugin management page (admin/plugins.php).
315 *
4df8bced
DM
316 * The filtering options array may contain following items:
317 * bool contribonly - show only contributed extensions
318 * bool updatesonly - show only plugins with an available update
319 *
e87214bd
PS
320 * @param core_plugin_manager $pluginman
321 * @param \core\update\checker $checker
4df8bced 322 * @param array $options filtering options
8342171b
DM
323 * @return string HTML to output.
324 */
e87214bd 325 public function plugin_management_page(core_plugin_manager $pluginman, \core\update\checker $checker, array $options = array()) {
7716057f 326
8342171b
DM
327 $output = '';
328
329 $output .= $this->header();
330 $output .= $this->heading(get_string('pluginsoverview', 'core_admin'));
44371554 331 $output .= $this->check_for_updates_button($checker, $this->page->url);
8726c07c 332 $output .= $this->plugins_overview_panel($pluginman, $options);
44371554
DM
333 $output .= $this->plugins_control_panel($pluginman, $options);
334 $output .= $this->footer();
335
336 return $output;
337 }
338
339 /**
340 * Renders a button to fetch for available updates.
341 *
342 * @param \core\update\checker $checker
343 * @param moodle_url $reloadurl
344 * @return string HTML
345 */
346 public function check_for_updates_button(\core\update\checker $checker, $reloadurl) {
347
348 $output = '';
8342171b 349
e9d3c212 350 if ($checker->enabled()) {
7716057f 351 $output .= $this->container_start('checkforupdates');
4df8bced 352 $output .= $this->single_button(
aa1d100c 353 new moodle_url($reloadurl, array('fetchupdates' => 1)),
4df8bced
DM
354 get_string('checkforupdates', 'core_plugin')
355 );
7716057f 356 if ($timefetched = $checker->get_last_timefetched()) {
44371554
DM
357 $timefetched = userdate($timefetched, get_string('strftimedatetime', 'core_langconfig'));
358 $output .= $this->container(get_string('checkforupdateslast', 'core_plugin', $timefetched), 'lasttimefetched');
7716057f
DM
359 }
360 $output .= $this->container_end();
8342171b 361 }
8342171b 362
8342171b
DM
363 return $output;
364 }
365
436d9447
DM
366 /**
367 * Display a page to confirm the plugin uninstallation.
368 *
e87214bd
PS
369 * @param core_plugin_manager $pluginman
370 * @param \core\plugininfo\base $pluginfo
436d9447 371 * @param moodle_url $continueurl URL to continue after confirmation
e87214bd 372 * @param moodle_url $cancelurl URL to to go if cancelled
436d9447
DM
373 * @return string
374 */
e87214bd 375 public function plugin_uninstall_confirm_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, moodle_url $continueurl, moodle_url $cancelurl) {
436d9447
DM
376 $output = '';
377
378 $pluginname = $pluginman->plugin_name($pluginfo->component);
379
2f87bb03
PS
380 $confirm = '<p>' . get_string('uninstallconfirm', 'core_plugin', array('name' => $pluginname)) . '</p>';
381 if ($extraconfirm = $pluginfo->get_uninstall_extra_warning()) {
382 $confirm .= $extraconfirm;
383 }
384
436d9447
DM
385 $output .= $this->output->header();
386 $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
e87214bd 387 $output .= $this->output->confirm($confirm, $continueurl, $cancelurl);
436d9447
DM
388 $output .= $this->output->footer();
389
390 return $output;
391 }
392
393 /**
394 * Display a page with results of plugin uninstallation and offer removal of plugin files.
395 *
e87214bd
PS
396 * @param core_plugin_manager $pluginman
397 * @param \core\plugininfo\base $pluginfo
3ca1b546 398 * @param progress_trace_buffer $progress
436d9447
DM
399 * @param moodle_url $continueurl URL to continue to remove the plugin folder
400 * @return string
401 */
e87214bd 402 public function plugin_uninstall_results_removable_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo,
3ca1b546 403 progress_trace_buffer $progress, moodle_url $continueurl) {
436d9447
DM
404 $output = '';
405
406 $pluginname = $pluginman->plugin_name($pluginfo->component);
407
82b1cf00
PS
408 // Do not show navigation here, they must click one of the buttons.
409 $this->page->set_pagelayout('maintenance');
410 $this->page->set_cacheable(false);
411
436d9447
DM
412 $output .= $this->output->header();
413 $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
414
3ca1b546 415 $output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
436d9447
DM
416
417 $confirm = $this->output->container(get_string('uninstalldeleteconfirm', 'core_plugin',
418 array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'uninstalldeleteconfirm');
419
420 if ($repotype = $pluginman->plugin_external_source($pluginfo->component)) {
421 $confirm .= $this->output->container(get_string('uninstalldeleteconfirmexternal', 'core_plugin', $repotype),
422 'uninstalldeleteconfirmexternal');
423 }
424
82b1cf00
PS
425 // After any uninstall we must execute full upgrade to finish the cleanup!
426 $output .= $this->output->confirm($confirm, $continueurl, new moodle_url('/admin/index.php'));
436d9447
DM
427 $output .= $this->output->footer();
428
429 return $output;
430 }
431
432 /**
433 * Display a page with results of plugin uninstallation and inform about the need to remove plugin files manually.
434 *
e87214bd
PS
435 * @param core_plugin_manager $pluginman
436 * @param \core\plugininfo\base $pluginfo
3ca1b546 437 * @param progress_trace_buffer $progress
436d9447
DM
438 * @return string
439 */
e87214bd 440 public function plugin_uninstall_results_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, progress_trace_buffer $progress) {
436d9447
DM
441 $output = '';
442
2612e75e 443 $pluginname = $pluginfo->component;
436d9447 444
436d9447
DM
445 $output .= $this->output->header();
446 $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
447
3ca1b546 448 $output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
436d9447
DM
449
450 $output .= $this->output->box(get_string('uninstalldelete', 'core_plugin',
451 array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'generalbox uninstalldelete');
2612e75e 452 $output .= $this->output->continue_button(new moodle_url('/admin/index.php'));
436d9447
DM
453 $output .= $this->output->footer();
454
455 return $output;
456 }
457
cc359566
TH
458 /**
459 * Display the plugin management page (admin/environment.php).
8d1da748
PS
460 * @param array $versions
461 * @param string $version
462 * @param boolean $envstatus final result of env check (true/false)
463 * @param array $environment_results array of results gathered
cc359566
TH
464 * @return string HTML to output.
465 */
466 public function environment_check_page($versions, $version, $envstatus, $environment_results) {
467 $output = '';
468 $output .= $this->header();
469
470 // Print the component download link
471 $output .= html_writer::tag('div', html_writer::link(
472 new moodle_url('/admin/environment.php', array('action' => 'updatecomponent', 'sesskey' => sesskey())),
473 get_string('updatecomponent', 'admin')),
474 array('class' => 'reportlink'));
475
476 // Heading.
477 $output .= $this->heading(get_string('environment', 'admin'));
478
479 // Box with info and a menu to choose the version.
480 $output .= $this->box_start();
481 $output .= html_writer::tag('div', get_string('adminhelpenvironment'));
482 $select = new single_select(new moodle_url('/admin/environment.php'), 'version', $versions, $version, null);
483 $select->label = get_string('moodleversion');
484 $output .= $this->render($select);
485 $output .= $this->box_end();
486
487 // The results
488 $output .= $this->environment_check_table($envstatus, $environment_results);
489
490 $output .= $this->footer();
491 return $output;
492 }
493
494 /**
495 * Output a warning message, of the type that appears on the admin notifications page.
496 * @param string $message the message to display.
8d1da748 497 * @param string $type type class
cc359566
TH
498 * @return string HTML to output.
499 */
500 protected function warning($message, $type = 'warning') {
501 return $this->box($message, 'generalbox admin' . $type);
502 }
503
504 /**
505 * Render an appropriate message if dataroot is insecure.
8d1da748 506 * @param bool $insecuredataroot
cc359566
TH
507 * @return string HTML to output.
508 */
509 protected function insecure_dataroot_warning($insecuredataroot) {
510 global $CFG;
511
512 if ($insecuredataroot == INSECURE_DATAROOT_WARNING) {
513 return $this->warning(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot));
514
515 } else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) {
516 return $this->warning(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'error');
517
518 } else {
519 return '';
520 }
521 }
522
523 /**
524 * Render an appropriate message if dataroot is insecure.
8d1da748 525 * @param bool $errorsdisplayed
cc359566
TH
526 * @return string HTML to output.
527 */
528 protected function display_errors_warning($errorsdisplayed) {
529 if (!$errorsdisplayed) {
530 return '';
531 }
532
533 return $this->warning(get_string('displayerrorswarning', 'admin'));
534 }
535
586cf929
DP
536 /**
537 * Render an appropriate message if themdesignermode is enabled.
538 * @param bool $themedesignermode true if enabled
539 * @return string HTML to output.
540 */
541 protected function themedesignermode_warning($themedesignermode) {
542 if (!$themedesignermode) {
543 return '';
544 }
545
546 return $this->warning(get_string('themedesignermodewarning', 'admin'));
547 }
548
0aff15c2
PS
549 /**
550 * Render an appropriate message if iconv is buggy and mbstring missing.
551 * @param bool $buggyiconvnomb
552 * @return string HTML to output.
553 */
554 protected function buggy_iconv_warning($buggyiconvnomb) {
555 if (!$buggyiconvnomb) {
556 return '';
557 }
558
559 return $this->warning(get_string('warningiconvbuggy', 'admin'));
560 }
561
cc359566
TH
562 /**
563 * Render an appropriate message if cron has not been run recently.
8d1da748 564 * @param bool $cronoverdue
cc359566
TH
565 * @return string HTML to output.
566 */
567 public function cron_overdue_warning($cronoverdue) {
ed25d7c4 568 global $CFG;
cc359566
TH
569 if (!$cronoverdue) {
570 return '';
571 }
572
ed25d7c4
MS
573 if (empty($CFG->cronclionly)) {
574 $url = new moodle_url('/admin/cron.php');
575 if (!empty($CFG->cronremotepassword)) {
576 $url = new moodle_url('/admin/cron.php', array('password' => $CFG->cronremotepassword));
577 }
578
579 return $this->warning(get_string('cronwarning', 'admin', $url->out()) . '&nbsp;' .
580 $this->help_icon('cron', 'admin'));
581 }
582
583 // $CFG->cronclionly is not empty: cron can run only from CLI.
584 return $this->warning(get_string('cronwarningcli', 'admin') . '&nbsp;' .
cc359566
TH
585 $this->help_icon('cron', 'admin'));
586 }
587
588 /**
589 * Render an appropriate message if there are any problems with the DB set-up.
8d1da748 590 * @param bool $dbproblems
cc359566
TH
591 * @return string HTML to output.
592 */
593 public function db_problems($dbproblems) {
594 if (!$dbproblems) {
595 return '';
596 }
597
598 return $this->warning($dbproblems);
599 }
600
915140c9
SH
601 /**
602 * Renders cache warnings if there are any.
603 *
604 * @param string[] $cachewarnings
605 * @return string
606 */
607 public function cache_warnings(array $cachewarnings) {
608 if (!count($cachewarnings)) {
609 return '';
610 }
611 return join("\n", array_map(array($this, 'warning'), $cachewarnings));
612 }
613
356e2354
DM
614 /**
615 * Renders events 1 API handlers warning.
616 *
617 * @param array $eventshandlers
618 * @return string
619 */
620 public function events_handlers($eventshandlers) {
621 if ($eventshandlers) {
622 $components = '';
623 foreach ($eventshandlers as $eventhandler) {
624 $components .= $eventhandler->component . ', ';
625 }
626 $components = rtrim($components, ', ');
627 return $this->warning(get_string('eventshandlersinuse', 'admin', $components));
628 }
629 }
630
cc359566
TH
631 /**
632 * Render an appropriate message if the site in in maintenance mode.
8d1da748 633 * @param bool $maintenancemode
cc359566
TH
634 * @return string HTML to output.
635 */
636 public function maintenance_mode_warning($maintenancemode) {
637 if (!$maintenancemode) {
638 return '';
639 }
640
ecc2897c
PS
641 $url = new moodle_url('/admin/settings.php', array('section' => 'maintenancemode'));
642 $url = $url->out(); // get_string() does not support objects in params
643
644 return $this->warning(get_string('sitemaintenancewarning2', 'admin', $url));
cc359566
TH
645 }
646
647 /**
648 * Display a warning about installing development code if necesary.
8d1da748 649 * @param int $maturity
cc359566
TH
650 * @return string HTML to output.
651 */
652 protected function maturity_warning($maturity) {
653 if ($maturity == MATURITY_STABLE) {
654 return ''; // No worries.
655 }
656
657 $maturitylevel = get_string('maturity' . $maturity, 'admin');
7f52dbd8 658 return $this->warning(
cc359566
TH
659 $this->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
660 $this->container($this->doc_link('admin/versions', get_string('morehelp'))),
7f52dbd8 661 'error');
cc359566
TH
662 }
663
6e09cf98
DM
664 /*
665 * If necessary, displays a warning about upgrading a test site.
666 *
667 * @param string $testsite
668 * @return string HTML
669 */
670 protected function test_site_warning($testsite) {
671
672 if (!$testsite) {
673 return '';
674 }
675
7f52dbd8
DS
676 $warning = (get_string('testsiteupgradewarning', 'admin', $testsite));
677 return $this->warning($warning, 'error');
6e09cf98
DM
678 }
679
cc359566
TH
680 /**
681 * Output the copyright notice.
682 * @return string HTML to output.
683 */
684 protected function moodle_copyright() {
685 global $CFG;
686
687 //////////////////////////////////////////////////////////////////////////////////////////////////
688 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
689 $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
690 '<a href="http://docs.moodle.org/dev/Releases" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
691 'Copyright &copy; 1999 onwards, Martin Dougiamas<br />'.
956082f1 692 'and <a href="http://moodle.org/dev">many other contributors</a>.<br />'.
cc359566
TH
693 '<a href="http://docs.moodle.org/dev/License">GNU Public License</a>';
694 //////////////////////////////////////////////////////////////////////////////////////////////////
695
696 return $this->box($copyrighttext, 'copyright');
697 }
698
699 /**
700 * Display a warning about installing development code if necesary.
8d1da748
PS
701 * @param int $maturity
702 * @return string HTML to output.
cc359566
TH
703 */
704 protected function maturity_info($maturity) {
705 if ($maturity == MATURITY_STABLE) {
706 return ''; // No worries.
707 }
708
7f52dbd8
DS
709 $level = 'warning';
710
711 if ($maturity == MATURITY_ALPHA) {
712 $level = 'error';
713 }
714
cc359566 715 $maturitylevel = get_string('maturity' . $maturity, 'admin');
7f52dbd8
DS
716 $warningtext = get_string('maturitycoreinfo', 'admin', $maturitylevel);
717 $warningtext .= ' ' . $this->doc_link('admin/versions', get_string('morehelp'));
718 return $this->warning($warningtext, $level);
cc359566
TH
719 }
720
55585f3a 721 /**
966bd785 722 * Displays the info about available Moodle core and plugin updates
55585f3a 723 *
966bd785
DM
724 * The structure of the $updates param has changed since 2.4. It contains not only updates
725 * for the core itself, but also for all other installed plugins.
726 *
e87214bd 727 * @param array|null $updates array of (string)component => array of \core\update\info objects or null
55585f3a
DM
728 * @param int|null $fetch timestamp of the most recent updates fetch or null (unknown)
729 * @return string
730 */
731 protected function available_updates($updates, $fetch) {
732
7f52dbd8 733 $updateinfo = '';
966bd785 734 $someupdateavailable = false;
55585f3a 735 if (is_array($updates)) {
966bd785
DM
736 if (is_array($updates['core'])) {
737 $someupdateavailable = true;
738 $updateinfo .= $this->heading(get_string('updateavailable', 'core_admin'), 3);
739 foreach ($updates['core'] as $update) {
740 $updateinfo .= $this->moodle_available_update_info($update);
741 }
657cb5ab
DM
742 $updateinfo .= html_writer::tag('p', get_string('updateavailablerecommendation', 'core_admin'),
743 array('class' => 'updateavailablerecommendation'));
55585f3a 744 }
966bd785
DM
745 unset($updates['core']);
746 // If something has left in the $updates array now, it is updates for plugins.
747 if (!empty($updates)) {
748 $someupdateavailable = true;
749 $updateinfo .= $this->heading(get_string('updateavailableforplugin', 'core_admin'), 3);
750 $pluginsoverviewurl = new moodle_url('/admin/plugins.php', array('updatesonly' => 1));
751 $updateinfo .= $this->container(get_string('pluginsoverviewsee', 'core_admin',
752 array('url' => $pluginsoverviewurl->out())));
753 }
754 }
755
756 if (!$someupdateavailable) {
cb1c3291
DM
757 $now = time();
758 if ($fetch and ($fetch <= $now) and ($now - $fetch < HOURSECS)) {
759 $updateinfo .= $this->heading(get_string('updateavailablenot', 'core_admin'), 3);
760 }
55585f3a
DM
761 }
762
763 $updateinfo .= $this->container_start('checkforupdates');
fc281113 764 $fetchurl = new moodle_url('/admin/index.php', array('fetchupdates' => 1, 'sesskey' => sesskey(), 'cache' => 0));
e2e35e71 765 $updateinfo .= $this->single_button($fetchurl, get_string('checkforupdates', 'core_plugin'));
55585f3a
DM
766 if ($fetch) {
767 $updateinfo .= $this->container(get_string('checkforupdateslast', 'core_plugin',
768 userdate($fetch, get_string('strftimedatetime', 'core_langconfig'))));
769 }
770 $updateinfo .= $this->container_end();
771
7f52dbd8 772 return $this->warning($updateinfo);
55585f3a
DM
773 }
774
b3245b75
DP
775 /**
776 * Display a warning about not being registered on Moodle.org if necesary.
777 *
778 * @param boolean $registered true if the site is registered on Moodle.org
779 * @return string HTML to output.
780 */
781 protected function registration_warning($registered) {
782
783 if (!$registered) {
784
505bbe7c
MG
785 if (has_capability('moodle/site:config', context_system::instance())) {
786 $registerbutton = $this->single_button(new moodle_url('/admin/registration/register.php',
5ac72c9c 787 array('huburl' => HUB_MOODLEORGHUBURL, 'hubname' => 'Moodle.net')),
b3245b75 788 get_string('register', 'admin'));
505bbe7c
MG
789 $str = 'registrationwarning';
790 } else {
791 $registerbutton = '';
792 $str = 'registrationwarningcontactadmin';
793 }
b3245b75 794
505bbe7c
MG
795 return $this->warning( get_string($str, 'admin')
796 . '&nbsp;' . $this->help_icon('registration', 'admin') . $registerbutton ,
797 'error alert alert-danger');
b3245b75
DP
798 }
799
800 return '';
801 }
802
505bbe7c
MG
803 /**
804 * Return an admin page warning if site is not registered with moodle.org
805 *
806 * @return string
807 */
808 public function warn_if_not_registered() {
809 global $CFG;
810 require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php');
811 $registrationmanager = new registration_manager();
812 return $this->registration_warning($registrationmanager->get_registeredhub(HUB_MOODLEORGHUBURL) ? true : false);
813 }
814
55585f3a
DM
815 /**
816 * Helper method to render the information about the available Moodle update
817 *
e87214bd 818 * @param \core\update\info $updateinfo information about the available Moodle core update
55585f3a 819 */
e87214bd 820 protected function moodle_available_update_info(\core\update\info $updateinfo) {
55585f3a
DM
821
822 $boxclasses = 'moodleupdateinfo';
823 $info = array();
824
825 if (isset($updateinfo->release)) {
826 $info[] = html_writer::tag('span', get_string('updateavailable_release', 'core_admin', $updateinfo->release),
827 array('class' => 'info release'));
828 }
829
830 if (isset($updateinfo->version)) {
831 $info[] = html_writer::tag('span', get_string('updateavailable_version', 'core_admin', $updateinfo->version),
832 array('class' => 'info version'));
833 }
834
835 if (isset($updateinfo->maturity)) {
836 $info[] = html_writer::tag('span', get_string('maturity'.$updateinfo->maturity, 'core_admin'),
837 array('class' => 'info maturity'));
838 $boxclasses .= ' maturity'.$updateinfo->maturity;
839 }
840
841 if (isset($updateinfo->download)) {
842 $info[] = html_writer::link($updateinfo->download, get_string('download'), array('class' => 'info download'));
843 }
844
845 if (isset($updateinfo->url)) {
846 $info[] = html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin'),
847 array('class' => 'info more'));
848 }
849
850 $box = $this->output->box_start($boxclasses);
851 $box .= $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $info), '');
852 $box .= $this->output->box_end();
853
854 return $box;
855 }
856
cc359566
TH
857 /**
858 * Display a link to the release notes.
8d1da748 859 * @return string HTML to output.
cc359566
TH
860 */
861 protected function release_notes_link() {
862 $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/dev/Releases');
863 $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
864 return $this->box($releasenoteslink, 'generalbox releasenoteslink');
865 }
866
867 /**
868 * Display the reload link that appears on several upgrade/install pages.
8d1da748 869 * @return string HTML to output.
cc359566
TH
870 */
871 function upgrade_reload($url) {
872 return html_writer::empty_tag('br') .
873 html_writer::tag('div',
c2e10ac0 874 html_writer::link($url, $this->pix_icon('i/reload', '', '', array('class' => 'icon icon-pre')) .
cc359566
TH
875 get_string('reload'), array('title' => get_string('reload'))),
876 array('class' => 'continuebutton')) . html_writer::empty_tag('br');
877 }
878
b9934a17
DM
879 /**
880 * Displays all known plugins and information about their installation or upgrade
881 *
882 * This default implementation renders all plugins into one big table. The rendering
883 * options support:
884 * (bool)full = false: whether to display up-to-date plugins, too
39f15cc7 885 * (bool)xdep = false: display the plugins with unsatisified dependecies only
b9934a17 886 *
e87214bd 887 * @param core_plugin_manager $pluginman provides information about the plugins.
faadd326 888 * @param int $version the version of the Moodle code from version.php.
b9934a17
DM
889 * @param array $options rendering options
890 * @return string HTML code
891 */
e87214bd 892 public function plugins_check_table(core_plugin_manager $pluginman, $version, array $options = array()) {
fa1d403f 893
36ca62ca 894 $plugininfo = $pluginman->get_plugins();
b9934a17
DM
895
896 if (empty($plugininfo)) {
897 return '';
898 }
899
39f15cc7
DM
900 $options['full'] = isset($options['full']) ? (bool)$options['full'] : false;
901 $options['xdep'] = isset($options['xdep']) ? (bool)$options['xdep'] : false;
b9934a17 902
b9934a17
DM
903 $table = new html_table();
904 $table->id = 'plugins-check';
905 $table->head = array(
fd17898c 906 get_string('displayname', 'core_plugin').' / '.get_string('rootdir', 'core_plugin'),
b9934a17
DM
907 get_string('versiondb', 'core_plugin'),
908 get_string('versiondisk', 'core_plugin'),
36ca62ca 909 get_string('requires', 'core_plugin'),
fd17898c 910 get_string('source', 'core_plugin').' / '.get_string('status', 'core_plugin'),
b9934a17
DM
911 );
912 $table->colclasses = array(
fd17898c 913 'displayname', 'versiondb', 'versiondisk', 'requires', 'status',
b9934a17
DM
914 );
915 $table->data = array();
916
0ec7d101
DM
917 // Number of displayed plugins per type.
918 $numdisplayed = array();
919 // Number of plugins known to the plugin manager.
920 $sumtotal = 0;
921 // Number of plugins requiring attention.
922 $sumattention = 0;
2f29cf6e 923 // List of all components we can cancel installation of.
c20e9ae8
DM
924 $installabortable = $pluginman->list_cancellable_installations();
925 // List of all components we can cancel upgrade of.
926 $upgradeabortable = $pluginman->list_restorable_archives();
b9934a17
DM
927
928 foreach ($plugininfo as $type => $plugins) {
929
930 $header = new html_table_cell($pluginman->plugintype_name_plural($type));
931 $header->header = true;
932 $header->colspan = count($table->head);
933 $header = new html_table_row(array($header));
934 $header->attributes['class'] = 'plugintypeheader type-' . $type;
935
0ec7d101 936 $numdisplayed[$type] = 0;
b9934a17
DM
937
938 if (empty($plugins) and $options['full']) {
939 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
940 $msg->colspan = count($table->head);
941 $row = new html_table_row(array($msg));
942 $row->attributes['class'] .= 'msg msg-noneinstalled';
943 $table->data[] = $header;
944 $table->data[] = $row;
945 continue;
946 }
947
948 $plugintyperows = array();
949
950 foreach ($plugins as $name => $plugin) {
0ec7d101 951 $sumtotal++;
b9934a17
DM
952 $row = new html_table_row();
953 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
954
436dbeec 955 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name, null)) {
b9934a17
DM
956 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
957 } else {
fd17898c 958 $icon = '';
b9934a17 959 }
b9934a17 960
fd17898c
DM
961 $displayname = new html_table_cell(
962 $icon.
963 html_writer::span($plugin->displayname, 'pluginname').
964 html_writer::div($plugin->get_dir(), 'plugindir')
965 );
966
967 $versiondb = new html_table_cell($plugin->versiondb);
968 $versiondisk = new html_table_cell($plugin->versiondisk);
b9934a17
DM
969
970 if ($isstandard = $plugin->is_standard()) {
971 $row->attributes['class'] .= ' standard';
fd17898c 972 $sourcelabel = html_writer::span(get_string('sourcestd', 'core_plugin'), 'sourcetext label');
b9934a17
DM
973 } else {
974 $row->attributes['class'] .= ' extension';
fd17898c 975 $sourcelabel = html_writer::span(get_string('sourceext', 'core_plugin'), 'sourcetext label label-info');
b9934a17
DM
976 }
977
fd17898c
DM
978 $coredependency = $plugin->is_core_dependency_satisfied($version);
979 $otherpluginsdependencies = $pluginman->are_dependencies_satisfied($plugin->get_other_required_plugins());
980 $dependenciesok = $coredependency && $otherpluginsdependencies;
b9934a17
DM
981
982 $statuscode = $plugin->get_status();
983 $row->attributes['class'] .= ' status-' . $statuscode;
fd17898c
DM
984 $statusclass = 'statustext label ';
985 switch ($statuscode) {
986 case core_plugin_manager::PLUGIN_STATUS_NEW:
987 $statusclass .= $dependenciesok ? 'label-success' : 'label-warning';
988 break;
989 case core_plugin_manager::PLUGIN_STATUS_UPGRADE:
990 $statusclass .= $dependenciesok ? 'label-info' : 'label-warning';
991 break;
992 case core_plugin_manager::PLUGIN_STATUS_MISSING:
993 case core_plugin_manager::PLUGIN_STATUS_DOWNGRADE:
994 case core_plugin_manager::PLUGIN_STATUS_DELETE:
995 $statusclass .= 'label-important';
996 break;
997 case core_plugin_manager::PLUGIN_STATUS_NODB:
998 case core_plugin_manager::PLUGIN_STATUS_UPTODATE:
999 $statusclass .= $dependenciesok ? '' : 'label-warning';
1000 break;
1001 }
1002 $status = html_writer::span(get_string('status_' . $statuscode, 'core_plugin'), $statusclass);
96dd9237 1003
c20e9ae8
DM
1004 if (!empty($installabortable[$plugin->component])) {
1005 $status .= $this->output->single_button(
1006 new moodle_url($this->page->url, array('abortinstall' => $plugin->component)),
1007 get_string('cancelinstallone', 'core_plugin'),
1008 'post',
1009 array('class' => 'actionbutton cancelinstallone')
1010 );
1011 }
1012
1013 if (!empty($upgradeabortable[$plugin->component])) {
1014 $status .= $this->output->single_button(
1015 new moodle_url($this->page->url, array('abortupgrade' => $plugin->component)),
1016 get_string('cancelupgradeone', 'core_plugin'),
1017 'post',
1018 array('class' => 'actionbutton cancelupgradeone')
1019 );
2f29cf6e
DM
1020 }
1021
96dd9237 1022 $availableupdates = $plugin->available_updates();
e9d3c212 1023 if (!empty($availableupdates)) {
96dd9237 1024 foreach ($availableupdates as $availableupdate) {
3bca7dbf 1025 $status .= $this->plugin_available_update_info($pluginman, $availableupdate);
96dd9237
DM
1026 }
1027 }
b9934a17 1028
fd17898c 1029 $status = new html_table_cell($sourcelabel.' '.$status);
b9934a17 1030
faadd326 1031 $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version));
36ca62ca
TH
1032
1033 $statusisboring = in_array($statuscode, array(
e87214bd 1034 core_plugin_manager::PLUGIN_STATUS_NODB, core_plugin_manager::PLUGIN_STATUS_UPTODATE));
e937c545 1035
39f15cc7
DM
1036 if ($options['xdep']) {
1037 // we want to see only plugins with failed dependencies
1038 if ($dependenciesok) {
1039 continue;
1040 }
1041
2f838a4e 1042 } else if ($statusisboring and $dependenciesok and empty($availableupdates)) {
39f15cc7
DM
1043 // no change is going to happen to the plugin - display it only
1044 // if the user wants to see the full list
b9934a17
DM
1045 if (empty($options['full'])) {
1046 continue;
1047 }
b9934a17 1048
0ec7d101
DM
1049 } else {
1050 $sumattention++;
1051 }
39f15cc7 1052
0ec7d101
DM
1053 // The plugin should be displayed.
1054 $numdisplayed[$type]++;
fd17898c 1055 $row->cells = array($displayname, $versiondb, $versiondisk, $requires, $status);
b9934a17
DM
1056 $plugintyperows[] = $row;
1057 }
1058
0ec7d101 1059 if (empty($numdisplayed[$type]) and empty($options['full'])) {
b9934a17
DM
1060 continue;
1061 }
1062
1063 $table->data[] = $header;
1064 $table->data = array_merge($table->data, $plugintyperows);
1065 }
1066
0ec7d101
DM
1067 // Total number of displayed plugins.
1068 $sumdisplayed = array_sum($numdisplayed);
b9934a17 1069
39f15cc7 1070 if ($options['xdep']) {
0ec7d101
DM
1071 // At the plugins dependencies check page, display the table only.
1072 return html_writer::table($table);
1073 }
1074
1075 $out = $this->output->container_start('', 'plugins-check-info');
39f15cc7 1076
0ec7d101
DM
1077 if ($sumdisplayed == 0) {
1078 $out .= $this->output->heading(get_string('pluginchecknone', 'core_plugin'));
b9934a17
DM
1079
1080 } else {
b9934a17 1081 if (empty($options['full'])) {
0ec7d101 1082 $out .= $this->output->heading(get_string('plugincheckattention', 'core_plugin'));
a687fcac 1083 } else {
0ec7d101 1084 $out .= $this->output->heading(get_string('plugincheckall', 'core_plugin'));
b9934a17 1085 }
228cbda3 1086 }
2f29cf6e 1087
228cbda3 1088 $out .= $this->output->container_start('actions');
c20e9ae8
DM
1089
1090 $installableupdates = $pluginman->filter_installable($pluginman->available_updates());
1091 if ($installableupdates) {
1092 $out .= $this->output->single_button(
1093 new moodle_url($this->page->url, array('installupdatex' => 1)),
1094 get_string('updateavailableinstallall', 'core_admin', count($installableupdates)),
1095 'post',
1096 array('class' => 'singlebutton updateavailableinstallall')
1097 );
1098 }
1099
228cbda3
DM
1100 if ($installabortable) {
1101 $out .= $this->output->single_button(
1102 new moodle_url($this->page->url, array('abortinstallx' => 1)),
1103 get_string('cancelinstallall', 'core_plugin', count($installabortable)),
1104 'post',
1105 array('class' => 'singlebutton cancelinstallall')
1106 );
1107 }
0ec7d101 1108
c20e9ae8 1109 if ($upgradeabortable) {
c948b813 1110 $out .= $this->output->single_button(
c20e9ae8
DM
1111 new moodle_url($this->page->url, array('abortupgradex' => 1)),
1112 get_string('cancelupgradeall', 'core_plugin', count($upgradeabortable)),
c948b813 1113 'post',
c20e9ae8 1114 array('class' => 'singlebutton cancelupgradeall')
c948b813
DM
1115 );
1116 }
1117
228cbda3
DM
1118 $out .= html_writer::div(html_writer::link(new moodle_url($this->page->url, array('showallplugins' => 0)),
1119 get_string('plugincheckattention', 'core_plugin')).' '.html_writer::span($sumattention, 'badge'));
2f29cf6e 1120
228cbda3
DM
1121 $out .= html_writer::div(html_writer::link(new moodle_url($this->page->url, array('showallplugins' => 1)),
1122 get_string('plugincheckall', 'core_plugin')).' '.html_writer::span($sumtotal, 'badge'));
b9934a17 1123
30c26421
DM
1124 $out .= $this->output->container_end(); // End of .actions container.
1125 $out .= $this->output->container_end(); // End of #plugins-check-info container.
0ec7d101
DM
1126
1127 if ($sumdisplayed > 0 or $options['full']) {
b9934a17
DM
1128 $out .= html_writer::table($table);
1129 }
1130
1131 return $out;
1132 }
1133
c948b813 1134 /**
4d7528f9 1135 * Display the continue / cancel widgets for the plugins management pages.
c948b813
DM
1136 *
1137 * @param null|moodle_url $continue URL for the continue button, should it be displayed
30c26421 1138 * @param null|moodle_url $cancel URL for the cancel link, defaults to the current page
c948b813
DM
1139 * @return string HTML
1140 */
4d7528f9 1141 public function plugins_management_confirm_buttons(moodle_url $continue=null, moodle_url $cancel=null) {
c948b813 1142
4d7528f9 1143 $out = html_writer::start_div('plugins-management-confirm-buttons');
c948b813
DM
1144
1145 if (!empty($continue)) {
4d7528f9 1146 $out .= $this->output->single_button($continue, get_string('continue'), 'post', array('class' => 'continue'));
c948b813
DM
1147 }
1148
1149 if (empty($cancel)) {
1150 $cancel = $this->page->url;
1151 }
1152 $out .= html_writer::div(html_writer::link($cancel, get_string('cancel')), 'cancel');
1153
1154 return $out;
1155 }
1156
5a92cd0b
DM
1157 /**
1158 * Displays the information about missing dependencies
1159 *
1160 * @param core_plugin_manager $pluginman
1161 * @return string
1162 */
1163 protected function missing_dependencies(core_plugin_manager $pluginman) {
1164
1165 $dependencies = $pluginman->missing_dependencies();
1166
1167 if (empty($dependencies)) {
1168 return '';
1169 }
1170
1171 $available = array();
1172 $unavailable = array();
1173 $unknown = array();
1174
1175 foreach ($dependencies as $component => $remoteinfo) {
1176 if ($remoteinfo === false) {
35f2b674 1177 // The required version is not available. Let us check if there
5a92cd0b 1178 // is at least some version in the plugins directory.
35f2b674 1179 $remoteinfoanyversion = $pluginman->get_remote_plugin_info($component, ANY_VERSION, false);
5a92cd0b
DM
1180 if ($remoteinfoanyversion === false) {
1181 $unknown[$component] = $component;
1182 } else {
1183 $unavailable[$component] = $remoteinfoanyversion;
1184 }
1185 } else {
1186 $available[$component] = $remoteinfo;
1187 }
1188 }
1189
1190 $out = $this->output->container_start('plugins-check-dependencies');
1191
1192 if ($unavailable or $unknown) {
1193 $out .= $this->output->heading(get_string('misdepsunavail', 'core_plugin'));
1194 if ($unknown) {
1195 $out .= $this->output->notification(get_string('misdepsunknownlist', 'core_plugin', implode($unknown, ', ')));
1196 }
1197 if ($unavailable) {
1198 $unavailablelist = array();
1199 foreach ($unavailable as $component => $remoteinfoanyversion) {
1200 $unavailablelistitem = html_writer::link('https://moodle.org/plugins/view.php?plugin='.$component,
1201 '<strong>'.$remoteinfoanyversion->name.'</strong>');
1202 if ($remoteinfoanyversion->version) {
1203 $unavailablelistitem .= ' ('.$component.' &gt; '.$remoteinfoanyversion->version->version.')';
1204 } else {
1205 $unavailablelistitem .= ' ('.$component.')';
1206 }
1207 $unavailablelist[] = $unavailablelistitem;
1208 }
1209 $out .= $this->output->notification(get_string('misdepsunavaillist', 'core_plugin',
1210 implode($unavailablelist, ', ')));
1211 }
1212 $out .= $this->output->container_start('plugins-check-dependencies-actions');
1213 $out .= ' '.html_writer::link(new moodle_url('/admin/tool/installaddon/'),
1214 get_string('dependencyuploadmissing', 'core_plugin'));
30c26421 1215 $out .= $this->output->container_end(); // End of .plugins-check-dependencies-actions container.
5a92cd0b
DM
1216 }
1217
1218 if ($available) {
1219 $out .= $this->output->heading(get_string('misdepsavail', 'core_plugin'));
5a92cd0b
DM
1220 $out .= $this->output->container_start('plugins-check-dependencies-actions');
1221
c948b813 1222 $installable = $pluginman->filter_installable($available);
9137a89a
DM
1223 if ($installable) {
1224 $out .= $this->output->single_button(
1225 new moodle_url($this->page->url, array('installdepx' => 1)),
1226 get_string('dependencyinstallmissing', 'core_plugin', count($installable)),
1227 'post',
1228 array('class' => 'singlebutton dependencyinstallmissing')
1229 );
1230 }
1231
c20e9ae8 1232 $out .= html_writer::div(html_writer::link(new moodle_url('/admin/tool/installaddon/'),
9137a89a
DM
1233 get_string('dependencyuploadmissing', 'core_plugin')), 'dependencyuploadmissing');
1234
30c26421 1235 $out .= $this->output->container_end(); // End of .plugins-check-dependencies-actions container.
9137a89a
DM
1236
1237 $out .= $this->available_missing_dependencies_list($pluginman, $available);
5a92cd0b
DM
1238 }
1239
30c26421 1240 $out .= $this->output->container_end(); // End of .plugins-check-dependencies container.
5a92cd0b
DM
1241
1242 return $out;
1243 }
1244
1245 /**
1246 * Displays the list if available missing dependencies.
1247 *
1248 * @param core_plugin_manager $pluginman
1249 * @param array $dependencies
1250 * @return string
1251 */
1252 protected function available_missing_dependencies_list(core_plugin_manager $pluginman, array $dependencies) {
1253 global $CFG;
1254
1255 $table = new html_table();
1256 $table->id = 'plugins-check-available-dependencies';
1257 $table->head = array(
1258 get_string('displayname', 'core_plugin'),
1259 get_string('release', 'core_plugin'),
1260 get_string('version', 'core_plugin'),
1261 get_string('supportedmoodleversions', 'core_plugin'),
1262 get_string('info', 'core'),
1263 );
1264 $table->colclasses = array('displayname', 'release', 'version', 'supportedmoodleversions', 'info');
1265 $table->data = array();
1266
1267 foreach ($dependencies as $plugin) {
1268
1269 $supportedmoodles = array();
1270 foreach ($plugin->version->supportedmoodles as $moodle) {
1271 if ($CFG->branch == str_replace('.', '', $moodle->release)) {
1272 $supportedmoodles[] = html_writer::span($moodle->release, 'label label-success');
1273 } else {
1274 $supportedmoodles[] = html_writer::span($moodle->release, 'label');
1275 }
1276 }
1277
1278 $requriedby = $pluginman->other_plugins_that_require($plugin->component);
1279 if ($requriedby) {
1280 foreach ($requriedby as $ix => $val) {
1281 $inf = $pluginman->get_plugin_info($val);
1282 if ($inf) {
1283 $requriedby[$ix] = $inf->displayname.' ('.$inf->component.')';
1284 }
1285 }
1286 $info = html_writer::div(
1287 get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
1288 'requiredby'
1289 );
1290 } else {
1291 $info = '';
1292 }
1293
9137a89a
DM
1294 $info .= $this->output->container_start('actions');
1295
1296 $info .= html_writer::div(
5a92cd0b
DM
1297 html_writer::link('https://moodle.org/plugins/view.php?plugin='.$plugin->component,
1298 get_string('misdepinfoplugin', 'core_plugin')),
1299 'misdepinfoplugin'
1300 );
1301
9137a89a 1302 $info .= html_writer::div(
5a92cd0b
DM
1303 html_writer::link('https://moodle.org/plugins/pluginversion.php?id='.$plugin->version->id,
1304 get_string('misdepinfoversion', 'core_plugin')),
1305 'misdepinfoversion'
1306 );
1307
9137a89a
DM
1308 $info .= html_writer::div(html_writer::link($plugin->version->downloadurl, get_string('download')), 'misdepdownload');
1309
36977a6d 1310 if ($pluginman->is_remote_plugin_installable($plugin->component, $plugin->version->version, $reason)) {
9137a89a
DM
1311 $info .= $this->output->single_button(
1312 new moodle_url($this->page->url, array('installdep' => $plugin->component)),
1313 get_string('dependencyinstall', 'core_plugin'),
1314 'post',
1315 array('class' => 'singlebutton dependencyinstall')
1316 );
36977a6d
DM
1317 } else {
1318 $reasonhelp = $this->info_remote_plugin_not_installable($reason);
1319 if ($reasonhelp) {
1320 $info .= html_writer::div($reasonhelp, 'reasonhelp dependencyinstall');
1321 }
9137a89a 1322 }
5a92cd0b 1323
30c26421 1324 $info .= $this->output->container_end(); // End of .actions container.
5a92cd0b
DM
1325
1326 $table->data[] = array(
1327 html_writer::div($plugin->name, 'name').' '.html_writer::div($plugin->component, 'component'),
1328 $plugin->version->release,
1329 $plugin->version->version,
1330 implode($supportedmoodles, ' '),
1331 $info
1332 );
1333 }
1334
1335 return html_writer::table($table);
1336 }
1337
36977a6d
DM
1338 /**
1339 * Explain why {@link core_plugin_manager::is_remote_plugin_installable()} returned false.
1340 *
1341 * @param string $reason the reason code as returned by the plugin manager
1342 * @return string
1343 */
1344 protected function info_remote_plugin_not_installable($reason) {
1345
1346 if ($reason === 'notwritableplugintype' or $reason === 'notwritableplugin') {
1347 return $this->output->help_icon('notwritable', 'core_plugin', get_string('notwritable', 'core_plugin'));
1348 }
1349
1350 if ($reason === 'remoteunavailable') {
1351 return $this->output->help_icon('notdownloadable', 'core_plugin', get_string('notdownloadable', 'core_plugin'));
1352 }
1353
1354 return false;
1355 }
1356
36ca62ca
TH
1357 /**
1358 * Formats the information that needs to go in the 'Requires' column.
e87214bd
PS
1359 * @param \core\plugininfo\base $plugin the plugin we are rendering the row for.
1360 * @param core_plugin_manager $pluginman provides data on all the plugins.
8d1da748
PS
1361 * @param string $version
1362 * @return string HTML code
36ca62ca 1363 */
e87214bd 1364 protected function required_column(\core\plugininfo\base $plugin, core_plugin_manager $pluginman, $version) {
7eb87eff 1365
36ca62ca 1366 $requires = array();
5a92cd0b
DM
1367 $displayuploadlink = false;
1368 $displayupdateslink = false;
36ca62ca 1369
7eb87eff
DM
1370 foreach ($pluginman->resolve_requirements($plugin, $version) as $reqname => $reqinfo) {
1371 if ($reqname === 'core') {
1372 if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OK) {
1373 $class = 'requires-ok';
1374 $label = '';
1375 } else {
1376 $class = 'requires-failed';
1377 $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'label label-important');
1378 }
1379 $requires[] = html_writer::tag('li',
1380 html_writer::span(get_string('moodleversion', 'core_plugin', $plugin->versionrequires), 'dep dep-core').
1381 ' '.$label, array('class' => $class));
36ca62ca 1382
7eb87eff
DM
1383 } else {
1384 $actions = array();
1385
1386 if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OK) {
1387 $label = '';
1388 $class = 'requires-ok';
1389
1390 } else if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_MISSING) {
5a92cd0b
DM
1391 if ($reqinfo->availability == $pluginman::REQUIREMENT_AVAILABLE) {
1392 $label = html_writer::span(get_string('dependencymissing', 'core_plugin'), 'label label-warning');
1393 $label .= ' '.html_writer::span(get_string('dependencyavailable', 'core_plugin'), 'label label-warning');
1394 $class = 'requires-failed requires-missing requires-available';
1395 $actions[] = html_writer::link(
1396 new moodle_url('https://moodle.org/plugins/view.php', array('plugin' => $reqname)),
1397 get_string('misdepinfoplugin', 'core_plugin')
1398 );
1399
1400 } else {
1401 $label = html_writer::span(get_string('dependencymissing', 'core_plugin'), 'label label-important');
1402 $label .= ' '.html_writer::span(get_string('dependencyunavailable', 'core_plugin'),
1403 'label label-important');
1404 $class = 'requires-failed requires-missing requires-unavailable';
1405 }
1406 $displayuploadlink = true;
7eb87eff
DM
1407
1408 } else if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OUTDATED) {
5a92cd0b
DM
1409 if ($reqinfo->availability == $pluginman::REQUIREMENT_AVAILABLE) {
1410 $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'label label-warning');
1411 $label .= ' '.html_writer::span(get_string('dependencyavailable', 'core_plugin'), 'label label-warning');
1412 $class = 'requires-failed requires-outdated requires-available';
1413 $displayupdateslink = true;
1414
1415 } else {
1416 $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'label label-important');
1417 $label .= ' '.html_writer::span(get_string('dependencyunavailable', 'core_plugin'),
1418 'label label-important');
1419 $class = 'requires-failed requires-outdated requires-unavailable';
1420 }
1421 $displayuploadlink = true;
2cdea9c7 1422 }
36ca62ca 1423
7eb87eff
DM
1424 if ($reqinfo->reqver != ANY_VERSION) {
1425 $str = 'otherpluginversion';
1426 } else {
1427 $str = 'otherplugin';
1428 }
36ca62ca 1429
7eb87eff
DM
1430 $requires[] = html_writer::tag('li', html_writer::span(
1431 get_string($str, 'core_plugin', array('component' => $reqname, 'version' => $reqinfo->reqver)),
1432 'dep dep-plugin').' '.$label.' '.html_writer::span(implode(' | ', $actions), 'actions'),
1433 array('class' => $class)
1434 );
36ca62ca 1435 }
36ca62ca
TH
1436 }
1437
1438 if (!$requires) {
1439 return '';
1440 }
5a92cd0b
DM
1441
1442 $out = html_writer::tag('ul', implode("\n", $requires));
1443
1444 if ($displayuploadlink) {
1445 $out .= html_writer::div(
1446 html_writer::link(
1447 new moodle_url('/admin/tool/installaddon/'),
1448 get_string('dependencyuploadmissing', 'core_plugin')
1449 ),
1450 'dependencyuploadmissing'
1451 );
1452 }
1453
1454 if ($displayupdateslink) {
1455 $out .= html_writer::div(
1456 html_writer::link(
1457 new moodle_url($this->page->url, array('sesskey' => sesskey(), 'fetchupdates' => 1)),
1458 get_string('checkforupdates', 'core_plugin')
1459 ),
1460 'checkforupdates'
1461 );
1462 }
1463
1464 return $out;
1465
36ca62ca
TH
1466 }
1467
d26f3ddd
DM
1468 /**
1469 * Prints an overview about the plugins - number of installed, number of extensions etc.
1470 *
e87214bd 1471 * @param core_plugin_manager $pluginman provides information about the plugins
4df8bced 1472 * @param array $options filtering options
d26f3ddd
DM
1473 * @return string as usually
1474 */
e87214bd 1475 public function plugins_overview_panel(core_plugin_manager $pluginman, array $options = array()) {
7716057f 1476
d26f3ddd
DM
1477 $plugininfo = $pluginman->get_plugins();
1478
44371554 1479 $numtotal = $numextension = $numupdatable = 0;
d26f3ddd
DM
1480
1481 foreach ($plugininfo as $type => $plugins) {
1482 foreach ($plugins as $name => $plugin) {
44371554
DM
1483 if ($plugin->available_updates()) {
1484 $numupdatable++;
1485 }
e87214bd 1486 if ($plugin->get_status() === core_plugin_manager::PLUGIN_STATUS_MISSING) {
d26f3ddd
DM
1487 continue;
1488 }
1489 $numtotal++;
d26f3ddd
DM
1490 if (!$plugin->is_standard()) {
1491 $numextension++;
1492 }
d26f3ddd
DM
1493 }
1494 }
1495
44371554
DM
1496 $infoall = html_writer::link(
1497 new moodle_url($this->page->url, array('contribonly' => 0, 'updatesonly' => 0)),
1498 get_string('overviewall', 'core_plugin'),
1499 array('title' => get_string('filterall', 'core_plugin'))
1500 ).' '.html_writer::span($numtotal, 'badge number number-all');
1501
1502 $infoext = html_writer::link(
1503 new moodle_url($this->page->url, array('contribonly' => 1, 'updatesonly' => 0)),
1504 get_string('overviewext', 'core_plugin'),
1505 array('title' => get_string('filtercontribonly', 'core_plugin'))
1506 ).' '.html_writer::span($numextension, 'badge number number-additional');
1507
1508 if ($numupdatable) {
1509 $infoupdatable = html_writer::link(
1510 new moodle_url($this->page->url, array('contribonly' => 0, 'updatesonly' => 1)),
1511 get_string('overviewupdatable', 'core_plugin'),
1512 array('title' => get_string('filterupdatesonly', 'core_plugin'))
1513 ).' '.html_writer::span($numupdatable, 'badge badge-info number number-updatable');
1514 } else {
1515 // No updates, or the notifications disabled.
1516 $infoupdatable = '';
4df8bced
DM
1517 }
1518
44371554 1519 $out = html_writer::start_div('', array('id' => 'plugins-overview-panel'));
d26f3ddd 1520
44371554
DM
1521 if (!empty($options['updatesonly'])) {
1522 $out .= $this->output->heading(get_string('overviewupdatable', 'core_plugin'), 3);
1523 } else if (!empty($options['contribonly'])) {
1524 $out .= $this->output->heading(get_string('overviewext', 'core_plugin'), 3);
4df8bced
DM
1525 }
1526
8726c07c
DM
1527 if ($numupdatable) {
1528 $installableupdates = $pluginman->filter_installable($pluginman->available_updates());
1529 if ($installableupdates) {
1530 $out .= $this->output->single_button(
1531 new moodle_url($this->page->url, array('installupdatex' => 1)),
1532 get_string('updateavailableinstallall', 'core_admin', count($installableupdates)),
1533 'post',
1534 array('class' => 'singlebutton updateavailableinstallall')
1535 );
1536 }
1537 }
1538
44371554
DM
1539 $out .= html_writer::div($infoall, 'info info-all').
1540 html_writer::div($infoext, 'info info-ext').
1541 html_writer::div($infoupdatable, 'info info-updatable');
1542
30c26421 1543 $out .= html_writer::end_div(); // End of #plugins-overview-panel block.
44371554
DM
1544
1545 return $out;
d26f3ddd
DM
1546 }
1547
b9934a17
DM
1548 /**
1549 * Displays all known plugins and links to manage them
1550 *
1551 * This default implementation renders all plugins into one big table.
1552 *
e87214bd 1553 * @param core_plugin_manager $pluginman provides information about the plugins.
4df8bced 1554 * @param array $options filtering options
b9934a17
DM
1555 * @return string HTML code
1556 */
e87214bd 1557 public function plugins_control_panel(core_plugin_manager $pluginman, array $options = array()) {
7716057f 1558
36ca62ca 1559 $plugininfo = $pluginman->get_plugins();
b9934a17 1560
4df8bced
DM
1561 // Filter the list of plugins according the options.
1562 if (!empty($options['updatesonly'])) {
1563 $updateable = array();
1564 foreach ($plugininfo as $plugintype => $pluginnames) {
1565 foreach ($pluginnames as $pluginname => $pluginfo) {
30d8bc5f
DM
1566 $pluginavailableupdates = $pluginfo->available_updates();
1567 if (!empty($pluginavailableupdates)) {
1568 foreach ($pluginavailableupdates as $pluginavailableupdate) {
1569 $updateable[$plugintype][$pluginname] = $pluginfo;
4df8bced
DM
1570 }
1571 }
1572 }
1573 }
1574 $plugininfo = $updateable;
1575 }
1576
1577 if (!empty($options['contribonly'])) {
1578 $contribs = array();
1579 foreach ($plugininfo as $plugintype => $pluginnames) {
1580 foreach ($pluginnames as $pluginname => $pluginfo) {
1581 if (!$pluginfo->is_standard()) {
1582 $contribs[$plugintype][$pluginname] = $pluginfo;
1583 }
1584 }
1585 }
1586 $plugininfo = $contribs;
1587 }
1588
b9934a17
DM
1589 if (empty($plugininfo)) {
1590 return '';
1591 }
1592
b9934a17
DM
1593 $table = new html_table();
1594 $table->id = 'plugins-control-panel';
1595 $table->head = array(
1596 get_string('displayname', 'core_plugin'),
b9934a17
DM
1597 get_string('version', 'core_plugin'),
1598 get_string('availability', 'core_plugin'),
2b135b05
DM
1599 get_string('actions', 'core_plugin'),
1600 get_string('notes','core_plugin'),
b9934a17 1601 );
44371554 1602 $table->headspan = array(1, 1, 1, 2, 1);
b9934a17 1603 $table->colclasses = array(
44371554 1604 'pluginname', 'version', 'availability', 'settings', 'uninstall', 'notes'
b9934a17
DM
1605 );
1606
1607 foreach ($plugininfo as $type => $plugins) {
e87214bd
PS
1608 $heading = $pluginman->plugintype_name_plural($type);
1609 $pluginclass = core_plugin_manager::resolve_plugininfo_class($type);
1610 if ($manageurl = $pluginclass::get_manage_url()) {
44371554
DM
1611 $heading .= $this->output->action_icon($manageurl, new pix_icon('i/settings',
1612 get_string('settings', 'core_plugin')));
e87214bd
PS
1613 }
1614 $header = new html_table_cell(html_writer::tag('span', $heading, array('id'=>'plugin_type_cell_'.$type)));
b9934a17 1615 $header->header = true;
54d75893 1616 $header->colspan = array_sum($table->headspan);
b9934a17
DM
1617 $header = new html_table_row(array($header));
1618 $header->attributes['class'] = 'plugintypeheader type-' . $type;
1619 $table->data[] = $header;
1620
1621 if (empty($plugins)) {
1622 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
54d75893 1623 $msg->colspan = array_sum($table->headspan);
b9934a17
DM
1624 $row = new html_table_row(array($msg));
1625 $row->attributes['class'] .= 'msg msg-noneinstalled';
1626 $table->data[] = $row;
1627 continue;
1628 }
1629
1630 foreach ($plugins as $name => $plugin) {
1631 $row = new html_table_row();
1632 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
1633
6abce1e1 1634 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name, null)) {
fa9c0aab 1635 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'icon pluginicon'));
b9934a17 1636 } else {
b4ef04e7 1637 $icon = $this->output->spacer();
b9934a17 1638 }
9074e478
DM
1639 $status = $plugin->get_status();
1640 $row->attributes['class'] .= ' status-'.$status;
44371554 1641 $pluginname = html_writer::tag('div', $icon.$plugin->displayname, array('class' => 'displayname')).
2b135b05
DM
1642 html_writer::tag('div', $plugin->component, array('class' => 'componentname'));
1643 $pluginname = new html_table_cell($pluginname);
b9934a17 1644
44371554
DM
1645 $version = html_writer::div($plugin->versiondb, 'versionnumber');
1646 if ((string)$plugin->release !== '') {
1647 $version = html_writer::div($plugin->release, 'release').$version;
b9934a17 1648 }
44371554 1649 $version = new html_table_cell($version);
b9934a17
DM
1650
1651 $isenabled = $plugin->is_enabled();
1652 if (is_null($isenabled)) {
1653 $availability = new html_table_cell('');
1654 } else if ($isenabled) {
1655 $row->attributes['class'] .= ' enabled';
7bc759bd 1656 $availability = new html_table_cell(get_string('pluginenabled', 'core_plugin'));
b9934a17
DM
1657 } else {
1658 $row->attributes['class'] .= ' disabled';
7bc759bd 1659 $availability = new html_table_cell(get_string('plugindisabled', 'core_plugin'));
b9934a17
DM
1660 }
1661
1662 $settingsurl = $plugin->get_settings_url();
2b135b05 1663 if (!is_null($settingsurl)) {
54d75893
DM
1664 $settings = html_writer::link($settingsurl, get_string('settings', 'core_plugin'), array('class' => 'settings'));
1665 } else {
1666 $settings = '';
b9934a17 1667 }
54d75893 1668 $settings = new html_table_cell($settings);
b9934a17 1669
e87214bd 1670 if ($uninstallurl = $pluginman->get_uninstall_url($plugin->component, 'overview')) {
54d75893
DM
1671 $uninstall = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin'));
1672 } else {
1673 $uninstall = '';
2b135b05 1674 }
54d75893 1675 $uninstall = new html_table_cell($uninstall);
2b135b05 1676
44371554
DM
1677 if ($plugin->is_standard()) {
1678 $row->attributes['class'] .= ' standard';
44371554
DM
1679 $source = '';
1680 } else {
1681 $row->attributes['class'] .= ' extension';
1682 $source = html_writer::div(get_string('sourceext', 'core_plugin'), 'source label label-info');
1683 }
1684
1685 if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) {
1686 $msg = html_writer::div(get_string('status_missing', 'core_plugin'), 'statusmsg label label-important');
1687 } else if ($status === core_plugin_manager::PLUGIN_STATUS_NEW) {
1688 $msg = html_writer::div(get_string('status_new', 'core_plugin'), 'statusmsg label label-success');
1689 } else {
1690 $msg = '';
1691 }
1692
828788f0 1693 $requriedby = $pluginman->other_plugins_that_require($plugin->component);
2b135b05
DM
1694 if ($requriedby) {
1695 $requiredby = html_writer::tag('div', get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
1696 array('class' => 'requiredby'));
b9934a17 1697 } else {
2b135b05 1698 $requiredby = '';
b9934a17
DM
1699 }
1700
7d8de6d8 1701 $updateinfo = '';
e9d3c212 1702 if (is_array($plugin->available_updates())) {
7d8de6d8 1703 foreach ($plugin->available_updates() as $availableupdate) {
3bca7dbf 1704 $updateinfo .= $this->plugin_available_update_info($pluginman, $availableupdate);
7d8de6d8 1705 }
3204daea
DM
1706 }
1707
44371554 1708 $notes = new html_table_cell($source.$msg.$requiredby.$updateinfo);
2b135b05 1709
b9934a17 1710 $row->cells = array(
44371554 1711 $pluginname, $version, $availability, $settings, $uninstall, $notes
b9934a17
DM
1712 );
1713 $table->data[] = $row;
1714 }
1715 }
1716
1717 return html_writer::table($table);
1718 }
da2fdc3f 1719
3204daea 1720 /**
e7611389 1721 * Helper method to render the information about the available plugin update
3204daea 1722 *
3bca7dbf 1723 * @param core_plugin_manager $pluginman plugin manager instance
e87214bd 1724 * @param \core\update\info $updateinfo information about the available update for the plugin
3204daea 1725 */
3bca7dbf 1726 protected function plugin_available_update_info(core_plugin_manager $pluginman, \core\update\info $updateinfo) {
3204daea 1727
e7611389 1728 $boxclasses = 'pluginupdateinfo';
3204daea
DM
1729 $info = array();
1730
1731 if (isset($updateinfo->release)) {
44371554
DM
1732 $info[] = html_writer::div(
1733 get_string('updateavailable_release', 'core_plugin', $updateinfo->release),
1734 'info release'
1735 );
3204daea
DM
1736 }
1737
1738 if (isset($updateinfo->maturity)) {
44371554
DM
1739 $info[] = html_writer::div(
1740 get_string('maturity'.$updateinfo->maturity, 'core_admin'),
1741 'info maturity'
1742 );
e7611389 1743 $boxclasses .= ' maturity'.$updateinfo->maturity;
3204daea
DM
1744 }
1745
1746 if (isset($updateinfo->download)) {
44371554
DM
1747 $info[] = html_writer::div(
1748 html_writer::link($updateinfo->download, get_string('download')),
1749 'info download'
1750 );
3204daea
DM
1751 }
1752
1753 if (isset($updateinfo->url)) {
44371554
DM
1754 $info[] = html_writer::div(
1755 html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin')),
1756 'info more'
1757 );
3204daea
DM
1758 }
1759
44371554
DM
1760 $box = html_writer::start_div($boxclasses);
1761 $box .= html_writer::div(
1762 get_string('updateavailable', 'core_plugin', $updateinfo->version),
1763 'version'
1764 );
1765 $box .= html_writer::div(
1766 implode(html_writer::span(' ', 'separator'), $info),
1767 'infos'
1768 );
fa3feafb 1769
3bca7dbf
DM
1770 if ($pluginman->is_remote_plugin_installable($updateinfo->component, $updateinfo->version, $reason)) {
1771 $box .= $this->output->single_button(
1772 new moodle_url($this->page->url, array('installupdate' => $updateinfo->component,
1773 'installupdateversion' => $updateinfo->version)),
1774 get_string('updateavailableinstall', 'core_admin'),
1775 'post',
1776 array('class' => 'singlebutton updateavailableinstall')
1777 );
1778 } else {
1779 $reasonhelp = $this->info_remote_plugin_not_installable($reason);
1780 if ($reasonhelp) {
1781 $box .= html_writer::div($reasonhelp, 'reasonhelp updateavailableinstall');
0daa6428 1782 }
fa3feafb 1783 }
44371554 1784 $box .= html_writer::end_div();
3204daea
DM
1785
1786 return $box;
1787 }
1788
da2fdc3f 1789 /**
cc359566
TH
1790 * This function will render one beautiful table with all the environmental
1791 * configuration and how it suits Moodle needs.
1792 *
1793 * @param boolean $result final result of the check (true/false)
40cba608 1794 * @param environment_results[] $environment_results array of results gathered
cc359566 1795 * @return string HTML to output.
da2fdc3f 1796 */
cc359566
TH
1797 public function environment_check_table($result, $environment_results) {
1798 global $CFG;
1799
1800 // Table headers
1801 $servertable = new html_table();//table for server checks
1802 $servertable->head = array(
1803 get_string('name'),
1804 get_string('info'),
1805 get_string('report'),
40cba608 1806 get_string('plugin'),
cc359566
TH
1807 get_string('status'),
1808 );
40cba608 1809 $servertable->colclasses = array('centeralign name', 'centeralign info', 'leftalign report', 'leftalign plugin', 'centeralign status');
6fc61f2d
RW
1810 $servertable->attributes['class'] = 'admintable environmenttable generaltable';
1811 $servertable->id = 'serverstatus';
cc359566
TH
1812
1813 $serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
1814
1815 $othertable = new html_table();//table for custom checks
1816 $othertable->head = array(
1817 get_string('info'),
1818 get_string('report'),
40cba608 1819 get_string('plugin'),
cc359566
TH
1820 get_string('status'),
1821 );
40cba608 1822 $othertable->colclasses = array('aligncenter info', 'alignleft report', 'alignleft plugin', 'aligncenter status');
6fc61f2d
RW
1823 $othertable->attributes['class'] = 'admintable environmenttable generaltable';
1824 $othertable->id = 'otherserverstatus';
cc359566
TH
1825
1826 $otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
1827
1828 // Iterate over each environment_result
1829 $continue = true;
1830 foreach ($environment_results as $environment_result) {
1831 $errorline = false;
1832 $warningline = false;
1833 $stringtouse = '';
1834 if ($continue) {
1835 $type = $environment_result->getPart();
1836 $info = $environment_result->getInfo();
1837 $status = $environment_result->getStatus();
40cba608 1838 $plugin = $environment_result->getPluginName();
cc359566
TH
1839 $error_code = $environment_result->getErrorCode();
1840 // Process Report field
1841 $rec = new stdClass();
1842 // Something has gone wrong at parsing time
1843 if ($error_code) {
1844 $stringtouse = 'environmentxmlerror';
1845 $rec->error_code = $error_code;
1846 $status = get_string('error');
1847 $errorline = true;
1848 $continue = false;
1849 }
1850
1851 if ($continue) {
1852 if ($rec->needed = $environment_result->getNeededVersion()) {
1853 // We are comparing versions
1854 $rec->current = $environment_result->getCurrentVersion();
1855 if ($environment_result->getLevel() == 'required') {
1856 $stringtouse = 'environmentrequireversion';
1857 } else {
1858 $stringtouse = 'environmentrecommendversion';
1859 }
1860
1861 } else if ($environment_result->getPart() == 'custom_check') {
1862 // We are checking installed & enabled things
1863 if ($environment_result->getLevel() == 'required') {
1864 $stringtouse = 'environmentrequirecustomcheck';
1865 } else {
1866 $stringtouse = 'environmentrecommendcustomcheck';
1867 }
1868
1869 } else if ($environment_result->getPart() == 'php_setting') {
1870 if ($status) {
1871 $stringtouse = 'environmentsettingok';
1872 } else if ($environment_result->getLevel() == 'required') {
1873 $stringtouse = 'environmentmustfixsetting';
1874 } else {
1875 $stringtouse = 'environmentshouldfixsetting';
1876 }
1877
1878 } else {
1879 if ($environment_result->getLevel() == 'required') {
1880 $stringtouse = 'environmentrequireinstall';
1881 } else {
1882 $stringtouse = 'environmentrecommendinstall';
1883 }
1884 }
1885
1886 // Calculate the status value
1887 if ($environment_result->getBypassStr() != '') { //Handle bypassed result (warning)
1888 $status = get_string('bypassed');
1889 $warningline = true;
1890 } else if ($environment_result->getRestrictStr() != '') { //Handle restricted result (error)
1891 $status = get_string('restricted');
1892 $errorline = true;
1893 } else {
1894 if ($status) { //Handle ok result (ok)
1895 $status = get_string('ok');
1896 } else {
1897 if ($environment_result->getLevel() == 'optional') {//Handle check result (warning)
1898 $status = get_string('check');
1899 $warningline = true;
1900 } else { //Handle error result (error)
1901 $status = get_string('check');
1902 $errorline = true;
1903 }
1904 }
1905 }
1906 }
1907
1908 // Build the text
1909 $linkparts = array();
1910 $linkparts[] = 'admin/environment';
1911 $linkparts[] = $type;
1912 if (!empty($info)){
1913 $linkparts[] = $info;
1914 }
40cba608
PS
1915 // Plugin environments do not have docs pages yet.
1916 if (empty($CFG->docroot) or $environment_result->plugin) {
cc359566
TH
1917 $report = get_string($stringtouse, 'admin', $rec);
1918 } else {
1919 $report = $this->doc_link(join($linkparts, '/'), get_string($stringtouse, 'admin', $rec));
1920 }
5920f633
JP
1921 // Enclose report text in div so feedback text will be displayed underneath it.
1922 $report = html_writer::div($report);
cc359566
TH
1923
1924 // Format error or warning line
5920f633
JP
1925 if ($errorline) {
1926 $messagetype = 'error';
1927 $statusclass = 'label-important';
1928 } else if ($warningline) {
1929 $messagetype = 'warn';
1930 $statusclass = 'label-warning';
cc359566
TH
1931 } else {
1932 $messagetype = 'ok';
5920f633 1933 $statusclass = 'label-success';
cc359566 1934 }
5920f633 1935 $status = html_writer::span($status, 'label ' . $statusclass);
cc359566
TH
1936 // Here we'll store all the feedback found
1937 $feedbacktext = '';
1938 // Append the feedback if there is some
1939 $feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), $messagetype);
1940 //Append the bypass if there is some
1941 $feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'warn');
1942 //Append the restrict if there is some
1943 $feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'error');
1944
1945 $report .= $feedbacktext;
1946
1947 // Add the row to the table
1948 if ($environment_result->getPart() == 'custom_check'){
40cba608 1949 $otherdata[$messagetype][] = array ($info, $report, $plugin, $status);
cc359566 1950 } else {
40cba608 1951 $serverdata[$messagetype][] = array ($type, $info, $report, $plugin, $status);
cc359566
TH
1952 }
1953 }
1954 }
1955
1956 //put errors first in
1957 $servertable->data = array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']);
1958 $othertable->data = array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']);
1959
1960 // Print table
1961 $output = '';
1962 $output .= $this->heading(get_string('serverchecks', 'admin'));
1963 $output .= html_writer::table($servertable);
1964 if (count($othertable->data)){
1965 $output .= $this->heading(get_string('customcheck', 'admin'));
1966 $output .= html_writer::table($othertable);
1967 }
1968
1969 // Finally, if any error has happened, print the summary box
1970 if (!$result) {
1971 $output .= $this->box(get_string('environmenterrortodo', 'admin'), 'environmentbox errorbox');
1972 }
1973
1974 return $output;
da2fdc3f 1975 }
98b32c9e
DM
1976
1977 /**
1978 * Render a simple page for providing the upgrade key.
1979 *
1980 * @param moodle_url|string $url
1981 * @return string
1982 */
1983 public function upgradekey_form_page($url) {
1984
1985 $output = '';
1986 $output .= $this->header();
1987 $output .= $this->container_start('upgradekeyreq');
1988 $output .= $this->heading(get_string('upgradekeyreq', 'core_admin'));
1989 $output .= html_writer::start_tag('form', array('method' => 'POST', 'action' => $url));
1990 $output .= html_writer::empty_tag('input', array('name' => 'upgradekey', 'type' => 'password'));
1991 $output .= html_writer::empty_tag('input', array('value' => get_string('submit'), 'type' => 'submit'));
1992 $output .= html_writer::end_tag('form');
1993 $output .= $this->container_end();
1994 $output .= $this->footer();
1995
1996 return $output;
1997 }
61f7b10b
AG
1998
1999 /**
2000 * Check to see if writing to the deprecated legacy log store is enabled.
2001 *
2002 * @return string An error message if writing to the legacy log store is enabled.
2003 */
3f195ab7 2004 protected function legacy_log_store_writing_error() {
61f7b10b 2005 $enabled = get_config('logstore_legacy', 'loglegacy');
a285d561
JO
2006 $plugins = explode(',', get_config('tool_log', 'enabled_stores'));
2007 $enabled = $enabled && in_array('logstore_legacy', $plugins);
2008
61f7b10b 2009 if ($enabled) {
e8d90872 2010 return $this->warning(get_string('legacylogginginuse'));
61f7b10b
AG
2011 }
2012 }
b9934a17 2013}