#!/usr/bin/perl -w use CGI qw(:standard -debug); use CGI::Carp qw(fatalsToBrowser); use Time::Local; ########## credits ################## # Created by Todd Vandenbark # ###################################### #----------- define variables ---------- my $idnum; # ID received from form my $form1; # input form my $sessnfile; # text file of study sessions my @sessions=""; # study sessions to search my @results=(); # matching sessions found my $totalhrs=0; # total hours studied $baseurl="http://studylog.firesidelibrarian.com/code/cgi"; $logo = ''; # ---- get info from form $form1 = 'findstudent.cgi'; $student = param("student"); ($idnum, $username, $first, $last, $org, $session) = split(/:/, $student); # ---- check for missing input ---- # if (!$student) { # none selected $title = 'oops...'; $subtitle = 'Missing input'; $content = '

Please select a student from the list.

' . "\n" . '

Back to list.

' . "\n"; &pgprint(); exit; } # ---- open input file of study sessions -- $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 ($idnum 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 Log report by student'; $subtitle = "Total hours: $totalhrs"; print header(); print start_html(-title => $title, -head => $css, -class => 'oneColFixCtrHdr'); print '
' . "\n"; print '
' . "\n"; print h2("$subtitle"); print "\n"; # ---- print table of data ---- print qq{ }; # ---- end qq ---- # ---- print study sessions ---- foreach $key (@results) { # print table rows 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 $idnum"); print p("User your browser's print function to print this report."); print p("Generate another report.."); print <
Report a problem.
Main menu. Help function EOF # ---- 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"); } # ------ print error page ------- sub pgprint { my $css = ''; print header(-cookie => [$cookie_user, $cookie_pwd]); print start_html (-title => $title, -head => $css, -class => 'oneColFixCtrHdr'); print '
' . "\n"; print '
' . "\n"; print h2("$subtitle"); print "$content \n"; print <
Report a problem.
Help function EOF # ---- print footer ---- print '
'. "\n" . ''. "\n" . '
'; print end_html } # ------ end sub --------