42,44c42,44
< $GRADEPREFSDEFAULTS = array('use_advanced'                => 0,
<                             'use_weighted_for_letter'     => 0,
<                             'display_weighted'            => 0,
---
> $GRADEPREFSDEFAULTS = array('use_advanced'                => 1,
>                             'use_weighted_for_letter'     => 1,
>                             'display_weighted'            => 2,
46,47c46,47
<                             'display_percent'             => 1,
<                             'display_letters'             => 0,
---
>                             'display_percent'             => 2,
>                             'display_letters'             => 2,
49c49
<                             'show_hidden'                 => 1
---
>                             'show_hidden'                 => 0
2177d2176
< 
2225d2223
<     
2300a2299
> 
2364a2364
>                     if ($view_by_student == -1) // Only start row with student link if looking at all students.  rlwebb 8/13/2007
2367a2368,2369
>                 $reallyfirst = 0;  // Variable to make sure the headers are only processed once for single student view
>                 
2396a2399,2400
>                                     // If viewing multiple students then row view.  rlwebb 8/13/2007
> 					                if ($view_by_student == -1) {
2406c2410
<                                     $header .= '<a href="javascript:void()" onclick="window.open(\'?id='.$course->id.'&amp;action=stats&amp;category='.urlencode($category).'&amp;item='.urlencode($assignment).'\',\''.get_string('statslink','grades').'\',\'height=260,width=500,scrollbars=no\')">'.get_string('statslink','grades').'</a>';
---
>                                     	$header .= '<a href="javascript:void()" onclick="window.open(\'?id='.$course->id.'&amp;action=stats&amp;category='.urlencode($category).'&amp;item='.urlencode($assignment).'\',\' '.get_string('statslink','grades').\',\'height=260,width=500,scrollbars=no\')"> ['.get_string('statslink','grades').']</a>';
2437a2442,2484
>                                     // End row view settings for multiple student view.  Else statement sets up column view.  rlwebb 8/13/2007
>                                     else {
>                                     	if ($all_categories[$category][$assignment]['hidden'] == 0) {
>                                         	$row .= '<th id="m_'.$link_id->id.'" class="'.$class.'" colspan="1" scope="col" align="left"><a href="'.$link.'">'.format_string($assignment,true).'</a>';
>                                    		}
>                                     	else {
>                                         	$row .= '<th name="table_element" id="m_'.$link_id->id.'" class="'.$class.'" colspan="1" scope="col" align="left"><a class="dimmed" href="'.$link.'">'.format_string($assignment,true).'</a>';
>                                     	}
>                                     
>                                     	
>                                     	// add stats link
>                                     	$row .= '<a href="javascript:void()" onclick="window.open(\'?id='.$course->id.'&amp;action=stats&amp;category='.urlencode($category).'&amp;item='.urlencode($assignment).'\',\''.get_string('statslink','grades').'\',\'height=260,width=500,scrollbars=no\')"> ['.get_string('statslink','grades').']</a>';
>                                                                         
>                                     	if ($all_categories[$category][$assignment]['extra_credit'] == 1) {
>                                         	$row .= '<span class="extracredit">('.get_string('extracredit','grades').')</span>'; 
>                                     	}
>                                     	$row .='</th>';
>                                     	
>                                     	if ($reallyfirst == 0) {
>                                     	     if (!has_capability('moodle/course:viewcoursegrades', $context)) 
>                                  				$header1 = '<th>Assignment</th>';
>                                     	
>                                     	if ($preferences->show_points) {
>                                         $header1 .= '<th id="maxgrade['.$link_id->id.']" name="table_element" class="'.$class.'">'.get_string('points','grades').' / Max Points</th>';                                   
>                                     	}
>                                                                         
>                                     	if($preferences->show_percent)    {
>                                         	if ($all_categories[$category][$assignment]['grade_against'] != $all_categories[$category][$assignment]['maxgrade']) {
>                                             	$header1 .= '<th class="'.$class.'" scope="col">'.get_string('scaledpct','grades').'</th>';
>                                         	}
>                                         	else {
>                                             	$header1 .= '<th class="'.$class.'" scope="col">'.get_string('rawpct','grades').'</th>';
>                                         	}
>                                     	}
>                                     	if ($preferences->show_weighted) {
>                                         	$header1 .= '<th scope="col">'.get_string('pctoftotalgrade','grades').'</th>';
>                                     	}
>                                     	
>                                     	$reallyfirst = 1;
>                                     	}
> 
>                                     }  // End column view settings for single student view.  rlwebb 8/13/2007
>                                 }
2443d2489
<                                 // display points 
2504c2550
<                                             $row .= '<td name="table_element" id="'.$student.'_'.$link_id->id.'h" class="'.$highlightclass.'">'.$items[$assignment]['grade'].'</a></td>';
---
>                                             $row .= '<td name="table_element" id="'.$student.'_'.$link_id->id.'h" class="'.$highlightclass.'">'.$items[$assignment]['grade'].'</a>';
2513c2559
<                                                 $row .= '<td name="table_element" id="'.$student.'_'.$link_id->id.'h" class="'.$highlightclass.'">'.$edit_link.'</td>';
---
>                                                 $row .= '<td name="table_element" id="'.$student.'_'.$link_id->id.'h" class="'.$highlightclass.'">'.$edit_link.'';
2516c2562
<                                                 $row .= '<td name="table_element" id="'.$student.'_'.$link_id->id.'h" class="'.$highlightclass.'">'.$items[$assignment]['grade'].'</td>';
---
>                                                 $row .= '<td name="table_element" id="'.$student.'_'.$link_id->id.'h" class="'.$highlightclass.'">'.$items[$assignment]['grade'].'';
2522c2568,2575
<                                         $row .= '<td class="'.$class.'">'.$items[$assignment]['grade'].'</td>';
---
>                                         $row .= '<td align="center">'.$items[$assignment]['grade'].'';
>                                     }
>                                     //I removed the </td> at the end of the preceding row entries and will put it in below for multiple student view, but add out of points for single student view.  rlwebb 8/13/2007
>                                     if($view_by_student ==-1) {
> 	                                    $row .= '</td>';
>                                     }
>                                     else {
>                                         $row .= ' / '.$all_categories[$category][$assignment]['grade_against'].'</td>';
2537c2590
<                             }
---
> 
2539a2593,2608
>                             //Start new row if viewing just one student.  rlwebb 8/13/2007
> 			                if ($view_by_student != -1) {
> 				                $reprint += 1;
> 				                if (($preferences->reprint_headers != 0) && ($reprint >= $preferences->reprint_headers)) {
> 				                    $row .=  '</tr><tr>'.$header1.'';
> 				                    $reprint=0;
> 				               }
> 				
> 				                // alternate row classes
> 				                $row .= ($oddrow) ? '</tr><tr class="r0">' : '</tr><tr class="r1">';
> 				                $oddrow = !$oddrow;
> 
> 				                // reset the col classes
> 				                $oddcol = true;
>                             }
>                         }
2554c2623,2626
<                     $stats_link = '<a href="javascript:void(0)" onclick="window.open(\'?id='.$course->id.'&amp;action=stats&amp;category='.$cview.'\',\''.get_string('statslink','grades').'\',\'height=200,width=300,scrollbars=no\')">'.get_string('statslink','grades').'</a>';
---
>                     $stats_link = '<a href="javascript:void(0)" onclick="window.open(\'?id='.$course->id.'&amp;action=stats&amp;category='.$cview.'\',\''.get_string('statslink','grades').'\',\'height=200,width=300,scrollbars=no\')"> ['.get_string('statslink','grades').']</a>';
>                     
>                     //If viewing multiple students, set headers for row view.  rlwebb 8/13/2007
> 	                if ($view_by_student == -1) {
2576a2649,2658
>                     }
>                     else // If viewing single student, put assignment in first column.  rlwebb 8/13/2007
>                     {
> 	                    if ($all_categories[$cview]['stats']['drop'] != 0) {
>                             $row .= '<th class="'.$class.'" colspan="1" align="left">'.get_string('total','grades').'&nbsp; (Lowest '. $all_categories[$cview]['stats']['drop']. ' Dropped)'.$total_sort_link.' '.$stats_link.'</th>';
>                         }
>                         else {
>                             $row .= '<th class="'.$class.'" colspan="1" align="left">'.get_string('total','grades').'&nbsp;'.$total_sort_link.' '.$stats_link.'</th>';
>                         }
>                     }
2578c2660,2662
<                     if (has_capability('moodle/course:viewcoursegrades', $context)) {
---
>                     // If viewing multiple students end header with student header link.  Otherwise, just end header row.  rlwebb 8/13/2007
>                     
>                     if ((has_capability('moodle/course:viewcoursegrades', $context))&&($view_by_student == -1)) {
2609a2694,2696
> 					// Add Student link to table title if single student.  rlwebb 8/13/2007
> 					if ($view_by_student != -1) 
> 						echo '<br>'.$student_link.'';
2621c2708,2717
<                     $row .= '<td id="total['.$student.']" class="'.$class.'">'.$grades_by_student[$student][$cview]['stats']['points'].'</td>';
---
>                     $row .= '<th id="total['.$student.']"  align="center">'.$grades_by_student[$student][$cview]['stats']['points'].'';
>                     
>                     //I removed the </td> at the end of the preceding row entry and will put it in below for multiple student view, but add out of points for single student view.  rlwebb 8/13/2007
>                     if($view_by_student ==-1) {
> 	                	$row .= '</th>';
>                     }
>                     else {
>                        	$row .= ' / '.$grades_by_student[$student][$cview]['stats']['totalpoints'].'</th>';
>                     }
> 
2628c2724
<                     $row .= '<td class="'.$class.'">'.$grades_by_student[$student][$cview]['stats']['percent'].'%</td>';
---
>                     $row .= '<th class="'.$class.'">'.$grades_by_student[$student][$cview]['stats']['percent'].'%</th>';
2636c2732
<                     $row .= '<td class="'.$class.'">'.$grades_by_student[$student][$cview]['stats']['weighted'].'%</td>';
---
>                     $row .= '<th class="'.$class.'">'.$grades_by_student[$student][$cview]['stats']['weighted'].'%</th>';
2649a2746,2748
> 	                    //If viewing multiple students, end row with name.  rlwebb 8/13/2007
> 	                    if ($view_by_student == -1) {
> 
2651a2751
>                     }
2652a2753,2754
> 	                    //If viewing multiple students, end row with name.  rlwebb 8/13/2007
> 	                    if ($view_by_student == -1) {
2655a2758
>                 }
2759c2862,2866
<                  $row .= '<th scope="row">'. $studentviewlink .'</th>';
---
>             }
>             //If viewing multiple students then start row with student link.  rlwebb 8/13/2007
>             if($view_by_student == -1) {
>                 $row .= '<td>'. $studentviewlink .'</td>';
> 	
2762a2870,2900
> 			// If viewing single student, set column headers.  rlwebb 8/14/2007
> 			if($view_by_student != -1) {
> 			            if (!has_capability('moodle/course:viewcoursegrades', $context)) {
> 			            	$header .='<th rowspan="2">'.get_string('category','grades').'</th>';
> 						}
>                             $count_columns = $grade_columns;
>                             if ($preferences->show_points) {
>                                 $header1 .= '<th>'.get_string('points','grades').' / Max Points';
>                                 if ($all_categories[$category]['stats']['bonus_points'] != 0) {
>                                      $header1 .='(+'.get_string('bonuspoints','grades').')';
>                                 }
>                                 $header1 .='</th>';
>                             }
>                             if ($preferences->show_percent) {
>                                 $header1 .= '<th>'.get_string('percent','grades').'</th>';
>                             }
>                             if ($preferences->display_weighted != 0) {
>                                 $header1 .= '<th>'.get_string('weight','grades').'</th>';
>                                 $count_columns++;
>                             }
> 
>                             if ($preferences->show_weighted) {
>                                 $header1 .= '<th>'.get_string('weightedpctcontribution','grades').'</th>';
>                             }
> 			                if ($preferences->show_letters) {
> 			                    $count_columns++;
> 		                        $header1 .= '<th>'.get_string('lettergrade','grades').'</th>';
> 			                }
> 							$header .= '<th colspan="'.$count_columns.'" scope="col">Category Information</th>';
>                           			}
> 
2772a2911,2914
>                         // Set column headers for viewing multiple students.  stats_link moved outside of if statement. rlwebb 8/14/2007
>                         $stats_link = '<a href="javascript:void(0)" onclick="window.open(\'?id='.$course->id.'&amp;action=stats&amp;category='.urlencode($category).'\',\''.get_string('statslink','grades').'\',\'height=250,width=300,scrollbars=no\')"><font size="-2"> ['.get_string('statslink','grades').'] </font></a>';
> 
> 					if($view_by_student == -1) {
2775d2916
<                             $stats_link = '<a href="javascript:void(0)" onclick="window.open(\'?id='.$course->id.'&amp;action=stats&amp;category='.urlencode($category).'\',\''.get_string('statslink','grades').'\',\'height=250,width=300,scrollbars=no\')"><font size="-2">'.get_string('statslink','grades').'</font></a>';
2801a2943,2949
>                 } // End if statement for multiple students.  rlwebb 8/14/2007
>                     }
>                     
>                     // Print category name if single student view.  rlwebb 8/14/2007
> 					if($view_by_student != -1) {
>  							$row .= '<th scope="col" align="left"><a href="?id='.$course->id.'&amp;action=vcats&amp;cview='.urlencode($category);
>                             $row .='">'. $categoryname .' '.$stats_link.'</a></th>';
2805c2953,2958
<                         $row .= '<td align="right">' . $items['stats']['points'] . '</td>';
---
>                         $row .= '<td align="center" scope="col">' . $items['stats']['points'] . '';
>                         
>                         // add out of total points if single student view.  rlwebb 8/14/2007
> 					if($view_by_student != -1) 
> 						$row .= ' / '.$all_categories[$category]['stats']['totalpoints'].'';
>                     $row .= '</td>';   
2808c2961,2965
<                         $row .= '<td align="right">'. $items['stats']['percent'].'%</td>';
---
>                         $row .= '<td align="right" scope="col">'. $items['stats']['percent'].'%</td>';
>                     }
>                     // Show weight if single student view.  rlwebb 8/14/2007
>                     if (($preferences->display_weighted != 0)&&($view_by_student != -1)) {
>                         $row .= '<td scope="col" align="right">'. $all_categories[$category]['stats']['weight'] . '%</td>';
2812c2969
<                         $row .= '<td align="right">'. $items['stats']['weighted'] . '%</td>';
---
>                         $row .= '<td align="right" scope="col">'. $items['stats']['weighted'] . '%</td>';
2814a2972,2995
>                     
>                     // Show letter grade if single student view.  rlwebb 8/14/2007
>                     if (($preferences->show_letters)&&($view_by_student != -1)) {
>                    
> 	                    $letter_grade = grade_get_grade_letter($course->id, $items['stats']['percent']);
> 	                    if ($letter_grade) {
> 	                        $row .= '<th align="center" scope="col">'.$letter_grade->letter.'</th>';
> 	                    }
> 	                    else {
> 	                        // there wasn't an appropriate entry to use in the gradebook.
> 	                        if (grade_letters_set($course->id)) {
> 	                            $row .= '<th align="center">'.get_string('nolettergrade','grades').' '.$grade.'</th>';
> 	                        }
> 	                        else {
> 	                            $row .= '<th align="center">'.get_string('nogradeletters','grades').'</th>';
> 	                        }
> 	                    }
> 	                }
> 	               if($view_by_student != -1) {
> 		                // alternate row classes
> 		                $row .= ($oddrow) ? '<tr class="r0">' : '<tr class="r1">';
> 		                $oddrow = !$oddrow;
> 	                }
> 
2835c3016,3019
<                 $stats_link = '<a href="javascript:void(0)" onclick="window.open(\'?id='.$course->id.'&amp;action=stats&amp;category=all\',\''.get_string('statslink','grades').'\',\'height=250,width=300,scrollbars=no\')"><font size="-2">'.get_string('statslink','grades').'</font></a>';
---
>                 $stats_link = '<a href="javascript:void(0)" onclick="window.open(\'?id='.$course->id.'&amp;action=stats&amp;category=all\',\''.get_string('statslink','grades').'\',\'height=250,width=300,scrollbars=no\')"><font size="-2"> ['.get_string('statslink','grades').']</font></a>';
>                 
>             // Column headers for overall grade in multiple student view.  rlwebb 8/14/2007    
>             if($view_by_student == -1) {
2878a3063
>             } // End column headers for final grade for multiple student view.  rlwebb 8/14/2007
2879a3065,3067
>                 
>                 // Set number of columns in table for single student or multiple student views.  rlwebb 8/14/2007
>             	if($view_by_student == -1) {
2880a3069,3073
>                 }
>                 else
>                 {
>                 	$colcount = $count_columns + 1;
>               	}
2888a3082,3086
>                 					
>                 // Add Student link to table title if single student.  rlwebb 8/14/2007
> 				if ($view_by_student != -1) 
> 					echo '<br>'.$studentviewlink.'';
> 
2895a3094,3099
>             
>             // Add total to final row in single student view.  rlwebb 8/14/2007
>             if ($view_by_student != -1) {
>             	$row .= '<th align="left" scope="col">'.get_string('total','grades').''.$stats_link.'</th>';
>             }
> 
2897c3101,3106
<                 $row .= '<td align="right">'.$grades_by_student[$student]['student_data']['points'].'</td>';
---
>                 $row .= '<th align="center" scope="col">'.$grades_by_student[$student]['student_data']['points'].'';
>             	if ($view_by_student != -1) {
>                 	$row .= ' / '.$grades_by_student[$student]['student_data']['totalpoints'].'';
>                 }
>                 $row .= '</th>';
>                 
2900c3109
<                 $row .= '<td align="right">'.$grades_by_student[$student]['student_data']['percent'].'%</td>';
---
>                 $row .= '<th align="right" scope="col">'.$grades_by_student[$student]['student_data']['percent'].'%</th>';
2901a3111,3114
>             if (($preferences->display_weighted != 0)&&($view_by_student != -1)) {
>                 $row .= '<th alignt="right" scope="col">'.$all_categories['stats']['weight'].'%</th>';
>             }
>             
2903c3116
<                 $row .= '<td align="right">'.$grades_by_student[$student]['student_data']['weighted'].'%</td>';
---
>                 $row .= '<th align="right" scope="col">'.$grades_by_student[$student]['student_data']['weighted'].'%</th>';
2914c3127
<                     $row .= '<td align="right">'.$letter_grade->letter.'</td>';
---
>                     $row .= '<th align="center" scope="col">'.$letter_grade->letter.'</th>';
2919c3132
<                         $row .= '<td align="right">'.get_string('nolettergrade','grades').' '.$grade.'</td>';
---
>                         $row .= '<td align="center" scope="col">'.get_string('nolettergrade','grades').' '.$grade.'</td>';
2922c3135
<                         $row .= '<td align="right">'.get_string('nogradeletters','grades').'</td>';
---
>                         $row .= '<td align="center" scope="col">'.get_string('nogradeletters','grades').'</td>';
2926c3139
<             if (has_capability('moodle/course:viewcoursegrades', $context)) {
---
>             if ((has_capability('moodle/course:viewcoursegrades', $context))&&($view_by_student == -1)) {
2943d3155
< 
