function course_search_edit_course_details_form_submit

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 207
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->id;

  $course_id = $form_state ["values"]["course_id"];
  $subject_id = $form_state ["values"]["subject_id"];
  $course_num = $form_state ["values"]["course_num"];

  //$term_array = get_term_id_suffixes();
  $term_array = csv_to_array(variable_get("course_search_avail_term_id_suffix_order"));


  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 ($form_state ["values"]["cb_$year$x"]["yes"] == "yes") {
        db_query("INSERT INTO course_rotation_schedule
                (faculty_id, course_id, term_id, entry_value, posted)
                VALUES ('?', '?', '?', '?', '?') ", $faculty_id, $course_id, "$year$x", "$subject_id~$course_num", time());
      }
    }

  }


  // Not anticipated check?

  // delete first...
  db_query("DELETE FROM course_rotation_schedule
            WHERE course_id = '?'
            AND term_id = 'NOTA' ", $course_id);

  if ($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 ($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"]) != "") 
   {
    $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.
    }
  }

  fp_add_message(t("This course's details have been updated successfully."));
  // TODO:  Do a "goto" back to wherever we came from
}