Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 * Standard HTML output 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
class core_admin_renderer extends plugin_renderer_base {
26
 
27
    /**
28
     * Display the 'Do you acknowledge the terms of the GPL' page. The first page
29
     * during install.
30
     * @return string HTML to output.
31
     */
32
    public function install_licence_page() {
33
        global $CFG;
34
        $output = '';
35
 
36
        $copyrightnotice = text_to_html(get_string('gpl3'));
37
        $copyrightnotice = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $copyrightnotice); // extremely ugly validation hack
38
 
39
        $continue = new single_button(new moodle_url($this->page->url, array(
40
            'lang' => $CFG->lang, 'agreelicense' => 1)), get_string('continue'), 'get');
41
 
42
        $output .= $this->header();
43
        $output .= $this->heading('<a href="http://moodle.org">Moodle</a> - Modular Object-Oriented Dynamic Learning Environment');
44
        $output .= $this->heading(get_string('copyrightnotice'));
45
        $output .= $this->box($copyrightnotice, 'copyrightnotice');
46
        $output .= html_writer::empty_tag('br');
47
        $output .= $this->confirm(get_string('doyouagree'), $continue, "https://moodledev.io/general/license");
48
        $output .= $this->footer();
49
 
50
        return $output;
51
    }
52
 
53
    /**
54
     * Display page explaining proper upgrade process,
55
     * there can not be any PHP file leftovers...
56
     *
57
     * @return string HTML to output.
58
     */
59
    public function upgrade_stale_php_files_page() {
60
        $output = '';
61
        $output .= $this->header();
62
        $output .= $this->heading(get_string('upgradestalefiles', 'admin'));
63
        $output .= $this->box_start('generalbox', 'notice');
64
        $output .= format_text(get_string('upgradestalefilesinfo', 'admin', get_docs_url('Upgrading')), FORMAT_MARKDOWN);
65
        $output .= html_writer::empty_tag('br');
66
        $output .= html_writer::tag('div', $this->single_button($this->page->url, get_string('reload'), 'get'), array('class' => 'buttons'));
67
        $output .= $this->box_end();
68
        $output .= $this->footer();
69
 
70
        return $output;
71
    }
72
 
73
    /**
74
     * Display the 'environment check' page that is displayed during install.
75
     * @param int $maturity
76
     * @param boolean $envstatus final result of the check (true/false)
77
     * @param array $environment_results array of results gathered
78
     * @param string $release moodle release
79
     * @return string HTML to output.
80
     */
81
    public function install_environment_page($maturity, $envstatus, $environment_results, $release) {
82
        global $CFG;
83
        $output = '';
84
 
85
        $output .= $this->header();
86
        $output .= $this->maturity_warning($maturity);
87
        $output .= $this->heading("Moodle $release");
88
        $output .= $this->release_notes_link();
89
 
90
        $output .= $this->environment_check_table($envstatus, $environment_results);
91
 
92
        if (!$envstatus) {
93
            $output .= $this->upgrade_reload(new moodle_url($this->page->url, array('agreelicense' => 1, 'lang' => $CFG->lang)));
94
        } else {
95
            $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
96
            $output .= $this->continue_button(new moodle_url($this->page->url, array(
97
                'agreelicense' => 1, 'confirmrelease' => 1, 'lang' => $CFG->lang)));
98
        }
99
 
100
        $output .= $this->footer();
101
        return $output;
102
    }
103
 
104
    /**
105
     * Displays the list of plugins with unsatisfied dependencies
106
     *
107
     * @param double|string|int $version Moodle on-disk version
108
     * @param array $failed list of plugins with unsatisfied dependecies
109
     * @param moodle_url $reloadurl URL of the page to recheck the dependencies
110
     * @return string HTML
111
     */
112
    public function unsatisfied_dependencies_page($version, array $failed, moodle_url $reloadurl) {
113
        $output = '';
114
 
115
        $output .= $this->header();
116
        $output .= $this->heading(get_string('pluginscheck', 'admin'));
117
        $output .= $this->warning(get_string('pluginscheckfailed', 'admin', array('pluginslist' => implode(', ', array_unique($failed)))));
118
        $output .= $this->plugins_check_table(core_plugin_manager::instance(), $version, array('xdep' => true));
119
        $output .= $this->warning(get_string('pluginschecktodo', 'admin'));
120
        $output .= $this->continue_button($reloadurl);
121
 
122
        $output .= $this->footer();
123
 
124
        return $output;
125
    }
126
 
127
    /**
128
     * Display the 'You are about to upgrade Moodle' page. The first page
129
     * during upgrade.
130
     * @param string $strnewversion
131
     * @param int $maturity
132
     * @param string $testsite
133
     * @return string HTML to output.
134
     */
135
    public function upgrade_confirm_page($strnewversion, $maturity, $testsite) {
136
        $output = '';
137
 
138
        $continueurl = new moodle_url($this->page->url, array('confirmupgrade' => 1, 'cache' => 0));
139
        $continue = new single_button($continueurl, get_string('continue'), 'get');
140
        $cancelurl = new moodle_url('/admin/index.php');
141
 
142
        $output .= $this->header();
143
        $output .= $this->maturity_warning($maturity);
144
        $output .= $this->test_site_warning($testsite);
145
        $output .= $this->confirm(get_string('upgradesure', 'admin', $strnewversion), $continue, $cancelurl);
146
        $output .= $this->footer();
147
 
148
        return $output;
149
    }
150
 
151
    /**
152
     * Display the environment page during the upgrade process.
153
     * @param string $release
154
     * @param boolean $envstatus final result of env check (true/false)
155
     * @param array $environment_results array of results gathered
156
     * @return string HTML to output.
157
     */
158
    public function upgrade_environment_page($release, $envstatus, $environment_results) {
159
        global $CFG;
160
        $output = '';
161
 
162
        $output .= $this->header();
163
        $output .= $this->heading("Moodle $release");
164
        $output .= $this->release_notes_link();
165
        $output .= $this->environment_check_table($envstatus, $environment_results);
166
 
167
        if (!$envstatus) {
168
            $output .= $this->upgrade_reload(new moodle_url($this->page->url, array('confirmupgrade' => 1, 'cache' => 0)));
169
 
170
        } else {
171
            $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
172
 
173
            if (empty($CFG->skiplangupgrade) and current_language() !== 'en') {
174
                $output .= $this->box(get_string('langpackwillbeupdated', 'admin'), 'generalbox', 'notice');
175
            }
176
 
177
            $output .= $this->continue_button(new moodle_url($this->page->url, array(
178
                'confirmupgrade' => 1, 'confirmrelease' => 1, 'cache' => 0)));
179
        }
180
 
181
        $output .= $this->footer();
182
 
183
        return $output;
184
    }
185
 
186
    /**
187
     * Display the upgrade page that lists all the plugins that require attention.
188
     * @param core_plugin_manager $pluginman provides information about the plugins.
189
     * @param \core\update\checker $checker provides information about available updates.
190
     * @param int $version the version of the Moodle code from version.php.
191
     * @param bool $showallplugins
192
     * @param moodle_url $reloadurl
193
     * @param moodle_url $continueurl
194
     * @return string HTML to output.
195
     */
196
    public function upgrade_plugin_check_page(core_plugin_manager $pluginman, \core\update\checker $checker,
197
            $version, $showallplugins, $reloadurl, $continueurl) {
198
 
199
        $output = '';
200
 
201
        $output .= $this->header();
202
        $output .= $this->box_start('generalbox', 'plugins-check-page');
203
        $output .= html_writer::tag('p', get_string('pluginchecknotice', 'core_plugin'), array('class' => 'page-description'));
204
        $output .= $this->check_for_updates_button($checker, $reloadurl);
205
        $output .= $this->missing_dependencies($pluginman);
206
        $output .= $this->plugins_check_table($pluginman, $version, array('full' => $showallplugins));
207
        $output .= $this->box_end();
208
        $output .= $this->upgrade_reload($reloadurl);
209
 
210
        if ($pluginman->some_plugins_updatable()) {
211
            $output .= $this->container_start('upgradepluginsinfo');
212
            $output .= $this->help_icon('upgradepluginsinfo', 'core_admin', get_string('upgradepluginsfirst', 'core_admin'));
213
            $output .= $this->container_end();
214
        }
215
 
216
        $button = new single_button($continueurl, get_string('upgradestart', 'admin'), 'get', single_button::BUTTON_PRIMARY);
217
        $button->class = 'continuebutton';
218
        $output .= $this->render($button);
219
        $output .= $this->footer();
220
 
221
        return $output;
222
    }
223
 
224
    /**
225
     * Display a page to confirm plugin installation cancelation.
226
     *
227
     * @param array $abortable list of \core\update\plugininfo
228
     * @param moodle_url $continue
229
     * @return string
230
     */
231
    public function upgrade_confirm_abort_install_page(array $abortable, moodle_url $continue) {
232
 
233
        $pluginman = core_plugin_manager::instance();
234
 
235
        if (empty($abortable)) {
236
            // The UI should not allow this.
237
            throw new moodle_exception('err_no_plugin_install_abortable', 'core_plugin');
238
        }
239
 
240
        $out = $this->output->header();
241
        $out .= $this->output->heading(get_string('cancelinstallhead', 'core_plugin'), 3);
242
        $out .= $this->output->container(get_string('cancelinstallinfo', 'core_plugin'), 'cancelinstallinfo');
243
 
244
        foreach ($abortable as $pluginfo) {
245
            $out .= $this->output->heading($pluginfo->displayname.' ('.$pluginfo->component.')', 4);
246
            $out .= $this->output->container(get_string('cancelinstallinfodir', 'core_plugin', $pluginfo->rootdir));
247
            if ($repotype = $pluginman->plugin_external_source($pluginfo->component)) {
248
                $out .= $this->output->container(get_string('uninstalldeleteconfirmexternal', 'core_plugin', $repotype),
249
                    'alert alert-warning mt-2');
250
            }
251
        }
252
 
253
        $out .= $this->plugins_management_confirm_buttons($continue, $this->page->url);
254
        $out .= $this->output->footer();
255
 
256
        return $out;
257
    }
258
 
259
    /**
260
     * Display the admin notifications page.
261
     * @param int $maturity
262
     * @param bool $insecuredataroot warn dataroot is invalid
263
     * @param bool $errorsdisplayed warn invalid dispaly error setting
264
     * @param bool $cronoverdue warn cron not running
265
     * @param bool $dbproblems warn db has problems
266
     * @param bool $maintenancemode warn in maintenance mode
267
     * @param bool $buggyiconvnomb warn iconv problems
268
     * @param array|null $availableupdates array of \core\update\info objects or null
269
     * @param int|null $availableupdatesfetch timestamp of the most recent updates fetch or null (unknown)
270
     * @param string[] $cachewarnings An array containing warnings from the Cache API.
271
     * @param array $eventshandlers Events 1 API handlers.
272
     * @param bool $themedesignermode Warn about the theme designer mode.
273
     * @param bool $devlibdir Warn about development libs directory presence.
274
     * @param bool $mobileconfigured Whether the mobile web services have been enabled
275
     * @param bool $overridetossl Whether or not ssl is being forced.
276
     * @param bool $invalidforgottenpasswordurl Whether the forgotten password URL does not link to a valid URL.
277
     * @param bool $croninfrequent If true, warn that cron hasn't run in the past few minutes
278
     * @param bool $showcampaigncontent Whether the campaign content should be visible or not.
279
     * @param bool $showfeedbackencouragement Whether the feedback encouragement content should be displayed or not.
280
     * @param bool $showservicesandsupport Whether the services and support content should be displayed or not.
281
     * @param string $xmlrpcwarning XML-RPC deprecation warning message.
282
     *
283
     * @return string HTML to output.
284
     */
285
    public function admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed,
286
            $cronoverdue, $dbproblems, $maintenancemode, $availableupdates, $availableupdatesfetch,
287
            $buggyiconvnomb, $registered, array $cachewarnings = array(), $eventshandlers = 0,
288
            $themedesignermode = false, $devlibdir = false, $mobileconfigured = false,
289
            $overridetossl = false, $invalidforgottenpasswordurl = false, $croninfrequent = false,
290
            $showcampaigncontent = false, bool $showfeedbackencouragement = false, bool $showservicesandsupport = false,
291
            $xmlrpcwarning = '') {
292
 
293
        global $CFG;
294
        $output = '';
295
 
296
        $output .= $this->header();
297
        $output .= $this->output->heading(get_string('notifications', 'admin'));
298
        $output .= $this->maturity_info($maturity);
299
        $output .= empty($CFG->disableupdatenotifications) ? $this->available_updates($availableupdates, $availableupdatesfetch) : '';
300
        $output .= $this->insecure_dataroot_warning($insecuredataroot);
301
        $output .= $this->development_libs_directories_warning($devlibdir);
302
        $output .= $this->themedesignermode_warning($themedesignermode);
303
        $output .= $this->display_errors_warning($errorsdisplayed);
304
        $output .= $this->buggy_iconv_warning($buggyiconvnomb);
305
        $output .= $this->cron_overdue_warning($cronoverdue);
306
        $output .= $this->cron_infrequent_warning($croninfrequent);
307
        $output .= $this->db_problems($dbproblems);
308
        $output .= $this->maintenance_mode_warning($maintenancemode);
309
        $output .= $this->overridetossl_warning($overridetossl);
310
        $output .= $this->cache_warnings($cachewarnings);
311
        $output .= $this->events_handlers($eventshandlers);
312
        $output .= $this->registration_warning($registered);
313
        $output .= $this->mobile_configuration_warning($mobileconfigured);
314
        $output .= $this->forgotten_password_url_warning($invalidforgottenpasswordurl);
315
        $output .= $this->mnet_deprecation_warning($xmlrpcwarning);
316
        $output .= $this->userfeedback_encouragement($showfeedbackencouragement);
317
        $output .= $this->services_and_support_content($showservicesandsupport);
318
        $output .= $this->campaign_content($showcampaigncontent);
319
 
320
        //////////////////////////////////////////////////////////////////////////////////////////////////
321
        ////  IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
322
        $output .= $this->moodle_copyright();
323
        //////////////////////////////////////////////////////////////////////////////////////////////////
324
 
325
        $output .= $this->footer();
326
 
327
        return $output;
328
    }
329
 
330
    /**
331
     * Display the plugin management page (admin/plugins.php).
332
     *
333
     * The filtering options array may contain following items:
334
     *  bool contribonly - show only contributed extensions
335
     *  bool updatesonly - show only plugins with an available update
336
     *
337
     * @param core_plugin_manager $pluginman
338
     * @param \core\update\checker $checker
339
     * @param array $options filtering options
340
     * @return string HTML to output.
341
     */
342
    public function plugin_management_page(core_plugin_manager $pluginman, \core\update\checker $checker, array $options = array()) {
343
 
344
        $output = '';
345
 
346
        $output .= $this->header();
347
        $output .= $this->heading(get_string('pluginsoverview', 'core_admin'));
348
        $output .= $this->check_for_updates_button($checker, $this->page->url);
349
        $output .= $this->plugins_overview_panel($pluginman, $options);
350
        $output .= $this->plugins_control_panel($pluginman, $options);
351
        $output .= $this->footer();
352
 
353
        return $output;
354
    }
355
 
356
    /**
357
     * Renders a button to fetch for available updates.
358
     *
359
     * @param \core\update\checker $checker
360
     * @param moodle_url $reloadurl
361
     * @return string HTML
362
     */
363
    public function check_for_updates_button(\core\update\checker $checker, $reloadurl) {
364
 
365
        $output = '';
366
 
367
        if ($checker->enabled()) {
368
            $output .= $this->container_start('checkforupdates mb-4');
369
            $output .= $this->single_button(
370
                new moodle_url($reloadurl, array('fetchupdates' => 1)),
371
                get_string('checkforupdates', 'core_plugin')
372
            );
373
            if ($timefetched = $checker->get_last_timefetched()) {
374
                $timefetched = userdate($timefetched, get_string('strftimedatetime', 'core_langconfig'));
375
                $output .= $this->container(get_string('checkforupdateslast', 'core_plugin', $timefetched),
376
                    'lasttimefetched small text-muted mt-1');
377
            }
378
            $output .= $this->container_end();
379
        }
380
 
381
        return $output;
382
    }
383
 
384
    /**
385
     * Display a page to confirm the plugin uninstallation.
386
     *
387
     * @param core_plugin_manager $pluginman
388
     * @param \core\plugininfo\base $pluginfo
389
     * @param moodle_url $continueurl URL to continue after confirmation
390
     * @param moodle_url $cancelurl URL to to go if cancelled
391
     * @return string
392
     */
393
    public function plugin_uninstall_confirm_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, moodle_url $continueurl, moodle_url $cancelurl) {
394
        $output = '';
395
 
396
        $pluginname = $pluginman->plugin_name($pluginfo->component);
397
 
398
        $confirm = '<p>' . get_string('uninstallconfirm', 'core_plugin', array('name' => $pluginname)) . '</p>';
399
        if ($extraconfirm = $pluginfo->get_uninstall_extra_warning()) {
400
            $confirm .= $extraconfirm;
401
        }
402
 
403
        $output .= $this->output->header();
404
        $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
405
        $output .= $this->output->confirm($confirm, $continueurl, $cancelurl);
406
        $output .= $this->output->footer();
407
 
408
        return $output;
409
    }
410
 
411
    /**
412
     * Display a page with results of plugin uninstallation and offer removal of plugin files.
413
     *
414
     * @param core_plugin_manager $pluginman
415
     * @param \core\plugininfo\base $pluginfo
416
     * @param progress_trace_buffer $progress
417
     * @param moodle_url $continueurl URL to continue to remove the plugin folder
418
     * @return string
419
     */
420
    public function plugin_uninstall_results_removable_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo,
421
                                                            progress_trace_buffer $progress, moodle_url $continueurl) {
422
        $output = '';
423
 
424
        $pluginname = $pluginman->plugin_name($pluginfo->component);
425
 
426
        // Do not show navigation here, they must click one of the buttons.
427
        $this->page->set_pagelayout('maintenance');
428
        $this->page->set_cacheable(false);
429
 
430
        $output .= $this->output->header();
431
        $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
432
 
433
        $output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
434
 
435
        $confirm = $this->output->container(get_string('uninstalldeleteconfirm', 'core_plugin',
436
            array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'uninstalldeleteconfirm');
437
 
438
        if ($repotype = $pluginman->plugin_external_source($pluginfo->component)) {
439
            $confirm .= $this->output->container(get_string('uninstalldeleteconfirmexternal', 'core_plugin', $repotype),
440
                'alert alert-warning mt-2');
441
        }
442
 
443
        // After any uninstall we must execute full upgrade to finish the cleanup!
444
        $output .= $this->output->confirm($confirm, $continueurl, new moodle_url('/admin/index.php'));
445
        $output .= $this->output->footer();
446
 
447
        return $output;
448
    }
449
 
450
    /**
451
     * Display a page with results of plugin uninstallation and inform about the need to remove plugin files manually.
452
     *
453
     * @param core_plugin_manager $pluginman
454
     * @param \core\plugininfo\base $pluginfo
455
     * @param progress_trace_buffer $progress
456
     * @return string
457
     */
458
    public function plugin_uninstall_results_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, progress_trace_buffer $progress) {
459
        $output = '';
460
 
461
        $pluginname = $pluginfo->component;
462
 
463
        $output .= $this->output->header();
464
        $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
465
 
466
        $output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
467
 
468
        $output .= $this->output->box(get_string('uninstalldelete', 'core_plugin',
469
            array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'generalbox uninstalldelete');
470
        $output .= $this->output->continue_button(new moodle_url('/admin/index.php'));
471
        $output .= $this->output->footer();
472
 
473
        return $output;
474
    }
475
 
476
    /**
477
     * Display the plugin management page (admin/environment.php).
478
     * @param array $versions
479
     * @param string $version
480
     * @param boolean $envstatus final result of env check (true/false)
481
     * @param array $environment_results array of results gathered
482
     * @return string HTML to output.
483
     */
484
    public function environment_check_page($versions, $version, $envstatus, $environment_results) {
485
        $output = '';
486
        $output .= $this->header();
487
 
488
        // Print the component download link
489
        $output .= html_writer::tag('div', html_writer::link(
490
                    new moodle_url('/admin/environment.php', array('action' => 'updatecomponent', 'sesskey' => sesskey())),
491
                    get_string('updatecomponent', 'admin')),
492
                array('class' => 'reportlink'));
493
 
494
        // Heading.
495
        $output .= $this->heading(get_string('environment', 'admin'));
496
 
497
        // Box with info and a menu to choose the version.
498
        $output .= $this->box_start();
499
        $output .= html_writer::tag('div', get_string('adminhelpenvironment'));
500
        $select = new single_select(new moodle_url('/admin/environment.php'), 'version', $versions, $version, null);
501
        $select->label = get_string('moodleversion');
502
        $output .= $this->render($select);
503
        $output .= $this->box_end();
504
 
505
        // The results
506
        $output .= $this->environment_check_table($envstatus, $environment_results);
507
 
508
        $output .= $this->footer();
509
        return $output;
510
    }
511
 
512
    /**
513
     * Output a warning message, of the type that appears on the admin notifications page.
514
     * @param string $message the message to display.
515
     * @param string $type type class
516
     * @return string HTML to output.
517
     */
518
    protected function warning($message, $type = 'warning') {
519
        return $this->box($message, 'generalbox alert alert-' . $type);
520
    }
521
 
522
    /**
523
     * Render an appropriate message if dataroot is insecure.
524
     * @param bool $insecuredataroot
525
     * @return string HTML to output.
526
     */
527
    protected function insecure_dataroot_warning($insecuredataroot) {
528
        global $CFG;
529
 
530
        if ($insecuredataroot == INSECURE_DATAROOT_WARNING) {
531
            return $this->warning(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot));
532
 
533
        } else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) {
534
            return $this->warning(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'danger');
535
 
536
        } else {
537
            return '';
538
        }
539
    }
540
 
541
    /**
542
     * Render a warning that a directory with development libs is present.
543
     *
544
     * @param bool $devlibdir True if the warning should be displayed.
545
     * @return string
546
     */
547
    protected function development_libs_directories_warning($devlibdir) {
548
 
549
        if ($devlibdir) {
550
            $moreinfo = new moodle_url('/report/security/index.php');
551
            $warning = get_string('devlibdirpresent', 'core_admin', ['moreinfourl' => $moreinfo->out()]);
552
            return $this->warning($warning, 'danger');
553
 
554
        } else {
555
            return '';
556
        }
557
    }
558
 
559
    /**
560
     * Render an appropriate message if dataroot is insecure.
561
     * @param bool $errorsdisplayed
562
     * @return string HTML to output.
563
     */
564
    protected function display_errors_warning($errorsdisplayed) {
565
        if (!$errorsdisplayed) {
566
            return '';
567
        }
568
 
569
        return $this->warning(get_string('displayerrorswarning', 'admin'));
570
    }
571
 
572
    /**
573
     * Render an appropriate message if themdesignermode is enabled.
574
     * @param bool $themedesignermode true if enabled
575
     * @return string HTML to output.
576
     */
577
    protected function themedesignermode_warning($themedesignermode) {
578
        if (!$themedesignermode) {
579
            return '';
580
        }
581
 
582
        return $this->warning(get_string('themedesignermodewarning', 'admin'));
583
    }
584
 
585
    /**
586
     * Render an appropriate message if iconv is buggy and mbstring missing.
587
     * @param bool $buggyiconvnomb
588
     * @return string HTML to output.
589
     */
590
    protected function buggy_iconv_warning($buggyiconvnomb) {
591
        if (!$buggyiconvnomb) {
592
            return '';
593
        }
594
 
595
        return $this->warning(get_string('warningiconvbuggy', 'admin'));
596
    }
597
 
598
    /**
599
     * Render an appropriate message if cron has not been run recently.
600
     * @param bool $cronoverdue
601
     * @return string HTML to output.
602
     */
603
    public function cron_overdue_warning($cronoverdue) {
604
        global $CFG;
605
        if (!$cronoverdue) {
606
            return '';
607
        }
608
 
609
        $check = new \tool_task\check\cronrunning();
610
        $result = $check->get_result();
611
        return $this->warning($result->get_summary() . '&nbsp;' . $this->help_icon('cron', 'admin'));
612
    }
613
 
614
    /**
615
     * Render an appropriate message if cron is not being run frequently (recommended every minute).
616
     *
617
     * @param bool $croninfrequent
618
     * @return string HTML to output.
619
     */
620
    public function cron_infrequent_warning(bool $croninfrequent): string {
621
        global $CFG;
622
 
623
        if (!$croninfrequent) {
624
            return '';
625
        }
626
 
627
        $check = new \tool_task\check\cronrunning();
628
        $result = $check->get_result();
629
        return $this->warning($result->get_summary() . '&nbsp;' . $this->help_icon('cron', 'admin'));
630
    }
631
 
632
    /**
633
     * Render an appropriate message if there are any problems with the DB set-up.
634
     * @param bool $dbproblems
635
     * @return string HTML to output.
636
     */
637
    public function db_problems($dbproblems) {
638
        if (!$dbproblems) {
639
            return '';
640
        }
641
 
642
        return $this->warning($dbproblems);
643
    }
644
 
645
    /**
646
     * Renders cache warnings if there are any.
647
     *
648
     * @param string[] $cachewarnings
649
     * @return string
650
     */
651
    public function cache_warnings(array $cachewarnings) {
652
        if (!count($cachewarnings)) {
653
            return '';
654
        }
655
        return join("\n", array_map(array($this, 'warning'), $cachewarnings));
656
    }
657
 
658
    /**
659
     * Renders events 1 API handlers warning.
660
     *
661
     * @param array $eventshandlers
662
     * @return string
663
     */
664
    public function events_handlers($eventshandlers) {
665
        if ($eventshandlers) {
666
            $components = '';
667
            foreach ($eventshandlers as $eventhandler) {
668
                $components .= $eventhandler->component . ', ';
669
            }
670
            $components = rtrim($components, ', ');
671
            return $this->warning(get_string('eventshandlersinuse', 'admin', $components));
672
        }
673
    }
674
 
675
    /**
676
     * Render an appropriate message if the site in in maintenance mode.
677
     * @param bool $maintenancemode
678
     * @return string HTML to output.
679
     */
680
    public function maintenance_mode_warning($maintenancemode) {
681
        if (!$maintenancemode) {
682
            return '';
683
        }
684
 
685
        $url = new moodle_url('/admin/settings.php', array('section' => 'maintenancemode'));
686
        $url = $url->out(); // get_string() does not support objects in params
687
 
688
        return $this->warning(get_string('sitemaintenancewarning2', 'admin', $url));
689
    }
690
 
691
    /**
692
     * Render a warning that ssl is forced because the site was on loginhttps.
693
     *
694
     * @param bool $overridetossl Whether or not ssl is being forced.
695
     * @return string
696
     */
697
    protected function overridetossl_warning($overridetossl) {
698
        if (!$overridetossl) {
699
            return '';
700
        }
701
        $warning = get_string('overridetossl', 'core_admin');
702
        return $this->warning($warning, 'warning');
703
    }
704
 
705
    /**
706
     * Display a warning about installing development code if necesary.
707
     * @param int $maturity
708
     * @return string HTML to output.
709
     */
710
    protected function maturity_warning($maturity) {
711
        if ($maturity == MATURITY_STABLE) {
712
            return ''; // No worries.
713
        }
714
 
715
        $maturitylevel = get_string('maturity' . $maturity, 'admin');
716
        return $this->warning(
717
                    $this->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
718
                    $this->container($this->doc_link('admin/versions', get_string('morehelp'))),
719
                'danger');
720
    }
721
 
722
    /*
723
     * If necessary, displays a warning about upgrading a test site.
724
     *
725
     * @param string $testsite
726
     * @return string HTML
727
     */
728
    protected function test_site_warning($testsite) {
729
 
730
        if (!$testsite) {
731
            return '';
732
        }
733
 
734
        $warning = (get_string('testsiteupgradewarning', 'admin', $testsite));
735
        return $this->warning($warning, 'danger');
736
    }
737
 
738
    /**
739
     * Output the copyright notice.
740
     * @return string HTML to output.
741
     */
742
    protected function moodle_copyright() {
743
        global $CFG;
744
 
745
        //////////////////////////////////////////////////////////////////////////////////////////////////
746
        ////  IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
747
        $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
748
                         '<a href="https://moodledev.io/general/releases" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
749
                         'Copyright &copy; 1999 onwards, Martin Dougiamas<br />'.
750
                         'and <a href="http://moodle.org/dev">many other contributors</a>.<br />'.
751
                         '<a href="https://moodledev.io/general/license">GNU Public License</a>';
752
        //////////////////////////////////////////////////////////////////////////////////////////////////
753
 
754
        return $this->box($copyrighttext, 'copyright');
755
    }
756
 
757
    /**
758
     * Display a warning about installing development code if necesary.
759
     * @param int $maturity
760
     * @return string HTML to output.
761
     */
762
    protected function maturity_info($maturity) {
763
        if ($maturity == MATURITY_STABLE) {
764
            return ''; // No worries.
765
        }
766
 
767
        $level = 'warning';
768
 
769
        if ($maturity == MATURITY_ALPHA) {
770
            $level = 'danger';
771
        }
772
 
773
        $maturitylevel = get_string('maturity' . $maturity, 'admin');
774
        $warningtext = get_string('maturitycoreinfo', 'admin', $maturitylevel);
775
        $warningtext .= ' ' . $this->doc_link('admin/versions', get_string('morehelp'));
776
        return $this->warning($warningtext, $level);
777
    }
778
 
779
    /**
780
     * Displays the info about available Moodle core and plugin updates
781
     *
782
     * The structure of the $updates param has changed since 2.4. It contains not only updates
783
     * for the core itself, but also for all other installed plugins.
784
     *
785
     * @param array|null $updates array of (string)component => array of \core\update\info objects or null
786
     * @param int|null $fetch timestamp of the most recent updates fetch or null (unknown)
787
     * @return string
788
     */
789
    protected function available_updates($updates, $fetch) {
790
 
791
        $updateinfo = '';
792
        $someupdateavailable = false;
793
        if (is_array($updates)) {
794
            if (is_array($updates['core'])) {
795
                $someupdateavailable = true;
796
                $updateinfo .= $this->heading(get_string('updateavailable', 'core_admin'), 3);
797
                foreach ($updates['core'] as $update) {
798
                    $updateinfo .= $this->moodle_available_update_info($update);
799
                }
800
                $updateinfo .= html_writer::tag('p', get_string('updateavailablerecommendation', 'core_admin'),
801
                    array('class' => 'updateavailablerecommendation'));
802
            }
803
            unset($updates['core']);
804
            // If something has left in the $updates array now, it is updates for plugins.
805
            if (!empty($updates)) {
806
                $someupdateavailable = true;
807
                $updateinfo .= $this->heading(get_string('updateavailableforplugin', 'core_admin'), 3);
808
                $pluginsoverviewurl = new moodle_url('/admin/plugins.php', array('updatesonly' => 1));
809
                $updateinfo .= $this->container(get_string('pluginsoverviewsee', 'core_admin',
810
                    array('url' => $pluginsoverviewurl->out())));
811
            }
812
        }
813
 
814
        if (!$someupdateavailable) {
815
            $now = time();
816
            if ($fetch and ($fetch <= $now) and ($now - $fetch < HOURSECS)) {
817
                $updateinfo .= $this->heading(get_string('updateavailablenot', 'core_admin'), 3);
818
            }
819
        }
820
 
821
        $updateinfo .= $this->container_start('checkforupdates mt-1');
822
        $fetchurl = new moodle_url('/admin/index.php', array('fetchupdates' => 1, 'sesskey' => sesskey(), 'cache' => 0));
823
        $updateinfo .= $this->single_button($fetchurl, get_string('checkforupdates', 'core_plugin'));
824
        if ($fetch) {
825
            $updateinfo .= $this->container(get_string('checkforupdateslast', 'core_plugin',
826
                userdate($fetch, get_string('strftimedatetime', 'core_langconfig'))));
827
        }
828
        $updateinfo .= $this->container_end();
829
 
830
        return $this->warning($updateinfo);
831
    }
832
 
833
    /**
834
     * Display a warning about not being registered on Moodle.org if necesary.
835
     *
836
     * @param boolean $registered true if the site is registered on Moodle.org
837
     * @return string HTML to output.
838
     */
839
    protected function registration_warning($registered) {
840
 
841
        if (!$registered && site_is_public()) {
842
            if (has_capability('moodle/site:config', context_system::instance())) {
843
                $registerbutton = $this->single_button(new moodle_url('/admin/registration/index.php'),
844
                    get_string('register', 'admin'));
845
                $str = 'registrationwarning';
1441 ariadna 846
                $type = 'error alert alert-danger';
1 efrain 847
            } else {
848
                $registerbutton = '';
849
                $str = 'registrationwarningcontactadmin';
1441 ariadna 850
                $type = 'info';
1 efrain 851
            }
852
 
1441 ariadna 853
            return $this->warning( get_string($str, 'admin') . '&nbsp;' . $registerbutton , $type);
1 efrain 854
        }
855
 
856
        return '';
857
    }
858
 
859
    /**
860
     * Return an admin page warning if site is not registered with moodle.org
861
     *
862
     * @return string
863
     */
864
    public function warn_if_not_registered() {
865
        return $this->registration_warning(\core\hub\registration::is_registered());
866
    }
867
 
868
    /**
869
     * Display a warning about the Mobile Web Services being disabled.
870
     *
871
     * @param boolean $mobileconfigured true if mobile web services are enabled
872
     * @return string HTML to output.
873
     */
874
    protected function mobile_configuration_warning($mobileconfigured) {
875
        $output = '';
876
        if (!$mobileconfigured) {
1441 ariadna 877
            $settingslink = new moodle_url('/admin/search.php', ['query' => 'enablemobilewebservice']);
878
            $configurebutton = $this->single_button($settingslink, get_string('enablemobilewebservice', 'admin'), 'get');
1 efrain 879
            $output .= $this->warning(get_string('mobilenotconfiguredwarning', 'admin') . '&nbsp;' . $configurebutton);
880
        }
881
 
882
        return $output;
883
    }
884
 
885
    /**
886
     * Display campaign content.
887
     *
888
     * @param bool $showcampaigncontent Whether the campaign content should be visible or not.
889
     * @return string the campaign content raw html.
890
     */
891
    protected function campaign_content(bool $showcampaigncontent): string {
892
        if (!$showcampaigncontent) {
893
            return '';
894
        }
895
 
896
        $lang = current_language();
897
        $url = "https://campaign.moodle.org/current/lms/{$lang}/install/";
898
        $params = [
899
            'url' => $url,
900
            'iframeid' => 'campaign-content',
901
            'title' => get_string('campaign', 'admin'),
902
        ];
903
 
904
        return $this->render_from_template('core/external_content_banner', $params);
905
    }
906
 
907
    /**
908
     * Display services and support content.
909
     *
910
     * @param bool $showservicesandsupport Whether the services and support content should be visible or not.
911
     * @return string the campaign content raw html.
912
     */
913
    protected function services_and_support_content(bool $showservicesandsupport): string {
914
        if (!$showservicesandsupport) {
915
            return '';
916
        }
917
 
918
        $lang = current_language();
919
        $url = "https://campaign.moodle.org/current/lms/{$lang}/servicesandsupport/";
920
        $params = [
921
            'url' => $url,
922
            'iframeid' => 'services-support-content',
923
            'title' => get_string('supportandservices', 'admin'),
924
        ];
925
 
926
        return $this->render_from_template('core/external_content_banner', $params);
927
    }
928
 
929
    /**
930
     * Display a warning about the forgotten password URL not linking to a valid URL.
931
     *
932
     * @param boolean $invalidforgottenpasswordurl true if the forgotten password URL is not valid
933
     * @return string HTML to output.
934
     */
935
    protected function forgotten_password_url_warning($invalidforgottenpasswordurl) {
936
        $output = '';
937
        if ($invalidforgottenpasswordurl) {
938
            $settingslink = new moodle_url('/admin/settings.php', ['section' => 'manageauths']);
939
            $configurebutton = $this->single_button($settingslink, get_string('check', 'moodle'));
940
            $output .= $this->warning(get_string('invalidforgottenpasswordurl', 'admin') . '&nbsp;' . $configurebutton,
941
                'error alert alert-danger');
942
        }
943
 
944
        return $output;
945
    }
946
 
947
    /**
948
     * Helper method to render the information about the available Moodle update
949
     *
950
     * @param \core\update\info $updateinfo information about the available Moodle core update
951
     */
952
    protected function moodle_available_update_info(\core\update\info $updateinfo) {
953
 
954
        $boxclasses = 'moodleupdateinfo mb-2';
955
        $info = array();
956
 
957
        if (isset($updateinfo->release)) {
958
            $info[] = html_writer::tag('span', get_string('updateavailable_release', 'core_admin', $updateinfo->release),
959
                array('class' => 'info release'));
960
        }
961
 
962
        if (isset($updateinfo->version)) {
963
            $info[] = html_writer::tag('span', get_string('updateavailable_version', 'core_admin', $updateinfo->version),
964
                array('class' => 'info version'));
965
        }
966
 
967
        if (isset($updateinfo->maturity)) {
968
            $info[] = html_writer::tag('span', get_string('maturity'.$updateinfo->maturity, 'core_admin'),
969
                array('class' => 'info maturity'));
970
            $boxclasses .= ' maturity'.$updateinfo->maturity;
971
        }
972
 
973
        if (isset($updateinfo->download)) {
974
            $info[] = html_writer::link($updateinfo->download, get_string('download'),
975
                array('class' => 'info download btn btn-secondary'));
976
        }
977
 
978
        if (isset($updateinfo->url)) {
979
            $info[] = html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin'),
980
                array('class' => 'info more'));
981
        }
982
 
983
        $box  = $this->output->container_start($boxclasses);
984
        $box .= $this->output->container(implode(html_writer::tag('span', ' | ', array('class' => 'separator')), $info), '');
985
        $box .= $this->output->container_end();
986
 
987
        return $box;
988
    }
989
 
990
    /**
991
     * Display a link to the release notes.
992
     * @return string HTML to output.
993
     */
994
    protected function release_notes_link() {
995
        $releasenoteslink = get_string('releasenoteslink', 'admin', 'https://moodledev.io/general/releases');
996
        $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
997
        return $this->box($releasenoteslink, 'generalbox alert alert-info');
998
    }
999
 
1000
    /**
1001
     * Display the reload link that appears on several upgrade/install pages.
1002
     * @return string HTML to output.
1003
     */
1004
    function upgrade_reload($url) {
1005
        return html_writer::empty_tag('br') .
1006
                html_writer::tag('div',
1441 ariadna 1007
                    html_writer::link($url, $this->pix_icon('i/reload', '', '', ['class' => 'icon']) .
1 efrain 1008
                            get_string('reload'), array('title' => get_string('reload'))),
1009
                array('class' => 'continuebutton')) . html_writer::empty_tag('br');
1010
    }
1011
 
1012
    /**
1013
     * Displays all known plugins and information about their installation or upgrade
1014
     *
1015
     * This default implementation renders all plugins into one big table. The rendering
1016
     * options support:
1017
     *     (bool)full = false: whether to display up-to-date plugins, too
1018
     *     (bool)xdep = false: display the plugins with unsatisified dependecies only
1019
     *
1020
     * @param core_plugin_manager $pluginman provides information about the plugins.
1021
     * @param int $version the version of the Moodle code from version.php.
1022
     * @param array $options rendering options
1023
     * @return string HTML code
1024
     */
1025
    public function plugins_check_table(core_plugin_manager $pluginman, $version, array $options = array()) {
1026
        global $CFG;
1441 ariadna 1027
        $plugininfo = $pluginman->get_plugins(true);
1 efrain 1028
 
1029
        if (empty($plugininfo)) {
1030
            return '';
1031
        }
1032
 
1033
        $options['full'] = isset($options['full']) ? (bool)$options['full'] : false;
1034
        $options['xdep'] = isset($options['xdep']) ? (bool)$options['xdep'] : false;
1035
 
1036
        $table = new html_table();
1037
        $table->id = 'plugins-check';
1038
        $table->head = array(
1039
            get_string('displayname', 'core_plugin').' / '.get_string('rootdir', 'core_plugin'),
1040
            get_string('versiondb', 'core_plugin'),
1041
            get_string('versiondisk', 'core_plugin'),
1042
            get_string('requires', 'core_plugin'),
1043
            get_string('source', 'core_plugin').' / '.get_string('status', 'core_plugin'),
1044
        );
1045
        $table->colclasses = array(
1046
            'displayname', 'versiondb', 'versiondisk', 'requires', 'status',
1047
        );
1048
        $table->data = array();
1049
 
1050
        // Number of displayed plugins per type.
1051
        $numdisplayed = array();
1052
        // Number of plugins known to the plugin manager.
1053
        $sumtotal = 0;
1054
        // Number of plugins requiring attention.
1055
        $sumattention = 0;
1056
        // List of all components we can cancel installation of.
1057
        $installabortable = $pluginman->list_cancellable_installations();
1058
        // List of all components we can cancel upgrade of.
1059
        $upgradeabortable = $pluginman->list_restorable_archives();
1060
 
1061
        foreach ($plugininfo as $type => $plugins) {
1441 ariadna 1062
            // Skip deleted plugin types.
1063
            if (\core_component::is_deleted_plugin_type($type)) {
1064
                continue;
1065
            }
1 efrain 1066
 
1441 ariadna 1067
            // Skip deprecated plugintypes having no installed plugins, in which case there is nothing to report.
1068
            if (\core_component::is_deprecated_plugin_type($type)) {
1069
                $reportableplugins = array_filter($plugins, function($plugininfo) {
1070
                    return $plugininfo->versiondb != null;
1071
                });
1072
                if (empty($reportableplugins)) {
1073
                    continue;
1074
                }
1075
            }
1076
 
1 efrain 1077
            $header = new html_table_cell($pluginman->plugintype_name_plural($type));
1078
            $header->header = true;
1079
            $header->colspan = count($table->head);
1080
            $header = new html_table_row(array($header));
1081
            $header->attributes['class'] = 'plugintypeheader type-' . $type;
1082
 
1083
            $numdisplayed[$type] = 0;
1084
 
1085
            if (empty($plugins) and $options['full']) {
1086
                $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
1087
                $msg->colspan = count($table->head);
1088
                $row = new html_table_row(array($msg));
1089
                $row->attributes['class'] .= 'msg msg-noneinstalled';
1090
                $table->data[] = $header;
1091
                $table->data[] = $row;
1092
                continue;
1093
            }
1094
 
1095
            $plugintyperows = array();
1096
 
1097
            foreach ($plugins as $name => $plugin) {
1098
                $component = "{$plugin->type}_{$plugin->name}";
1099
 
1100
                $sumtotal++;
1101
                $row = new html_table_row();
1102
                $row->attributes['class'] = "type-{$plugin->type} name-{$component}";
1103
 
1104
                $iconidentifier = 'icon';
1105
                if ($plugin->type === 'mod') {
1106
                    $iconidentifier = 'monologo';
1107
                }
1108
 
1109
                if ($this->page->theme->resolve_image_location($iconidentifier, $component, null)) {
1110
                    $icon = $this->output->pix_icon($iconidentifier, '', $component, [
1111
                        'class' => 'smallicon pluginicon',
1112
                    ]);
1113
                } else {
1114
                    $icon = '';
1115
                }
1116
 
1117
                $displayname = new html_table_cell(
1118
                    $icon.
1119
                    html_writer::span($plugin->displayname, 'pluginname').
1120
                    html_writer::div($plugin->get_dir(), 'plugindir text-muted small')
1121
                );
1122
 
1123
                $versiondb = new html_table_cell($plugin->versiondb);
1441 ariadna 1124
                $versiondisk = $plugin->is_deprecated() ? new html_table_cell() : new html_table_cell($plugin->versiondisk);
1 efrain 1125
 
1126
                if ($isstandard = $plugin->is_standard()) {
1127
                    $row->attributes['class'] .= ' standard';
1128
                    $sourcelabel = html_writer::span(get_string('sourcestd', 'core_plugin'),
1129
                        'sourcetext badge bg-secondary text-dark');
1130
                } else {
1131
                    $row->attributes['class'] .= ' extension';
1132
                    $sourcelabel = html_writer::span(get_string('sourceext', 'core_plugin'), 'sourcetext badge bg-info text-white');
1133
                }
1134
 
1135
                $coredependency = $plugin->is_core_dependency_satisfied($version);
1136
                $incompatibledependency = $plugin->is_core_compatible_satisfied($CFG->branch);
1137
 
1138
                $otherpluginsdependencies = $pluginman->are_dependencies_satisfied($plugin->get_other_required_plugins());
1139
                $dependenciesok = $coredependency && $otherpluginsdependencies && $incompatibledependency;
1140
 
1141
                $statuscode = $plugin->get_status();
1142
                $row->attributes['class'] .= ' status-' . $statuscode;
1441 ariadna 1143
                if ($plugin->is_deprecated()) {
1144
                    $row->attributes['class'] .= ' deprecatedtype';
1145
                }
1 efrain 1146
                $statusclass = 'statustext badge ';
1147
                switch ($statuscode) {
1148
                    case core_plugin_manager::PLUGIN_STATUS_NEW:
1149
                        $statusclass .= $dependenciesok ? 'bg-success text-white' : 'bg-warning text-dark';
1150
                        break;
1151
                    case core_plugin_manager::PLUGIN_STATUS_UPGRADE:
1152
                        $statusclass .= $dependenciesok ? 'bg-info text-white' : 'bg-warning text-dark';
1153
                        break;
1154
                    case core_plugin_manager::PLUGIN_STATUS_MISSING:
1155
                    case core_plugin_manager::PLUGIN_STATUS_DOWNGRADE:
1156
                    case core_plugin_manager::PLUGIN_STATUS_DELETE:
1157
                        $statusclass .= 'bg-danger text-white';
1158
                        break;
1159
                    case core_plugin_manager::PLUGIN_STATUS_NODB:
1160
                    case core_plugin_manager::PLUGIN_STATUS_UPTODATE:
1161
                        $statusclass .= $dependenciesok ? 'bg-light text-dark' : 'bg-warning text-dark';
1162
                        break;
1163
                }
1164
                $status = html_writer::span(get_string('status_' . $statuscode, 'core_plugin'), $statusclass);
1165
 
1441 ariadna 1166
                $deprecatedstatus = '';
1167
                if ($plugin->is_deprecated()) {
1168
                    // During upgrade, omit the status for deprecated plugin types, unless it's 'missing from disk'.
1169
                    // Deprecated plugins cannot be installed, upgraded, downgraded, and won't be automatically deleted.
1170
                    $status = in_array($statuscode,
1171
                        [core_plugin_manager::PLUGIN_STATUS_MISSING, core_plugin_manager::PLUGIN_STATUS_DELETE]) ? $status : '';
1172
                    $deprecatedstatus = html_writer::span(
1173
                        get_string('deprecated_type', 'core_plugin'),
1174
                        'statustext badge bg-danger text-white'
1175
                    );
1176
                }
1177
 
1 efrain 1178
                if (!empty($installabortable[$plugin->component])) {
1179
                    $status .= $this->output->single_button(
1180
                        new moodle_url($this->page->url, array('abortinstall' => $plugin->component, 'confirmplugincheck' => 0)),
1181
                        get_string('cancelinstallone', 'core_plugin'),
1182
                        'post',
1183
                        array('class' => 'actionbutton cancelinstallone d-block mt-1')
1184
                    );
1185
                }
1186
 
1187
                if (!empty($upgradeabortable[$plugin->component])) {
1188
                    $status .= $this->output->single_button(
1189
                        new moodle_url($this->page->url, array('abortupgrade' => $plugin->component)),
1190
                        get_string('cancelupgradeone', 'core_plugin'),
1191
                        'post',
1192
                        array('class' => 'actionbutton cancelupgradeone d-block mt-1')
1193
                    );
1194
                }
1195
 
1196
                $availableupdates = $plugin->available_updates();
1197
                if (!empty($availableupdates)) {
1198
                    foreach ($availableupdates as $availableupdate) {
1199
                        $status .= $this->plugin_available_update_info($pluginman, $availableupdate);
1200
                    }
1201
                }
1202
 
1441 ariadna 1203
                $status = new html_table_cell($sourcelabel.' '.$status.' '.$deprecatedstatus);
1 efrain 1204
                if ($plugin->pluginsupported != null) {
1205
                    $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version, $CFG->branch));
1206
                } else {
1207
                    $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version));
1208
                }
1209
 
1210
                $statusisboring = in_array($statuscode, array(
1441 ariadna 1211
                        core_plugin_manager::PLUGIN_STATUS_NODB, core_plugin_manager::PLUGIN_STATUS_UPTODATE))
1212
                        && !$plugin->is_deprecated();
1 efrain 1213
 
1214
                if ($options['xdep']) {
1215
                    // we want to see only plugins with failed dependencies
1216
                    if ($dependenciesok) {
1217
                        continue;
1218
                    }
1219
 
1220
                } else if ($statusisboring and $dependenciesok and empty($availableupdates)) {
1221
                    // no change is going to happen to the plugin - display it only
1222
                    // if the user wants to see the full list
1223
                    if (empty($options['full'])) {
1224
                        continue;
1225
                    }
1226
 
1227
                } else {
1228
                    $sumattention++;
1229
                }
1230
 
1231
                // The plugin should be displayed.
1232
                $numdisplayed[$type]++;
1233
                $row->cells = array($displayname, $versiondb, $versiondisk, $requires, $status);
1234
                $plugintyperows[] = $row;
1235
            }
1236
 
1237
            if (empty($numdisplayed[$type]) and empty($options['full'])) {
1238
                continue;
1239
            }
1240
 
1241
            $table->data[] = $header;
1242
            $table->data = array_merge($table->data, $plugintyperows);
1243
        }
1244
 
1245
        // Total number of displayed plugins.
1246
        $sumdisplayed = array_sum($numdisplayed);
1247
 
1248
        if ($options['xdep']) {
1249
            // At the plugins dependencies check page, display the table only.
1250
            return html_writer::table($table);
1251
        }
1252
 
1253
        $out = $this->output->container_start('', 'plugins-check-info');
1254
 
1255
        if ($sumdisplayed == 0) {
1256
            $out .= $this->output->heading(get_string('pluginchecknone', 'core_plugin'));
1257
 
1258
        } else {
1259
            if (empty($options['full'])) {
1260
                $out .= $this->output->heading(get_string('plugincheckattention', 'core_plugin'));
1261
            } else {
1262
                $out .= $this->output->heading(get_string('plugincheckall', 'core_plugin'));
1263
            }
1264
        }
1265
 
1266
        $out .= $this->output->container_start('actions mb-2');
1267
 
1268
        $installableupdates = $pluginman->filter_installable($pluginman->available_updates());
1269
        if ($installableupdates) {
1270
            $out .= $this->output->single_button(
1271
                new moodle_url($this->page->url, array('installupdatex' => 1)),
1272
                get_string('updateavailableinstallall', 'core_admin', count($installableupdates)),
1273
                'post',
1441 ariadna 1274
                array('class' => 'singlebutton updateavailableinstallall me-1')
1 efrain 1275
            );
1276
        }
1277
 
1278
        if ($installabortable) {
1279
            $out .= $this->output->single_button(
1280
                new moodle_url($this->page->url, array('abortinstallx' => 1, 'confirmplugincheck' => 0)),
1281
                get_string('cancelinstallall', 'core_plugin', count($installabortable)),
1282
                'post',
1441 ariadna 1283
                array('class' => 'singlebutton cancelinstallall me-1')
1 efrain 1284
            );
1285
        }
1286
 
1287
        if ($upgradeabortable) {
1288
            $out .= $this->output->single_button(
1289
                new moodle_url($this->page->url, array('abortupgradex' => 1)),
1290
                get_string('cancelupgradeall', 'core_plugin', count($upgradeabortable)),
1291
                'post',
1441 ariadna 1292
                array('class' => 'singlebutton cancelupgradeall me-1')
1 efrain 1293
            );
1294
        }
1295
 
1296
        $out .= html_writer::div(html_writer::link(new moodle_url($this->page->url, array('showallplugins' => 0)),
1297
            get_string('plugincheckattention', 'core_plugin')).' '.html_writer::span($sumattention, 'badge bg-light text-dark'),
1441 ariadna 1298
            'btn btn-link me-1');
1 efrain 1299
 
1300
        $out .= html_writer::div(html_writer::link(new moodle_url($this->page->url, array('showallplugins' => 1)),
1301
            get_string('plugincheckall', 'core_plugin')).' '.html_writer::span($sumtotal, 'badge bg-light text-dark'),
1441 ariadna 1302
            'btn btn-link me-1');
1 efrain 1303
 
1304
        $out .= $this->output->container_end(); // End of .actions container.
1305
        $out .= $this->output->container_end(); // End of #plugins-check-info container.
1306
 
1307
        if ($sumdisplayed > 0 or $options['full']) {
1308
            $out .= html_writer::table($table);
1309
        }
1310
 
1311
        return $out;
1312
    }
1313
 
1314
    /**
1315
     * Display the continue / cancel widgets for the plugins management pages.
1316
     *
1317
     * @param null|moodle_url $continue URL for the continue button, should it be displayed
1318
     * @param null|moodle_url $cancel URL for the cancel link, defaults to the current page
1319
     * @return string HTML
1320
     */
1441 ariadna 1321
    public function plugins_management_confirm_buttons(?moodle_url $continue=null, ?moodle_url $cancel=null) {
1 efrain 1322
 
1323
        $out = html_writer::start_div('plugins-management-confirm-buttons');
1324
 
1325
        if (!empty($continue)) {
1326
            $out .= $this->output->single_button($continue, get_string('continue'), 'post', array('class' => 'continue'));
1327
        }
1328
 
1329
        if (empty($cancel)) {
1330
            $cancel = $this->page->url;
1331
        }
1332
        $out .= html_writer::div(html_writer::link($cancel, get_string('cancel')), 'cancel');
1333
 
1334
        return $out;
1335
    }
1336
 
1337
    /**
1338
     * Displays the information about missing dependencies
1339
     *
1340
     * @param core_plugin_manager $pluginman
1341
     * @return string
1342
     */
1343
    protected function missing_dependencies(core_plugin_manager $pluginman) {
1344
 
1345
        $dependencies = $pluginman->missing_dependencies();
1346
 
1347
        if (empty($dependencies)) {
1348
            return '';
1349
        }
1350
 
1351
        $available = array();
1352
        $unavailable = array();
1353
        $unknown = array();
1354
 
1355
        foreach ($dependencies as $component => $remoteinfo) {
1356
            if ($remoteinfo === false) {
1357
                // The required version is not available. Let us check if there
1358
                // is at least some version in the plugins directory.
1359
                $remoteinfoanyversion = $pluginman->get_remote_plugin_info($component, ANY_VERSION, false);
1360
                if ($remoteinfoanyversion === false) {
1361
                    $unknown[$component] = $component;
1362
                } else {
1363
                    $unavailable[$component] = $remoteinfoanyversion;
1364
                }
1365
            } else {
1366
                $available[$component] = $remoteinfo;
1367
            }
1368
        }
1369
 
1370
        $out  = $this->output->container_start('plugins-check-dependencies mb-4');
1371
 
1372
        if ($unavailable or $unknown) {
1373
            $out .= $this->output->heading(get_string('misdepsunavail', 'core_plugin'));
1374
            if ($unknown) {
1375
                $out .= $this->output->render((new \core\output\notification(get_string('misdepsunknownlist', 'core_plugin',
1376
                    implode(', ', $unknown))))->set_show_closebutton(false));
1377
            }
1378
            if ($unavailable) {
1379
                $unavailablelist = array();
1380
                foreach ($unavailable as $component => $remoteinfoanyversion) {
1381
                    $unavailablelistitem = html_writer::link('https://moodle.org/plugins/view.php?plugin='.$component,
1382
                        '<strong>'.$remoteinfoanyversion->name.'</strong>');
1383
                    if ($remoteinfoanyversion->version) {
1384
                        $unavailablelistitem .= ' ('.$component.' &gt; '.$remoteinfoanyversion->version->version.')';
1385
                    } else {
1386
                        $unavailablelistitem .= ' ('.$component.')';
1387
                    }
1388
                    $unavailablelist[] = $unavailablelistitem;
1389
                }
1390
                $out .= $this->output->render((new \core\output\notification(get_string('misdepsunavaillist', 'core_plugin',
1391
                    implode(', ', $unavailablelist))))->set_show_closebutton(false));
1392
            }
1393
            $out .= $this->output->container_start('plugins-check-dependencies-actions mb-4');
1394
            $out .= ' '.html_writer::link(new moodle_url('/admin/tool/installaddon/'),
1395
                get_string('dependencyuploadmissing', 'core_plugin'), array('class' => 'btn btn-secondary'));
1396
            $out .= $this->output->container_end(); // End of .plugins-check-dependencies-actions container.
1397
        }
1398
 
1399
        if ($available) {
1400
            $out .= $this->output->heading(get_string('misdepsavail', 'core_plugin'));
1401
            $out .= $this->output->container_start('plugins-check-dependencies-actions mb-2');
1402
 
1403
            $installable = $pluginman->filter_installable($available);
1404
            if ($installable) {
1405
                $out .= $this->output->single_button(
1406
                    new moodle_url($this->page->url, array('installdepx' => 1)),
1407
                    get_string('dependencyinstallmissing', 'core_plugin', count($installable)),
1408
                    'post',
1441 ariadna 1409
                    array('class' => 'singlebutton dependencyinstallmissing d-inline-block me-1')
1 efrain 1410
                );
1411
            }
1412
 
1413
            $out .= html_writer::div(html_writer::link(new moodle_url('/admin/tool/installaddon/'),
1414
                get_string('dependencyuploadmissing', 'core_plugin'), array('class' => 'btn btn-link')),
1441 ariadna 1415
                'dependencyuploadmissing d-inline-block me-1');
1 efrain 1416
 
1417
            $out .= $this->output->container_end(); // End of .plugins-check-dependencies-actions container.
1418
 
1419
            $out .= $this->available_missing_dependencies_list($pluginman, $available);
1420
        }
1421
 
1422
        $out .= $this->output->container_end(); // End of .plugins-check-dependencies container.
1423
 
1424
        return $out;
1425
    }
1426
 
1427
    /**
1428
     * Displays the list if available missing dependencies.
1429
     *
1430
     * @param core_plugin_manager $pluginman
1431
     * @param array $dependencies
1432
     * @return string
1433
     */
1434
    protected function available_missing_dependencies_list(core_plugin_manager $pluginman, array $dependencies) {
1435
        global $CFG;
1436
 
1437
        $table = new html_table();
1438
        $table->id = 'plugins-check-available-dependencies';
1439
        $table->head = array(
1440
            get_string('displayname', 'core_plugin'),
1441
            get_string('release', 'core_plugin'),
1442
            get_string('version', 'core_plugin'),
1443
            get_string('supportedmoodleversions', 'core_plugin'),
1444
            get_string('info', 'core'),
1445
        );
1446
        $table->colclasses = array('displayname', 'release', 'version', 'supportedmoodleversions', 'info');
1447
        $table->data = array();
1448
 
1449
        foreach ($dependencies as $plugin) {
1450
 
1451
            $supportedmoodles = array();
1452
            foreach ($plugin->version->supportedmoodles as $moodle) {
1453
                if ($CFG->branch == str_replace('.', '', $moodle->release)) {
1454
                    $supportedmoodles[] = html_writer::span($moodle->release, 'badge bg-success text-white');
1455
                } else {
1456
                    $supportedmoodles[] = html_writer::span($moodle->release, 'badge bg-light text-dark');
1457
                }
1458
            }
1459
 
1460
            $requriedby = $pluginman->other_plugins_that_require($plugin->component);
1461
            if ($requriedby) {
1462
                foreach ($requriedby as $ix => $val) {
1463
                    $inf = $pluginman->get_plugin_info($val);
1464
                    if ($inf) {
1465
                        $requriedby[$ix] = $inf->displayname.' ('.$inf->component.')';
1466
                    }
1467
                }
1468
                $info = html_writer::div(
1469
                    get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
1470
                    'requiredby mb-1'
1471
                );
1472
            } else {
1473
                $info = '';
1474
            }
1475
 
1476
            $info .= $this->output->container_start('actions');
1477
 
1478
            $info .= html_writer::div(
1479
                html_writer::link('https://moodle.org/plugins/view.php?plugin='.$plugin->component,
1480
                    get_string('misdepinfoplugin', 'core_plugin')),
1441 ariadna 1481
                'misdepinfoplugin d-inline-block me-3 mb-1'
1 efrain 1482
            );
1483
 
1484
            $info .= html_writer::div(
1485
                html_writer::link('https://moodle.org/plugins/pluginversion.php?id='.$plugin->version->id,
1486
                    get_string('misdepinfoversion', 'core_plugin')),
1441 ariadna 1487
                'misdepinfoversion d-inline-block me-3 mb-1'
1 efrain 1488
            );
1489
 
1490
            $info .= html_writer::div(html_writer::link($plugin->version->downloadurl, get_string('download')),
1441 ariadna 1491
                'misdepdownload d-inline-block me-3 mb-1');
1 efrain 1492
 
1493
            if ($pluginman->is_remote_plugin_installable($plugin->component, $plugin->version->version, $reason)) {
1494
                $info .= $this->output->single_button(
1495
                    new moodle_url($this->page->url, array('installdep' => $plugin->component)),
1496
                    get_string('dependencyinstall', 'core_plugin'),
1497
                    'post',
1441 ariadna 1498
                    array('class' => 'singlebutton dependencyinstall me-3 mb-1')
1 efrain 1499
                );
1500
            } else {
1501
                $reasonhelp = $this->info_remote_plugin_not_installable($reason);
1502
                if ($reasonhelp) {
1441 ariadna 1503
                    $info .= html_writer::div($reasonhelp, 'reasonhelp dependencyinstall d-inline-block me-3 mb-1');
1 efrain 1504
                }
1505
            }
1506
 
1507
            $info .= $this->output->container_end(); // End of .actions container.
1508
 
1509
            $table->data[] = array(
1510
                html_writer::div($plugin->name, 'name').' '.html_writer::div($plugin->component, 'component text-muted small'),
1511
                $plugin->version->release,
1512
                $plugin->version->version,
1513
                implode(' ', $supportedmoodles),
1514
                $info
1515
            );
1516
        }
1517
 
1518
        return html_writer::table($table);
1519
    }
1520
 
1521
    /**
1522
     * Explain why {@link core_plugin_manager::is_remote_plugin_installable()} returned false.
1523
     *
1524
     * @param string $reason the reason code as returned by the plugin manager
1525
     * @return string
1526
     */
1527
    protected function info_remote_plugin_not_installable($reason) {
1528
 
1529
        if ($reason === 'notwritableplugintype' or $reason === 'notwritableplugin') {
1530
            return $this->output->help_icon('notwritable', 'core_plugin', get_string('notwritable', 'core_plugin'));
1531
        }
1532
 
1533
        if ($reason === 'remoteunavailable') {
1534
            return $this->output->help_icon('notdownloadable', 'core_plugin', get_string('notdownloadable', 'core_plugin'));
1535
        }
1536
 
1537
        return false;
1538
    }
1539
 
1540
    /**
1541
     * Formats the information that needs to go in the 'Requires' column.
1542
     * @param \core\plugininfo\base $plugin the plugin we are rendering the row for.
1543
     * @param core_plugin_manager $pluginman provides data on all the plugins.
1544
     * @param string $version
1545
     * @param int $branch the current Moodle branch
1546
     * @return string HTML code
1547
     */
1548
    protected function required_column(\core\plugininfo\base $plugin, core_plugin_manager $pluginman, $version, $branch = null) {
1549
 
1550
        $requires = array();
1551
        $displayuploadlink = false;
1552
        $displayupdateslink = false;
1553
 
1554
        $requirements = $pluginman->resolve_requirements($plugin, $version, $branch);
1555
        foreach ($requirements as $reqname => $reqinfo) {
1556
            if ($reqname === 'core') {
1557
                if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OK) {
1558
                    $class = 'requires-ok text-muted';
1559
                    $label = '';
1560
                } else {
1561
                    $class = 'requires-failed';
1562
                    $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'badge bg-danger text-white');
1563
                }
1564
 
1565
                if ($branch != null && !$plugin->is_core_compatible_satisfied($branch)) {
1566
                    $requires[] = html_writer::tag('li',
1567
                    html_writer::span(get_string('incompatibleversion', 'core_plugin', $branch), 'dep dep-core').
1568
                    ' '.$label, array('class' => $class));
1569
 
1570
                } else if ($branch != null && $plugin->pluginsupported != null) {
1571
                    $requires[] = html_writer::tag('li',
1572
                        html_writer::span(get_string('moodlebranch', 'core_plugin',
1573
                        array('min' => $plugin->pluginsupported[0], 'max' => $plugin->pluginsupported[1])), 'dep dep-core').
1574
                        ' '.$label, array('class' => $class));
1575
 
1576
                } else if ($reqinfo->reqver != ANY_VERSION) {
1577
                    $requires[] = html_writer::tag('li',
1578
                        html_writer::span(get_string('moodleversion', 'core_plugin', $plugin->versionrequires), 'dep dep-core').
1579
                        ' '.$label, array('class' => $class));
1580
                }
1581
 
1582
            } else {
1583
                $actions = array();
1584
 
1585
                if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OK) {
1586
                    $label = '';
1587
                    $class = 'requires-ok text-muted';
1588
 
1589
                } else if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_MISSING) {
1590
                    if ($reqinfo->availability == $pluginman::REQUIREMENT_AVAILABLE) {
1591
                        $label = html_writer::span(get_string('dependencymissing', 'core_plugin'),
1592
                            'badge bg-warning text-dark');
1593
                        $label .= ' '.html_writer::span(get_string('dependencyavailable', 'core_plugin'),
1594
                            'badge bg-warning text-dark');
1595
                        $class = 'requires-failed requires-missing requires-available';
1596
                        $actions[] = html_writer::link(
1597
                            new moodle_url('https://moodle.org/plugins/view.php', array('plugin' => $reqname)),
1598
                            get_string('misdepinfoplugin', 'core_plugin')
1599
                        );
1600
 
1601
                    } else {
1602
                        $label = html_writer::span(get_string('dependencymissing', 'core_plugin'), 'badge bg-danger text-white');
1603
                        $label .= ' '.html_writer::span(get_string('dependencyunavailable', 'core_plugin'),
1604
                            'badge bg-danger text-white');
1605
                        $class = 'requires-failed requires-missing requires-unavailable';
1606
                    }
1607
                    $displayuploadlink = true;
1608
 
1609
                } else if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OUTDATED) {
1610
                    if ($reqinfo->availability == $pluginman::REQUIREMENT_AVAILABLE) {
1611
                        $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'badge bg-warning text-dark');
1612
                        $label .= ' '.html_writer::span(get_string('dependencyavailable', 'core_plugin'),
1613
                            'badge bg-warning text-dark');
1614
                        $class = 'requires-failed requires-outdated requires-available';
1615
                        $displayupdateslink = true;
1616
 
1617
                    } else {
1618
                        $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'badge bg-danger text-white');
1619
                        $label .= ' '.html_writer::span(get_string('dependencyunavailable', 'core_plugin'),
1620
                            'badge bg-danger text-white');
1621
                        $class = 'requires-failed requires-outdated requires-unavailable';
1622
                    }
1623
                    $displayuploadlink = true;
1624
                }
1625
 
1626
                if ($reqinfo->reqver != ANY_VERSION) {
1627
                    $str = 'otherpluginversion';
1628
                } else {
1629
                    $str = 'otherplugin';
1630
                }
1631
 
1632
                $requires[] = html_writer::tag('li', html_writer::span(
1633
                    get_string($str, 'core_plugin', array('component' => $reqname, 'version' => $reqinfo->reqver)),
1634
                    'dep dep-plugin').' '.$label.' '.html_writer::span(implode(' | ', $actions), 'actions'),
1635
                    array('class' => $class)
1636
                );
1637
            }
1638
        }
1639
 
1640
        if (!$requires) {
1641
            return '';
1642
        }
1643
 
1644
        $out = html_writer::tag('ul', implode("\n", $requires), array('class' => 'm-0'));
1645
 
1646
        if ($displayuploadlink) {
1647
            $out .= html_writer::div(
1648
                html_writer::link(
1649
                    new moodle_url('/admin/tool/installaddon/'),
1650
                    get_string('dependencyuploadmissing', 'core_plugin'),
1651
                    array('class' => 'btn btn-secondary btn-sm m-1')
1652
                ),
1653
                'dependencyuploadmissing'
1654
            );
1655
        }
1656
 
1657
        if ($displayupdateslink) {
1658
            $out .= html_writer::div(
1659
                html_writer::link(
1660
                    new moodle_url($this->page->url, array('sesskey' => sesskey(), 'fetchupdates' => 1)),
1661
                    get_string('checkforupdates', 'core_plugin'),
1662
                    array('class' => 'btn btn-secondary btn-sm m-1')
1663
                ),
1664
                'checkforupdates'
1665
            );
1666
        }
1667
 
1668
        // Check if supports is present, and $branch is not in, only if $incompatible check was ok.
1669
        if ($plugin->pluginsupported != null && $class == 'requires-ok' && $branch != null) {
1670
            if ($pluginman->check_explicitly_supported($plugin, $branch) == $pluginman::VERSION_NOT_SUPPORTED) {
1671
                $out .= html_writer::div(get_string('notsupported', 'core_plugin', $branch));
1672
            }
1673
        }
1674
 
1675
        return $out;
1676
 
1677
    }
1678
 
1679
    /**
1680
     * Prints an overview about the plugins - number of installed, number of extensions etc.
1681
     *
1682
     * @param core_plugin_manager $pluginman provides information about the plugins
1683
     * @param array $options filtering options
1684
     * @return string as usually
1685
     */
1686
    public function plugins_overview_panel(core_plugin_manager $pluginman, array $options = array()) {
1687
 
1441 ariadna 1688
        $plugininfo = $pluginman->get_plugins(true);
1689
        $this->page->requires->js_call_amd('core_admin/plugins_overview', 'init');
1 efrain 1690
 
1441 ariadna 1691
        $numtotal = $numextension = $numupdatable = $numinstallable = $nummissing = $numnew = 0;
1 efrain 1692
 
1693
        foreach ($plugininfo as $type => $plugins) {
1441 ariadna 1694
            if (\core_component::is_deleted_plugin_type($type)) {
1695
                continue;
1696
            }
1697
 
1698
            // Skip deprecated plugintypes having no installed plugins, in which case there is nothing to report.
1699
            if (\core_component::is_deprecated_plugin_type($type)) {
1700
                $reportableplugins = array_filter($plugins, function($plugininfo) {
1701
                    return $plugininfo->versiondb != null;
1702
                });
1703
                if (empty($reportableplugins)) {
1704
                    continue;
1705
                }
1706
            }
1707
 
1 efrain 1708
            foreach ($plugins as $name => $plugin) {
1709
                if ($res = $plugin->available_updates()) {
1710
                    $numupdatable++;
1711
                    foreach ($res as $updateinfo) {
1712
                        if ($pluginman->is_remote_plugin_installable($updateinfo->component, $updateinfo->version, $reason, false)) {
1713
                            $numinstallable++;
1714
                            break;
1715
                        }
1716
                    }
1717
                }
1718
                if ($plugin->get_status() === core_plugin_manager::PLUGIN_STATUS_MISSING) {
1441 ariadna 1719
                    $nummissing++;
1 efrain 1720
                    continue;
1721
                }
1441 ariadna 1722
                if ($plugin->get_status() === core_plugin_manager::PLUGIN_STATUS_NEW) {
1723
                    $numnew++;
1724
                }
1 efrain 1725
                $numtotal++;
1726
                if (!$plugin->is_standard()) {
1727
                    $numextension++;
1728
                }
1729
            }
1730
        }
1731
 
1732
        $infoall = html_writer::link(
1441 ariadna 1733
            $this->page->url,
1 efrain 1734
            get_string('overviewall', 'core_plugin'),
1441 ariadna 1735
            ['title' => get_string('filterall', 'core_plugin'), 'data-filterby' => 'all', 'class' => 'active']
1736
        ).' '.html_writer::span($numtotal, 'badge text-dark number number-all');
1 efrain 1737
 
1738
        $infoext = html_writer::link(
1441 ariadna 1739
            new moodle_url($this->page->url, [], 'additional'),
1 efrain 1740
            get_string('overviewext', 'core_plugin'),
1441 ariadna 1741
            ['title' => get_string('filtercontribonly', 'core_plugin'), 'data-filterby' => 'additional']
1742
        ).' '.html_writer::span($numextension, 'badge text-dark number number-additional');
1 efrain 1743
 
1744
        if ($numupdatable) {
1745
            $infoupdatable = html_writer::link(
1441 ariadna 1746
                new moodle_url($this->page->url, [], 'updatable'),
1 efrain 1747
                get_string('overviewupdatable', 'core_plugin'),
1441 ariadna 1748
                ['title' => get_string('filterupdatesonly', 'core_plugin'), 'data-filterby' => 'updatable']
1 efrain 1749
            ).' '.html_writer::span($numupdatable, 'badge bg-info text-white number number-updatable');
1750
        } else {
1751
            // No updates, or the notifications disabled.
1752
            $infoupdatable = '';
1753
        }
1754
 
1441 ariadna 1755
        if ($numnew) {
1756
            $infonew = html_writer::link(
1757
                new moodle_url($this->page->url, [], 'newplugin'),
1758
                get_string('status_new', 'plugin'),
1759
                ['title' => get_string('filternewpluginsonly', 'core_plugin'), 'data-filterby' => 'newplugin']
1760
            ).' '.html_writer::span($numnew, 'badge bg-success text-white number number-newplugin');
1761
        } else {
1762
            $infonew = '';
1763
        }
1 efrain 1764
 
1441 ariadna 1765
        if ($nummissing) {
1766
            $infomissing = html_writer::link(
1767
                new moodle_url($this->page->url, [], 'missing'),
1768
                get_string('status_missing', 'plugin'),
1769
                ['title' => get_string('filtermissingonly', 'core_plugin'), 'data-filterby' => 'missing']
1770
            ).' '.html_writer::span($nummissing, 'badge bg-danger text-white number number-missing');
1771
        } else {
1772
            $infomissing = '';
1 efrain 1773
        }
1774
 
1441 ariadna 1775
        $out = html_writer::start_div('', ['id' => 'plugins-overview-panel']);
1776
 
1 efrain 1777
        if ($numinstallable) {
1778
            $out .= $this->output->single_button(
1779
                new moodle_url($this->page->url, array('installupdatex' => 1)),
1780
                get_string('updateavailableinstallall', 'core_admin', $numinstallable),
1781
                'post',
1782
                array('class' => 'singlebutton updateavailableinstallall')
1783
            );
1784
        }
1785
 
1786
        $out .= html_writer::div($infoall, 'info info-all').
1441 ariadna 1787
            html_writer::div($infoext, 'info info-additional').
1788
            html_writer::div($infoupdatable, 'info info-updatable').
1789
            html_writer::div($infonew, 'info info-newplugin').
1790
            html_writer::div($infomissing, 'info info-missing');
1 efrain 1791
 
1792
        $out .= html_writer::end_div(); // End of #plugins-overview-panel block.
1793
 
1794
        return $out;
1795
    }
1796
 
1797
    /**
1798
     * Displays all known plugins and links to manage them
1799
     *
1800
     * This default implementation renders all plugins into one big table.
1801
     *
1802
     * @param core_plugin_manager $pluginman provides information about the plugins.
1803
     * @param array $options filtering options
1804
     * @return string HTML code
1805
     */
1806
    public function plugins_control_panel(core_plugin_manager $pluginman, array $options = array()) {
1807
 
1441 ariadna 1808
        $plugininfo = $pluginman->get_plugins(true);
1 efrain 1809
 
1810
        $table = new html_table();
1811
        $table->id = 'plugins-control-panel';
1812
        $table->head = array(
1813
            get_string('displayname', 'core_plugin'),
1814
            get_string('version', 'core_plugin'),
1815
            get_string('availability', 'core_plugin'),
1816
            get_string('actions', 'core_plugin'),
1817
            get_string('notes','core_plugin'),
1818
        );
1819
        $table->headspan = array(1, 1, 1, 2, 1);
1820
        $table->colclasses = array(
1821
            'pluginname', 'version', 'availability', 'settings', 'uninstall', 'notes'
1822
        );
1823
 
1824
        foreach ($plugininfo as $type => $plugins) {
1441 ariadna 1825
            if (\core_component::is_deleted_plugin_type($type)) {
1826
                continue;
1827
            }
1828
 
1829
            // Skip deprecated plugintypes having no installed plugins, in which case there is nothing to report.
1830
            if (\core_component::is_deprecated_plugin_type($type)) {
1831
                $reportableplugins = array_filter($plugins, function($plugininfo) {
1832
                    return $plugininfo->versiondb != null;
1833
                });
1834
                if (empty($reportableplugins)) {
1835
                    continue;
1836
                }
1837
            }
1838
 
1 efrain 1839
            $heading = $pluginman->plugintype_name_plural($type);
1840
            $pluginclass = core_plugin_manager::resolve_plugininfo_class($type);
1841
            if ($manageurl = $pluginclass::get_manage_url()) {
1842
                $heading .= $this->output->action_icon($manageurl, new pix_icon('i/settings',
1843
                    get_string('settings', 'core_plugin')));
1844
            }
1845
            $header = new html_table_cell(html_writer::tag('span', $heading, array('id'=>'plugin_type_cell_'.$type)));
1846
            $header->header = true;
1847
            $header->colspan = array_sum($table->headspan);
1848
            $header = new html_table_row(array($header));
1849
            $header->attributes['class'] = 'plugintypeheader type-' . $type;
1850
            $table->data[] = $header;
1851
 
1852
            if (empty($plugins)) {
1853
                $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
1854
                $msg->colspan = array_sum($table->headspan);
1855
                $row = new html_table_row(array($msg));
1856
                $row->attributes['class'] .= 'msg msg-noneinstalled';
1857
                $table->data[] = $row;
1858
                continue;
1859
            }
1860
 
1861
            foreach ($plugins as $name => $plugin) {
1862
                $component = "{$plugin->type}_{$plugin->name}";
1863
 
1864
                $row = new html_table_row();
1865
                $row->attributes['class'] = "type-{$plugin->type} name-{$component}";
1866
 
1867
                $iconidentifier = 'icon';
1868
                if ($plugin->type === 'mod') {
1869
                    $iconidentifier = 'monologo';
1870
                }
1871
 
1872
                if ($this->page->theme->resolve_image_location($iconidentifier, $component, null)) {
1873
                    $icon = $this->output->pix_icon($iconidentifier, '', $component, [
1874
                        'class' => 'icon pluginicon',
1875
                    ]);
1876
                } else {
1877
                    $icon = $this->output->spacer();
1878
                }
1879
                $status = $plugin->get_status();
1880
                $row->attributes['class'] .= ' status-'.$status;
1441 ariadna 1881
                if ($plugin->is_deprecated()) {
1882
                    $row->attributes['class'] .= ' deprecatedtype';
1883
                }
1 efrain 1884
                $pluginname  = html_writer::tag('div', $icon.$plugin->displayname, array('class' => 'displayname')).
1885
                               html_writer::tag('div', $plugin->component, array('class' => 'componentname'));
1886
                $pluginname  = new html_table_cell($pluginname);
1887
 
1888
                $version = html_writer::div($plugin->versiondb, 'versionnumber');
1889
                if ((string)$plugin->release !== '') {
1890
                    $version = html_writer::div($plugin->release, 'release').$version;
1891
                }
1892
                $version = new html_table_cell($version);
1893
 
1894
                $isenabled = $plugin->is_enabled();
1895
                if (is_null($isenabled)) {
1896
                    $availability = new html_table_cell('');
1897
                } else if ($isenabled) {
1898
                    $row->attributes['class'] .= ' enabled';
1899
                    $availability = new html_table_cell(get_string('pluginenabled', 'core_plugin'));
1900
                } else {
1901
                    $row->attributes['class'] .= ' disabled';
1902
                    $availability = new html_table_cell(get_string('plugindisabled', 'core_plugin'));
1903
                }
1904
 
1905
                $settingsurl = $plugin->get_settings_url();
1906
                if (!is_null($settingsurl)) {
1907
                    $settings = html_writer::link($settingsurl, get_string('settings', 'core_plugin'), array('class' => 'settings'));
1908
                } else {
1909
                    $settings = '';
1910
                }
1911
                $settings = new html_table_cell($settings);
1912
 
1913
                if ($uninstallurl = $pluginman->get_uninstall_url($plugin->component, 'overview')) {
1914
                    $uninstall = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin'));
1915
                } else {
1916
                    $uninstall = '';
1917
                }
1918
                $uninstall = new html_table_cell($uninstall);
1919
 
1920
                if ($plugin->is_standard()) {
1921
                    $row->attributes['class'] .= ' standard';
1922
                    $source = '';
1923
                } else {
1441 ariadna 1924
                    $row->attributes['class'] .= ' additional';
1925
                    $source = html_writer::div(get_string('sourceext', 'core_plugin'), 'source badge me-1 text-bg-info');
1 efrain 1926
                }
1927
 
1928
                if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) {
1441 ariadna 1929
                    $row->attributes['class'] .= ' missing';
1930
                    $msg = html_writer::div(get_string('status_missing', 'core_plugin'), 'statusmsg badge text-bg-danger');
1 efrain 1931
                } else if ($status === core_plugin_manager::PLUGIN_STATUS_NEW) {
1441 ariadna 1932
                    $row->attributes['class'] .= ' newplugin';
1933
                    $msg = html_writer::div(get_string('status_new', 'core_plugin'), 'statusmsg badge text-bg-success');
1 efrain 1934
                } else {
1935
                    $msg = '';
1936
                }
1937
 
1441 ariadna 1938
                $deprecatedmsg = '';
1939
                if ($plugin->is_deprecated()) {
1940
                    // Omit the status for deprecated plugin types, unless it's 'missing from disk'.
1941
                    $msg = $status == core_plugin_manager::PLUGIN_STATUS_MISSING ? $msg : '';
1942
                    $deprecatedmsg = html_writer::div(
1943
                        get_string('deprecated_type', 'core_plugin'),
1944
                        'statusmsg badge bg-danger text-white'
1945
                    );
1946
                }
1947
 
1 efrain 1948
                $requriedby = $pluginman->other_plugins_that_require($plugin->component);
1949
                if ($requriedby) {
1950
                    $requiredby = html_writer::tag('div', get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
1951
                        array('class' => 'requiredby'));
1952
                } else {
1953
                    $requiredby = '';
1954
                }
1955
 
1956
                $updateinfo = '';
1957
                if (is_array($plugin->available_updates())) {
1441 ariadna 1958
                    $row->attributes['class'] .= ' updatable';
1 efrain 1959
                    foreach ($plugin->available_updates() as $availableupdate) {
1960
                        $updateinfo .= $this->plugin_available_update_info($pluginman, $availableupdate);
1961
                    }
1962
                }
1963
 
1441 ariadna 1964
                $notes = new html_table_cell($source.' '.$msg.' '.$deprecatedmsg.$requiredby.$updateinfo);
1 efrain 1965
 
1966
                $row->cells = array(
1967
                    $pluginname, $version, $availability, $settings, $uninstall, $notes
1968
                );
1969
                $table->data[] = $row;
1970
            }
1971
        }
1972
 
1973
        return html_writer::table($table);
1974
    }
1975
 
1976
    /**
1977
     * Helper method to render the information about the available plugin update
1978
     *
1979
     * @param core_plugin_manager $pluginman plugin manager instance
1980
     * @param \core\update\info $updateinfo information about the available update for the plugin
1981
     */
1982
    protected function plugin_available_update_info(core_plugin_manager $pluginman, \core\update\info $updateinfo) {
1983
 
1984
        $boxclasses = 'pluginupdateinfo';
1985
        $info = array();
1986
 
1987
        if (isset($updateinfo->release)) {
1988
            $info[] = html_writer::div(
1989
                get_string('updateavailable_release', 'core_plugin', $updateinfo->release),
1990
                'info release'
1991
            );
1992
        }
1993
 
1994
        if (isset($updateinfo->maturity)) {
1995
            $info[] = html_writer::div(
1996
                get_string('maturity'.$updateinfo->maturity, 'core_admin'),
1997
                'info maturity'
1998
            );
1999
            $boxclasses .= ' maturity'.$updateinfo->maturity;
2000
        }
2001
 
2002
        if (isset($updateinfo->download)) {
2003
            $info[] = html_writer::div(
2004
                html_writer::link($updateinfo->download, get_string('download')),
2005
                'info download'
2006
            );
2007
        }
2008
 
2009
        if (isset($updateinfo->url)) {
2010
            $info[] = html_writer::div(
2011
                html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin')),
2012
                'info more'
2013
            );
2014
        }
2015
 
2016
        $box = html_writer::start_div($boxclasses);
2017
        $box .= html_writer::div(
2018
            get_string('updateavailable', 'core_plugin', $updateinfo->version),
2019
            'version'
2020
        );
2021
        $box .= html_writer::div(
2022
            implode(html_writer::span(' ', 'separator'), $info),
2023
            'infos'
2024
        );
2025
 
2026
        if ($pluginman->is_remote_plugin_installable($updateinfo->component, $updateinfo->version, $reason, false)) {
2027
            $box .= $this->output->single_button(
2028
                new moodle_url($this->page->url, array('installupdate' => $updateinfo->component,
2029
                    'installupdateversion' => $updateinfo->version)),
2030
                get_string('updateavailableinstall', 'core_admin'),
2031
                'post',
2032
                array('class' => 'singlebutton updateavailableinstall')
2033
            );
2034
        } else {
2035
            $reasonhelp = $this->info_remote_plugin_not_installable($reason);
2036
            if ($reasonhelp) {
2037
                $box .= html_writer::div($reasonhelp, 'reasonhelp updateavailableinstall');
2038
            }
2039
        }
2040
        $box .= html_writer::end_div();
2041
 
2042
        return $box;
2043
    }
2044
 
2045
    /**
2046
     * This function will render one beautiful table with all the environmental
2047
     * configuration and how it suits Moodle needs.
2048
     *
2049
     * @param boolean $result final result of the check (true/false)
2050
     * @param environment_results[] $environment_results array of results gathered
2051
     * @return string HTML to output.
2052
     */
2053
    public function environment_check_table($result, $environment_results) {
2054
        global $CFG;
2055
 
2056
        // Table headers
2057
        $servertable = new html_table();//table for server checks
2058
        $servertable->head  = array(
2059
            get_string('name'),
2060
            get_string('info'),
2061
            get_string('report'),
2062
            get_string('plugin'),
2063
            get_string('status'),
2064
        );
2065
        $servertable->colclasses = array('centeralign name', 'centeralign info', 'leftalign report', 'leftalign plugin', 'centeralign status');
1441 ariadna 2066
        $servertable->attributes['class'] = 'table table-striped admintable environmenttable generaltable table-sm';
1 efrain 2067
        $servertable->id = 'serverstatus';
2068
 
2069
        $serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
2070
 
2071
        $othertable = new html_table();//table for custom checks
2072
        $othertable->head  = array(
2073
            get_string('info'),
2074
            get_string('report'),
2075
            get_string('plugin'),
2076
            get_string('status'),
2077
        );
2078
        $othertable->colclasses = array('aligncenter info', 'alignleft report', 'alignleft plugin', 'aligncenter status');
1441 ariadna 2079
        $othertable->attributes['class'] = 'table table-striped admintable environmenttable generaltable table-sm';
1 efrain 2080
        $othertable->id = 'otherserverstatus';
2081
 
2082
        $otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
2083
 
2084
        // Iterate over each environment_result
2085
        $continue = true;
2086
        foreach ($environment_results as $environment_result) {
2087
            $errorline   = false;
2088
            $warningline = false;
2089
            $stringtouse = '';
2090
            if ($continue) {
2091
                $type = $environment_result->getPart();
2092
                $info = $environment_result->getInfo();
2093
                $status = $environment_result->getStatus();
2094
                $plugin = $environment_result->getPluginName();
2095
                $error_code = $environment_result->getErrorCode();
2096
                // Process Report field
2097
                $rec = new stdClass();
2098
                // Something has gone wrong at parsing time
2099
                if ($error_code) {
2100
                    $stringtouse = 'environmentxmlerror';
2101
                    $rec->error_code = $error_code;
2102
                    $status = get_string('error');
2103
                    $errorline = true;
2104
                    $continue = false;
2105
                }
2106
 
2107
                if ($continue) {
2108
                    if ($rec->needed = $environment_result->getNeededVersion()) {
2109
                        // We are comparing versions
2110
                        $rec->current = $environment_result->getCurrentVersion();
2111
                        if ($environment_result->getLevel() == 'required') {
2112
                            $stringtouse = 'environmentrequireversion';
2113
                        } else {
2114
                            $stringtouse = 'environmentrecommendversion';
2115
                        }
2116
 
2117
                    } else if ($environment_result->getPart() == 'custom_check') {
2118
                        // We are checking installed & enabled things
2119
                        if ($environment_result->getLevel() == 'required') {
2120
                            $stringtouse = 'environmentrequirecustomcheck';
2121
                        } else if ($environment_result->getLevel() == 'optional') {
2122
                            $stringtouse = 'environmentrecommendcustomcheck';
2123
                        } else {
2124
                            $stringtouse = 'environmentshouldfixcustomcheck';
2125
                        }
2126
 
2127
                    } else if ($environment_result->getPart() == 'php_setting') {
2128
                        if ($status) {
2129
                            $stringtouse = 'environmentsettingok';
2130
                        } else if ($environment_result->getLevel() == 'required') {
2131
                            $stringtouse = 'environmentmustfixsetting';
2132
                        } else {
2133
                            $stringtouse = 'environmentshouldfixsetting';
2134
                        }
2135
 
2136
                    } else {
2137
                        if ($environment_result->getLevel() == 'required') {
2138
                            $stringtouse = 'environmentrequireinstall';
2139
                        } else {
2140
                            $stringtouse = 'environmentrecommendinstall';
2141
                        }
2142
                    }
2143
 
2144
                    // Calculate the status value
2145
                    if ($environment_result->getBypassStr() != '') {            //Handle bypassed result (warning)
2146
                        $status = get_string('bypassed');
2147
                        $warningline = true;
2148
                    } else if ($environment_result->getRestrictStr() != '') {   //Handle restricted result (error)
2149
                        $status = get_string('restricted');
2150
                        $errorline = true;
2151
                    } else {
2152
                        if ($status) {                                          //Handle ok result (ok)
2153
                            $status = get_string('statusok');
2154
                        } else {
2155
                            // Handle check result (warning).
2156
                            if (in_array($environment_result->getLevel(), ['optional', 'recommended'])) {
2157
                                $status = get_string('check');
2158
                                $warningline = true;
2159
                            } else {                                            //Handle error result (error)
2160
                                $status = get_string('check');
2161
                                $errorline = true;
2162
                            }
2163
                        }
2164
                    }
2165
                }
2166
 
2167
                // Build the text
2168
                $linkparts = array();
2169
                $linkparts[] = 'admin/environment';
2170
                $linkparts[] = $type;
2171
                if (!empty($info)){
2172
                   $linkparts[] = $info;
2173
                }
2174
                // Plugin environments do not have docs pages yet.
2175
                if (empty($CFG->docroot) or $environment_result->plugin) {
2176
                    $report = get_string($stringtouse, 'admin', $rec);
2177
                } else {
2178
                    $report = $this->doc_link(join('/', $linkparts), get_string($stringtouse, 'admin', $rec), true);
2179
                }
2180
 
2181
                // Format error or warning line
2182
                if ($errorline) {
2183
                    $messagetype = 'error';
2184
                    $statusclass = 'bg-danger text-white';
1441 ariadna 2185
                    $feedbackclass = 'alert-danger';
1 efrain 2186
                } else if ($warningline) {
2187
                    $messagetype = 'warn';
2188
                    $statusclass = 'bg-warning text-dark';
1441 ariadna 2189
                    $feedbackclass = 'alert-warning';
1 efrain 2190
                } else {
2191
                    $messagetype = 'ok';
2192
                    $statusclass = 'bg-success text-white';
1441 ariadna 2193
                    $feedbackclass = 'alert-success';
1 efrain 2194
                }
2195
                $status = html_writer::span($status, 'badge ' . $statusclass);
2196
                // Here we'll store all the feedback found
2197
                $feedbacktext = '';
2198
                // Append the feedback if there is some
1441 ariadna 2199
                $feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(),
2200
                    "alert {$feedbackclass} px-2 py-1 m-1");
1 efrain 2201
                //Append the bypass if there is some
1441 ariadna 2202
                $feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(),
2203
                    'alert alert-warning px-2 py-1 m-1');
1 efrain 2204
                //Append the restrict if there is some
1441 ariadna 2205
                $feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(),
2206
                    'alert alert-danger px-2 py-1 m-1');
1 efrain 2207
 
2208
                $report .= $feedbacktext;
2209
 
2210
                // Add the row to the table
2211
                if ($environment_result->getPart() == 'custom_check'){
2212
                    $otherdata[$messagetype][] = array ($info, $report, $plugin, $status);
2213
                } else {
2214
                    $serverdata[$messagetype][] = array ($type, $info, $report, $plugin, $status);
2215
                }
2216
            }
2217
        }
2218
 
2219
        //put errors first in
2220
        $servertable->data = array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']);
2221
        $othertable->data = array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']);
2222
 
2223
        // Print table
2224
        $output = '';
2225
        $output .= $this->heading(get_string('serverchecks', 'admin'));
2226
        $output .= html_writer::table($servertable);
2227
        if (count($othertable->data)){
2228
            $output .= $this->heading(get_string('customcheck', 'admin'));
2229
            $output .= html_writer::table($othertable);
2230
        }
2231
 
2232
        // Finally, if any error has happened, print the summary box
2233
        if (!$result) {
2234
            $output .= $this->box(get_string('environmenterrortodo', 'admin'), 'environmentbox errorbox');
2235
        }
2236
 
2237
        return $output;
2238
    }
2239
 
2240
    /**
2241
     * Render a simple page for providing the upgrade key.
2242
     *
2243
     * @param moodle_url|string $url
2244
     * @return string
2245
     */
2246
    public function upgradekey_form_page($url) {
2247
 
2248
        $output = '';
2249
        $output .= $this->header();
2250
        $output .= $this->heading(get_string('upgradekeyreq', 'core_admin'));
1441 ariadna 2251
        $output .= $this->container_start('upgradekeyreq w-25');
1 efrain 2252
        $output .= html_writer::start_tag('form', array('method' => 'POST', 'action' => $url));
2253
        $output .= html_writer::empty_tag('input', [
1441 ariadna 2254
            'id' => 'upgradekey',
1 efrain 2255
            'name' => 'upgradekey',
2256
            'type' => 'password',
2257
            'class' => 'form-control w-auto',
2258
        ]);
2259
        $output .= html_writer::empty_tag('input', [
2260
            'type' => 'submit',
2261
            'value' => get_string('submit'),
2262
            'class' => 'btn btn-primary mt-3',
2263
        ]);
2264
        $output .= html_writer::end_tag('form');
2265
        $output .= $this->container_end();
2266
        $output .= $this->footer();
2267
 
2268
        return $output;
2269
    }
2270
 
2271
    /**
2272
     * Display message about the benefits of registering on Moodle.org
2273
     *
2274
     * @return string
2275
     */
2276
    public function moodleorg_registration_message() {
1441 ariadna 2277
        $a = new stdClass();
2278
        $a->moreinformation = '#id_sitestats'; // More information anchor.
2279
        $a->moodleapp = MOODLE_PRODUCTURL . '/solutions/moodle-app/';
2280
        $out = format_text(get_string('registerwithmoodleorginfo', 'core_hub', $a), FORMAT_MARKDOWN);
1 efrain 2281
 
2282
        $out .= html_writer::link(
2283
            HUB_MOODLEORGHUBURL,
2284
            $this->output->pix_icon('i/stats', '').' '.get_string('registerwithmoodleorginfostats', 'core_hub'),
2285
            ['class' => 'btn btn-link', 'role' => 'opener', 'target' => '_href']
2286
        );
2287
 
2288
        $out .= html_writer::link(
2289
            HUB_MOODLEORGHUBURL.'/sites',
2290
            $this->output->pix_icon('i/location', '').' '.get_string('registerwithmoodleorginfosites', 'core_hub'),
2291
            ['class' => 'btn btn-link', 'role' => 'opener', 'target' => '_href']
2292
        );
2293
 
2294
        return $this->output->box($out);
2295
    }
2296
 
2297
    /**
2298
     * Display message about benefits of enabling the user feedback feature.
2299
     *
2300
     * @param bool $showfeedbackencouragement Whether the encouragement content should be displayed or not
2301
     * @return string
2302
     */
2303
    protected function userfeedback_encouragement(bool $showfeedbackencouragement): string {
2304
        $output = '';
2305
 
2306
        if ($showfeedbackencouragement) {
2307
            $settingslink = new moodle_url('/admin/settings.php', ['section' => 'userfeedback']);
2308
            $output .= $this->warning(get_string('userfeedbackencouragement', 'admin', $settingslink->out()), 'info');
2309
        }
2310
 
2311
        return $output;
2312
    }
2313
 
2314
    /**
2315
     * Display a warning about the deprecation of Mnet.
2316
     *
2317
     * @param string $xmlrpcwarning The warning message
2318
     * @return string HTML to output.
2319
     */
2320
    protected function mnet_deprecation_warning($xmlrpcwarning) {
2321
        if (empty($xmlrpcwarning)) {
2322
            return '';
2323
        }
2324
 
2325
        return $this->warning($xmlrpcwarning);
2326
    }
2327
 
2328
    /**
2329
     * Renders the theme selector list.
2330
     *
2331
     * @param core_admin\output\theme_selector $themeselector
2332
     * @return string HTML
2333
     */
2334
    public function theme_selector_list(core_admin\output\theme_selector $themeselector): string {
2335
        $renderable = $themeselector->export_for_template($this);
2336
        return $this->render_from_template('core_admin/themeselector/theme_selector', $renderable);
2337
    }
2338
}