\n};
}
# Now do teacher attendance entries, including perfect att.
# Insert the teacher attendance record
my $sth = $dbh->prepare("insert into tattend ( userid, attdate, currdate, subjects, periods )
values ( ?,?, now(),?,? )");
my $sth1 = $dbh->prepare("select count(*) from tattend where userid = ? and attdate = ?
and subjects = ? and periods = ?");
# Teacher Attendance Entry; loop through all passed values.
foreach my $key ( keys %arr ) {
# find out the kind of entry: PA or not.
my @temp = split(':', $key);
if ( $temp[0] eq 'PA' ) { # perfect attendance record
my ( $txt,$subjsec,$date,$period ) = split(':',$key);
if ( $method ne 'subject' ) { # munge the subjsec
my $tempsubj = $subjsec;
$tempsubj =~ s/^HR//; # strip leading HR
$subjsec = qq{HR:$tempsubj}; # put in HR with colon
}
# Check if added already
$sth1->execute( $userid, $date, $subjsec,$period );
if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; }
my $count = $sth1->fetchrow;
# Otherwise, add the record
if ( not $count ) { # Insert tattend records
# print qq{Insert: PA rec: User:$userid Date:$date Subjsec:$subjsec Period:$period \n};
$sth->execute( $userid, $date, $subjsec, $period );
if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; }
}
} else { # a normal teacher attendance record
my ( $studnum,$subjsec,$period, $reason, $late, $date ) = split(':',$key);
if ( $method ne 'subject' ) { # munge the subjsec
my $tempsubj = $subjsec;
$tempsubj =~ s/^HR//; # strip leading HR
$subjsec = qq{HR:$tempsubj}; # put in HR with colon
}
# Check if added already
$sth1->execute( $userid, $date, $subjsec,$period );
if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; }
my $count = $sth1->fetchrow;
# Otherwise, add the record
if ( not $count ) { # Insert tattend records
# print qq{Insert Normal rec: User:$userid Date:$date Subjsec:$subjsec Period:$period \n};
$sth->execute( $userid, $date, $subjsec, $period );
if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; }
}
}
} # end of %arr loop
# Add more Attendance Records
print qq{
\n};
print qq{\n};
exit;
} # end of writeAttendance
#-----------
sub addLates {
#-----------
# Test Section
# print qq{ \n};
# foreach my $key ( sort keys %arr ) {
# if ( $arr{$key} ) { print qq{K:$key V:$arr{$key} \n}; }
# }
# if coming from multiday, there will be no date value
# passed. Homeroom method pass a date, but there will be blanks in
# the keys coming from the enterAttendance function. They both
# will have values of studnum:subjsec:date:period and reason and
# late values will have a 5th field of Reason (no Late value
# passed into addLates of course).
my $method = $arr{method};
delete $arr{method};
my $date = $arr{date};
delete $arr{date};
print qq{