function schools_administer_schools_form_submit
Search API
7.x schools.module | schools_administer_schools_form_submit($form, $form_state) |
6.x schools.module | schools_administer_schools_form_submit($form, $form_state) |
File
- modules/
schools/ schools.module, line 1372 - Schools module.
Code
function schools_administer_schools_form_submit($form, $form_state) {
$values = $form_state ["values"];
variable_set("schools_allow_courses_from_default_school", $values ["schools_allow_courses_from_default_school"]);
fp_add_message(t("Settings saved successfully."));
if (trim($values ["new_school"]) != "") {
$new_school = trim($values ["new_school"]);
if (!strstr($new_school, "~")) {
form_error("new_school", t("Sorry, but the format you entered was not correct. Plase enter a unique 1 to 5 character code for this school, tilda (~), then the name.
<br> Ex: ULM ~ University of Louisiana Monroe"));
return;
}
$temp = explode("~", $new_school);
$code = trim(strtoupper($temp [0]));
$new_school = trim($temp [1]);
// Clean up any trouble chars
$new_school = preg_replace("/[^a-zA-Z0-9_\-]/", " ", $new_school);
$code = preg_replace("/[^a-zA-Z0-9_]/", "", $code);
if ($code == "" || strlen($code) > 5) {
form_error("new_school", t("Sorry, but the format you entered was not correct. Plase enter a unique 1 to 5 character code for this school, tilda (~), then the name.
<br> Ex: ULM ~ University of Louisiana Monroe"));
return;
}
// Check that code is not already in use.
$temp = schools_get_school_id_from_school_code($code);
if ($temp) {
form_error("new_school", t("Sorry, but the code you specified is already in use."));
return;
}
// Okay, add to the roles table.
db_query("INSERT INTO schools (school_code, name) VALUES (?,?) ", strtoupper($code), $new_school);
fp_add_message(t("The new school has been added successfully."));
}
if (strstr($values ["perform_action2"], "del~_~")) {
$temp = explode("~_~", $values ["perform_action2"]);
$i = trim($temp [1]);
// Remove this rid from the table.
db_query("DELETE FROM schools WHERE school_id = ? ", $i);
fp_add_message(t("The school has been deleted successfully. All data linking to this school id (%i) still exists.", array("%i" => $i)));
}
if (strstr($values ["perform_action2"], "edit~_~")) {
$temp = explode("~_~", $values ["perform_action2"]);
$i = trim($temp [1]);
$new_school = trim($temp [2]);
if (!strstr($new_school, "~")) {
form_error("", t("Sorry, but the format you entered was not correct. Plase enter a unique 1 to 5 character code for this school, tilda (~), then the name.
<br> Ex: ULM ~ University of Louisiana Monroexxx"));
return;
}
$temp = explode("~", $new_school);
$code = trim(strtoupper($temp [0]));
$new_school = trim($temp [1]);
$new_school = preg_replace("/[^a-zA-Z0-9_\-]/", " ", $new_school);
$code = preg_replace("/[^a-zA-Z0-9_]/", "", $code);
// Check that code is not already in use
$temp = schools_get_school_id_from_school_code($code);
if ($temp) {
if ($temp != $i) { // meaning, it's not the school we are editing.
form_error("new_school", t("Sorry, but the code you specified is already in use."));
return;
}
}
if ($code == "" || strlen($code) > 5) {
form_error("", t("Sorry, but the format you entered was not correct. Plase enter a unique 1 to 5 character code for this school, tilda (~), then the name.
<br> Ex: ULM ~ University of Louisiana Monroe"));
return;
}
if (trim($new_school) != "") {
// Let's update the table.
db_query("UPDATE schools SET name = ?, school_code = ?
WHERE school_id = ? ", $new_school, strtoupper($code), $i);
fp_add_message(t("The school has been edited successfully."));
}
} // if edit
// Rebuild the menu cache, since other modules have tabs and/other menu items based on schools
menu_rebuild_cache(FALSE);
}