renderer.php 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974
  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');
  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. 'uninstalldeleteconfirmexternal');
  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. *
  234. * @return string HTML to output.
  235. */
  236. public function admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed,
  237. $cronoverdue, $dbproblems, $maintenancemode, $availableupdates, $availableupdatesfetch,
  238. $buggyiconvnomb, $registered, array $cachewarnings = array(), $eventshandlers = 0) {
  239. global $CFG;
  240. $output = '';
  241. $output .= $this->header();
  242. $output .= $this->maturity_info($maturity);
  243. $output .= $this->legacy_log_store_writing_error();
  244. $output .= empty($CFG->disableupdatenotifications) ? $this->available_updates($availableupdates, $availableupdatesfetch) : '';
  245. $output .= $this->insecure_dataroot_warning($insecuredataroot);
  246. $output .= $this->display_errors_warning($errorsdisplayed);
  247. $output .= $this->buggy_iconv_warning($buggyiconvnomb);
  248. $output .= $this->cron_overdue_warning($cronoverdue);
  249. $output .= $this->db_problems($dbproblems);
  250. $output .= $this->maintenance_mode_warning($maintenancemode);
  251. $output .= $this->cache_warnings($cachewarnings);
  252. $output .= $this->events_handlers($eventshandlers);
  253. $output .= $this->registration_warning($registered);
  254. //////////////////////////////////////////////////////////////////////////////////////////////////
  255. //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
  256. $output .= $this->moodle_copyright();
  257. //////////////////////////////////////////////////////////////////////////////////////////////////
  258. $output .= $this->footer();
  259. return $output;
  260. }
  261. /**
  262. * Display the plugin management page (admin/plugins.php).
  263. *
  264. * The filtering options array may contain following items:
  265. * bool contribonly - show only contributed extensions
  266. * bool updatesonly - show only plugins with an available update
  267. *
  268. * @param core_plugin_manager $pluginman
  269. * @param \core\update\checker $checker
  270. * @param array $options filtering options
  271. * @return string HTML to output.
  272. */
  273. public function plugin_management_page(core_plugin_manager $pluginman, \core\update\checker $checker, array $options = array()) {
  274. $output = '';
  275. $output .= $this->header();
  276. $output .= $this->heading(get_string('pluginsoverview', 'core_admin'));
  277. $output .= $this->check_for_updates_button($checker, $this->page->url);
  278. $output .= $this->plugins_overview_panel($pluginman, $options);
  279. $output .= $this->plugins_control_panel($pluginman, $options);
  280. $output .= $this->footer();
  281. return $output;
  282. }
  283. /**
  284. * Renders a button to fetch for available updates.
  285. *
  286. * @param \core\update\checker $checker
  287. * @param moodle_url $reloadurl
  288. * @return string HTML
  289. */
  290. public function check_for_updates_button(\core\update\checker $checker, $reloadurl) {
  291. $output = '';
  292. if ($checker->enabled()) {
  293. $output .= $this->container_start('checkforupdates');
  294. $output .= $this->single_button(
  295. new moodle_url($reloadurl, array('fetchupdates' => 1)),
  296. get_string('checkforupdates', 'core_plugin')
  297. );
  298. if ($timefetched = $checker->get_last_timefetched()) {
  299. $timefetched = userdate($timefetched, get_string('strftimedatetime', 'core_langconfig'));
  300. $output .= $this->container(get_string('checkforupdateslast', 'core_plugin', $timefetched), 'lasttimefetched');
  301. }
  302. $output .= $this->container_end();
  303. }
  304. return $output;
  305. }
  306. /**
  307. * Display a page to confirm the plugin uninstallation.
  308. *
  309. * @param core_plugin_manager $pluginman
  310. * @param \core\plugininfo\base $pluginfo
  311. * @param moodle_url $continueurl URL to continue after confirmation
  312. * @param moodle_url $cancelurl URL to to go if cancelled
  313. * @return string
  314. */
  315. public function plugin_uninstall_confirm_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, moodle_url $continueurl, moodle_url $cancelurl) {
  316. $output = '';
  317. $pluginname = $pluginman->plugin_name($pluginfo->component);
  318. $confirm = '<p>' . get_string('uninstallconfirm', 'core_plugin', array('name' => $pluginname)) . '</p>';
  319. if ($extraconfirm = $pluginfo->get_uninstall_extra_warning()) {
  320. $confirm .= $extraconfirm;
  321. }
  322. $output .= $this->output->header();
  323. $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
  324. $output .= $this->output->confirm($confirm, $continueurl, $cancelurl);
  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 core_plugin_manager $pluginman
  332. * @param \core\plugininfo\base $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(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo,
  338. progress_trace_buffer $progress, moodle_url $continueurl) {
  339. $output = '';
  340. $pluginname = $pluginman->plugin_name($pluginfo->component);
  341. // Do not show navigation here, they must click one of the buttons.
  342. $this->page->set_pagelayout('maintenance');
  343. $this->page->set_cacheable(false);
  344. $output .= $this->output->header();
  345. $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
  346. $output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
  347. $confirm = $this->output->container(get_string('uninstalldeleteconfirm', 'core_plugin',
  348. array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'uninstalldeleteconfirm');
  349. if ($repotype = $pluginman->plugin_external_source($pluginfo->component)) {
  350. $confirm .= $this->output->container(get_string('uninstalldeleteconfirmexternal', 'core_plugin', $repotype),
  351. 'uninstalldeleteconfirmexternal');
  352. }
  353. // After any uninstall we must execute full upgrade to finish the cleanup!
  354. $output .= $this->output->confirm($confirm, $continueurl, new moodle_url('/admin/index.php'));
  355. $output .= $this->output->footer();
  356. return $output;
  357. }
  358. /**
  359. * Display a page with results of plugin uninstallation and inform about the need to remove plugin files manually.
  360. *
  361. * @param core_plugin_manager $pluginman
  362. * @param \core\plugininfo\base $pluginfo
  363. * @param progress_trace_buffer $progress
  364. * @return string
  365. */
  366. public function plugin_uninstall_results_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, progress_trace_buffer $progress) {
  367. $output = '';
  368. $pluginname = $pluginfo->component;
  369. $output .= $this->output->header();
  370. $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
  371. $output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
  372. $output .= $this->output->box(get_string('uninstalldelete', 'core_plugin',
  373. array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'generalbox uninstalldelete');
  374. $output .= $this->output->continue_button(new moodle_url('/admin/index.php'));
  375. $output .= $this->output->footer();
  376. return $output;
  377. }
  378. /**
  379. * Display the plugin management page (admin/environment.php).
  380. * @param array $versions
  381. * @param string $version
  382. * @param boolean $envstatus final result of env check (true/false)
  383. * @param array $environment_results array of results gathered
  384. * @return string HTML to output.
  385. */
  386. public function environment_check_page($versions, $version, $envstatus, $environment_results) {
  387. $output = '';
  388. $output .= $this->header();
  389. // Print the component download link
  390. $output .= html_writer::tag('div', html_writer::link(
  391. new moodle_url('/admin/environment.php', array('action' => 'updatecomponent', 'sesskey' => sesskey())),
  392. get_string('updatecomponent', 'admin')),
  393. array('class' => 'reportlink'));
  394. // Heading.
  395. $output .= $this->heading(get_string('environment', 'admin'));
  396. // Box with info and a menu to choose the version.
  397. $output .= $this->box_start();
  398. $output .= html_writer::tag('div', get_string('adminhelpenvironment'));
  399. $select = new single_select(new moodle_url('/admin/environment.php'), 'version', $versions, $version, null);
  400. $select->label = get_string('moodleversion');
  401. $output .= $this->render($select);
  402. $output .= $this->box_end();
  403. // The results
  404. $output .= $this->environment_check_table($envstatus, $environment_results);
  405. $output .= $this->footer();
  406. return $output;
  407. }
  408. /**
  409. * Output a warning message, of the type that appears on the admin notifications page.
  410. * @param string $message the message to display.
  411. * @param string $type type class
  412. * @return string HTML to output.
  413. */
  414. protected function warning($message, $type = 'warning') {
  415. return $this->box($message, 'generalbox admin' . $type);
  416. }
  417. /**
  418. * Render an appropriate message if dataroot is insecure.
  419. * @param bool $insecuredataroot
  420. * @return string HTML to output.
  421. */
  422. protected function insecure_dataroot_warning($insecuredataroot) {
  423. global $CFG;
  424. if ($insecuredataroot == INSECURE_DATAROOT_WARNING) {
  425. return $this->warning(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot));
  426. } else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) {
  427. return $this->warning(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'error');
  428. } else {
  429. return '';
  430. }
  431. }
  432. /**
  433. * Render an appropriate message if dataroot is insecure.
  434. * @param bool $errorsdisplayed
  435. * @return string HTML to output.
  436. */
  437. protected function display_errors_warning($errorsdisplayed) {
  438. if (!$errorsdisplayed) {
  439. return '';
  440. }
  441. return $this->warning(get_string('displayerrorswarning', 'admin'));
  442. }
  443. /**
  444. * Render an appropriate message if iconv is buggy and mbstring missing.
  445. * @param bool $buggyiconvnomb
  446. * @return string HTML to output.
  447. */
  448. protected function buggy_iconv_warning($buggyiconvnomb) {
  449. if (!$buggyiconvnomb) {
  450. return '';
  451. }
  452. return $this->warning(get_string('warningiconvbuggy', 'admin'));
  453. }
  454. /**
  455. * Render an appropriate message if cron has not been run recently.
  456. * @param bool $cronoverdue
  457. * @return string HTML to output.
  458. */
  459. public function cron_overdue_warning($cronoverdue) {
  460. global $CFG;
  461. if (!$cronoverdue) {
  462. return '';
  463. }
  464. if (empty($CFG->cronclionly)) {
  465. $url = new moodle_url('/admin/cron.php');
  466. if (!empty($CFG->cronremotepassword)) {
  467. $url = new moodle_url('/admin/cron.php', array('password' => $CFG->cronremotepassword));
  468. }
  469. return $this->warning(get_string('cronwarning', 'admin', $url->out()) . '&nbsp;' .
  470. $this->help_icon('cron', 'admin'));
  471. }
  472. // $CFG->cronclionly is not empty: cron can run only from CLI.
  473. return $this->warning(get_string('cronwarningcli', 'admin') . '&nbsp;' .
  474. $this->help_icon('cron', 'admin'));
  475. }
  476. /**
  477. * Render an appropriate message if there are any problems with the DB set-up.
  478. * @param bool $dbproblems
  479. * @return string HTML to output.
  480. */
  481. public function db_problems($dbproblems) {
  482. if (!$dbproblems) {
  483. return '';
  484. }
  485. return $this->warning($dbproblems);
  486. }
  487. /**
  488. * Renders cache warnings if there are any.
  489. *
  490. * @param string[] $cachewarnings
  491. * @return string
  492. */
  493. public function cache_warnings(array $cachewarnings) {
  494. if (!count($cachewarnings)) {
  495. return '';
  496. }
  497. return join("\n", array_map(array($this, 'warning'), $cachewarnings));
  498. }
  499. /**
  500. * Renders events 1 API handlers warning.
  501. *
  502. * @param array $eventshandlers
  503. * @return string
  504. */
  505. public function events_handlers($eventshandlers) {
  506. if ($eventshandlers) {
  507. $components = '';
  508. foreach ($eventshandlers as $eventhandler) {
  509. $components .= $eventhandler->component . ', ';
  510. }
  511. $components = rtrim($components, ', ');
  512. return $this->warning(get_string('eventshandlersinuse', 'admin', $components));
  513. }
  514. }
  515. /**
  516. * Render an appropriate message if the site in in maintenance mode.
  517. * @param bool $maintenancemode
  518. * @return string HTML to output.
  519. */
  520. public function maintenance_mode_warning($maintenancemode) {
  521. if (!$maintenancemode) {
  522. return '';
  523. }
  524. $url = new moodle_url('/admin/settings.php', array('section' => 'maintenancemode'));
  525. $url = $url->out(); // get_string() does not support objects in params
  526. return $this->warning(get_string('sitemaintenancewarning2', 'admin', $url));
  527. }
  528. /**
  529. * Display a warning about installing development code if necesary.
  530. * @param int $maturity
  531. * @return string HTML to output.
  532. */
  533. protected function maturity_warning($maturity) {
  534. if ($maturity == MATURITY_STABLE) {
  535. return ''; // No worries.
  536. }
  537. $maturitylevel = get_string('maturity' . $maturity, 'admin');
  538. return $this->warning(
  539. $this->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
  540. $this->container($this->doc_link('admin/versions', get_string('morehelp'))),
  541. 'error');
  542. }
  543. /*
  544. * If necessary, displays a warning about upgrading a test site.
  545. *
  546. * @param string $testsite
  547. * @return string HTML
  548. */
  549. protected function test_site_warning($testsite) {
  550. if (!$testsite) {
  551. return '';
  552. }
  553. $warning = (get_string('testsiteupgradewarning', 'admin', $testsite));
  554. return $this->warning($warning, 'error');
  555. }
  556. /**
  557. * Output the copyright notice.
  558. * @return string HTML to output.
  559. */
  560. protected function moodle_copyright() {
  561. global $CFG;
  562. //////////////////////////////////////////////////////////////////////////////////////////////////
  563. //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
  564. $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
  565. '<a href="http://docs.moodle.org/dev/Releases" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
  566. 'Copyright &copy; 1999 onwards, Martin Dougiamas<br />'.
  567. 'and <a href="http://moodle.org/dev">many other contributors</a>.<br />'.
  568. '<a href="http://docs.moodle.org/dev/License">GNU Public License</a>';
  569. //////////////////////////////////////////////////////////////////////////////////////////////////
  570. return $this->box($copyrighttext, 'copyright');
  571. }
  572. /**
  573. * Display a warning about installing development code if necesary.
  574. * @param int $maturity
  575. * @return string HTML to output.
  576. */
  577. protected function maturity_info($maturity) {
  578. if ($maturity == MATURITY_STABLE) {
  579. return ''; // No worries.
  580. }
  581. $level = 'warning';
  582. if ($maturity == MATURITY_ALPHA) {
  583. $level = 'error';
  584. }
  585. $maturitylevel = get_string('maturity' . $maturity, 'admin');
  586. $warningtext = get_string('maturitycoreinfo', 'admin', $maturitylevel);
  587. $warningtext .= ' ' . $this->doc_link('admin/versions', get_string('morehelp'));
  588. return $this->warning($warningtext, $level);
  589. }
  590. /**
  591. * Displays the info about available Moodle core and plugin updates
  592. *
  593. * The structure of the $updates param has changed since 2.4. It contains not only updates
  594. * for the core itself, but also for all other installed plugins.
  595. *
  596. * @param array|null $updates array of (string)component => array of \core\update\info objects or null
  597. * @param int|null $fetch timestamp of the most recent updates fetch or null (unknown)
  598. * @return string
  599. */
  600. protected function available_updates($updates, $fetch) {
  601. $updateinfo = '';
  602. $someupdateavailable = false;
  603. if (is_array($updates)) {
  604. if (is_array($updates['core'])) {
  605. $someupdateavailable = true;
  606. $updateinfo .= $this->heading(get_string('updateavailable', 'core_admin'), 3);
  607. foreach ($updates['core'] as $update) {
  608. $updateinfo .= $this->moodle_available_update_info($update);
  609. }
  610. $updateinfo .= html_writer::tag('p', get_string('updateavailablerecommendation', 'core_admin'),
  611. array('class' => 'updateavailablerecommendation'));
  612. }
  613. unset($updates['core']);
  614. // If something has left in the $updates array now, it is updates for plugins.
  615. if (!empty($updates)) {
  616. $someupdateavailable = true;
  617. $updateinfo .= $this->heading(get_string('updateavailableforplugin', 'core_admin'), 3);
  618. $pluginsoverviewurl = new moodle_url('/admin/plugins.php', array('updatesonly' => 1));
  619. $updateinfo .= $this->container(get_string('pluginsoverviewsee', 'core_admin',
  620. array('url' => $pluginsoverviewurl->out())));
  621. }
  622. }
  623. if (!$someupdateavailable) {
  624. $now = time();
  625. if ($fetch and ($fetch <= $now) and ($now - $fetch < HOURSECS)) {
  626. $updateinfo .= $this->heading(get_string('updateavailablenot', 'core_admin'), 3);
  627. }
  628. }
  629. $updateinfo .= $this->container_start('checkforupdates');
  630. $fetchurl = new moodle_url('/admin/index.php', array('fetchupdates' => 1, 'sesskey' => sesskey(), 'cache' => 0));
  631. $updateinfo .= $this->single_button($fetchurl, get_string('checkforupdates', 'core_plugin'));
  632. if ($fetch) {
  633. $updateinfo .= $this->container(get_string('checkforupdateslast', 'core_plugin',
  634. userdate($fetch, get_string('strftimedatetime', 'core_langconfig'))));
  635. }
  636. $updateinfo .= $this->container_end();
  637. return $this->warning($updateinfo);
  638. }
  639. /**
  640. * Display a warning about not being registered on Moodle.org if necesary.
  641. *
  642. * @param boolean $registered true if the site is registered on Moodle.org
  643. * @return string HTML to output.
  644. */
  645. protected function registration_warning($registered) {
  646. if (!$registered) {
  647. $registerbutton = $this->single_button(new moodle_url('/admin/registration/register.php',
  648. array('huburl' => HUB_MOODLEORGHUBURL, 'hubname' => 'Moodle.org')),
  649. get_string('register', 'admin'));
  650. return $this->warning( get_string('registrationwarning', 'admin')
  651. . '&nbsp;' . $this->help_icon('registration', 'admin') . $registerbutton );
  652. }
  653. return '';
  654. }
  655. /**
  656. * Helper method to render the information about the available Moodle update
  657. *
  658. * @param \core\update\info $updateinfo information about the available Moodle core update
  659. */
  660. protected function moodle_available_update_info(\core\update\info $updateinfo) {
  661. $boxclasses = 'moodleupdateinfo';
  662. $info = array();
  663. if (isset($updateinfo->release)) {
  664. $info[] = html_writer::tag('span', get_string('updateavailable_release', 'core_admin', $updateinfo->release),
  665. array('class' => 'info release'));
  666. }
  667. if (isset($updateinfo->version)) {
  668. $info[] = html_writer::tag('span', get_string('updateavailable_version', 'core_admin', $updateinfo->version),
  669. array('class' => 'info version'));
  670. }
  671. if (isset($updateinfo->maturity)) {
  672. $info[] = html_writer::tag('span', get_string('maturity'.$updateinfo->maturity, 'core_admin'),
  673. array('class' => 'info maturity'));
  674. $boxclasses .= ' maturity'.$updateinfo->maturity;
  675. }
  676. if (isset($updateinfo->download)) {
  677. $info[] = html_writer::link($updateinfo->download, get_string('download'), array('class' => 'info download'));
  678. }
  679. if (isset($updateinfo->url)) {
  680. $info[] = html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin'),
  681. array('class' => 'info more'));
  682. }
  683. $box = $this->output->box_start($boxclasses);
  684. $box .= $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $info), '');
  685. $box .= $this->output->box_end();
  686. return $box;
  687. }
  688. /**
  689. * Display a link to the release notes.
  690. * @return string HTML to output.
  691. */
  692. protected function release_notes_link() {
  693. $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/dev/Releases');
  694. $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
  695. return $this->box($releasenoteslink, 'generalbox releasenoteslink');
  696. }
  697. /**
  698. * Display the reload link that appears on several upgrade/install pages.
  699. * @return string HTML to output.
  700. */
  701. function upgrade_reload($url) {
  702. return html_writer::empty_tag('br') .
  703. html_writer::tag('div',
  704. html_writer::link($url, $this->pix_icon('i/reload', '', '', array('class' => 'icon icon-pre')) .
  705. get_string('reload'), array('title' => get_string('reload'))),
  706. array('class' => 'continuebutton')) . html_writer::empty_tag('br');
  707. }
  708. /**
  709. * Displays all known plugins and information about their installation or upgrade
  710. *
  711. * This default implementation renders all plugins into one big table. The rendering
  712. * options support:
  713. * (bool)full = false: whether to display up-to-date plugins, too
  714. * (bool)xdep = false: display the plugins with unsatisified dependecies only
  715. *
  716. * @param core_plugin_manager $pluginman provides information about the plugins.
  717. * @param int $version the version of the Moodle code from version.php.
  718. * @param array $options rendering options
  719. * @return string HTML code
  720. */
  721. public function plugins_check_table(core_plugin_manager $pluginman, $version, array $options = array()) {
  722. $plugininfo = $pluginman->get_plugins();
  723. if (empty($plugininfo)) {
  724. return '';
  725. }
  726. $options['full'] = isset($options['full']) ? (bool)$options['full'] : false;
  727. $options['xdep'] = isset($options['xdep']) ? (bool)$options['xdep'] : false;
  728. $table = new html_table();
  729. $table->id = 'plugins-check';
  730. $table->head = array(
  731. get_string('displayname', 'core_plugin').' / '.get_string('rootdir', 'core_plugin'),
  732. get_string('versiondb', 'core_plugin'),
  733. get_string('versiondisk', 'core_plugin'),
  734. get_string('requires', 'core_plugin'),
  735. get_string('source', 'core_plugin').' / '.get_string('status', 'core_plugin'),
  736. );
  737. $table->colclasses = array(
  738. 'displayname', 'versiondb', 'versiondisk', 'requires', 'status',
  739. );
  740. $table->data = array();
  741. // Number of displayed plugins per type.
  742. $numdisplayed = array();
  743. // Number of plugins known to the plugin manager.
  744. $sumtotal = 0;
  745. // Number of plugins requiring attention.
  746. $sumattention = 0;
  747. // List of all components we can cancel installation of.
  748. $installabortable = $pluginman->list_cancellable_installations();
  749. // List of all components we can cancel upgrade of.
  750. $upgradeabortable = $pluginman->list_restorable_archives();
  751. foreach ($plugininfo as $type => $plugins) {
  752. $header = new html_table_cell($pluginman->plugintype_name_plural($type));
  753. $header->header = true;
  754. $header->colspan = count($table->head);
  755. $header = new html_table_row(array($header));
  756. $header->attributes['class'] = 'plugintypeheader type-' . $type;
  757. $numdisplayed[$type] = 0;
  758. if (empty($plugins) and $options['full']) {
  759. $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
  760. $msg->colspan = count($table->head);
  761. $row = new html_table_row(array($msg));
  762. $row->attributes['class'] .= 'msg msg-noneinstalled';
  763. $table->data[] = $header;
  764. $table->data[] = $row;
  765. continue;
  766. }
  767. $plugintyperows = array();
  768. foreach ($plugins as $name => $plugin) {
  769. $sumtotal++;
  770. $row = new html_table_row();
  771. $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
  772. if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name, null)) {
  773. $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
  774. } else {
  775. $icon = '';
  776. }
  777. $displayname = new html_table_cell(
  778. $icon.
  779. html_writer::span($plugin->displayname, 'pluginname').
  780. html_writer::div($plugin->get_dir(), 'plugindir')
  781. );
  782. $versiondb = new html_table_cell($plugin->versiondb);
  783. $versiondisk = new html_table_cell($plugin->versiondisk);
  784. if ($isstandard = $plugin->is_standard()) {
  785. $row->attributes['class'] .= ' standard';
  786. $sourcelabel = html_writer::span(get_string('sourcestd', 'core_plugin'), 'sourcetext label');
  787. } else {
  788. $row->attributes['class'] .= ' extension';
  789. $sourcelabel = html_writer::span(get_string('sourceext', 'core_plugin'), 'sourcetext label label-info');
  790. }
  791. $coredependency = $plugin->is_core_dependency_satisfied($version);
  792. $otherpluginsdependencies = $pluginman->are_dependencies_satisfied($plugin->get_other_required_plugins());
  793. $dependenciesok = $coredependency && $otherpluginsdependencies;
  794. $statuscode = $plugin->get_status();
  795. $row->attributes['class'] .= ' status-' . $statuscode;
  796. $statusclass = 'statustext label ';
  797. switch ($statuscode) {
  798. case core_plugin_manager::PLUGIN_STATUS_NEW:
  799. $statusclass .= $dependenciesok ? 'label-success' : 'label-warning';
  800. break;
  801. case core_plugin_manager::PLUGIN_STATUS_UPGRADE:
  802. $statusclass .= $dependenciesok ? 'label-info' : 'label-warning';
  803. break;
  804. case core_plugin_manager::PLUGIN_STATUS_MISSING:
  805. case core_plugin_manager::PLUGIN_STATUS_DOWNGRADE:
  806. case core_plugin_manager::PLUGIN_STATUS_DELETE:
  807. $statusclass .= 'label-important';
  808. break;
  809. case core_plugin_manager::PLUGIN_STATUS_NODB:
  810. case core_plugin_manager::PLUGIN_STATUS_UPTODATE:
  811. $statusclass .= $dependenciesok ? '' : 'label-warning';
  812. break;
  813. }
  814. $status = html_writer::span(get_string('status_' . $statuscode, 'core_plugin'), $statusclass);
  815. if (!empty($installabortable[$plugin->component])) {
  816. $status .= $this->output->single_button(
  817. new moodle_url($this->page->url, array('abortinstall' => $plugin->component)),
  818. get_string('cancelinstallone', 'core_plugin'),
  819. 'post',
  820. array('class' => 'actionbutton cancelinstallone')
  821. );
  822. }
  823. if (!empty($upgradeabortable[$plugin->component])) {
  824. $status .= $this->output->single_button(
  825. new moodle_url($this->page->url, array('abortupgrade' => $plugin->component)),
  826. get_string('cancelupgradeone', 'core_plugin'),
  827. 'post',
  828. array('class' => 'actionbutton cancelupgradeone')
  829. );
  830. }
  831. $availableupdates = $plugin->available_updates();
  832. if (!empty($availableupdates)) {
  833. foreach ($availableupdates as $availableupdate) {
  834. $status .= $this->plugin_available_update_info($pluginman, $availableupdate);
  835. }
  836. }
  837. $status = new html_table_cell($sourcelabel.' '.$status);
  838. $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version));
  839. $statusisboring = in_array($statuscode, array(
  840. core_plugin_manager::PLUGIN_STATUS_NODB, core_plugin_manager::PLUGIN_STATUS_UPTODATE));
  841. if ($options['xdep']) {
  842. // we want to see only plugins with failed dependencies
  843. if ($dependenciesok) {
  844. continue;
  845. }
  846. } else if ($statusisboring and $dependenciesok and empty($availableupdates)) {
  847. // no change is going to happen to the plugin - display it only
  848. // if the user wants to see the full list
  849. if (empty($options['full'])) {
  850. continue;
  851. }
  852. } else {
  853. $sumattention++;
  854. }
  855. // The plugin should be displayed.
  856. $numdisplayed[$type]++;
  857. $row->cells = array($displayname, $versiondb, $versiondisk, $requires, $status);
  858. $plugintyperows[] = $row;
  859. }
  860. if (empty($numdisplayed[$type]) and empty($options['full'])) {
  861. continue;
  862. }
  863. $table->data[] = $header;
  864. $table->data = array_merge($table->data, $plugintyperows);
  865. }
  866. // Total number of displayed plugins.
  867. $sumdisplayed = array_sum($numdisplayed);
  868. if ($options['xdep']) {
  869. // At the plugins dependencies check page, display the table only.
  870. return html_writer::table($table);
  871. }
  872. $out = $this->output->container_start('', 'plugins-check-info');
  873. if ($sumdisplayed == 0) {
  874. $out .= $this->output->heading(get_string('pluginchecknone', 'core_plugin'));
  875. } else {
  876. if (empty($options['full'])) {
  877. $out .= $this->output->heading(get_string('plugincheckattention', 'core_plugin'));
  878. } else {
  879. $out .= $this->output->heading(get_string('plugincheckall', 'core_plugin'));
  880. }
  881. }
  882. $out .= $this->output->container_start('actions');
  883. $installableupdates = $pluginman->filter_installable($pluginman->available_updates());
  884. if ($installableupdates) {
  885. $out .= $this->output->single_button(
  886. new moodle_url($this->page->url, array('installupdatex' => 1)),
  887. get_string('updateavailableinstallall', 'core_admin', count($installableupdates)),
  888. 'post',
  889. array('class' => 'singlebutton updateavailableinstallall')
  890. );
  891. }
  892. if ($installabortable) {
  893. $out .= $this->output->single_button(
  894. new moodle_url($this->page->url, array('abortinstallx' => 1)),
  895. get_string('cancelinstallall', 'core_plugin', count($installabortable)),
  896. 'post',
  897. array('class' => 'singlebutton cancelinstallall')
  898. );
  899. }
  900. if ($upgradeabortable) {
  901. $out .= $this->output->single_button(
  902. new moodle_url($this->page->url, array('abortupgradex' => 1)),
  903. get_string('cancelupgradeall', 'core_plugin', count($upgradeabortable)),
  904. 'post',
  905. array('class' => 'singlebutton cancelupgradeall')
  906. );
  907. }
  908. $out .= html_writer::div(html_writer::link(new moodle_url($this->page->url, array('showallplugins' => 0)),
  909. get_string('plugincheckattention', 'core_plugin')).' '.html_writer::span($sumattention, 'badge'));
  910. $out .= html_writer::div(html_writer::link(new moodle_url($this->page->url, array('showallplugins' => 1)),
  911. get_string('plugincheckall', 'core_plugin')).' '.html_writer::span($sumtotal, 'badge'));
  912. $out .= $this->output->container_end(); // End of .actions container.
  913. $out .= $this->output->container_end(); // End of #plugins-check-info container.
  914. if ($sumdisplayed > 0 or $options['full']) {
  915. $out .= html_writer::table($table);
  916. }
  917. return $out;
  918. }
  919. /**
  920. * Display the continue / cancel widgets for the plugins management pages.
  921. *
  922. * @param null|moodle_url $continue URL for the continue button, should it be displayed
  923. * @param null|moodle_url $cancel URL for the cancel link, defaults to the current page
  924. * @return string HTML
  925. */
  926. public function plugins_management_confirm_buttons(moodle_url $continue=null, moodle_url $cancel=null) {
  927. $out = html_writer::start_div('plugins-management-confirm-buttons');
  928. if (!empty($continue)) {
  929. $out .= $this->output->single_button($continue, get_string('continue'), 'post', array('class' => 'continue'));
  930. }
  931. if (empty($cancel)) {
  932. $cancel = $this->page->url;
  933. }
  934. $out .= html_writer::div(html_writer::link($cancel, get_string('cancel')), 'cancel');
  935. return $out;
  936. }
  937. /**
  938. * Displays the information about missing dependencies
  939. *
  940. * @param core_plugin_manager $pluginman
  941. * @return string
  942. */
  943. protected function missing_dependencies(core_plugin_manager $pluginman) {
  944. $dependencies = $pluginman->missing_dependencies();
  945. if (empty($dependencies)) {
  946. return '';
  947. }
  948. $available = array();
  949. $unavailable = array();
  950. $unknown = array();
  951. foreach ($dependencies as $component => $remoteinfo) {
  952. if ($remoteinfo === false) {
  953. // The required version is not available. Let us check if there
  954. // is at least some version in the plugins directory.
  955. $remoteinfoanyversion = $pluginman->get_remote_plugin_info($component, ANY_VERSION, false);
  956. if ($remoteinfoanyversion === false) {
  957. $unknown[$component] = $component;
  958. } else {
  959. $unavailable[$component] = $remoteinfoanyversion;
  960. }
  961. } else {
  962. $available[$component] = $remoteinfo;
  963. }
  964. }
  965. $out = $this->output->container_start('plugins-check-dependencies');
  966. if ($unavailable or $unknown) {
  967. $out .= $this->output->heading(get_string('misdepsunavail', 'core_plugin'));
  968. if ($unknown) {
  969. $out .= $this->output->notification(get_string('misdepsunknownlist', 'core_plugin', implode($unknown, ', ')));
  970. }
  971. if ($unavailable) {
  972. $unavailablelist = array();
  973. foreach ($unavailable as $component => $remoteinfoanyversion) {
  974. $unavailablelistitem = html_writer::link('https://moodle.org/plugins/view.php?plugin='.$component,
  975. '<strong>'.$remoteinfoanyversion->name.'</strong>');
  976. if ($remoteinfoanyversion->version) {
  977. $unavailablelistitem .= ' ('.$component.' &gt; '.$remoteinfoanyversion->version->version.')';
  978. } else {
  979. $unavailablelistitem .= ' ('.$component.')';
  980. }
  981. $unavailablelist[] = $unavailablelistitem;
  982. }
  983. $out .= $this->output->notification(get_string('misdepsunavaillist', 'core_plugin',
  984. implode($unavailablelist, ', ')));
  985. }
  986. $out .= $this->output->container_start('plugins-check-dependencies-actions');
  987. $out .= ' '.html_writer::link(new moodle_url('/admin/tool/installaddon/'),
  988. get_string('dependencyuploadmissing', 'core_plugin'));
  989. $out .= $this->output->container_end(); // End of .plugins-check-dependencies-actions container.
  990. }
  991. if ($available) {
  992. $out .= $this->output->heading(get_string('misdepsavail', 'core_plugin'));
  993. $out .= $this->output->container_start('plugins-check-dependencies-actions');
  994. $installable = $pluginman->filter_installable($available);
  995. if ($installable) {
  996. $out .= $this->output->single_button(
  997. new moodle_url($this->page->url, array('installdepx' => 1)),
  998. get_string('dependencyinstallmissing', 'core_plugin', count($installable)),
  999. 'post',
  1000. array('class' => 'singlebutton dependencyinstallmissing')
  1001. );
  1002. }
  1003. $out .= html_writer::div(html_writer::link(new moodle_url('/admin/tool/installaddon/'),
  1004. get_string('dependencyuploadmissing', 'core_plugin')), 'dependencyuploadmissing');
  1005. $out .= $this->output->container_end(); // End of .plugins-check-dependencies-actions container.
  1006. $out .= $this->available_missing_dependencies_list($pluginman, $available);
  1007. }
  1008. $out .= $this->output->container_end(); // End of .plugins-check-dependencies container.
  1009. return $out;
  1010. }
  1011. /**
  1012. * Displays the list if available missing dependencies.
  1013. *
  1014. * @param core_plugin_manager $pluginman
  1015. * @param array $dependencies
  1016. * @return string
  1017. */
  1018. protected function available_missing_dependencies_list(core_plugin_manager $pluginman, array $dependencies) {
  1019. global $CFG;
  1020. $table = new html_table();
  1021. $table->id = 'plugins-check-available-dependencies';
  1022. $table->head = array(
  1023. get_string('displayname', 'core_plugin'),
  1024. get_string('release', 'core_plugin'),
  1025. get_string('version', 'core_plugin'),
  1026. get_string('supportedmoodleversions', 'core_plugin'),
  1027. get_string('info', 'core'),
  1028. );
  1029. $table->colclasses = array('displayname', 'release', 'version', 'supportedmoodleversions', 'info');
  1030. $table->data = array();
  1031. foreach ($dependencies as $plugin) {
  1032. $supportedmoodles = array();
  1033. foreach ($plugin->version->supportedmoodles as $moodle) {
  1034. if ($CFG->branch == str_replace('.', '', $moodle->release)) {
  1035. $supportedmoodles[] = html_writer::span($moodle->release, 'label label-success');
  1036. } else {
  1037. $supportedmoodles[] = html_writer::span($moodle->release, 'label');
  1038. }
  1039. }
  1040. $requriedby = $pluginman->other_plugins_that_require($plugin->component);
  1041. if ($requriedby) {
  1042. foreach ($requriedby as $ix => $val) {
  1043. $inf = $pluginman->get_plugin_info($val);
  1044. if ($inf) {
  1045. $requriedby[$ix] = $inf->displayname.' ('.$inf->component.')';
  1046. }
  1047. }
  1048. $info = html_writer::div(
  1049. get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
  1050. 'requiredby'
  1051. );
  1052. } else {
  1053. $info = '';
  1054. }
  1055. $info .= $this->output->container_start('actions');
  1056. $info .= html_writer::div(
  1057. html_writer::link('https://moodle.org/plugins/view.php?plugin='.$plugin->component,
  1058. get_string('misdepinfoplugin', 'core_plugin')),
  1059. 'misdepinfoplugin'
  1060. );
  1061. $info .= html_writer::div(
  1062. html_writer::link('https://moodle.org/plugins/pluginversion.php?id='.$plugin->version->id,
  1063. get_string('misdepinfoversion', 'core_plugin')),
  1064. 'misdepinfoversion'
  1065. );
  1066. $info .= html_writer::div(html_writer::link($plugin->version->downloadurl, get_string('download')), 'misdepdownload');
  1067. if ($pluginman->is_remote_plugin_installable($plugin->component, $plugin->version->version, $reason)) {
  1068. $info .= $this->output->single_button(
  1069. new moodle_url($this->page->url, array('installdep' => $plugin->component)),
  1070. get_string('dependencyinstall', 'core_plugin'),
  1071. 'post',
  1072. array('class' => 'singlebutton dependencyinstall')
  1073. );
  1074. } else {
  1075. $reasonhelp = $this->info_remote_plugin_not_installable($reason);
  1076. if ($reasonhelp) {
  1077. $info .= html_writer::div($reasonhelp, 'reasonhelp dependencyinstall');
  1078. }
  1079. }
  1080. $info .= $this->output->container_end(); // End of .actions container.
  1081. $table->data[] = array(
  1082. html_writer::div($plugin->name, 'name').' '.html_writer::div($plugin->component, 'component'),
  1083. $plugin->version->release,
  1084. $plugin->version->version,
  1085. implode($supportedmoodles, ' '),
  1086. $info
  1087. );
  1088. }
  1089. return html_writer::table($table);
  1090. }
  1091. /**
  1092. * Explain why {@link core_plugin_manager::is_remote_plugin_installable()} returned false.
  1093. *
  1094. * @param string $reason the reason code as returned by the plugin manager
  1095. * @return string
  1096. */
  1097. protected function info_remote_plugin_not_installable($reason) {
  1098. if ($reason === 'notwritableplugintype' or $reason === 'notwritableplugin') {
  1099. return $this->output->help_icon('notwritable', 'core_plugin', get_string('notwritable', 'core_plugin'));
  1100. }
  1101. if ($reason === 'remoteunavailable') {
  1102. return $this->output->help_icon('notdownloadable', 'core_plugin', get_string('notdownloadable', 'core_plugin'));
  1103. }
  1104. return false;
  1105. }
  1106. /**
  1107. * Formats the information that needs to go in the 'Requires' column.
  1108. * @param \core\plugininfo\base $plugin the plugin we are rendering the row for.
  1109. * @param core_plugin_manager $pluginman provides data on all the plugins.
  1110. * @param string $version
  1111. * @return string HTML code
  1112. */
  1113. protected function required_column(\core\plugininfo\base $plugin, core_plugin_manager $pluginman, $version) {
  1114. $requires = array();
  1115. $displayuploadlink = false;
  1116. $displayupdateslink = false;
  1117. foreach ($pluginman->resolve_requirements($plugin, $version) as $reqname => $reqinfo) {
  1118. if ($reqname === 'core') {
  1119. if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OK) {
  1120. $class = 'requires-ok';
  1121. $label = '';
  1122. } else {
  1123. $class = 'requires-failed';
  1124. $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'label label-important');
  1125. }
  1126. $requires[] = html_writer::tag('li',
  1127. html_writer::span(get_string('moodleversion', 'core_plugin', $plugin->versionrequires), 'dep dep-core').
  1128. ' '.$label, array('class' => $class));
  1129. } else {
  1130. $actions = array();
  1131. if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OK) {
  1132. $label = '';
  1133. $class = 'requires-ok';
  1134. } else if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_MISSING) {
  1135. if ($reqinfo->availability == $pluginman::REQUIREMENT_AVAILABLE) {
  1136. $label = html_writer::span(get_string('dependencymissing', 'core_plugin'), 'label label-warning');
  1137. $label .= ' '.html_writer::span(get_string('dependencyavailable', 'core_plugin'), 'label label-warning');
  1138. $class = 'requires-failed requires-missing requires-available';
  1139. $actions[] = html_writer::link(
  1140. new moodle_url('https://moodle.org/plugins/view.php', array('plugin' => $reqname)),
  1141. get_string('misdepinfoplugin', 'core_plugin')
  1142. );
  1143. } else {
  1144. $label = html_writer::span(get_string('dependencymissing', 'core_plugin'), 'label label-important');
  1145. $label .= ' '.html_writer::span(get_string('dependencyunavailable', 'core_plugin'),
  1146. 'label label-important');
  1147. $class = 'requires-failed requires-missing requires-unavailable';
  1148. }
  1149. $displayuploadlink = true;
  1150. } else if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OUTDATED) {
  1151. if ($reqinfo->availability == $pluginman::REQUIREMENT_AVAILABLE) {
  1152. $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'label label-warning');
  1153. $label .= ' '.html_writer::span(get_string('dependencyavailable', 'core_plugin'), 'label label-warning');
  1154. $class = 'requires-failed requires-outdated requires-available';
  1155. $displayupdateslink = true;
  1156. } else {
  1157. $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'label label-important');
  1158. $label .= ' '.html_writer::span(get_string('dependencyunavailable', 'core_plugin'),
  1159. 'label label-important');
  1160. $class = 'requires-failed requires-outdated requires-unavailable';
  1161. }
  1162. $displayuploadlink = true;
  1163. }
  1164. if ($reqinfo->reqver != ANY_VERSION) {
  1165. $str = 'otherpluginversion';
  1166. } else {
  1167. $str = 'otherplugin';
  1168. }
  1169. $requires[] = html_writer::tag('li', html_writer::span(
  1170. get_string($str, 'core_plugin', array('component' => $reqname, 'version' => $reqinfo->reqver)),
  1171. 'dep dep-plugin').' '.$label.' '.html_writer::span(implode(' | ', $actions), 'actions'),
  1172. array('class' => $class)
  1173. );
  1174. }
  1175. }
  1176. if (!$requires) {
  1177. return '';
  1178. }
  1179. $out = html_writer::tag('ul', implode("\n", $requires));
  1180. if ($displayuploadlink) {
  1181. $out .= html_writer::div(
  1182. html_writer::link(
  1183. new moodle_url('/admin/tool/installaddon/'),
  1184. get_string('dependencyuploadmissing', 'core_plugin')
  1185. ),
  1186. 'dependencyuploadmissing'
  1187. );
  1188. }
  1189. if ($displayupdateslink) {
  1190. $out .= html_writer::div(
  1191. html_writer::link(
  1192. new moodle_url($this->page->url, array('sesskey' => sesskey(), 'fetchupdates' => 1)),
  1193. get_string('checkforupdates', 'core_plugin')
  1194. ),
  1195. 'checkforupdates'
  1196. );
  1197. }
  1198. return $out;
  1199. }
  1200. /**
  1201. * Prints an overview about the plugins - number of installed, number of extensions etc.
  1202. *
  1203. * @param core_plugin_manager $pluginman provides information about the plugins
  1204. * @param array $options filtering options
  1205. * @return string as usually
  1206. */
  1207. public function plugins_overview_panel(core_plugin_manager $pluginman, array $options = array()) {
  1208. $plugininfo = $pluginman->get_plugins();
  1209. $numtotal = $numextension = $numupdatable = 0;
  1210. foreach ($plugininfo as $type => $plugins) {
  1211. foreach ($plugins as $name => $plugin) {
  1212. if ($plugin->available_updates()) {
  1213. $numupdatable++;
  1214. }
  1215. if ($plugin->get_status() === core_plugin_manager::PLUGIN_STATUS_MISSING) {
  1216. continue;
  1217. }
  1218. $numtotal++;
  1219. if (!$plugin->is_standard()) {
  1220. $numextension++;
  1221. }
  1222. }
  1223. }
  1224. $infoall = html_writer::link(
  1225. new moodle_url($this->page->url, array('contribonly' => 0, 'updatesonly' => 0)),
  1226. get_string('overviewall', 'core_plugin'),
  1227. array('title' => get_string('filterall', 'core_plugin'))
  1228. ).' '.html_writer::span($numtotal, 'badge number number-all');
  1229. $infoext = html_writer::link(
  1230. new moodle_url($this->page->url, array('contribonly' => 1, 'updatesonly' => 0)),
  1231. get_string('overviewext', 'core_plugin'),
  1232. array('title' => get_string('filtercontribonly', 'core_plugin'))
  1233. ).' '.html_writer::span($numextension, 'badge number number-additional');
  1234. if ($numupdatable) {
  1235. $infoupdatable = html_writer::link(
  1236. new moodle_url($this->page->url, array('contribonly' => 0, 'updatesonly' => 1)),
  1237. get_string('overviewupdatable', 'core_plugin'),
  1238. array('title' => get_string('filterupdatesonly', 'core_plugin'))
  1239. ).' '.html_writer::span($numupdatable, 'badge badge-info number number-updatable');
  1240. } else {
  1241. // No updates, or the notifications disabled.
  1242. $infoupdatable = '';
  1243. }
  1244. $out = html_writer::start_div('', array('id' => 'plugins-overview-panel'));
  1245. if (!empty($options['updatesonly'])) {
  1246. $out .= $this->output->heading(get_string('overviewupdatable', 'core_plugin'), 3);
  1247. } else if (!empty($options['contribonly'])) {
  1248. $out .= $this->output->heading(get_string('overviewext', 'core_plugin'), 3);
  1249. }
  1250. if ($numupdatable) {
  1251. $installableupdates = $pluginman->filter_installable($pluginman->available_updates());
  1252. if ($installableupdates) {
  1253. $out .= $this->output->single_button(
  1254. new moodle_url($this->page->url, array('installupdatex' => 1)),
  1255. get_string('updateavailableinstallall', 'core_admin', count($installableupdates)),
  1256. 'post',
  1257. array('class' => 'singlebutton updateavailableinstallall')
  1258. );
  1259. }
  1260. }
  1261. $out .= html_writer::div($infoall, 'info info-all').
  1262. html_writer::div($infoext, 'info info-ext').
  1263. html_writer::div($infoupdatable, 'info info-updatable');
  1264. $out .= html_writer::end_div(); // End of #plugins-overview-panel block.
  1265. return $out;
  1266. }
  1267. /**
  1268. * Displays all known plugins and links to manage them
  1269. *
  1270. * This default implementation renders all plugins into one big table.
  1271. *
  1272. * @param core_plugin_manager $pluginman provides information about the plugins.
  1273. * @param array $options filtering options
  1274. * @return string HTML code
  1275. */
  1276. public function plugins_control_panel(core_plugin_manager $pluginman, array $options = array()) {
  1277. $plugininfo = $pluginman->get_plugins();
  1278. // Filter the list of plugins according the options.
  1279. if (!empty($options['updatesonly'])) {
  1280. $updateable = array();
  1281. foreach ($plugininfo as $plugintype => $pluginnames) {
  1282. foreach ($pluginnames as $pluginname => $pluginfo) {
  1283. $pluginavailableupdates = $pluginfo->available_updates();
  1284. if (!empty($pluginavailableupdates)) {
  1285. foreach ($pluginavailableupdates as $pluginavailableupdate) {
  1286. $updateable[$plugintype][$pluginname] = $pluginfo;
  1287. }
  1288. }
  1289. }
  1290. }
  1291. $plugininfo = $updateable;
  1292. }
  1293. if (!empty($options['contribonly'])) {
  1294. $contribs = array();
  1295. foreach ($plugininfo as $plugintype => $pluginnames) {
  1296. foreach ($pluginnames as $pluginname => $pluginfo) {
  1297. if (!$pluginfo->is_standard()) {
  1298. $contribs[$plugintype][$pluginname] = $pluginfo;
  1299. }
  1300. }
  1301. }
  1302. $plugininfo = $contribs;
  1303. }
  1304. if (empty($plugininfo)) {
  1305. return '';
  1306. }
  1307. $table = new html_table();
  1308. $table->id = 'plugins-control-panel';
  1309. $table->head = array(
  1310. get_string('displayname', 'core_plugin'),
  1311. get_string('version', 'core_plugin'),
  1312. get_string('availability', 'core_plugin'),
  1313. get_string('actions', 'core_plugin'),
  1314. get_string('notes','core_plugin'),
  1315. );
  1316. $table->headspan = array(1, 1, 1, 2, 1);
  1317. $table->colclasses = array(
  1318. 'pluginname', 'version', 'availability', 'settings', 'uninstall', 'notes'
  1319. );
  1320. foreach ($plugininfo as $type => $plugins) {
  1321. $heading = $pluginman->plugintype_name_plural($type);
  1322. $pluginclass = core_plugin_manager::resolve_plugininfo_class($type);
  1323. if ($manageurl = $pluginclass::get_manage_url()) {
  1324. $heading .= $this->output->action_icon($manageurl, new pix_icon('i/settings',
  1325. get_string('settings', 'core_plugin')));
  1326. }
  1327. $header = new html_table_cell(html_writer::tag('span', $heading, array('id'=>'plugin_type_cell_'.$type)));
  1328. $header->header = true;
  1329. $header->colspan = array_sum($table->headspan);
  1330. $header = new html_table_row(array($header));
  1331. $header->attributes['class'] = 'plugintypeheader type-' . $type;
  1332. $table->data[] = $header;
  1333. if (empty($plugins)) {
  1334. $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
  1335. $msg->colspan = array_sum($table->headspan);
  1336. $row = new html_table_row(array($msg));
  1337. $row->attributes['class'] .= 'msg msg-noneinstalled';
  1338. $table->data[] = $row;
  1339. continue;
  1340. }
  1341. foreach ($plugins as $name => $plugin) {
  1342. $row = new html_table_row();
  1343. $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
  1344. if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) {
  1345. $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'icon pluginicon'));
  1346. } else {
  1347. $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'icon pluginicon noicon'));
  1348. }
  1349. $status = $plugin->get_status();
  1350. $row->attributes['class'] .= ' status-'.$status;
  1351. $pluginname = html_writer::tag('div', $icon.$plugin->displayname, array('class' => 'displayname')).
  1352. html_writer::tag('div', $plugin->component, array('class' => 'componentname'));
  1353. $pluginname = new html_table_cell($pluginname);
  1354. $version = html_writer::div($plugin->versiondb, 'versionnumber');
  1355. if ((string)$plugin->release !== '') {
  1356. $version = html_writer::div($plugin->release, 'release').$version;
  1357. }
  1358. $version = new html_table_cell($version);
  1359. $isenabled = $plugin->is_enabled();
  1360. if (is_null($isenabled)) {
  1361. $availability = new html_table_cell('');
  1362. } else if ($isenabled) {
  1363. $row->attributes['class'] .= ' enabled';
  1364. $availability = new html_table_cell(get_string('pluginenabled', 'core_plugin'));
  1365. } else {
  1366. $row->attributes['class'] .= ' disabled';
  1367. $availability = new html_table_cell(get_string('plugindisabled', 'core_plugin'));
  1368. }
  1369. $settingsurl = $plugin->get_settings_url();
  1370. if (!is_null($settingsurl)) {
  1371. $settings = html_writer::link($settingsurl, get_string('settings', 'core_plugin'), array('class' => 'settings'));
  1372. } else {
  1373. $settings = '';
  1374. }
  1375. $settings = new html_table_cell($settings);
  1376. if ($uninstallurl = $pluginman->get_uninstall_url($plugin->component, 'overview')) {
  1377. $uninstall = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin'));
  1378. } else {
  1379. $uninstall = '';
  1380. }
  1381. $uninstall = new html_table_cell($uninstall);
  1382. if ($plugin->is_standard()) {
  1383. $row->attributes['class'] .= ' standard';
  1384. $source = '';
  1385. } else {
  1386. $row->attributes['class'] .= ' extension';
  1387. $source = html_writer::div(get_string('sourceext', 'core_plugin'), 'source label label-info');
  1388. }
  1389. if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) {
  1390. $msg = html_writer::div(get_string('status_missing', 'core_plugin'), 'statusmsg label label-important');
  1391. } else if ($status === core_plugin_manager::PLUGIN_STATUS_NEW) {
  1392. $msg = html_writer::div(get_string('status_new', 'core_plugin'), 'statusmsg label label-success');
  1393. } else {
  1394. $msg = '';
  1395. }
  1396. $requriedby = $pluginman->other_plugins_that_require($plugin->component);
  1397. if ($requriedby) {
  1398. $requiredby = html_writer::tag('div', get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
  1399. array('class' => 'requiredby'));
  1400. } else {
  1401. $requiredby = '';
  1402. }
  1403. $updateinfo = '';
  1404. if (is_array($plugin->available_updates())) {
  1405. foreach ($plugin->available_updates() as $availableupdate) {
  1406. $updateinfo .= $this->plugin_available_update_info($pluginman, $availableupdate);
  1407. }
  1408. }
  1409. $notes = new html_table_cell($source.$msg.$requiredby.$updateinfo);
  1410. $row->cells = array(
  1411. $pluginname, $version, $availability, $settings, $uninstall, $notes
  1412. );
  1413. $table->data[] = $row;
  1414. }
  1415. }
  1416. return html_writer::table($table);
  1417. }
  1418. /**
  1419. * Helper method to render the information about the available plugin update
  1420. *
  1421. * @param core_plugin_manager $pluginman plugin manager instance
  1422. * @param \core\update\info $updateinfo information about the available update for the plugin
  1423. */
  1424. protected function plugin_available_update_info(core_plugin_manager $pluginman, \core\update\info $updateinfo) {
  1425. $boxclasses = 'pluginupdateinfo';
  1426. $info = array();
  1427. if (isset($updateinfo->release)) {
  1428. $info[] = html_writer::div(
  1429. get_string('updateavailable_release', 'core_plugin', $updateinfo->release),
  1430. 'info release'
  1431. );
  1432. }
  1433. if (isset($updateinfo->maturity)) {
  1434. $info[] = html_writer::div(
  1435. get_string('maturity'.$updateinfo->maturity, 'core_admin'),
  1436. 'info maturity'
  1437. );
  1438. $boxclasses .= ' maturity'.$updateinfo->maturity;
  1439. }
  1440. if (isset($updateinfo->download)) {
  1441. $info[] = html_writer::div(
  1442. html_writer::link($updateinfo->download, get_string('download')),
  1443. 'info download'
  1444. );
  1445. }
  1446. if (isset($updateinfo->url)) {
  1447. $info[] = html_writer::div(
  1448. html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin')),
  1449. 'info more'
  1450. );
  1451. }
  1452. $box = html_writer::start_div($boxclasses);
  1453. $box .= html_writer::div(
  1454. get_string('updateavailable', 'core_plugin', $updateinfo->version),
  1455. 'version'
  1456. );
  1457. $box .= html_writer::div(
  1458. implode(html_writer::span(' ', 'separator'), $info),
  1459. 'infos'
  1460. );
  1461. if ($pluginman->is_remote_plugin_installable($updateinfo->component, $updateinfo->version, $reason)) {
  1462. $box .= $this->output->single_button(
  1463. new moodle_url($this->page->url, array('installupdate' => $updateinfo->component,
  1464. 'installupdateversion' => $updateinfo->version)),
  1465. get_string('updateavailableinstall', 'core_admin'),
  1466. 'post',
  1467. array('class' => 'singlebutton updateavailableinstall')
  1468. );
  1469. } else {
  1470. $reasonhelp = $this->info_remote_plugin_not_installable($reason);
  1471. if ($reasonhelp) {
  1472. $box .= html_writer::div($reasonhelp, 'reasonhelp updateavailableinstall');
  1473. }
  1474. }
  1475. $box .= html_writer::end_div();
  1476. return $box;
  1477. }
  1478. /**
  1479. * This function will render one beautiful table with all the environmental
  1480. * configuration and how it suits Moodle needs.
  1481. *
  1482. * @param boolean $result final result of the check (true/false)
  1483. * @param environment_results[] $environment_results array of results gathered
  1484. * @return string HTML to output.
  1485. */
  1486. public function environment_check_table($result, $environment_results) {
  1487. global $CFG;
  1488. // Table headers
  1489. $servertable = new html_table();//table for server checks
  1490. $servertable->head = array(
  1491. get_string('name'),
  1492. get_string('info'),
  1493. get_string('report'),
  1494. get_string('plugin'),
  1495. get_string('status'),
  1496. );
  1497. $servertable->colclasses = array('centeralign name', 'centeralign info', 'leftalign report', 'leftalign plugin', 'centeralign status');
  1498. $servertable->attributes['class'] = 'admintable environmenttable generaltable';
  1499. $servertable->id = 'serverstatus';
  1500. $serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
  1501. $othertable = new html_table();//table for custom checks
  1502. $othertable->head = array(
  1503. get_string('info'),
  1504. get_string('report'),
  1505. get_string('plugin'),
  1506. get_string('status'),
  1507. );
  1508. $othertable->colclasses = array('aligncenter info', 'alignleft report', 'alignleft plugin', 'aligncenter status');
  1509. $othertable->attributes['class'] = 'admintable environmenttable generaltable';
  1510. $othertable->id = 'otherserverstatus';
  1511. $otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
  1512. // Iterate over each environment_result
  1513. $continue = true;
  1514. foreach ($environment_results as $environment_result) {
  1515. $errorline = false;
  1516. $warningline = false;
  1517. $stringtouse = '';
  1518. if ($continue) {
  1519. $type = $environment_result->getPart();
  1520. $info = $environment_result->getInfo();
  1521. $status = $environment_result->getStatus();
  1522. $plugin = $environment_result->getPluginName();
  1523. $error_code = $environment_result->getErrorCode();
  1524. // Process Report field
  1525. $rec = new stdClass();
  1526. // Something has gone wrong at parsing time
  1527. if ($error_code) {
  1528. $stringtouse = 'environmentxmlerror';
  1529. $rec->error_code = $error_code;
  1530. $status = get_string('error');
  1531. $errorline = true;
  1532. $continue = false;
  1533. }
  1534. if ($continue) {
  1535. if ($rec->needed = $environment_result->getNeededVersion()) {
  1536. // We are comparing versions
  1537. $rec->current = $environment_result->getCurrentVersion();
  1538. if ($environment_result->getLevel() == 'required') {
  1539. $stringtouse = 'environmentrequireversion';
  1540. } else {
  1541. $stringtouse = 'environmentrecommendversion';
  1542. }
  1543. } else if ($environment_result->getPart() == 'custom_check') {
  1544. // We are checking installed & enabled things
  1545. if ($environment_result->getLevel() == 'required') {
  1546. $stringtouse = 'environmentrequirecustomcheck';
  1547. } else {
  1548. $stringtouse = 'environmentrecommendcustomcheck';
  1549. }
  1550. } else if ($environment_result->getPart() == 'php_setting') {
  1551. if ($status) {
  1552. $stringtouse = 'environmentsettingok';
  1553. } else if ($environment_result->getLevel() == 'required') {
  1554. $stringtouse = 'environmentmustfixsetting';
  1555. } else {
  1556. $stringtouse = 'environmentshouldfixsetting';
  1557. }
  1558. } else {
  1559. if ($environment_result->getLevel() == 'required') {
  1560. $stringtouse = 'environmentrequireinstall';
  1561. } else {
  1562. $stringtouse = 'environmentrecommendinstall';
  1563. }
  1564. }
  1565. // Calculate the status value
  1566. if ($environment_result->getBypassStr() != '') { //Handle bypassed result (warning)
  1567. $status = get_string('bypassed');
  1568. $warningline = true;
  1569. } else if ($environment_result->getRestrictStr() != '') { //Handle restricted result (error)
  1570. $status = get_string('restricted');
  1571. $errorline = true;
  1572. } else {
  1573. if ($status) { //Handle ok result (ok)
  1574. $status = get_string('ok');
  1575. } else {
  1576. if ($environment_result->getLevel() == 'optional') {//Handle check result (warning)
  1577. $status = get_string('check');
  1578. $warningline = true;
  1579. } else { //Handle error result (error)
  1580. $status = get_string('check');
  1581. $errorline = true;
  1582. }
  1583. }
  1584. }
  1585. }
  1586. // Build the text
  1587. $linkparts = array();
  1588. $linkparts[] = 'admin/environment';
  1589. $linkparts[] = $type;
  1590. if (!empty($info)){
  1591. $linkparts[] = $info;
  1592. }
  1593. // Plugin environments do not have docs pages yet.
  1594. if (empty($CFG->docroot) or $environment_result->plugin) {
  1595. $report = get_string($stringtouse, 'admin', $rec);
  1596. } else {
  1597. $report = $this->doc_link(join($linkparts, '/'), get_string($stringtouse, 'admin', $rec));
  1598. }
  1599. // Format error or warning line
  1600. if ($errorline || $warningline) {
  1601. $messagetype = $errorline? 'error':'warn';
  1602. } else {
  1603. $messagetype = 'ok';
  1604. }
  1605. $status = '<span class="'.$messagetype.'">'.$status.'</span>';
  1606. // Here we'll store all the feedback found
  1607. $feedbacktext = '';
  1608. // Append the feedback if there is some
  1609. $feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), $messagetype);
  1610. //Append the bypass if there is some
  1611. $feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'warn');
  1612. //Append the restrict if there is some
  1613. $feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'error');
  1614. $report .= $feedbacktext;
  1615. // Add the row to the table
  1616. if ($environment_result->getPart() == 'custom_check'){
  1617. $otherdata[$messagetype][] = array ($info, $report, $plugin, $status);
  1618. } else {
  1619. $serverdata[$messagetype][] = array ($type, $info, $report, $plugin, $status);
  1620. }
  1621. }
  1622. }
  1623. //put errors first in
  1624. $servertable->data = array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']);
  1625. $othertable->data = array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']);
  1626. // Print table
  1627. $output = '';
  1628. $output .= $this->heading(get_string('serverchecks', 'admin'));
  1629. $output .= html_writer::table($servertable);
  1630. if (count($othertable->data)){
  1631. $output .= $this->heading(get_string('customcheck', 'admin'));
  1632. $output .= html_writer::table($othertable);
  1633. }
  1634. // Finally, if any error has happened, print the summary box
  1635. if (!$result) {
  1636. $output .= $this->box(get_string('environmenterrortodo', 'admin'), 'environmentbox errorbox');
  1637. }
  1638. return $output;
  1639. }
  1640. /**
  1641. * Render a simple page for providing the upgrade key.
  1642. *
  1643. * @param moodle_url|string $url
  1644. * @return string
  1645. */
  1646. public function upgradekey_form_page($url) {
  1647. $output = '';
  1648. $output .= $this->header();
  1649. $output .= $this->container_start('upgradekeyreq');
  1650. $output .= $this->heading(get_string('upgradekeyreq', 'core_admin'));
  1651. $output .= html_writer::start_tag('form', array('method' => 'POST', 'action' => $url));
  1652. $output .= html_writer::empty_tag('input', array('name' => 'upgradekey', 'type' => 'password'));
  1653. $output .= html_writer::empty_tag('input', array('value' => get_string('submit'), 'type' => 'submit'));
  1654. $output .= html_writer::end_tag('form');
  1655. $output .= $this->container_end();
  1656. $output .= $this->footer();
  1657. return $output;
  1658. }
  1659. /**
  1660. * Check to see if writing to the deprecated legacy log store is enabled.
  1661. *
  1662. * @return string An error message if writing to the legacy log store is enabled.
  1663. */
  1664. protected function legacy_log_store_writing_error() {
  1665. $enabled = get_config('logstore_legacy', 'loglegacy');
  1666. $plugins = explode(',', get_config('tool_log', 'enabled_stores'));
  1667. $enabled = $enabled && in_array('logstore_legacy', $plugins);
  1668. if ($enabled) {
  1669. return $this->warning(get_string('legacylogginginuse'));
  1670. }
  1671. }
  1672. }