PageRenderTime 53ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/admin/renderer.php

https://github.com/dongsheng/moodle
PHP | 2211 lines | 1432 code | 327 blank | 452 comment | 252 complexity | 7ce1caab791c92ea7c24e8b8bf3d9544 MD5 | raw file
Possible License(s): BSD-3-Clause, MIT, GPL-3.0, Apache-2.0, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  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. * Renderer for core_admin subsystem
  18. *
  19. * @package core
  20. * @subpackage admin
  21. * @copyright 2011 David Mudrak <david@moodle.com>
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23. */
  24. defined('MOODLE_INTERNAL') || die();
  25. /**
  26. * Standard HTML output renderer for core_admin subsystem
  27. */
  28. class core_admin_renderer extends plugin_renderer_base {
  29. /**
  30. * Display the 'Do you acknowledge the terms of the GPL' page. The first page
  31. * during install.
  32. * @return string HTML to output.
  33. */
  34. public function install_licence_page() {
  35. global $CFG;
  36. $output = '';
  37. $copyrightnotice = text_to_html(get_string('gpl3'));
  38. $copyrightnotice = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $copyrightnotice); // extremely ugly validation hack
  39. $continue = new single_button(new moodle_url($this->page->url, array(
  40. 'lang' => $CFG->lang, 'agreelicense' => 1)), get_string('continue'), 'get');
  41. $output .= $this->header();
  42. $output .= $this->heading('<a href="http://moodle.org">Moodle</a> - Modular Object-Oriented Dynamic Learning Environment');
  43. $output .= $this->heading(get_string('copyrightnotice'));
  44. $output .= $this->box($copyrightnotice, 'copyrightnotice');
  45. $output .= html_writer::empty_tag('br');
  46. $output .= $this->confirm(get_string('doyouagree'), $continue, "http://docs.moodle.org/dev/License");
  47. $output .= $this->footer();
  48. return $output;
  49. }
  50. /**
  51. * Display page explaining proper upgrade process,
  52. * there can not be any PHP file leftovers...
  53. *
  54. * @return string HTML to output.
  55. */
  56. public function upgrade_stale_php_files_page() {
  57. $output = '';
  58. $output .= $this->header();
  59. $output .= $this->heading(get_string('upgradestalefiles', 'admin'));
  60. $output .= $this->box_start('generalbox', 'notice');
  61. $output .= format_text(get_string('upgradestalefilesinfo', 'admin', get_docs_url('Upgrading')), FORMAT_MARKDOWN);
  62. $output .= html_writer::empty_tag('br');
  63. $output .= html_writer::tag('div', $this->single_button($this->page->url, get_string('reload'), 'get'), array('class' => 'buttons'));
  64. $output .= $this->box_end();
  65. $output .= $this->footer();
  66. return $output;
  67. }
  68. /**
  69. * Display the 'environment check' page that is displayed during install.
  70. * @param int $maturity
  71. * @param boolean $envstatus final result of the check (true/false)
  72. * @param array $environment_results array of results gathered
  73. * @param string $release moodle release
  74. * @return string HTML to output.
  75. */
  76. public function install_environment_page($maturity, $envstatus, $environment_results, $release) {
  77. global $CFG;
  78. $output = '';
  79. $output .= $this->header();
  80. $output .= $this->maturity_warning($maturity);
  81. $output .= $this->heading("Moodle $release");
  82. $output .= $this->release_notes_link();
  83. $output .= $this->environment_check_table($envstatus, $environment_results);
  84. if (!$envstatus) {
  85. $output .= $this->upgrade_reload(new moodle_url($this->page->url, array('agreelicense' => 1, 'lang' => $CFG->lang)));
  86. } else {
  87. $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
  88. $output .= $this->continue_button(new moodle_url($this->page->url, array(
  89. 'agreelicense' => 1, 'confirmrelease' => 1, 'lang' => $CFG->lang)));
  90. }
  91. $output .= $this->footer();
  92. return $output;
  93. }
  94. /**
  95. * Displays the list of plugins with unsatisfied dependencies
  96. *
  97. * @param double|string|int $version Moodle on-disk version
  98. * @param array $failed list of plugins with unsatisfied dependecies
  99. * @param moodle_url $reloadurl URL of the page to recheck the dependencies
  100. * @return string HTML
  101. */
  102. public function unsatisfied_dependencies_page($version, array $failed, moodle_url $reloadurl) {
  103. $output = '';
  104. $output .= $this->header();
  105. $output .= $this->heading(get_string('pluginscheck', 'admin'));
  106. $output .= $this->warning(get_string('pluginscheckfailed', 'admin', array('pluginslist' => implode(', ', array_unique($failed)))));
  107. $output .= $this->plugins_check_table(core_plugin_manager::instance(), $version, array('xdep' => true));
  108. $output .= $this->warning(get_string('pluginschecktodo', 'admin'));
  109. $output .= $this->continue_button($reloadurl);
  110. $output .= $this->footer();
  111. return $output;
  112. }
  113. /**
  114. * Display the 'You are about to upgrade Moodle' page. The first page
  115. * during upgrade.
  116. * @param string $strnewversion
  117. * @param int $maturity
  118. * @param string $testsite
  119. * @return string HTML to output.
  120. */
  121. public function upgrade_confirm_page($strnewversion, $maturity, $testsite) {
  122. $output = '';
  123. $continueurl = new moodle_url($this->page->url, array('confirmupgrade' => 1, 'cache' => 0));
  124. $continue = new single_button($continueurl, get_string('continue'), 'get');
  125. $cancelurl = new moodle_url('/admin/index.php');
  126. $output .= $this->header();
  127. $output .= $this->maturity_warning($maturity);
  128. $output .= $this->test_site_warning($testsite);
  129. $output .= $this->confirm(get_string('upgradesure', 'admin', $strnewversion), $continue, $cancelurl);
  130. $output .= $this->footer();
  131. return $output;
  132. }
  133. /**
  134. * Display the environment page during the upgrade process.
  135. * @param string $release
  136. * @param boolean $envstatus final result of env check (true/false)
  137. * @param array $environment_results array of results gathered
  138. * @return string HTML to output.
  139. */
  140. public function upgrade_environment_page($release, $envstatus, $environment_results) {
  141. global $CFG;
  142. $output = '';
  143. $output .= $this->header();
  144. $output .= $this->heading("Moodle $release");
  145. $output .= $this->release_notes_link();
  146. $output .= $this->environment_check_table($envstatus, $environment_results);
  147. if (!$envstatus) {
  148. $output .= $this->upgrade_reload(new moodle_url($this->page->url, array('confirmupgrade' => 1, 'cache' => 0)));
  149. } else {
  150. $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
  151. if (empty($CFG->skiplangupgrade) and current_language() !== 'en') {
  152. $output .= $this->box(get_string('langpackwillbeupdated', 'admin'), 'generalbox', 'notice');
  153. }
  154. $output .= $this->continue_button(new moodle_url($this->page->url, array(
  155. 'confirmupgrade' => 1, 'confirmrelease' => 1, 'cache' => 0)));
  156. }
  157. $output .= $this->footer();
  158. return $output;
  159. }
  160. /**
  161. * Display the upgrade page that lists all the plugins that require attention.
  162. * @param core_plugin_manager $pluginman provides information about the plugins.
  163. * @param \core\update\checker $checker provides information about available updates.
  164. * @param int $version the version of the Moodle code from version.php.
  165. * @param bool $showallplugins
  166. * @param moodle_url $reloadurl
  167. * @param moodle_url $continueurl
  168. * @return string HTML to output.
  169. */
  170. public function upgrade_plugin_check_page(core_plugin_manager $pluginman, \core\update\checker $checker,
  171. $version, $showallplugins, $reloadurl, $continueurl) {
  172. $output = '';
  173. $output .= $this->header();
  174. $output .= $this->box_start('generalbox', 'plugins-check-page');
  175. $output .= html_writer::tag('p', get_string('pluginchecknotice', 'core_plugin'), array('class' => 'page-description'));
  176. $output .= $this->check_for_updates_button($checker, $reloadurl);
  177. $output .= $this->missing_dependencies($pluginman);
  178. $output .= $this->plugins_check_table($pluginman, $version, array('full' => $showallplugins));
  179. $output .= $this->box_end();
  180. $output .= $this->upgrade_reload($reloadurl);
  181. if ($pluginman->some_plugins_updatable()) {
  182. $output .= $this->container_start('upgradepluginsinfo');
  183. $output .= $this->help_icon('upgradepluginsinfo', 'core_admin', get_string('upgradepluginsfirst', 'core_admin'));
  184. $output .= $this->container_end();
  185. }
  186. $button = new single_button($continueurl, get_string('upgradestart', 'admin'), 'get', true);
  187. $button->class = 'continuebutton';
  188. $output .= $this->render($button);
  189. $output .= $this->footer();
  190. return $output;
  191. }
  192. /**
  193. * Display a page to confirm plugin installation cancelation.
  194. *
  195. * @param array $abortable list of \core\update\plugininfo
  196. * @param moodle_url $continue
  197. * @return string
  198. */
  199. public function upgrade_confirm_abort_install_page(array $abortable, moodle_url $continue) {
  200. $pluginman = core_plugin_manager::instance();
  201. if (empty($abortable)) {
  202. // The UI should not allow this.
  203. throw new moodle_exception('err_no_plugin_install_abortable', 'core_plugin');
  204. }
  205. $out = $this->output->header();
  206. $out .= $this->output->heading(get_string('cancelinstallhead', 'core_plugin'), 3);
  207. $out .= $this->output->container(get_string('cancelinstallinfo', 'core_plugin'), 'cancelinstallinfo');
  208. foreach ($abortable as $pluginfo) {
  209. $out .= $this->output->heading($pluginfo->displayname.' ('.$pluginfo->component.')', 4);
  210. $out .= $this->output->container(get_string('cancelinstallinfodir', 'core_plugin', $pluginfo->rootdir));
  211. if ($repotype = $pluginman->plugin_external_source($pluginfo->component)) {
  212. $out .= $this->output->container(get_string('uninstalldeleteconfirmexternal', 'core_plugin', $repotype),
  213. 'alert alert-warning mt-2');
  214. }
  215. }
  216. $out .= $this->plugins_management_confirm_buttons($continue, $this->page->url);
  217. $out .= $this->output->footer();
  218. return $out;
  219. }
  220. /**
  221. * Display the admin notifications page.
  222. * @param int $maturity
  223. * @param bool $insecuredataroot warn dataroot is invalid
  224. * @param bool $errorsdisplayed warn invalid dispaly error setting
  225. * @param bool $cronoverdue warn cron not running
  226. * @param bool $dbproblems warn db has problems
  227. * @param bool $maintenancemode warn in maintenance mode
  228. * @param bool $buggyiconvnomb warn iconv problems
  229. * @param array|null $availableupdates array of \core\update\info objects or null
  230. * @param int|null $availableupdatesfetch timestamp of the most recent updates fetch or null (unknown)
  231. * @param string[] $cachewarnings An array containing warnings from the Cache API.
  232. * @param array $eventshandlers Events 1 API handlers.
  233. * @param bool $themedesignermode Warn about the theme designer mode.
  234. * @param bool $devlibdir Warn about development libs directory presence.
  235. * @param bool $mobileconfigured Whether the mobile web services have been enabled
  236. * @param bool $overridetossl Whether or not ssl is being forced.
  237. * @param bool $invalidforgottenpasswordurl Whether the forgotten password URL does not link to a valid URL.
  238. * @param bool $croninfrequent If true, warn that cron hasn't run in the past few minutes
  239. * @param bool $showcampaigncontent Whether the campaign content should be visible or not.
  240. * @param bool $showfeedbackencouragement Whether the feedback encouragement content should be displayed or not.
  241. *
  242. * @return string HTML to output.
  243. */
  244. public function admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed,
  245. $cronoverdue, $dbproblems, $maintenancemode, $availableupdates, $availableupdatesfetch,
  246. $buggyiconvnomb, $registered, array $cachewarnings = array(), $eventshandlers = 0,
  247. $themedesignermode = false, $devlibdir = false, $mobileconfigured = false,
  248. $overridetossl = false, $invalidforgottenpasswordurl = false, $croninfrequent = false,
  249. $showcampaigncontent = false, bool $showfeedbackencouragement = false) {
  250. global $CFG;
  251. $output = '';
  252. $output .= $this->header();
  253. $output .= $this->maturity_info($maturity);
  254. $output .= $this->legacy_log_store_writing_error();
  255. $output .= empty($CFG->disableupdatenotifications) ? $this->available_updates($availableupdates, $availableupdatesfetch) : '';
  256. $output .= $this->insecure_dataroot_warning($insecuredataroot);
  257. $output .= $this->development_libs_directories_warning($devlibdir);
  258. $output .= $this->themedesignermode_warning($themedesignermode);
  259. $output .= $this->display_errors_warning($errorsdisplayed);
  260. $output .= $this->buggy_iconv_warning($buggyiconvnomb);
  261. $output .= $this->cron_overdue_warning($cronoverdue);
  262. $output .= $this->cron_infrequent_warning($croninfrequent);
  263. $output .= $this->db_problems($dbproblems);
  264. $output .= $this->maintenance_mode_warning($maintenancemode);
  265. $output .= $this->overridetossl_warning($overridetossl);
  266. $output .= $this->cache_warnings($cachewarnings);
  267. $output .= $this->events_handlers($eventshandlers);
  268. $output .= $this->registration_warning($registered);
  269. $output .= $this->mobile_configuration_warning($mobileconfigured);
  270. $output .= $this->forgotten_password_url_warning($invalidforgottenpasswordurl);
  271. $output .= $this->userfeedback_encouragement($showfeedbackencouragement);
  272. $output .= $this->campaign_content($showcampaigncontent);
  273. //////////////////////////////////////////////////////////////////////////////////////////////////
  274. //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
  275. $output .= $this->moodle_copyright();
  276. //////////////////////////////////////////////////////////////////////////////////////////////////
  277. $output .= $this->footer();
  278. return $output;
  279. }
  280. /**
  281. * Display the plugin management page (admin/plugins.php).
  282. *
  283. * The filtering options array may contain following items:
  284. * bool contribonly - show only contributed extensions
  285. * bool updatesonly - show only plugins with an available update
  286. *
  287. * @param core_plugin_manager $pluginman
  288. * @param \core\update\checker $checker
  289. * @param array $options filtering options
  290. * @return string HTML to output.
  291. */
  292. public function plugin_management_page(core_plugin_manager $pluginman, \core\update\checker $checker, array $options = array()) {
  293. $output = '';
  294. $output .= $this->header();
  295. $output .= $this->heading(get_string('pluginsoverview', 'core_admin'));
  296. $output .= $this->check_for_updates_button($checker, $this->page->url);
  297. $output .= $this->plugins_overview_panel($pluginman, $options);
  298. $output .= $this->plugins_control_panel($pluginman, $options);
  299. $output .= $this->footer();
  300. return $output;
  301. }
  302. /**
  303. * Renders a button to fetch for available updates.
  304. *
  305. * @param \core\update\checker $checker
  306. * @param moodle_url $reloadurl
  307. * @return string HTML
  308. */
  309. public function check_for_updates_button(\core\update\checker $checker, $reloadurl) {
  310. $output = '';
  311. if ($checker->enabled()) {
  312. $output .= $this->container_start('checkforupdates mb-4');
  313. $output .= $this->single_button(
  314. new moodle_url($reloadurl, array('fetchupdates' => 1)),
  315. get_string('checkforupdates', 'core_plugin')
  316. );
  317. if ($timefetched = $checker->get_last_timefetched()) {
  318. $timefetched = userdate($timefetched, get_string('strftimedatetime', 'core_langconfig'));
  319. $output .= $this->container(get_string('checkforupdateslast', 'core_plugin', $timefetched),
  320. 'lasttimefetched small text-muted mt-1');
  321. }
  322. $output .= $this->container_end();
  323. }
  324. return $output;
  325. }
  326. /**
  327. * Display a page to confirm the plugin uninstallation.
  328. *
  329. * @param core_plugin_manager $pluginman
  330. * @param \core\plugininfo\base $pluginfo
  331. * @param moodle_url $continueurl URL to continue after confirmation
  332. * @param moodle_url $cancelurl URL to to go if cancelled
  333. * @return string
  334. */
  335. public function plugin_uninstall_confirm_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, moodle_url $continueurl, moodle_url $cancelurl) {
  336. $output = '';
  337. $pluginname = $pluginman->plugin_name($pluginfo->component);
  338. $confirm = '<p>' . get_string('uninstallconfirm', 'core_plugin', array('name' => $pluginname)) . '</p>';
  339. if ($extraconfirm = $pluginfo->get_uninstall_extra_warning()) {
  340. $confirm .= $extraconfirm;
  341. }
  342. $output .= $this->output->header();
  343. $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
  344. $output .= $this->output->confirm($confirm, $continueurl, $cancelurl);
  345. $output .= $this->output->footer();
  346. return $output;
  347. }
  348. /**
  349. * Display a page with results of plugin uninstallation and offer removal of plugin files.
  350. *
  351. * @param core_plugin_manager $pluginman
  352. * @param \core\plugininfo\base $pluginfo
  353. * @param progress_trace_buffer $progress
  354. * @param moodle_url $continueurl URL to continue to remove the plugin folder
  355. * @return string
  356. */
  357. public function plugin_uninstall_results_removable_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo,
  358. progress_trace_buffer $progress, moodle_url $continueurl) {
  359. $output = '';
  360. $pluginname = $pluginman->plugin_name($pluginfo->component);
  361. // Do not show navigation here, they must click one of the buttons.
  362. $this->page->set_pagelayout('maintenance');
  363. $this->page->set_cacheable(false);
  364. $output .= $this->output->header();
  365. $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
  366. $output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
  367. $confirm = $this->output->container(get_string('uninstalldeleteconfirm', 'core_plugin',
  368. array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'uninstalldeleteconfirm');
  369. if ($repotype = $pluginman->plugin_external_source($pluginfo->component)) {
  370. $confirm .= $this->output->container(get_string('uninstalldeleteconfirmexternal', 'core_plugin', $repotype),
  371. 'alert alert-warning mt-2');
  372. }
  373. // After any uninstall we must execute full upgrade to finish the cleanup!
  374. $output .= $this->output->confirm($confirm, $continueurl, new moodle_url('/admin/index.php'));
  375. $output .= $this->output->footer();
  376. return $output;
  377. }
  378. /**
  379. * Display a page with results of plugin uninstallation and inform about the need to remove plugin files manually.
  380. *
  381. * @param core_plugin_manager $pluginman
  382. * @param \core\plugininfo\base $pluginfo
  383. * @param progress_trace_buffer $progress
  384. * @return string
  385. */
  386. public function plugin_uninstall_results_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, progress_trace_buffer $progress) {
  387. $output = '';
  388. $pluginname = $pluginfo->component;
  389. $output .= $this->output->header();
  390. $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
  391. $output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
  392. $output .= $this->output->box(get_string('uninstalldelete', 'core_plugin',
  393. array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'generalbox uninstalldelete');
  394. $output .= $this->output->continue_button(new moodle_url('/admin/index.php'));
  395. $output .= $this->output->footer();
  396. return $output;
  397. }
  398. /**
  399. * Display the plugin management page (admin/environment.php).
  400. * @param array $versions
  401. * @param string $version
  402. * @param boolean $envstatus final result of env check (true/false)
  403. * @param array $environment_results array of results gathered
  404. * @return string HTML to output.
  405. */
  406. public function environment_check_page($versions, $version, $envstatus, $environment_results) {
  407. $output = '';
  408. $output .= $this->header();
  409. // Print the component download link
  410. $output .= html_writer::tag('div', html_writer::link(
  411. new moodle_url('/admin/environment.php', array('action' => 'updatecomponent', 'sesskey' => sesskey())),
  412. get_string('updatecomponent', 'admin')),
  413. array('class' => 'reportlink'));
  414. // Heading.
  415. $output .= $this->heading(get_string('environment', 'admin'));
  416. // Box with info and a menu to choose the version.
  417. $output .= $this->box_start();
  418. $output .= html_writer::tag('div', get_string('adminhelpenvironment'));
  419. $select = new single_select(new moodle_url('/admin/environment.php'), 'version', $versions, $version, null);
  420. $select->label = get_string('moodleversion');
  421. $output .= $this->render($select);
  422. $output .= $this->box_end();
  423. // The results
  424. $output .= $this->environment_check_table($envstatus, $environment_results);
  425. $output .= $this->footer();
  426. return $output;
  427. }
  428. /**
  429. * Output a warning message, of the type that appears on the admin notifications page.
  430. * @param string $message the message to display.
  431. * @param string $type type class
  432. * @return string HTML to output.
  433. */
  434. protected function warning($message, $type = 'warning') {
  435. return $this->box($message, 'generalbox alert alert-' . $type);
  436. }
  437. /**
  438. * Render an appropriate message if dataroot is insecure.
  439. * @param bool $insecuredataroot
  440. * @return string HTML to output.
  441. */
  442. protected function insecure_dataroot_warning($insecuredataroot) {
  443. global $CFG;
  444. if ($insecuredataroot == INSECURE_DATAROOT_WARNING) {
  445. return $this->warning(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot));
  446. } else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) {
  447. return $this->warning(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'danger');
  448. } else {
  449. return '';
  450. }
  451. }
  452. /**
  453. * Render a warning that a directory with development libs is present.
  454. *
  455. * @param bool $devlibdir True if the warning should be displayed.
  456. * @return string
  457. */
  458. protected function development_libs_directories_warning($devlibdir) {
  459. if ($devlibdir) {
  460. $moreinfo = new moodle_url('/report/security/index.php');
  461. $warning = get_string('devlibdirpresent', 'core_admin', ['moreinfourl' => $moreinfo->out()]);
  462. return $this->warning($warning, 'danger');
  463. } else {
  464. return '';
  465. }
  466. }
  467. /**
  468. * Render an appropriate message if dataroot is insecure.
  469. * @param bool $errorsdisplayed
  470. * @return string HTML to output.
  471. */
  472. protected function display_errors_warning($errorsdisplayed) {
  473. if (!$errorsdisplayed) {
  474. return '';
  475. }
  476. return $this->warning(get_string('displayerrorswarning', 'admin'));
  477. }
  478. /**
  479. * Render an appropriate message if themdesignermode is enabled.
  480. * @param bool $themedesignermode true if enabled
  481. * @return string HTML to output.
  482. */
  483. protected function themedesignermode_warning($themedesignermode) {
  484. if (!$themedesignermode) {
  485. return '';
  486. }
  487. return $this->warning(get_string('themedesignermodewarning', 'admin'));
  488. }
  489. /**
  490. * Render an appropriate message if iconv is buggy and mbstring missing.
  491. * @param bool $buggyiconvnomb
  492. * @return string HTML to output.
  493. */
  494. protected function buggy_iconv_warning($buggyiconvnomb) {
  495. if (!$buggyiconvnomb) {
  496. return '';
  497. }
  498. return $this->warning(get_string('warningiconvbuggy', 'admin'));
  499. }
  500. /**
  501. * Render an appropriate message if cron has not been run recently.
  502. * @param bool $cronoverdue
  503. * @return string HTML to output.
  504. */
  505. public function cron_overdue_warning($cronoverdue) {
  506. global $CFG;
  507. if (!$cronoverdue) {
  508. return '';
  509. }
  510. $check = new \tool_task\check\cronrunning();
  511. $result = $check->get_result();
  512. return $this->warning($result->get_summary() . '&nbsp;' . $this->help_icon('cron', 'admin'));
  513. }
  514. /**
  515. * Render an appropriate message if cron is not being run frequently (recommended every minute).
  516. *
  517. * @param bool $croninfrequent
  518. * @return string HTML to output.
  519. */
  520. public function cron_infrequent_warning(bool $croninfrequent) : string {
  521. global $CFG;
  522. if (!$croninfrequent) {
  523. return '';
  524. }
  525. $check = new \tool_task\check\cronrunning();
  526. $result = $check->get_result();
  527. return $this->warning($result->get_summary() . '&nbsp;' . $this->help_icon('cron', 'admin'));
  528. }
  529. /**
  530. * Render an appropriate message if there are any problems with the DB set-up.
  531. * @param bool $dbproblems
  532. * @return string HTML to output.
  533. */
  534. public function db_problems($dbproblems) {
  535. if (!$dbproblems) {
  536. return '';
  537. }
  538. return $this->warning($dbproblems);
  539. }
  540. /**
  541. * Renders cache warnings if there are any.
  542. *
  543. * @param string[] $cachewarnings
  544. * @return string
  545. */
  546. public function cache_warnings(array $cachewarnings) {
  547. if (!count($cachewarnings)) {
  548. return '';
  549. }
  550. return join("\n", array_map(array($this, 'warning'), $cachewarnings));
  551. }
  552. /**
  553. * Renders events 1 API handlers warning.
  554. *
  555. * @param array $eventshandlers
  556. * @return string
  557. */
  558. public function events_handlers($eventshandlers) {
  559. if ($eventshandlers) {
  560. $components = '';
  561. foreach ($eventshandlers as $eventhandler) {
  562. $components .= $eventhandler->component . ', ';
  563. }
  564. $components = rtrim($components, ', ');
  565. return $this->warning(get_string('eventshandlersinuse', 'admin', $components));
  566. }
  567. }
  568. /**
  569. * Render an appropriate message if the site in in maintenance mode.
  570. * @param bool $maintenancemode
  571. * @return string HTML to output.
  572. */
  573. public function maintenance_mode_warning($maintenancemode) {
  574. if (!$maintenancemode) {
  575. return '';
  576. }
  577. $url = new moodle_url('/admin/settings.php', array('section' => 'maintenancemode'));
  578. $url = $url->out(); // get_string() does not support objects in params
  579. return $this->warning(get_string('sitemaintenancewarning2', 'admin', $url));
  580. }
  581. /**
  582. * Render a warning that ssl is forced because the site was on loginhttps.
  583. *
  584. * @param bool $overridetossl Whether or not ssl is being forced.
  585. * @return string
  586. */
  587. protected function overridetossl_warning($overridetossl) {
  588. if (!$overridetossl) {
  589. return '';
  590. }
  591. $warning = get_string('overridetossl', 'core_admin');
  592. return $this->warning($warning, 'warning');
  593. }
  594. /**
  595. * Display a warning about installing development code if necesary.
  596. * @param int $maturity
  597. * @return string HTML to output.
  598. */
  599. protected function maturity_warning($maturity) {
  600. if ($maturity == MATURITY_STABLE) {
  601. return ''; // No worries.
  602. }
  603. $maturitylevel = get_string('maturity' . $maturity, 'admin');
  604. return $this->warning(
  605. $this->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
  606. $this->container($this->doc_link('admin/versions', get_string('morehelp'))),
  607. 'danger');
  608. }
  609. /*
  610. * If necessary, displays a warning about upgrading a test site.
  611. *
  612. * @param string $testsite
  613. * @return string HTML
  614. */
  615. protected function test_site_warning($testsite) {
  616. if (!$testsite) {
  617. return '';
  618. }
  619. $warning = (get_string('testsiteupgradewarning', 'admin', $testsite));
  620. return $this->warning($warning, 'danger');
  621. }
  622. /**
  623. * Output the copyright notice.
  624. * @return string HTML to output.
  625. */
  626. protected function moodle_copyright() {
  627. global $CFG;
  628. //////////////////////////////////////////////////////////////////////////////////////////////////
  629. //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
  630. $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
  631. '<a href="http://docs.moodle.org/dev/Releases" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
  632. 'Copyright &copy; 1999 onwards, Martin Dougiamas<br />'.
  633. 'and <a href="http://moodle.org/dev">many other contributors</a>.<br />'.
  634. '<a href="http://docs.moodle.org/dev/License">GNU Public License</a>';
  635. //////////////////////////////////////////////////////////////////////////////////////////////////
  636. return $this->box($copyrighttext, 'copyright');
  637. }
  638. /**
  639. * Display a warning about installing development code if necesary.
  640. * @param int $maturity
  641. * @return string HTML to output.
  642. */
  643. protected function maturity_info($maturity) {
  644. if ($maturity == MATURITY_STABLE) {
  645. return ''; // No worries.
  646. }
  647. $level = 'warning';
  648. if ($maturity == MATURITY_ALPHA) {
  649. $level = 'danger';
  650. }
  651. $maturitylevel = get_string('maturity' . $maturity, 'admin');
  652. $warningtext = get_string('maturitycoreinfo', 'admin', $maturitylevel);
  653. $warningtext .= ' ' . $this->doc_link('admin/versions', get_string('morehelp'));
  654. return $this->warning($warningtext, $level);
  655. }
  656. /**
  657. * Displays the info about available Moodle core and plugin updates
  658. *
  659. * The structure of the $updates param has changed since 2.4. It contains not only updates
  660. * for the core itself, but also for all other installed plugins.
  661. *
  662. * @param array|null $updates array of (string)component => array of \core\update\info objects or null
  663. * @param int|null $fetch timestamp of the most recent updates fetch or null (unknown)
  664. * @return string
  665. */
  666. protected function available_updates($updates, $fetch) {
  667. $updateinfo = '';
  668. $someupdateavailable = false;
  669. if (is_array($updates)) {
  670. if (is_array($updates['core'])) {
  671. $someupdateavailable = true;
  672. $updateinfo .= $this->heading(get_string('updateavailable', 'core_admin'), 3);
  673. foreach ($updates['core'] as $update) {
  674. $updateinfo .= $this->moodle_available_update_info($update);
  675. }
  676. $updateinfo .= html_writer::tag('p', get_string('updateavailablerecommendation', 'core_admin'),
  677. array('class' => 'updateavailablerecommendation'));
  678. }
  679. unset($updates['core']);
  680. // If something has left in the $updates array now, it is updates for plugins.
  681. if (!empty($updates)) {
  682. $someupdateavailable = true;
  683. $updateinfo .= $this->heading(get_string('updateavailableforplugin', 'core_admin'), 3);
  684. $pluginsoverviewurl = new moodle_url('/admin/plugins.php', array('updatesonly' => 1));
  685. $updateinfo .= $this->container(get_string('pluginsoverviewsee', 'core_admin',
  686. array('url' => $pluginsoverviewurl->out())));
  687. }
  688. }
  689. if (!$someupdateavailable) {
  690. $now = time();
  691. if ($fetch and ($fetch <= $now) and ($now - $fetch < HOURSECS)) {
  692. $updateinfo .= $this->heading(get_string('updateavailablenot', 'core_admin'), 3);
  693. }
  694. }
  695. $updateinfo .= $this->container_start('checkforupdates mt-1');
  696. $fetchurl = new moodle_url('/admin/index.php', array('fetchupdates' => 1, 'sesskey' => sesskey(), 'cache' => 0));
  697. $updateinfo .= $this->single_button($fetchurl, get_string('checkforupdates', 'core_plugin'));
  698. if ($fetch) {
  699. $updateinfo .= $this->container(get_string('checkforupdateslast', 'core_plugin',
  700. userdate($fetch, get_string('strftimedatetime', 'core_langconfig'))));
  701. }
  702. $updateinfo .= $this->container_end();
  703. return $this->warning($updateinfo);
  704. }
  705. /**
  706. * Display a warning about not being registered on Moodle.org if necesary.
  707. *
  708. * @param boolean $registered true if the site is registered on Moodle.org
  709. * @return string HTML to output.
  710. */
  711. protected function registration_warning($registered) {
  712. if (!$registered && site_is_public()) {
  713. if (has_capability('moodle/site:config', context_system::instance())) {
  714. $registerbutton = $this->single_button(new moodle_url('/admin/registration/index.php'),
  715. get_string('register', 'admin'));
  716. $str = 'registrationwarning';
  717. } else {
  718. $registerbutton = '';
  719. $str = 'registrationwarningcontactadmin';
  720. }
  721. return $this->warning( get_string($str, 'admin')
  722. . '&nbsp;' . $this->help_icon('registration', 'admin') . $registerbutton ,
  723. 'error alert alert-danger');
  724. }
  725. return '';
  726. }
  727. /**
  728. * Return an admin page warning if site is not registered with moodle.org
  729. *
  730. * @return string
  731. */
  732. public function warn_if_not_registered() {
  733. return $this->registration_warning(\core\hub\registration::is_registered());
  734. }
  735. /**
  736. * Display a warning about the Mobile Web Services being disabled.
  737. *
  738. * @param boolean $mobileconfigured true if mobile web services are enabled
  739. * @return string HTML to output.
  740. */
  741. protected function mobile_configuration_warning($mobileconfigured) {
  742. $output = '';
  743. if (!$mobileconfigured) {
  744. $settingslink = new moodle_url('/admin/settings.php', ['section' => 'mobilesettings']);
  745. $configurebutton = $this->single_button($settingslink, get_string('enablemobilewebservice', 'admin'));
  746. $output .= $this->warning(get_string('mobilenotconfiguredwarning', 'admin') . '&nbsp;' . $configurebutton);
  747. }
  748. return $output;
  749. }
  750. /**
  751. * Display campaign content.
  752. *
  753. * @param bool $showcampaigncontent Whether the campaign content should be visible or not.
  754. * @return string the campaign content raw html.
  755. */
  756. protected function campaign_content(bool $showcampaigncontent): string {
  757. if (!$showcampaigncontent) {
  758. return '';
  759. }
  760. return $this->render_from_template('core/campaign_content', ['lang' => current_language()]);
  761. }
  762. /**
  763. * Display a warning about the forgotten password URL not linking to a valid URL.
  764. *
  765. * @param boolean $invalidforgottenpasswordurl true if the forgotten password URL is not valid
  766. * @return string HTML to output.
  767. */
  768. protected function forgotten_password_url_warning($invalidforgottenpasswordurl) {
  769. $output = '';
  770. if ($invalidforgottenpasswordurl) {
  771. $settingslink = new moodle_url('/admin/settings.php', ['section' => 'manageauths']);
  772. $configurebutton = $this->single_button($settingslink, get_string('check', 'moodle'));
  773. $output .= $this->warning(get_string('invalidforgottenpasswordurl', 'admin') . '&nbsp;' . $configurebutton,
  774. 'error alert alert-danger');
  775. }
  776. return $output;
  777. }
  778. /**
  779. * Helper method to render the information about the available Moodle update
  780. *
  781. * @param \core\update\info $updateinfo information about the available Moodle core update
  782. */
  783. protected function moodle_available_update_info(\core\update\info $updateinfo) {
  784. $boxclasses = 'moodleupdateinfo mb-2';
  785. $info = array();
  786. if (isset($updateinfo->release)) {
  787. $info[] = html_writer::tag('span', get_string('updateavailable_release', 'core_admin', $updateinfo->release),
  788. array('class' => 'info release'));
  789. }
  790. if (isset($updateinfo->version)) {
  791. $info[] = html_writer::tag('span', get_string('updateavailable_version', 'core_admin', $updateinfo->version),
  792. array('class' => 'info version'));
  793. }
  794. if (isset($updateinfo->maturity)) {
  795. $info[] = html_writer::tag('span', get_string('maturity'.$updateinfo->maturity, 'core_admin'),
  796. array('class' => 'info maturity'));
  797. $boxclasses .= ' maturity'.$updateinfo->maturity;
  798. }
  799. if (isset($updateinfo->download)) {
  800. $info[] = html_writer::link($updateinfo->download, get_string('download'),
  801. array('class' => 'info download btn btn-secondary'));
  802. }
  803. if (isset($updateinfo->url)) {
  804. $info[] = html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin'),
  805. array('class' => 'info more'));
  806. }
  807. $box = $this->output->container_start($boxclasses);
  808. $box .= $this->output->container(implode(html_writer::tag('span', ' | ', array('class' => 'separator')), $info), '');
  809. $box .= $this->output->container_end();
  810. return $box;
  811. }
  812. /**
  813. * Display a link to the release notes.
  814. * @return string HTML to output.
  815. */
  816. protected function release_notes_link() {
  817. $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/dev/Releases');
  818. $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
  819. return $this->box($releasenoteslink, 'generalbox alert alert-info');
  820. }
  821. /**
  822. * Display the reload link that appears on several upgrade/install pages.
  823. * @return string HTML to output.
  824. */
  825. function upgrade_reload($url) {
  826. return html_writer::empty_tag('br') .
  827. html_writer::tag('div',
  828. html_writer::link($url, $this->pix_icon('i/reload', '', '', array('class' => 'icon icon-pre')) .
  829. get_string('reload'), array('title' => get_string('reload'))),
  830. array('class' => 'continuebutton')) . html_writer::empty_tag('br');
  831. }
  832. /**
  833. * Displays all known plugins and information about their installation or upgrade
  834. *
  835. * This default implementation renders all plugins into one big table. The rendering
  836. * options support:
  837. * (bool)full = false: whether to display up-to-date plugins, too
  838. * (bool)xdep = false: display the plugins with unsatisified dependecies only
  839. *
  840. * @param core_plugin_manager $pluginman provides information about the plugins.
  841. * @param int $version the version of the Moodle code from version.php.
  842. * @param array $options rendering options
  843. * @return string HTML code
  844. */
  845. public function plugins_check_table(core_plugin_manager $pluginman, $version, array $options = array()) {
  846. global $CFG;
  847. $plugininfo = $pluginman->get_plugins();
  848. if (empty($plugininfo)) {
  849. return '';
  850. }
  851. $options['full'] = isset($options['full']) ? (bool)$options['full'] : false;
  852. $options['xdep'] = isset($options['xdep']) ? (bool)$options['xdep'] : false;
  853. $table = new html_table();
  854. $table->id = 'plugins-check';
  855. $table->head = array(
  856. get_string('displayname', 'core_plugin').' / '.get_string('rootdir', 'core_plugin'),
  857. get_string('versiondb', 'core_plugin'),
  858. get_string('versiondisk', 'core_plugin'),
  859. get_string('requires', 'core_plugin'),
  860. get_string('source', 'core_plugin').' / '.get_string('status', 'core_plugin'),
  861. );
  862. $table->colclasses = array(
  863. 'displayname', 'versiondb', 'versiondisk', 'requires', 'status',
  864. );
  865. $table->data = array();
  866. // Number of displayed plugins per type.
  867. $numdisplayed = array();
  868. // Number of plugins known to the plugin manager.
  869. $sumtotal = 0;
  870. // Number of plugins requiring attention.
  871. $sumattention = 0;
  872. // List of all components we can cancel installation of.
  873. $installabortable = $pluginman->list_cancellable_installations();
  874. // List of all components we can cancel upgrade of.
  875. $upgradeabortable = $pluginman->list_restorable_archives();
  876. foreach ($plugininfo as $type => $plugins) {
  877. $header = new html_table_cell($pluginman->plugintype_name_plural($type));
  878. $header->header = true;
  879. $header->colspan = count($table->head);
  880. $header = new html_table_row(array($header));
  881. $header->attributes['class'] = 'plugintypeheader type-' . $type;
  882. $numdisplayed[$type] = 0;
  883. if (empty($plugins) and $options['full']) {
  884. $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
  885. $msg->colspan = count($table->head);
  886. $row = new html_table_row(array($msg));
  887. $row->attributes['class'] .= 'msg msg-noneinstalled';
  888. $table->data[] = $header;
  889. $table->data[] = $row;
  890. continue;
  891. }
  892. $plugintyperows = array();
  893. foreach ($plugins as $name => $plugin) {
  894. $sumtotal++;
  895. $row = new html_table_row();
  896. $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
  897. if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name, null)) {
  898. $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
  899. } else {
  900. $icon = '';
  901. }
  902. $displayname = new html_table_cell(
  903. $icon.
  904. html_writer::span($plugin->displayname, 'pluginname').
  905. html_writer::div($plugin->get_dir(), 'plugindir text-muted small')
  906. );
  907. $versiondb = new html_table_cell($plugin->versiondb);
  908. $versiondisk = new html_table_cell($plugin->versiondisk);
  909. if ($isstandard = $plugin->is_standard()) {
  910. $row->attributes['class'] .= ' standard';
  911. $sourcelabel = html_writer::span(get_string('sourcestd', 'core_plugin'), 'sourcetext badge badge-secondary');
  912. } else {
  913. $row->attributes['class'] .= ' extension';
  914. $sourcelabel = html_writer::span(get_string('sourceext', 'core_plugin'), 'sourcetext badge badge-info');
  915. }
  916. $coredependency = $plugin->is_core_dependency_satisfied($version);
  917. $incompatibledependency = $plugin->is_core_compatible_satisfied($CFG->branch);
  918. $otherpluginsdependencies = $pluginman->are_dependencies_satisfied($plugin->get_other_required_plugins());
  919. $dependenciesok = $coredependency && $otherpluginsdependencies && $incompatibledependency;
  920. $statuscode = $plugin->get_status();
  921. $row->attributes['class'] .= ' status-' . $statuscode;
  922. $statusclass = 'statustext badge ';
  923. switch ($statuscode) {
  924. case core_plugin_manager::PLUGIN_STATUS_NEW:
  925. $statusclass .= $dependenciesok ? 'badge-success' : 'badge-warning';
  926. break;
  927. case core_plugin_manager::PLUGIN_STATUS_UPGRADE:
  928. $statusclass .= $dependenciesok ? 'badge-info' : 'badge-warning';
  929. break;
  930. case core_plugin_manager::PLUGIN_STATUS_MISSING:
  931. case core_plugin_manager::PLUGIN_STATUS_DOWNGRADE:
  932. case core_plugin_manager::PLUGIN_STATUS_DELETE:
  933. $statusclass .= 'badge-danger';
  934. break;
  935. case core_plugin_manager::PLUGIN_STATUS_NODB:
  936. case core_plugin_manager::PLUGIN_STATUS_UPTODATE:
  937. $statusclass .= $dependenciesok ? 'badge-light' : 'badge-warning';
  938. break;
  939. }
  940. $status = html_writer::span(get_string('status_' . $statuscode, 'core_plugin'), $statusclass);
  941. if (!empty($installabortable[$plugin->component])) {
  942. $status .= $this->output->single_button(
  943. new moodle_url($this->page->url, array('abortinstall' => $plugin->component, 'confirmplugincheck' => 0)),
  944. get_string('cancelinstallone', 'core_plugin'),
  945. 'post',
  946. array('class' => 'actionbutton cancelinstallone d-block mt-1')
  947. );
  948. }
  949. if (!empty($upgradeabortable[$plugin->component])) {
  950. $status .= $this->output->single_button(
  951. new moodle_url($this->page->url, array('abortupgrade' => $plugin->component)),
  952. get_string('cancelupgradeone', 'core_plugin'),
  953. 'post',
  954. array('class' => 'actionbutton cancelupgradeone d-block mt-1')
  955. );
  956. }
  957. $availableupdates = $plugin->available_updates();
  958. if (!empty($availableupdates)) {
  959. foreach ($availableupdates as $availableupdate) {
  960. $status .= $this->plugin_available_update_info($pluginman, $availableupdate);
  961. }
  962. }
  963. $status = new html_table_cell($sourcelabel.' '.$status);
  964. if ($plugin->pluginsupported != null) {
  965. $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version, $CFG->branch));
  966. } else {
  967. $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version));
  968. }
  969. $statusisboring = in_array($statuscode, array(
  970. core_plugin_manager::PLUGIN_STATUS_NODB, core_plugin_manager::PLUGIN_STATUS_UPTODATE));
  971. if ($options['xdep']) {
  972. // we want to see only plugins with failed dependencies
  973. if ($dependenciesok) {
  974. continue;
  975. }
  976. } else if ($statusisboring and $dependenciesok and empty($availableupdates)) {
  977. // no change is going to happen to the plugin - display it only
  978. // if the user wants to see the full list
  979. if (empty($options['full'])) {
  980. continue;
  981. }
  982. } else {
  983. $sumattention++;
  984. }
  985. // The plugin should be displayed.
  986. $numdisplayed[$type]++;
  987. $row->cells = array($displayname, $versiondb, $versiondisk, $requires, $status);
  988. $plugintyperows[] = $row;
  989. }
  990. if (empty($numdisplayed[$type]) and empty($options['full'])) {
  991. continue;
  992. }
  993. $table->data[] = $header;
  994. $table->data = array_merge($table->data, $plugintyperows);
  995. }
  996. // Total number of displayed plugins.
  997. $sumdisplayed = array_sum($numdisplayed);
  998. if ($options['xdep']) {
  999. // At the plugins dependencies check page, display the table only.
  1000. return html_writer::table($table);
  1001. }
  1002. $out = $this->output->container_start('', 'plugins-check-info');
  1003. if ($sumdisplayed == 0) {
  1004. $out .= $this->output->heading(get_string('pluginchecknone', 'core_plugin'));
  1005. } else {
  1006. if (empty($options['full'])) {
  1007. $out .= $this->output->heading(get_string('plugincheck…

Large files files are truncated, but you can click here to view the full file