]> git.mjollnir.org Git - moodle.git/commitdiff
Changes to Course catagery editor to prevent duplicates
authormoodler <moodler>
Fri, 17 Jan 2003 02:03:42 +0000 (02:03 +0000)
committermoodler <moodler>
Fri, 17 Jan 2003 02:03:42 +0000 (02:03 +0000)
course/categories.php
lang/en/moodle.php

index a07f95f3f0e5447b50c937575e2473b75efd55b6..b46a62d3f36557c82cd7534685e560aa39f60ae7 100644 (file)
         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'");
                 }
index a357f0914bc8b7e6c2e28592ace24cf6e471b822..f5496f561a1dca12d42427c9c120cce1efbdfd47 100644 (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";