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