create.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. * Create admin bookmarks.
  18. *
  19. * @package block_admin_bookmarks
  20. * @copyright 2006 vinkmar
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. require('../../config.php');
  24. require_once($CFG->libdir.'/adminlib.php');
  25. require_login();
  26. $context = context_system::instance();
  27. $PAGE->set_context($context);
  28. $adminroot = admin_get_root(false, false); // settings not required - only pages
  29. if ($section = optional_param('section', '', PARAM_SAFEDIR) and confirm_sesskey()) {
  30. if (get_user_preferences('admin_bookmarks')) {
  31. $bookmarks = explode(',', get_user_preferences('admin_bookmarks'));
  32. if (in_array($section, $bookmarks)) {
  33. print_error('bookmarkalreadyexists','admin');
  34. die;
  35. }
  36. } else {
  37. $bookmarks = array();
  38. }
  39. $temp = $adminroot->locate($section);
  40. if ($temp instanceof admin_settingpage || $temp instanceof admin_externalpage) {
  41. $bookmarks[] = $section;
  42. $bookmarks = implode(',', $bookmarks);
  43. set_user_preference('admin_bookmarks', $bookmarks);
  44. } else {
  45. print_error('invalidsection','admin');
  46. die;
  47. }
  48. if ($temp instanceof admin_settingpage) {
  49. redirect($CFG->wwwroot . '/' . $CFG->admin . '/settings.php?section=' . $section);
  50. } elseif ($temp instanceof admin_externalpage) {
  51. redirect($temp->url);
  52. }
  53. } else {
  54. print_error('invalidsection','admin');
  55. die;
  56. }