]> git.mjollnir.org Git - moodle.git/commitdiff
fixed bugs in view.php, mod.html, viewall.php
authorjungwirr <jungwirr>
Wed, 17 Sep 2003 14:37:42 +0000 (14:37 +0000)
committerjungwirr <jungwirr>
Wed, 17 Sep 2003 14:37:42 +0000 (14:37 +0000)
added add.php for adding mutiple instances at once - not nearly done yet!

mod/attendance/add.php [new file with mode: 0644]
mod/attendance/lib.php
mod/attendance/mod.html
mod/attendance/version.php
mod/attendance/view.php
mod/attendance/viewall.php

diff --git a/mod/attendance/add.php b/mod/attendance/add.php
new file mode 100644 (file)
index 0000000..6136c7e
--- /dev/null
@@ -0,0 +1,250 @@
+<?php  // $Id$
+/// This page prints all instances of attendance in a given course
+    error_reporting(E_ALL);
+    require("../../config.php");
+    require("lib.php");
+
+if (isset($_POST["course"]))  {
+
+echo "<html><body><pre>";
+echo "submitted form with these values:\n";
+
+    var_dump($_POST);
+
+echo "</pre></body></html>";
+/*
+
+    require_login();
+/// -----------------------------------------------------------------------------------
+/// --------------------SECTION FOR PROCESSING THE FORM ON POST -----------------------
+/// -----------------------------------------------------------------------------------
+    if (isset($SESSION->modform)) {   // Variables are stored in the session
+        $mod = $SESSION->modform;
+        unset($SESSION->modform);
+    } else {
+        $mod = (object)$_POST;
+    }
+
+
+    if (isset($cancel)) {  
+        if (!empty($SESSION->returnpage)) {
+            $return = $SESSION->returnpage;
+            unset($SESSION->returnpage);
+            redirect($return);
+        } else {
+            redirect("view.php?id=$mod->course");
+        }
+    }
+
+
+    if (isset($_POST["course"])) {    // add or update form submitted
+
+        if (!isteacheredit($mod->course)) {
+            error("You can't modify this course!");
+        }
+
+        $modlib = "../mod/$mod->modulename/lib.php";
+        if (file_exists($modlib)) {
+            include_once($modlib);
+        } else {
+            error("This module is missing important code! ($modlib)");
+        }
+        $addinstancefunction    = $mod->modulename."_add_instance";
+        $updateinstancefunction = $mod->modulename."_update_instance";
+        $deleteinstancefunction = $mod->modulename."_delete_instance";
+
+        switch ($mod->mode) {
+            case "update":
+                if (! $updateinstancefunction($mod)) {
+                    error("Could not update the $mod->modulename");
+                }
+                add_to_log($mod->course, "course", "update mod", 
+                           "../mod/$mod->modulename/view.php?id=$mod->coursemodule", 
+                           "$mod->modulename $mod->instance"); 
+                break;
+
+            case "add":
+                if (! $mod->instance = $addinstancefunction($mod)) {
+                    error("Could not add a new instance of $mod->modulename");
+                }
+                // course_modules and course_sections each contain a reference 
+                // to each other, so we have to update one of them twice.
+
+                if (! $mod->coursemodule = add_course_module($mod) ) {
+                    error("Could not add a new course module");
+                }
+                if (! $sectionid = add_mod_to_section($mod) ) {
+                    error("Could not add the new course module to that section");
+                }
+                if (! set_field("course_modules", "section", $sectionid, "id", $mod->coursemodule)) {
+                    error("Could not update the course module with the correct section");
+                }   
+                add_to_log($mod->course, "course", "add mod", 
+                           "../mod/$mod->modulename/view.php?id=$mod->coursemodule", 
+                           "$mod->modulename $mod->instance"); 
+                break;
+            case "delete":
+                if (! $deleteinstancefunction($mod->instance)) {
+                    notify("Could not delete the $mod->modulename (instance)");
+                }
+                if (! delete_course_module($mod->coursemodule)) {
+                    notify("Could not delete the $mod->modulename (coursemodule)");
+                }
+                if (! delete_mod_from_section($mod->coursemodule, "$mod->section")) {
+                    notify("Could not delete the $mod->modulename from that section");
+                }
+                add_to_log($mod->course, "course", "delete mod", 
+                           "view.php?id=$mod->course", 
+                           "$mod->modulename $mod->instance"); 
+                break;
+            default:
+                error("No mode defined");
+
+        }
+
+        rebuild_course_cache($mod->course);
+
+        if (!empty($SESSION->returnpage)) {
+            $return = $SESSION->returnpage;
+            unset($SESSION->returnpage);
+            redirect($return);
+        } else {
+            redirect("view.php?id=$mod->course");
+        }
+        exit;
+    }
+*/
+
+
+} else {
+/// -----------------------------------------------------------------------------------
+/// ------------------ SECTION FOR MAKING THE FORM TO BE POSTED -----------------------
+/// -----------------------------------------------------------------------------------
+
+/// @include_once("$CFG->dirroot/mod/attendance/lib.php"); 
+/// error_reporting(E_ALL);
+
+    optional_variable($id);    // Course Module ID, or
+    optional_variable($a);     // attendance ID
+
+/// populate the appropriate objects
+    if ($id) {
+        if (! $course = get_record("course", "id", $id)) {
+            error("Course is misconfigured");
+        }
+        if (! $attendance = get_record("attendance", "course", $id)) {
+            error("Course module is incorrect");
+        }
+/*        if (! $cm = get_coursemodule_from_instance("attendance", $attendance->id, $id)) {
+            error("Course Module ID was incorrect");
+        }
+        if (! $attendances = get_records("attendance", "course", $cm->course)) {
+            error("Course module is incorrect");
+        }
+*/
+    } else {
+        if (! $attendance = get_record("attendance", "id", $a)) {
+            error("Course module is incorrect");
+        }
+        if (! $course = get_record("course", "id", $attendance->course)) {
+            error("Course is misconfigured");
+        }
+        if (! $cm = get_coursemodule_from_instance("attendance", $attendance->id, $course->id)) {
+            error("Course Module ID was incorrect");
+        }
+        if (! $attendances = get_records("attendance", "course", $cm->course)) {
+            error("Course module is incorrect");
+        }
+    }
+
+    require_login($course->id);
+
+    add_to_log($course->id, "attendance", "add", "add.php?id=$course->id");
+
+/// Print the page header
+    if ($course->category) {
+        $navigation = "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->";
+    }
+
+    $strattendances = get_string("modulenameplural", "attendance");
+    $strattendance  = get_string("modulename", "attendance");
+    $straddmultiple  = get_string("addmultiple", "attendance");
+    $strallattendance = get_string("allmodulename", "attendance");
+    
+    print_header("$course->shortname: $strallattendance", "$course->fullname",
+                 "$navigation <A HREF=index.php?id=$course->id>$strattendances</A> -> $straddmultiple", 
+                  "", "", true, "&nbsp;", 
+                  navmenu($course));
+/// Print the main part of the page
+
+   // adaptation of mod code to view code needs this:
+   $form = $attendance;
+
+   if (!isteacher($course->id)) {
+     notice(get_string("cantadd", "attendance"));
+     print_footer($course); exit;
+   }
+//choose the start date
+//choose the end date
+//OR 
+//for the whole course
+//choose the days of the week you want attendance 
+  @include_once("$CFG->dirroot/mod/attendance/lib.php");
+    //require_once("lib.php")
+?>
+<FORM name="form" method="post" action="<?=$ME ?>">
+<CENTER>
+<INPUT type="submit" value="<? print_string("savechanges") ?>">
+<INPUT type="submit" name="cancel" value="<? print_string("cancel") ?>">
+<TABLE cellpadding=5>
+
+<!-- <? $options[0] = get_string("no"); $options[1] = get_string("yes"); ?> -->
+<!-- <TR valign=top> -->
+<!--     <TD align=right><P><B><? print_string("takeroll", "attendance") ?>:</B></P></TD> -->
+<!--     <TD align=left><? choose_from_menu($options, "roll", $form->roll, "") ?></td> -->
+<!-- </tr> -->
+
+<TR valign=top>
+    <TD align=right><P><B><?php print_string("dayofroll", "attendance") ?>:</B></P></TD>
+    <TD colspan="3"><?php print_date_selector("theday", "themonth", "theyear", $form->day) ?></TD>
+</TR>
+<tr valign=top>
+    <TD align="right"><P><B><?php print_string("dynamicsection", "attendance") ?>:</B></P></TD>
+    <TD align="left">
+      <input type="checkbox" name="dynsection" <?php echo !empty($form->dynsection) ? 'checked' : '' ?> >
+    </TD>
+</tr>
+<?php // starting with 2 to allow for the nothing value in choose_from_menu to be the default of 1
+for ($i=2;$i<=24;$i++){ $opt[$i] = $i; } ?>
+<TR valign=top>
+    <TD align=right><P><B><?php print_string("hoursinclass", "attendance") ?>:</B></P></TD>
+    <TD  colspan="3" align="left"><?php choose_from_menu($opt, "hours", $form->hours, "1","","1") ?></td>
+</tr>
+<tr valign=top>
+    <td align=right><p><b><?php print_string("notes", "attendance") ?>:</b></p></td>
+    <td colspan="3">
+        <input type="text" name="notes" size=60 value="<?php p($form->notes) ?>">
+    </td>
+</tr>
+</TABLE>
+<!-- These hidden variables are always the same -->
+<INPUT type="hidden" name=course        value="<?php p($form->course) ?>">
+<INPUT type="hidden" name=coursemodule  value="<?php p($form->coursemodule) ?>">
+<INPUT type="hidden" name=section       value="<?php p($form->section) ?>">
+<INPUT type="hidden" name=module        value="<?php p($form->module) ?>">
+<INPUT type="hidden" name=modulename    value="<?php p($form->modulename) ?>">
+<INPUT type="hidden" name=instance      value="<?php p($form->instance) ?>">
+<INPUT type="hidden" name=mode          value="<?php p($form->mode) ?>">
+<BR />
+<INPUT type="submit" value="<?php print_string("savechanges") ?>">
+<INPUT type="submit" name="cancel" value="<?php print_string("cancel") ?>">
+</CENTER>
+</FORM>
+
+<?php
+/// Finish the page
+    print_footer($course);
+    }
+
+?>
\ No newline at end of file
index efbeaece7fc09fb77f4fceef30a82bc9a31ea81e..4ed73a57378ec4dc32c07767862495eece9ee702 100755 (executable)
@@ -4,7 +4,8 @@
 
 // error_reporting(E_ALL);
 
-function attendance_add_instance(&$attendance) {
+function attendance_add_instance($attendance) {
+       global $mod;
      $attendance->timemodified = time();
      $attendance->dynsection = !empty($attendance->dynsection) ? 1 : 0;
      $attendance->day = make_timestamp($attendance->theyear, 
@@ -13,14 +14,30 @@ function attendance_add_instance(&$attendance) {
         if ($attendance->notes) { 
                $attendance->name = $attendance->name . " - " . $attendance->notes;
         }
+
+if (($attendance->dynsection) && ($course->format =="weeks")) { 
+       if ($mod->course) {
+               if (! $course = get_record("course", "id", $mod->course)) {
+                       error("Course is misconfigured");
+               }
+       }
+//     floor($date_relative / 604800) + 1
+       $attendance->section = floor(($attendance->day - $course->startdate)/604800) +1;
+       if($attendance->section > $course->numsections){
+               $attendance->section = 0;
+       }
+       $attendance->section = "$attendance->section";
+       $mod->section = "$attendance->section";
+}
         // insert the main record first
         return $attendance->id = insert_record("attendance", $attendance);
 }
 
 
-function attendance_update_instance(&$attendance) {
+function attendance_update_instance($attendance) {
+       global $mod;
     $attendance->timemodified = time();
-    $attendance->oldid=$attendance->id;
+//    $attendance->oldid=$attendance->id;
     $attendance->id = $attendance->instance;
     $attendance->dynsection = !empty($attendance->dynsection) ? 1 : 0;
 
@@ -31,29 +48,71 @@ function attendance_update_instance(&$attendance) {
                $attendance->name = $attendance->name . " - " . 
                  $attendance->notes;
         }  
+  if (($attendance->dynsection) && ($course->format =="weeks")) { 
+           //get info about the course
+               if ($mod->course) {
+                       if (! $course = get_record("course", "id", $mod->course)) {
+                               error("Course is misconfigured");
+                       }
+               }
+               
+               //work out which section this should be in
+               $attendance->section = floor(($attendance->day - $course->startdate)/604800) +1;
+               if($attendance->section > $course->numsections){
+                       $attendance->section = 0;
+               }
+               $attendance->section = "$attendance->section";
+  }    
        // get the data from the attendance grid
-    if ($data = data_submitted()) {      
-      // Peel out all the data from variable names.
-      $attrec->dayid = $attendance->id;
-      foreach ($data as $key => $val) {
-        $pieces = explode('_',$key);
-        if ($pieces[0] == 'student') {
-                 $attrec->userid=$pieces[1];
-          $attrec->hour=$pieces[2];
-          $attrec->status=$val;
-          // clear out any old records for the student
-                 delete_records("attendance_roll", 
-            "dayid",$attrec->dayid,
-            "hour", $attrec->hour, 
-            "userid",$attrec->userid);
-          if ($attrec->status != 0) { 
-            // student is registered as absent or tardy
-                   insert_record("attendance_roll",$attrec, false);
-          }
-       } // if we have a piece of the student roll data
-      } // foreach for all form variables
-    } // if    
-    return  update_record("attendance", $attendance);
+  if ($data = data_submitted()) {      
+    // Peel out all the data from variable names.
+    $attrec->dayid = $attendance->id;
+    foreach ($data as $key => $val) {
+      $pieces = explode('_',$key);
+      if ($pieces[0] == 'student') {
+         $attrec->userid=$pieces[1];
+        $attrec->hour=$pieces[2];
+        $attrec->status=$val;
+        // clear out any old records for the student
+         delete_records("attendance_roll", 
+          "dayid",$attrec->dayid,
+          "hour", $attrec->hour, 
+          "userid",$attrec->userid);
+        if ($attrec->status != 0) { 
+          // student is registered as absent or tardy
+               insert_record("attendance_roll",$attrec, false);
+        }
+       } // if we have a piece of the student roll data
+    } // foreach for all form variables
+  } // if      
+
+
+       if(!update_record("attendance", $attendance)){
+               error("Couldn't update record");
+       }
+       
+       if ($attendance->dynsection) {
+               //get section info
+               $section = get_record("course_sections", "course", $attendance->course, "section", $attendance->section);
+               
+               //remove module from the current section
+               if (! delete_mod_from_section($attendance->coursemodule, $mod->section)) {
+              notify("Could not delete module from existing section");
+           }
+           
+           //update course with new module location
+           if(! set_field("course_modules", "section", $section->id, "id", $attendance->coursemodule)){
+                notify("Could not update course module list");
+           }
+           
+           //add module to the new section
+           if (! add_mod_to_section($attendance, NULL)) {
+               notify("Could not add module to new section");
+           }
+       
+               rebuild_course_cache($section->course);
+       }
+       return true;
 }
 
 function attendance_delete_instance($id) {
@@ -127,6 +186,10 @@ function attendance_user_complete($course, $user, $mod, $attendance) {
 /// Print a detailed representation of what a  user has done with 
 /// a given particular instance of this module, for user activity reports.
     // get the attendance record for that day and user
+    $A = get_string("absentshort","attendance");
+    $T = get_string("tardyshort","attendance");
+    $P = get_string("presentshort","attendance");
+
     $attrecs=attendance_get_records("attendance_roll", "dayid", $attendance->id, "userid", $user->id, "", "", "hour ASC");
     // fill an array with the absences and tardies, as those are the only records actually stored
     $grid = array();
@@ -140,8 +203,8 @@ function attendance_user_complete($course, $user, $mod, $attendance) {
        for($j=1;$j<=$attendance->hours;$j++) {
       // set the attendance defaults for each student
              if (isset($grid[$j])) {
-               $status = (($grid[$j] == 1) ? "T" : "A");
-             } else {$status="X";}
+               $status = (($grid[$j] == 1) ? $T : $A);
+             } else {$status=$P;}
       echo "<td align=\"left\" nowrap class=\"generaltablecell\" style=\"border-left: 1px dotted; border-top: 1px solid;\">".$status."</td>\n";
        } /// for loop
     echo "</tr></table>\n";
index ecfb48f770b108a0c9e29f744bc185164fb26ebd..a4ce37337b6f3ddc184e8682b7b7859dad928a07 100755 (executable)
@@ -3,56 +3,58 @@
 
 <!-- RJJ I'm using inline CSS styles for some stuff in this page because I want to centralize -->
 <!-- the logic and styles in a single directory -->
- <?php   @include_once("$CFG->dirroot/mod/attendance/lib.php") 
+  <?php @include_once("$CFG->dirroot/mod/attendance/lib.php")
     //require_once("lib.php")
     ?>
-<FORM name="form" method="post" action="<?php echo $ME ?>">
+<FORM name="form" method="post" action="<?=$ME ?>">
 <CENTER>
-<INPUT type="submit" value="<?php  print_string("savechanges") ?>">
-<INPUT type="submit" name="cancel" value="<?php  print_string("cancel") ?>">
+<INPUT type="submit" value="<? print_string("savechanges") ?>">
+<INPUT type="submit" name="cancel" value="<? print_string("cancel") ?>">
 <TABLE cellpadding=5>
 
-<!-- <?php  $options[0] = get_string("no"); $options[1] = get_string("yes"); ?> -->
+<!-- <? $options[0] = get_string("no"); $options[1] = get_string("yes"); ?> -->
 <!-- <TR valign=top> -->
-<!--     <TD align=right><P><B><?php  print_string("takeroll", "attendance") ?>:</B></P></TD> -->
-<!--     <TD align=left><?php  choose_from_menu($options, "roll", $form->roll, "") ?></td> -->
+<!--     <TD align=right><P><B><? print_string("takeroll", "attendance") ?>:</B></P></TD> -->
+<!--     <TD align=left><? choose_from_menu($options, "roll", $form->roll, "") ?></td> -->
 <!-- </tr> -->
 
 <TR valign=top>
-    <TD align=right><P><B><?php  print_string("dayofroll", "attendance") ?>:</B></P></TD>
-    <TD colspan="3"><?php  print_date_selector("theday", "themonth", "theyear", $form->day) ?></TD>
+    <TD align=right><P><B><?php print_string("dayofroll", "attendance") ?>:</B></P></TD>
+    <TD colspan="3"><?php print_date_selector("theday", "themonth", "theyear", $form->day) ?></TD>
 </TR>
 <tr valign=top>
-    <TD align="right"><P><B><?php  print_string("dynamicsection", "attendance") ?>:</B></P></TD>
+    <TD align="right"><P><B><?php print_string("dynamicsection", "attendance") ?>:</B></P></TD>
     <TD align="left">
-      <input type="checkbox" name="dynsection" <?php  echo !empty($form->dynsection) ? 'checked' : '' ?> >
+      <input type="checkbox" name="dynsection" <?php echo !empty($form->dynsection) ? 'checked' : '' ?> >
     </TD>
 </tr>
-<?php  // starting with 2 to allow for the nothing value in choose_from_menu to be the default of 1
+<?php // starting with 2 to allow for the nothing value in choose_from_menu to be the default of 1
 for ($i=2;$i<=24;$i++){ $opt[$i] = $i; } ?>
 <TR valign=top>
-    <TD align=right><P><B><?php  print_string("hoursinclass", "attendance") ?>:</B></P></TD>
-    <TD  colspan="3" align="left"><?php  choose_from_menu($opt, "hours", $form->hours, "1","","1") ?></td>
+    <TD align=right><P><B><?php print_string("hoursinclass", "attendance") ?>:</B></P></TD>
+    <TD  colspan="3" align="left"><?php choose_from_menu($opt, "hours", $form->hours, "1","","1") ?></td>
 </tr>
 <tr valign=top>
-    <td align=right><p><b><?php  print_string("notes", "attendance") ?>:</b></p></td>
+    <td align=right><p><b><?php print_string("notes", "attendance") ?>:</b></p></td>
     <td colspan="3">
-        <input type="text" name="notes" size=60 value="<?php  p($form->notes) ?>">
+        <input type="text" name="notes" size=60 value="<?php p($form->notes) ?>">
     </td>
 </tr>
 </TABLE>
 
 
-<?php   // if we're modifying an existing instance of attendance instead 
+<?php  // if we're modifying an existing instance of attendance instead 
     //   of creating a new one
  if ($form->id) {
    // get the list of attendance records for all hours of the given day and 
    // put it in the array for use in the attendance table
    $rolls = get_records("attendance_roll", "dayid", $form->id);
-   foreach ($rolls as $roll) {
-      $sroll[$roll->userid][$roll->hour]->status=$roll->status;
-      $sroll[$roll->userid][$roll->hour]->notes=$roll->notes;
-       }
+   if ($rolls) {
+     foreach ($rolls as $roll) {
+       $sroll[$roll->userid][$roll->hour]->status=$roll->status;
+       $sroll[$roll->userid][$roll->hour]->notes=$roll->notes;
+          }
+   }
    // get the list of students along with student ID field
 // get back array of stdclass objects in sorted order, with members:
 // id, username,firstname,lastname,maildisplay,mailformat,email,city,country,
@@ -129,15 +131,15 @@ if ($form->hours >1) {
 } // if ($form->id)
 ?>
 <!-- These hidden variables are always the same -->
-<INPUT type="hidden" name=course        value="<?php  p($form->course) ?>">
-<INPUT type="hidden" name=coursemodule  value="<?php  p($form->coursemodule) ?>">
-<INPUT type="hidden" name=section       value="<?php  p($form->section) ?>">
-<INPUT type="hidden" name=module        value="<?php  p($form->module) ?>">
-<INPUT type="hidden" name=modulename    value="<?php  p($form->modulename) ?>">
-<INPUT type="hidden" name=instance      value="<?php  p($form->instance) ?>">
-<INPUT type="hidden" name=mode          value="<?php  p($form->mode) ?>">
+<INPUT type="hidden" name=course        value="<?php p($form->course) ?>">
+<INPUT type="hidden" name=coursemodule  value="<?php p($form->coursemodule) ?>">
+<INPUT type="hidden" name=section       value="<?php p($form->section) ?>">
+<INPUT type="hidden" name=module        value="<?php p($form->module) ?>">
+<INPUT type="hidden" name=modulename    value="<?php p($form->modulename) ?>">
+<INPUT type="hidden" name=instance      value="<?php p($form->instance) ?>">
+<INPUT type="hidden" name=mode          value="<?php p($form->mode) ?>">
 <BR />
-<INPUT type="submit" value="<?php  print_string("savechanges") ?>">
-<INPUT type="submit" name="cancel" value="<?php  print_string("cancel") ?>">
+<INPUT type="submit" value="<?php print_string("savechanges") ?>">
+<INPUT type="submit" name="cancel" value="<?php print_string("cancel") ?>">
 </CENTER>
 </FORM>
index 5a7356808aef6d6992b1bf7b188d5a353b4b2d78..380cd3e28171507d4d52d7eb718ab396d02112ff 100644 (file)
@@ -5,7 +5,7 @@
 ///  This fragment is called by moodle_needs_upgrading() and /admin/index.php
 /////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2003091001;  // The current module version (Date: YYYYMMDDXX)
+$module->version  = 2003090301;  // The current module version (Date: YYYYMMDDXX)
 $module->cron     = 0;           // Period for cron to check this module (secs)
 
 ?>
index fabf3c2cab8618cd16c0affd24878ae937380f1e..67f8d3df2e4782f7faaee0ae7b588fe787a51606 100644 (file)
@@ -1,4 +1,4 @@
-<?php   // $Id$
+<?  // $Id$
 /// This page prints a particular instance of attendance
     require_once("../../config.php");
     require_once("lib.php" );
        $students[0] = get_user_info_from_db("id", $USER->id);
   }
   $i=0;
+  $A = get_string("absentshort","attendance");
+  $T = get_string("tardyshort","attendance");
+  $P = get_string("presentshort","attendance");  
+  
   foreach ($students as $student) {
     echo "<tr><td align=\"left\" nowrap class=\"generaltablecell\" style=\"border-top: 1px solid;\">".$student->lastname."</td>\n";
     echo "<td align=\"left\" nowrap class=\"generaltablecell\"  style=\"border-top: 1px solid;\">".$student->firstname."</td>\n";
          $abs=$tar=0;
          for($j=1;$j<=$form->hours;$j++) {
       // set the attendance defaults for each student
-             if ($sroll[$student->id][$j]->status == 1) {$status="T";$tar++;}
-             elseif ($sroll[$student->id][$j]->status == 2) {$status="A";$abs++;}
-           else {$status="X";}
+             if ($sroll[$student->id][$j]->status == 1) {$status=$T;$tar++;}
+             elseif ($sroll[$student->id][$j]->status == 2) {$status=$A;$abs++;}
+           else {$status=$P;}
       echo "<td align=\"left\" nowrap class=\"generaltablecell\" style=\"border-left: 1px dotted; border-top: 1px solid;\">".$status."</td>\n";
          } /// for loop
     if ($form->hours > 1) {
index 86e55dbb1c0b07d728eb824985921e3fbb3df7f8..48624b8923ea19888a4ae7f6692d04bf36291bdb 100644 (file)
@@ -1,4 +1,4 @@
-<?php   // $Id$
+<?  // $Id$
 /// This page prints all instances of attendance in a given course
 
     require_once("../../config.php");
@@ -14,7 +14,7 @@
         if (! $course = get_record("course", "id", $id)) {
             error("Course is misconfigured");
         }
-        if (! $attendances = get_records("attendance", "course", $id)) {
+        if (! $attendances = get_records("attendance", "course", $id, "day ASC ")) {
             error("Course module is incorrect");
         }
     } else {
@@ -34,7 +34,7 @@
 
     require_login($course->id);
 
-    add_to_log($course->id, "attendance", "viewall", "viewall.php?id=$cm->id", "$attendance->id");
+    add_to_log($course->id, "attendance", "viewall", "viewall.php?id=$course->id");
 
 /// Print the page header
     if ($course->category) {
@@ -93,10 +93,12 @@ if ($attendances) {
      } else { // must be a teacher
         $rolls = get_records("attendance_roll", "dayid", $attendance->id);
      }
-     foreach ($rolls as $roll) {
-       $atts[$numatt]->sroll[$roll->userid][$roll->hour]->status=$roll->status;
-       $atts[$numatt]->sroll[$roll->userid][$roll->hour]->notes=$roll->notes;
-        }
+     if ($rolls) {
+            foreach ($rolls as $roll) {
+              $atts[$numatt]->sroll[$roll->userid][$roll->hour]->status=$roll->status;
+              $atts[$numatt]->sroll[$roll->userid][$roll->hour]->notes=$roll->notes;
+            }
+     }
    $numatt++;
    }
 
@@ -116,7 +118,7 @@ if ($attendances) {
 // adjust the width for the report for students 
 
    if (($onetable) || ($CFG->attendance_hours_in_full_report == 0)) {
-      $hoursinreport = 10000;          
+      $hoursinreport = 100+$numhours;
    } else if (isstudent($course->id)) {
       $hoursinreport = $CFG->attendance_hours_in_full_report + 15;
    } else { 
@@ -140,7 +142,7 @@ while (($multipage || $onepage) && (!$endonepage)) {
 //             $startatt=$endatt;
                $curpage=1;
                $endatt=0;
-      for($curpage=1;true;$curpage++) { // the for loop is broken from the inside
+  for($curpage=1;true;$curpage++) { // the for loop is broken from the inside
                $pagehours=$atts[$endatt]->attendance->hours;
                $startatt=$endatt;
                while(($pagehours<$hoursinreport)) {
@@ -230,6 +232,9 @@ while (($multipage || $onepage) && (!$endonepage)) {
     $students = attendance_get_course_students($attendance->course, "u.lastname ASC");
   }
   $i=0;
+  $A = get_string("absentshort","attendance");
+  $T = get_string("tardyshort","attendance");
+  $P = get_string("presentshort","attendance");  
   foreach ($students as $student) {
     if (isteacher($course->id)) {
       echo "<tr><td align=\"left\" nowrap class=\"generaltablecell\" style=\"border-top: 1px solid;\">".$student->lastname."</td>\n";
@@ -240,9 +245,9 @@ while (($multipage || $onepage) && (!$endonepage)) {
     for($k=$minatt;$k<$maxatt;$k++)  {  // for eacj day of attendance for the student
          for($j=1;$j<=$atts[$k]->attendance->hours;$j++) {
       // set the attendance defaults for each student
-           if ($atts[$k]->sroll[$student->id][$j]->status == 1) {$status="T";}
-           elseif ($atts[$k]->sroll[$student->id][$j]->status == 2) {$status="A";}
-           else {$status="X";}
+           if ($atts[$k]->sroll[$student->id][$j]->status == 1) {$status=$T;}
+           elseif ($atts[$k]->sroll[$student->id][$j]->status == 2) {$status=$A;}
+           else {$status=$P;}
         echo "<td align=\"left\" nowrap class=\"generaltablecell\" style=\"border-left: 1px dotted; border-top: 1px solid;\">".$status."</td>\n";
          } /// for loop
     }