2001-11-22 06:23:56 +00:00
|
|
|
<?PHP // $Id$
|
|
|
|
|
|
|
|
require("../config.php");
|
|
|
|
require("lib.php");
|
|
|
|
|
|
|
|
optional_variable($id, 0); // course id
|
|
|
|
|
|
|
|
if ($id) {
|
|
|
|
if (! $course = get_record("course", "id", $id)) {
|
|
|
|
error("Course ID was incorrect");
|
|
|
|
}
|
|
|
|
|
|
|
|
require_login($course->id);
|
|
|
|
|
2002-04-03 06:36:04 +00:00
|
|
|
if (!isteacher($course->id)) {
|
2001-11-22 06:23:56 +00:00
|
|
|
error("Only teachers can edit the course!");
|
|
|
|
}
|
|
|
|
} else { // Admin is creating a new course
|
|
|
|
require_login();
|
|
|
|
|
|
|
|
if (!isadmin()) {
|
|
|
|
error("Only administrators can use this page");
|
|
|
|
}
|
2002-06-02 08:10:50 +00:00
|
|
|
|
2002-07-11 05:30:10 +00:00
|
|
|
if (! $site = get_site()) {
|
2002-06-02 08:10:50 +00:00
|
|
|
redirect("$CFG->wwwroot/admin/");
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// If data submitted, then process and store.
|
|
|
|
|
|
|
|
if (match_referer() && isset($HTTP_POST_VARS)) {
|
|
|
|
|
|
|
|
$form = (object)$HTTP_POST_VARS;
|
|
|
|
|
|
|
|
$form->startdate = mktime(0,0,0,(int)$form->startmonth,(int)$form->startday,(int)$form->startyear);
|
|
|
|
|
|
|
|
validate_form($course, $form, $err);
|
|
|
|
|
|
|
|
|
|
|
|
if (count($err) == 0) {
|
|
|
|
|
|
|
|
$form->timemodified = time();
|
|
|
|
|
|
|
|
if ($course) {
|
|
|
|
if (update_record("course", $form)) {
|
2002-05-31 09:27:30 +00:00
|
|
|
add_to_log($course->id, "course", "update", "edit.php?id=$id", "");
|
2001-11-22 06:23:56 +00:00
|
|
|
redirect("view.php?id=$course->id", "Changes saved");
|
|
|
|
} 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();
|
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
if ($newid = insert_record("course", $form)) { // Set up new course
|
2002-06-25 11:49:06 +00:00
|
|
|
$section->course = $newid; // Create a default section.
|
|
|
|
$section->section = 0;
|
|
|
|
$section->timemodified = time();
|
|
|
|
$section->id = insert_record("course_sections", $section);
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-05-31 09:27:30 +00:00
|
|
|
add_to_log($newid, "course", "new", "view.php?id=$newid", "");
|
2001-11-22 06:23:56 +00:00
|
|
|
redirect("$CFG->wwwroot/admin/teacher.php?id=$newid", "Changes saved");
|
|
|
|
} else {
|
|
|
|
error("Serious Error! Could not create the new course!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
die;
|
|
|
|
} else {
|
|
|
|
foreach ($err as $key => $value) {
|
|
|
|
$focus = "form.$key";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Otherwise fill and print the form.
|
|
|
|
|
|
|
|
if (!$form) {
|
|
|
|
if ($course) {
|
|
|
|
$form = $course;
|
|
|
|
$ts = getdate($course->startdate);
|
|
|
|
} else {
|
|
|
|
$ts = getdate(time() + 3600 * 24);
|
2002-06-02 08:10:50 +00:00
|
|
|
$form->teacher = "Facilitator";
|
|
|
|
$form->student = "Student";
|
|
|
|
$form->fullname = "Course Fullname 101";
|
|
|
|
$form->shortname = "CF101";
|
|
|
|
$form->summary = "Write a concise and interesting paragraph here that explains what this course is about.";
|
2002-06-25 11:49:06 +00:00
|
|
|
$form->format = "weeks";
|
|
|
|
$form->numsections = 10;
|
|
|
|
$form->newsitems = 5;
|
2002-06-02 08:10:50 +00:00
|
|
|
$form->category = 1;
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$form->startday = $ts[mday];
|
|
|
|
$form->startmonth = $ts[mon];
|
|
|
|
$form->startyear = $ts[year];
|
|
|
|
|
|
|
|
$form->endday = $te[mday];
|
|
|
|
$form->endmonth = $te[mon];
|
|
|
|
$form->endyear = $te[year];
|
|
|
|
}
|
|
|
|
|
|
|
|
for ($i=1;$i<=31;$i++) {
|
|
|
|
$form->days[$i] = "$i";
|
|
|
|
}
|
|
|
|
for ($i=1;$i<=12;$i++) {
|
|
|
|
$form->months[$i] = date("F", mktime(0,0,0,$i,1,2000));
|
|
|
|
}
|
2002-06-25 11:49:06 +00:00
|
|
|
for ($i=2000;$i<=2010;$i++) {
|
2001-11-22 06:23:56 +00:00
|
|
|
$form->years[$i] = $i;
|
|
|
|
}
|
|
|
|
|
|
|
|
$form->categories = get_records_sql_menu("SELECT id,name FROM course_categories");
|
|
|
|
|
|
|
|
//$form->owners = get_records_sql_menu("SELECT u.id, CONCAT(u.firstname, " ", u.lastname) FROM users u, teachers t WHERE t.user = u.id");
|
|
|
|
|
2002-06-02 08:10:50 +00:00
|
|
|
if (isset($course)) {
|
2001-11-22 06:23:56 +00:00
|
|
|
print_header("Edit course settings", "$course->fullname",
|
|
|
|
"<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A>
|
|
|
|
-> Edit course settings", $focus);
|
2002-06-02 08:10:50 +00:00
|
|
|
} else {
|
|
|
|
print_header("Admin: Creating a new course", "$site->shortname: Administration",
|
|
|
|
"<A HREF=\"$CFG->wwwroot/admin/\">Admin</A>
|
|
|
|
-> Create a new course", $focus);
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
print_simple_box_start("center", "", "$THEME->cellheading");
|
|
|
|
print_heading("Editing course settings");
|
|
|
|
include("edit.html");
|
|
|
|
print_simple_box_end();
|
|
|
|
|
|
|
|
print_footer($course);
|
|
|
|
|
|
|
|
exit;
|
|
|
|
|
|
|
|
/// Functions /////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
function validate_form($course, &$form, &$err) {
|
|
|
|
|
|
|
|
if (empty($form->fullname))
|
|
|
|
$err["fullname"] = "Missing full name";
|
|
|
|
|
|
|
|
if (empty($form->shortname))
|
|
|
|
$err["shortname"] = "Missing short name";
|
|
|
|
|
|
|
|
if (empty($form->summary))
|
|
|
|
$err["summary"] = "Missing summary";
|
|
|
|
|
|
|
|
if (empty($form->teacher))
|
2002-06-02 08:10:50 +00:00
|
|
|
$err["teacher"] = "Must choose something";
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-06-02 08:10:50 +00:00
|
|
|
if (empty($form->student))
|
|
|
|
$err["student"] = "Must choose something";
|
2001-11-22 06:23:56 +00:00
|
|
|
|
|
|
|
if (! $form->category)
|
|
|
|
$err["category"] = "You need to choose a category";
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|