function prereqs_edit_course_form_validate

7.x prereqs.module prereqs_edit_course_form_validate($form, &$form_state)
6.x prereqs.module prereqs_edit_course_form_validate($form, &$form_state)

validate for the edit course form, from admin.courses.inc.

We want to check that the prereqs entered are valid.

File

modules/prereqs/prereqs.module, line 274
This is the module file for the prereqs module.

Code

function prereqs_edit_course_form_validate($form, &$form_state) {
  $prereqs = trim($form_state ["values"]["prereqs_prereqs"]);
  if ($prereqs == "") {
    return; //nothing there, so ignore.
  }

  $db = get_global_database_handler();
  $school_id = $db->get_school_id_for_course_id($form_state ["values"]["course_id"], TRUE);
  // TODO:  If schools_school exists, use THAT id instead?  

  // Turn into a friendly array.
  $prereq_array = prereqs_get_prereq_array_from_string($prereqs, $school_id);

  // If any of the courses in our array don't have valid course id's, it means
  // the course wasn't found.
  foreach ($prereq_array as $reqs) {

    foreach ($reqs as $details) {

      if (!$details ["course_id"] || $details ["course_id"] == 0) {
        form_error("prereqs_prereqs", t("Prereqs: Could not find course %course in any catalog year.  Check spelling and try again.", array("%course" => $details ["subject_id"] . " " . $details ["course_num"])));
        continue;
      }

      // also make sure they didn't enter the same course as its own prereq...
      if (intval($details ["course_id"]) == intval($form_state ["values"]["course_id"])) {
        form_error("prereqs_prereqs", t("Prereqs: You entered %course for a prereq but that is the course you are currently editing.  A course cannot be its own prereq.
                                          Please check your spelling and try again.", array("%course" => $details ["subject_id"] . " " . $details ["course_num"])));
        continue;
      }

    }

  }


}