-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblock_cegep_createcourse.php
56 lines (39 loc) · 1.58 KB
/
block_cegep_createcourse.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
<?php
require_once('../../config.php');
require('lib.php');
require('block_cegep_createcourse_form.php');
global $CFG, $DB, $USER, $PAGE, $OUTPUT;
$coursecode = optional_param('coursecode', null, PARAM_ALPHANUM);
require_login();
$coursetitle = cegep_local_get_course_title($coursecode);
$createcourse_form = new cegep_createcourse_form(null, array('coursecode' => $coursecode, 'coursetitle' => $coursetitle));
if ($createcourse_form->is_cancelled()){
redirect($CFG->wwwroot);
}
elseif ($data = $createcourse_form->get_data()) {
require_once('../../course/lib.php');
$course = cegep_local_new_course_template($data->coursecode);
$course->shortname = $course->idnumber;
$course->fullname = $data->fullname;
$course->visible = $data->visible;
$course = create_course($course);
if (is_object($course) && $course->id > 0) {
// Enrol current user (teacher) into the new course (except if admin)
if (!is_siteadmin($USER)) {
cegep_local_enrol_user($course->idnumber, $USER->username, 'editingteacher');
}
// Redirect to the enrolment form
redirect($CFG->wwwroot.'/blocks/cegep/block_cegep_enrolment.php?a=enrol&id=' . $course->id, get_string('coursecreatesuccess','block_cegep'));
} else {
print_error('errorcreatingcourse','block_cegep');
}
}
else {
$PAGE->navbar->add(get_string('coursecreate','block_cegep'));
$PAGE->set_heading('heading');
$PAGE->set_title(get_string('coursecreate','block_cegep'));
echo $OUTPUT->header();
$createcourse_form->display();
echo $OUTPUT->footer();
}
?>