]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10999 Cannot Insert or Edit a Label
authorskodak <skodak>
Sun, 26 Aug 2007 07:44:14 +0000 (07:44 +0000)
committerskodak <skodak>
Sun, 26 Aug 2007 07:44:14 +0000 (07:44 +0000)
course/modedit.php
course/moodleform_mod.php

index 7f575ec0908ce5b603eaa71bbac629e3a07b05d0..1792d0fb9e1a5a8df1dd5536a6c5e6263471f4b5 100644 (file)
@@ -75,7 +75,6 @@
         }
 
         $navlinksinstancename = '';
-
     } else if (!empty($update)) {
         if (! $cm = get_record("course_modules", "id", $update)) {
             error("This course module doesn't exist");
         $addinstancefunction    = $fromform->modulename."_add_instance";
         $updateinstancefunction = $fromform->modulename."_update_instance";
 
-        if (!empty($fromform->update)) {
-            if (!isset($fromform->groupingid)) {
-                $fromform->groupingid = 0;
-            }
+        if (!isset($fromform->groupingid)) {
+            $fromform->groupingid = 0;
+        }
 
-            if (!isset($fromform->groupmembersonly)) {
-                $fromform->groupmembersonly = 0;
-            }
+        if (!isset($fromform->groupmembersonly)) {
+            $fromform->groupmembersonly = 0;
+        }
 
-            if (!isset($fromform->groupmode)) {
-                $fromform->groupmode = 0;
-            }
+        if (!isset($fromform->groupmode)) {
+            $fromform->groupmode = 0;
+        }
+
+        if (!isset($fromform->name)) { //label
+            $fromform->name = $fromform->modulename;
+        }
+
+        if (!empty($fromform->update)) {
 
             $returnfromfunc = $updateinstancefunction($fromform);
             if (!$returnfromfunc) {
             set_coursemodule_groupingid($fromform->coursemodule, $fromform->groupingid);
             set_coursemodule_groupmembersonly($fromform->coursemodule, $fromform->groupmembersonly);
 
-            // set cm id number
-            set_coursemodule_idnumber($fromform->coursemodule, $fromform->cmidnumber);
+            if (isset($fromform->cmidnumber)) { //label
+                // set cm idnumber
+                set_coursemodule_idnumber($fromform->coursemodule, $fromform->cmidnumber);
+            }
 
             add_to_log($course->id, "course", "update mod",
                        "../mod/$fromform->modulename/view.php?id=$fromform->coursemodule",
                        "$fromform->instance", $fromform->coursemodule);
 
         } else if (!empty($fromform->add)){
+
             if (!course_allowed_module($course,$fromform->modulename)) {
                 error("This module ($fromform->modulename) has been disabled for this particular course");
             }
 
-            if (!isset($fromform->groupingid)) {
-                $fromform->groupingid = 0;
-            }
-
-            if (!isset($fromform->groupmembersonly)) {
-                $fromform->groupmembersonly = 0;
-            }
-
-            if (!isset($fromform->groupmode)) {
-                $fromform->groupmode = 0;
-            }
-
             $returnfromfunc = $addinstancefunction($fromform);
             if (!$returnfromfunc) {
                 error("Could not add a new instance of $fromform->modulename", "view.php?id=$course->id");
             // make sure visibility is set correctly (in particular in calendar)
             set_coursemodule_visible($fromform->coursemodule, $fromform->visible);
 
-            // set cm idnumber
-            set_coursemodule_idnumber($fromform->coursemodule, $fromform->cmidnumber);
+            if (isset($fromform->cmidnumber)) { //label
+                // set cm idnumber
+                set_coursemodule_idnumber($fromform->coursemodule, $fromform->cmidnumber);
+            }
 
             add_to_log($course->id, "course", "add mod",
                        "../mod/$fromform->modulename/view.php?id=$fromform->coursemodule",
index b3cc68d50d50f6f92436237e28ef67e3d3943eaa..5ec1951186d012a122b9795f446210655359f8d4 100644 (file)
@@ -83,11 +83,15 @@ class moodleform_mod extends moodleform {
     function validation($data) {
         global $COURSE;
 
+        $mform =& $this->_form;
+
         $errors = array();
 
-        $name = trim($data['name']);
-        if ($name == '') {
-            $errors['name'] = get_string('required');
+        if ($mform->elementExists('name')) {
+            $name = trim($data['name']);
+            if ($name == '') {
+                $errors['name'] = get_string('required');
+            }
         }
 
         $grade_item = grade_item::fetch(array('itemtype'=>'mod', 'itemmodule'=>$data['modulename'],
@@ -98,9 +102,11 @@ class moodleform_mod extends moodleform {
             $cm = null;
         }
 
-        // verify the idnumber
-        if (!grade_verify_idnumber($data['cmidnumber'], $grade_item, $cm)) {
-            $errors['cmidnumber'] = get_string('idnumbertaken');
+        if ($mform->elementExists('cmidnumber')) {
+            // verify the idnumber
+            if (!grade_verify_idnumber($data['cmidnumber'], $grade_item, $cm)) {
+                $errors['cmidnumber'] = get_string('idnumbertaken');
+            }
         }
 
         if (count($errors) == 0) {