| Update of /cvsroot/aimmath/moodle/mod/math_assignment
In directory sc8-pr-cvs1:/tmp/cvs-serv24415/mod/math_assignment
Modified Files:
	aimpage.php index.php lib.php pdfgen.php view.php 
Log Message:
some minor improvements.
Index: aimpage.php
===================================================================
RCS file: /cvsroot/aimmath/moodle/mod/math_assignment/aimpage.php,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** aimpage.php	31 Oct 2003 14:05:59 -0000	1.17
--- aimpage.php	2 Nov 2003 15:45:30 -0000	1.18
***************
*** 267,273 ****
      echo "<td align=\"center\" width=\"35%\">";
      // write admin links
!     if (isteacher($course->id))
          echo math_assignment_get_admin_links($cm, $math_assignment, $server->password, "center");
!         echo "<center><a href=\"view.php?id=$cm->id&showgrades=true\">Show Grades table</a></center>";
      echo "</td></tr></table>";
  
--- 267,274 ----
      echo "<td align=\"center\" width=\"35%\">";
      // write admin links
!     if (isteacher($course->id)) {
          echo math_assignment_get_admin_links($cm, $math_assignment, $server->password, "center");
!         echo "<center><a href=\"view.php?id=$cm->id&showgrades=true\">".get_string("showgradestable", "math_assignment").'</a></center>';
!     }
      echo "</td></tr></table>";
  
Index: index.php
===================================================================
RCS file: /cvsroot/aimmath/moodle/mod/math_assignment/index.php,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** index.php	26 Sep 2003 22:23:23 -0000	1.8
--- index.php	2 Nov 2003 15:45:30 -0000	1.9
***************
*** 7,10 ****
--- 7,12 ----
  
      require_variable($id);   // course
+     
+     global $USER;
  
      if (! $course = get_record("course", "id", $id)) {
***************
*** 33,44 ****
      print_header("$course->shortname: $strmath_assignments", "$course->fullname", "$navigation $strmath_assignments");
  
- /// Get all the appropriate data
  
!     if (! $math_assignments = get_all_instances_in_course("math_assignment", $course)) {
          notice("There are no $strmath_assignments", "../../course/view.php?id=$course->id");
          die;
      }
  
! /// Print the list of instances (your module will probably extend this)
  
      $timenow = time();
--- 35,46 ----
      print_header("$course->shortname: $strmath_assignments", "$course->fullname", "$navigation $strmath_assignments");
  
  
!     if (!$table = math_assignment_gradestable($course, $USER->id)) {
          notice("There are no $strmath_assignments", "../../course/view.php?id=$course->id");
          die;
      }
+ /*
  
! /// Print the list of instances 
  
      $timenow = time();
***************
*** 55,58 ****
--- 57,61 ----
      $strtotal = get_string("total");
      $strgrade = get_string("grade");
+     $stropen = get_string("open", "math_assignment");
  
      if (isteacher($course->id)) {
***************
*** 155,175 ****
                  $grade->aimcomment = "";
              }
!             if ($grade->papergrade >= 0 && $math_assignment->papergrade > 0)
!                 $papergrade = "$grade->papergrade / $math_assignment->papergrade";
!             else
                  $papergrade = "";
              if ($math_assignment->aimgrade > 0) {
!                 if ($grade->aimgrade >= 0)
                      $aimgrade = "$grade->aimgrade / $math_assignment->aimgrade";
!                 else
!                     $aimgrade = "";
!                 if ($grade->aimoverride > AIMOVR_RESET)
                      $aimgrade .= " (" . get_string("gradeoverride", "math_assignment") . ")";
              }
!             else
                  $aimgrade = "";
              $totalgrade = math_assignment_total_grade($math_assignment, $grade);
              $maxgrade = $math_assignment->papergrade + $math_assignment->aimgrade;
              $totalgrade = "$totalgrade / $maxgrade";
              if ($course->format == "weeks" or $course->format == "topics")
                  $row = array ($math_assignment->section, $link);
--- 158,200 ----
                  $grade->aimcomment = "";
              }
!             if ($math_assignment->papergrade > 0) {
!                 if (!$math_assignment->papersheetsreturned) {
!                     $papergrade = get_string("notpublished", "math_assignment");
!                 } else if ($grade->papergrade >= 0) {
!                     $papergrade = "$grade->papergrade / $math_assignment->papergrade";
!                 } else if ($grade->papergrade = -1) {
!                     $papergrade = "-- / $math_assignment->papergrade";
!                 }
!                 if ($math_assignment->timedue > time()) {
!                     $papergrade = $stropen;
!                 }
!             }
!             else {
                  $papergrade = "";
+             }
              if ($math_assignment->aimgrade > 0) {
!                 if ($grade->aimgrade >= 0) {
                      $aimgrade = "$grade->aimgrade / $math_assignment->aimgrade";
!                 } else {
!                     $aimgrade = "-- / $math_assignment->aimgrade";
!                 }
!                 if ($math_assignment->timedue > time()) {
!                     $aimgrade = $stropen;
!                 }
!                 if ($grade->aimoverride > AIMOVR_RESET) {
                      $aimgrade .= " (" . get_string("gradeoverride", "math_assignment") . ")";
+                 }
              }
!             else {
                  $aimgrade = "";
+             }
+ 
              $totalgrade = math_assignment_total_grade($math_assignment, $grade);
              $maxgrade = $math_assignment->papergrade + $math_assignment->aimgrade;
              $totalgrade = "$totalgrade / $maxgrade";
+             // Don't show a total grade if there is an unpublished paper grade
+             if ($math_assignment->papergrade > 0 and !$math_assignment->papersheetsreturned) {
+                 $totalgrade = "";
+             }
              if ($course->format == "weeks" or $course->format == "topics")
                  $row = array ($math_assignment->section, $link);
***************
*** 188,191 ****
--- 213,217 ----
          }
      }
+ */
  
      print_heading($strmath_assignments);
Index: lib.php
===================================================================
RCS file: /cvsroot/aimmath/moodle/mod/math_assignment/lib.php,v
retrieving revision 1.40
retrieving revision 1.41
diff -C2 -d -r1.40 -r1.41
*** lib.php	31 Oct 2003 14:05:59 -0000	1.40
--- lib.php	2 Nov 2003 15:45:30 -0000	1.41
***************
*** 314,318 ****
      if($math_assignment->problems) {
          if (math_assignment_is_tex_file($math_assignment->problems))
!             $proburl = "pdfgen.php?id=$math_assignment->id&type=problems";
          else if ($math_assignment->problemsisurl)
              $proburl = $math_assignment->problems;
--- 314,318 ----
      if($math_assignment->problems) {
          if (math_assignment_is_tex_file($math_assignment->problems))
!             $proburl = "$CFG->wwwroot/mod/math_assignment/pdfgen.php?id=$math_assignment->id&type=problems";
          else if ($math_assignment->problemsisurl)
              $proburl = $math_assignment->problems;
***************
*** 323,327 ****
      }
      else if ($math_assignment->aimquiz)
!         $proburl = "pdfgen.php?id=$math_assignment->id&type=problems";
      else
          $proburl = "";
--- 323,327 ----
      }
      else if ($math_assignment->aimquiz)
!         $proburl = "$CFG->wwwroot/mod/math_assignment/pdfgen.php?id=$math_assignment->id&type=problems";
      else
          $proburl = "";
***************
*** 329,333 ****
      if($math_assignment->solutions) {
          if (math_assignment_is_tex_file($math_assignment->solutions))
!             $solurl = "pdfgen.php?id=$math_assignment->id&type=solutions";
          else if ($math_assignment->solutionsisurl)
              $solurl = $math_assignment->solutions;
--- 329,333 ----
      if($math_assignment->solutions) {
          if (math_assignment_is_tex_file($math_assignment->solutions))
!             $solurl = "$CFG->wwwroot/mod/math_assignment/pdfgen.php?id=$math_assignment->id&type=solutions";
          else if ($math_assignment->solutionsisurl)
              $solurl = $math_assignment->solutions;
***************
*** 338,342 ****
      }
      else if ($math_assignment->aimquiz)
!         $solurl = "pdfgen.php?id=$math_assignment->id&type=solutions";
      else
          $solurl = "";
--- 338,342 ----
      }
      else if ($math_assignment->aimquiz)
!         $solurl = "$CFG->wwwroot/mod/math_assignment/pdfgen.php?id=$math_assignment->id&type=solutions";
      else
          $solurl = "";
***************
*** 789,793 ****
  /// Funtion which returns the total grade given a grade object
      $grade = min(max($gradeobj->aimgrade, 0), $math_assignment->aimgrade);
!     if ($math_assignment->papersheetreturned) {
          $grade += min(max($gradeobj->papergrade, 0), $math_assignment->papergrade);
      }
--- 789,793 ----
  /// Funtion which returns the total grade given a grade object
      $grade = min(max($gradeobj->aimgrade, 0), $math_assignment->aimgrade);
!     if ($math_assignment->papersheetsreturned) {
          $grade += min(max($gradeobj->papergrade, 0), $math_assignment->papergrade);
      }
***************
*** 872,876 ****
              break;
      }
!     return $students;
  }
  
--- 872,880 ----
              break;
      }
!     if (count($students) > 1) {
!         return $students;
!     } else {
!         return false;
!     }
  }
  
***************
*** 989,992 ****
--- 993,1191 ----
  }
  
+ function math_assignment_gradestable($course, $userid, $showlinks='true') {
+ 
+     global $CFG;
+ 
+     $timenow = time();
+     $strweek  = get_string("week");
+     $strtopic  = get_string("topic");
+     $strname  = get_string("name");
+     $strtimedue = get_string("timedue", "math_assignment");
+     $strproblems = get_string("problemsbrief", "math_assignment");
+     $strsolutions = get_string("solutionsbrief", "math_assignment");
+     $strviewproblems = get_string("view", "math_assignment");
+     $strviewsolutions = get_string("view", "math_assignment");
+     $strpaper = get_string("paper", "math_assignment");
+     $strcomputer = get_string("computer", "math_assignment");
+     $strtotal = get_string("total");
+     $strgrade = get_string("grade");
+     $stropen = get_string("open", "math_assignment");
+     
+     if (! $math_assignments = get_all_instances_in_course("math_assignment", $course)) {
+         return false;
+     }
+ 
+     if (isteacher($course->id, $userid)) {
+         $teacher = true;
+ 
+ //        if ($CFG->math_assignment_aim_display == 0)
+ //            $showaim = false;
+ //        else if ($CFG->math_assignment_aim_display == 1)
+ //            $showaim = isadmin();
+ //        else
+ //            $showaim = true;
+ //
+ //        if ($showaim) {
+ //            $straimsubject = get_string("aimsubject", "math_assignment");
+ //            $strserver = get_string("aimserver", "math_assignment");
+ //        }
+ 
+         if ($course->format == "weeks") {
+             $table->head  = array ($strweek, $strname, $strtimedue, $strproblems, $strsolutions);
+             $table->align = array ("CENTER", "LEFT","LEFT","LEFT","LEFT");
+             $table->width = array (10, "*","*","*","*");
+         } else if ($course->format == "topics") {
+             $table->head  = array ($strtopic, $strname, $strtimedue, $strproblems, $strsolutions);
+             $table->align = array ("CENTER", "LEFT","LEFT","LEFT","LEFT");
+             $table->width = array (10, "*","*","*","*");
+         } else {
+             $table->head  = array ($strname, $strtimedue, $strproblems, $strsolutions);
+             $table->align = array ("LEFT","LEFT","LEFT","LEFT");
+             $table->width = array ("*","*","*","*");
+         }
+         if ($showaim) {
+             array_push($table->head, $straimsubject, $strserver);
+             array_push($table->align, "LEFT", "LEFT");
+             array_push($table->width, "*", "*");
+         }
+     }
+     else {
+         $teacher = false;
+ 
+         if ($course->format == "weeks") {
+             $table->head  = array ($strweek, $strname, $strtimedue, $strproblems, $strsolutions, "$strpaper $strgrade", "$strcomputer $strgrade", "$strtotal $strgrade");
+             $table->align = array ("CENTER", "LEFT", "LEFT", "LEFT", "LEFT", "CENTER", "CENTER", "CENTER");
+             $table->width = array (10, "*", "*", "*", "*", "*", "*", "*");
+         } else if ($course->format == "topics") {
+             $table->head  = array ($strtopic, $strname, $strtimedue, $strproblems, $strsolutions, "$strpaper $strgrade", "$strcomputer $strgrade", "$strtotal $strgrade");
+             $table->align = array ("CENTER", "LEFT", "LEFT", "LEFT", "LEFT", "CENTER", "CENTER", "CENTER");
+             $table->width = array (10, "*", "*", "*", "*", "*", "*", "*");
+         } else {
+             $table->head  = array ($strname, $strtimedue, $strproblems, $strsolutions, "$strpaper $strgrade", "$strcomputer $strgrade", "$strtotal $strgrade");
+             $table->align = array ("LEFT", "LEFT", "LEFT", "LEFT", "CENTER", "CENTER", "CENTER");
+             $table->width = array ("*", "*", "*", "*", "*", "*", "*");
+         }
+     }
+ 
+     foreach ($math_assignments as $math_assignment) {
+ 
+         $link = "<b>$math_assignment->name</b>";
+         if ($showlinks) {
+             $link = "<a href=\"$CFG->wwwroot/mod/math_assignment/view.php?id=$math_assignment->coursemodule\">$link</a>";
+         }
+         if (!$math_assignment->visible) {
+             //Show dimmed if the mod is hidden
+             $link = "<span style=\"dimmed\">$link</span>";
+         }
+             
+         math_assignment_get_file_urls($math_assignment, $proburl, $solurl);
+         $proburl = htmlspecialchars($proburl);
+         $solurl = htmlspecialchars($solurl);
+         if ($teacher) { // this is for teachers. They are not shown any grades
+ //            if ($showaim && $math_assignment->aimquiz) {
+ //                // lookup subject
+ //                if (! $subject = get_record("math_assignment_subject", "course", $course->id)) {
+ //                    $subject->server = 0;
+ //                    $subject->name = "Unknown";
+ //                }
+ //                // lookup server
+ //                if (! $server = get_record("math_assignment_server", "id", $subject->server)) {
+ //                    $server->name = "Unknown";
+ //                    $server->address = "unknown";
+ //                }
+ //            }
+             if ($course->format == "weeks" or $course->format == "topics") {
+                 $row = array ($math_assignment->section, $link);
+             } else {
+                 $row = array ($link);
+             }
+             array_push($row, userdate($math_assignment->timedue, "", 99, false), $proburl ? "<a href=\"$proburl\" target=\"problems\">$strviewproblems</a>" : "", $solurl ? "<a href=\"$solurl\" target=\"solutions\">$strviewsolutions</a>" : "");
+ //            if ($showaim) {
+ //                if ($math_assignment->aimquiz)
+ //                    array_push($row, $subject->name, "$server->name ($server->address)");
+ //                else
+ //                    array_push($row, "", "");
+ //            }
+             $table->data[] = $row;
+         }
+         else if ($math_assignment->visible) { // this is for students. They are shown grades
+             if (!$grade = get_record("math_assignment_grades", "assignment", $math_assignment->id, "userid", $userid)) {
+                 $grade->papergrade = -1;
+                 $grade->aimgrade = -1;
+                 $grade->aimoverride = AIMOVR_OFF;
+                 $grade->aimcomment = "";
+             }
+             if ($math_assignment->papergrade > 0) {
+                 if (!$math_assignment->papersheetsreturned) {
+                     $papergrade = get_string("notpublished", "math_assignment");
+                 } else if ($grade->papergrade >= 0) {
+                     $papergrade = "<b>$grade->papergrade / $math_assignment->papergrade</b>";
+                 } else if ($grade->papergrade = -1) {
+                     $papergrade = "<b>-- / $math_assignment->papergrade</b>";
+                 }
+                 if ($math_assignment->timedue > time()) {
+                     $papergrade = $stropen;
+                 }
+             }
+             else {
+                 $papergrade = "";
+             }
+             if ($math_assignment->aimgrade > 0) {
+                 if ($grade->aimgrade >= 0) {
+                     $aimgrade = "<b>$grade->aimgrade / $math_assignment->aimgrade</b>";
+                 } else {
+                     $aimgrade = "<b>-- / $math_assignment->aimgrade</b>";
+                 }
+                 // show aimgrade in grey if quiz has not closed yet
+                 if ($math_assignment->timedue > time()) {
+                     $aimgrade = "<span style=\"color: silver \">$aimgrade</span>";
+                 }
+                 if ($grade->aimoverride > AIMOVR_RESET) {
+                     $aimgrade .= " (" . get_string("gradeoverride", "math_assignment") . ")";
+                 }
+             }
+             else {
+                 $aimgrade = "";
+             }
+ 
+             $totalgrade = math_assignment_total_grade($math_assignment, $grade);
+             $maxgrade = $math_assignment->papergrade + $math_assignment->aimgrade;
+             $totalgrade = "<b>$totalgrade / $maxgrade</b>";
+             // Don't show a total grade if there is an unpublished paper grade
+             if ($math_assignment->timedue > time() or ($math_assignment->papergrade > 0 and !$math_assignment->papersheetsreturned)) {
+                 $totalgrade = "<span style=\"color: silver \">$totalgrade</span>";
+             }            
+             if ($course->format == "weeks" or $course->format == "topics")
+                 $row = array ($math_assignment->section, $link);
+             else
+                 $row = array ($link);
+             
+             // show links to the solutions only after the due date
+             if ($solurl) {
+                 if ($timenow > $math_assignment->timedue)
+                     $solutions = "<a href=\"$solurl\" target=\"solutions\">$strviewsolutions</a>";
+                 else
+                     $solutions = "";
+             }
+             else
+                 $solutions = "";
+ 
+             array_push($row, userdate($math_assignment->timedue, "", 99, false), $proburl ? "<a href=\"$proburl\" target=\"problems\">$strviewproblems</a>" : "", $solutions, $papergrade, $aimgrade, $totalgrade);
+             $table->data[] = $row;
+         }
+     }
+     if (count($table->data) > 1) {
+         return $table;
+     } else {
+         return false;
+     }
+ }
+ 
+ ////////////////////////////////////////////////////////////////////////////////////
+ //
+ // The following functions are general purpose functions not specific to this module
+ //
+ 
+ 
  function str_replace_once($needle, $replace, $haystack) {
      // Looks for the first occurence of $needle in $haystack
***************
*** 1034,1037 ****
--- 1233,1237 ----
      }
  }
+ 
  
  ?>
Index: pdfgen.php
===================================================================
RCS file: /cvsroot/aimmath/moodle/mod/math_assignment/pdfgen.php,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** pdfgen.php	31 Oct 2003 14:05:59 -0000	1.21
--- pdfgen.php	2 Nov 2003 15:45:30 -0000	1.22
***************
*** 10,14 ****
      optional_variable($printcopies);  // number of randomized copies to send to printer
      optional_variable($seed, 0);  // seed to be passed to AiM. 0 means no seed set.
!                                   // This may be overruled by the student's saved seed.
      global $USER;
  
--- 10,14 ----
      optional_variable($printcopies);  // number of randomized copies to send to printer
      optional_variable($seed, 0);  // seed to be passed to AiM. 0 means no seed set.
! 	              // This may be overruled by the student's saved seed.
      global $USER;
  
***************
*** 25,43 ****
      }
  
!     require_login($course->id);
      
!     if (!isstudent($course->id) and !isteacher($course->id)) {
          error("Sorry, this assignment is not for you!");
      }
  
      add_to_log($course->id, "math_assignment", "pdfgen", "pdfgen.php?id=$math_assignment->id", $type);
  
-     // check that the request is valid
-     if ($solutions) {
-         if (time() < $math_assignment->solutiontime and !isteacher($course->id)) {
-             error("You can not view the solutions yet!");
-         }
-     }
- 
      if ($math_assignment->aimquiz) {
  
--- 25,42 ----
      }
  
!     require_login();
      
!     // have to be a student on this course or a teacher on any course to view this page
!     if (!isstudent($course->id) and !record_exists("user_teachers", "userid", $USER->id)) {
          error("Sorry, this assignment is not for you!");
      }
+     
+     // make sure students don't look at solutions before they should
+     if (($type == "solutions") and isstudent($course->id) and $math_assignment->solutiontime > time()){
+         error("You can not view the solutions yet!");
+     }
  
      add_to_log($course->id, "math_assignment", "pdfgen", "pdfgen.php?id=$math_assignment->id", $type);
  
      if ($math_assignment->aimquiz) {
  
***************
*** 125,129 ****
              // tell the browser that it is pdf
              header("Content-type: application/pdf");
!             if ($solutions)
                  header("Content-disposition: inline; filename=solutions.pdf");
              else
--- 124,128 ----
              // tell the browser that it is pdf
              header("Content-type: application/pdf");
!             if ($type = "solutions")
                  header("Content-disposition: inline; filename=solutions.pdf");
              else
***************
*** 134,138 ****
          }
  */
! //error("Problem and solution sheets are temporarily unavailable. You can however still view the AiM assignment.");
      }
  
--- 133,140 ----
          }
  */
! error("<p>Problem and solution sheets are temporarily unavailable. You can however still view the AiM assignment.</p>
!  <p>Unfortunately the machine that was supposed to automatically
!  generate these sheets has had a hard disk failure. If you did not receive a copy of the problem sheet during the lectures
!  please send an email to <a href=\"mailto:gw...@yo...\">gw...@yo...</a>. I may be able to email you the pdf file. </p>");
      }
  
***************
*** 171,175 ****
                  // attempt to register them automatically
                  if (!math_assignment_register_with_aim($server, $subject)) {
!                     error(get_string("nooutput", "math_assignment"), "view.php?id=$cm->id");
                  }
                  // retry
--- 173,177 ----
                  // attempt to register them automatically
                  if (!math_assignment_register_with_aim($server, $subject)) {
! 	error(get_string("nooutput", "math_assignment"), "view.php?id=$cm->id");
                  }
                  // retry
***************
*** 205,209 ****
          }
      }
!     else if ($type == solutions) {
          if ($math_assignment->solutionsisurl) {
              $texfile = $math_assignment->solutions;
--- 207,211 ----
          }
      }
!     else if ($type == "solutions") {
          if ($math_assignment->solutionsisurl) {
              $texfile = $math_assignment->solutions;
Index: view.php
===================================================================
RCS file: /cvsroot/aimmath/moodle/mod/math_assignment/view.php,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** view.php	31 Oct 2003 14:05:59 -0000	1.21
--- view.php	2 Nov 2003 15:45:30 -0000	1.22
***************
*** 76,79 ****
--- 76,81 ----
      $strgrades = get_string("grades");
      $strreview = get_string("review", "math_assignment");
+     $strshowgradestable = get_string("showgradestable", "math_assignment");
+     $strhidegradestable = get_string("hidegradestable", "math_assignment");
  
      if ($course->category) {
***************
*** 325,331 ****
              echo math_assignment_get_admin_links($cm, $math_assignment, $zonelink, "center");
              if ($showgrades) {
!                 echo "<center><a href=\"view.php?id=$cm->id\">Hide grades table</a></center>";
              } else {
!                 echo "<center><a href=\"view.php?id=$cm->id&showgrades=true\">Show Grades table</a></center>";
              }
          }
--- 327,333 ----
              echo math_assignment_get_admin_links($cm, $math_assignment, $zonelink, "center");
              if ($showgrades) {
!                 echo "<center><a href=\"view.php?id=$cm->id\">$strhidegradestable</a></center>";
              } else {
!                 echo "<center><a href=\"view.php?id=$cm->id&showgrades=true\">$strshowgradestable</a></center>";
              }
          }
***************
*** 418,422 ****
                      echo "<center>The grades have not yet been finalized</center>";
                  }
!                 if (!$math_assignment->papersheetsreturned and !empty($USER->teacheredit[$course->id])) {
                      echo "<table border=\"0\" align=\"center\"><tr><td>";
                      $options = array("id"=>$cm->id); 
--- 420,424 ----
                      echo "<center>The grades have not yet been finalized</center>";
                  }
!                 if (!$math_assignment->papersheetsreturned and (!empty($USER->teacheredit[$course->id]) or isadmin())) {
                      echo "<table border=\"0\" align=\"center\"><tr><td>";
                      $options = array("id"=>$cm->id); 
 |