MDL-23255 fixed inverted isset preventing visibility change in course edit form ...
authorPetr Skoda <skodak@moodle.org>
Wed, 14 Jul 2010 14:23:32 +0000 (14:23 +0000)
committerPetr Skoda <skodak@moodle.org>
Wed, 14 Jul 2010 14:23:32 +0000 (14:23 +0000)
course/edit_form.php
course/lib.php

index f69f1b2..c37d99d 100644 (file)
@@ -200,9 +200,13 @@ class course_edit_form extends moodleform {
         $mform->addElement('select', 'visible', get_string('availability'), $choices);
         $mform->addHelpButton('visible', 'availability');
         $mform->setDefault('visible', $courseconfig->visible);
-        if (!empty($course->id) and !has_capability('moodle/course:visibility', $coursecontext)) {
+        if (!has_capability('moodle/course:visibility', $context)) {
             $mform->hardFreeze('visible');
-            $mform->setConstant('visible', $course->visible);
+            if (!empty($course->id)) {
+                $mform->setConstant('visible', $course->visible);
+            } else {
+                $mform->setConstant('visible', $category->visible);
+            }
         }
 
 //--------------------------------------------------------------------------------
index af19fc2..7335c69 100644 (file)
@@ -3471,12 +3471,11 @@ function create_course($data, $editoroptions = NULL) {
         $data->summary_format = FORMAT_HTML;
     }
 
-    // init visible flags
-    if (isset($data->visible)) {
-        $data->visibleold = $data->visible;
-    } else {
-        $data->visibleold = $data->visible = 1;
+    if (!isset($data->visible)) {
+        // data not from form, add missing visibility info
+        $data->visible = $category->category;
     }
+    $data->visibleold = $data->visible;
 
     $newcourseid = $DB->insert_record('course', $data);
     $context = get_context_instance(CONTEXT_COURSE, $newcourseid, MUST_EXIST);
@@ -3557,8 +3556,8 @@ function update_course($data, $editoroptions = NULL) {
     }
     $movecat = (isset($data->category) and $oldcourse->category != $data->category);
 
-    // init visible flags
-    if (isset($data->visible)) {
+    if (!isset($data->visible)) {
+        // data not from form, add missing visibility info
         $data->visible = $oldcourse->visible;
     }