PageRenderTime 79ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/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
  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('plugincheckattention', 'core_plugin'));
  1008. } else {
  1009. $out .= $this->output->heading(get_string('plugincheckall', 'core_plugin'));
  1010. }
  1011. }
  1012. $out .= $this->output->container_start('actions mb-2');
  1013. $installableupdates = $pluginman->filter_installable($pluginman->available_updates());
  1014. if ($installableupdates) {
  1015. $out .= $this->output->single_button(
  1016. new moodle_url($this->page->url, array('installupdatex' => 1)),
  1017. get_string('updateavailableinstallall', 'core_admin', count($installableupdates)),
  1018. 'post',
  1019. array('class' => 'singlebutton updateavailableinstallall mr-1')
  1020. );
  1021. }
  1022. if ($installabortable) {
  1023. $out .= $this->output->single_button(
  1024. new moodle_url($this->page->url, array('abortinstallx' => 1, 'confirmplugincheck' => 0)),
  1025. get_string('cancelinstallall', 'core_plugin', count($installabortable)),
  1026. 'post',
  1027. array('class' => 'singlebutton cancelinstallall mr-1')
  1028. );
  1029. }
  1030. if ($upgradeabortable) {
  1031. $out .= $this->output->single_button(
  1032. new moodle_url($this->page->url, array('abortupgradex' => 1)),
  1033. get_string('cancelupgradeall', 'core_plugin', count($upgradeabortable)),
  1034. 'post',
  1035. array('class' => 'singlebutton cancelupgradeall mr-1')
  1036. );
  1037. }
  1038. $out .= html_writer::div(html_writer::link(new moodle_url($this->page->url, array('showallplugins' => 0)),
  1039. get_string('plugincheckattention', 'core_plugin')).' '.html_writer::span($sumattention, 'badge badge-light'),
  1040. 'btn btn-link mr-1');
  1041. $out .= html_writer::div(html_writer::link(new moodle_url($this->page->url, array('showallplugins' => 1)),
  1042. get_string('plugincheckall', 'core_plugin')).' '.html_writer::span($sumtotal, 'badge badge-light'),
  1043. 'btn btn-link mr-1');
  1044. $out .= $this->output->container_end(); // End of .actions container.
  1045. $out .= $this->output->container_end(); // End of #plugins-check-info container.
  1046. if ($sumdisplayed > 0 or $options['full']) {
  1047. $out .= html_writer::table($table);
  1048. }
  1049. return $out;
  1050. }
  1051. /**
  1052. * Display the continue / cancel widgets for the plugins management pages.
  1053. *
  1054. * @param null|moodle_url $continue URL for the continue button, should it be displayed
  1055. * @param null|moodle_url $cancel URL for the cancel link, defaults to the current page
  1056. * @return string HTML
  1057. */
  1058. public function plugins_management_confirm_buttons(moodle_url $continue=null, moodle_url $cancel=null) {
  1059. $out = html_writer::start_div('plugins-management-confirm-buttons');
  1060. if (!empty($continue)) {
  1061. $out .= $this->output->single_button($continue, get_string('continue'), 'post', array('class' => 'continue'));
  1062. }
  1063. if (empty($cancel)) {
  1064. $cancel = $this->page->url;
  1065. }
  1066. $out .= html_writer::div(html_writer::link($cancel, get_string('cancel')), 'cancel');
  1067. return $out;
  1068. }
  1069. /**
  1070. * Displays the information about missing dependencies
  1071. *
  1072. * @param core_plugin_manager $pluginman
  1073. * @return string
  1074. */
  1075. protected function missing_dependencies(core_plugin_manager $pluginman) {
  1076. $dependencies = $pluginman->missing_dependencies();
  1077. if (empty($dependencies)) {
  1078. return '';
  1079. }
  1080. $available = array();
  1081. $unavailable = array();
  1082. $unknown = array();
  1083. foreach ($dependencies as $component => $remoteinfo) {
  1084. if ($remoteinfo === false) {
  1085. // The required version is not available. Let us check if there
  1086. // is at least some version in the plugins directory.
  1087. $remoteinfoanyversion = $pluginman->get_remote_plugin_info($component, ANY_VERSION, false);
  1088. if ($remoteinfoanyversion === false) {
  1089. $unknown[$component] = $component;
  1090. } else {
  1091. $unavailable[$component] = $remoteinfoanyversion;
  1092. }
  1093. } else {
  1094. $available[$component] = $remoteinfo;
  1095. }
  1096. }
  1097. $out = $this->output->container_start('plugins-check-dependencies mb-4');
  1098. if ($unavailable or $unknown) {
  1099. $out .= $this->output->heading(get_string('misdepsunavail', 'core_plugin'));
  1100. if ($unknown) {
  1101. $out .= $this->output->render((new \core\output\notification(get_string('misdepsunknownlist', 'core_plugin',
  1102. implode(', ', $unknown))))->set_show_closebutton(false));
  1103. }
  1104. if ($unavailable) {
  1105. $unavailablelist = array();
  1106. foreach ($unavailable as $component => $remoteinfoanyversion) {
  1107. $unavailablelistitem = html_writer::link('https://moodle.org/plugins/view.php?plugin='.$component,
  1108. '<strong>'.$remoteinfoanyversion->name.'</strong>');
  1109. if ($remoteinfoanyversion->version) {
  1110. $unavailablelistitem .= ' ('.$component.' &gt; '.$remoteinfoanyversion->version->version.')';
  1111. } else {
  1112. $unavailablelistitem .= ' ('.$component.')';
  1113. }
  1114. $unavailablelist[] = $unavailablelistitem;
  1115. }
  1116. $out .= $this->output->render((new \core\output\notification(get_string('misdepsunavaillist', 'core_plugin',
  1117. implode(', ', $unavailablelist))))->set_show_closebutton(false));
  1118. }
  1119. $out .= $this->output->container_start('plugins-check-dependencies-actions mb-4');
  1120. $out .= ' '.html_writer::link(new moodle_url('/admin/tool/installaddon/'),
  1121. get_string('dependencyuploadmissing', 'core_plugin'), array('class' => 'btn btn-secondary'));
  1122. $out .= $this->output->container_end(); // End of .plugins-check-dependencies-actions container.
  1123. }
  1124. if ($available) {
  1125. $out .= $this->output->heading(get_string('misdepsavail', 'core_plugin'));
  1126. $out .= $this->output->container_start('plugins-check-dependencies-actions mb-2');
  1127. $installable = $pluginman->filter_installable($available);
  1128. if ($installable) {
  1129. $out .= $this->output->single_button(
  1130. new moodle_url($this->page->url, array('installdepx' => 1)),
  1131. get_string('dependencyinstallmissing', 'core_plugin', count($installable)),
  1132. 'post',
  1133. array('class' => 'singlebutton dependencyinstallmissing d-inline-block mr-1')
  1134. );
  1135. }
  1136. $out .= html_writer::div(html_writer::link(new moodle_url('/admin/tool/installaddon/'),
  1137. get_string('dependencyuploadmissing', 'core_plugin'), array('class' => 'btn btn-link')),
  1138. 'dependencyuploadmissing d-inline-block mr-1');
  1139. $out .= $this->output->container_end(); // End of .plugins-check-dependencies-actions container.
  1140. $out .= $this->available_missing_dependencies_list($pluginman, $available);
  1141. }
  1142. $out .= $this->output->container_end(); // End of .plugins-check-dependencies container.
  1143. return $out;
  1144. }
  1145. /**
  1146. * Displays the list if available missing dependencies.
  1147. *
  1148. * @param core_plugin_manager $pluginman
  1149. * @param array $dependencies
  1150. * @return string
  1151. */
  1152. protected function available_missing_dependencies_list(core_plugin_manager $pluginman, array $dependencies) {
  1153. global $CFG;
  1154. $table = new html_table();
  1155. $table->id = 'plugins-check-available-dependencies';
  1156. $table->head = array(
  1157. get_string('displayname', 'core_plugin'),
  1158. get_string('release', 'core_plugin'),
  1159. get_string('version', 'core_plugin'),
  1160. get_string('supportedmoodleversions', 'core_plugin'),
  1161. get_string('info', 'core'),
  1162. );
  1163. $table->colclasses = array('displayname', 'release', 'version', 'supportedmoodleversions', 'info');
  1164. $table->data = array();
  1165. foreach ($dependencies as $plugin) {
  1166. $supportedmoodles = array();
  1167. foreach ($plugin->version->supportedmoodles as $moodle) {
  1168. if ($CFG->branch == str_replace('.', '', $moodle->release)) {
  1169. $supportedmoodles[] = html_writer::span($moodle->release, 'badge badge-success');
  1170. } else {
  1171. $supportedmoodles[] = html_writer::span($moodle->release, 'badge badge-light');
  1172. }
  1173. }
  1174. $requriedby = $pluginman->other_plugins_that_require($plugin->component);
  1175. if ($requriedby) {
  1176. foreach ($requriedby as $ix => $val) {
  1177. $inf = $pluginman->get_plugin_info($val);
  1178. if ($inf) {
  1179. $requriedby[$ix] = $inf->displayname.' ('.$inf->component.')';
  1180. }
  1181. }
  1182. $info = html_writer::div(
  1183. get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
  1184. 'requiredby mb-1'
  1185. );
  1186. } else {
  1187. $info = '';
  1188. }
  1189. $info .= $this->output->container_start('actions');
  1190. $info .= html_writer::div(
  1191. html_writer::link('https://moodle.org/plugins/view.php?plugin='.$plugin->component,
  1192. get_string('misdepinfoplugin', 'core_plugin')),
  1193. 'misdepinfoplugin d-inline-block mr-3 mb-1'
  1194. );
  1195. $info .= html_writer::div(
  1196. html_writer::link('https://moodle.org/plugins/pluginversion.php?id='.$plugin->version->id,
  1197. get_string('misdepinfoversion', 'core_plugin')),
  1198. 'misdepinfoversion d-inline-block mr-3 mb-1'
  1199. );
  1200. $info .= html_writer::div(html_writer::link($plugin->version->downloadurl, get_string('download')),
  1201. 'misdepdownload d-inline-block mr-3 mb-1');
  1202. if ($pluginman->is_remote_plugin_installable($plugin->component, $plugin->version->version, $reason)) {
  1203. $info .= $this->output->single_button(
  1204. new moodle_url($this->page->url, array('installdep' => $plugin->component)),
  1205. get_string('dependencyinstall', 'core_plugin'),
  1206. 'post',
  1207. array('class' => 'singlebutton dependencyinstall mr-3 mb-1')
  1208. );
  1209. } else {
  1210. $reasonhelp = $this->info_remote_plugin_not_installable($reason);
  1211. if ($reasonhelp) {
  1212. $info .= html_writer::div($reasonhelp, 'reasonhelp dependencyinstall d-inline-block mr-3 mb-1');
  1213. }
  1214. }
  1215. $info .= $this->output->container_end(); // End of .actions container.
  1216. $table->data[] = array(
  1217. html_writer::div($plugin->name, 'name').' '.html_writer::div($plugin->component, 'component text-muted small'),
  1218. $plugin->version->release,
  1219. $plugin->version->version,
  1220. implode(' ', $supportedmoodles),
  1221. $info
  1222. );
  1223. }
  1224. return html_writer::table($table);
  1225. }
  1226. /**
  1227. * Explain why {@link core_plugin_manager::is_remote_plugin_installable()} returned false.
  1228. *
  1229. * @param string $reason the reason code as returned by the plugin manager
  1230. * @return string
  1231. */
  1232. protected function info_remote_plugin_not_installable($reason) {
  1233. if ($reason === 'notwritableplugintype' or $reason === 'notwritableplugin') {
  1234. return $this->output->help_icon('notwritable', 'core_plugin', get_string('notwritable', 'core_plugin'));
  1235. }
  1236. if ($reason === 'remoteunavailable') {
  1237. return $this->output->help_icon('notdownloadable', 'core_plugin', get_string('notdownloadable', 'core_plugin'));
  1238. }
  1239. return false;
  1240. }
  1241. /**
  1242. * Formats the information that needs to go in the 'Requires' column.
  1243. * @param \core\plugininfo\base $plugin the plugin we are rendering the row for.
  1244. * @param core_plugin_manager $pluginman provides data on all the plugins.
  1245. * @param string $version
  1246. * @param int $branch the current Moodle branch
  1247. * @return string HTML code
  1248. */
  1249. protected function required_column(\core\plugininfo\base $plugin, core_plugin_manager $pluginman, $version, $branch = null) {
  1250. $requires = array();
  1251. $displayuploadlink = false;
  1252. $displayupdateslink = false;
  1253. $requirements = $pluginman->resolve_requirements($plugin, $version, $branch);
  1254. foreach ($requirements as $reqname => $reqinfo) {
  1255. if ($reqname === 'core') {
  1256. if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OK) {
  1257. $class = 'requires-ok text-muted';
  1258. $label = '';
  1259. } else {
  1260. $class = 'requires-failed';
  1261. $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'badge badge-danger');
  1262. }
  1263. if ($branch != null && !$plugin->is_core_compatible_satisfied($branch)) {
  1264. $requires[] = html_writer::tag('li',
  1265. html_writer::span(get_string('incompatibleversion', 'core_plugin', $branch), 'dep dep-core').
  1266. ' '.$label, array('class' => $class));
  1267. } else if ($branch != null && $plugin->pluginsupported != null) {
  1268. $requires[] = html_writer::tag('li',
  1269. html_writer::span(get_string('moodlebranch', 'core_plugin',
  1270. array('min' => $plugin->pluginsupported[0], 'max' => $plugin->pluginsupported[1])), 'dep dep-core').
  1271. ' '.$label, array('class' => $class));
  1272. } else if ($reqinfo->reqver != ANY_VERSION) {
  1273. $requires[] = html_writer::tag('li',
  1274. html_writer::span(get_string('moodleversion', 'core_plugin', $plugin->versionrequires), 'dep dep-core').
  1275. ' '.$label, array('class' => $class));
  1276. }
  1277. } else {
  1278. $actions = array();
  1279. if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OK) {
  1280. $label = '';
  1281. $class = 'requires-ok text-muted';
  1282. } else if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_MISSING) {
  1283. if ($reqinfo->availability == $pluginman::REQUIREMENT_AVAILABLE) {
  1284. $label = html_writer::span(get_string('dependencymissing', 'core_plugin'), 'badge badge-warning');
  1285. $label .= ' '.html_writer::span(get_string('dependencyavailable', 'core_plugin'), 'badge badge-warning');
  1286. $class = 'requires-failed requires-missing requires-available';
  1287. $actions[] = html_writer::link(
  1288. new moodle_url('https://moodle.org/plugins/view.php', array('plugin' => $reqname)),
  1289. get_string('misdepinfoplugin', 'core_plugin')
  1290. );
  1291. } else {
  1292. $label = html_writer::span(get_string('dependencymissing', 'core_plugin'), 'badge badge-danger');
  1293. $label .= ' '.html_writer::span(get_string('dependencyunavailable', 'core_plugin'),
  1294. 'badge badge-danger');
  1295. $class = 'requires-failed requires-missing requires-unavailable';
  1296. }
  1297. $displayuploadlink = true;
  1298. } else if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OUTDATED) {
  1299. if ($reqinfo->availability == $pluginman::REQUIREMENT_AVAILABLE) {
  1300. $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'badge badge-warning');
  1301. $label .= ' '.html_writer::span(get_string('dependencyavailable', 'core_plugin'), 'badge badge-warning');
  1302. $class = 'requires-failed requires-outdated requires-available';
  1303. $displayupdateslink = true;
  1304. } else {
  1305. $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'badge badge-danger');
  1306. $label .= ' '.html_writer::span(get_string('dependencyunavailable', 'core_plugin'),
  1307. 'badge badge-danger');
  1308. $class = 'requires-failed requires-outdated requires-unavailable';
  1309. }
  1310. $displayuploadlink = true;
  1311. }
  1312. if ($reqinfo->reqver != ANY_VERSION) {
  1313. $str = 'otherpluginversion';
  1314. } else {
  1315. $str = 'otherplugin';
  1316. }
  1317. $requires[] = html_writer::tag('li', html_writer::span(
  1318. get_string($str, 'core_plugin', array('component' => $reqname, 'version' => $reqinfo->reqver)),
  1319. 'dep dep-plugin').' '.$label.' '.html_writer::span(implode(' | ', $actions), 'actions'),
  1320. array('class' => $class)
  1321. );
  1322. }
  1323. }
  1324. if (!$requires) {
  1325. return '';
  1326. }
  1327. $out = html_writer::tag('ul', implode("\n", $requires), array('class' => 'm-0'));
  1328. if ($displayuploadlink) {
  1329. $out .= html_writer::div(
  1330. html_writer::link(
  1331. new moodle_url('/admin/tool/installaddon/'),
  1332. get_string('dependencyuploadmissing', 'core_plugin'),
  1333. array('class' => 'btn btn-secondary btn-sm m-1')
  1334. ),
  1335. 'dependencyuploadmissing'
  1336. );
  1337. }
  1338. if ($displayupdateslink) {
  1339. $out .= html_writer::div(
  1340. html_writer::link(
  1341. new moodle_url($this->page->url, array('sesskey' => sesskey(), 'fetchupdates' => 1)),
  1342. get_string('checkforupdates', 'core_plugin'),
  1343. array('class' => 'btn btn-secondary btn-sm m-1')
  1344. ),
  1345. 'checkforupdates'
  1346. );
  1347. }
  1348. // Check if supports is present, and $branch is not in, only if $incompatible check was ok.
  1349. if ($plugin->pluginsupported != null && $class == 'requires-ok' && $branch != null) {
  1350. if ($pluginman->check_explicitly_supported($plugin, $branch) == $pluginman::VERSION_NOT_SUPPORTED) {
  1351. $out .= html_writer::div(get_string('notsupported', 'core_plugin', $branch));
  1352. }
  1353. }
  1354. return $out;
  1355. }
  1356. /**
  1357. * Prints an overview about the plugins - number of installed, number of extensions etc.
  1358. *
  1359. * @param core_plugin_manager $pluginman provides information about the plugins
  1360. * @param array $options filtering options
  1361. * @return string as usually
  1362. */
  1363. public function plugins_overview_panel(core_plugin_manager $pluginman, array $options = array()) {
  1364. $plugininfo = $pluginman->get_plugins();
  1365. $numtotal = $numextension = $numupdatable = $numinstallable = 0;
  1366. foreach ($plugininfo as $type => $plugins) {
  1367. foreach ($plugins as $name => $plugin) {
  1368. if ($res = $plugin->available_updates()) {
  1369. $numupdatable++;
  1370. foreach ($res as $updateinfo) {
  1371. if ($pluginman->is_remote_plugin_installable($updateinfo->component, $updateinfo->version, $reason, false)) {
  1372. $numinstallable++;
  1373. break;
  1374. }
  1375. }
  1376. }
  1377. if ($plugin->get_status() === core_plugin_manager::PLUGIN_STATUS_MISSING) {
  1378. continue;
  1379. }
  1380. $numtotal++;
  1381. if (!$plugin->is_standard()) {
  1382. $numextension++;
  1383. }
  1384. }
  1385. }
  1386. $infoall = html_writer::link(
  1387. new moodle_url($this->page->url, array('contribonly' => 0, 'updatesonly' => 0)),
  1388. get_string('overviewall', 'core_plugin'),
  1389. array('title' => get_string('filterall', 'core_plugin'))
  1390. ).' '.html_writer::span($numtotal, 'badge number number-all');
  1391. $infoext = html_writer::link(
  1392. new moodle_url($this->page->url, array('contribonly' => 1, 'updatesonly' => 0)),
  1393. get_string('overviewext', 'core_plugin'),
  1394. array('title' => get_string('filtercontribonly', 'core_plugin'))
  1395. ).' '.html_writer::span($numextension, 'badge number number-additional');
  1396. if ($numupdatable) {
  1397. $infoupdatable = html_writer::link(
  1398. new moodle_url($this->page->url, array('contribonly' => 0, 'updatesonly' => 1)),
  1399. get_string('overviewupdatable', 'core_plugin'),
  1400. array('title' => get_string('filterupdatesonly', 'core_plugin'))
  1401. ).' '.html_writer::span($numupdatable, 'badge badge-info number number-updatable');
  1402. } else {
  1403. // No updates, or the notifications disabled.
  1404. $infoupdatable = '';
  1405. }
  1406. $out = html_writer::start_div('', array('id' => 'plugins-overview-panel'));
  1407. if (!empty($options['updatesonly'])) {
  1408. $out .= $this->output->heading(get_string('overviewupdatable', 'core_plugin'), 3);
  1409. } else if (!empty($options['contribonly'])) {
  1410. $out .= $this->output->heading(get_string('overviewext', 'core_plugin'), 3);
  1411. }
  1412. if ($numinstallable) {
  1413. $out .= $this->output->single_button(
  1414. new moodle_url($this->page->url, array('installupdatex' => 1)),
  1415. get_string('updateavailableinstallall', 'core_admin', $numinstallable),
  1416. 'post',
  1417. array('class' => 'singlebutton updateavailableinstallall')
  1418. );
  1419. }
  1420. $out .= html_writer::div($infoall, 'info info-all').
  1421. html_writer::div($infoext, 'info info-ext').
  1422. html_writer::div($infoupdatable, 'info info-updatable');
  1423. $out .= html_writer::end_div(); // End of #plugins-overview-panel block.
  1424. return $out;
  1425. }
  1426. /**
  1427. * Displays all known plugins and links to manage them
  1428. *
  1429. * This default implementation renders all plugins into one big table.
  1430. *
  1431. * @param core_plugin_manager $pluginman provides information about the plugins.
  1432. * @param array $options filtering options
  1433. * @return string HTML code
  1434. */
  1435. public function plugins_control_panel(core_plugin_manager $pluginman, array $options = array()) {
  1436. $plugininfo = $pluginman->get_plugins();
  1437. // Filter the list of plugins according the options.
  1438. if (!empty($options['updatesonly'])) {
  1439. $updateable = array();
  1440. foreach ($plugininfo as $plugintype => $pluginnames) {
  1441. foreach ($pluginnames as $pluginname => $pluginfo) {
  1442. $pluginavailableupdates = $pluginfo->available_updates();
  1443. if (!empty($pluginavailableupdates)) {
  1444. foreach ($pluginavailableupdates as $pluginavailableupdate) {
  1445. $updateable[$plugintype][$pluginname] = $pluginfo;
  1446. }
  1447. }
  1448. }
  1449. }
  1450. $plugininfo = $updateable;
  1451. }
  1452. if (!empty($options['contribonly'])) {
  1453. $contribs = array();
  1454. foreach ($plugininfo as $plugintype => $pluginnames) {
  1455. foreach ($pluginnames as $pluginname => $pluginfo) {
  1456. if (!$pluginfo->is_standard()) {
  1457. $contribs[$plugintype][$pluginname] = $pluginfo;
  1458. }
  1459. }
  1460. }
  1461. $plugininfo = $contribs;
  1462. }
  1463. if (empty($plugininfo)) {
  1464. return '';
  1465. }
  1466. $table = new html_table();
  1467. $table->id = 'plugins-control-panel';
  1468. $table->head = array(
  1469. get_string('displayname', 'core_plugin'),
  1470. get_string('version', 'core_plugin'),
  1471. get_string('availability', 'core_plugin'),
  1472. get_string('actions', 'core_plugin'),
  1473. get_string('notes','core_plugin'),
  1474. );
  1475. $table->headspan = array(1, 1, 1, 2, 1);
  1476. $table->colclasses = array(
  1477. 'pluginname', 'version', 'availability', 'settings', 'uninstall', 'notes'
  1478. );
  1479. foreach ($plugininfo as $type => $plugins) {
  1480. $heading = $pluginman->plugintype_name_plural($type);
  1481. $pluginclass = core_plugin_manager::resolve_plugininfo_class($type);
  1482. if ($manageurl = $pluginclass::get_manage_url()) {
  1483. $heading .= $this->output->action_icon($manageurl, new pix_icon('i/settings',
  1484. get_string('settings', 'core_plugin')));
  1485. }
  1486. $header = new html_table_cell(html_writer::tag('span', $heading, array('id'=>'plugin_type_cell_'.$type)));
  1487. $header->header = true;
  1488. $header->colspan = array_sum($table->headspan);
  1489. $header = new html_table_row(array($header));
  1490. $header->attributes['class'] = 'plugintypeheader type-' . $type;
  1491. $table->data[] = $header;
  1492. if (empty($plugins)) {
  1493. $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
  1494. $msg->colspan = array_sum($table->headspan);
  1495. $row = new html_table_row(array($msg));
  1496. $row->attributes['class'] .= 'msg msg-noneinstalled';
  1497. $table->data[] = $row;
  1498. continue;
  1499. }
  1500. foreach ($plugins as $name => $plugin) {
  1501. $row = new html_table_row();
  1502. $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
  1503. if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name, null)) {
  1504. $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'icon pluginicon'));
  1505. } else {
  1506. $icon = $this->output->spacer();
  1507. }
  1508. $status = $plugin->get_status();
  1509. $row->attributes['class'] .= ' status-'.$status;
  1510. $pluginname = html_writer::tag('div', $icon.$plugin->displayname, array('class' => 'displayname')).
  1511. html_writer::tag('div', $plugin->component, array('class' => 'componentname'));
  1512. $pluginname = new html_table_cell($pluginname);
  1513. $version = html_writer::div($plugin->versiondb, 'versionnumber');
  1514. if ((string)$plugin->release !== '') {
  1515. $version = html_writer::div($plugin->release, 'release').$version;
  1516. }
  1517. $version = new html_table_cell($version);
  1518. $isenabled = $plugin->is_enabled();
  1519. if (is_null($isenabled)) {
  1520. $availability = new html_table_cell('');
  1521. } else if ($isenabled) {
  1522. $row->attributes['class'] .= ' enabled';
  1523. $availability = new html_table_cell(get_string('pluginenabled', 'core_plugin'));
  1524. } else {
  1525. $row->attributes['class'] .= ' disabled';
  1526. $availability = new html_table_cell(get_string('plugindisabled', 'core_plugin'));
  1527. }
  1528. $settingsurl = $plugin->get_settings_url();
  1529. if (!is_null($settingsurl)) {
  1530. $settings = html_writer::link($settingsurl, get_string('settings', 'core_plugin'), array('class' => 'settings'));
  1531. } else {
  1532. $settings = '';
  1533. }
  1534. $settings = new html_table_cell($settings);
  1535. if ($uninstallurl = $pluginman->get_uninstall_url($plugin->component, 'overview')) {
  1536. $uninstall = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin'));
  1537. } else {
  1538. $uninstall = '';
  1539. }
  1540. $uninstall = new html_table_cell($uninstall);
  1541. if ($plugin->is_standard()) {
  1542. $row->attributes['class'] .= ' standard';
  1543. $source = '';
  1544. } else {
  1545. $row->attributes['class'] .= ' extension';
  1546. $source = html_writer::div(get_string('sourceext', 'core_plugin'), 'source badge badge-info');
  1547. }
  1548. if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) {
  1549. $msg = html_writer::div(get_string('status_missing', 'core_plugin'), 'statusmsg badge badge-danger');
  1550. } else if ($status === core_plugin_manager::PLUGIN_STATUS_NEW) {
  1551. $msg = html_writer::div(get_string('status_new', 'core_plugin'), 'statusmsg badge badge-success');
  1552. } else {
  1553. $msg = '';
  1554. }
  1555. $requriedby = $pluginman->other_plugins_that_require($plugin->component);
  1556. if ($requriedby) {
  1557. $requiredby = html_writer::tag('div', get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
  1558. array('class' => 'requiredby'));
  1559. } else {
  1560. $requiredby = '';
  1561. }
  1562. $updateinfo = '';
  1563. if (is_array($plugin->available_updates())) {
  1564. foreach ($plugin->available_updates() as $availableupdate) {
  1565. $updateinfo .= $this->plugin_available_update_info($pluginman, $availableupdate);
  1566. }
  1567. }
  1568. $notes = new html_table_cell($source.$msg.$requiredby.$updateinfo);
  1569. $row->cells = array(
  1570. $pluginname, $version, $availability, $settings, $uninstall, $notes
  1571. );
  1572. $table->data[] = $row;
  1573. }
  1574. }
  1575. return html_writer::table($table);
  1576. }
  1577. /**
  1578. * Helper method to render the information about the available plugin update
  1579. *
  1580. * @param core_plugin_manager $pluginman plugin manager instance
  1581. * @param \core\update\info $updateinfo information about the available update for the plugin
  1582. */
  1583. protected function plugin_available_update_info(core_plugin_manager $pluginman, \core\update\info $updateinfo) {
  1584. $boxclasses = 'pluginupdateinfo';
  1585. $info = array();
  1586. if (isset($updateinfo->release)) {
  1587. $info[] = html_writer::div(
  1588. get_string('updateavailable_release', 'core_plugin', $updateinfo->release),
  1589. 'info release'
  1590. );
  1591. }
  1592. if (isset($updateinfo->maturity)) {
  1593. $info[] = html_writer::div(
  1594. get_string('maturity'.$updateinfo->maturity, 'core_admin'),
  1595. 'info maturity'
  1596. );
  1597. $boxclasses .= ' maturity'.$updateinfo->maturity;
  1598. }
  1599. if (isset($updateinfo->download)) {
  1600. $info[] = html_writer::div(
  1601. html_writer::link($updateinfo->download, get_string('download')),
  1602. 'info download'
  1603. );
  1604. }
  1605. if (isset($updateinfo->url)) {
  1606. $info[] = html_writer::div(
  1607. html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin')),
  1608. 'info more'
  1609. );
  1610. }
  1611. $box = html_writer::start_div($boxclasses);
  1612. $box .= html_writer::div(
  1613. get_string('updateavailable', 'core_plugin', $updateinfo->version),
  1614. 'version'
  1615. );
  1616. $box .= html_writer::div(
  1617. implode(html_writer::span(' ', 'separator'), $info),
  1618. 'infos'
  1619. );
  1620. if ($pluginman->is_remote_plugin_installable($updateinfo->component, $updateinfo->version, $reason, false)) {
  1621. $box .= $this->output->single_button(
  1622. new moodle_url($this->page->url, array('installupdate' => $updateinfo->component,
  1623. 'installupdateversion' => $updateinfo->version)),
  1624. get_string('updateavailableinstall', 'core_admin'),
  1625. 'post',
  1626. array('class' => 'singlebutton updateavailableinstall')
  1627. );
  1628. } else {
  1629. $reasonhelp = $this->info_remote_plugin_not_installable($reason);
  1630. if ($reasonhelp) {
  1631. $box .= html_writer::div($reasonhelp, 'reasonhelp updateavailableinstall');
  1632. }
  1633. }
  1634. $box .= html_writer::end_div();
  1635. return $box;
  1636. }
  1637. /**
  1638. * This function will render one beautiful table with all the environmental
  1639. * configuration and how it suits Moodle needs.
  1640. *
  1641. * @param boolean $result final result of the check (true/false)
  1642. * @param environment_results[] $environment_results array of results gathered
  1643. * @return string HTML to output.
  1644. */
  1645. public function environment_check_table($result, $environment_results) {
  1646. global $CFG;
  1647. // Table headers
  1648. $servertable = new html_table();//table for server checks
  1649. $servertable->head = array(
  1650. get_string('name'),
  1651. get_string('info'),
  1652. get_string('report'),
  1653. get_string('plugin'),
  1654. get_string('status'),
  1655. );
  1656. $servertable->colclasses = array('centeralign name', 'centeralign info', 'leftalign report', 'leftalign plugin', 'centeralign status');
  1657. $servertable->attributes['class'] = 'admintable environmenttable generaltable table-sm';
  1658. $servertable->id = 'serverstatus';
  1659. $serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
  1660. $othertable = new html_table();//table for custom checks
  1661. $othertable->head = array(
  1662. get_string('info'),
  1663. get_string('report'),
  1664. get_string('plugin'),
  1665. get_string('status'),
  1666. );
  1667. $othertable->colclasses = array('aligncenter info', 'alignleft report', 'alignleft plugin', 'aligncenter status');
  1668. $othertable->attributes['class'] = 'admintable environmenttable generaltable table-sm';
  1669. $othertable->id = 'otherserverstatus';
  1670. $otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
  1671. // Iterate over each environment_result
  1672. $continue = true;
  1673. foreach ($environment_results as $environment_result) {
  1674. $errorline = false;
  1675. $warningline = false;
  1676. $stringtouse = '';
  1677. if ($continue) {
  1678. $type = $environment_result->getPart();
  1679. $info = $environment_result->getInfo();
  1680. $status = $environment_result->getStatus();
  1681. $plugin = $environment_result->getPluginName();
  1682. $error_code = $environment_result->getErrorCode();
  1683. // Process Report field
  1684. $rec = new stdClass();
  1685. // Something has gone wrong at parsing time
  1686. if ($error_code) {
  1687. $stringtouse = 'environmentxmlerror';
  1688. $rec->error_code = $error_code;
  1689. $status = get_string('error');
  1690. $errorline = true;
  1691. $continue = false;
  1692. }
  1693. if ($continue) {
  1694. if ($rec->needed = $environment_result->getNeededVersion()) {
  1695. // We are comparing versions
  1696. $rec->current = $environment_result->getCurrentVersion();
  1697. if ($environment_result->getLevel() == 'required') {
  1698. $stringtouse = 'environmentrequireversion';
  1699. } else {
  1700. $stringtouse = 'environmentrecommendversion';
  1701. }
  1702. } else if ($environment_result->getPart() == 'custom_check') {
  1703. // We are checking installed & enabled things
  1704. if ($environment_result->getLevel() == 'required') {
  1705. $stringtouse = 'environmentrequirecustomcheck';
  1706. } else {
  1707. $stringtouse = 'environmentrecommendcustomcheck';
  1708. }
  1709. } else if ($environment_result->getPart() == 'php_setting') {
  1710. if ($status) {
  1711. $stringtouse = 'environmentsettingok';
  1712. } else if ($environment_result->getLevel() == 'required') {
  1713. $stringtouse = 'environmentmustfixsetting';
  1714. } else {
  1715. $stringtouse = 'environmentshouldfixsetting';
  1716. }
  1717. } else {
  1718. if ($environment_result->getLevel() == 'required') {
  1719. $stringtouse = 'environmentrequireinstall';
  1720. } else {
  1721. $stringtouse = 'environmentrecommendinstall';
  1722. }
  1723. }
  1724. // Calculate the status value
  1725. if ($environment_result->getBypassStr() != '') { //Handle bypassed result (warning)
  1726. $status = get_string('bypassed');
  1727. $warningline = true;
  1728. } else if ($environment_result->getRestrictStr() != '') { //Handle restricted result (error)
  1729. $status = get_string('restricted');
  1730. $errorline = true;
  1731. } else {
  1732. if ($status) { //Handle ok result (ok)
  1733. $status = get_string('ok');
  1734. } else {
  1735. if ($environment_result->getLevel() == 'optional') {//Handle check result (warning)
  1736. $status = get_string('check');
  1737. $warningline = true;
  1738. } else { //Handle error result (error)
  1739. $status = get_string('check');
  1740. $errorline = true;
  1741. }
  1742. }
  1743. }
  1744. }
  1745. // Build the text
  1746. $linkparts = array();
  1747. $linkparts[] = 'admin/environment';
  1748. $linkparts[] = $type;
  1749. if (!empty($info)){
  1750. $linkparts[] = $info;
  1751. }
  1752. // Plugin environments do not have docs pages yet.
  1753. if (empty($CFG->docroot) or $environment_result->plugin) {
  1754. $report = get_string($stringtouse, 'admin', $rec);
  1755. } else {
  1756. $report = $this->doc_link(join('/', $linkparts), get_string($stringtouse, 'admin', $rec), true);
  1757. }
  1758. // Enclose report text in div so feedback text will be displayed underneath it.
  1759. $report = html_writer::div($report);
  1760. // Format error or warning line
  1761. if ($errorline) {
  1762. $messagetype = 'error';
  1763. $statusclass = 'badge-danger';
  1764. } else if ($warningline) {
  1765. $messagetype = 'warn';
  1766. $statusclass = 'badge-warning';
  1767. } else {
  1768. $messagetype = 'ok';
  1769. $statusclass = 'badge-success';
  1770. }
  1771. $status = html_writer::span($status, 'badge ' . $statusclass);
  1772. // Here we'll store all the feedback found
  1773. $feedbacktext = '';
  1774. // Append the feedback if there is some
  1775. $feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), $messagetype);
  1776. //Append the bypass if there is some
  1777. $feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'warn');
  1778. //Append the restrict if there is some
  1779. $feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'error');
  1780. $report .= $feedbacktext;
  1781. // Add the row to the table
  1782. if ($environment_result->getPart() == 'custom_check'){
  1783. $otherdata[$messagetype][] = array ($info, $report, $plugin, $status);
  1784. } else {
  1785. $serverdata[$messagetype][] = array ($type, $info, $report, $plugin, $status);
  1786. }
  1787. }
  1788. }
  1789. //put errors first in
  1790. $servertable->data = array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']);
  1791. $othertable->data = array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']);
  1792. // Print table
  1793. $output = '';
  1794. $output .= $this->heading(get_string('serverchecks', 'admin'));
  1795. $output .= html_writer::table($servertable);
  1796. if (count($othertable->data)){
  1797. $output .= $this->heading(get_string('customcheck', 'admin'));
  1798. $output .= html_writer::table($othertable);
  1799. }
  1800. // Finally, if any error has happened, print the summary box
  1801. if (!$result) {
  1802. $output .= $this->box(get_string('environmenterrortodo', 'admin'), 'environmentbox errorbox');
  1803. }
  1804. return $output;
  1805. }
  1806. /**
  1807. * Render a simple page for providing the upgrade key.
  1808. *
  1809. * @param moodle_url|string $url
  1810. * @return string
  1811. */
  1812. public function upgradekey_form_page($url) {
  1813. $output = '';
  1814. $output .= $this->header();
  1815. $output .= $this->container_start('upgradekeyreq');
  1816. $output .= $this->heading(get_string('upgradekeyreq', 'core_admin'));
  1817. $output .= html_writer::start_tag('form', array('method' => 'POST', 'action' => $url));
  1818. $output .= html_writer::empty_tag('input', [
  1819. 'name' => 'upgradekey',
  1820. 'type' => 'password',
  1821. 'class' => 'form-control w-auto',
  1822. ]);
  1823. $output .= html_writer::empty_tag('input', [
  1824. 'type' => 'submit',
  1825. 'value' => get_string('submit'),
  1826. 'class' => 'btn btn-primary mt-3',
  1827. ]);
  1828. $output .= html_writer::end_tag('form');
  1829. $output .= $this->container_end();
  1830. $output .= $this->footer();
  1831. return $output;
  1832. }
  1833. /**
  1834. * Check to see if writing to the deprecated legacy log store is enabled.
  1835. *
  1836. * @return string An error message if writing to the legacy log store is enabled.
  1837. */
  1838. protected function legacy_log_store_writing_error() {
  1839. $enabled = get_config('logstore_legacy', 'loglegacy');
  1840. $plugins = explode(',', get_config('tool_log', 'enabled_stores'));
  1841. $enabled = $enabled && in_array('logstore_legacy', $plugins);
  1842. if ($enabled) {
  1843. return $this->warning(get_string('legacylogginginuse'));
  1844. }
  1845. }
  1846. /**
  1847. * Display message about the benefits of registering on Moodle.org
  1848. *
  1849. * @return string
  1850. */
  1851. public function moodleorg_registration_message() {
  1852. $out = format_text(get_string('registerwithmoodleorginfo', 'core_hub'), FORMAT_MARKDOWN);
  1853. $out .= html_writer::link(
  1854. new moodle_url('/admin/settings.php', ['section' => 'moodleservices']),
  1855. $this->output->pix_icon('i/info', '').' '.get_string('registerwithmoodleorginfoapp', 'core_hub'),
  1856. ['class' => 'btn btn-link', 'role' => 'opener', 'target' => '_href']
  1857. );
  1858. $out .= html_writer::link(
  1859. HUB_MOODLEORGHUBURL,
  1860. $this->output->pix_icon('i/stats', '').' '.get_string('registerwithmoodleorginfostats', 'core_hub'),
  1861. ['class' => 'btn btn-link', 'role' => 'opener', 'target' => '_href']
  1862. );
  1863. $out .= html_writer::link(
  1864. HUB_MOODLEORGHUBURL.'/sites',
  1865. $this->output->pix_icon('i/location', '').' '.get_string('registerwithmoodleorginfosites', 'core_hub'),
  1866. ['class' => 'btn btn-link', 'role' => 'opener', 'target' => '_href']
  1867. );
  1868. return $this->output->box($out);
  1869. }
  1870. /**
  1871. * Display message about benefits of enabling the user feedback feature.
  1872. *
  1873. * @param bool $showfeedbackencouragement Whether the encouragement content should be displayed or not
  1874. * @return string
  1875. */
  1876. protected function userfeedback_encouragement(bool $showfeedbackencouragement): string {
  1877. $output = '';
  1878. if ($showfeedbackencouragement) {
  1879. $settingslink = new moodle_url('/admin/settings.php', ['section' => 'userfeedback']);
  1880. $output .= $this->warning(get_string('userfeedbackencouragement', 'admin', $settingslink->out()), 'info');
  1881. }
  1882. return $output;
  1883. }
  1884. }