function admin_copy_degree_form_validate

7.x admin.degrees.inc admin_copy_degree_form_validate($form, $form_state)
6.x admin.degrees.inc admin_copy_degree_form_validate($form, $form_state)
5.x admin.degrees.inc admin_copy_degree_form_validate($form, $form_state)

Validate handler. Make sure our allow_overwrite setting is working. Check for existing major code.

File

modules/admin/admin.degrees.inc, line 198

Code

function admin_copy_degree_form_validate($form, $form_state) {

  $values = $form_state ["values"];

  $de_catalog_year = $values ["de_catalog_year"];
  $destination_major_code = trim(strtoupper($values ["destination_major_code"]));
  $school_id = intval($values ['school_id']);
  $destination_school_id = intval($values ['destination_school_id']);

  $source_major_code = trim(strtoupper($values ["source_major_code"]));
  $include_tracks = @$values ["include_tracks"]["yes"];

  $for_school = $school_name = "";
  if (module_enabled("schools")) {
    $for_school = " for school %school";
    $source_school_name = schools_get_school_name_for_id($school_id);
    $dest_school_name = schools_get_school_name_for_id($destination_school_id);
  }


  if (admin_string_contains_illegal_chars($destination_major_code)) {
    form_error("destination_major_code", t("Sorry, the destination major code must contain only numbers, letters, and dashes (-)."));
    return;
  }


  if ($values ["allow_overwrite"] == "no") {
    // Check to see if destination major code already exists.

    // First thing's first.  Make sure the sourceMajorCode exists.
    $res = db_query("SELECT * FROM draft_degrees 
                      WHERE major_code = ?                      
                      AND catalog_year = ? 
                      AND school_id = ? ", $destination_major_code, $de_catalog_year, $destination_school_id);
    if (db_num_rows($res) != 0) {
      // Meaning, it WAS be found.
      form_error("destination_major_code", t("The destination major, %dest, was found for %year$for_school.  Since you selected not to overwrite
                        existing majors, your submission was not processed.  Please try again.", array("%dest" => $destination_major_code, "%year" => $de_catalog_year, "%school" => $dest_school_name)));

    }

  } // allow_overwrite == no



  // First thing's first.  Make sure the sourceMajorCode exists.
  $res = db_query("SELECT * FROM draft_degrees 
                    WHERE (major_code = ?
                    OR major_code LIKE ?)
                    AND catalog_year = ? 
                    AND school_id = ? ", $source_major_code, "$source_major_code|%", $de_catalog_year, $school_id);
  if (db_num_rows($res) == 0) {
    // Meaning, it could not be found.    

    form_error("source_major_code", t("The source major, %source, could not be found for %year$for_school.", array("%source" => $source_major_code, "%year" => $de_catalog_year, "%school" => $source_school_name)));

  }


}