#!/usr/bin/perl # Copyright 2001-2010 Leslie Richardson # This file is part of Open Admin for Schools. # Passed as "group": Accept Grade, Class, or All for group to # find for attendance. # Passed as "mode": Weekly or Biweekly Mode. (or Date Range?) # Passed as "class": The value of the group: ie. 8c, 10. my %lex = ( 'Multi-Day Attendance Entry' => 'Multi-Day Attendance Entry', 'Attendance' => 'Attendance', 'Name' => 'Name', 'Continue' => 'Continue', 'Error' => 'Error', 'Weekly' => 'Weekly', 'Select by' => 'Select by', 'Grade' => 'Grade', 'Homeroom' => 'Homeroom', 'Weekly' => 'Weekly', 'Biweekly' => 'Biweekly', 'Continue' => 'Continue', 'Mode' => 'Mode', 'Blank=All' => 'Blank=All', ); my $self = 'attentrymd0.pl'; use DBI; use CGI; use Time::JulianDay; eval require "../../etc/admin.conf"; if ( $@ ) { print $lex{Error}. ": $@
\n"; die $lex{Error}. ": $@\n"; } my $q = new CGI; print $q->header( -charset, $charset ); my %arr = $q->Vars; print "$doctype\n"; print $lex{'Multi-Day Attendance Entry'}; print "\n\n"; print "$chartype\n[ ". $lex{Attendance}; print " ] $currdate1\n
\n

". $lex{'Multi-Day Attendance Entry'}. "

\n"; if ( not $arr{page} ) { showStartPage(); } else { delete $arr{page}; } # Setup MaxPPD.(Maximum Periods per Day) my $maxppd; # Maximum periods per day if ( not %g_ppd ) { print "Periods per Day not set in configuration file!"; print "\n"; exit; } foreach my $key ( keys %g_ppd){ if ($g_ppd{$key} > $maxppd){ $maxppd = $g_ppd{$key};} } # Set # of weeks to do. if ( $arr{mode} eq $lex{Weekly} ){ $weekcount = 1;} else {$weekcount = 2;} # Get Date if ( $arr{date} ) { # Generate a list from those dates. Assume year-mon-day ($year,$month,$day) = split /-/,$arr{date}; $jd = julian_day($year,$month,$day); $dow = day_of_week($jd); $mondayjd = $jd - ($dow-1); if (length($month) == 1){ $month = "0".$month;} if (length($day) == 1){ $day = "0".$day;} $currsdate = "$year$month$day"; $currdate = "$year-$month-$day"; } else { # get current date @tim = localtime(time); $year = @tim[5] + 1900; $month = @tim[4] + 1; $day = @tim[3]; $jd = julian_day($year,$month,$day); $mondayjd = $jd - ($tim[6]-1); #This will now give Monday of that week. if (length($month) == 1){ $month = "0".$month;} if (length($day) == 1){ $day = "0".$day;} $currdate = "$year-$month-$day"; $currsdate = "$year$month$day"; $currdate1 = "@month[$month] $day, $year"; } # Setup Array and Hash to hold Dates and DOW Dates mkDateData($mondayjd,$weekcount); my $dsn = "DBI:$dbtype:dbname=$dbase"; my $dbh = DBI->connect($dsn,$user,$password); $dbh->{mysql_enable_utf8} = 1; # Setup the select from passed values: grouptype, groupvalue my $select; if ( $arr{grouptype} eq $lex{Homeroom} and $arr{groupvalue} ){ $select = " where homeroom = ? "; } elsif ( $arr{grouptype} eq $lex{Grade} and $arr{groupvalue} ) { $select = " where grade = ? "; } # Find the kids' names and studnum my $sth = $dbh->prepare("select lastname, firstname, studnum from student $select order by lastname, firstname"); if ( $arr{groupvalue} ) { $sth->execute( $arr{groupvalue} ); } else { $sth->execute; } if ($DBI::errstr){ print $DBI::errstr; die "$DBI::errstr\n";} print "

$arr{grouptype} $arr{groupvalue}

\n"; $prevjd = $mondayjd - 7; ($prevyear, $prevmonth, $prevday) = inverse_julian_day($prevjd); $prevdate = "$prevyear-$prevmonth-$prevday"; print "\n\n"; $nextjd = $mondayjd + 7; ($nextyear, $nextmonth, $nextday) = inverse_julian_day($nextjd); $nextdate = "$nextyear-$nextmonth-$nextday"; print "
\">
\n\n"; print "
\n"; print "\n"; # Loop through table headings. print '\n"; foreach my $day ( @days ){ print "";} print "\n"; # Loop through kids displaying the values. while ( @student = $sth->fetchrow){ # print Name. print "\n"; # print the days for this mode: foreach my $day (@days){ print ""; } print "\n"; } print "
'. $lex{Name}. "$datedata{$day}
$student[0], $student[1]"; for (1..$maxppd){ print "P$_"; } print "
\n"; #------------- sub mkDateData { #------------- my ($jd, $weeks) = @_; # Build an array of ISO dates and a hash using them # as keys to hash values of 'Mon Jan 6' format. # If one week, then just 5 values, if two wk then 10, etc. for (1..$weeks){ for ( 1..5 ){ my ($yr,$mon,$day) = inverse_julian_day($jd); my $dow = day_of_week($jd) + 1; push @days, "$yr-$mon-$day"; $datedata{"$yr-$mon-$day"} = "$dow[$dow], $month[$mon] $day"; $jd++; } $jd = $jd + 2; # skip over weekend. } } #---------------- sub showStartPage { #---------------- print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
". $lex{'Select by'}. "\n"; print "\n"; print " "; # print $lex{'Separate with Spaces'}. q{, } # save for later. print $lex{'Blank=All'}. "
". $lex{Mode}. "\n"; print "
\n"; print "
\n"; print "\n"; exit; }