#!/usr/bin/perl -w #--------------------------------------------------------------- # Study Log: Tally CGI # By Todd Vandenbark and modified by Crystal White # April 4, 2009 (last modified April 26, 2009) # Task: # -to check for the ID in a file # -to check get the epox time and duration of the study sessions # -to print a page with the information from the file # -Direct back to the Main Menu Page # -use cookies to maintain the state of pages # Input: ID Number # Output: Page with start date, start time, end date, end time, and duration of study sessions #--------------------------------------------------------------- use CGI qw(:standard -debug); use CGI::Carp qw(fatalsToBrowser); use Time::Local; # retrieve cookie $cookiedata=cookie('id'); # HTML forms $form1 = "http://studylog.firesidelibrarian.com/cgi/confirmHouse.cgi"; # File for Student Information $stf= "../student.txt"; # ---- open input file of student information -- if (-r $stf) { # read in file open(IN,$stf) || die "can't read $stf"; @sts = ; close IN; chomp @sts; # %pws : key=ID, value=name foreach $key (@sts) { ($idnum,$user,$first,$last,$session) = split(/:/,$key); } # end foreach } # ---- open input file of studysessions -- $sessnfile = '../session.txt'; open (IN, "$sessnfile") || die "Can't open $sessnfile: $!\n"; @sessions = ; # read in all sessions close IN; # ---- find matching sessions ---- foreach $key (@sessions) { ($idnum2,$start,$end,$duration) = split (/:/, $key); if ($cookiedata eq $idnum2) { # if found matching record $subtot = $duration/(60*60); $subtot = sprintf("%.2f", $subtot); $totalhrs += $subtot; ($stdydate,$begin)=&datetime($start); ($endstudy,$ended)=&datetime($end); $string = join ("_", $stdydate,$begin,$endstudy,$ended,$subtot); $string .= "\n"; push (@results, $string); } # ---- end if } # ---- end foreach # ---- print to screen ---- my $css = ''; my $title = 'Study Session Tally'; print header(); print start_html(-title => $title, -head => $css,); print '
' . "\n"; print '
' . "\n"; # ---- print table of data ---- print qq{ }; # ---- end qq ---- # ---- print study sessions ---- foreach $key (@results) { my ($date2s,$stime,$date2e,$etime,$duration2) = split (/_/, $key); print qq{ }; # ---- end qq ---- } # ---- end foreach ---- print '
Start date Start time End date End time Duration
$date2s $stime $date2e $etime $duration2
'; # ---- print summary ---- $totalhrs = sprintf("%.2f", $totalhrs); print p("$last, $first total study hours: $totalhrs"); print p("Student ID $cookiedata"); print p("User your browser's print function to print this report."); print qq|Back to Main Login|; # ---- print footer ---- print '
'. "\n" . ''. "\n" . '
'; print end_html; #------------------------------------- # get timestamp #------------------------------------- # arg1 = epoch time # r.v. = ("MM-DD-YY","HH:MN:SS") #------------------------------------- sub datetime { my($time)=@_; my ($ss,$mn,$hh,$dd,$mm,$yy,$wkd,$yrd,$isdl) = localtime($time); # month goes from 0 to 11 $mm= $mm+1; # convert to 4 digit year my $yy2= $yy+1900; # put leading zeros foreach ($ss,$mn,$hh,$dd,$mm) { $_= sprintf("%02d",$_); } return ("$yy2-$mm-$dd","$hh:$mn:$ss"); }