courseformats.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. * Allows the admin to enable, disable and uninstall course formats
  18. *
  19. * @package core_admin
  20. * @copyright 2012 Marina Glancy
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. require_once('../config.php');
  24. require_once($CFG->libdir.'/adminlib.php');
  25. $action = required_param('action', PARAM_ALPHANUMEXT);
  26. $formatname = required_param('format', PARAM_PLUGIN);
  27. $syscontext = context_system::instance();
  28. $PAGE->set_url('/admin/courseformats.php');
  29. $PAGE->set_context($syscontext);
  30. require_login();
  31. require_capability('moodle/site:config', $syscontext);
  32. require_sesskey();
  33. $return = new moodle_url('/admin/settings.php', array('section' => 'manageformats'));
  34. $formatplugins = core_plugin_manager::instance()->get_plugins_of_type('format');
  35. $sortorder = array_flip(array_keys($formatplugins));
  36. if (!isset($formatplugins[$formatname])) {
  37. print_error('courseformatnotfound', 'error', $return, $formatname);
  38. }
  39. switch ($action) {
  40. case 'disable':
  41. if ($formatplugins[$formatname]->is_enabled()) {
  42. if (get_config('moodlecourse', 'format') === $formatname) {
  43. print_error('cannotdisableformat', 'error', $return);
  44. }
  45. set_config('disabled', 1, 'format_'. $formatname);
  46. core_plugin_manager::reset_caches();
  47. }
  48. break;
  49. case 'enable':
  50. if (!$formatplugins[$formatname]->is_enabled()) {
  51. unset_config('disabled', 'format_'. $formatname);
  52. core_plugin_manager::reset_caches();
  53. }
  54. break;
  55. case 'up':
  56. if ($sortorder[$formatname]) {
  57. $currentindex = $sortorder[$formatname];
  58. $seq = array_keys($formatplugins);
  59. $seq[$currentindex] = $seq[$currentindex-1];
  60. $seq[$currentindex-1] = $formatname;
  61. set_config('format_plugins_sortorder', implode(',', $seq));
  62. }
  63. break;
  64. case 'down':
  65. if ($sortorder[$formatname] < count($sortorder)-1) {
  66. $currentindex = $sortorder[$formatname];
  67. $seq = array_keys($formatplugins);
  68. $seq[$currentindex] = $seq[$currentindex+1];
  69. $seq[$currentindex+1] = $formatname;
  70. set_config('format_plugins_sortorder', implode(',', $seq));
  71. }
  72. break;
  73. }
  74. redirect($return);