]> git.mjollnir.org Git - moodle.git/commitdiff
Courses are forced to have unique shortnames (see bug 299)
authormoodler <moodler>
Sat, 1 Mar 2003 12:52:04 +0000 (12:52 +0000)
committermoodler <moodler>
Sat, 1 Mar 2003 12:52:04 +0000 (12:52 +0000)
course/edit.php
lang/en/moodle.php

index 9add1fa212a6ab7788ef67be7a7f5f59f51427f5..087fd2472779b738a083021e71db0bacb04b8a82 100644 (file)
@@ -41,7 +41,7 @@
 
             $form->timemodified = time();
 
-            if ($course) {
+            if (!empty($course)) {
                 if (update_record("course", $form)) {
                     add_to_log($course->id, "course", "update", "edit.php?id=$id", "");
                            redirect("view.php?id=$course->id", get_string("changessaved"));
@@ -160,6 +160,20 @@ function validate_form($course, &$form, &$err) {
     if (empty($form->shortname))
         $err["shortname"] = get_string("missingshortname");
 
+    if ($foundcourses = get_records("course", "shortname", $form->shortname)) {
+        if (!empty($course->id)) {
+            unset($foundcourses[$course->id]);
+        }
+        if (!empty($foundcourses)) {
+            foreach ($foundcourses as $foundcourse) {
+                $foundcoursenames[] = $foundcourse->fullname;
+            }
+            $foundcoursenamestring = addslashes(implode(',', $foundcoursenames));
+
+            $err["shortname"] = get_string("shortnametaken", "", $foundcoursenamestring);
+        }
+    }
+
     if (empty($form->summary))
         $err["summary"] = get_string("missingsummary");
 
index a7d32190b57d61c63c224e508f1c7e32d5b0831d..22f09bc89e9efd54474ed3e86ddc07862a0468fc 100644 (file)
@@ -448,6 +448,7 @@ $string['separateandconnected'] = "Separate and Connected ways of knowing";
 $string['serverlocaltime'] = "Server's local time";
 $string['settings'] = "Settings";
 $string['shortname'] = "Short name";
+$string['shortnametaken'] = "Short name is already used for another course (\$a)";
 $string['shortsitename'] = "Short name for site (eg single word)";
 $string['show'] = "Show";
 $string['showalltopics'] = "Show all topics";