\n";
#foreach my $key (keys %arr) { print "K: $key V: $arr{$key} \n"; }
# Passed either $arr{date} or $arr{startdate} and $arr{enddate}
# if date is could be today, yesterday, thisweek, or lastweek.
# if today or yesterday, set $singleDay; other cases set startdate and enddate.
# Set Dates - FIX THIS AFTER DONE; remove stuff we don't need.
#($sec, $min, $hour, $mday, $mon, $year, $wday,
# $yday, $iddst) = localtime(time);
my @tim = localtime(time);
my $year = $tim[5] + 1900;
my $month = $tim[4] + 1;
my $day = $tim[3];
my $jd = julian_day($year,$month,$day);
if (length($month) == 1){ $month = "0".$month;}
if (length($day) == 1){ $day = "0".$day;}
#my $currdate = "$dow["$tim[6]+1"], $month[$month] $tim[3], $year";
my $today = "$year-$month-$day";
my $currdate = "$year-$month-$day";
$currsdate = "$year$month$day";
$currdate1 = "$month[$month] $day, $year";
$dow = day_of_week($jd + 1); # a number from 0 (Sunday) to 6 (Saturday)
# Branch to different pages
if ( not $arr{flag} ) {
showStartPage();
} elsif ($arr{flag} == 2) {
delete $arr{flag};
writeRecords();
} else { # and continue on below...
delete $arr{flag};
}
# Now setup date range values.
my ($singleday, $startdate, $enddate, $prevday);
if ( $arr{date} ) {
if ($arr{date} eq $lex{Today}) {
$singleday = $currdate;
} elsif ($arr{date} eq $lex{Yesterday}) {
# Figure out yesterday using Date::Business
my $btoday = new Date::Business();
$btoday->prevb();
$singleday = $btoday->image();
$singleday = substr($singleday,0,4).'-'.substr($singleday,4,2).'-'.substr($singleday,6,2);
} elsif ( $arr{date} eq $lex{'This Week'} ) {
# set startdate and enddate
my $mondayjd = $jd - ($tim[6]-1); #This will now give Monday of this week.
my $fridayjd = $mondayjd + 4;
my ($y,$m,$d) = inverse_julian_day($mondayjd);
if (length($m) == 1){ $m = "0".$m;}
if (length($d) == 1){ $d = "0".$d;}
$startdate = "$y-$m-$d";
my ($y,$m,$d) = inverse_julian_day($fridayjd);
if (length($m) == 1){ $m = "0".$m;}
if (length($d) == 1){ $d = "0".$d;}
$enddate = "$y-$m-$d";
} elsif ($arr{date} eq $lex{'Last Week'}) {
my $mondayjd = $jd - ($tim[6]-1); #This will now give Monday of this week.
my $mondayjd = $mondayjd - 7; # last monday.
my $fridayjd = $mondayjd + 4; # last friday.
my ($y,$m,$d) = inverse_julian_day($mondayjd);
if (length($m) == 1){ $m = "0".$m;}
if (length($d) == 1){ $d = "0".$d;}
$startdate = "$y-$m-$d";
my ($y,$m,$d) = inverse_julian_day($fridayjd);
if (length($m) == 1){ $m = "0".$m;}
if (length($d) == 1){ $d = "0".$d;}
$enddate = "$y-$m-$d";
} else { # an error... no match
print $lex{'Missing Date'}," \n";
die;
}
} elsif ($arr{startdate} and $arr{enddate}) {
$startdate = $arr{startdate};
$enddate = $arr{enddate};
} else { # another error... no date or no startdate/enddate
print $lex{'Missing Start Date or End Date'}," \n";
die;
}
# display date range(s) Set startdate/enddate if singleday; set
# prevday. Prevday is one day before the single day value or the day
# before the start of the date range. It is used as the enddate for
# searches for previous attendance values. We have 2 blocks of time:
# 1) Start of Year to Prev Day.
# 2) Single Day (1 day) or Startdate and Enddate (a block of days).
if ( $singleday ) {
print "",$lex{Date},": $singleday \n";
$startdate = $singleday;
$enddate = $singleday;
} else {
print "",$lex{'Start Date'},": $startdate\n";
print "",$lex{'End Date'},": $enddate \n";
}
# Set $prevday from $startdate
my $tmpdate = $startdate;
$tmpdate =~ s/-//g;
$sdate = new Date::Business(DATE => $tmpdate);
$sdate->prevb();
$prevday = $sdate->image();
$prevday = substr($prevday,0,4).'-'.substr($prevday,4,2).'-'.substr($prevday,6,2);
#foreach my $key (keys %arr) { print "K: $key V: $arr{$key} \n"; }
my $sth;
# Find the students that have attendance records in this date range
if ( $singleday ) { # A single day query
$sth = $dbh->prepare("select distinct studentid from attend
where absdate = '$singleday' order by studentid");
} elsif ( $startdate ) { # We select a date range
$sth = $dbh->prepare("select distinct studentid from attend
where to_days(attend.absdate) >= to_days('$startdate') and
to_days(attend.absdate) <= to_days('$enddate')
order by studentid");
} else { # a mistake
print $lex{'Missing Date'}, " \n";
print "\n";
exit;
}
$sth->execute;
if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; }
my $sth1 = $dbh->prepare("select lastname, firstname from studentall
where studnum = ?");
my @studnum;
while ( my $sn = $sth->fetchrow ) {
# Get Name
$sth1->execute( $sn );
if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr;}
my ($lastname, $firstname) = $sth1->fetchrow;
push @studnum, "$lastname:$firstname:$sn";
}
# Map reason to points in points hash.
for (0..$#attend) {
$points{$attend[$_]} = $points[$_];
}
print "