mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
Changes to Course catagery editor to prevent duplicates
This commit is contained in:
parent
41b95af210
commit
fdf5a1e2fb
@ -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'");
|
||||
}
|
||||
|
@ -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";
|
||||
|
Loading…
x
Reference in New Issue
Block a user