<% # Daily.pl # provides a connection to a MySQL backend where daily announcements # are stored; time format is epoch # # version history # 2.00 - added ability to look through archives 02.28.00 # 1.00 - first release 01.09.00 # # (c) 2000 Jason Surovy; 01/09/00 Undistributable license. # Cannot be altered in anyway without consent of author. use DBI; use Date::Calc qw(:all); use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); my $query = new CGI; my @days = qw:Error Mon Tue Wed Thur Fri Sat Sun:; my @months = qw:Error Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec:; my %monthToNum = ( 'Jan' => '01', 'Feb' => '02', 'Mar' => '03', 'Apr' => '04', 'May' => '05', 'Jun' => '06', 'Jul' => '07', 'Aug' => '08', 'Sep' => '09', 'Oct' => '10', 'Nov' => '11', 'Dec' => '12', ); my %numToMonth = ( '1' => 'January', '2' => 'February', '3' => 'March', '4' => 'April', '5' => 'May', '6' => 'June', '7' => 'July', '8' => 'August', '9' => 'September', '10' => 'October', '11' => 'November', '12' => 'December', ); $action = param('action') || "default"; # what we're going to do $id = param('id'); #true if looking at an archive $status = param('status'); # status - error code (if any) # define constants $font = 'font face="arial,helvetica" size="-1"'; $fontbig = 'font face="arial,helvetica"'; $fontsmall = 'font face="verdana,arial,helvetica" size="-2"'; $home = "/daily/default.asp"; # location of us! my %states = ( 'default' => \&home, 'home' => \&home, 'archive' => \&archive, ); # see if we can process $action die "No routine for action $action" unless $states{$action}; $dailydb = DBI->connect('DBI:mysql:dailydb:localhost:3306', 'jason', 'tnox'); print $query->header(); if ($states{$action}) { $states{$action}->(); } else { no_such_page(); } print ""; print &loadssi('/hfs/www2.mhs.k12.oh.us/nav.ssi'); print &loadssi('/hfs/www2.mhs.k12.oh.us/navend.ssi'); sub loadssi { my $file = $_[0]; open(SSI, "<$file"); my @slurp = ; close(SSI); return @slurp; } sub home { my $sth = $dailydb->prepare("SELECT id FROM daily ORDER BY date DESC"); $sth->execute(); my $getDay = $sth->fetchrow_hashref; $sth->finish; my $sth = $dailydb->prepare("SELECT * FROM daily WHERE id=$getDay->{id}"); $sth->execute(); my $result = $sth->fetchrow_hashref; &dailyparse($result); &archiveList($result->{date}); } sub archive { my $sth = $dailydb->prepare("SELECT * FROM daily WHERE id=$id"); $sth->execute(); my $result = $sth->fetchrow_hashref; &dailyparse($result); &archiveList($result->{date}); } sub dailyparse { my $rec = $_[0]; $rec->{text} =~ s/\n/

\n/g; #$input =~ s/SCHOLARSHIPS (more information available in A-19)/ Scholars my $date = &epochToReal($rec->{date}); print qq` Daily Announcements for $numToMonth{$date->{month}} $date->{day}, $date->{year} `; print &loadssi('/hfs/www2.mhs.k12.oh.us/header.ssi'); print '
'; print &loadssi('/hfs/www2.mhs.k12.oh.us/headerClose.ssi'); print "

"; print qq`
<$fontsmall>Email Subscriptions
<$fontsmall> Subscribe to Mentor High's email notification service to receive the latest Mentor High sport scores, scholarship information from Room A-19, and the Daily Morning Announcements via email.
Sports Update
A-19 Scholarships
Daily Announcements
<$font>Announcements for $numToMonth{$date->{month}} $date->{day}, $date->{year}

<$font>$rec->{text} `; } sub archiveList { my $date = $_[0]; # we receive an epoch date, which well look for by # minus-ing and adding a week to the date to obtain a search range my $begin = $date-604800-10; #seconds in a week my $end = $date+604800+10; #the 10 seconds is to make sure we hit any days on number print qq`


<$font>Daily Announcement Archives
`; $sth = $dailydb->prepare("SELECT id,date FROM daily WHERE date>$date GROUP BY DATE DESC LIMIT 5"); $sth->execute(); print qq` `; } sub printRes { my $result = $_[0]; my $realdate = &epochToReal($result->{date}); if ($id == $result->{id}) { print qq`
  • $numToMonth{$realdate->{month}} $realdate->{day}, $realdate->{year} (viewing) `; } else { print qq`
  • $numToMonth{$realdate->{month}} $realdate->{day}, $realdate->{year} `; } } sub epochToReal { my ($sec,$min,$hrs,$day,$mon,$year) = localtime($_[0]); my $time = {'year' => $year+1900, 'month' => $mon+1, 'day' => $day, 'hour' => $hrs, 'min' => $min, 'sec' => $sec, }; return $time; } %>