Changes to Course catagery editor to prevent duplicates

This commit is contained in:
moodler 2003-01-17 02:03:42 +00:00
parent 41b95af210
commit fdf5a1e2fb
2 changed files with 19 additions and 4 deletions

View File

@ -39,17 +39,31 @@
foreach ($form as $key => $val) {
if ($key == "new") {
if (!empty($val)) {
$cat->name = $val;
if (!insert_record("course_categories", $cat)) {
error("Could not insert the new category '$val'");
if (get_records("course_categories", "name", $val)) {
notify(get_string("categoryduplicate", "", $val));
} else {
notify(get_string("categoryadded", "", $val));
$cat->name = $val;
if (!insert_record("course_categories", $cat)) {
error("Could not insert the new category '$val'");
} else {
notify(get_string("categoryadded", "", $val));
}
}
}
} else {
$cat->id = substr($key,1);
$cat->name = $val;
if ($existingcats = get_records("course_categories", "name", $val)) {
foreach($existingcats as $existingcat) {
if ($existingcat->id != $cat->id) {
notify(get_string("categoryduplicate", "", $val));
continue 2;
}
}
}
if (!update_record("course_categories", $cat)) {
error("Could not update the category '$val'");
}

View File

@ -40,6 +40,7 @@ $string['categories'] = "Course categories";
$string['category'] = "Category";
$string['categoryadded'] = "The category '\$a' was added";
$string['categorydeleted'] = "The category '\$a' was deleted";
$string['categoryduplicate'] = "A category named '\$a' already exists!";
$string['changepassword'] = "Change password";
$string['changedpassword'] = "Changed password";
$string['changessaved'] = "Changes saved";