From 1ec74ea5aaa1778c93277f094dd5dc7d6c1f4fb5 Mon Sep 17 00:00:00 2001
From: nicolasconnault <nicolasconnault>
Date: Thu, 28 Jun 2007 11:15:12 +0000
Subject: [PATCH] MDL-10209 MDL-10211 Added two tiny feedback/add_feedback
 icons. Enabled feedback mode with button next to "Turn editing on". Added
 tooltip (with overlib for the time being) for "Show feedback" when edit mode
 is off, and for "Edit feedback" when edit is on.

---
 grade/report.php              |  28 ++++++++-
 grade/report/grader/index.php |  44 +++++++-------
 lang/en_utf8/grades.php       |   6 ++
 lib/gradelib.php              | 107 +++++++++++++++++++++++-----------
 pix/i/feedback_add.gif        | Bin 0 -> 115 bytes
 pix/t/feedback.gif            | Bin 0 -> 79 bytes
 pix/t/feedback_add.gif        | Bin 0 -> 73 bytes
 7 files changed, 126 insertions(+), 59 deletions(-)
 create mode 100644 pix/i/feedback_add.gif
 create mode 100644 pix/t/feedback.gif
 create mode 100644 pix/t/feedback_add.gif

diff --git a/grade/report.php b/grade/report.php
index c9dc916dd6..1ca197bb34 100644
--- a/grade/report.php
+++ b/grade/report.php
@@ -29,6 +29,7 @@
     $courseid = required_param('id');              // course id
     $report   = optional_param('report', 'user', PARAM_FILE);              // course id
     $edit     = optional_param('edit', -1, PARAM_BOOL); // sticky editting mode
+    $feedback = optional_param('feedback', -1, PARAM_BOOL); // sticky feedback mode
 
 /// Make sure they can even access this course
 
@@ -97,8 +98,19 @@
     } else if (($edit == 0) and confirm_sesskey()) {
         $USER->gradeediting = 0;
     }
+    
+    // Setup feedback mode
+    if (!isset($USER->gradefeedback)) {
+        $USER->gradefeedback = 0;
+    }
+
+    if (($feedback == 1) and confirm_sesskey()) {
+        $USER->gradefeedback = 1;
+    } else if (($feedback == 0) and confirm_sesskey()) {
+        $USER->gradefeedback = 0;
+    }
 
-    // params for the turn editting on button
+    // params for the turn editting on and feedback buttons
     $options['id'] = $courseid;
     $options['report'] = $report;
     
@@ -113,8 +125,20 @@
     $options['sesskey'] = sesskey();
     $link = 'report.php';
 
-    // turn eidtting on and off buttons
+    // turn editting on and off buttons
     $buttons = print_single_button($link, $options, $string, 'get', '_self', true);
+    unset($options['edit']);
+
+    if ($USER->gradefeedback) {
+        $options['feedback'] = 0;
+        $string = get_string('turnfeedbackoff', 'grades');
+    } else {
+        $options['feedback'] = 1;
+        $string = get_string('turnfeedbackon', 'grades'); 
+    }
+
+    // turn editting on and off buttons
+    $buttons .= print_single_button($link, $options, $string, 'get', '_self', true);
     
     print_header_simple($strgrades.':'.$reportnames[$report], ':'.$strgrades, $navigation, 
                         '', '', true, $buttons, navmenu($course));
diff --git a/grade/report/grader/index.php b/grade/report/grader/index.php
index 06672d2607..f00c4588ad 100644
--- a/grade/report/grader/index.php
+++ b/grade/report/grader/index.php
@@ -5,6 +5,10 @@
 require_once($CFG->libdir.'/tablelib.php');
 include_once($CFG->libdir.'/gradelib.php');
 
+// Prepare language strings
+$strsortasc  = get_string('sortasc', 'grades');
+$strsortdesc = get_string('sortdesc', 'grades');
+
 /// processing posted grades here
 
 if ($data = data_submitted()) {
@@ -261,9 +265,9 @@ $cathtml    = '<tr><td class="filler">&nbsp;</td>';
 
 if ($sortitemid === 'lastname') {
     if ($sortorder == 'ASC') {
-        $lastarrow = ' <img src="'.$CFG->pixpath.'/t/up.gif"/> ';
+        $lastarrow = ' <img src="'.$CFG->pixpath.'/t/up.gif" alt="'.$strsortasc.'" /> ';
     } else {
-        $lastarrow = ' <img src="'.$CFG->pixpath.'/t/down.gif"/> ';
+        $lastarrow = ' <img src="'.$CFG->pixpath.'/t/down.gif" alt="'.$strsortdesc.'" /> ';
     }
 } else {
     $lastarrow = '';  
@@ -271,9 +275,9 @@ if ($sortitemid === 'lastname') {
 
 if ($sortitemid === 'firstname') {
     if ($sortorder == 'ASC') {
-        $firstarrow = ' <img src="'.$CFG->pixpath.'/t/up.gif"/> ';
+        $firstarrow = ' <img src="'.$CFG->pixpath.'/t/up.gif" alt="'.$strsortasc.'" /> ';
     } else {
-        $firstarrow = ' <img src="'.$CFG->pixpath.'/t/down.gif"/> ';
+        $firstarrow = ' <img src="'.$CFG->pixpath.'/t/down.gif" alt="'.$strsortdesc.'" /> ';
     }
 } else {
     $firstarrow = '';  
@@ -296,9 +300,9 @@ foreach ($tree as $topcat) {
             
             if ($item['object']->id == $sortitemid) {
                 if ($sortorder == 'ASC') {
-                    $arrow = ' <img src="'.$CFG->pixpath.'/t/up.gif"/> ';
+                    $arrow = ' <img src="'.$CFG->pixpath.'/t/up.gif" alt="'.$strsortasc.'" /> ';
                 } else {
-                    $arrow = ' <img src="'.$CFG->pixpath.'/t/down.gif"/> ';
+                    $arrow = ' <img src="'.$CFG->pixpath.'/t/down.gif" alt="'.$strsortdesc.'" /> ';
                 }
             } else {
                 $arrow = '';
@@ -313,10 +317,8 @@ foreach ($tree as $topcat) {
                       . $item['object']->id .'">'. $item['object']->itemname 
                       . '</a>' . $arrow; 
             
-            // Print icons if grade editing is on 
-            if ($USER->gradeediting) {
-                $itemhtml .= grade_get_icons($item['object'], $gtree) . '</th>';
-            }
+            // Print icons
+            $itemhtml .= grade_get_icons($item['object'], $gtree) . '</th>';
 
             $items[] = $item;
         }
@@ -332,10 +334,8 @@ foreach ($tree as $topcat) {
             $cat['object']->load_grade_item();
             $cathtml .= '<td '.$dimmed.' colspan="' . $catitemcount . '">' . $cat['object']->fullname;
 
-            // Print icons if grade editing is on 
-            if ($USER->gradeediting) {
-                $cathtml .= grade_get_icons($cat['object'], $gtree) . '</td>';
-            }
+            // Print icons 
+            $cathtml .= grade_get_icons($cat['object'], $gtree) . '</td>';
         }
     }
 
@@ -353,10 +353,8 @@ foreach ($tree as $topcat) {
         
         $topcathtml .= '<th '.$dimmed.' colspan="' . $itemcount . '">' . $topcat['object']->fullname;
         
-        // Print icons if grade editing is on 
-        if ($USER->gradeediting) {
-            $topcathtml .= grade_get_icons($topcat['object'], $gtree) . '</th>';
-        }
+        // Print icons
+        $topcathtml .= grade_get_icons($topcat['object'], $gtree) . '</th>';
     }
 }
     
@@ -372,6 +370,7 @@ foreach ($users as $userid => $user) {
         if (isset($finalgrades[$userid][$item['object']->id])) {
             $gradeval = $finalgrades[$userid][$item['object']->id]->finalgrade;
             $grade_grades = new grade_grades($finalgrades[$userid][$item['object']->id], false);
+            $grade_grades->feedback = $finalgrades[$userid][$item['object']->id]->feedback;
         } else {
             $gradeval = '-';  
             $grade_grades = new grade_grades(array('userid' => $userid, 'itemid' => $item['object']->id), false);
@@ -398,10 +397,6 @@ foreach ($users as $userid => $user) {
                 $studentshtml .= '<input type="text" name="grade_'.$userid.'_'.$item['object']->id.'" value="'.$gradeval.'"/>';
             }
             
-            // Do not show any icons if no grade (no record in DB to match)
-            if (!empty($grade_grades->id)) {
-                $studentshtml .= grade_get_icons($grade_grades, $gtree);
-            }
         } else {
             // finalgrades[$userid][$itemid] could be null because of the outer join
             // in this case it's different than a 0  
@@ -423,6 +418,11 @@ foreach ($users as $userid => $user) {
             }
         }
         
+        // Do not show any icons if no grade (no record in DB to match)
+        if (!empty($grade_grades->id)) {
+            $studentshtml .= grade_get_icons($grade_grades, $gtree);
+        }
+        
         $studentshtml .=  '</td>' . "\n";
     }
     $studentshtml .= '</tr>';
diff --git a/lang/en_utf8/grades.php b/lang/en_utf8/grades.php
index 94963bf185..f5d11f7c1b 100644
--- a/lang/en_utf8/grades.php
+++ b/lang/en_utf8/grades.php
@@ -5,6 +5,7 @@
 $string['addcategory'] = 'Add Category';
 $string['addcategoryerror'] = 'Could not add category.';
 $string['addexceptionerror'] = 'Error occurred while adding exception for userid:gradeitem';
+$string['addfeedback'] = 'Add Feedback';
 $string['allgrades'] = 'All grades by category';
 $string['allstudents'] = 'All Students';
 $string['average'] = 'Average';
@@ -28,6 +29,7 @@ $string['displayweighted'] = 'Display Weighted Grades';
 $string['dropped'] = 'Dropped';
 $string['dropxlowest'] = 'Drop X Lowest';
 $string['dropxlowestwarning'] = 'Note: If you use drop x lowest the grading assumes that all items in the category have the same point value. If point values differ results will be unpredictable';
+$string['editfeedback'] = 'Edit Feedback';
 $string['encoding'] = 'Encoding';
 $string['errorgradevaluenonnumeric'] = 'Received non-numeric for low or high grade for';
 $string['errornocategorizedid'] = 'Could not get an uncategorized id!';
@@ -138,6 +140,8 @@ $string['setweights'] = 'Set Weights';
 $string['showallstudents'] = 'Show All Students';
 $string['showhiddenitems'] = 'Show Hidden Items';
 $string['sort'] = 'sort';
+$string['sortasc'] = 'Sort in ascending order';
+$string['sortdesc'] = 'Sort in descending order';
 $string['sortbyfirstname'] = 'Sort by Firstname';
 $string['sortbylastname'] = 'Sort by Lastname';
 $string['standarddeviation'] = 'Standard Deviation';
@@ -149,6 +153,8 @@ $string['topcategory'] = 'Super Category';
 $string['total'] = 'Total';
 $string['totalweight100'] = 'The total weight is equal to 100';
 $string['totalweightnot100'] = 'The total weight is not equal to 100';
+$string['turnfeedbackoff'] = 'Turn feedback off';
+$string['turnfeedbackon'] = 'Turn feedback on';
 $string['uncategorised'] = 'Uncategorised';
 $string['unlock'] = 'Unlock';
 $string['uploadgrades'] = 'Upload grades';
diff --git a/lib/gradelib.php b/lib/gradelib.php
index 809758e148..b8cc8b4578 100644
--- a/lib/gradelib.php
+++ b/lib/gradelib.php
@@ -688,8 +688,12 @@ function grade_oldgradebook_upgrade($courseid) {
  */
 function grade_get_icons($object, $tree) {
     global $CFG;
+    global $USER;
 
+    $straddfeedback    = get_string("addfeedback", 'grades');
     $stredit           = get_string("edit");
+    $streditfeedback   = get_string("editfeedback", 'grades');
+    $strfeedback       = get_string("feedback");
     $strmove           = get_string("move");
     $strmoveup         = get_string("moveup");
     $strmovedown       = get_string("movedown");
@@ -704,47 +708,80 @@ function grade_get_icons($object, $tree) {
 
     $html = '<div class="grade_icons">';
     
-    // Edit icon (except for grade_grades)
-    if (get_class($object) != 'grade_grades') {
-        $html .= '<a href="report/grader/category.php?target=' . $object->get_sortorder() 
-              . "&amp;action=edit$tree->commonvars\">\n";
-        $html .= '<img src="'.$CFG->pixpath.'/t/edit.gif" class="iconsmall" alt="'
-              .$stredit.'" title="'.$stredit.'" /></a>'. "\n";
-    }
-
-    // Hide/Show icon
-    $hide_show = 'hide';
-    if ($object->is_hidden()) {
-        $hide_show = 'show';
-    }
-    
-    if (get_class($object) != 'grade_grades') {
-        $identifier = $object->get_sortorder();
-    } else {
-        $identifier = 'grade' . $object->id;
-    }
+    // Icons shown when edit mode is on
+    if ($USER->gradeediting) {
+        // Edit icon (except for grade_grades)
+        if (get_class($object) != 'grade_grades') {
+            $html .= '<a href="report/grader/category.php?target=' . $object->get_sortorder() 
+                  . "&amp;action=edit$tree->commonvars\">\n";
+            $html .= '<img src="'.$CFG->pixpath.'/t/edit.gif" class="iconsmall" alt="'
+                  .$stredit.'" title="'.$stredit.'" /></a>'. "\n";
+        }
 
-    $html .= '<a href="report.php?report=grader&amp;target=' . $identifier
-          . "&amp;action=$hide_show$tree->commonvars\">\n";
-    $html .= '<img src="'.$CFG->pixpath.'/t/'.$hide_show.'.gif" class="iconsmall" alt="'
-          .${'str' . $hide_show}.'" title="'.${'str' . $hide_show}.'" /></a>'. "\n";
+        // Prepare Hide/Show icon state
+        $hide_show = 'hide';
+        if ($object->is_hidden()) {
+            $hide_show = 'show';
+        }
+        
+        // Setup object identifier and show feedback icon if applicable
+        if (get_class($object) != 'grade_grades') {
+            $identifier = $object->get_sortorder();
+        } else {
+            $identifier = 'grade' . $object->id;
+            
+            if ($USER->gradefeedback) {
+                // Display Edit/Add feedback icon
+                if (empty($object->feedback)) {
+                    $html .= '<a href="report.php?report=grader&amp;target=' . $object->id
+                          . "&amp;action=addfeedback$tree->commonvars\">\n"; 
+                    $html .= '<img src="'.$CFG->pixpath.'/t/feedback_add.gif" class="iconsmall" alt="'.$straddfeedback.'" '
+                          . 'title="'.$straddfeedback.'" /></a>'. "\n";
+                } else {
+                    $html .= '<a href="report.php?report=grader&amp;target=' . $object->id
+                          . "&amp;action=editfeedback$tree->commonvars\">\n"; 
+                    $html .= '<img src="'.$CFG->pixpath.'/t/feedback.gif" class="iconsmall" alt="'.$streditfeedback.'" '
+                          . 'title="'.$streditfeedback.'" onmouseover="return overlib(\''.$object->feedback.'\', CAPTION, \''
+                      . $strfeedback.'\');" onmouseout="return nd();" /></a>'. "\n";
+                } 
+            }
+        }
 
-    // Prepare lock/unlock string
-    $lock_unlock = 'lock';
-    if ($object->is_locked()) {
-        $lock_unlock = 'unlock';
-    }
-    
-    // Print lock/unlock icon
-    $html .= '<a href="report.php?report=grader&amp;target=' . $identifier
-          . "&amp;action=$lock_unlock$tree->commonvars\">\n";
-    $html .= '<img src="'.$CFG->pixpath.'/t/'.$lock_unlock.'.gif" class="iconsmall" alt="'
-          .${'str' . $lock_unlock}.'" title="'.${'str' . $lock_unlock}.'" /></a>'. "\n";
+        // Display Hide/Show icon
+        $html .= '<a href="report.php?report=grader&amp;target=' . $identifier
+              . "&amp;action=$hide_show$tree->commonvars\">\n";
+        $html .= '<img src="'.$CFG->pixpath.'/t/'.$hide_show.'.gif" class="iconsmall" alt="'
+              .${'str' . $hide_show}.'" title="'.${'str' . $hide_show}.'" /></a>'. "\n";
 
-    if ($grade) {
+        // Prepare lock/unlock string
+        $lock_unlock = 'lock';
+        if ($object->is_locked()) {
+            $lock_unlock = 'unlock';
+        }
         
+        // Print lock/unlock icon
+        $html .= '<a href="report.php?report=grader&amp;target=' . $identifier
+              . "&amp;action=$lock_unlock$tree->commonvars\">\n";
+        $html .= '<img src="'.$CFG->pixpath.'/t/'.$lock_unlock.'.gif" class="iconsmall" alt="'
+              .${'str' . $lock_unlock}.'" title="'.${'str' . $lock_unlock}.'" /></a>'. "\n";
+
+        if ($grade) {
+            
+        }
+    } else {
+        if ($USER->gradefeedback) {
+            // Display Edit/Add feedback icon
+            if (!empty($object->feedback)) {
+                $html .= '<a href="report.php?report=grader&amp;target=' . $object->id
+                      . "&amp;action=viewfeedback$tree->commonvars\">\n"; 
+                $html .= '<img onmouseover="return overlib(\''.$object->feedback.'\', CAPTION, \''
+                      . $strfeedback.'\');" onmouseout="return nd();" ' 
+                      . 'src="'.$CFG->pixpath.'/t/feedback.gif" class="iconsmall" alt="" /></a>'. "\n";
+            }            
+        }
     }
 
     return $html . '</div>';
 }
+
 ?>
diff --git a/pix/i/feedback_add.gif b/pix/i/feedback_add.gif
new file mode 100644
index 0000000000000000000000000000000000000000..a39b5fa097f39ebca9cec497377391811be983ee
GIT binary patch
literal 115
zcmZ?wbhEHb6krfwSjfci|Ns9JCr&Vcf#N?==c3falGGH1^30M9g^-L?1$R&100zaM
zEQ|~c%nUjpWgv|VOxkl=R~}>HU!1Y=kma1U5$~&Of;8-6GbcUmOuBhWrgP?zZO?8Q
OuDhRkf5lfW25SH<9Vv7G

literal 0
HcmV?d00001

diff --git a/pix/t/feedback.gif b/pix/t/feedback.gif
new file mode 100644
index 0000000000000000000000000000000000000000..e1cf9bb9d34a1ba7e66d55db3a346a828767e03f
GIT binary patch
literal 79
zcmZ?wbhEHb<YwSzSjYeZ^XJe1|NlRbq4<-9k%57kK?fuXl4oF2xYNK{_DEl>U}0GM
cf^&!NS!D7*XN^$Sb7NZN^LXD$YY_%(05RbgH2?qr

literal 0
HcmV?d00001

diff --git a/pix/t/feedback_add.gif b/pix/t/feedback_add.gif
new file mode 100644
index 0000000000000000000000000000000000000000..742ed4682e95e5051aa753b6be3e4a3434ce7961
GIT binary patch
literal 73
zcmZ?wbhEHb<YwSzSjfci|Ns9JCr&Vcf#OdVMg|6E1|1L&B+tMkb*DwM>;eC@29dyw
W^`~dW-!$}WF-S`3S{li~U=0A)q7@4O

literal 0
HcmV?d00001

-- 
2.39.5