-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathduplicate.php
executable file
·111 lines (91 loc) · 4.02 KB
/
duplicate.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
// This file is part of local/courseduplication
//
// 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/>.
/**
* @package local_courseduplication
* @copyright 2014-2018 Liip AG <https://www.liip.ch/>
* @author Brian King <[email protected]>
* @author Claude Bossy <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once('../../config.php');
require_once($CFG->libdir . '/formslib.php');
require_once($CFG->dirroot . '/local/courseduplication/duplication_form.php');
require_once($CFG->dirroot . '/local/courseduplication/locallib.php');
$id = required_param('id', PARAM_INT);
$categoryid = optional_param('categoryid', 0, PARAM_INT);
$PAGE->set_url('/local/courseduplication/duplicate.php', array('id' => $id));
if (! $course = $DB->get_record("course", array('id' => $id))) {
throw new \moodle_exception('invalidcourseid');
}
require_course_login($course);
$coursecontext = context_course::instance($course->id);
$strduplicate = get_string('courseduplication', 'local_courseduplication');
$PAGE->set_pagelayout('incourse');
$PAGE->set_title($strduplicate);
$PAGE->set_heading($course->fullname);
// Init mform with base course id and category id as customdata.
$mform = new courseduplication_duplication_form(null, array(
'categoryid' => $categoryid ? $categoryid : $course->category,
'id' => $course->id)
);
if ($mform->is_cancelled()) {
redirect(new moodle_url('/course/view.php', array('id' => $course->id)));
}
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('duplicatecourseheader', 'local_courseduplication', $course));
if (!has_capability('local/courseduplication:backup_course', $coursecontext)) {
throw new \moodle_exception(
'nopermissions',
'error',
new moodle_url('/course/view.php', array('id' => $course->id)),
$strduplicate
);
}
echo $OUTPUT->box(
get_string('duplicatedesc', 'local_courseduplication')
);
if ($form = $mform->get_data()) {
if (!$category = $DB->get_record('course_categories', array('id' => $form->categoryid))) {
throw new \moodle_exception('errornosuchcategory', 'local_courseduplication');
}
if (!has_capability('local/courseduplication:restore_course', context_coursecat::instance($category->id))) {
throw new \moodle_exception(
'errornopermsintarget',
'local_courseduplication',
new moodle_url('/course/view.php', array('id' => $course->id))
);
}
local_course_duplication_queue::queue($USER->id, $form);
$notification = new \core\output\notification(
get_string('duplicationscheduled', 'local_courseduplication'),
\core\output\notification::NOTIFY_WARNING);
$notification->set_show_closebutton(false);
echo $OUTPUT->render($notification);
echo $OUTPUT->continue_button(new moodle_url('/my/index.php'));
} else {
// This branch is executed if the form is submitted but the data doesn't validate and the form should be redisplayed
// or on the first display of the form.
$notification = new \core\output\notification(
get_string('duplicationwillbescheduled', 'local_courseduplication'),
\core\output\notification::NOTIFY_INFO);
$notification->set_show_closebutton(false);
echo $OUTPUT->render($notification);
$mform->set_data(array(
'categoryid' => $categoryid ? $categoryid : $course->category,
'id' => $course->id));
$mform->display();
}
echo $OUTPUT->footer();