From: moodler Date: Sat, 1 Mar 2003 12:52:04 +0000 (+0000) Subject: Courses are forced to have unique shortnames (see bug 299) X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=068e57cebc164367764932c0ba317fc526b0f998;p=moodle.git Courses are forced to have unique shortnames (see bug 299) --- diff --git a/course/edit.php b/course/edit.php index 9add1fa212..087fd24727 100644 --- a/course/edit.php +++ b/course/edit.php @@ -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"); diff --git a/lang/en/moodle.php b/lang/en/moodle.php index a7d32190b5..22f09bc89e 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -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";