Removing Attendance from main tree (it's now in contrib/attendance)

This commit is contained in:
moodler
2005-06-02 14:18:43 +00:00
parent b2d5bbbf1e
commit 7d45304236
22 changed files with 0 additions and 3513 deletions
-30
View File
@@ -1,30 +0,0 @@
ATTENDANCE version 0.1
----------------------
By Russell Jungwirth ([email protected])
This is the attendance module created and maintained by Russell J. Jungwirth
of Sureblue Studios. (surebluestudios.com) It allows for attendance to be
tracked for an arbitrary number of hours per instance. Instances are
labelled by date. Attendance is tracked for all instances in a given course
as well.
Quick install instructions
1) Copy attendance.php into lang/en/attendance.php
2) Move this folder to become mod/attendance
3) Visit your admin page to install the module
4) Go to the site configuration page -> modules section -> attendance
to specify your preferences for the module (optional)
New Feature and fix list:
Automatic attendance loggin based on IP address range
Attendance logging by email/Imode (via cel phone)
Specify a range of attendance times for automatic attendance logging.
Tighter integration with the new calendar features.
-286
View File
@@ -1,286 +0,0 @@
<?php // $Id$
/// This page prints all instances of attendance in a given course
error_reporting(E_ALL);
require("../../config.php");
require("lib.php");
// if form is being submitted from generated form
if (isset($_POST["course"])) {
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 (!isteacheredit($mod->course)) {
error("You can't modify this course!");
}
$modlib = "lib.php";
if (file_exists($modlib)) {
include_once($modlib);
} else {
error("This module is missing important code! ($modlib)");
}
/* // set the information for the new instances
$attendance->dynsection = !empty($attendance->dynsection) ? 1 : 0;
$attendance->day = make_timestamp($attendance->theyear,
$attendance->themonth, $attendance->theday);
$attendance->name=userdate($attendance->day, get_string("strftimedate"));
if ($attendance->notes) {
$attendance->name = $attendance->name . " - " . $attendance->notes;
}
*/
$curdate = make_timestamp($mod->startyear, $mod->startmonth, $mod->startday);
$stopdate = make_timestamp($mod->endyear, $mod->endmonth, $mod->endday);
$enddate = $curdate + $mod->numsections * 604800;
if ($curdate > $stopdate) {
error(get_string("endbeforestart", "attendance"));
}
if ($enddate < $curdate) {
error(get_string("startafterend", "attendance"));
}
if ($stopdate > $enddate) {
// if stop date is after end of course, just move it to end of course
$stopdate = $enddate;
}
while ($curdate <= $stopdate) {
$mod->day = $curdate;
$mod->name=userdate($mod->day, get_string("strftimedate"));
if (isset($mod->notes)) {$mod->name = $mod->name . " - " . $mod->notes;}
switch(userdate($curdate, "%u")) {
case 1: if (!empty($mod->mon)) {attendance_add_module($mod);}break;
case 2: if (!empty($mod->tue)) {attendance_add_module($mod);}break;
case 3: if (!empty($mod->wed)) {attendance_add_module($mod);}break;
case 4: if (!empty($mod->thu)) {attendance_add_module($mod);}break;
case 5: if (!empty($mod->fri)) {attendance_add_module($mod);}break;
case 6: if (!empty($mod->sat)) {attendance_add_module($mod);}break;
case 7: if (!empty($mod->sun)) {attendance_add_module($mod);}break;
} // switch
$curdate = $curdate + 86400; // add one day to the date
} // while for days
if (!empty($SESSION->returnpage)) {
$return = $SESSION->returnpage;
unset($SESSION->returnpage);
redirect($return);
} else {
redirect("index.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);
require_variable($id);
require_variable($section);
if (! $course = get_record("course", "id", $id)) {
error("This course doesn't exist");
}
if (! $module = get_record("modules", "name", "attendance")) {
error("This module type doesn't exist");
}
$form->section = $section; // The section number itself
$form->course = $course->id;
$form->module = $module->id;
$form->modulename = $module->name;
$form->instance = "";
$form->coursemodule = "";
$form->mode = "add";
$sectionname = get_string("name$course->format");
$fullmodulename = strtolower(get_string("modulename", $module->name));
if ($form->section) {
$heading->what = $fullmodulename;
$heading->to = "$sectionname $form->section";
$pageheading = get_string("addingmultiple", "attendance");
} else {
$pageheading = get_string("addingmultiple", "attendance");
}
if (!isteacheredit($course->id)) {
error("You can't modify this course!");
}
$streditinga = get_string("editinga", "moodle", $fullmodulename);
$strmodulenameplural = get_string("modulenameplural", $module->name);
if ($course->category) {
print_header("$course->shortname: $streditinga", "$course->fullname",
"<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> ->
<a href=\"$CFG->wwwroot/mod/$module->name/index.php?id=$course->id\">$strmodulenameplural</a> ->
$streditinga", "form.name", "", false);
} else {
print_header("$course->shortname: $streditinga", "$course->fullname",
"$streditinga", "form.name", "", false);
}
unset($SESSION->modform); // Clear any old ones that may be hanging around.
$icon = "<img align=middle height=16 width=16 src=\"$CFG->modpixpath/$module->name/icon.gif\" alt=\"\" />&nbsp;";
print_heading_with_help($pageheading, "mods", $module->name, $icon);
print_simple_box_start('center');
/// Print the main part of the page
// adaptation of mod code to view code needs this:
@include_once("$CFG->dirroot/mod/attendance/lib.php");
//require_once("lib.php")
// determine the end date for the course based on the number of sections and the start date
$course->enddate = $course->startdate + $course->numsections * 604800;
if (isset($CFG->attendance_dynsection) && ($CFG->attendance_dynsection == "1")) { $form->dynsection = 1; }
if (isset($CFG->attendance_autoattend) && ($CFG->attendance_autoattend == "1")) { $form->autoattend = 1; }
if (isset($CFG->attendance_grade) && ($CFG->attendance_grade == "1")) { $form->grade = 1; }
$form->maxgrade = isset($CFG->attendance_maxgrade)?$CFG->attendance_maxgrade:0;
$form->hours = isset($CFG->attendance_default_hours)?$CFG->attendance_default_hours:1;
?>
<form name="form" method="post" action="add.php">
<center>
<input type="submit" value="<?php print_string("savechanges") ?>" />
<input type="submit" name="cancel" value="<?php print_string("cancel") ?>" />
<table cellpadding=5>
<tr valign=top>
<td align=right><p><b><?php print_string("startmulti", "attendance") ?>:</b></p></td>
<td colspan="3"><?php print_date_selector("startday", "startmonth", "startyear",$course->startdate) ?></td>
</tr>
<tr valign=top>
<td align=right><p><b><?php print_string("endmulti", "attendance") ?>:</b></p></td>
<td colspan="3"><?php print_date_selector("endday", "endmonth", "endyear",$course->enddate) ?></td>
</tr>
<tr valign=top>
<td align=right><p><b><?php print_string("choosedays", "attendance") ?>:</b></p></td>
<td colspan="3">
<?php print_string("sunday","attendance"); echo ":"; ?>
<input type="checkbox" name="sun" />
<?php print_string("monday","attendance"); echo ":"; ?>
<input type="checkbox" name="mon" checked="checked" />
<?php print_string("tuesday","attendance"); echo ":"; ?>
<input type="checkbox" name="tue" checked="checked" />
<?php print_string("wednesday","attendance"); echo ":"; ?>
<input type="checkbox" name="wed" checked="checked" />
<?php print_string("thursday","attendance"); echo ":"; ?>
<input type="checkbox" name="thu" checked="checked" />
<?php print_string("friday","attendance"); echo ":"; ?>
<input type="checkbox" name="fri" checked="checked" />
<?php print_string("saturday","attendance"); echo ":"; ?>
<input type="checkbox" name="sat" />
<?php helpbutton("choosedays", get_string("choosedays","attendance"), "attendance");?>
</td>
</tr>
<tr valign=top>
<td align="right"><p><b><?php print_string("dynamicsectionmulti", "attendance") ?>:</b></p></td>
<td align="left">
<?php
$options = array();
$options[0] = get_string("no");
$options[1] = get_string("yes");
choose_from_menu($options, "dynsection", "", "");
helpbutton("dynsection", get_string("dynamicsectionmulti","attendance"), "attendance");
?>
<!-- <input type="checkbox" name="dynsection" <?php echo !empty($form->dynsection) ? 'checked' : '' ?> /> -->
</td>
</tr>
<tr valign=top>
<td align="right"><p><b><?php print_string("autoattendmulti", "attendance") ?>:</b></p></td>
<td align="left">
<?php
$options = array();
$options[0] = get_string("no");
$options[1] = get_string("yes");
choose_from_menu($options, "autoattend", "", "");
helpbutton("autoattendmulti", get_string("autoattend","attendance"), "attendance");
?>
<!-- <input type="checkbox" name="autoattend" <?php echo !empty($form->autoattend) ? '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("hoursineachclass", "attendance") ?>:</b></p></td>
<td colspan="3" align="left"><?php choose_from_menu($opt, "hours", $form->hours, "1","","1") ?>
<?php helpbutton("hours", get_string("hoursinclass","attendance"), "attendance"); ?>
</td>
</tr>
<tr valign=top>
<td align="right"><p><b><?php print_string("gradevaluemulti", "attendance") ?>:</b></p></td>
<td align="left">
<?php
$options = array();
$options[0] = get_string("no");
$options[1] = get_string("yes");
choose_from_menu($options, "grade", "", "");
helpbutton("grade", get_string("gradevalue","attendance"), "attendance");
?>
<!-- <input type="checkbox" name="grade" <?php echo !empty($form->grade) ? '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=0;$i<=100;$i++){ $opt2[$i] = $i; } ?>
<tr valign=top>
<td align=right><p><b><?php print_string("maxgradevalue", "attendance") ?>:</b></p></td>
<td colspan="3" align="left"><?php choose_from_menu($opt2, "maxgrade", $form->maxgrade, "0","","0");
helpbutton("maxgrade", get_string("maxgradevalue","attendance"), "attendance");
?></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) ?>" />
<input type="hidden" name=numsections value="<?php p($course->numsections) ?>" />
<br />
<input type="submit" value="<?php print_string("savechanges") ?>" />
<input type="submit" name="cancel" value="<?php print_string("cancel") ?>" />
</center>
</form>
<?php
print_simple_box_end();
/// Finish the page
print_footer($course);
}
?>
-140
View File
@@ -1,140 +0,0 @@
<?php //$Id$
//This php script contains all the stuff to backup/restore
//attendance mods
//This is the "graphical" structure of the attendance mod:
//
// attendance
// (CL,pk->id)
// |
// |
// |
// attendance_roll
// (UL,pk->id, fk->dayid)
//
// Meaning: pk->primary key field of the table
// fk->foreign key to link with parent
// nt->nested field (recursive data)
// CL->course level info
// UL->user level info
// files->table may have files)
//
//-----------------------------------------------------------
function attendance_backup_mods($bf,$preferences) {
global $CFG;
$status = true;
//Iterate over attendance table
$attendances = get_records ("attendance","course",$preferences->backup_course,"id");
if ($attendances) {
foreach ($attendances as $attendance) {
//Start mod
fwrite ($bf,start_tag("MOD",3,true));
//Print choice data
fwrite ($bf,full_tag("ID",4,false,$attendance->id));
fwrite ($bf,full_tag("MODTYPE",4,false,"attendance"));
fwrite ($bf,full_tag("NAME",4,false,$attendance->name));
fwrite ($bf,full_tag("DAY",4,false,$attendance->day));
fwrite ($bf,full_tag("HOURS",4,false,$attendance->hours));
fwrite ($bf,full_tag("ROLL",4,false,$attendance->roll));
fwrite ($bf,full_tag("NOTES",4,false,$attendance->notes));
fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$attendance->timemodified));
fwrite ($bf,full_tag("DYNSECTION",4,false,$attendance->dynsection));
fwrite ($bf,full_tag("EDITED",4,false,$attendance->edited));
fwrite ($bf,full_tag("AUTOATTEND",4,false,$attendance->autoattend));
//if we've selected to backup users info, then execute backup_attendance_roll
if ($preferences->mods["attendance"]->userinfo) {
$status = backup_attendance_roll($bf,$preferences,$attendance->id);
}
//End mod
$status =fwrite ($bf,end_tag("MOD",3,true));
}
}
return $status;
}
//Backup attendance_roll contents (executed from attendance_backup_mods)
function backup_attendance_roll ($bf,$preferences,$attendance) {
global $CFG;
$status = true;
$attendance_rolls = get_records("attendance_roll","dayid",$attendance,"id");
//If there is rolls
if ($attendance_rolls) {
//Write start tag
$status =fwrite ($bf,start_tag("ROLLS",4,true));
//Iterate over each roll
foreach ($attendance_rolls as $att_rol) {
//Start roll
$status =fwrite ($bf,start_tag("ROLL",5,true));
//Print roll contents
fwrite ($bf,full_tag("ID",6,false,$att_rol->id));
fwrite ($bf,full_tag("USERID",6,false,$att_rol->userid));
fwrite ($bf,full_tag("HOUR",6,false,$att_rol->hour));
fwrite ($bf,full_tag("STATUS",6,false,$att_rol->status));
fwrite ($bf,full_tag("NOTES",6,false,$att_rol->notes));
//End roll
$status =fwrite ($bf,end_tag("ROLL",5,true));
}
//Write end tag
$status =fwrite ($bf,end_tag("ROLLS",4,true));
}
return $status;
}
////Return an array of info (name,value)
function attendance_check_backup_mods($course,$user_data=false,$backup_unique_code) {
//First the course data
$info[0][0] = get_string("modulenameplural","attendance");
if ($ids = attendance_ids ($course)) {
$info[0][1] = count($ids);
} else {
$info[0][1] = 0;
}
//Now, if requested, the user_data
if ($user_data) {
$info[1][0] = get_string("entries");
if ($ids = attendance_roll_ids_by_course ($course)) {
$info[1][1] = count($ids);
} else {
$info[1][1] = 0;
}
}
return $info;
}
// INTERNAL FUNCTIONS. BASED IN THE MOD STRUCTURE
//Returns an array of attendances id
function attendance_ids ($course) {
global $CFG;
return get_records_sql ("SELECT a.id, a.course
FROM {$CFG->prefix}attendance a
WHERE a.course = '$course'");
}
//Returns an array of attendance_rolls id
function attendance_roll_ids_by_course ($course) {
global $CFG;
return get_records_sql ("SELECT r.id , r.dayid
FROM {$CFG->prefix}attendance_roll r,
{$CFG->prefix}attendance a
WHERE a.course = '$course' AND
r.dayid = a.id");
}
?>
-143
View File
@@ -1,143 +0,0 @@
<?php
if (!isset($CFG->attendance_dynsection)) {
$CFG->attendance_dynsection = '';
}
if (!isset($CFG->attendance_default_hours)) {
$CFG->attendance_default_hours = '';
}
if (!isset($CFG->attendance_tardies_per_absence)) {
$CFG->attendance_tardies_per_absence = '';
}
if (!isset($CFG->attendance_hours_in_full_report)) {
$CFG->attendance_hours_in_full_report = '';
}
if (!isset($CFG->attendance_default_student_status)) {
$CFG->attendance_default_student_status = '';
}
if (!isset($CFG->attendance_autoattend)) {
$CFG->attendance_autoattend = '';
}
if (!isset($CFG->attendance_grade)) {
$CFG->attendance_grade = '';
}
if (!isset($CFG->attendance_maxgrade)) {
$CFG->attendance_maxgrade = '';
}
?>
<form method="post" action="module.php" name="form">
<input type="hidden" name="sesskey" value="<?php echo $USER->sesskey ?>">
<table cellpadding=9 cellspacing=0 >
<tr valign=top>
<td align=right>attendance_dynsection:</td>
<td>
<?php $optds[0] = "No";$optds[1] = "Yes";
choose_from_menu($optds, "attendance_dynsection", $CFG->attendance_dynsection, ""); ?>
</td>
<td>
<?php p(get_string("defaultdynamicsection","attendance")) ?>
</td>
</tr>
<tr valign=top>
<td align=right>attendance_default_hours:</td>
<td>
<?php for ($i=1;$i<=24;$i++){ $opt[$i] = $i; }
choose_from_menu($opt, "attendance_default_hours", $CFG->attendance_default_hours, ""); ?>
</td>
<td>
<?php p(get_string("defaulthoursinclass","attendance")) ?>
</td>
</tr>
<tr valign=top>
<td align=right>attendance_tardies_per_absence:</td>
<td>
<?php for ($i=1;$i<=24;$i++){ $opt2[$i] = $i; }
choose_from_menu($opt2, "attendance_tardies_per_absence", $CFG->attendance_tardies_per_absence, "none","","0"); ?>
</td>
<td>
<?php p(get_string("tardiesperabsence","attendance")) ?>
</td>
</tr>
<tr valign=top>
<td align=right>attendance_hours_in_full_report:</td>
<td>
<?php for ($i=10;$i<=24;$i++){ $opt3[$i] = $i; }
choose_from_menu($opt3, "attendance_hours_in_full_report", $CFG->attendance_tardies_per_absence, ""); ?>
</td>
<td>
<?php p(get_string("hoursinfullreport","attendance")) ?>
</td>
</tr>
<tr valign=top>
<td align=right>attendance_default_student_status:</td>
<td>
<?php
$A = get_string("absentlong","attendance");
$T = get_string("tardylong","attendance");
$P = get_string("presentlong","attendance");
$r1c=$r2c=$r3c=" ";
if ($CFG->attendance_default_student_status == 1) {$r2c="checked";}
elseif ($CFG->attendance_default_student_status == 2) {$r3c="checked";}
else {$r1c="checked";}
$radio1="<input type=\"radio\" name=\"attendance_default_student_status\" value=\"0\" ".$r1c." />";
$radio2="<input type=\"radio\" name=\"attendance_default_student_status\" value=\"1\" ".$r2c." />";
$radio3="<input type=\"radio\" name=\"attendance_default_student_status\" value=\"2\" ".$r3c." />";
echo "<table><tr><td align=\"left\" nowrap class=\"generaltablecell\">".
$radio1.$P."</td>\n";
echo "<td align=\"left\" nowrap class=\"generaltablecell\">".
$radio2.$T."</td>\n";
echo "<td align=\"left\" nowrap class=\"generaltablecell\">".
$radio3.$A."</td></tr></table>\n";
?>
</td>
<td>
<?php p(get_string("defaultstudentstatus","attendance")) ?>
</td>
</tr>
<tr valign=top>
<td align=right>attendance_autoattend:</td>
<td>
<?php $optaa[0] = "No";$optaa[1] = "Yes";
choose_from_menu($optaa, "attendance_autoattend", $CFG->attendance_autoattend, ""); ?>
</td>
<td>
<?php p(get_string("defaultautoattend","attendance")) ?>
</td>
</tr>
<tr valign=top>
<td align=right>attendance_grade:</td>
<td>
<?php $optgr[0] = "No";$optgr[1] = "Yes";
choose_from_menu($optgr, "attendance_grade", $CFG->attendance_grade, ""); ?>
</td>
<td>
<?php p(get_string("defaultgrade","attendance")) ?>
</td>
</tr>
<tr valign=top>
<td align=right>attendance_maxgrade:</td>
<td>
<?php for ($i=0;$i<=100;$i++){ $opt4[$i] = $i; }
choose_from_menu($opt4, "attendance_maxgrade", $CFG->attendance_maxgrade, ""); ?>
</td>
<td>
<?php p(get_string("defaultmaxgrade","attendance")) ?>
</td>
</tr>
<tr>
<td colspan=3 align=center>
<input type="submit" value="<?php print_string("savechanges") ?>" /></td>
</tr>
</table>
</form>
-37
View File
@@ -1,37 +0,0 @@
<?php
function attendance_upgrade($oldversion) {
/// This function does anything necessary to upgrade
/// older versions to match current functionality
global $CFG;
if ($oldversion < 2003091802) {
execute_sql("ALTER TABLE `{$CFG->prefix}attendance` ADD `edited` TINYINT( 1 ) DEFAULT '0' NOT NULL;");
execute_sql("UPDATE `{$CFG->prefix}attendance` set `edited` = 1;");
}
if ($oldversion < 2003092500) {
execute_sql("ALTER TABLE `{$CFG->prefix}attendance` ADD `autoattend` TINYINT( 1 ) DEFAULT '0' NOT NULL;");
}
if ($oldversion < 2004050301) {
modify_database("", "INSERT INTO {$CFG->prefix}log_display VALUES ('attendance', 'view', 'attendance', 'name');");
modify_database("", "INSERT INTO {$CFG->prefix}log_display VALUES ('attendance', 'viewall', 'attendance', 'name');");
modify_database("", "INSERT INTO {$CFG->prefix}log_display VALUES ('attendance', 'viewweek', 'attendance', 'name');");
}
if ($oldversion < 2004111200) {
execute_sql("ALTER TABLE {$CFG->prefix}attendance DROP INDEX course;",false);
execute_sql("ALTER TABLE {$CFG->prefix}attendance_roll DROP INDEX dayid;",false);
execute_sql("ALTER TABLE {$CFG->prefix}attendance_roll DROP INDEX userid;",false);
modify_database('','ALTER TABLE prefix_attendance ADD INDEX course (course);');
modify_database('','ALTER TABLE prefix_attendance_roll ADD INDEX dayid (dayid);');
modify_database('','ALTER TABLE prefix_attendance_roll ADD INDEX userid (userid);');
}
return true;
}
?>
-39
View File
@@ -1,39 +0,0 @@
#
# Table structure for table `prefix_attendance`
#
CREATE TABLE prefix_attendance (
id int(10) unsigned NOT NULL auto_increment,
name varchar(255) NOT NULL default '',
course int(10) NOT NULL default '0',
day int(10) unsigned NOT NULL default '0',
hours tinyint(1) NOT NULL default '0',
roll tinyint(1) NOT NULL default '0',
notes varchar(64) NOT NULL default '',
timemodified int(10) unsigned NOT NULL default '0',
dynsection tinyint(1) NOT NULL default '0',
edited tinyint(1) NOT NULL default '0',
autoattend tinyint(1) NOT NULL default '0',
PRIMARY KEY (id),
KEY `course` (`course`)
) TYPE=MyISAM;
#
# Table structure for table `prefix_attendance_roll`
#
CREATE TABLE prefix_attendance_roll (
id int(11) NOT NULL auto_increment,
dayid int(10) unsigned NOT NULL default '0',
userid int(11) NOT NULL default '0',
hour tinyint(1) unsigned NOT NULL default '0',
status int(11) NOT NULL default '0',
notes varchar(64) NOT NULL default '',
PRIMARY KEY (id),
KEY `dayid` (`dayid`),
KEY `userid` (`userid`)
) TYPE=MyISAM;
INSERT INTO prefix_log_display VALUES ('attendance', 'view', 'attendance', 'name');
INSERT INTO prefix_log_display VALUES ('attendance', 'view', 'attendance', 'name');
INSERT INTO prefix_log_display VALUES ('attendance', 'viewall', 'attendance', 'name');
-22
View File
@@ -1,22 +0,0 @@
<?php
function attendance_upgrade($oldversion) {
/// This function does anything necessary to upgrade
/// older versions to match current functionality
global $CFG;
return true;
}
?>
-75
View File
@@ -1,75 +0,0 @@
rem
rem Table structure for table prefix_attendance
rem
drop TABLE prefix_attendance;
CREATE TABLE prefix_attendance (
id number(10) primary key,
name varchar2(255) default '' not null,
course number(10) default '0' not null,
day number(10) default '0' not null,
hours number(1) default '0' not null,
roll number(1) default '0' not null,
notes varchar2(64) default '' not null,
timemodified number(10) default '0' not null,
dynsection number(1) default '0' not null,
edited number(1) default '0' not null,
autoattend number(1) default '0' not null
);
drop sequence p_attendance_seq;
create sequence p_attendance_seq;
create or replace trigger p_attendance_trig
before insert on prefix_attendance
referencing new as new_row
for each row
begin
select p_attendance_seq.nextval into :new_row.id from dual;
end;
.
/
insert into prefix_attendance (name,course,day,hours,roll,notes,timemodified,dynsection,edited) values ('1',1,1,1,1,'1',1,1,1,1);
insert into prefix_attendance (name,course,day,hours,roll,notes,timemodified,dynsection,edited) values ('2',2,2,2,2,'2',2,2,2,2);
insert into prefix_attendance (name,course,day,hours,roll,notes,timemodified,dynsection,edited) values ('3',3,3,3,3,'3',3,3,3,3);
insert into prefix_attendance (name,course,day,hours,roll,notes,timemodified,dynsection,edited) values ('4',4,4,4,4,'4',4,4,4,4);
select * from prefix_attendance order by 1,2;
rem
rem Table structure for table prefix_attendance_roll
rem
drop TABLE prefix_attendance_roll;
CREATE TABLE prefix_attendance_roll (
id number(11) primary key,
dayid number(10) default '0' not null,
userid number(11) default '0' not null,
hour number(1) default '0' not null,
status number(11) default '0' not null,
notes varchar2(64) default '' not null
);
drop sequence p_attendance_roll_seq;
create sequence p_attendance_roll_seq;
create or replace trigger p_attendance_roll_trig
before insert on prefix_attendance_roll
referencing new as new_row
for each row
begin
select p_attendance_roll_seq.nextval into :new_row.id from dual;
end;
.
/
insert into prefix_attendance_roll (dayid,userid,hour,status,notes) values (1,1,1,1,'1');
insert into prefix_attendance_roll (dayid,userid,hour,status,notes) values (2,2,2,2,'2');
insert into prefix_attendance_roll (dayid,userid,hour,status,notes) values (3,3,3,3,'3');
insert into prefix_attendance_roll (dayid,userid,hour,status,notes) values (4,4,4,4,'4');
col format format 99
select * from prefix_attendance_roll order by 1,2;
-46
View File
@@ -1,46 +0,0 @@
<?php
function attendance_upgrade($oldversion) {
/// This function does anything necessary to upgrade
/// older versions to match current functionality
global $CFG;
//table_column($table, $oldfield, $field, $type="integer", $size="10",
// $signed="unsigned", $default="0", $null="not null", $after="")
if ($oldversion < 2003091802) {
table_column("attendance", "", "edited", "integer", 2, "unsigned", "0", "not null");
execute_sql("UPDATE {$CFG->prefix}attendance set edited = 1;");
}
if ($oldversion < 2003092500) {
table_column("attendance", "", "autoattend", "integer", 2, "unsigned", "0", "not null");
}
if ($oldversion < 2004050301) {
modify_database("", "INSERT INTO {$CFG->prefix}log_display VALUES ('attendance', 'view', 'attendance', 'name');");
modify_database("", "INSERT INTO {$CFG->prefix}log_display VALUES ('attendance', 'viewall', 'attendance', 'name');");
modify_database("", "INSERT INTO {$CFG->prefix}log_display VALUES ('attendance', 'viewweek', 'attendance', 'name');");
}
if ($oldversion < 2004111200) {
execute_sql("DROP INDEX {$CFG->prefix}attendance_course_idx;",false);
execute_sql("DROP INDEX {$CFG->prefix}attendance_roll_dayid_idx;",false);
execute_sql("DROP INDEX {$CFG->prefix}attendance_roll_userid_idx;",false);
modify_database('','CREATE INDEX prefix_attendance_course_idx ON prefix_attendance (course);');
modify_database('','CREATE INDEX prefix_attendance_roll_dayid_idx ON prefix_attendance_roll (dayid);');
modify_database('','CREATE INDEX prefix_attendance_roll_userid_idx ON prefix_attendance_roll (userid);');
}
return true;
}
?>
-42
View File
@@ -1,42 +0,0 @@
#
# Table structure for table `prefix_attendance`
#
CREATE TABLE prefix_attendance (
id SERIAL8,
name varchar(255) NOT NULL default '',
course int8 NOT NULL default '0',
day int8 NOT NULL default '0',
hours int2 NOT NULL default '0',
roll int2 NOT NULL default '0',
notes varchar(64) NOT NULL default '',
timemodified int8 NOT NULL default '0',
dynsection int2 NOT NULL default '0',
edited int2 NOT NULL default '0',
autoattend int2 NOT NULL default '0',
PRIMARY KEY(id)
);
CREATE INDEX prefix_attendance_course_idx ON prefix_attendance (course);
#
# Table structure for table `prefix_attendance_roll`
#
CREATE TABLE prefix_attendance_roll (
id SERIAL8,
dayid int4 NOT NULL default '0',
userid int8 NOT NULL default '0',
hour int2 NOT NULL default '0',
status int4 NOT NULL default '0',
notes varchar(64) NOT NULL default '',
PRIMARY KEY (id)
);
CREATE INDEX prefix_attendance_roll_dayid_idx ON prefix_attendance_roll (dayid);
CREATE INDEX prefix_attendance_roll_userid_idx ON prefix_attendance_roll (userid);
INSERT INTO prefix_log_display VALUES ('attendance', 'view', 'attendance', 'name');
INSERT INTO prefix_log_display VALUES ('attendance', 'view', 'attendance', 'name');
INSERT INTO prefix_log_display VALUES ('attendance', 'viewall', 'attendance', 'name');
-29
View File
@@ -1,29 +0,0 @@
<?php
include_once('tohtml.inc.php');
include_once('adodb.inc.php');
include_once('adodb-xmlschema.inc.php');
$database = "oci8po";
$db = ADONewConnection("$database");
$db->debug = true;
$server = "false";
$user = "scott";
$password = "tiger";
$db->Connect(false, $user, $password);
$rs = $db->Execute('select * from dept');
print "<pre>";
print_r($rs->GetRows());
print "</pre>";
rs2html($rs,'border=2 cellpadding=3',array('Deptno','DName','Loc'));
$dict = NewDataDictionary($db);
$rs = $db->Execute('drop table attendance');
$schema = new adoSchema($db);
$rs = $db->Execute('drop table attendance_roll');
$schema = new adoSchema($db);
$sql = $schema->ParseSchema("schema.xml");
$result = $schema->ExecuteSchema( $sql );
$sql = "insert into attendance(id,name,course,day,hours,roll,notes,timemodified,dynsection,edited,autoattend) values (2,'2',2,2,2,2,'2',2,2,2,2)";
$rs = $db->Execute($sql);
$rs = $db->Execute('select * from attendance');
rs2html($rs,'border=2 cellpadding=3',array('id','name','course','day','hours','roll','notes','timemodified','dynsection','edited','autoattend'));
?>
</body></html>
-95
View File
@@ -1,95 +0,0 @@
<?xml version="1.0"?>
<schema>
<table name="attendance">
<field name="id" type="I" size="10">
<KEY/>
<AUTOINCREMENT/>
</field>
<field name="name" type="C" size="255">
<NOTNULL/>
</field>
<field name="course" type="I" size="10">
<NOTNULL/>
</field>
<field name="day" type="I" size="10">
<NOTNULL/>
</field>
<field name="hours" type="I1" size="1">
<NOTNULL/>
</field>
<field name="roll" type="I1" size="1">
<NOTNULL/>
</field>
<field name="notes" type="C" size="64">
<NOTNULL/>
</field>
<field name="timemodified" type="I1" size="1">
<NOTNULL/>
</field>
<field name="dynsection" type="I1" size="1">
<NOTNULL/>
</field>
<field name="edited" type="I1" size="1">
<NOTNULL/>
</field>
<field name="autoattend" type="I1" size="1">
<NOTNULL/>
</field>
</table>
<table name="attendance_roll">
<field name="id" type="I" size="11">
<KEY/>
<AUTOINCREMENT/>
</field>
<field name="dayid" type="I" size="10">
<NOTNULL/>
</field>
<field name="userid" type="I" size="11">
<NOTNULL/>
</field>
<field name="hour" type="I1" size="1">
<NOTNULL/>
</field>
<field name="status" type="I" size="11">
<NOTNULL/>
</field>
<field name="notes" type="C" size="64">
<NOTNULL/>
</field>
</table>
<sql>
<descr>Insert 1 row for testing only...comment out later</descr>
<query platform="postgres|postgres7">
insert into attendance(id,name,course,day,hours,roll,notes,timemodified,dynsection,edited,autoattend) values (1,'1',1,1,1,1,'1',1,1,1,1)
</query>
<query platform="mysql">
insert into attendance(id,name,course,day,hours,roll,notes,timemodified,dynsection,edited,autoattend) values (1,'1',1,1,1,1,'1',1,1,1,1)
</query>
<query platform="oci8po">
insert into attendance(id,name,course,day,hours,roll,notes,timemodified,dynsection,edited,autoattend) values (1,'1',1,1,1,1,'1',1,1,1,1)
</query>
</sql>
</schema>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 125 B

-80
View File
@@ -1,80 +0,0 @@
<?php // $Id$
/// index.php for attendance module
/// This page lists all the instances of NEWMODULE in a particular course
/// Replace NEWMODULE with the name of your module
require_once("../../config.php");
require_once("lib.php");
require_variable($id); // course
if (! $course = get_record("course", "id", $id)) {
error("Course ID is incorrect");
}
require_course_login($course);
add_to_log($course->id, "attendance", "viewall", "index.php?id=$course->id", "");
/// Get all required strings
$strattendances = get_string("modulenameplural", "attendance");
$strattendance = get_string("modulename", "attendance");
/// Print the header
print_header_simple($strattendance, "", "$strattendances", "", "", true, "", navmenu($course));
/// Get all the appropriate data
if (! $attendances = get_all_instances_in_course("attendance", $course)) {
notice("There are no attendances", "../../course/view.php?id=$course->id");
die;
}
/// Print the list of instances (your module will probably extend this)
$timenow = time();
$strname = get_string("name");
$strweek = get_string("week");
$strtopic = get_string("topic");
if ($course->format == "weeks") {
$table->head = array ($strweek, $strname);
$table->align = array ("CENTER", "LEFT");
} else if ($course->format == "topics") {
$table->head = array ($strtopic, $strname);
$table->align = array ("CENTER", "LEFT", "LEFT", "LEFT");
} else {
$table->head = array ($strname);
$table->align = array ("LEFT", "LEFT", "LEFT");
}
if ($attendances) foreach ($attendances as $attendance) {
if (!$attendance->visible) {
//Show dimmed if the mod is hidden
$link = "<a class=\"dimmed\" href=\"view.php?id=$attendance->coursemodule\">$attendance->name</a>";
} else {
//Show normal if the mod is visible
$link = "<a href=\"view.php?id=$attendance->coursemodule\">$attendance->name</a>";
}
if ($course->format == "weeks" or $course->format == "topics") {
$table->data[] = array ($attendance->section, $link);
} else {
$table->data[] = array ($link);
}
}
echo "<br />";
print_table($table);
/// Finish the page
print_footer($course);
?>
-602
View File
@@ -1,602 +0,0 @@
<?php // $Id$
/// Library of functions and constants for attendance module
// error_reporting(E_ALL);
function attendance_add_module(&$mod) {
// global $mod;
require_once("../../course/lib.php");
if (! $mod->instance = attendance_add_instance($mod)) {
error("Could not add a new instance of $mod->modulename"); return 0;
}
// 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"); return 0;
}
if (! $sectionid = add_mod_to_section($mod) ) {
error("Could not add the new course module to that section"); return 0;
}
if (! set_field("course_modules", "section", $sectionid, "id", $mod->coursemodule)) {
error("Could not update the course module with the correct section"); return 0;
}
add_to_log($mod->course, "course", "add mod",
"../mod/$mod->modulename/view.php?id=$mod->coursemodule",
"$mod->modulename $mod->instance");
rebuild_course_cache($mod->course);
}
function attendance_add_instance($attendance) {
global $mod;
$attendance->timemodified = time();
$attendance->dynsection = !empty($attendance->dynsection) ? 1 : 0;
$attendance->autoattend = !empty($attendance->autoattend) ? 1 : 0;
$attendance->grade = !empty($attendance->grade) ? 1 : 0;
if (empty($attendance->day)) {
$attendance->day = make_timestamp($attendance->theyear,
$attendance->themonth, $attendance->theday);
}
$attendance->notes = $attendance->name;
$attendance->name=userdate($attendance->day, get_string("strftimedate"));
if ($attendance->notes) {
$attendance->name = $attendance->name . " - " . $attendance->notes;
}
$attendance->edited = 0;
if ($attendance->dynsection) {
if ($mod->course) {
if (! $course = get_record("course", "id", $mod->course)) {
error("Course is misconfigured");
}
}
if ($course->format =="weeks") {
// 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) {
global $mod;
$attendance->edited = 1;
$attendance->timemodified = time();
// $attendance->oldid=$attendance->id;
$attendance->id = $attendance->instance;
$attendance->dynsection = !empty($attendance->dynsection) ? 1 : 0;
$attendance->autoattend = !empty($attendance->autoattend) ? 1 : 0;
$attendance->grade = !empty($attendance->grade) ? 1 : 0;
$attendance->day = make_timestamp($attendance->theyear,
$attendance->themonth, $attendance->theday);
$attendance->notes = $attendance->name;
$attendance->name=userdate($attendance->day, get_string("strftimedate"));
if ($attendance->notes) {
$attendance->name = $attendance->name . " - " . $attendance->notes;
}
if ($attendance->dynsection) {
//get info about the course
if ($attendance->course) {
if (! $course = get_record("course", "id", $attendance->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 = 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;
if ($data) 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) {
if (! $attendance = get_record("attendance", "id", "$id")) {
return false;
}
$result = true;
/// delete all the rolls for the day
delete_records("attendance_roll", "dayid", "$attendance->id");
if (! delete_records("attendance", "id", "$attendance->id")) {
$result = false;
}
return $result;
}
function attendance_user_outline($course, $user, $mod, $attendance) {
/// Return a small object with summary information about what a
/// user has done with a given particular instance of this module
/// Used for user activity reports.
/// $return->time = the time they did it
/// $return->info = a short text description
/// for attendance, this would be a list present and tardy for every hour of the day
$tardies=count_records("attendance_roll", "dayid", $attendance->id, "userid", $user->id, "status", 1);
$absences=count_records("attendance_roll", "dayid", $attendance->id, "userid", $user->id, "status", 2);
// build longer string for tardies
if ($tardies > 0) {
$tardyrecs=attendance_get_records("attendance_roll", "dayid", $attendance->id, "userid", $user->id, "status", 1, "hour ASC");
if ($tardies == 1) {
$tardystring = "Tardy in hour " . $tardyrecs[0]->hour . ". ";
} elseif ($tardies == $attendance->hours) {
$tardystring = "Tardy in all hours. (" . $attendance->hours . ") ";
} else {
// build array of all tardies
$tarr = array();
if ($tardyrecs) foreach ($tardyrecs as $tardyrec) {
array_push($tarr, $tardyrec->hour);
$tardystring = $tardystring . ", " . $tardyrec->hour;
}
$end=array_pop($tarr);
$tardystring = "Tardy in hours " . implode(", ", $tarr) . " and ". $end . ". ";
}
} else { $tardystring = "";}
// build longer string for absences
if ($absences > 0) {
$absrecs=attendance_get_records("attendance_roll", "dayid", $attendance->id, "userid", $user->id, "status", 2, "hour ASC");
if ($absences == 1) {
$absstring = "Absent in hour " . $absrecs[0]->hour . ".";
} elseif ($absences == $attendance->hours) {
$absstring = "Absent in all hours. (" . $attendance->hours . ")";
} else {
// build array of all absences
$aarr = array();
if ($absrecs) foreach ($absrecs as $absrec) {
array_push($aarr, $absrec->hour);
}
$end=array_pop($aarr);
$absstring = "Absent in hours " . implode(", ", $aarr) . " and ". $end . ".";
}
} else { $absstring = "";}
$return->info=$tardystring . $absstring;
if ($return->info == "") $return->info = "No Tardies or Absences";
return $return;
}
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();
if ($attrecs) { foreach ($attrecs as $attrec) { $grid[$attrec->hour]=$attrec->status; } }
echo "<table><tr><th>Hour:</th>\n";
// echo out the table header
for($j=1;$j<=$attendance->hours;$j++) {
echo "<th valign=\"top\" align=\"center\" nowrap class=\"generaltableheader\">".$j."</th>\n";
}
echo "</tr><tr><th>Status:</th>";
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=$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";
return true;
}
function attendance_cron () {
/// Function to be run periodically according to the moodle cron
/// This function searches for things that need to be done, such
/// as sending out mail, toggling flags etc ...
global $CFG;
echo "Attendance: Performing automatic attendance logging\n";
// look for all attendance instances set to autoattend
if (!$attendances = get_records("attendance", "autoattend", 1, "course ASC")) {
return true;
}
$td = attendance_find_today(time());
$tm = attendance_find_tomorrow(time());
if ($attendances) foreach($attendances as $attendance) {
if (($attendance->day >=$td ) && ($attendance->day < $tm)) {
echo "Attendance: Taking attendance for $attendance->name\n";
if(!isset($courses[$attendance->course]->students)) {
$courses[$attendance->course]->students =
attendance_get_course_students($attendance->course, "u.lastname ASC");
}
if ($courses[$attendance->course]->students) {
foreach ($courses[$attendance->course]->students as $student) {
// first, clear out the records that may be there already
delete_records("attendance_roll",
"dayid",$attendance->id,
"userid",$student->id);
$wc = "userid = " . $student->id . " AND course = " . $attendance->course .
" AND time >= " . $td . " AND time < " . $tm;
$count = get_record_select("log",$wc,"COUNT(*) as c");
if ($count->c == "0") { // then the student hasn't done anything today, so mark him absent
$attrec->dayid = $attendance->id;
$attrec->userid = $student->id;
$attrec->status = 2; // status 2 is absent
// mark ALL hours as absent for first version
for ($i=1;$i<=$attendance->hours;$i++) {
$attrec->hour = $i;
insert_record("attendance_roll",$attrec, false);
} // for loop to mark all hours absent
} // if student has no activity
} // foreach student in the list
} // if students exist
} // if the attendance roll is for today
} // for each attendance in the system
return true;
} // function cron
function attendance_grades($attendanceid) {
/// Must return an array of grades for a given instance of this module,
/// indexed by user. It also returns a maximum allowed grade.
$attendance = get_record("attendance", "id", $attendanceid);
if ($attendance->grade == "1") {
$students = get_course_students($attendance->course);
if ($students) {
foreach ($students as $student) {
$rolls = attendance_get_records("attendance_roll",
"dayid",$attendance->id,
"userid",$student->id);
$abs=$tar=0;
if ($rolls) {
foreach ($rolls as $roll) {
if ($roll->status == 1) {$tar++;}
elseif ($roll->status == 2) {$abs++;}
} // if rolls
$total = $attendance->hours - attendance_tally_overall_absences_decimal($abs, $tar);
$percent = ($total != 0)?$total/$attendance->hours:0;
$return->grades[$student->id] = ($percent == 0)?0.0:$attendance->maxgrade * $percent;
} else { $return->grades[$student->id] = $attendance->maxgrade; }
} // foreach student
} // if students
$return->maxgrade = $attendance->maxgrade;
} else { // if attendance->grade == "1"
$return = NULL;
}// else for if attendance->grade == "1"
return $return;
}
/**
* Returns user records for all users who have DATA in a given attendance instance
*
* This function is present only for the backup routines. It won't return meaningful data
* for an attendance roll because it only returns records for users who have been counted as
* tardy or absent in the rolls for a single attendance instance, since these are the only
* records I store in the database - for brevity's sake of course.
*
* @param int $attendanceid the id of the attendance record we're looging for student data from
* @return (object)recordset associative array of records containing the student records we wanted
*/
function attendance_get_participants($attendanceid) {
//Returns the users with data in one attendance
//(users with records in attendance_roll, students)
global $CFG;
//Get students
$students = get_records_sql("SELECT DISTINCT u.id, u.id
FROM {$CFG->prefix}user u,
{$CFG->prefix}attendance_roll a
WHERE a.dayid = '$attendanceid' and
u.id = a.userid");
//Return students array (it contains an array of unique users)
return ($students);
}
//////////////////////////////////////////////////////////////////////////////////////
/// Any other attendance functions go here. Each of them must have a name that
/// starts with attendance_
/**
* get a list of all students enrolled in a given course - modified version
*
* THIS IS JUST THE GET_COURSE_STUDENTS FUNCTION WITH THE INCLUSION OF THE
* STUDENT ID INTO THE RECORDSET
* if courseid = 0 then return ALL students in all courses
*
* @param int $courseid the id of the course
* @param string $sort a field name and ASC or DESC for a SQL 'ORDER BY' clause (optional)
* @return array(recorset) a list of all students in the specified course
Returns
*/
function attendance_get_course_students($courseid, $sort="u.lastaccess DESC") {
global $CFG;
// make sure it works on the site course
$select = "s.course = '$courseid' AND";
if ($courseid == SITEID) {
$select = '';
}
return get_records_sql("SELECT u.id, u.username, u.firstname, u.lastname, u.maildisplay, u.mailformat,
u.email, u.city, u.country, u.lastaccess, u.lastlogin, u.picture, u.idnumber
FROM {$CFG->prefix}user u,
{$CFG->prefix}user_students s
WHERE $select s.userid = u.id AND u.deleted = '0'
ORDER BY $sort");
}
/**
* Find total absences based on number of tardies per absence
*
* Given a number of tardies and absences, determine the total
* number of equivalent absences it adds up to.
*
* @param int $absences the total number of absences for a span of time
* @param int $tardies the total number of tardies for a span of time
* @return float the number of absences it adds up to - may be a decimal!
*/
function attendance_tally_overall_absences_decimal($absences, $tardies) {
global $CFG;
if (isset($CFG->attendance_tardies_per_absence) && ($CFG->attendance_tardies_per_absence>0)) {
return $absences + ($tardies/$CFG->attendance_tardies_per_absence);
} else { return $absences; }
}
/**
* Find total absences based on number of tardies per absence and put it in a string
*
* Given a number of tardies and absences, determine the total
* number of equivalent absences it adds up to and express it as a string with
* a possible fractional remainder
*
* @param int $absences the total number of absences for a span of time
* @param int $tardies the total number of tardies for a span of time
* @return string the number of absences it adds up to - may have a fractional component!
*/
function attendance_tally_overall_absences_fraction($absences, $tardies) {
global $CFG;
if (isset($CFG->attendance_tardies_per_absence) && ($CFG->attendance_tardies_per_absence>0)) {
$whole = floor($tardies/$CFG->attendance_tardies_per_absence);
$fractional=$tardies-($whole * $CFG->attendance_tardies_per_absence);
if ($absences + $whole > 0) {
return ($absences + $whole) . (($fractional > 0) ? " ". $fractional. "/". $CFG->attendance_tardies_per_absence : "");
} else {
return (($fractional > 0) ? $fractional. "/". $CFG->attendance_tardies_per_absence : "0");
}
} else {
return $absences."";
}
}
/**
* get a list of records from a table with multiple criteria
*
* This one is different from the datalib.php one (called get_records) in the sense that it
* allows for multiple criteria to be easily supplied as parameters, but doesn't
* give the ability to specify sort, fields, or limits
*
*/
function attendance_get_records($table, $field1="", $value1="", $field2="", $value2="", $field3="", $value3="", $sort="", $fields="*", $limitfrom="", $limitnum="") {
global $CFG;
if ($field1) {
$select = "WHERE $field1 = '$value1'";
if ($field2) {
$select .= " AND $field2 = '$value2'";
if ($field3) {
$select .= " AND $field3 = '$value3'";
}
}
} else {
$select = "";
}
if ($limitfrom !== "") {
switch ($CFG->dbtype) {
case "mysql":
$limit = "LIMIT $limitfrom,$limitnum";
break;
case "postgres7":
$limit = "LIMIT $limitnum OFFSET $limitfrom";
break;
default:
$limit = "LIMIT $limitnum,$limitfrom";
}
} else {
$limit = "";
}
if ($sort != "") {
$sort = "ORDER BY $sort";
}
return get_records_sql("SELECT $fields FROM $CFG->prefix$table $select $sort $limit");
}
/**
* Return all attendance records that are in the same section as the instance specified
*
* This function uses course_modules, modules, and attendance tables together to determine
* first what section the specified attendance instance in the course is in, then all the
* attendance records that are in the same section, regardless of the format of the course
*
* @param int $instance id of the attendance instance in course_modules
* @param int $courseid the id of the course for which we're getting records
* @return (object)recordset associative array of records containing the attendance records we wanted
*/
function get_attendance_for_section($instance, $courseid) {
global $CFG;
// first, get the section for the instance specified
$sql = "SELECT cm.section
FROM {$CFG->prefix}course_modules cm,
{$CFG->prefix}modules md,
{$CFG->prefix}attendance a
WHERE cm.course = '$courseid' AND
cm.deleted = '0' AND
cm.instance = a.id AND
md.name = 'attendance' AND
md.id = cm.module AND
a.id = '$instance'";
$sectarray = get_record_sql($sql);
// echo "<pre>$sql \n</pre>";
$section = $sectarray->section;
/*
select cm.section from
mdl_course_modules cm, mdl_modules md, mdl_attendance m
where cm.course = '7' AND cm.deleted = '0' AND cm.instance = m.id
AND md.name = 'attendance' AND md.id = cm.module AND m.id = '119';
*/
// then get all the attendance instances in that section
$sql = "SELECT a.*
FROM {$CFG->prefix}course_modules cm,
{$CFG->prefix}modules md,
{$CFG->prefix}attendance a
WHERE cm.course = '$courseid' AND
cm.deleted = '0' AND
cm.section = '$section' AND
md.name = 'attendance' AND
md.id = cm.module AND
a.id = cm.instance order by a.day ASC";
// echo "<pre>$sql \n</pre>";
return get_records_sql($sql);
/*
select m.* from mdl_course_modules cm, mdl_modules md, mdl_attendance m
where cm.course = '7' AND cm.deleted = '0' AND cm.section = '85'
AND md.name = 'attendance' AND md.id = cm.module AND m.id = cm.instance;
*/
}
/**
* Return all attendance records that are in the same 7 day span as the instance specified
*
* This function uses the course and attendance tables together to find all the attendance
* records that are for days within the same week span as the instance specified. The week is
* determined based NOT on calendar week, but instead on the week span as it occurs in a
* weekly formatted course - I find this by starting with the startdate of the course and
* then skipping ahead by weeks til I find the range that fits the instance, then I use that
* range as min and max to query the attendance table for all the other records. Note that this
* function will work with non-weekly formatted courses, though the results won't easily
* correlate with the course view. But it will work regardless.
*
* @param int $id the id of the attendance record we're using as a basis for the query
* @param int $courseid the id of the course for which we're getting records
* @return (object)recordset associative array of records containing the attendance records we wanted
*/
function get_attendance_for_week($id, $courseid) {
global $CFG;
if (! $attendance = get_record("attendance", "id", $id)) {
error("Course module is incorrect");
}
if (! $course = get_record("course", "id", $courseid)) {
error("Course module is incorrect");
}
// the offset is for weeks that don't start on Monday
$day = $attendance->day;
// determine the week range for the select, based on the day
for ($maxday=$course->startdate;$day>$maxday;$maxday=$maxday+604800)
{;}$minday = $maxday-608400;
$sql = "SELECT * FROM {$CFG->prefix}attendance
WHERE course = '$courseid' AND day<$maxday AND day>=$minday order by day ASC;";
// echo "<pre>$sql \n</pre>";
return get_records_sql($sql);
}
/**
* Finds the beginning of the day for the date specified
*
* This function returns the timestamp for midnight of the day specified in the timestamp
*
* @param timestamp $d The time to find the beginning of the day for
* @return timestamp midnight for that day
*/
function attendance_find_today($d) {
// $da = getdate($d);
$damon = gmdate("m",$d);
$daday = gmdate("d",$d);
$dayear = gmdate("Y",$d);
// now return midnight of that day
// return mktime(0,0,0,$da["mon"], $da["mday"], $da["year"]);
return gmmktime(0,0,0,$damon, $daday, $dayear);
}
/**
* Finds the beginning of the day following the date specified
*
* This function returns the timestamp for midnight of the day after the timestamp specified
*
* @param timestamp $d The time to find the next day of
* @return timestamp midnight of the next day
*/
function attendance_find_tomorrow($d) {
// add 24 hours to the current time - to solve end of month date issues
return attendance_find_today($d+86400);
}
?>
-220
View File
@@ -1,220 +0,0 @@
<!-- This page defines the form to create or edit an instance of the attendance module -->
<!-- It is used from /course/mod.php. The whole instance is available as $form. -->
<!-- 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");
$nohtmleditorneeded = true;
//require_once("lib.php")
if (empty($form->dynsection)) {
$form->dynsection = 0;
}
if (empty($form->autoattend)) {
$form->autoattend = 0;
}
if (empty($form->grade)) {
$form->grade = 0;
}
if (empty($form->maxgrade)) {
$form->maxgrade = 0;
}
// error_reporting(E_ALL);
// if we're adding a new instance
if (empty($form->id)) {
if (isset($CFG->attendance_dynsection) && ($CFG->attendance_dynsection == "1")) { $form->dynsection = 1; }
if (isset($CFG->attendance_autoattend) && ($CFG->attendance_autoattend == "1")) { $form->autoattend = 1; }
if (isset($CFG->attendance_grade) && ($CFG->attendance_grade == "1")) { $form->grade = 1; }
$form->maxgrade = isset($CFG->attendance_maxgrade)?$CFG->attendance_maxgrade:0;
$form->hours = isset($CFG->attendance_default_hours)?$CFG->attendance_default_hours:1;
$form->day = time();
$form->notes = "";
}
?>
<form name="form" method="post" action="mod.php">
<center>
<table cellpadding="5">
<!-- <?php $options[0] = get_string("no"); $options[1] = get_string("yes"); ?> -->
<!-- <tr valign=top> -->
<!-- <td align=right><b><?php print_string("takeroll", "attendance") ?>:</b></td> -->
<!-- <td align=left><?php choose_from_menu($options, "roll", $form->roll, "") ?></td> -->
<!-- </tr> -->
<tr valign="top">
<td align="right"><b><?php print_string("name") ?>:</b></td>
<td colspan="3">
<input type="text" name="name" size="60" value="<?php p($form->notes)?>" alt="<?php print_string("name") ?>" />
</td>
</tr>
<tr valign="top">
<td align="right"><b><?php print_string("dayofroll", "attendance") ?>:</b></td>
<td colspan="3"><?php print_date_selector("theday", "themonth", "theyear", $form->day) ?></td>
</tr>
<tr valign="top">
<td align="right"><b><?php print_string("dynamicsection", "attendance") ?>:</b></td>
<td align="left">
<?php
$options = array();
$options[0] = get_string("no");
$options[1] = get_string("yes");
choose_from_menu($options, "dynsection", "$form->dynsection", "");
helpbutton("dynsection", get_string("dynamicsection","attendance"), "attendance");
?>
<!-- <input type="checkbox" name="dynsection" <?php echo !empty($form->dynsection) ? 'checked="checked"' : '' ?> /> -->
</td>
</tr>
<tr valign="top">
<td align="right"><b><?php print_string("autoattend", "attendance") ?>:</b></td>
<td align="left">
<?php
$options = array();
$options[0] = get_string("no");
$options[1] = get_string("yes");
choose_from_menu($options, "autoattend", "$form->autoattend", "");
helpbutton("autoattend", get_string("autoattend","attendance"), "attendance");
?>
<!-- <input type="checkbox" name="autoattend" <?php echo !empty($form->autoattend) ? 'checked="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"><b><?php print_string("hoursinclass", "attendance") ?>:</b></td>
<td colspan="3" align="left"><?php choose_from_menu($opt, "hours", $form->hours, "1","","1") ?>
<?php helpbutton("hours", get_string("hoursinclass","attendance"), "hours"); ?>
</td>
</tr>
<tr valign="top">
<td align="right"><b><?php print_string("gradevalue", "attendance") ?>:</b></td>
<td align="left">
<?php
$options = array();
$options[0] = get_string("no");
$options[1] = get_string("yes");
choose_from_menu($options, "grade", "$form->grade", "");
helpbutton("grade", get_string("gradevalue","attendance"), "attendance");
?>
<!-- <input type="checkbox" name="grade" <?php echo !empty($form->grade) ? 'checked="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=0;$i<=100;$i++){ $opt2[$i] = $i; } ?>
<tr valign="top">
<td align="right"><b><?php print_string("maxgradevalue", "attendance") ?>:</b></td>
<td colspan="3" align="left"><?php choose_from_menu($opt2, "maxgrade", $form->maxgrade, "0","","0");
helpbutton("maxgrade", get_string("maxgradevalue","attendance"), "attendance");
?></td>
</tr>
<?php print_visible_setting($form); ?>
</table>
<?php // if we're modifying an existing instance of attendance instead
// of creating a new one
if (isset($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);
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,
// lastaccess,lastlogin,picture (picture is null, 0, or 1), idnumber
// build the table for attendance roll
// this is the wrapper table
echo "<table align=\"center\" width=\"80\" class=\"generalbox\"".
"border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>".
"<td bgcolor=\"#ffffff\" class=\"generalboxcontent\">";
// this is the main table
echo "<table width=\"100%\" border=\"0\" valign=\"top\" align=\"center\" ".
"cellpadding=\"5\" cellspacing=\"1\" class=\"generaltable\">";
if ($form->hours >1) {
echo "<tr><th valign=\"top\" align=\"right\" colspan=\"3\" nowrap class=\"generaltableheader\">".
"Hours:</th>\n";
for($i=1;$i<=$form->hours;$i++) {
echo "<th valign=\"top\" align=\"center\" colspan=\"3\" nowrap class=\"generaltableheader\">".
"$i</th>\n";
}
echo "</tr>\n";
} // if more than one hour for each day
echo "<tr><th valign=\"top\" align=\"left\" nowrap class=\"generaltableheader\">Last Name</th>\n";
echo "<th valign=\"top\" align=\"left\" nowrap class=\"generaltableheader\">First Name</th>\n";
echo "<th valign=\"top\" align=\"left\" nowrap class=\"generaltableheader\">ID</th>\n";
$P=get_string("presentshort","attendance");
$T=get_string("tardyshort","attendance");
$A=get_string("absentshort","attendance");
// generate the headers for the attendance hours
for($i=1;$i<=$form->hours;$i++) {
echo "<th valign=\"top\" align=\"center\" nowrap class=\"generaltableheader\">".$P."</th>\n";
echo "<th valign=\"top\" align=\"center\" nowrap class=\"generaltableheader\">".$T."</th>\n";
echo "<th valign=\"top\" align=\"center\" nowrap class=\"generaltableheader\">".$A."</th>\n";
}
echo "</tr>\n";
$table->head = array("Last Name","First Name","ID",
get_string("presentlong","attendance"),
get_string("tardylong","attendance"),
get_string("absentlong","attendance"));
$table->align = array("left", "left", "left", "center","center","center");
$table->wrap = array("nowrap", "nowrap", "nowrap", "nowrap", "nowrap", "nowrap");
$table->width = "80";
$students = attendance_get_course_students($form->course, "u.lastname ASC");
$i=0;
if ($students) 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";
echo "<td align=\"left\" nowrap class=\"generaltablecell\" style=\"border-top: 1px solid;\">".$student->idnumber."</td>\n";
for($j=1;$j<=$form->hours;$j++) {
// set the attendance defaults for each student
$r1c=$r2c=$r3c=" ";
$rollstatus = (($form->edited==0)?$CFG->attendance_default_student_status:
((isset($sroll[$student->id][$j]->status)?$sroll[$student->id][$j]->status:0)));
if ($rollstatus==1) {$r2c="checked=\"checked\"";}
elseif ($rollstatus==2) {$r3c="checked=\"checked\"";}
else {$r1c="checked=\"checked\"";}
$radio1="<input type=\"radio\" name=\"student_".$student->id."_".$j."\" value=\"0\" ".$r1c." />";
$radio2="<input type=\"radio\" name=\"student_".$student->id."_".$j."\" value=\"1\" ".$r2c." />";
$radio3="<input type=\"radio\" name=\"student_".$student->id."_".$j."\" value=\"2\" ".$r3c." />";
echo "<td align=\"left\" nowrap class=\"generaltablecell\" style=\"border-left: 1px dotted; border-top: 1px solid;\">".$radio1."</td>\n";
echo "<td align=\"left\" nowrap class=\"generaltablecell\" style=\"border-top: 1px solid;\">".$radio2."</td>\n";
echo "<td align=\"left\" nowrap class=\"generaltablecell\" style=\"border-top: 1px solid;\">".$radio3."</td>\n";
} // for loop
echo "</tr>\n";
// $radio1="<input type=\"radio\" name=\"student_".$student->id."\" value=\"0\" checked=\"checked\" />";
// $radio2="<input type=\"radio\" name=\"student_".$student->id."\" value=\"1\" />";
// $radio3="<input type=\"radio\" name=\"student_".$student->id."\" value=\"2\" />";
// $table->data[$i]=array($student->lastname, $student->firstname,
// $student->idnumber, $radio1,$radio2,$radio3);
// $i++;
}
// doing the table manually now
// print_table($table);
// ending for both the tables
echo "</table></td></tr></table>\n";
} // if ($form->id)
?>
<!-- These hidden variables are always the same -->
<input type="hidden" name="course" value="<?php p($form->course) ?>" />
<input type="hidden" name="sesskey" value="<?php p($form->sesskey) ?>" />
<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 />
<?php
echo "<a href=\"../mod/attendance/add.php?id=".$form->course . "&amp;section=".$form->section ."\">" . get_string("addmultiple","attendance") . "</a><br /><br />";
?>
<input type="submit" value="<?php print_string("savechanges") ?>" />
<input type="submit" name="cancel" value="<?php print_string("cancel") ?>" />
</center>
</form>
-137
View File
@@ -1,137 +0,0 @@
<?php //$Id$
//This php script contains all the stuff to backup/restore
//attendance mods
//This is the "graphical" structure of the attendance mod:
//
// attendance
// (CL,pk->id)
// |
// |
// |
// attendance_roll
// (UL,pk->id, fk->dayid)
//
// Meaning: pk->primary key field of the table
// fk->foreign key to link with parent
// nt->nested field (recursive data)
// CL->course level info
// UL->user level info
// files->table may have files)
//
//-----------------------------------------------------------
//This function executes all the restore procedure about this mod
function attendance_restore_mods($mod,$restore) {
global $CFG;
$status = true;
//Get record from backup_ids
$data = backup_getid($restore->backup_unique_code,$mod->modtype,$mod->id);
if ($data) {
//Now get completed xmlized object
$info = $data->info;
//traverse_xmlize($info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
//Now, build the ATTENDANCE record structure
$attendance->course = $restore->course_id;
$attendance->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
$attendance->day = backup_todb($info['MOD']['#']['DAY']['0']['#']);
$attendance->hours = backup_todb($info['MOD']['#']['HOURS']['0']['#']);
$attendance->roll = backup_todb($info['MOD']['#']['ROLL']['0']['#']);
$attendance->notes = backup_todb($info['MOD']['#']['NOTES']['0']['#']);
$attendance->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
$attendance->dynsection = backup_todb($info['MOD']['#']['DYNSECTION']['0']['#']);
$attendance->edited = backup_todb($info['MOD']['#']['EDITED']['0']['#']);
$attendance->autoattend = backup_todb($info['MOD']['#']['AUTOATTEND']['0']['#']);
//The structure is equal to the db, so insert the attendance
$newid = insert_record ("attendance",$attendance);
//Do some output
echo "<li>".get_string("modulename","attendance")." \"".$attendance->name."\"</li>";
backup_flush(300);
if ($newid) {
//We have the newid, update backup_ids
backup_putid($restore->backup_unique_code,$mod->modtype,
$mod->id, $newid);
//Now check if want to restore user data and do it.
if ($restore->mods['attendance']->userinfo) {
//Restore attendance_roll
$status = attendance_roll_restore_mods ($newid,$info,$restore);
}
} else {
$status = false;
}
} else {
$status = false;
}
return $status;
}
//This function restores the attendance_roll
function attendance_roll_restore_mods($attendance_id,$info,$restore) {
global $CFG;
$status = true;
//Get the rolls array
$rolls = $info['MOD']['#']['ROLLS']['0']['#']['ROLL'];
//Iterate over rolls
for($i = 0; $i < sizeof($rolls); $i++) {
$rol_info = $rolls[$i];
//traverse_xmlize($rol_info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
//We'll need this later!!
$oldid = backup_todb($sub_info['#']['ID']['0']['#']);
$olduserid = backup_todb($sub_info['#']['USERID']['0']['#']);
//Now, build the ATTENDANCE_ROLL record structure
$roll->dayid = $attendance_id;
$roll->userid = backup_todb($rol_info['#']['USERID']['0']['#']);
$roll->hour = backup_todb($rol_info['#']['HOUR']['0']['#']);
$roll->status = backup_todb($rol_info['#']['STATUS']['0']['#']);
$roll->notes = backup_todb($rol_info['#']['NOTES']['0']['#']);
//We have to recode the userid field
$user = backup_getid($restore->backup_unique_code,"user",$roll->userid);
if ($user) {
$roll->userid = $user->new_id;
}
//The structure is equal to the db, so insert the attendance_roll
$newid = insert_record ("attendance_roll",$roll);
//Do some output
if (($i+1) % 50 == 0) {
echo ".";
if (($i+1) % 1000 == 0) {
echo "<br />";
}
backup_flush(300);
}
if ($newid) {
//We have the newid, update backup_ids
backup_putid($restore->backup_unique_code,"attendance_roll",$oldid,
$newid);
} else {
$status = false;
}
}
return $status;
}
?>
-233
View File
@@ -1,233 +0,0 @@
<!-- This page defines the form to create or edit an instance of the attendance module -->
<!-- It is used from /course/mod.php. The whole instance is available as $form. -->
<!-- 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 require_once("../../config.php");
require_once("lib.php" );
@include_once("$CFG->dirroot/course/lib.php");
//require_once("lib.php")
// this is code from course/mod.php
if (! $cm = get_record("course_modules", "id", $_GET['update'])) {
error("This course module doesn't exist");
}
if (! $course = get_record("course", "id", $cm->course)) {
error("This course doesn't exist");
}
if (!isteacher($course->id)) {
error("You can't modify this record!");
}
if (! $module = get_record("modules", "id", $cm->module)) {
error("This module doesn't exist");
}
if (! $form = get_record($module->name, "id", $cm->instance)) {
error("The required instance of this module doesn't exist");
}
if (! $cw = get_record("course_sections", "id", $cm->section)) {
error("This course section doesn't exist");
}
if (isset($return)) {
$SESSION->returnpage = "$CFG->wwwroot/mod/$module->name/view.php?id=$cm->id";
}
$form->coursemodule = $cm->id;
$form->section = $cm->section; // The section ID
$form->course = $course->id;
$form->module = $module->id;
$form->modulename = $module->name;
$form->instance = $cm->instance;
$form->mode = "update";
$sectionname = get_string("name$course->format");
$fullmodulename = strtolower(get_string("modulename", $module->name));
if ($form->section) {
$heading->what = $fullmodulename;
$heading->in = "$sectionname $cw->section";
$pageheading = get_string("updatingain", "moodle", $heading);
} else {
$pageheading = get_string("updatinga", "moodle", $fullmodulename);
}
$streditinga = get_string("editinga", "moodle", $fullmodulename);
$strmodulenameplural = get_string("modulenameplural", $module->name);
if ($module->name == "label") {
$focuscursor = "";
} else {
$focuscursor = "form.name";
}
if ($course->category) {
print_header("$course->shortname: $streditinga", "$course->fullname",
"<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> ->
<a href=\"$CFG->wwwroot/mod/$module->name/index.php?id=$course->id\">$strmodulenameplural</a> ->
$streditinga", $focuscursor, "", false);
} else {
print_header("$course->shortname: $streditinga", "$course->fullname",
"$streditinga", $focuscursor, "", false);
}
$icon = "<img align=middle height=16 width=16 src=\"$CFG->modpixpath/$module->name/icon.gif\" alt=\"\" />&nbsp;";
print_heading_with_help($pageheading, "mods", $module->name, $icon);
print_simple_box_start('center');
// this information is included below instead
// include_once($modform);
// error_reporting(E_ALL);
// if we're adding a new instance
if (empty($form->id)) {
if (isset($CFG->attendance_dynsection) && ($CFG->attendance_dynsection == "1")) { $form->dynsection = 1; }
if (isset($CFG->attendance_autoattend) && ($CFG->attendance_autoattend == "1")) { $form->autoattend = 1; }
if (isset($CFG->attendance_grade) && ($CFG->attendance_grade == "1")) { $form->grade = 1; }
$form->maxgrade = isset($CFG->attendance_maxgrade)?$CFG->attendance_maxgrade:0;
$form->hours = isset($CFG->attendance_default_hours)?$CFG->attendance_default_hours:1;
$form->day = time();
$form->notes = "";
}
?>
<form name="form" method="post" action="<?php echo "$CFG->wwwroot/course/mod.php"; ?>">
<center>
<input type="submit" value="<?php print_string("savechanges") ?>" />
<input type="submit" name="cancel" value="<?php print_string("cancel") ?>" />
<?php // if we're modifying an existing instance of attendance instead
// of creating a new one
if (isset($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);
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,
// lastaccess,lastlogin,picture (picture is null, 0, or 1), idnumber
// build the table for attendance roll
// this is the wrapper table
echo "<table align=\"center\" width=\"80\" class=\"generalbox\"".
"border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>".
"<td bgcolor=\"#ffffff\" class=\"generalboxcontent\">";
// this is the main table
echo "<table width=\"100%\" border=\"0\" valign=\"top\" align=\"center\" ".
"cellpadding=\"5\" cellspacing=\"1\" class=\"generaltable\">";
if ($form->hours >1) {
echo "<tr><th valign=\"top\" align=\"right\" colspan=\"3\" nowrap class=\"generaltableheader\">".
"Hours:</th>\n";
for($i=1;$i<=$form->hours;$i++) {
echo "<th valign=\"top\" align=\"center\" colspan=\"3\" nowrap class=\"generaltableheader\">".
"$i</th>\n";
}
echo "</tr>\n";
} // if more than one hour for each day
echo "<tr><th valign=\"top\" align=\"left\" nowrap class=\"generaltableheader\">Last Name</th>\n";
echo "<th valign=\"top\" align=\"left\" nowrap class=\"generaltableheader\">First Name</th>\n";
echo "<th valign=\"top\" align=\"left\" nowrap class=\"generaltableheader\">ID</th>\n";
$P=get_string("presentshort","attendance");
$T=get_string("tardyshort","attendance");
$A=get_string("absentshort","attendance");
// generate the headers for the attendance hours
for($i=1;$i<=$form->hours;$i++) {
echo "<th valign=\"top\" align=\"center\" nowrap class=\"generaltableheader\">".$P."</th>\n";
echo "<th valign=\"top\" align=\"center\" nowrap class=\"generaltableheader\">".$T."</th>\n";
echo "<th valign=\"top\" align=\"center\" nowrap class=\"generaltableheader\">".$A."</th>\n";
}
echo "</tr>\n";
$table->head = array("Last Name","First Name","ID",
get_string("presentlong","attendance"),
get_string("tardylong","attendance"),
get_string("absentlong","attendance"));
$table->align = array("left", "left", "left", "center","center","center");
$table->wrap = array("nowrap", "nowrap", "nowrap", "nowrap", "nowrap", "nowrap");
$table->width = "80";
$students = attendance_get_course_students($form->course, "u.lastname ASC");
$i=0;
if ($students) 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";
echo "<td align=\"left\" nowrap class=\"generaltablecell\" style=\"border-top: 1px solid;\">".$student->idnumber."</td>\n";
for($j=1;$j<=$form->hours;$j++) {
// set the attendance defaults for each student
$r1c=$r2c=$r3c=" ";
$rollstatus = (($form->edited==0)?$CFG->attendance_default_student_status:
((isset($sroll[$student->id][$j]->status)?$sroll[$student->id][$j]->status:0)));
if ($rollstatus==1) {$r2c="checked";}
elseif ($rollstatus==2) {$r3c="checked";}
else {$r1c="checked";}
$radio1="<input type=\"radio\" name=\"student_".$student->id."_".$j."\" value=\"0\" ".$r1c." />";
$radio2="<input type=\"radio\" name=\"student_".$student->id."_".$j."\" value=\"1\" ".$r2c." />";
$radio3="<input type=\"radio\" name=\"student_".$student->id."_".$j."\" value=\"2\" ".$r3c." />";
echo "<td align=\"left\" nowrap class=\"generaltablecell\" style=\"border-left: 1px dotted; border-top: 1px solid;\">".$radio1."</td>\n";
echo "<td align=\"left\" nowrap class=\"generaltablecell\" style=\"border-top: 1px solid;\">".$radio2."</td>\n";
echo "<td align=\"left\" nowrap class=\"generaltablecell\" style=\"border-top: 1px solid;\">".$radio3."</td>\n";
} // for loop
echo "</tr>\n";
// $radio1="<input type=\"radio\" name=\"student_".$student->id."\" value=\"0\" checked>";
// $radio2="<input type=\"radio\" name=\"student_".$student->id."\" value=\"1\">";
// $radio3="<input type=\"radio\" name=\"student_".$student->id."\" value=\"2\">";
// $table->data[$i]=array($student->lastname, $student->firstname,
// $student->idnumber, $radio1,$radio2,$radio3);
// $i++;
}
// doing the table manually now
// print_table($table);
// ending for both the tables
echo "</table></td></tr></table>\n";
} // 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) ?>" />
<br />
<?php
echo "<a href=\"../mod/attendance/add.php?id=".$form->course . "&amp;section=".$form->section ."\">Add multiple rolls</a><br /><br />";
?>
<input type="submit" value="<?php print_string("savechanges") ?>" />
<input type="submit" name="cancel" value="<?php print_string("cancel") ?>" />
</center>
</form>
<?php
print_simple_box_end();
print_footer($course);
?>
-12
View File
@@ -1,12 +0,0 @@
<?php // $Id$
/////////////////////////////////////////////////////////////////////////////////
/// Code fragment to define the version of attendance
/// This fragment is called by moodle_needs_upgrading() and /admin/index.php
/////////////////////////////////////////////////////////////////////////////////
$module->version = 2005021600; // The current module version (Date: YYYYMMDDXX)
$module->requires = 2005021600; // Requires this Moodle version
$module->cron = 3600; // Period for cron to check this module (secs)
?>
-178
View File
@@ -1,178 +0,0 @@
<?php // $Id$
/// This page prints a particular instance of attendance
require_once("../../config.php");
require_once("lib.php" );
/// @include_once("$CFG->dirroot/mod/attendance/lib.php"); teachered
// error_reporting(E_ALL);
optional_variable($id); // Course Module ID, or
optional_variable($a); // attendance ID
if ($id) {
if (! $cm = get_record("course_modules", "id", $id)) {
error("Course Module ID was incorrect");
}
if (! $course = get_record("course", "id", $cm->course)) {
error("Course is misconfigured");
}
if (! $attendance = get_record("attendance", "id", $cm->instance)) {
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");
}
}
require_login($course->id, true, $cm);
add_to_log($course->id, "attendance", "view", "view.php?id=$cm->id", $attendance->id, $cm->id);
/// Print the page header
$strattendances = get_string("modulenameplural", "attendance");
$strattendance = get_string("modulename", "attendance");
$strteacheredit = get_string("teacheredit", "attendance");
print_header_simple($attendance->name, "",
"<a href=index.php?id=$course->id>$strattendances</a> -> $attendance->name",
"", "", true, update_module_button($cm->id, $course->id, $strattendance),
navmenu($course, $cm));
/// Print the main part of the page
// adaptation of mod code to view code needs this:
$form = $attendance;
if (isteacher($course->id)) {
$rolls = get_records("attendance_roll", "dayid", $form->id);
} else if (!$cm->visible) {
notice(get_string("activityiscurrentlyhidden"));
print_footer($course); exit;
} else if (isstudent($course->id)) { // visible and a student
$rolls = get_records("attendance_roll", "dayid", $form->id, "userid", $USER->id);
} else {
notice(get_string("noviews", "attendance"));
print_footer($course); exit;
}
if ($rolls) {
foreach ($rolls as $roll) {
$sroll[$roll->userid][$roll->hour]->status=$roll->status;
$sroll[$roll->userid][$roll->hour]->notes=$roll->notes;
}
} else {
$sroll = array(); //just to set default value
}
// 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
$strviewall = get_string("viewall", "attendance");
$strviewweek = get_string("viewweek", "attendance");
echo '<div class="reportlink">';
if (isteacher($course->id)) {
echo "<a href=\"teacheredit.php?update=".$cm->id."&amp;return=true\">$strteacheredit</a><br/>";
}
echo "<a href=\"viewall.php?id=".$course->id."\">$strviewall</a><br/>";
echo "<a href=\"viewweek.php?scope=week&amp;id=".$attendance->id."\">$strviewweek</a>";
echo "</div>";
// this is the wrapper table
echo "<table align=\"center\" width=\"80\" class=\"generalbox\"".
"border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
echo "<tr><td bgcolor=\"#ffffff\" class=\"generalboxcontent\">";
// this is the main table
echo "<table width=\"100%\" border=\"0\" valign=\"top\" align=\"center\" ".
"cellpadding=\"5\" cellspacing=\"1\" class=\"generaltable\">";
// print the date headings at the top of the table
echo "<tr><th valign=\"top\" align=\"right\" colspan=\"3\" nowrap class=\"generaltableheader\">".
"&nbsp;</th>\n";
// put notes for the date in the date heading
$notes = ($form->notes != "") ? ":<br />".$form->notes : "";
echo "<th valign=\"top\" align=\"left\" colspan=\"" .$form->hours. "\" nowrap class=\"generaltableheader\">".
userdate($form->day,get_string("strftimedateshort")).$notes."</th>\n";
echo (($form->hours > 1) ? "<th valign=\"top\" align=\"left\" nowrap class=\"generaltableheader\">&nbsp;</th>\n" : "");
echo "</tr>\n";
// print the second level headings with name and possibly hour numbers
echo "<tr><th valign=\"top\" align=\"left\" nowrap class=\"generaltableheader\">Last Name</th>\n";
echo "<th valign=\"top\" align=\"left\" nowrap class=\"generaltableheader\">First Name</th>\n";
echo "<th valign=\"top\" align=\"left\" nowrap class=\"generaltableheader\">ID</th>\n";
// generate the headers for the attendance hours
if ($form->hours > 1) {
for($i=1;$i<=$form->hours;$i++) {
echo "<th valign=\"top\" align=\"center\" nowrap class=\"generaltableheader\">".$i."</th>\n";
}
echo "<th valign=\"top\" align=\"center\" nowrap class=\"generaltableheader\">total</td>";
} else { echo "<th valign=\"top\" align=\"center\" nowrap class=\"generaltableheader\">&nbsp;</th>\n"; }
echo "</tr>\n";
// 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,
// lastaccess,lastlogin,picture (picture is null, 0, or 1), idnumber
if (isteacher($course->id)){
$students = attendance_get_course_students($form->course, "u.lastname ASC");
} else { // must be a student
$students[0] = $USER;
}
$i=0;
$A = get_string("absentshort","attendance");
$T = get_string("tardyshort","attendance");
$P = get_string("presentshort","attendance");
if ($students) 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";
$studentid=(($student->idnumber != "") ? $student->idnumber : "&nbsp");
echo "<td align=\"left\" nowrap class=\"generaltablecell\" style=\"border-top: 1px solid;\">".$studentid."</td>\n";
$abs=$tar=0;
for($j=1;$j<=$form->hours;$j++) {
// set the attendance defaults for each student
if (isset ($sroll[$student->id][$j]->status) && $sroll[$student->id][$j]->status == 1 ) {$status=$T;$tar++;}
elseif (isset ($sroll[$student->id][$j]->status) && $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) {
$tot=attendance_tally_overall_absences_fraction($abs,$tar);
echo "<td align=\"left\" nowrap class=\"generaltablecell\" style=\"border-left: 1px dotted; border-top: 1px solid;\">".$tot."</td></tr>\n";
}
}
/// ending for the table
echo "</table></td></tr></table>\n";
/// print the miscellaneous settings information before the attendance roll
echo "<center><table align=\"center\" width=\"80\" class=\"generalbox\"".
"border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>".
"<td bgcolor=\"#ffffff\" class=\"generalboxcontent\">";
// this is the main table
echo "<table width=\"100%\" border=\"0\" valign=\"top\" align=\"center\" ".
"cellpadding=\"5\" cellspacing=\"1\" class=\"generaltable\">";
echo"<tr><th valign=\"top\" align=\"right\" nowrap class=\"generaltableheader\">".
get_string("dynsectionshort","attendance").":</th>\n";
echo"<th valign=\"top\" align=\"right\" nowrap class=\"generaltableheader\">".
(($form->dynsection=="1")?"Yes":"No")."</th></tr>\n";
echo"<tr><th valign=\"top\" align=\"right\" nowrap class=\"generaltableheader\">".
get_string("autoattendshort","attendance").":</th>\n";
echo"<th valign=\"top\" align=\"right\" nowrap class=\"generaltableheader\">".
(($form->autoattend=="1")?"Yes":"No")."</th></tr>\n";
echo"<tr><th valign=\"top\" align=\"right\" nowrap class=\"generaltableheader\">".
get_string("gradeshort","attendance").":</th>\n";
echo"<th valign=\"top\" align=\"right\" nowrap class=\"generaltableheader\">".
(($form->grade=="1")?"Yes":"No")."</th></tr>\n";
if ($form->grade == "1") {
echo"<tr><th valign=\"top\" align=\"right\" nowrap class=\"generaltableheader\">".
get_string("maxgradeshort","attendance").":</th>\n";
echo"<th valign=\"top\" align=\"right\" nowrap class=\"generaltableheader\">".
$form->maxgrade."</th></tr>\n";
}
echo "</table></td></table>\n";
/// Finish the page
print_footer($course);
?>
-530
View File
@@ -1,530 +0,0 @@
<?php // $Id$
/// This page prints all instances of attendance in a given course
require_once("../../config.php");
require_once("lib.php" );
/// @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 (! $attendances = get_records("attendance", "course", $id, "day ASC ")) {
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", "viewall", "viewall.php?id=$course->id");
/// Print the main part of the page
if ($attendances) {
if ( isstudent($course->id) && !isteacher($course->id)) {
attendance_print_header();
notice(get_string("noviews", "attendance"));
print_footer($course); exit;
}
/// create an array of all the attendance objects for the entire course
$numatt=0;
$numhours=0;
if ($attendances) foreach ($attendances as $attendance){
// store the raw attendance object
$cm = get_coursemodule_from_instance("attendance", $attendance->id, $course->id);
$attendance->cmid = $cm->id;
$atts[$numatt]->attendance=$attendance;
// tally the hours for possible paging of the report
$numhours=$numhours+$attendance->hours;
// 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
if (isstudent($course->id) && !isteacher($course->id)) {
$rolls = get_records("attendance_roll", "dayid", $form->id, "userid", $USER->id);
} else { // must be a teacher
$rolls = get_records("attendance_roll", "dayid", $attendance->id);
}
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++;
}
//
//
// IF REQUESTING A DATA FILE DOWNLOAD, GENERATE IT INSTEAD OF THE HTML PAGE, SEND IT, AND EXIT
//
//
if ($download == "xls") {
require_once("$CFG->libdir/excel/Worksheet.php");
require_once("$CFG->libdir/excel/Workbook.php");
// HTTP headers
attendance_HeaderingExcel($course->shortname."_Attendance.xls");
// Creating a workbook
$workbook = new Workbook("-");
// Creating the first worksheet
$myxls =& $workbook->add_worksheet('Attendance');
// print the date headings at the top of the table
// for each day of attendance
$myxls->write_string(3,0,get_string("lastname"));
$myxls->write_string(3,1,get_string("firstname"));
$myxls->write_string(3,2,get_string("idnumber"));
$pos=3;
if ($dlsub== "all") {
for($k=0;$k<$numatt;$k++) {
// put notes for the date in the date heading
$myxls->write_string(1,$pos,userdate($atts[$k]->attendance->day,"%m/%0d"));
$myxls->set_column($pos,$pos,5);
$myxls->write_string(2,$pos,$atts[$k]->attendance->notes);
for ($i=1;$i<=$atts[$k]->attendance->hours;$i++) {
$myxls->write_number(3,$pos,$i);
$myxls->set_column($pos,$pos,1);
$pos++;
}
}
} // if dlsub==all
$myxls->write_string(3,$pos,get_string("total"));
$myxls->set_column($pos,$pos,5);
/// generate the attendance rolls for the body of the spreadsheet
if (isstudent($course->id) && !isteacher($course->id)) {
$students[0] = $USER;
} else { // must be a teacher
$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");
$row=4;
if ($students) foreach ($students as $student) {
$myxls->write_string($row,0,$student->lastname);
$myxls->write_string($row,1,$student->firstname);
$studentid=(($student->idnumber != "") ? $student->idnumber : " ");
$myxls->write_string($row,2,$studentid);
$pos=3;
if ($dlsub== "all") {
for($k=0;$k<$numatt;$k++) { // for each 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=$P;}
$myxls->write_string($row,$pos,$status);
$pos++;
} /// for loop
}
}
$abs=$tar=0;
for($k=0;$k<$numatt;$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) {;$tar++;}
elseif ($atts[$k]->sroll[$student->id][$j]->status == 2) {;$abs++;}
} /// for loop
} // outer for for each day of attendance
$tot=attendance_tally_overall_absences_decimal($abs,$tar);
$myxls->write_number($row,$pos,$tot);
$row++;
}
$workbook->close();
exit;
}
if ($download == "txt") {
header("Content-Type: application/download\n");
header("Content-Disposition: attachment; filename=\"".$course->shortname."_Attendance.txt\"");
/// Print names of all the fields
echo get_string("firstname")."\t".get_string("lastname") . "\t". get_string("idnumber");
if ($dlsub== "all") {
for($k=0;$k<$numatt;$k++) {
// put notes for the date in the date heading
echo "\t" . userdate($atts[$k]->attendance->day,"%m/%0d");
echo (($atts[$k]->attendance->notes != "")?" ".$atts[$k]->attendance->notes:"");
for ($i=2;$i<=$atts[$k]->attendance->hours;$i++) { echo "\t$i"; }
}
} // if dlsub==all
echo "\t". get_string("total") . "\n";
/// generate the attendance rolls for the body of the spreadsheet
if (isstudent($course->id) && !isteacher($course->id)) {
$students[0] = $USER;
} else { // must be a teacher
$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");
$row=3;
if ($students) foreach ($students as $student) {
echo $student->lastname;
echo "\t".$student->firstname;
$studentid=(($student->idnumber != "") ? $student->idnumber : " ");
echo "\t". $studentid;
if ($dlsub== "all") {
for($k=0;$k<$numatt;$k++) { // for each 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=$P;}
echo "\t".$status;
} /// for loop
}
}
$abs=$tar=0;
for($k=0;$k<$numatt;$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) {;$tar++;}
elseif ($atts[$k]->sroll[$student->id][$j]->status == 2) {;$abs++;}
} /// for loop
} // outer for for each day of attendance
$tot=attendance_tally_overall_absences_decimal($abs,$tar);
echo "\t".$tot."\n";
$row++;
}
exit;
}
//
//
// FIGURE OUT THE PAGING LAYOUT FOR THE DATA BASED ON STATUS, PAGE NUMBER REQUESTED, ETC
//
//
// A LOOP FOR CREATING SINGLE-USER VERSION OF THE REPORT OR A ONE-PAGE REPORT
if (isstudent($course->id) && !isteacher($course->id)) {
$onepage=true;
$multipage=false;
} else if (!(isset($onepage))){
$onepage=false;
$multipage=true;
} else if ($onepage) {
$multipage=false;
} else { // if onepage is set to false
$multilpage=true;
}
// adjust the width for the report for students
if (($onetable) || ($CFG->attendance_hours_in_full_report == 0)) {
$hoursinreport = 100+$numhours;
} else if (isstudent($course->id) && !isteacher($course->id)) {
$hoursinreport = $CFG->attendance_hours_in_full_report + 15;
} else {
$hoursinreport = $CFG->attendance_hours_in_full_report;
}
while (($multipage || $onepage) && (!$endonepage)) {
// this makes for a one iteration loop for multipage
if ($multipage) {$onepage = false; $multipage = false; $endonepage=false;}
if ($numhours>=$hoursinreport) {
if (!isset($pagereport)) {
// $pagereport is used to determine whether the report needs to be paged at all
$pagereport=true;
$endatt=0;
$page=1;
}
// find the last hour to have on this page of the report
// go to the next (or first) page
// $endatt++;
// $startatt=$endatt;
$curpage=1;
$endatt=0;
for($curpage=1;true;$curpage++) { // the for loop is broken from the inside
$pagehours=$atts[$endatt]->attendance->hours;
$startatt=$endatt;
while(($pagehours<=$hoursinreport)) {
if ($endatt>=$numatt) { break 2; } // end the page number calculations and trigger the end of a multi-page report!
$endatt++;
$pagehours=$pagehours+$atts[$endatt]->attendance->hours;
}
// if this is the page we're on, save the info
if ($curpage == $page) {$endatt_target = $endatt; $startatt_target = $startatt; }
} // hopefully at this point, startatt and endatt are set correctly for the current page
if ($curpage == $page) {$endatt_target = $endatt; $startatt_target = $startatt; } else {
$endatt=$endatt_target; $startatt=$startatt_target; }
$maxpages = $curpage;
} else {$pagereport=false;}
$minatt=($pagereport ? $startatt : 0);
$maxatt=($pagereport ? $endatt : $numatt);
if ((!$pagereport) || ($page == $maxpages)) {$endonepage = true;} // end a one page display
//
//
// ALL PRELIMINARY STUFF DONE - MAKE THE MEAT OF THE PAGE
//
//
attendance_print_header();
// print other links at top of page
$strviewone = get_string("viewone", "attendance");
$strviewtable = get_string("viewtable", "attendance");
$strviewmulti = get_string("viewmulti", "attendance");
$strviewweek = get_string("viewweek", "attendance");
if ($onepage) { // one page for all tables
echo "<p align=\"right\"><a href=\"viewall.php?id=".$course->id."\">";
echo "$strviewmulti</a><br />";
echo "<a href=\"viewall.php?id=".$course->id."&amp;onetable=1\">";
echo "$strviewtable</a><br />";
echo "<a href=\"viewweek.php?scope=week&amp;id=".$atts[$minatt]->attendance->id."\">";
echo "$strviewweek</a></p>";
} else if ($onetable) { // one table for all
echo "<p align=\"right\"><a href=\"viewall.php?id=".$course->id."\">";
echo "$strviewmulti</a><br />";
echo "<a href=\"viewall.php?id=".$course->id."&amp;onepage=1\">";
echo "$strviewone</a><br />";
echo "<a href=\"viewweek.php?scope=week&amp;id=".$atts[$minatt]->attendance->id."\">";
echo "$strviewweek</a></p>";
} else { // multiple pages
echo "<p align=\"right\"><a href=\"viewall.php?id=".$course->id."&amp;onepage=1\">";
echo "$strviewone</a><br />";
echo "<a href=\"viewall.php?id=".$course->id."&amp;onetable=1\">";
echo "$strviewtable</a><br />";
echo "<a href=\"viewweek.php?scope=week&amp;id=".$atts[$minatt]->attendance->id."\">";
echo "$strviewweek</a></p>";
}
if (!$onepage) {
attendance_print_pagenav();
}
// build the table for attendance roll
// this is the wrapper table
echo "<table align=\"center\" width=\"80\" class=\"generalbox\"".
"border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>".
"<td bgcolor=\"#ffffff\" class=\"generalboxcontent\">";
// this is the main table
echo "<table width=\"100%\" border=\"0\" valign=\"top\" align=\"center\" ".
"cellpadding=\"5\" cellspacing=\"1\" class=\"generaltable\">";
if (isteacher($course->id)) {
echo "<tr><th valign=\"top\" align=\"right\" colspan=\"3\" nowrap class=\"generaltableheader\">".
"&nbsp;</th>\n";
}
// $minpage=0;$maxpage=$numatt;
// print the date headings at the top of the table
// for each day of attendance
for($k=$minatt;$k<$maxatt;$k++) {
// put notes for the date in the date heading
$notes = ($atts[$k]->attendance->notes != "") ? ":<br />".$atts[$k]->attendance->notes : "";
$auto = ($atts[$k]->attendance->autoattend == 1) ? "(".get_string("auto","attendance").")" : "";
echo "<th valign=\"top\" align=\"left\" colspan=\"" .$atts[$k]->attendance->hours. "\" nowrap class=\"generaltableheader\">".
"<a href=\"view.php?id=".$atts[$k]->attendance->cmid."\">".userdate($atts[$k]->attendance->day,"%m/%0d")."</a>".$auto.
$notes."</th>\n";
}
// if we're at the end of the report
if ($maxatt==$numatt || !$pagereport) {
echo "<th valign=\"top\" align=\"left\" nowrap class=\"generaltableheader\">&nbsp;</th>\n";
}
echo "</tr>\n";
// print the second level headings with name and possibly hour numbers
if (isteacher($course->id)) {
echo "<tr><th valign=\"top\" align=\"left\" nowrap class=\"generaltableheader\">Last Name</th>\n";
echo "<th valign=\"top\" align=\"left\" nowrap class=\"generaltableheader\">First Name</th>\n";
echo "<th valign=\"top\" align=\"left\" nowrap class=\"generaltableheader\">ID</th>\n";
}
// generate the headers for the attendance hours
for($k=$minatt;$k<$maxatt;$k++) {
if ($atts[$k]->attendance->hours > 1) {
for($i=1;$i<=$atts[$k]->attendance->hours;$i++) {
echo "<th valign=\"top\" align=\"center\" nowrap class=\"generaltableheader\">".$i."</th>\n";
}
} else { echo "<th valign=\"top\" align=\"center\" nowrap class=\"generaltableheader\">&nbsp;</th>\n"; }
}
// if we're at the end of the report
if ($maxatt==$numatt || !$pagereport) {
echo "<th valign=\"top\" align=\"center\" nowrap class=\"generaltableheader\">total</th>";
}
echo "</tr>\n";
// 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,
// lastaccess,lastlogin,picture (picture is null, 0, or 1), idnumber
if (isstudent($course->id) && !isteacher($course->id)) {
$students[0] = $USER;
} else { // must be a teacher
$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");
if ($students) 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";
echo "<td align=\"left\" nowrap class=\"generaltablecell\" style=\"border-top: 1px solid;\">".$student->firstname."</td>\n";
$studentid=(($student->idnumber != "") ? $student->idnumber : "&nbsp");
echo "<td align=\"left\" nowrap class=\"generaltablecell\" style=\"border-top: 1px solid;\">".$studentid."</td>\n";
}
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=$P;}
echo "<td align=\"left\" nowrap class=\"generaltablecell\" style=\"border-left: 1px dotted; border-top: 1px solid;\">".$status."</td>\n";
} /// for loop
}
if ($maxatt==$numatt || !$pagereport) {
// tally total attendances for the students
$abs=$tar=0;
for($k=0;$k<$numatt;$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) {;$tar++;}
elseif ($atts[$k]->sroll[$student->id][$j]->status == 2) {;$abs++;}
} /// for loop
} // outer for for each day of attendance
$tot=attendance_tally_overall_absences_fraction($abs,$tar);
echo "<td align=\"left\" nowrap class=\"generaltablecell\" style=\"border-left: 1px dotted; border-top: 1px solid;\">".$tot."</td></tr>\n";
}
} // foreach
/// doing the table manually now
/// print_table($table);
/// ending for the table
echo "</table></td></tr></table>\n";
if ($onepage) {$page++; echo "<br /> <br />\n"; }
} // while loop for multipage/one page printing
if (!$onepage) { attendance_print_pagenav(); }
echo "<center><table border=0 align=CENTER><tr>";
echo "<td>";
if (($numhours-4) > 255) {
echo "<form><input type=\"button\" value=\"".get_string("downloadexcelfull", "attendance").
"\" onclick=\"alert('Sorry, you have more than 251 days on this report. This will not fit into an Excel Spreadsheet. ".
" Please try downloading the report week by week instead.')\" /></form>";
} else {
$options["id"] = "$course->id";
$options["download"] = "xls";
$options["dlsub"] = "all";
print_single_button("viewall.php", $options, get_string("downloadexcelfull", "attendance"));
}
echo "</td><td>";
$options["id"] = "$course->id";
$options["download"] = "xls";
$options["dlsub"] = "totals";
print_single_button("viewall.php", $options, get_string("downloadexceltotals", "attendance"));
echo "</td><td>";
$options["download"] = "txt";
$options["dlsub"] = "all";
print_single_button("viewall.php", $options, get_string("downloadtextfull", "attendance"));
echo "</td><td>";
$options["dlsub"] = "totals";
print_single_button("viewall.php", $options, get_string("downloadtexttotals", "attendance"));
echo "</td></table></center>";
} else { error("There are no attendance rolls in this course.");} // for no attendance rolls
/// Finish the page
print_footer($course);
function attendance_print_header() {
global $course, $cm;
/// Print the page header
$strattendances = get_string("modulenameplural", "attendance");
$strattendance = get_string("modulename", "attendance");
$strallattendance = get_string("allmodulename", "attendance");
print_header_simple("$strallattendance", "",
"<a href=index.php?id=$course->id>$strattendances</a> -> $strallattendance",
"", "", true, "&nbsp;",
navmenu($course, $cm));
}
function attendance_print_pagenav() {
global $pagereport, $minatt, $maxatt, $course, $page, $numatt, $maxpages;
if ($pagereport) {
$of = get_string('of','attendance');
$pg = get_string('page');
echo "<center><table align=\"center\" width=\"80\" class=\"generalbox\"".
"border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>".
"<td bgcolor=\"#ffffff\" class=\"generalboxcontent\">";
// this is the main table
echo "<table width=\"100%\" border=\"0\" valign=\"top\" align=\"center\" ".
"cellpadding=\"5\" cellspacing=\"1\" class=\"generaltable\">";
echo "<tr>";
if ($minatt!=0) {
echo "<th valign=\"top\" align=\"right\" nowrap class=\"generaltableheader\">".
"<a href=\"viewall.php?id=".$course->id ."&amp;pagereport=1&amp;page=1\">&lt;&lt;</a>&nbsp;\n".
"<a href=\"viewall.php?id=".$course->id ."&amp;pagereport=1&amp;page=".($page-1)."\">&lt;</a></th>\n";
} else {
echo "<th valign=\"top\" align=\"right\" nowrap class=\"generaltableheader\">&lt;&lt;&nbsp;&lt;</th>\n";
}
echo "<th valign=\"top\" align=\"right\" nowrap class=\"generaltableheader\">".
"$pg $page $of $maxpages</th>\n";
if ($maxatt!=$numatt) {
echo "<th valign=\"top\" align=\"right\" nowrap class=\"generaltableheader\">".
"<a href=\"viewall.php?id=".$course->id ."&amp;pagereport=1&amp;page=". ($page+1)."\">&gt;</a>&nbsp;".
"<a href=\"viewall.php?id=".$course->id ."&amp;pagereport=1&amp;page=$maxpages\">&gt;&gt;</a></th>";
} else {
echo "<th valign=\"top\" align=\"right\" nowrap class=\"generaltableheader\">&gt;&nbsp;&gt;&gt;</th>\n";
}
echo "</tr></table></td></tr></table></center>\n";
}
}
function attendance_HeaderingExcel($filename) {
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$filename" );
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
header("Pragma: public");
}
?>
http://www.alpine-usa.com/company_info/press_release/010804_ipad.html
-537
View File
@@ -1,537 +0,0 @@
<?php // $Id$
/// This page prints all instances of attendance in a given week
require_once("../../config.php");
require_once("lib.php" );
/// @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 (! $attendance = get_record("attendance", "id", $id)) {
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 ($scope == "section") {
if (! $attendances = get_attendance_for_section($attendance->id, $course->id)) {
error("Course module is incorrect");
}
} else {
if (! $attendances = get_attendance_for_week($attendance->id, $course->id)) {
error("Course module is incorrect");
}
}
}
require_login($course->id);
add_to_log($course->id, "attendance", "viewweek", "viewweek.php?scope=".$scope."&amp;id=$course->id");
if ($attendances) {
if ( !(isteacher($course->id) || isstudent($course->id)) ) {
attendance_print_header();
notice(get_string("noviews", "attendance"));
print_footer($course); exit;
}
/// create an array of all the attendance objects for the week
$numatt=0;
$numhours=0;
if ($attendances) foreach ($attendances as $attendance){
// store the raw attendance object
$cm = get_coursemodule_from_instance("attendance", $attendance->id, $course->id);
$attendance->cmid = $cm->id;
$atts[$numatt]->attendance=$attendance;
// tally the hours for possible paging of the report
$numhours=$numhours+$attendance->hours;
// 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
if (isstudent($course->id)) {
$rolls = get_records("attendance_roll", "dayid", $form->id, "userid", $USER->id);
} else { // must be a teacher
$rolls = get_records("attendance_roll", "dayid", $attendance->id);
}
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++;
}
//
//
// IF REQUESTING A DATA FILE DOWNLOAD, GENERATE IT INSTEAD OF THE HTML PAGE, SEND IT, AND EXIT
//
//
if ($download == "xls") {
require_once("$CFG->libdir/excel/Worksheet.php");
require_once("$CFG->libdir/excel/Workbook.php");
// HTTP headers
attendance_HeaderingExcel($course->shortname."_Attendance_Week.xls");
// Creating a workbook
$workbook = new Workbook("-");
// Creating the first worksheet
$myxls =& $workbook->add_worksheet('Weekly Attendance');
// print the date headings at the top of the table
// for each day of attendance
$myxls->write_string(3,0,get_string("lastname"));
$myxls->write_string(3,1,get_string("firstname"));
$myxls->write_string(3,2,get_string("idnumber"));
$pos=3;
if ($dlsub== "all") {
for($k=0;$k<$numatt;$k++) {
// put notes for the date in the date heading
$myxls->write_string(1,$pos,userdate($atts[$k]->attendance->day,"%m/%0d"));
$myxls->set_column($pos,$pos,5);
$myxls->write_string(2,$pos,$atts[$k]->attendance->notes);
for ($i=1;$i<=$atts[$k]->attendance->hours;$i++) {
$myxls->write_number(3,$pos,$i);
$myxls->set_column($pos,$pos,1);
$pos++;
}
}
} // if dlsub==all
$myxls->write_string(3,$pos,get_string("total"));
$myxls->set_column($pos,$pos,5);
/// generate the attendance rolls for the body of the spreadsheet
if (isstudent($course->id)) {
$students[0] = $USER;
} else { // must be a teacher
$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");
$row=4;
if ($students) foreach ($students as $student) {
$myxls->write_string($row,0,$student->lastname);
$myxls->write_string($row,1,$student->firstname);
$studentid=(($student->idnumber != "") ? $student->idnumber : " ");
$myxls->write_string($row,2,$studentid);
$pos=3;
if ($dlsub== "all") {
for($k=0;$k<$numatt;$k++) { // for each 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=$P;}
$myxls->write_string($row,$pos,$status);
$pos++;
} /// for loop
}
}
$abs=$tar=0;
for($k=0;$k<$numatt;$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) {;$tar++;}
elseif ($atts[$k]->sroll[$student->id][$j]->status == 2) {;$abs++;}
} /// for loop
} // outer for for each day of attendance
$tot=attendance_tally_overall_absences_decimal($abs,$tar);
$myxls->write_number($row,$pos,$tot);
$row++;
}
$workbook->close();
exit;
}
if ($download == "txt") {
header("Content-Type: application/download\n");
header("Content-Disposition: attachment; filename=\"".$course->shortname."_Attendance_Week.txt\"");
/// Print names of all the fields
echo get_string("firstname")."\t".get_string("lastname") . "\t". get_string("idnumber");
if ($dlsub== "all") {
for($k=0;$k<$numatt;$k++) {
// put notes for the date in the date heading
echo "\t" . userdate($atts[$k]->attendance->day,"%m/%0d");
echo (($atts[$k]->attendance->notes != "")?" ".$atts[$k]->attendance->notes:"");
for ($i=2;$i<=$atts[$k]->attendance->hours;$i++) { echo "\t$i"; }
}
} // if dlsub==all
echo "\t". get_string("total") . "\n";
/// generate the attendance rolls for the body of the spreadsheet
if (isstudent($course->id)) {
$students[0] = get_user_info_from_db("id", $USER->id);
} else { // must be a teacher
$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");
$row=3;
if ($students) foreach ($students as $student) {
echo $student->lastname;
echo "\t".$student->firstname;
$studentid=(($student->idnumber != "") ? $student->idnumber : " ");
echo "\t". $studentid;
if ($dlsub== "all") {
for($k=0;$k<$numatt;$k++) { // for each 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=$P;}
echo "\t".$status;
} /// for loop
}
}
$abs=$tar=0;
for($k=0;$k<$numatt;$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) {;$tar++;}
elseif ($atts[$k]->sroll[$student->id][$j]->status == 2) {;$abs++;}
} /// for loop
} // outer for for each day of attendance
$tot=attendance_tally_overall_absences_decimal($abs,$tar);
echo "\t".$tot."\n";
$row++;
}
exit;
}
//
//
// FIGURE OUT THE PAGING LAYOUT FOR THE DATA BASED ON STATUS, PAGE NUMBER REQUESTED, ETC
//
//
if (isstudent($course->id)) {
$onepage=true;
$multipage=false;
} else if (!(isset($onepage))){
$onepage=false;
$multipage=true;
} else if ($onepage) {
$multipage=false;
} else { // if onepage is set to false
$multilpage=true;
}
// adjust the width for the report for students
if (($onetable) || ($CFG->attendance_hours_in_full_report == 0)) {
$hoursinreport = 100+$numhours;
} else if (isstudent($course->id)) {
$hoursinreport = $CFG->attendance_hours_in_full_report + 15;
} else {
$hoursinreport = $CFG->attendance_hours_in_full_report;
}
while (($multipage || $onepage) && (!$endonepage)) {
// this makes for a one iteration loop for multipage
$multipage = false;
if ($numhours>=$hoursinreport) {
if (!isset($pagereport)) {
// $pagereport is used to determine whether the report needs to be paged at all
$pagereport=true;
$endatt=0;
$page=1;
}
// find the last hour to have on this page of the report
// go to the next (or first) page
// $endatt++;
// $startatt=$endatt;
$curpage=1;
$endatt=0;
for($curpage=1;true;$curpage++) { // the for loop is broken from the inside
$pagehours=$atts[$endatt]->attendance->hours;
$startatt=$endatt;
while(($pagehours<$hoursinreport)) {
if ($endatt>=$numatt) { break 2; } // end the page number calculations and trigger the end of a multi-page report!
$endatt++;
$pagehours=$pagehours+$atts[$endatt]->attendance->hours;
}
// if this is the page we're on, save the info
if ($curpage == $page) {$endatt_target = $endatt; $startatt_target = $startatt; }
} // hopefully at this point, startatt and endatt are set correctly for the current page
if ($curpage == $page) {$endatt_target = $endatt; $startatt_target = $startatt; } else {
$endatt=$endatt_target; $startatt=$startatt_target; }
$maxpages = $curpage;
} else {$pagereport=false;}
$minatt=($pagereport ? $startatt : 0);
$maxatt=($pagereport ? $endatt : $numatt);
if ((!$pagereport) || ($page == $maxpages)) {$endonepage = true;} // end a one page display
//
//
// ALL PRELIMINARY STUFF DONE - MAKE THE MEAT OF THE PAGE
//
//
attendance_print_header();
// print other links at top of page
$strviewsection = get_string("viewsection", "attendance");
$strviewweek = get_string("viewweek", "attendance");
$strviewall = get_string("viewall", "attendance");
$strviewone = get_string("viewone", "attendance");
$strviewtable = get_string("viewtable", "attendance");
$strviewmulti = get_string("viewmulti", "attendance");
echo "<p align=\"right\"><a href=\"viewall.php?id=".$course->id."\">";
echo "$strviewall</a><br />";
if ($onepage) { // one page for all tables
echo "<a href=\"viewweek.php?scope=".$scope."&amp;id=".$id ."\">";
echo "$strviewmulti</a><br />";
echo "<a href=\"viewweek.php?scope=".$scope."&amp;id=".$id ."&amp;onetable=1\">";
echo "$strviewtable</a><br />";
} else if ($onetable) { // one table for all
echo "<a href=\"viewweek.php?scope=".$scope."&amp;id=".$id ."\">";
echo "$strviewmulti</a><br />";
echo "<a href=\"viewweek.php?scope=".$scope."&amp;id=".$id ."&amp;onepage=1\">";
echo "$strviewone</a><br />";
} else { // multiple pages
echo "<a href=\"viewweek.php?scope=".$scope."&amp;id=".$id ."&amp;onepage=1\">";
echo "$strviewone</a><br />";
echo "<a href=\"viewweek.php?scope=".$scope."&amp;id=".$id ."&amp;onetable=1\">";
echo "$strviewtable</a><br />";
}
if ($scope=="week") { // week view for scope
echo "<a href=\"viewweek.php?scope=section&amp;id=".$id."\">";
echo "$strviewsection</a></p>";
} else { // section view for scope
echo "<a href=\"viewweek.php?scope=week&amp;id=".$id."\">";
echo "$strviewweek</a></p>";
}
if (!$onepage) {
attendance_print_pagenav();
}
// build the table for attendance roll
// this is the wrapper table
echo "<table align=\"center\" width=\"80\" class=\"generalbox\"".
"border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>".
"<td bgcolor=\"#ffffff\" class=\"generalboxcontent\">";
// this is the main table
echo "<table width=\"100%\" border=\"0\" valign=\"top\" align=\"center\" ".
"cellpadding=\"5\" cellspacing=\"1\" class=\"generaltable\">";
if (isteacher($course->id)) {
echo "<tr><th valign=\"top\" align=\"right\" colspan=\"3\" nowrap class=\"generaltableheader\">".
"&nbsp;</th>\n";
}
// $minpage=0;$maxpage=$numatt;
// print the date headings at the top of the table
// for each day of attendance
for($k=$minatt;$k<$maxatt;$k++) {
// put notes for the date in the date heading
$notes = ($atts[$k]->attendance->notes != "") ? ":<br />".$atts[$k]->attendance->notes : "";
$auto = ($atts[$k]->attendance->autoattend == 1) ? "(".get_string("auto","attendance").")" : "";
echo "<th valign=\"top\" align=\"left\" colspan=\"" .$atts[$k]->attendance->hours. "\" nowrap class=\"generaltableheader\">".
"<a href=\"view.php?id=".$atts[$k]->attendance->cmid."\">".userdate($atts[$k]->attendance->day,"%m/%0d")."</a>".$auto.
$notes."</th>\n";
}
// if we're at the end of the report
if ($maxatt==$numatt || !$pagereport) {
echo "<th valign=\"top\" align=\"left\" nowrap class=\"generaltableheader\">&nbsp;</th>\n";
}
echo "</tr>\n";
// print the second level headings with name and possibly hour numbers
if (isteacher($course->id)) {
echo "<tr><th valign=\"top\" align=\"left\" nowrap class=\"generaltableheader\">Last Name</th>\n";
echo "<th valign=\"top\" align=\"left\" nowrap class=\"generaltableheader\">First Name</th>\n";
echo "<th valign=\"top\" align=\"left\" nowrap class=\"generaltableheader\">ID</th>\n";
}
// generate the headers for the attendance hours
for($k=$minatt;$k<$maxatt;$k++) {
if ($atts[$k]->attendance->hours > 1) {
for($i=1;$i<=$atts[$k]->attendance->hours;$i++) {
echo "<th valign=\"top\" align=\"center\" nowrap class=\"generaltableheader\">".$i."</th>\n";
}
} else { echo "<th valign=\"top\" align=\"center\" nowrap class=\"generaltableheader\">&nbsp;</th>\n"; }
}
// if we're at the end of the report
if ($maxatt==$numatt || !$pagereport) {
echo "<th valign=\"top\" align=\"center\" nowrap class=\"generaltableheader\">total</th>";
}
echo "</tr>\n";
// 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,
// lastaccess,lastlogin,picture (picture is null, 0, or 1), idnumber
if (isstudent($course->id)) {
$students[0] = get_user_info_from_db("id", $USER->id);
} else { // must be a teacher
$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");
if ($students) 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";
echo "<td align=\"left\" nowrap class=\"generaltablecell\" style=\"border-top: 1px solid;\">".$student->firstname."</td>\n";
$studentid=(($student->idnumber != "") ? $student->idnumber : "&nbsp");
echo "<td align=\"left\" nowrap class=\"generaltablecell\" style=\"border-top: 1px solid;\">".$studentid."</td>\n";
}
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=$P;}
echo "<td align=\"left\" nowrap class=\"generaltablecell\" style=\"border-left: 1px dotted; border-top: 1px solid;\">".$status."</td>\n";
} /// for loop
}
if ($maxatt==$numatt || !$pagereport) {
// tally total attendances for the students
$abs=$tar=0;
for($k=0;$k<$numatt;$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) {;$tar++;}
elseif ($atts[$k]->sroll[$student->id][$j]->status == 2) {;$abs++;}
} /// for loop
} // outer for for each day of attendance
$tot=attendance_tally_overall_absences_fraction($abs,$tar);
echo "<td align=\"left\" nowrap class=\"generaltablecell\" style=\"border-left: 1px dotted; border-top: 1px solid;\">".$tot."</td></tr>\n";
}
} // foreach
/// doing the table manually now
/// print_table($table);
/// ending for the table
echo "</table></td></tr></table>\n";
if ($onepage) {$page++; echo "<br /> <br />\n"; }
} // while loop for multipage/one page printing
if (!$onepage) { attendance_print_pagenav(); }
echo "<center><table border=0 align=CENTER><tr>";
echo "<td>";
if (($numhours-4) > 255) {
echo "<form><input type=\"button\" value=\"".get_string("downloadexcelfull", "attendance").
"\" onclick=\"alert('Sorry, you have more than 251 days on this report. This will not fit into an Excel Spreadsheet. ".
" Please try downloading the report week by week instead.')\" /></form>";
} else {
$options["id"] = "$id";
$options["download"] = "xls";
$options["dlsub"] = "all";
print_single_button("viewweek.php", $options, get_string("downloadexcelfull", "attendance"));
}
echo "</td><td>";
$options["id"] = "$id";
$options["download"] = "xls";
$options["dlsub"] = "totals";
print_single_button("viewweek.php", $options, get_string("downloadexceltotals", "attendance"));
echo "</td><td>";
$options["download"] = "txt";
$options["dlsub"] = "all";
print_single_button("viewweek.php", $options, get_string("downloadtextfull", "attendance"));
echo "</td><td>";
$options["dlsub"] = "totals";
print_single_button("viewweek.php", $options, get_string("downloadtexttotals", "attendance"));
echo "</td></table></center>";
} else { error("There are no attendance rolls in this course.");} // for no attendance rolls
/// Finish the page
print_footer($course);
function attendance_print_pagenav() {
global $pagereport, $minatt, $maxatt, $course, $page, $numatt, $maxpages, $attendance,$scope,$id;
if ($pagereport) {
$of = get_string('of','attendance');
$pg = get_string('page');
echo "<center><table align=\"center\" width=\"80\" class=\"generalbox\"".
"border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>".
"<td bgcolor=\"#ffffff\" class=\"generalboxcontent\">";
// this is the main table
echo "<table width=\"100%\" border=\"0\" valign=\"top\" align=\"center\" ".
"cellpadding=\"5\" cellspacing=\"1\" class=\"generaltable\">";
echo "<tr>";
if ($minatt!=0) {
echo "<th valign=\"top\" align=\"right\" nowrap class=\"generaltableheader\">".
"<a href=\"viewweek.php?scope=".$scope."&amp;id=".$id ."&amp;pagereport=1&amp;page=".($page-1)."\">&lt;</a>&nbsp;\n";
"<a href=\"viewweek.php?scope=".$scope."&amp;id=".$id ."&amp;pagereport=1&amp;page=1\">&lt;&lt;</a></th>\n";
} else {
echo "<th valign=\"top\" align=\"right\" nowrap class=\"generaltableheader\">&lt;&lt;&nbsp;&lt;</th>\n";
}
echo "<th valign=\"top\" align=\"right\" nowrap class=\"generaltableheader\">".
"$pg $page $of $maxpages</th>\n";
if ($maxatt!=$numatt) {
echo "<th valign=\"top\" align=\"right\" nowrap class=\"generaltableheader\">".
"<a href=\"viewweek.php?scope=".$scope."&amp;id=".$id ."&amp;pagereport=1&amp;page=". ($page+1)."\">&gt;</a>&nbsp;".
"<a href=\"viewweek.php?scope=".$scope."&amp;id=".$id ."&amp;pagereport=1&amp;page=$maxpages\">&gt;&gt;</a></th>";
} else {
echo "<th valign=\"top\" align=\"right\" nowrap class=\"generaltableheader\">&gt;&nbsp;&gt;&gt;</th>\n";
}
echo "</tr></table></td></tr></table></center>\n";
}
}
function attendance_print_header() {
global $course, $cm;
/// Print the page header
$strattendances = get_string("modulenameplural", "attendance");
$strattendance = get_string("modulename", "attendance");
$strweekattendance = get_string("weekmodulename", "attendance");
print_header_simple("$strallattendance", "",
"<a href=index.php?id=$course->id>$strattendances</a> -> $strweekattendance",
"", "", true, "&nbsp;",
navmenu($course, $cm));
}
function attendance_HeaderingExcel($filename) {
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$filename" );
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
header("Pragma: public");
}
?>