function admin_add_degree_form_submit
Search API
7.x admin.degrees.inc | admin_add_degree_form_submit($form, $form_submit) |
6.x admin.degrees.inc | admin_add_degree_form_submit($form, $form_submit) |
4.x admin.degrees.inc | admin_add_degree_form_submit($form, $form_submit) |
5.x admin.degrees.inc | admin_add_degree_form_submit($form, $form_submit) |
Submit handler for the add_degree_form.
File
- modules/
admin/ admin.degrees.inc, line 388
Code
function admin_add_degree_form_submit($form, $form_submit) {
$values = $form_submit ["values"];
$de_catalog_year = $values ["de_catalog_year"];
// This will be used to add a new degree (and possibly track)
// to the database.
$major_code = trim(strtoupper($values ["major_code"]));
$track_code = trim(strtoupper($values ["track_code"]));
$new_major = $values ["new_major"];
$new_track = $values ["new_track"];
//////////////////////////////////////////////
if ($new_track == "new" && $track_code == "") {
form_error("track_code", t("You selected to add a track, but did not specify a track code."));
}
// Make sure user did not enter an underscore (_) in either
// the track or major code!
if (strstr($track_code, "_") || strstr($major_code, "_")) {
form_error("major_code", t("You are not allowed to enter underscores (_) in either the track code
or major code. FlightPath will add that for you. Please re-enter
your new degree without using an underscore."));
}
// Return since we have errors all ready.
if (form_has_errors()) {
return;
}
////////////////////////////////////////////////////
// First, deal with the major/concentration.
// Firstly, check to see if it already exists...
$res = db_query("SELECT * FROM draft_degrees
WHERE catalog_year = '?'
AND major_code = '?' ", $de_catalog_year, $major_code);
if (db_num_rows($res) > 0 && $new_major == "new") {
// Meaning, it already exists, yet we are trying to add it as a new
// major. This is an error!
fp_add_message(t("The major code %major_code already exists for %year. You cannot add it as a new major.", array("%major_code" => $major_code, "%year" => $de_catalog_year)), "error");
return;
}
if (db_num_rows($res) == 0 && $new_major == "existing") {
// This is another error. We are trying to add a track to an existing
// major code, but none was found.
fp_add_message(t("The major code %major_code could not be found in the system for %year. Perhaps you need to add it first?", array("%major_code" => $major_code, "%year" => $de_catalog_year)), "error");
return;
}
if (db_num_rows($res) == 0 && $new_major == "new") {
// This means we are trying to add a new major to the degrees table.
// We may proceed with this.
$db2 = new DatabaseHandler();
$degree_id = $db2->request_new_degree_id();
$db2->db_query("INSERT INTO draft_degrees
(degree_id, major_code, catalog_year)
values ('?', '?', '?') ", $degree_id, $major_code, $de_catalog_year);
}
if ($new_track == "new") {
//////////////////////////////////////////////////
// Now, let's see about adding ourself a track...
// First, check to see if it exists...
$res = db_query("SELECT * FROM draft_degree_tracks
WHERE catalog_year = '?'
AND major_code = '?'
AND track_code = '?' ", $de_catalog_year, $major_code, $track_code);
if (db_num_rows($res) > 0) {
// Meaning, it already existed, so we can't create it.
fp_add_message(t("The major and track code %major_code already exists for %year. You cannot add it as a new major/track code.", array("%major_code" => "$major_code $track_code", "%year" => $de_catalog_year)), "error");
return;
}
else {
// We can add it to the tracks table...
$db2 = new DatabaseHandler();
$db2->db_query("INSERT INTO draft_degree_tracks
(catalog_year, major_code, track_code)
values ('?', '?', '?') ", $de_catalog_year, $major_code, $track_code);
// Now, we also need to add this major & track code to the degrees table.
$new_major_code = $major_code;
if (strstr($major_code, "|")) {
// Already has a pipe, so it has a concentration.
$new_major_code .= "_$track_code";
}
else {
// No concentration...
$new_major_code .= "|_$track_code";
}
$degree_id = $db2->request_new_degree_id();
$db2->db_query("INSERT INTO draft_degrees
(degree_id, major_code, catalog_year)
values ('?', '?', '?') ", $degree_id, $new_major_code, $de_catalog_year);
}
}
// Success! We are done.
fp_add_message(t("The new degree %major_code was added successfully for %year.
You may add another degree, or use the menu at the top of the page to return to your list
of degrees, so you may begin editing the degree.", array("%major_code" => "$major_code $track_code", "%year" => $de_catalog_year)));
clear_session_form_values("admin_add_degree_form");
}