### Eclipse Workspace Patch 1.0
#P moodle19
Index: lib/adminlib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/adminlib.php,v
retrieving revision 1.153.2.43
diff -u -r1.153.2.43 adminlib.php
--- lib/adminlib.php	18 Feb 2008 02:10:14 -0000	1.153.2.43
+++ lib/adminlib.php	3 Mar 2008 10:45:13 -0000
@@ -3194,6 +3194,23 @@
     }
 }
 
+class admin_setting_regradingcheckbox extends admin_setting_configcheckbox {
+    function write_setting($data) {
+        global $CFG;
+
+        $oldvalue  = $this->config_read($this->name);
+        $return    = parent::write_setting($data);
+        $newvalue  = $this->config_read($this->name);
+
+        if ($oldvalue !== $newvalue) {
+            // force full regrading
+            set_field('grade_items', 'needsupdate', 1, 'needsupdate', 0);
+        }
+
+        return $return;
+    }    
+}
+
 /**
  * Which roles to show on course decription page
  */
Index: lib/grade/grade_item.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/grade/grade_item.php,v
retrieving revision 1.130.2.16
diff -u -r1.130.2.16 grade_item.php
--- lib/grade/grade_item.php	27 Feb 2008 10:00:47 -0000	1.130.2.16
+++ lib/grade/grade_item.php	3 Mar 2008 10:45:19 -0000
@@ -1236,11 +1236,17 @@
                 $outcomes_sql = "AND gi.outcomeid IS NULL";
             }
 
+            if (empty($CFG->grade_includescalesinaggregation)) {
+                $gtypes = "gi.gradetype = ".GRADE_TYPE_VALUE;
+            } else {
+                $gtypes = "(gi.gradetype = ".GRADE_TYPE_VALUE." OR gi.gradetype = ".GRADE_TYPE_SCALE.")";
+            }
+
             if ($grade_category->aggregatesubcats) {
                 // return all children excluding category items
                 $sql = "SELECT gi.id
                           FROM {$CFG->prefix}grade_items gi
-                         WHERE (gi.gradetype = ".GRADE_TYPE_VALUE." OR gi.gradetype = ".GRADE_TYPE_SCALE.")
+                         WHERE $gtypes 
                                $outcomes_sql
                                AND gi.categoryid IN (
                                   SELECT gc.id
@@ -1251,7 +1257,7 @@
                 $sql = "SELECT gi.id
                           FROM {$CFG->prefix}grade_items gi
                          WHERE gi.categoryid = {$grade_category->id}
-                               AND (gi.gradetype = ".GRADE_TYPE_VALUE." OR gi.gradetype = ".GRADE_TYPE_SCALE.")
+                               AND $gtypes
                                $outcomes_sql
 
                         UNION
@@ -1260,7 +1266,7 @@
                           FROM {$CFG->prefix}grade_items gi, {$CFG->prefix}grade_categories gc
                          WHERE (gi.itemtype = 'category' OR gi.itemtype = 'course') AND gi.iteminstance=gc.id
                                AND gc.parent = {$grade_category->id}
-                               AND (gi.gradetype = ".GRADE_TYPE_VALUE." OR gi.gradetype = ".GRADE_TYPE_SCALE.")
+                               AND $gtypes
                                $outcomes_sql";
             }
 
Index: lib/grade/grade_category.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/grade/grade_category.php,v
retrieving revision 1.96.2.14
diff -u -r1.96.2.14 grade_category.php
--- lib/grade/grade_category.php	27 Feb 2008 12:45:10 -0000	1.96.2.14
+++ lib/grade/grade_category.php	3 Mar 2008 10:45:18 -0000
@@ -697,16 +697,15 @@
 
         //find max grade
         foreach ($items as $item) {
-            if ($item->gradetype != GRADE_TYPE_VALUE) {
-                // sum only items with value grades, no scales and outcomes!
-                unset($grade_values[$item->id]);
-                continue;
-            }
             if ($item->aggregationcoef > 0) {
                 // extra credit from this activity - does not affect total
                 continue;
             }
-            $max += $item->grademax;
+            if ($item->gradetype == GRADE_TYPE_VALUE) {
+                $max += $item->grademax;
+            } else if ($item->gradetype == GRADE_TYPE_SCALE) {
+                $max += $item->grademax - 1; // scales min is 1
+            }
         }
 
         if ($this->grade_item->grademax != $max or $this->grade_item->grademin != 0 or $this->grade_item->gradetype != GRADE_TYPE_VALUE){
Index: lang/en_utf8/grades.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lang/en_utf8/grades.php,v
retrieving revision 1.111.2.51
diff -u -r1.111.2.51 grades.php
--- lang/en_utf8/grades.php	3 Mar 2008 10:21:41 -0000	1.111.2.51
+++ lang/en_utf8/grades.php	3 Mar 2008 10:45:08 -0000
@@ -80,6 +80,7 @@
 $string['configgradeletterdefault'] = 'A letter or other symbol used to represent a range of grades. Leave this field empty to use the site default (currently $a).';
 $string['configgradepublishing'] = 'Enable publishing in exports and imports: Exported grades can be accessed by accessing a URL, without having to log on to a Moodle site. Grades can be imported by accessing such a URL (which means that a Moodle site can import grades published by another site). By default only administrators may use this feature, please educate users before adding required capabilities to other roles (dangers of bookmark sharing and download accelerators, IP restrictions, etc.).';
 $string['confighiddenasdate'] = 'If user can not see hidden grades show date of submission instead of \'-\'.';
+$string['configincludescalesinaggregation'] = 'You can change whether scales are to be included as numbers in all aggregated grades across all gradebooks in all courses. CAUTION: changing this setting will force all aggregated grades to be recalculated.';
 $string['configmeanselection'] = 'Whether cells with no grade should be included when calculating the mean for each column.';
 $string['configprofilereport'] = 'Grade report used on user profile page.';
 $string['configshowquickfeedback'] = 'Quick Feedback adds a text input element in each grade cell on the grader report, allowing you to edit the feedback for many grades at once. You can then click the Update button to perform all these changes at once, instead of one at a time.';
@@ -258,6 +259,7 @@
 $string['importskippedoutcome'] = 'An outcome with shortname \"$a\" already exists in this context, the one in the imported file was skipped.';
 $string['importsuccess'] = 'Grade import success';
 $string['importxml'] = 'Import XML';
+$string['includescalesinaggregation'] = 'Include scales in aggregation';
 $string['incorrectcourseid'] = 'Course ID was incorrect';
 $string['incorrectminmax'] = 'The minimum must be lower than the maximum';
 $string['inherit'] = 'Inherit';
Index: admin/settings/grades.php
===================================================================
RCS file: /cvsroot/moodle/moodle/admin/settings/grades.php,v
retrieving revision 1.14.2.16
diff -u -r1.14.2.16 grades.php
--- admin/settings/grades.php	26 Feb 2008 08:34:04 -0000	1.14.2.16
+++ admin/settings/grades.php	3 Mar 2008 10:45:07 -0000
@@ -24,10 +24,12 @@
                                                   array(GRADE_REPORT_AGGREGATION_POSITION_FIRST => get_string('positionfirst', 'grades'),
                                                         GRADE_REPORT_AGGREGATION_POSITION_LAST => get_string('positionlast', 'grades'))));
 
-        $temp->add(new admin_setting_configcheckbox('grade_hiddenasdate', get_string('hiddenasdate', 'grades'), get_string('confighiddenasdate', 'grades'), 0, PARAM_INT));
+        $temp->add(new admin_setting_regradingcheckbox('grade_includescalesinaggregation', get_string('includescalesinaggregation', 'grades'), get_string('configincludescalesinaggregation', 'grades'), 1));
+
+        $temp->add(new admin_setting_configcheckbox('grade_hiddenasdate', get_string('hiddenasdate', 'grades'), get_string('confighiddenasdate', 'grades'), 0));
 
         // enable publishing in exports/imports
-        $temp->add(new admin_setting_configcheckbox('gradepublishing', get_string('gradepublishing', 'grades'), get_string('configgradepublishing', 'grades'), 0, PARAM_INT));
+        $temp->add(new admin_setting_configcheckbox('gradepublishing', get_string('gradepublishing', 'grades'), get_string('configgradepublishing', 'grades'), 0));
 
         $temp->add(new admin_setting_configselect('grade_export_displaytype', get_string('gradeexportdisplaytype', 'grades'),
                                                   get_string('configgradeexportdisplaytype', 'grades'), GRADE_DISPLAY_TYPE_REAL,
Index: lib/db/upgrade.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/db/upgrade.php,v
retrieving revision 1.154.2.27
diff -u -r1.154.2.27 upgrade.php
--- lib/db/upgrade.php	29 Feb 2008 08:40:41 -0000	1.154.2.27
+++ lib/db/upgrade.php	3 Mar 2008 10:45:17 -0000
@@ -2939,6 +2939,10 @@
         upgrade_main_savepoint($result, 2007101508.08);
     }
 
+    if ($result && $oldversion < 2007101509) {
+        // force full regrading
+        set_field('grade_items', 'needsupdate', 1, 'needsupdate', 0);
+    }
 
     return $result;
 }
