function course_search_edit_course_details_form_submit
Search API
6.x course_search.edit.inc | course_search_edit_course_details_form_submit($form, $form_state) |
4.x course_search.edit.inc | course_search_edit_course_details_form_submit($form, $form_state) |
5.x course_search.edit.inc | course_search_edit_course_details_form_submit($form, $form_state) |
File
- modules/
course_search/ course_search.edit.inc, line 264 - This file contains functions relating to editing the course info, like rotation schedule and syllabus
Code
function course_search_edit_course_details_form_submit($form, $form_state) {
global $user;
$faculty_id = $user->cwid;
$course_id = $form_state ["values"]["course_id"];
$subject_id = $form_state ["values"]["subject_id"];
$course_num = $form_state ["values"]["course_num"];
$school_id = intval($form_state ["values"]["school_id"]);
$_SESSION ['last_saved_school_id'] = $school_id;
$term_array = csv_to_array(variable_get_for_school("course_search_avail_term_id_suffix_order", '', $school_id));
for ($t = 1; $t <= 6; $t++) {
$year = $form_state ["values"]["year$t"];
// delete the existing entries for this year & course here.
db_query("DELETE FROM course_rotation_schedule
WHERE `course_id`= ?
AND `term_id` LIKE ? ", $course_id, "$year%");
/////////////////////////
// Now, for x = 1 to 5,
// if ($_request["cb_$year$x"] == "yes")
// then insert into table... blah blah...
foreach ($term_array as $x) {
if (isset($form_state ["values"]["cb_$year$x"]) && $form_state ["values"]["cb_$year$x"]["yes"] == "yes") {
$capacity = intval($form_state ["values"]["capacity_$year$x"]);
db_query("INSERT INTO course_rotation_schedule
(faculty_id, course_id, term_id, entry_value, posted, capacity)
VALUES (?, ?, ?, ?, ?, ?) ", $faculty_id, $course_id, "$year$x", "$subject_id~$course_num", time(), $capacity);
}
}
}
// Not anticipated check?
// delete first...
db_query("DELETE FROM course_rotation_schedule
WHERE course_id = ?
AND term_id = 'NOTA' ", $course_id);
if (isset($form_state ["values"]["not_anticipated"]) && $form_state ["values"]["not_anticipated"]["yes"] == "yes") {
db_query("INSERT INTO course_rotation_schedule
(faculty_id, course_id, term_id, entry_value, posted)
VALUES (?, ?, ?, ?, ?) ", $faculty_id, $course_id, "NOTA", "$subject_id~$course_num", time());
}
// Should we delete the current syllabus?
if (isset($form_state ["values"]["del_syllabus"]) && $form_state ["values"]["del_syllabus"]["yes"] == "yes") {
if ($details = course_search_get_course_syllabus_details($course_id)) {
$filename = $details ["filename"];
if ($filename != "") {
unlink("./custom/files/syllabi/$filename");
db_query("DELETE FROM course_syllabi
WHERE `course_id`= ? ", $course_id);
}
}
}
// Did the user try to upload a file?
if (trim($_FILES ["syllabus"]["tmp_name"][0]) != "")
{
$test = course_search_upload_attachment($course_id, $subject_id, $course_num);
if (!$test)
{
fp_add_message(t("There was an error uploading attachment. It is possible this is a write-permission
issue with the server."));
}
else {
// success.
}
}
watchdog('course_search', "edit_course_details course_id:$course_id, subject_id:$subject_id, course_num:$course_num, school_id:$school_id", array());
fp_add_message(t("This course's details have been updated successfully."));
}