#!/usr/bin/perl use strict; use warnings; use DBI; use Time::Format qw(%time time_format %strftime %manip); use Data::Dumper; use Skidmore::Utils qw(setOracleEnv); # -- call sub to set Oracle env so script can run as cronjob &setOracleEnv; # -- define outfile my $htmlout = "/www/includes/lib_except_hours.html"; # -- connection info for db my ($voy_dsn,$voy_dbun,$voy_dbpass) = ( 'dbi:Oracle:***','***','***' ); # -- connect to db my $dbh = DBI->connect( $voy_dsn,$voy_dbun,$voy_dbpass, { AutoCommit => 0, RaiseError => 0, PrintError => 1 } ) || die $DBI::errstr; # -- query to get exception dates for the semester my $sql = qq(select TO_CHAR (exception_date, 'DY/MM/DD/YYYY'), exception_openhour, exception_closehour, CASE when UPPER(Exception_open) = 'N' THEN 'Closed' END AS Closed FROM exception_calendar); my $sth = $dbh->prepare( $sql ); $sth->execute or die $DBI::errstr; # -- fetch all data and create var to refer to my $arrayref_exc_dates = $sth->fetchall_arrayref(); # -- hash to store found exception dates my %fnd_excep = (); # -- loop thru the exception data from Voyager table foreach my $row ( @$arrayref_exc_dates ) { my ( $exception_date,$exception_openhour,$exception_closehour ) = @$row; if ( not defined $exception_openhour ) { $exception_openhour = "closed" } if ( not defined $exception_closehour ) { $exception_closehour = "closed" } } # -- uncomment this for testing #print Data::Dumper->Dump([%fnd_excep]); $sth->finish; $dbh->disconnect; # -- store html in here my $content; # -- begin html code $content = qq(
); $content .= qq(
| Day/Date | Times | ); # -- store exception hours in here my %except_hrs = (); # -- now we can figure out the hours to use and create the table rows for my $key ( sort keys %fnd_excep ) { # -- date in exception hash so use exception data # -- use sub to format time if ( exists $fnd_excep{$key} ) { $fnd_excep{$key}{open} = format_time( $fnd_excep{$key}{open} ); $fnd_excep{$key}{close} = format_time( $fnd_excep{$key}{close} ); # -- date not in exception hash so use normal hours } else { $fnd_excep{$key}{open} = format_time( $except_hrs{$key}{open} ); $fnd_excep{$key}{close} = format_time( $except_hrs{$key}{close} ); } ## end exception open/closed if # -- let's write the table rows if ( $fnd_excep{$key}{open} eq 'closed') { $content .= "
| $fnd_excep{$key}{day_text} | Closed |
| $fnd_excep{$key}{day_text} | $fnd_excep{$key}{open} - $fnd_excep{$key}{close} |