#!/usr/bin/perl -w use CGI qw(:standard -debug); use CGI::Carp qw(fatalsToBrowser); use Time::localtime; ########## credits ################## # Created by Todd Vandenbark # ###################################### #----------- define variables ---------- @results=(); # search results @orgs=(); # list of Greek organizations # ---- get info from form -------- # $form1 = 'orgreport.cgi'; $semester = param("semester"); $orgzn = param("orgzn"); $orgzn =~ s/_/ /g; # ---- open input file of organizations --- $orgfile = '../../org.txt'; open (IN, $orgfile) || die "Can't open $orgfile: $!\n"; @orgs = ; chomp @orgs; close IN; # ---- open input file of students ------- $studentf = '../../student.txt'; open (IN2, "$studentf") || die "Can't open $studentf: $!\n"; @students = ; chomp @students; close IN2; # ---- open input file of study sessions -- $sessnfile = '../../session.txt'; open (IN3, "$sessnfile") || die "Can't open $sessnfile: $!\n"; @sessions = ; # read in all sessions chomp @sessions; close IN3; # ---- find students ---- foreach $key (@students) { ($id, $username, $first, $last, $org, $session) = split(/:/, $key); if ($orgzn eq $org) { # if student in organization $totalhrs = &matchsess($semester,$id); $member = join(":", $last, $first, $totalhrs); push (@results, $member); } # -- end if -- } # -- end foreach -- # ---- print to screen ---- my $css = ''; my $title = 'Study Log Report'; print header(); print start_html(-title => $title, -head => $css, -class => 'oneColFixCtrHdr'); print '
'; print '
'; # ---- print table of data ---- print qq{ }; # ---- end qq ---- # ---- print study sessions ---- foreach $key (@results) { my ($last, $first, $totalhrs) = split (/:/, $key); $totalhrs = sprintf("%.2f", $totalhrs); print qq{ }; # ---- end qq ---- } # ---- end foreach ---- print '
Last Name First Name Total hours
$last $first $totalhrs
'; # ---- print summary ---- print p("User your browser's print function to print this report."); print p('Print another.'); print <
Report a problem.
Main menu. Help function EOF # ---- print footer ---- print '
'. ''. '
'; print end_html; # ---- find matching sessions ------------- # arg1 = semester # arg2 = student ID# # r.v. = total hours the student studied # ----------------------------------------- sub matchsess { my $subtot=0; my $totalhrs=0; # -- define variables -- my $sem = $_[0]; my ($beginsem,$endsem) = split(/_/,$sem); my $idnum = $_[1]; foreach $key (@sessions) { ($idnum2,$start,$end,$duration) = split (/:/, $key); if ($idnum eq $idnum2) { # if found matching record if ( ($start > $beginsem) && ($end < $endsem) ) { # if in date range $subtot = $duration/(60*60); $totalhrs += $subtot; } } # ---- end if } # ---- end foreach return $totalhrs; } # --- end sub #------------------------------------- # 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"); }