2 // Edit course settings
4 require_once('../config.php');
5 require_once($CFG->dirroot
.'/enrol/enrol.class.php');
6 require_once($CFG->libdir
.'/blocklib.php');
7 require_once('lib.php');
8 require_once('edit_form.php');
10 $id = optional_param('id', 0, PARAM_INT
); // course id
11 $categoryid = optional_param('category', 0, PARAM_INT
); // course category - can be changed in edit form
15 /// basic access control checks
16 if ($id) { // editing course
17 if (!$course = get_record('course', 'id', $id)) {
18 error('Course ID was incorrect');
20 $category = get_record('course_categories', 'id', $course->category
);
21 require_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE
, $course->id
));
23 } else if ($categoryid) { // creating new course in this category
25 if (!$category = get_record('course_categories', 'id', $categoryid)) {
26 error('Category ID was incorrect');
28 require_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT
, $category->id
));
30 error('Either course id or category must be specified');
34 if (!empty($course)) {
35 $allowedmods = array();
36 if (!empty($course)) {
37 if ($am = get_records('course_allowed_modules','course',$course->id
)) {
39 $allowedmods[] = $m->module
;
42 if (empty($course->restrictmodules
)) {
43 $allowedmods = explode(',',$CFG->defaultallowedmodules
);
44 } // it'll be greyed out but we want these by default anyway.
46 $course->allowedmods
= $allowedmods;
48 if ($course->enrolstartdate
){
49 $course->enrolstartdisabled
= 0;
52 if ($course->enrolenddate
) {
53 $course->enrolenddisabled
= 0;
59 /// first create the form
60 $editform = new course_edit_form('edit.php', compact('course', 'category'));
61 // now override defaults if course already exists
62 if (!empty($course)) {
63 $editform->set_data($course);
65 if ($editform->is_cancelled()){
67 redirect($CFG->wwwroot
);
69 redirect($CFG->wwwroot
.'/course/view.php?id='.$course->id
);
72 } else if ($data = $editform->get_data()) {
74 /// process data if submitted
77 if ($data->enrolstartdisabled
){
78 $data->enrolstartdate
= 0;
81 if ($data->enrolenddisabled
) {
82 $data->enrolenddate
= 0;
85 $data->timemodified
= time();
88 if (!$course = create_course($data)) {
89 print_error('coursenotcreated');
92 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
94 // assign default role to creator if not already having permission to manage course assignments
95 if (!has_capability('moodle/course:view', $context) or !has_capability('moodle/role:assign', $context)) {
96 role_assign($CFG->creatornewroleid
, $USER->id
, 0, $context->id
);
99 if ($data->metacourse
and has_capability('moodle/course:managemetacourse', $context)) {
100 // Redirect users with metacourse capability to student import
101 redirect($CFG->wwwroot
."/course/importstudents.php?id=$course->id");
103 // Redirect to roles assignment
104 redirect($CFG->wwwroot
."/$CFG->admin/roles/assign.php?contextid=$context->id");
108 if (!update_course($data)) {
109 print_error('coursenotupdated');
112 redirect($CFG->wwwroot
."/course/view.php?id=$course->id");
121 $streditcoursesettings = get_string("editcoursesettings");
122 $straddnewcourse = get_string("addnewcourse");
123 $stradministration = get_string("administration");
124 $strcategories = get_string("categories");
126 if (!empty($course)) {
127 print_header($streditcoursesettings, $course->fullname
,
128 "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a>
129 -> $streditcoursesettings", $editform->focus());
131 print_header("$site->shortname: $straddnewcourse", $site->fullname
,
132 "<a href=\"$CFG->wwwroot/$CFG->admin/index.php\">$stradministration</a> -> ".
133 "<a href=\"index.php\">$strcategories</a> -> $straddnewcourse", $editform->focus());
136 print_heading($streditcoursesettings);
138 $editform->display();
140 print_footer($course);