From: skodak Date: Sun, 26 Aug 2007 07:44:14 +0000 (+0000) Subject: MDL-10999 Cannot Insert or Edit a Label X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=273eb2f5aaf9662c67c6b665d22a187c78f9dd4f;p=moodle.git MDL-10999 Cannot Insert or Edit a Label --- diff --git a/course/modedit.php b/course/modedit.php index 7f575ec090..1792d0fb9e 100644 --- a/course/modedit.php +++ b/course/modedit.php @@ -75,7 +75,6 @@ } $navlinksinstancename = ''; - } else if (!empty($update)) { if (! $cm = get_record("course_modules", "id", $update)) { error("This course module doesn't exist"); @@ -207,18 +206,23 @@ $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) { @@ -233,8 +237,10 @@ 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", @@ -244,22 +250,11 @@ "$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"); @@ -287,8 +282,10 @@ // 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", diff --git a/course/moodleform_mod.php b/course/moodleform_mod.php index b3cc68d50d..5ec1951186 100644 --- a/course/moodleform_mod.php +++ b/course/moodleform_mod.php @@ -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) {