-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete_course.php
85 lines (78 loc) · 3.19 KB
/
delete_course.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Edit course recompletion settings
*
* @package local_delete_course
* @copyright 2021 Marcelo A. Rauh Schmitt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__.'/../../config.php');
require_once($CFG->dirroot.'/course/lib.php');
require_once($CFG->libdir.'/formslib.php');
require_once('classes/confirm_form.php');
$id = required_param('id', PARAM_INT);
// Perform some basic access control checks.
if ($id) {
if ($id == SITEID) {
// Don't allow editing of 'site course' using this form.
throw new moodle_exception('cannoteditsiteform');
}
if (!$course = $DB->get_record('course', array('id' => $id))) {
throw new moodle_exception('invalidcourseid');
}
require_login($course);
$context = context_course::instance($course->id);
require_capability('local/delete_course:manage', $context);
} else {
require_login();
throw new moodle_exception('needcourseid');
}
// Setup PAGE.
$PAGE->set_course($course);
$PAGE->set_url('/local/delete_course/delete_course.php', array('id' => $course->id));
$PAGE->set_title($course->shortname);
$PAGE->set_heading($course->fullname);
$PAGE->set_pagelayout('admin');
$form = new local_delete_course_confirm_form('delete_course.php?id='.$id, array('course' => $course));
// Se foi cancelado.
if ($form->is_cancelled()) {
redirect($CFG->wwwroot.'/course/view.php?id='.$course->id);
} else if ($data = $form->get_data()) { // Se foi confirmado.
$strdeletingcourse = get_string("deletingcourse", "local_delete_course") . " " .
$course->shortname;
$categoryurl = new moodle_url('/course/index.php', array('categoryid' => $course->category));
$PAGE->navbar->add($strdeletingcourse);
$PAGE->set_title("$SITE->shortname: $strdeletingcourse");
$PAGE->set_heading($SITE->fullname);
echo $OUTPUT->header();
echo $OUTPUT->heading($strdeletingcourse);
// This might take a while. Raise the execution time limit.
core_php_time_limit::raise();
// We do this here because it spits out feedback as it goes.
delete_course($course);
echo $OUTPUT->heading( get_string("deletedcourse", "local_delete_course") . $course->shortname);
// Update course count in categories.
fix_course_sortorder();
echo $OUTPUT->continue_button($categoryurl);
echo $OUTPUT->footer();
exit; // We must exit here!!!
}
// Se foi a primeira vez.
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('delete_course', 'local_delete_course'));
$form->display();
echo $OUTPUT->footer();