### Eclipse Workspace Patch 1.0
#P GBPv2_18STABLE
Index: lib.php
===================================================================
RCS file: /cvsroot/moodle/contrib/patches/gradebookplus_v2_1.7/lib.php,v
retrieving revision 1.3.2.12
diff -u -r1.3.2.12 lib.php
--- lib.php	18 Oct 2007 21:29:24 -0000	1.3.2.12
+++ lib.php	12 Nov 2007 23:37:47 -0000
@@ -1,5 +1,6 @@
 <?php // $Id: lib.php,v 1.3.2.12 2007/10/18 21:29:24 arborrow Exp $
-// Branch from core at: lib.php,v 1.65.2.5, 2007/06/26 11:50:19 Exp  
+// Branch from core at: lib.php,v 1.65.2.13, 2007/11/09 07:46:43 Exp
+// with the exception of the changes made in 1.65.2.12 in response to MDL-12043 because I was not sure how this might impact graded events  
 if (!defined('MOODLE_INTERNAL')) {
     die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page
 }
@@ -528,6 +529,7 @@
 							$assgn = get_record('grade_events', 'id', $exception->cminstance, 'course', $course->id);
 						}
 						$grades_by_student["$exception->userid"]['student_data']['totalpoints'] = $grades_by_student["$exception->userid"]['student_data']['totalpoints'] - $all_categories["$exception->catname"]["$assgn->name"]['maxgrade'];
+
                         //total point should not be smaller than grade against
                         if ($grades_by_student["$exception->userid"]["$exception->catname"]['stats']['totalpoints'] - $all_categories["$exception->catname"]["$assgn->name"]['grade_against'] != 0 ) {
                             $grades_by_student["$exception->userid"]["$exception->catname"]['stats']['totalpoints'] = $grades_by_student["$exception->userid"]["$exception->catname"]['stats']['totalpoints'] - $all_categories["$exception->catname"]["$assgn->name"]['grade_against'];
@@ -539,10 +541,13 @@
                         if ($all_categories["$exception->catname"]['stats']['drop'] == 0) {
                             $grades_by_student["$exception->userid"]["$exception->catname"]['stats']['points'] = $grades_by_student["$exception->userid"]["$exception->catname"]['stats']['points'] - $grades_by_student["$exception->userid"]["$exception->catname"]["$assgn->name"]['grade'];
                         }
+
                         $grades_by_student["$exception->userid"]["$exception->catname"]["$assgn->name"]['maxgrade'] = $strexcluded;
                         $grades_by_student["$exception->userid"]["$exception->catname"]["$assgn->name"]['grade'] = $strexcluded;
+
                         // see if they are excluded entirely from a category
                         if ($grades_by_student["$exception->userid"]["$exception->catname"]['stats']['totalpoints'] == 0) {
+                            
                             $grades_by_student["$exception->userid"]["$exception->catname"]['stats']['totalpoints'] = $strexcluded;
                             $grades_by_student["$exception->userid"]["$exception->catname"]['stats']['percent'] = $strexcluded;
                             $grades_by_student["$exception->userid"]["$exception->catname"]['stats']['points'] = $strexcluded;
@@ -550,8 +555,7 @@
                             $grades_by_student["$exception->userid"]["$exception->catname"]['stats']['weighted'] = $strexcluded;
                         }
                     }
-                }
-                else {
+                } else {
                     // the user had exceptions, but was unenrolled from the course... we could delete it here, but we will leave it because the user may be re-added to the course
                 }
             }
@@ -566,7 +570,8 @@
                 foreach($categories as $category => $assignments) {
                     if ($category != 'student_data') {
                         // set the student's total points earned 
-                        if ($grades_by_student["$student"]["$category"]['stats']['points'] != $strexcluded) {
+                        /// MDL-11235, 0 == 'Excluded', so we need to do type equality check too
+                        if ($grades_by_student["$student"]["$category"]['stats']['points'] !== $strexcluded) {
                             if ($grades_by_student["$student"]["$category"]['stats']['points'] != '-') {
                                 $grades_by_student["$student"]['student_data']['points'] = $grades_by_student["$student"]['student_data']['points'] + $grades_by_student["$student"]["$category"]['stats']['points'];
                             }
@@ -576,7 +581,7 @@
                         // set percents and weights for each assignment
                         foreach($assignments as $assignment => $info) {
                             if ($assignment != 'stats') {
-                                if ($grades_by_student["$student"]["$category"]["$assignment"]['grade'] != $strexcluded) {    
+                                if ($grades_by_student["$student"]["$category"]["$assignment"]['grade'] !== $strexcluded) {    
                                     if ($grades_by_student["$student"]["$category"]["$assignment"]['maxgrade'] != 0) {
                                         $grades_by_student["$student"]["$category"]["$assignment"]['percent'] = round($grades_by_student["$student"]["$category"]["$assignment"]['grade']/$grades_by_student["$student"]["$category"]["$assignment"]['maxgrade']*100,2);
                                     }
@@ -610,14 +615,14 @@
                             $grades_by_student["$student"]["$category"]['stats']['weighted'] = round($grades_by_student["$student"]["$category"]['stats']['points']/$grades_by_student["$student"]["$category"]['stats']['totalpoints']*$grades_by_student["$student"]["$category"]['stats']['weight'],2);
                         }
                         else {
-                            if ($grades_by_student["$student"]["$category"]['stats']['totalpoints'] != $strexcluded) {
+                            if ($grades_by_student["$student"]["$category"]['stats']['totalpoints'] !== $strexcluded) {
                                 $grades_by_student["$student"]["$category"]['stats']['percent'] = 0.00;
                                 $grades_by_student["$student"]["$category"]['stats']['weighted'] = 0.00;
                             }
                         }
                                 
                         // set students overall weight (this is what percent they will be graded against)
-                        if ($grades_by_student["$student"]["$category"]['stats']['weight'] != $strexcluded) {
+                        if ($grades_by_student["$student"]["$category"]['stats']['weight'] !== $strexcluded) {
                             $grades_by_student["$student"]['student_data']['weight'] = $grades_by_student["$student"]['student_data']['weight'] + $grades_by_student["$student"]["$category"]['stats']['weight'];
                         }
                         
@@ -632,7 +637,7 @@
                 }
                 
                 // set the percent and weight overall
-                if ($grades_by_student["$student"]['student_data']['totalpoints'] != 0 && $grades_by_student["$student"]['student_data']['totalpoints'] != $strexcluded) {
+                if ($grades_by_student["$student"]['student_data']['totalpoints'] != 0 && $grades_by_student["$student"]['student_data']['totalpoints'] !== $strexcluded) {
                     $grades_by_student["$student"]['student_data']['percent'] = round($grades_by_student["$student"]['student_data']['points']/$grades_by_student["$student"]['student_data']['totalpoints']*100,2);
                     if ($grades_by_student["$student"]['student_data']['weight'] != 0) {
                         $grades_by_student["$student"]['student_data']['weighted'] = round($grades_by_student["$student"]['student_data']['weighted']/$grades_by_student["$student"]['student_data']['weight']*100,2);
@@ -905,7 +910,7 @@
                                     // get instance name from db.
                                     $instance = get_record($mod->modname, 'id', $mod->instance);
                                     // see if the item is already in the category table and if it is call category select with the id so it is selected
-                                    get_record('modules', 'name', $mod->modname);
+                                    // get_record('modules', 'name', $mod->modname);
                                     $item = get_record('grade_item', 'courseid', $course->id, 'modid', $mod->module, 'cminstance', $mod->instance);
                                     if (!$item) {
                                         // set the item to uncategorized in grade_item
@@ -1148,7 +1153,7 @@
 
 /// We don't need advanced features, and we need to unset all extra features
 /// So they don't affect grades    (This approach should be revisited because it resets everything!!)
-    $prefs = get_records('grade_preferences', 'courseid', $course);
+    $prefs = get_records('grade_preferences', 'courseid', $course->id);
     $prefs = urlencode(md5(serialize($prefs)));
     if ($reset) {
         if ($reset == $prefs) {
