Index: mod/quiz/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/quiz/lib.php,v
retrieving revision 1.282.2.19
diff -u -w -r1.282.2.19 lib.php
--- mod/quiz/lib.php	14 Jan 2009 07:03:13 -0000	1.282.2.19
+++ mod/quiz/lib.php	6 Mar 2009 07:26:27 -0000
@@ -286,16 +286,16 @@
 
     if ($quiz != null) {
         if ($grades = quiz_get_user_grades($quiz, $userid)) {
-            quiz_grade_item_update($quiz, $grades);
+            quiz_grade_item_update($quiz, $grades, true);
 
         } else if ($userid and $nullifnone) {
             $grade = new object();
             $grade->userid   = $userid;
             $grade->rawgrade = NULL;
-            quiz_grade_item_update($quiz, $grade);
+            quiz_grade_item_update($quiz, $grade, true);
 
         } else {
-            quiz_grade_item_update($quiz);
+            quiz_grade_item_update($quiz, null, true);
         }
 
     } else {
@@ -317,12 +317,14 @@
 
 /**
  * Create grade item for given quiz
+ * @note MDL-18301 This is called each time the created grade item is changed in the gradebook!!
  *
  * @param object $quiz object with extra cmidnumber
  * @param mixed optional array/object of grade(s); 'reset' means reset grades in gradebook
+ * @param boolean $updating We don't want to override grade item settings that have been set in the gradebook (like hidden) if only updating.
  * @return int 0 if ok, error code otherwise
  */
-function quiz_grade_item_update($quiz, $grades=NULL) {
+function quiz_grade_item_update($quiz, $grades=NULL, $updating=false) {
     global $CFG;
     if (!function_exists('grade_update')) { //workaround for buggy PHP versions
         require_once($CFG->libdir.'/gradelib.php');
@@ -334,6 +336,7 @@
         $params = array('itemname'=>$quiz->name);
     }
 
+    if (!$updating) {
     if ($quiz->grade > 0) {
         $params['gradetype'] = GRADE_TYPE_VALUE;
         $params['grademax']  = $quiz->grade;
@@ -366,6 +369,7 @@
         // b) open enabled, closed disabled - we can not "hide after", grades are kept visible even after closing
         $params['hidden'] = 0;
     }
+    }
 
     if ($grades  === 'reset') {
         $params['reset'] = true;
Index: lib/gradelib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/gradelib.php,v
retrieving revision 1.120.2.27
diff -u -w -r1.120.2.27 gradelib.php
--- lib/gradelib.php	8 Jan 2009 08:19:42 -0000	1.120.2.27
+++ lib/gradelib.php	6 Mar 2009 07:26:27 -0000
@@ -1133,7 +1133,7 @@
 
     } else if (function_exists($updategradesfunc) and function_exists($updateitemfunc)) {
         //new grading supported, force updating of grades
-        $updateitemfunc($modinstance);
+        $updateitemfunc($modinstance, null, true);
         $updategradesfunc($modinstance, $userid);
 
     } else {
