Merge branch 'MDL-40920_master' of https://github.com/markn86/moodle
[moodle.git] / course / manage.php
blob8670abdca21349de460a405c9074cf5be8d20912
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.
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/>.
17 /**
18 * Allows the admin to create, delete and rename course categories rearrange courses
20 * This script has been deprecated since Moodle 2.6.
21 * Please update your links as
23 * @deprecated
24 * @todo remove in 2.7 MDL-41502
25 * @package core_course
26 * @copyright 2013 Marina Glancy
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30 require_once("../config.php");
31 require_once($CFG->dirroot.'/course/lib.php');
32 require_once($CFG->libdir.'/coursecatlib.php');
34 $id = optional_param('categoryid', 0, PARAM_INT); // Category id.
35 $page = optional_param('page', 0, PARAM_INT); // Which page to show.
36 $perpage = optional_param('perpage', $CFG->coursesperpage, PARAM_INT); // How many per page.
37 $search = optional_param('search', '', PARAM_RAW); // Search words.
38 $blocklist = optional_param('blocklist', 0, PARAM_INT);
39 $modulelist = optional_param('modulelist', '', PARAM_PLUGIN);
41 debugging('This script has been deprecated and will be removed in the future. Please update any bookmarks you have.',
42 DEBUG_DEVELOPER);
44 // Look for legacy actions.
45 // If there are any we're going to make and equivalent request to management.php.
46 $sesskey = optional_param('sesskey', null, PARAM_RAW);
47 if ($sesskey !== null && confirm_sesskey($sesskey)) {
48 // Actions to manage categories.
49 $deletecat = optional_param('deletecat', 0, PARAM_INT);
50 $hidecat = optional_param('hidecat', 0, PARAM_INT);
51 $showcat = optional_param('showcat', 0, PARAM_INT);
52 $movecat = optional_param('movecat', 0, PARAM_INT);
53 $movetocat = optional_param('movetocat', -1, PARAM_INT);
54 $moveupcat = optional_param('moveupcat', 0, PARAM_INT);
55 $movedowncat = optional_param('movedowncat', 0, PARAM_INT);
57 // Actions to manage courses.
58 $hide = optional_param('hide', 0, PARAM_INT);
59 $show = optional_param('show', 0, PARAM_INT);
60 $moveup = optional_param('moveup', 0, PARAM_INT);
61 $movedown = optional_param('movedown', 0, PARAM_INT);
62 $moveto = optional_param('moveto', 0, PARAM_INT);
63 $resort = optional_param('resort', 0, PARAM_BOOL);
65 $murl = new moodle_url('/course/management.php', array('sesskey' => sesskey()));
67 // Process any category actions.
68 if (!empty($deletecat)) {
69 // Redirect to the new management script.
70 redirect(new moodle_url($murl, array('categoryid' => $deletecat, 'action' => 'deletecategory')));
73 if (!empty($movecat) and $movetocat >= 0) {
74 // Redirect to the new management script.
75 redirect(new moodle_url($murl, array(
76 'action' => 'bulkaction',
77 'bulkmovecategories' => true,
78 'movecategoriesto' => $movetocat,
79 'bcat[]' => $movecat
80 )));
83 // Hide or show a category.
84 if ($hidecat) {
85 // Redirect to the new management script.
86 redirect(new moodle_url($murl, array('categoryid' => $hidecat, 'action' => 'hidecategory')));
87 } else if ($showcat) {
88 // Redirect to the new management script.
89 redirect(new moodle_url($murl, array('categoryid' => $showcat, 'action' => 'showcategory')));
92 if (!empty($moveupcat) or !empty($movedowncat)) {
93 // Redirect to the new management script.
94 if (!empty($moveupcat)) {
95 redirect(new moodle_url($murl, array('categoryid' => $moveupcat, 'action' => 'movecategoryup')));
96 } else {
97 redirect(new moodle_url($murl, array('categoryid' => $movedowncat, 'action' => 'movecategorydown')));
101 if ($resort && $id) {
102 // Redirect to the new management script.
103 redirect(new moodle_url($murl, array('categoryid' => $id, 'action' => 'resortcategories', 'resort' => 'name')));
106 if (!empty($moveto) && ($data = data_submitted())) {
107 // Redirect to the new management script.
108 $courses = array();
109 foreach ($data as $key => $value) {
110 if (preg_match('/^c\d+$/', $key)) {
111 $courses[] = substr($key, 1);
114 redirect(new moodle_url($murl, array(
115 'action' => 'bulkaction',
116 'bulkmovecourses' => true,
117 'movecoursesto' => $moveto,
118 'bc' => $courses
119 )));
122 if (!empty($hide) or !empty($show)) {
123 // Redirect to the new management script.
124 if (!empty($hide)) {
125 redirect(new moodle_url($murl, array('courseid' => $hide, 'action' => 'hidecourse')));
126 } else {
127 redirect(new moodle_url($murl, array('courseid' => $show, 'action' => 'showcourse')));
131 if (!empty($moveup) or !empty($movedown)) {
132 // Redirect to the new management script.
133 if (!empty($moveup)) {
134 redirect(new moodle_url($murl, array('courseid' => $moveup, 'action' => 'movecourseup')));
135 } else {
136 redirect(new moodle_url($murl, array('courseid' => $movedown, 'action' => 'movecoursedown')));
141 // Now check if its a search or not. If its not we'll head to the new management page.
142 $url = new moodle_url('/course/management.php');
143 if ($id !== 0) {
144 // We've got an ID it can't be a search.
145 $url->param('categoryid', $id);
146 } else {
147 // No $id, perhaps its a search.
148 if ($search !== '') {
149 $url->param('search', $search);
151 if ($blocklist !== 0) {
152 $url->param('blocklist', $blocklist);
154 if ($modulelist !== '') {
155 $url->param('modulelist', $modulelist);
158 redirect($url);