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

/admin/renderer.php

https://bitbucket.org/kudutest1/moodlegit
PHP | 1183 lines | 717 code | 192 blank | 274 comment | 104 complexity | 66ec07df5e4c32b88e65662a21430803 MD5 | raw 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. require_once($CFG->libdir . '/pluginlib.php');
  26. /**
  27. * Standard HTML output renderer for core_admin subsystem
  28. */
  29. class core_admin_renderer extends plugin_renderer_base {
  30. /**
  31. * Display the 'Do you acknowledge the terms of the GPL' page. The first page
  32. * during install.
  33. * @return string HTML to output.
  34. */
  35. public function install_licence_page() {
  36. global $CFG;
  37. $output = '';
  38. $copyrightnotice = text_to_html(get_string('gpl3'));
  39. $copyrightnotice = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $copyrightnotice); // extremely ugly validation hack
  40. $continue = new single_button(new moodle_url('/admin/index.php', array('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('/admin/index.php', 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('/admin/index.php', array('agreelicense'=>1, 'confirmrelease'=>1, 'lang'=>$CFG->lang)));
  89. }
  90. $output .= $this->footer();
  91. return $output;
  92. }
  93. /**
  94. * Displays the list of plugins with unsatisfied dependencies
  95. *
  96. * @param double|string|int $version Moodle on-disk version
  97. * @param array $failed list of plugins with unsatisfied dependecies
  98. * @param moodle_url $reloadurl URL of the page to recheck the dependencies
  99. * @return string HTML
  100. */
  101. public function unsatisfied_dependencies_page($version, array $failed, moodle_url $reloadurl) {
  102. $output = '';
  103. $output .= $this->header();
  104. $output .= $this->heading(get_string('pluginscheck', 'admin'));
  105. $output .= $this->warning(get_string('pluginscheckfailed', 'admin', array('pluginslist' => implode(', ', array_unique($failed)))));
  106. $output .= $this->plugins_check_table(plugin_manager::instance(), $version, array('xdep' => true));
  107. $output .= $this->warning(get_string('pluginschecktodo', 'admin'));
  108. $output .= $this->continue_button($reloadurl);
  109. $output .= $this->footer();
  110. return $output;
  111. }
  112. /**
  113. * Display the 'You are about to upgrade Moodle' page. The first page
  114. * during upgrade.
  115. * @param string $strnewversion
  116. * @param int $maturity
  117. * @return string HTML to output.
  118. */
  119. public function upgrade_confirm_page($strnewversion, $maturity) {
  120. $output = '';
  121. $continueurl = new moodle_url('index.php', array('confirmupgrade' => 1));
  122. $cancelurl = new moodle_url('index.php');
  123. $output .= $this->header();
  124. $output .= $this->maturity_warning($maturity);
  125. $output .= $this->confirm(get_string('upgradesure', 'admin', $strnewversion), $continueurl, $cancelurl);
  126. $output .= $this->footer();
  127. return $output;
  128. }
  129. /**
  130. * Display the environment page during the upgrade process.
  131. * @param string $release
  132. * @param boolean $envstatus final result of env check (true/false)
  133. * @param array $environment_results array of results gathered
  134. * @return string HTML to output.
  135. */
  136. public function upgrade_environment_page($release, $envstatus, $environment_results) {
  137. global $CFG;
  138. $output = '';
  139. $output .= $this->header();
  140. $output .= $this->heading("Moodle $release");
  141. $output .= $this->release_notes_link();
  142. $output .= $this->environment_check_table($envstatus, $environment_results);
  143. if (!$envstatus) {
  144. $output .= $this->upgrade_reload(new moodle_url('/admin/index.php'), array('confirmupgrade' => 1));
  145. } else {
  146. $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
  147. if (empty($CFG->skiplangupgrade) and current_language() !== 'en') {
  148. $output .= $this->box(get_string('langpackwillbeupdated', 'admin'), 'generalbox', 'notice');
  149. }
  150. $output .= $this->continue_button(new moodle_url('/admin/index.php', array('confirmupgrade' => 1, 'confirmrelease' => 1)));
  151. }
  152. $output .= $this->footer();
  153. return $output;
  154. }
  155. /**
  156. * Display the upgrade page that lists all the plugins that require attention.
  157. * @param plugin_manager $pluginman provides information about the plugins.
  158. * @param available_update_checker $checker provides information about available updates.
  159. * @param int $version the version of the Moodle code from version.php.
  160. * @param bool $showallplugins
  161. * @param moodle_url $reloadurl
  162. * @param moodle_url $continueurl
  163. * @return string HTML to output.
  164. */
  165. public function upgrade_plugin_check_page(plugin_manager $pluginman, available_update_checker $checker,
  166. $version, $showallplugins, $reloadurl, $continueurl) {
  167. global $CFG;
  168. $output = '';
  169. $output .= $this->header();
  170. $output .= $this->box_start('generalbox');
  171. $output .= $this->container_start('generalbox', 'notice');
  172. $output .= html_writer::tag('p', get_string('pluginchecknotice', 'core_plugin'));
  173. if (empty($CFG->disableupdatenotifications)) {
  174. $output .= $this->container_start('checkforupdates');
  175. $output .= $this->single_button(new moodle_url($reloadurl, array('fetchupdates' => 1)), get_string('checkforupdates', 'core_plugin'));
  176. if ($timefetched = $checker->get_last_timefetched()) {
  177. $output .= $this->container(get_string('checkforupdateslast', 'core_plugin',
  178. userdate($timefetched, get_string('strftimedatetime', 'core_langconfig'))));
  179. }
  180. $output .= $this->container_end();
  181. }
  182. $output .= $this->container_end();
  183. $output .= $this->plugins_check_table($pluginman, $version, array('full' => $showallplugins));
  184. $output .= $this->box_end();
  185. $output .= $this->upgrade_reload($reloadurl);
  186. if ($pluginman->some_plugins_updatable()) {
  187. $output .= $this->container_start('upgradepluginsinfo');
  188. $output .= $this->help_icon('upgradepluginsinfo', 'core_admin', get_string('upgradepluginsfirst', 'core_admin'));
  189. $output .= $this->container_end();
  190. }
  191. $button = new single_button($continueurl, get_string('upgradestart', 'admin'), 'get');
  192. $button->class = 'continuebutton';
  193. $output .= $this->render($button);
  194. $output .= $this->footer();
  195. return $output;
  196. }
  197. /**
  198. * Prints a page with a summary of plugin deployment to be confirmed.
  199. *
  200. * @param available_update_deployer $deployer
  201. * @param array $data deployer's data package as returned by {@link available_update_deployer::submitted_data()}
  202. * @return string
  203. */
  204. public function upgrade_plugin_confirm_deploy_page(available_update_deployer $deployer, array $data) {
  205. if (!$deployer->initialized()) {
  206. throw new coding_exception('Unable to render a page for non-initialized deployer.');
  207. }
  208. if (empty($data['updateinfo'])) {
  209. throw new coding_exception('Missing required data component.');
  210. }
  211. $updateinfo = $data['updateinfo'];
  212. $output = '';
  213. $output .= $this->header();
  214. $output .= $this->container_start('generalbox updateplugin', 'notice');
  215. $a = new stdClass();
  216. if (get_string_manager()->string_exists('pluginname', $updateinfo->component)) {
  217. $a->name = get_string('pluginname', $updateinfo->component);
  218. } else {
  219. $a->name = $updateinfo->component;
  220. }
  221. if (isset($updateinfo->release)) {
  222. $a->version = $updateinfo->release . ' (' . $updateinfo->version . ')';
  223. } else {
  224. $a->version = $updateinfo->version;
  225. }
  226. $a->url = $updateinfo->download;
  227. $output .= $this->output->heading(get_string('updatepluginconfirm', 'core_plugin'));
  228. $output .= $this->output->container(format_text(get_string('updatepluginconfirminfo', 'core_plugin', $a)), 'updatepluginconfirminfo');
  229. $output .= $this->output->container(get_string('updatepluginconfirmwarning', 'core_plugin', 'updatepluginconfirmwarning'));
  230. if ($repotype = $deployer->plugin_external_source($data['updateinfo'])) {
  231. $output .= $this->output->container(get_string('updatepluginconfirmexternal', 'core_plugin', $repotype), 'updatepluginconfirmexternal');
  232. }
  233. $widget = $deployer->make_execution_widget($data['updateinfo']);
  234. $output .= $this->output->render($widget);
  235. $output .= $this->output->single_button($data['returnurl'], get_string('cancel', 'core'), 'get');
  236. $output .= $this->container_end();
  237. $output .= $this->footer();
  238. return $output;
  239. }
  240. /**
  241. * Display the admin notifications page.
  242. * @param int $maturity
  243. * @param bool $insecuredataroot warn dataroot is invalid
  244. * @param bool $errorsdisplayed warn invalid dispaly error setting
  245. * @param bool $cronoverdue warn cron not running
  246. * @param bool $dbproblems warn db has problems
  247. * @param bool $maintenancemode warn in maintenance mode
  248. * @param bool $buggyiconvnomb warn iconv problems
  249. * @param array|null $availableupdates array of available_update_info objects or null
  250. * @param int|null $availableupdatesfetch timestamp of the most recent updates fetch or null (unknown)
  251. *
  252. * @return string HTML to output.
  253. */
  254. public function admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed,
  255. $cronoverdue, $dbproblems, $maintenancemode, $availableupdates, $availableupdatesfetch,
  256. $buggyiconvnomb, $registered) {
  257. global $CFG;
  258. $output = '';
  259. $output .= $this->header();
  260. $output .= $this->maturity_info($maturity);
  261. $output .= empty($CFG->disableupdatenotifications) ? $this->available_updates($availableupdates, $availableupdatesfetch) : '';
  262. $output .= $this->insecure_dataroot_warning($insecuredataroot);
  263. $output .= $this->display_errors_warning($errorsdisplayed);
  264. $output .= $this->buggy_iconv_warning($buggyiconvnomb);
  265. $output .= $this->cron_overdue_warning($cronoverdue);
  266. $output .= $this->db_problems($dbproblems);
  267. $output .= $this->maintenance_mode_warning($maintenancemode);
  268. $output .= $this->registration_warning($registered);
  269. //////////////////////////////////////////////////////////////////////////////////////////////////
  270. //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
  271. $output .= $this->moodle_copyright();
  272. //////////////////////////////////////////////////////////////////////////////////////////////////
  273. $output .= $this->footer();
  274. return $output;
  275. }
  276. /**
  277. * Display the plugin management page (admin/plugins.php).
  278. *
  279. * The filtering options array may contain following items:
  280. * bool contribonly - show only contributed extensions
  281. * bool updatesonly - show only plugins with an available update
  282. *
  283. * @param plugin_manager $pluginman
  284. * @param available_update_checker $checker
  285. * @param array $options filtering options
  286. * @return string HTML to output.
  287. */
  288. public function plugin_management_page(plugin_manager $pluginman, available_update_checker $checker, array $options = array()) {
  289. global $CFG;
  290. $output = '';
  291. $output .= $this->header();
  292. $output .= $this->heading(get_string('pluginsoverview', 'core_admin'));
  293. $output .= $this->plugins_overview_panel($pluginman, $options);
  294. if (empty($CFG->disableupdatenotifications)) {
  295. $output .= $this->container_start('checkforupdates');
  296. $output .= $this->single_button(
  297. new moodle_url($this->page->url, array_merge($options, array('fetchremote' => 1))),
  298. get_string('checkforupdates', 'core_plugin')
  299. );
  300. if ($timefetched = $checker->get_last_timefetched()) {
  301. $output .= $this->container(get_string('checkforupdateslast', 'core_plugin',
  302. userdate($timefetched, get_string('strftimedatetime', 'core_langconfig'))));
  303. }
  304. $output .= $this->container_end();
  305. }
  306. $output .= $this->box($this->plugins_control_panel($pluginman, $options), 'generalbox');
  307. $output .= $this->footer();
  308. return $output;
  309. }
  310. /**
  311. * Display a page to confirm the plugin uninstallation.
  312. *
  313. * @param plugin_manager $pluginman
  314. * @param plugin_info $pluginfo
  315. * @param moodle_url $continueurl URL to continue after confirmation
  316. * @return string
  317. */
  318. public function plugin_uninstall_confirm_page(plugin_manager $pluginman, plugininfo_base $pluginfo, moodle_url $continueurl) {
  319. $output = '';
  320. $pluginname = $pluginman->plugin_name($pluginfo->component);
  321. $output .= $this->output->header();
  322. $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
  323. $output .= $this->output->confirm(get_string('uninstallconfirm', 'core_plugin', array('name' => $pluginname)),
  324. $continueurl, $this->page->url);
  325. $output .= $this->output->footer();
  326. return $output;
  327. }
  328. /**
  329. * Display a page with results of plugin uninstallation and offer removal of plugin files.
  330. *
  331. * @param plugin_manager $pluginman
  332. * @param plugin_info $pluginfo
  333. * @param progress_trace_buffer $progress
  334. * @param moodle_url $continueurl URL to continue to remove the plugin folder
  335. * @return string
  336. */
  337. public function plugin_uninstall_results_removable_page(plugin_manager $pluginman, plugininfo_base $pluginfo,
  338. progress_trace_buffer $progress, moodle_url $continueurl) {
  339. $output = '';
  340. $pluginname = $pluginman->plugin_name($pluginfo->component);
  341. $output .= $this->output->header();
  342. $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
  343. $output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
  344. $confirm = $this->output->container(get_string('uninstalldeleteconfirm', 'core_plugin',
  345. array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'uninstalldeleteconfirm');
  346. if ($repotype = $pluginman->plugin_external_source($pluginfo->component)) {
  347. $confirm .= $this->output->container(get_string('uninstalldeleteconfirmexternal', 'core_plugin', $repotype),
  348. 'uninstalldeleteconfirmexternal');
  349. }
  350. $output .= $this->output->confirm($confirm, $continueurl, $this->page->url);
  351. $output .= $this->output->footer();
  352. return $output;
  353. }
  354. /**
  355. * Display a page with results of plugin uninstallation and inform about the need to remove plugin files manually.
  356. *
  357. * @param plugin_manager $pluginman
  358. * @param plugin_info $pluginfo
  359. * @param progress_trace_buffer $progress
  360. * @return string
  361. */
  362. public function plugin_uninstall_results_page(plugin_manager $pluginman, plugininfo_base $pluginfo, progress_trace_buffer $progress) {
  363. $output = '';
  364. $pluginname = $pluginman->plugin_name($pluginfo->component);
  365. $output .= $this->output->header();
  366. $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
  367. $output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
  368. $output .= $this->output->box(get_string('uninstalldelete', 'core_plugin',
  369. array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'generalbox uninstalldelete');
  370. $output .= $this->output->continue_button($this->page->url);
  371. $output .= $this->output->footer();
  372. return $output;
  373. }
  374. /**
  375. * Display the plugin management page (admin/environment.php).
  376. * @param array $versions
  377. * @param string $version
  378. * @param boolean $envstatus final result of env check (true/false)
  379. * @param array $environment_results array of results gathered
  380. * @return string HTML to output.
  381. */
  382. public function environment_check_page($versions, $version, $envstatus, $environment_results) {
  383. $output = '';
  384. $output .= $this->header();
  385. // Print the component download link
  386. $output .= html_writer::tag('div', html_writer::link(
  387. new moodle_url('/admin/environment.php', array('action' => 'updatecomponent', 'sesskey' => sesskey())),
  388. get_string('updatecomponent', 'admin')),
  389. array('class' => 'reportlink'));
  390. // Heading.
  391. $output .= $this->heading(get_string('environment', 'admin'));
  392. // Box with info and a menu to choose the version.
  393. $output .= $this->box_start();
  394. $output .= html_writer::tag('div', get_string('adminhelpenvironment'));
  395. $select = new single_select(new moodle_url('/admin/environment.php'), 'version', $versions, $version, null);
  396. $select->label = get_string('moodleversion');
  397. $output .= $this->render($select);
  398. $output .= $this->box_end();
  399. // The results
  400. $output .= $this->environment_check_table($envstatus, $environment_results);
  401. $output .= $this->footer();
  402. return $output;
  403. }
  404. /**
  405. * Output a warning message, of the type that appears on the admin notifications page.
  406. * @param string $message the message to display.
  407. * @param string $type type class
  408. * @return string HTML to output.
  409. */
  410. protected function warning($message, $type = 'warning') {
  411. return $this->box($message, 'generalbox admin' . $type);
  412. }
  413. /**
  414. * Render an appropriate message if dataroot is insecure.
  415. * @param bool $insecuredataroot
  416. * @return string HTML to output.
  417. */
  418. protected function insecure_dataroot_warning($insecuredataroot) {
  419. global $CFG;
  420. if ($insecuredataroot == INSECURE_DATAROOT_WARNING) {
  421. return $this->warning(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot));
  422. } else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) {
  423. return $this->warning(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'error');
  424. } else {
  425. return '';
  426. }
  427. }
  428. /**
  429. * Render an appropriate message if dataroot is insecure.
  430. * @param bool $errorsdisplayed
  431. * @return string HTML to output.
  432. */
  433. protected function display_errors_warning($errorsdisplayed) {
  434. if (!$errorsdisplayed) {
  435. return '';
  436. }
  437. return $this->warning(get_string('displayerrorswarning', 'admin'));
  438. }
  439. /**
  440. * Render an appropriate message if iconv is buggy and mbstring missing.
  441. * @param bool $buggyiconvnomb
  442. * @return string HTML to output.
  443. */
  444. protected function buggy_iconv_warning($buggyiconvnomb) {
  445. if (!$buggyiconvnomb) {
  446. return '';
  447. }
  448. return $this->warning(get_string('warningiconvbuggy', 'admin'));
  449. }
  450. /**
  451. * Render an appropriate message if cron has not been run recently.
  452. * @param bool $cronoverdue
  453. * @return string HTML to output.
  454. */
  455. public function cron_overdue_warning($cronoverdue) {
  456. if (!$cronoverdue) {
  457. return '';
  458. }
  459. return $this->warning(get_string('cronwarning', 'admin') . '&nbsp;' .
  460. $this->help_icon('cron', 'admin'));
  461. }
  462. /**
  463. * Render an appropriate message if there are any problems with the DB set-up.
  464. * @param bool $dbproblems
  465. * @return string HTML to output.
  466. */
  467. public function db_problems($dbproblems) {
  468. if (!$dbproblems) {
  469. return '';
  470. }
  471. return $this->warning($dbproblems);
  472. }
  473. /**
  474. * Render an appropriate message if the site in in maintenance mode.
  475. * @param bool $maintenancemode
  476. * @return string HTML to output.
  477. */
  478. public function maintenance_mode_warning($maintenancemode) {
  479. if (!$maintenancemode) {
  480. return '';
  481. }
  482. $url = new moodle_url('/admin/settings.php', array('section' => 'maintenancemode'));
  483. $url = $url->out(); // get_string() does not support objects in params
  484. return $this->warning(get_string('sitemaintenancewarning2', 'admin', $url));
  485. }
  486. /**
  487. * Display a warning about installing development code if necesary.
  488. * @param int $maturity
  489. * @return string HTML to output.
  490. */
  491. protected function maturity_warning($maturity) {
  492. if ($maturity == MATURITY_STABLE) {
  493. return ''; // No worries.
  494. }
  495. $maturitylevel = get_string('maturity' . $maturity, 'admin');
  496. return $this->box(
  497. $this->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
  498. $this->container($this->doc_link('admin/versions', get_string('morehelp'))),
  499. 'generalbox maturitywarning');
  500. }
  501. /**
  502. * Output the copyright notice.
  503. * @return string HTML to output.
  504. */
  505. protected function moodle_copyright() {
  506. global $CFG;
  507. //////////////////////////////////////////////////////////////////////////////////////////////////
  508. //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
  509. $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
  510. '<a href="http://docs.moodle.org/dev/Releases" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
  511. 'Copyright &copy; 1999 onwards, Martin Dougiamas<br />'.
  512. 'and <a href="http://moodle.org/dev">many other contributors</a>.<br />'.
  513. '<a href="http://docs.moodle.org/dev/License">GNU Public License</a>';
  514. //////////////////////////////////////////////////////////////////////////////////////////////////
  515. return $this->box($copyrighttext, 'copyright');
  516. }
  517. /**
  518. * Display a warning about installing development code if necesary.
  519. * @param int $maturity
  520. * @return string HTML to output.
  521. */
  522. protected function maturity_info($maturity) {
  523. if ($maturity == MATURITY_STABLE) {
  524. return ''; // No worries.
  525. }
  526. $maturitylevel = get_string('maturity' . $maturity, 'admin');
  527. return $this->box(
  528. get_string('maturitycoreinfo', 'admin', $maturitylevel) . ' ' .
  529. $this->doc_link('admin/versions', get_string('morehelp')),
  530. 'generalbox adminwarning maturityinfo maturity'.$maturity);
  531. }
  532. /**
  533. * Displays the info about available Moodle core and plugin updates
  534. *
  535. * The structure of the $updates param has changed since 2.4. It contains not only updates
  536. * for the core itself, but also for all other installed plugins.
  537. *
  538. * @param array|null $updates array of (string)component => array of available_update_info objects or null
  539. * @param int|null $fetch timestamp of the most recent updates fetch or null (unknown)
  540. * @return string
  541. */
  542. protected function available_updates($updates, $fetch) {
  543. $updateinfo = $this->box_start('generalbox adminwarning availableupdatesinfo');
  544. $someupdateavailable = false;
  545. if (is_array($updates)) {
  546. if (is_array($updates['core'])) {
  547. $someupdateavailable = true;
  548. $updateinfo .= $this->heading(get_string('updateavailable', 'core_admin'), 3);
  549. foreach ($updates['core'] as $update) {
  550. $updateinfo .= $this->moodle_available_update_info($update);
  551. }
  552. }
  553. unset($updates['core']);
  554. // If something has left in the $updates array now, it is updates for plugins.
  555. if (!empty($updates)) {
  556. $someupdateavailable = true;
  557. $updateinfo .= $this->heading(get_string('updateavailableforplugin', 'core_admin'), 3);
  558. $pluginsoverviewurl = new moodle_url('/admin/plugins.php', array('updatesonly' => 1));
  559. $updateinfo .= $this->container(get_string('pluginsoverviewsee', 'core_admin',
  560. array('url' => $pluginsoverviewurl->out())));
  561. }
  562. }
  563. if (!$someupdateavailable) {
  564. $now = time();
  565. if ($fetch and ($fetch <= $now) and ($now - $fetch < HOURSECS)) {
  566. $updateinfo .= $this->heading(get_string('updateavailablenot', 'core_admin'), 3);
  567. }
  568. }
  569. $updateinfo .= $this->container_start('checkforupdates');
  570. $updateinfo .= $this->single_button(new moodle_url($this->page->url, array('fetchupdates' => 1)), get_string('checkforupdates', 'core_plugin'));
  571. if ($fetch) {
  572. $updateinfo .= $this->container(get_string('checkforupdateslast', 'core_plugin',
  573. userdate($fetch, get_string('strftimedatetime', 'core_langconfig'))));
  574. }
  575. $updateinfo .= $this->container_end();
  576. $updateinfo .= $this->box_end();
  577. return $updateinfo;
  578. }
  579. /**
  580. * Display a warning about not being registered on Moodle.org if necesary.
  581. *
  582. * @param boolean $registered true if the site is registered on Moodle.org
  583. * @return string HTML to output.
  584. */
  585. protected function registration_warning($registered) {
  586. if (!$registered) {
  587. $registerbutton = $this->single_button(new moodle_url('registration/register.php',
  588. array('huburl' => HUB_MOODLEORGHUBURL, 'hubname' => 'Moodle.org')),
  589. get_string('register', 'admin'));
  590. return $this->warning( get_string('registrationwarning', 'admin')
  591. . '&nbsp;' . $this->help_icon('registration', 'admin') . $registerbutton );
  592. }
  593. return '';
  594. }
  595. /**
  596. * Helper method to render the information about the available Moodle update
  597. *
  598. * @param available_update_info $updateinfo information about the available Moodle core update
  599. */
  600. protected function moodle_available_update_info(available_update_info $updateinfo) {
  601. $boxclasses = 'moodleupdateinfo';
  602. $info = array();
  603. if (isset($updateinfo->release)) {
  604. $info[] = html_writer::tag('span', get_string('updateavailable_release', 'core_admin', $updateinfo->release),
  605. array('class' => 'info release'));
  606. }
  607. if (isset($updateinfo->version)) {
  608. $info[] = html_writer::tag('span', get_string('updateavailable_version', 'core_admin', $updateinfo->version),
  609. array('class' => 'info version'));
  610. }
  611. if (isset($updateinfo->maturity)) {
  612. $info[] = html_writer::tag('span', get_string('maturity'.$updateinfo->maturity, 'core_admin'),
  613. array('class' => 'info maturity'));
  614. $boxclasses .= ' maturity'.$updateinfo->maturity;
  615. }
  616. if (isset($updateinfo->download)) {
  617. $info[] = html_writer::link($updateinfo->download, get_string('download'), array('class' => 'info download'));
  618. }
  619. if (isset($updateinfo->url)) {
  620. $info[] = html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin'),
  621. array('class' => 'info more'));
  622. }
  623. $box = $this->output->box_start($boxclasses);
  624. $box .= $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $info), '');
  625. $box .= $this->output->box_end();
  626. return $box;
  627. }
  628. /**
  629. * Display a link to the release notes.
  630. * @return string HTML to output.
  631. */
  632. protected function release_notes_link() {
  633. $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/dev/Releases');
  634. $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
  635. return $this->box($releasenoteslink, 'generalbox releasenoteslink');
  636. }
  637. /**
  638. * Display the reload link that appears on several upgrade/install pages.
  639. * @return string HTML to output.
  640. */
  641. function upgrade_reload($url) {
  642. return html_writer::empty_tag('br') .
  643. html_writer::tag('div',
  644. html_writer::link($url, $this->pix_icon('i/reload', '', '', array('class' => 'icon icon-pre')) .
  645. get_string('reload'), array('title' => get_string('reload'))),
  646. array('class' => 'continuebutton')) . html_writer::empty_tag('br');
  647. }
  648. /**
  649. * Displays all known plugins and information about their installation or upgrade
  650. *
  651. * This default implementation renders all plugins into one big table. The rendering
  652. * options support:
  653. * (bool)full = false: whether to display up-to-date plugins, too
  654. * (bool)xdep = false: display the plugins with unsatisified dependecies only
  655. *
  656. * @param plugin_manager $pluginman provides information about the plugins.
  657. * @param int $version the version of the Moodle code from version.php.
  658. * @param array $options rendering options
  659. * @return string HTML code
  660. */
  661. public function plugins_check_table(plugin_manager $pluginman, $version, array $options = array()) {
  662. global $CFG;
  663. $plugininfo = $pluginman->get_plugins();
  664. if (empty($plugininfo)) {
  665. return '';
  666. }
  667. $options['full'] = isset($options['full']) ? (bool)$options['full'] : false;
  668. $options['xdep'] = isset($options['xdep']) ? (bool)$options['xdep'] : false;
  669. $table = new html_table();
  670. $table->id = 'plugins-check';
  671. $table->head = array(
  672. get_string('displayname', 'core_plugin'),
  673. get_string('rootdir', 'core_plugin'),
  674. get_string('source', 'core_plugin'),
  675. get_string('versiondb', 'core_plugin'),
  676. get_string('versiondisk', 'core_plugin'),
  677. get_string('requires', 'core_plugin'),
  678. get_string('status', 'core_plugin'),
  679. );
  680. $table->colclasses = array(
  681. 'displayname', 'rootdir', 'source', 'versiondb', 'versiondisk', 'requires', 'status',
  682. );
  683. $table->data = array();
  684. $numofhighlighted = array(); // number of highlighted rows per this subsection
  685. foreach ($plugininfo as $type => $plugins) {
  686. $header = new html_table_cell($pluginman->plugintype_name_plural($type));
  687. $header->header = true;
  688. $header->colspan = count($table->head);
  689. $header = new html_table_row(array($header));
  690. $header->attributes['class'] = 'plugintypeheader type-' . $type;
  691. $numofhighlighted[$type] = 0;
  692. if (empty($plugins) and $options['full']) {
  693. $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
  694. $msg->colspan = count($table->head);
  695. $row = new html_table_row(array($msg));
  696. $row->attributes['class'] .= 'msg msg-noneinstalled';
  697. $table->data[] = $header;
  698. $table->data[] = $row;
  699. continue;
  700. }
  701. $plugintyperows = array();
  702. foreach ($plugins as $name => $plugin) {
  703. $row = new html_table_row();
  704. $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
  705. if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name, null)) {
  706. $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
  707. } else {
  708. $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon'));
  709. }
  710. $displayname = $icon . ' ' . $plugin->displayname;
  711. $displayname = new html_table_cell($displayname);
  712. $rootdir = new html_table_cell($plugin->get_dir());
  713. if ($isstandard = $plugin->is_standard()) {
  714. $row->attributes['class'] .= ' standard';
  715. $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
  716. } else {
  717. $row->attributes['class'] .= ' extension';
  718. $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
  719. }
  720. $versiondb = new html_table_cell($plugin->versiondb);
  721. $versiondisk = new html_table_cell($plugin->versiondisk);
  722. $statuscode = $plugin->get_status();
  723. $row->attributes['class'] .= ' status-' . $statuscode;
  724. $status = get_string('status_' . $statuscode, 'core_plugin');
  725. $availableupdates = $plugin->available_updates();
  726. if (!empty($availableupdates) and empty($CFG->disableupdatenotifications)) {
  727. foreach ($availableupdates as $availableupdate) {
  728. $status .= $this->plugin_available_update_info($availableupdate);
  729. }
  730. }
  731. $status = new html_table_cell($status);
  732. $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version));
  733. $statusisboring = in_array($statuscode, array(
  734. plugin_manager::PLUGIN_STATUS_NODB, plugin_manager::PLUGIN_STATUS_UPTODATE));
  735. $coredependency = $plugin->is_core_dependency_satisfied($version);
  736. $otherpluginsdependencies = $pluginman->are_dependencies_satisfied($plugin->get_other_required_plugins());
  737. $dependenciesok = $coredependency && $otherpluginsdependencies;
  738. if ($options['xdep']) {
  739. // we want to see only plugins with failed dependencies
  740. if ($dependenciesok) {
  741. continue;
  742. }
  743. } else if ($isstandard and $statusisboring and $dependenciesok and empty($availableupdates)) {
  744. // no change is going to happen to the plugin - display it only
  745. // if the user wants to see the full list
  746. if (empty($options['full'])) {
  747. continue;
  748. }
  749. }
  750. // ok, the plugin should be displayed
  751. $numofhighlighted[$type]++;
  752. $row->cells = array($displayname, $rootdir, $source,
  753. $versiondb, $versiondisk, $requires, $status);
  754. $plugintyperows[] = $row;
  755. }
  756. if (empty($numofhighlighted[$type]) and empty($options['full'])) {
  757. continue;
  758. }
  759. $table->data[] = $header;
  760. $table->data = array_merge($table->data, $plugintyperows);
  761. }
  762. $sumofhighlighted = array_sum($numofhighlighted);
  763. if ($options['xdep']) {
  764. // we do not want to display no heading and links in this mode
  765. $out = '';
  766. } else if ($sumofhighlighted == 0) {
  767. $out = $this->output->container_start('nonehighlighted', 'plugins-check-info');
  768. $out .= $this->output->heading(get_string('nonehighlighted', 'core_plugin'));
  769. if (empty($options['full'])) {
  770. $out .= html_writer::link(new moodle_url('/admin/index.php',
  771. array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1)),
  772. get_string('nonehighlightedinfo', 'core_plugin'));
  773. }
  774. $out .= $this->output->container_end();
  775. } else {
  776. $out = $this->output->container_start('somehighlighted', 'plugins-check-info');
  777. $out .= $this->output->heading(get_string('somehighlighted', 'core_plugin', $sumofhighlighted));
  778. if (empty($options['full'])) {
  779. $out .= html_writer::link(new moodle_url('/admin/index.php',
  780. array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1)),
  781. get_string('somehighlightedinfo', 'core_plugin'));
  782. } else {
  783. $out .= html_writer::link(new moodle_url('/admin/index.php',
  784. array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 0)),
  785. get_string('somehighlightedonly', 'core_plugin'));
  786. }
  787. $out .= $this->output->container_end();
  788. }
  789. if ($sumofhighlighted > 0 or $options['full']) {
  790. $out .= html_writer::table($table);
  791. }
  792. return $out;
  793. }
  794. /**
  795. * Formats the information that needs to go in the 'Requires' column.
  796. * @param plugininfo_base $plugin the plugin we are rendering the row for.
  797. * @param plugin_manager $pluginman provides data on all the plugins.
  798. * @param string $version
  799. * @return string HTML code
  800. */
  801. protected function required_column(plugininfo_base $plugin, plugin_manager $pluginman, $version) {
  802. $requires = array();
  803. if (!empty($plugin->versionrequires)) {
  804. if ($plugin->versionrequires <= $version) {
  805. $class = 'requires-ok';
  806. } else {
  807. $class = 'requires-failed';
  808. }
  809. $requires[] = html_writer::tag('li',
  810. get_string('moodleversion', 'core_plugin', $plugin->versionrequires),
  811. array('class' => $class));
  812. }
  813. foreach ($plugin->get_other_required_plugins() as $component => $requiredversion) {
  814. $ok = true;
  815. $otherplugin = $pluginman->get_plugin_info($component);
  816. if (is_null($otherplugin)) {
  817. $ok = false;
  818. } else if ($requiredversion != ANY_VERSION and $otherplugin->versiondisk < $requiredversion) {
  819. $ok = false;
  820. }
  821. if ($ok) {
  822. $class = 'requires-ok';
  823. } else {
  824. $class = 'requires-failed';
  825. }
  826. if ($requiredversion != ANY_VERSION) {
  827. $str = 'otherpluginversion';
  828. } else {
  829. $str = 'otherplugin';
  830. }
  831. $requires[] = html_writer::tag('li',
  832. get_string($str, 'core_plugin',
  833. array('component' => $component, 'version' => $requiredversion)),
  834. array('class' => $class));
  835. }
  836. if (!$requires) {
  837. return '';
  838. }
  839. return html_writer::tag('ul', implode("\n", $requires));
  840. }
  841. /**
  842. * Prints an overview about the plugins - number of installed, number of extensions etc.
  843. *
  844. * @param plugin_manager $pluginman provides information about the plugins
  845. * @param array $options filtering options
  846. * @return string as usually
  847. */
  848. public function plugins_overview_panel(plugin_manager $pluginman, array $options = array()) {
  849. global $CFG;
  850. $plugininfo = $pluginman->get_plugins();
  851. $numtotal = $numdisabled = $numextension = $numupdatable = 0;
  852. foreach ($plugininfo as $type => $plugins) {
  853. foreach ($plugins as $name => $plugin) {
  854. if ($plugin->get_status() === plugin_manager::PLUGIN_STATUS_MISSING) {
  855. continue;
  856. }
  857. $numtotal++;
  858. if ($plugin->is_enabled() === false) {
  859. $numdisabled++;
  860. }
  861. if (!$plugin->is_standard()) {
  862. $numextension++;
  863. }
  864. if (empty($CFG->disableupdatenotifications) and $plugin->available_updates()) {
  865. $numupdatable++;
  866. }
  867. }
  868. }
  869. $info = array();
  870. $filter = array();
  871. $somefilteractive = false;
  872. $info[] = html_writer::tag('span', get_string('numtotal', 'core_plugin', $numtotal), array('class' => 'info total'));
  873. $info[] = html_writer::tag('span', get_string('numdisabled', 'core_plugin', $numdisabled), array('class' => 'info disabled'));
  874. $info[] = html_writer::tag('span', get_string('numextension', 'core_plugin', $numextension), array('class' => 'info extension'));
  875. if ($numextension > 0) {
  876. if (empty($options['contribonly'])) {
  877. $filter[] = html_writer::link(
  878. new moodle_url($this->page->url, array('contribonly' => 1)),
  879. get_string('filtercontribonly', 'core_plugin'),
  880. array('class' => 'filter-item show-contribonly')
  881. );
  882. } else {
  883. $filter[] = html_writer::tag('span', get_string('filtercontribonlyactive', 'core_plugin'),
  884. array('class' => 'filter-item active show-contribonly'));
  885. $somefilteractive = true;
  886. }
  887. }
  888. if ($numupdatable > 0) {
  889. $info[] = html_writer::tag('span', get_string('numupdatable', 'core_plugin', $numupdatable), array('class' => 'info updatable'));
  890. if (empty($options['updatesonly'])) {
  891. $filter[] = html_writer::link(
  892. new moodle_url($this->page->url, array('updatesonly' => 1)),
  893. get_string('filterupdatesonly', 'core_plugin'),
  894. array('class' => 'filter-item show-updatesonly')
  895. );
  896. } else {
  897. $filter[] = html_writer::tag('span', get_string('filterupdatesonlyactive', 'core_plugin'),
  898. array('class' => 'filter-item active show-updatesonly'));
  899. $somefilteractive = true;
  900. }
  901. }
  902. if ($somefilteractive) {
  903. $filter[] = html_writer::link($this->page->url, get_string('filterall', 'core_plugin'), array('class' => 'filter-item show-all'));
  904. }
  905. $output = $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $info), '', 'plugins-overview-panel');
  906. if (!empty($filter)) {
  907. $output .= $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $filter), '', 'plugins-overview-filter');
  908. }
  909. return $output;
  910. }
  911. /**
  912. * Displays all known plugins and links to manage them
  913. *
  914. * This default implementation renders all plugins into one big table.
  915. *
  916. * @param plugin_manager $pluginman provides information about the plugins.
  917. * @param array $options filtering options
  918. * @return string HTML code
  919. */
  920. public function plugins_control_panel(plugin_manager $pluginman, array $options = array()) {
  921. global $CFG;
  922. $plugininfo = $pluginman->get_plugins();
  923. // Filter the list of plugins according the options.
  924. if (!empty($options['updatesonly'])) {
  925. $updateable = array();
  926. foreach ($plugininfo as $plugintype => $pluginnames) {
  927. foreach ($pluginnames as $pluginname => $pluginfo) {
  928. if (!empty($pluginfo->availableupdates)) {
  929. foreach ($pluginfo->availableupdates as $pluginavailableupdate) {
  930. if ($pluginavailableupdate->version > $pluginfo->versiondisk) {
  931. $updateable[$plugintype][$pluginname] = $pluginfo;
  932. }
  933. }
  934. }
  935. }
  936. }
  937. $plugininfo = $updateable;
  938. }
  939. if (!empty($options['contribonly'])) {
  940. $contribs = array();
  941. foreach ($plugininfo as $plugintype => $pluginnames) {
  942. foreach ($pluginnames as $pluginname => $pluginfo) {
  943. if (!$pluginfo->is_standard()) {
  944. $contribs[$plugintype][$pluginname] = $pluginfo;
  945. }
  946. }
  947. }
  948. $plugininfo = $contribs;
  949. }
  950. if (empty($plugininfo)) {
  951. return '';
  952. }
  953. $table = new html_table();
  954. $table->id = 'plugins-control-panel';
  955. $table->head = array(
  956. get_string('displayname', 'core_plugin'),
  957. get_string('source', 'core_plugin'),
  958. get_string('version', 'core_plugin'),
  959. get_string('availability', 'core_plugin'),
  960. get_string('actions', 'core_plugin'),
  961. get_string('notes','core_plugin'),
  962. );
  963. $table->headspan = array(1, 1, 1, 1, 2, 1);
  964. $table->colclasses = array(
  965. 'pluginname', 'source', 'version', 'availability', 'settings', 'uninstall', 'notes'
  966. );
  967. foreach ($plugininfo as $type => $plugins) {
  968. $header = new html_table_cell($pluginman->plugintype_name_plural($type));
  969. $header->header = true;
  970. $header->colspan = array_sum($table->headspan);
  971. $header = new html_table_row(array($header));
  972. $header->attributes['class'] = 'plugintypeheader type-' . $type;
  973. $table->data[] = $header;
  974. if (empty($plugins)) {
  975. $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
  976. $msg->colspan = array_sum($table->headspan);
  977. $row = new html_table_row(array($msg));
  978. $row->attributes['class'] .= 'msg msg-noneinstalled';
  979. $table->data[] = $row;
  980. continue;
  981. }
  982. foreach ($plugins as $name => $plugin) {
  983. $row = new html_table_row();
  984. $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
  985. if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) {
  986. $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'icon pluginicon'));
  987. } else {
  988. $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'icon pluginicon noicon'));
  989. }
  990. if ($plugin->get_status() === plugin_manager::PLUGIN_STATUS_MISSING) {
  991. $msg = html_writer::tag('span', get_string('status_missing', '