2004-09-12 12:21:27 +00:00
|
|
|
<?php // $Id$
|
2002-08-11 15:41:54 +00:00
|
|
|
// Edit course settings
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2004-05-30 00:33:45 +00:00
|
|
|
require_once("../config.php");
|
|
|
|
require_once("lib.php");
|
2004-07-28 06:27:10 +00:00
|
|
|
require_once("$CFG->libdir/blocklib.php");
|
2006-03-09 02:48:29 +00:00
|
|
|
require_once("$CFG->dirroot/enrol/enrol.class.php");
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2006-03-07 19:36:13 +00:00
|
|
|
$id = optional_param('id', 0, PARAM_INT); // course id
|
2005-06-14 09:21:09 +00:00
|
|
|
$category = optional_param('category', 0, PARAM_INT); // possible default category
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2003-05-24 07:29:17 +00:00
|
|
|
require_login();
|
2005-01-24 22:21:28 +00:00
|
|
|
|
|
|
|
$disable_meta = false;
|
2005-10-29 16:18:18 +00:00
|
|
|
$focus = "";
|
2003-05-24 07:29:17 +00:00
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
if ($id) {
|
|
|
|
if (! $course = get_record("course", "id", $id)) {
|
|
|
|
error("Course ID was incorrect");
|
|
|
|
}
|
|
|
|
|
2003-08-16 05:40:27 +00:00
|
|
|
if (!isteacheredit($course->id)) {
|
|
|
|
error("You do not currently have editing privileges!");
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
2005-01-24 22:21:28 +00:00
|
|
|
|
|
|
|
if (course_in_meta($course)) {
|
|
|
|
$disable_meta = get_string('metaalreadyinmeta');
|
|
|
|
}
|
2005-01-25 04:33:02 +00:00
|
|
|
else if ($course->metacourse) {
|
|
|
|
if (count_records("course_meta","parent_course",$course->id) > 0) {
|
2005-01-24 22:21:28 +00:00
|
|
|
$disable_meta = get_string('metaalreadyhascourses');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (count_records("user_students","course",$course->id) > 0) {
|
|
|
|
$disable_meta = get_string('metaalreadyhasenrolments');
|
|
|
|
}
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
} else { // Admin is creating a new course
|
|
|
|
|
2003-02-24 18:48:55 +00:00
|
|
|
if (!iscreator()) {
|
2003-08-16 05:40:27 +00:00
|
|
|
error("You do not currently have course creation privileges!");
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
2003-04-17 13:20:26 +00:00
|
|
|
|
|
|
|
$course = NULL;
|
2002-08-08 15:51:23 +00:00
|
|
|
}
|
2002-06-02 08:10:50 +00:00
|
|
|
|
2002-08-08 15:51:23 +00:00
|
|
|
if (! $site = get_site()) {
|
2003-04-10 13:46:52 +00:00
|
|
|
redirect("$CFG->wwwroot/$CFG->admin/index.php");
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// If data submitted, then process and store.
|
|
|
|
|
2004-10-08 18:13:05 +00:00
|
|
|
if ($form = data_submitted() and confirm_sesskey()) {
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2004-08-12 07:52:44 +00:00
|
|
|
if (empty($course)) {
|
|
|
|
check_for_restricted_user($USER->username, "$CFG->wwwroot");
|
|
|
|
} else {
|
|
|
|
check_for_restricted_user($USER->username, "$CFG->wwwroot/course/view.php?id=$course->id");
|
|
|
|
}
|
2004-02-04 12:45:35 +00:00
|
|
|
|
2002-07-29 15:10:21 +00:00
|
|
|
$form->startdate = make_timestamp($form->startyear, $form->startmonth, $form->startday);
|
2005-10-29 16:18:18 +00:00
|
|
|
$form->category = clean_param($form->category, PARAM_INT);
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2005-10-04 01:59:19 +00:00
|
|
|
if (empty($form->enrolstartdisabled)) {
|
|
|
|
$form->enrolstartdate = make_timestamp($form->enrolstartyear, $form->enrolstartmonth, $form->enrolstartday);
|
|
|
|
} else {
|
|
|
|
$form->enrolstartdate = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($form->enrolenddisabled)) {
|
|
|
|
$form->enrolenddate = make_timestamp($form->enrolendyear, $form->enrolendmonth, $form->enrolendday);
|
|
|
|
} else {
|
|
|
|
$form->enrolenddate = 0;
|
|
|
|
}
|
|
|
|
|
2005-01-22 09:00:42 +00:00
|
|
|
$form->format = optional_param('format', 'social', PARAM_ALPHA);
|
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
validate_form($course, $form, $err);
|
|
|
|
|
|
|
|
if (count($err) == 0) {
|
|
|
|
|
2005-08-16 06:15:49 +00:00
|
|
|
$allowedmods = array();
|
|
|
|
if (!empty($form->allowedmods)) {
|
|
|
|
$allowedmods = $form->allowedmods;
|
|
|
|
unset($form->allowedmods);
|
|
|
|
}
|
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
$form->timemodified = time();
|
2005-08-16 06:15:49 +00:00
|
|
|
|
2003-03-01 12:52:04 +00:00
|
|
|
if (!empty($course)) {
|
2004-08-22 16:49:40 +00:00
|
|
|
// Test for and remove blocks which aren't appropriate anymore
|
2005-01-31 02:18:15 +00:00
|
|
|
$page = page_create_object(PAGE_COURSE_VIEW, $course->id);
|
2004-10-19 21:04:28 +00:00
|
|
|
blocks_remove_inappropriate($page);
|
2004-08-22 16:49:40 +00:00
|
|
|
|
|
|
|
// Update with the new data
|
2004-11-08 19:36:07 +00:00
|
|
|
if (update_record('course', $form)) {
|
2002-05-31 09:27:30 +00:00
|
|
|
add_to_log($course->id, "course", "update", "edit.php?id=$id", "");
|
2005-08-16 06:15:49 +00:00
|
|
|
if (isadmin()) {
|
|
|
|
$course->restrictmodules = $form->restrictmodules;
|
|
|
|
update_restricted_mods($course,$allowedmods);
|
|
|
|
}
|
2004-05-30 00:33:45 +00:00
|
|
|
fix_course_sortorder();
|
2004-11-08 19:36:07 +00:00
|
|
|
redirect($page->url_get_full(), get_string('changessaved'));
|
2001-11-22 06:23:56 +00:00
|
|
|
} else {
|
|
|
|
error("Serious Error! Could not update the course record! (id = $form->id)");
|
|
|
|
}
|
|
|
|
} else {
|
2002-06-10 11:30:02 +00:00
|
|
|
$form->timecreated = time();
|
|
|
|
|
2005-01-25 05:03:43 +00:00
|
|
|
// place at beginning of category
|
|
|
|
fix_course_sortorder();
|
2005-02-24 21:22:06 +00:00
|
|
|
$form->sortorder = get_field_sql("SELECT min(sortorder)-1 FROM {$CFG->prefix}course WHERE category=$form->category");
|
|
|
|
if (empty($form->sortorder)) {
|
|
|
|
$form->sortorder = 100;
|
|
|
|
}
|
2005-01-25 05:03:43 +00:00
|
|
|
|
2004-11-08 19:36:07 +00:00
|
|
|
if ($newcourseid = insert_record('course', $form)) { // Set up new course
|
2004-10-19 21:04:28 +00:00
|
|
|
|
|
|
|
// Setup the blocks
|
2005-01-31 02:18:15 +00:00
|
|
|
$page = page_create_object(PAGE_COURSE_VIEW, $newcourseid);
|
2004-10-19 21:04:28 +00:00
|
|
|
blocks_repopulate_page($page); // Return value not checked because you can always edit later
|
|
|
|
|
2005-08-16 06:15:49 +00:00
|
|
|
if (isadmin()) {
|
|
|
|
$course = get_record("course","id",$newcourseid);
|
|
|
|
update_restricted_mods($course,$allowedmods);
|
|
|
|
}
|
|
|
|
|
2003-02-26 04:18:46 +00:00
|
|
|
$section = NULL;
|
|
|
|
$section->course = $newcourseid; // Create a default section.
|
2002-06-25 11:49:06 +00:00
|
|
|
$section->section = 0;
|
|
|
|
$section->id = insert_record("course_sections", $section);
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2004-05-30 00:33:45 +00:00
|
|
|
fix_course_sortorder();
|
2005-03-14 07:31:47 +00:00
|
|
|
add_to_log(SITEID, "course", "new", "view.php?id=$newcourseid", "$form->fullname (ID $newcourseid)");
|
2003-02-26 04:18:46 +00:00
|
|
|
|
|
|
|
if (isadmin()) { // Redirect admin to add teachers
|
2003-08-15 13:59:24 +00:00
|
|
|
redirect("teacher.php?id=$newcourseid", get_string("changessaved"));
|
2003-02-26 04:18:46 +00:00
|
|
|
|
|
|
|
} else { // Add current teacher and send to course
|
2004-04-29 10:28:58 +00:00
|
|
|
|
2003-02-26 04:18:46 +00:00
|
|
|
$newteacher = NULL;
|
|
|
|
$newteacher->userid = $USER->id;
|
|
|
|
$newteacher->course = $newcourseid;
|
|
|
|
$newteacher->authority = 1; // First teacher is the main teacher
|
2003-08-16 05:40:27 +00:00
|
|
|
$newteacher->editall = 1; // Course creator can edit their own course
|
2003-02-26 04:18:46 +00:00
|
|
|
|
|
|
|
if (!$newteacher->id = insert_record("user_teachers", $newteacher)) {
|
|
|
|
error("Could not add you to this new course!");
|
|
|
|
}
|
|
|
|
|
|
|
|
$USER->teacher[$newcourseid] = true;
|
2003-08-16 05:40:27 +00:00
|
|
|
$USER->teacheredit[$newcourseid] = true;
|
2003-02-26 04:18:46 +00:00
|
|
|
|
2005-02-24 21:22:06 +00:00
|
|
|
fix_course_sortorder();
|
|
|
|
|
2003-02-26 04:18:46 +00:00
|
|
|
redirect("view.php?id=$newcourseid", get_string("changessaved"));
|
2003-02-25 10:45:37 +00:00
|
|
|
}
|
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
} else {
|
|
|
|
error("Serious Error! Could not create the new course!");
|
|
|
|
}
|
|
|
|
}
|
2004-05-30 00:33:45 +00:00
|
|
|
die;
|
2001-11-22 06:23:56 +00:00
|
|
|
} else {
|
|
|
|
foreach ($err as $key => $value) {
|
|
|
|
$focus = "form.$key";
|
|
|
|
}
|
2004-04-29 10:28:58 +00:00
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
2004-05-30 00:33:45 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
|
|
|
/// Otherwise fill and print the form.
|
|
|
|
|
2002-12-30 06:07:03 +00:00
|
|
|
if (empty($form)) {
|
2003-01-13 12:16:46 +00:00
|
|
|
if (!empty($course)) {
|
2001-11-22 06:23:56 +00:00
|
|
|
$form = $course;
|
|
|
|
} else {
|
2002-07-29 15:10:21 +00:00
|
|
|
$form->startdate = time() + 3600 * 24;
|
2002-08-04 02:10:00 +00:00
|
|
|
$form->fullname = get_string("defaultcoursefullname");
|
|
|
|
$form->shortname = get_string("defaultcourseshortname");
|
|
|
|
$form->summary = get_string("defaultcoursesummary");
|
2002-06-25 11:49:06 +00:00
|
|
|
$form->format = "weeks";
|
2003-01-20 09:30:24 +00:00
|
|
|
$form->password = "";
|
2003-01-13 12:16:46 +00:00
|
|
|
$form->guest = 0;
|
2002-06-25 11:49:06 +00:00
|
|
|
$form->numsections = 10;
|
2004-07-28 06:27:10 +00:00
|
|
|
$form->idnumber = '';
|
|
|
|
$form->cost = '';
|
2005-07-22 18:52:58 +00:00
|
|
|
$form->currency = empty($CFG->enrol_currency) ? 'USD' : $CFG->enrol_currency;
|
2002-06-25 11:49:06 +00:00
|
|
|
$form->newsitems = 5;
|
2003-09-08 13:01:47 +00:00
|
|
|
$form->showgrades = 1;
|
2003-12-30 17:18:06 +00:00
|
|
|
$form->groupmode = 0;
|
|
|
|
$form->groupmodeforce = 0;
|
2003-08-09 16:53:30 +00:00
|
|
|
$form->category = $category;
|
2003-04-17 13:20:26 +00:00
|
|
|
$form->id = "";
|
2003-07-21 07:31:01 +00:00
|
|
|
$form->visible = 1;
|
2003-08-23 07:26:50 +00:00
|
|
|
|
|
|
|
if (current_language() == $CFG->lang) {
|
|
|
|
$form->teacher = $site->teacher;
|
|
|
|
$form->teachers = $site->teachers;
|
|
|
|
$form->student = $site->student;
|
|
|
|
$form->students = $site->students;
|
|
|
|
} else {
|
|
|
|
$form->teacher = get_string("defaultcourseteacher");
|
|
|
|
$form->teachers = get_string("defaultcourseteachers");
|
|
|
|
$form->student = get_string("defaultcoursestudent");
|
|
|
|
$form->students = get_string("defaultcoursestudents");
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-20 14:44:14 +00:00
|
|
|
$form->categories = get_records_select_menu("course_categories", "", "name", "id,name");
|
2003-12-21 04:52:25 +00:00
|
|
|
|
|
|
|
$courseformats = get_list_of_plugins("course/format");
|
|
|
|
$form->courseformats = array();
|
|
|
|
|
|
|
|
foreach ($courseformats as $courseformat) {
|
|
|
|
$form->courseformats["$courseformat"] = get_string("format$courseformat");
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2005-08-16 06:15:49 +00:00
|
|
|
if (empty($allowedmods)) {
|
|
|
|
$allowedmods = array();
|
|
|
|
if (!empty($course)) {
|
|
|
|
if ($am = get_records("course_allowed_modules","course",$course->id)) {
|
|
|
|
foreach ($am as $m) {
|
|
|
|
$allowedmods[] = $m->module;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (empty($course->restrictmodules)) {
|
|
|
|
$allowedmods = explode(',',$CFG->defaultallowedmodules);
|
|
|
|
} // it'll be greyed out but we want these by default anyway.
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ($CFG->restrictmodulesfor == 'all') {
|
|
|
|
$allowedmods = explode(',',$CFG->defaultallowedmodules);
|
|
|
|
if (!empty($CFG->restrictbydefault)) {
|
|
|
|
$form->restrictmodules = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-30 17:18:06 +00:00
|
|
|
$usehtmleditor = can_use_html_editor();
|
|
|
|
|
2002-08-04 02:10:00 +00:00
|
|
|
$streditcoursesettings = get_string("editcoursesettings");
|
2002-08-08 15:51:23 +00:00
|
|
|
$straddnewcourse = get_string("addnewcourse");
|
|
|
|
$stradministration = get_string("administration");
|
2003-08-09 16:53:30 +00:00
|
|
|
$strcategories = get_string("categories");
|
2002-07-19 12:01:35 +00:00
|
|
|
|
2003-04-17 13:20:26 +00:00
|
|
|
if (!empty($course)) {
|
2004-05-30 00:33:45 +00:00
|
|
|
print_header($streditcoursesettings, "$course->fullname",
|
2004-04-29 10:28:58 +00:00
|
|
|
"<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a>
|
2002-08-04 02:10:00 +00:00
|
|
|
-> $streditcoursesettings", $focus);
|
2002-06-02 08:10:50 +00:00
|
|
|
} else {
|
2002-09-27 14:26:02 +00:00
|
|
|
print_header("$site->shortname: $straddnewcourse", "$site->fullname",
|
2003-08-09 16:53:30 +00:00
|
|
|
"<a href=\"../$CFG->admin/index.php\">$stradministration</a> -> ".
|
|
|
|
"<a href=\"index.php\">$strcategories</a> -> $straddnewcourse", $focus);
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2004-10-08 18:13:05 +00:00
|
|
|
$form->sesskey = !empty($USER->id) ? $USER->sesskey : '';
|
|
|
|
|
2002-08-04 02:10:00 +00:00
|
|
|
print_heading($streditcoursesettings);
|
2005-01-25 14:03:43 +00:00
|
|
|
print_simple_box_start("center");
|
2004-05-30 00:33:45 +00:00
|
|
|
include("edit.html");
|
2001-11-22 06:23:56 +00:00
|
|
|
print_simple_box_end();
|
|
|
|
|
|
|
|
print_footer($course);
|
|
|
|
|
2004-04-29 10:28:58 +00:00
|
|
|
if ($usehtmleditor) {
|
2004-06-04 06:17:30 +00:00
|
|
|
use_html_editor("summary");
|
2003-12-30 17:18:06 +00:00
|
|
|
}
|
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
exit;
|
|
|
|
|
|
|
|
/// Functions /////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
function validate_form($course, &$form, &$err) {
|
|
|
|
|
2005-10-04 01:59:19 +00:00
|
|
|
if (empty($form->enrolenddisabled) && $form->enrolenddate <= $form->enrolstartdate) {
|
|
|
|
$err["enroldate"] = get_string("enrolenddaterror");
|
|
|
|
}
|
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
if (empty($form->fullname))
|
2002-08-04 02:10:00 +00:00
|
|
|
$err["fullname"] = get_string("missingfullname");
|
2001-11-22 06:23:56 +00:00
|
|
|
|
|
|
|
if (empty($form->shortname))
|
2002-08-04 02:10:00 +00:00
|
|
|
$err["shortname"] = get_string("missingshortname");
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2003-03-01 12:52:04 +00:00
|
|
|
if ($foundcourses = get_records("course", "shortname", $form->shortname)) {
|
|
|
|
if (!empty($course->id)) {
|
|
|
|
unset($foundcourses[$course->id]);
|
|
|
|
}
|
|
|
|
if (!empty($foundcourses)) {
|
|
|
|
foreach ($foundcourses as $foundcourse) {
|
|
|
|
$foundcoursenames[] = $foundcourse->fullname;
|
|
|
|
}
|
|
|
|
$foundcoursenamestring = addslashes(implode(',', $foundcoursenames));
|
|
|
|
|
|
|
|
$err["shortname"] = get_string("shortnametaken", "", $foundcoursenamestring);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
if (empty($form->summary))
|
2002-08-04 02:10:00 +00:00
|
|
|
$err["summary"] = get_string("missingsummary");
|
2001-11-22 06:23:56 +00:00
|
|
|
|
|
|
|
if (empty($form->teacher))
|
2002-08-04 02:10:00 +00:00
|
|
|
$err["teacher"] = get_string("missingteacher");
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-06-02 08:10:50 +00:00
|
|
|
if (empty($form->student))
|
2002-08-04 02:10:00 +00:00
|
|
|
$err["student"] = get_string("missingstudent");
|
2001-11-22 06:23:56 +00:00
|
|
|
|
|
|
|
if (! $form->category)
|
2002-08-04 02:10:00 +00:00
|
|
|
$err["category"] = get_string("missingcategory");
|
2001-11-22 06:23:56 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|