From fdf5a1e2fb198876bf34afc61ee0a5570cec9a32 Mon Sep 17 00:00:00 2001 From: moodler Date: Fri, 17 Jan 2003 02:03:42 +0000 Subject: [PATCH] Changes to Course catagery editor to prevent duplicates --- course/categories.php | 22 ++++++++++++++++++---- lang/en/moodle.php | 1 + 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/course/categories.php b/course/categories.php index a07f95f3f0..b46a62d3f3 100644 --- a/course/categories.php +++ b/course/categories.php @@ -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'"); } diff --git a/lang/en/moodle.php b/lang/en/moodle.php index a357f0914b..f5496f561a 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -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"; -- 2.39.5