#!/usr/bin/perl use DBI; #use CGI qw/:standard/; #use Carp::Heavy; #use LWP::Simple; my $cgiparam ; my $database = "tvguide"; my $hostname = "localhost"; my $user = "*****"; my $password = "*****"; my $driver = "mysql"; my $dsn = "DBI:$driver:database=$database;host=$hostname"; my $dbh ; my $palm = "false" ; sub PrintMyTVListings(){ $cgiparam = shift; $dbh = DBI->connect($dsn, $user, $password); #TrimTable(); if ($cgiparam->param()) { if( $cgiparam->param("type") eq "GetListings" ) { PrintTop(); GetListings("Now"); } else { if( $cgiparam->param( "type" ) eq "GetSelectedListings" ) { PrintTop(); GetListings( "Selected", $cgiparam->param("SelectedDate"), $cgiparam->param("SelectedTime")); } else { if( $cgiparam->param( "type" ) eq "PayPerView" ) { PrintTop(); PayPerView("Now"); } else { if ( $cgiparam->param( "type" ) eq "PalmDetails" ) { $palm = "true" ; Palm( "Selected", $cgiparam->param("SelectedDate"), $cgiparam->param("SelectedTime")); } else { if ( $cgiparam->param( "type" ) eq "Palm" ) { $palm = "true" ; PalmPrep(); } else { PrintTop(); GetListings("Now"); } } } } } } else { PrintTop(); GetListings("Now"); } if( $palm eq "true" ) { PrintBottomPalm(); } else { PrintBottom(); } } sub Palm(){ PrintTopPalm( @_ ); GetListings("Selected", @_[1], @_[2] ); } sub PrintTopPalm() { my $Date = @_[1]; my $Time = @_[2]; print "$Time\n"; print < CnlTtlLen EOF } sub PalmPrep() { my $sth_statement = "SELECT DISTINCT DATE_FORMAT( start_date, '%Y-%m-%d') FROM programme"; my $sth = $dbh->prepare($sth_statement); $sth->execute(); while ( my @row = $sth->fetchrow_array ) { my $DTwjm = @row[0]; print ""; print "
"; foreach( '08', '09', 10...23 ) { print "" ; my $hr = $_; my $hrdisplay = $hr - 0; my $ampm = "AM" ; if( $hr > 11 ) { if( $hr > 12 ) { $hrdisplay = $hr - 12; } $ampm = "PM" ; } foreach( "00", "30" ) { print "" ; } print "" ; } print "
$DTwjm
" ; print '' . $hrdisplay . ':' . $_ . ' ' . $ampm . '
'; print "
"; } } sub PrintBottomPalm(){ print < EOF } sub GetListings() { my $Type = @_[0]; my $DTwjm = "NOW()"; if( $Type eq "Now" ) { $DTwjm = "NOW()"; } else { my $Date = @_[1]; my $Time = @_[2]; $DTwjm = "'" . $Date . ' ' . $Time . "'"; } PopulateHListStyle( "SELECT DISTINCT channel.id, TIME_FORMAT(start_date, '%I:%i') , programme.title, sub_title, star_rating, length, desc_str, channel.iconurl, programme.uniquenum, channellike.id, hatedcategories.category, hatedprograms.title FROM programme LEFT OUTER JOIN channel ON programme.channel_no = channel.channelnum LEFT OUTER JOIN channellike ON channel.id = channellike.id LEFT OUTER JOIN hatedcategories ON programme.category = hatedcategories.category LEFT OUTER JOIN hatedprograms ON programme.title = hatedprograms.title WHERE START_DATE < DATE_ADD( $DTwjm, INTERVAL '14:00' MINUTE_SECOND ) AND (( TIME_TO_SEC( $DTwjm ) - TIME_TO_SEC( START_DATE ) ) / 60 ) < 20 AND STOP_DATE > $DTwjm AND channel not like '2__ %' ORDER BY channel.channelnum" ); } sub PayPerView() { my $Type = @_[0]; my $DTwjm = "NOW()"; if( $Type eq "Now" ) { $DTwjm = "NOW()"; } else { my $Date = @_[1]; my $Time = @_[2]; $DTwjm = "'" . $Date . ' ' . $Time . "'"; } PopulateHListStyle( "SELECT DISTINCT channel.id, TIME_FORMAT(start_date, '%I:%i') , programme.title, sub_title, star_rating, length, desc_str, channel.iconurl, programme.uniquenum, channellike.id, hatedcategories.category, hatedprograms.title FROM programme LEFT OUTER JOIN channel ON programme.channel_no = channel.channelnum LEFT OUTER JOIN channellike ON channel.id = channellike.id LEFT OUTER JOIN hatedcategories ON programme.category = hatedcategories.category LEFT OUTER JOIN hatedprograms ON programme.title = hatedprograms.title WHERE START_DATE < DATE_ADD( $DTwjm, INTERVAL '14:00' MINUTE_SECOND ) AND (( TIME_TO_SEC( $DTwjm ) - TIME_TO_SEC( START_DATE ) ) / 60 ) < 20 AND STOP_DATE > $DTwjm AND channel like '2__ %' ORDER BY channel.channelnum" ); } sub PopulateHListStyle { my $sth_statement = @_[0]; # print $sth_statement; my $sth = $dbh->prepare($sth_statement); $sth->execute(); while ( my @row = $sth->fetchrow_array ) { my $title = @row[2] ; $title = $title . '-' . @row[3] if ( @row[3] ne '' ); my $line = @row[1]; $line =~ s/[0-9][0-9][0-9][0-9]-[01][0-9]-[0-9][0-9] ([0-9][0-9]:[0-9][0-9]):00.000/$1/g; my $style = 'normal'; if( @row[5] > 60 ) { $style = 'movie'; } #$style = 'preferred'; my $ilike = "ILike"; if( @row[9] eq '' ) { $ilike = "IHate"; } if( @row[10] ne '' ) { $ilike = "IHate"; } if( @row[11] ne '' ) { $ilike = "IHate"; } printf "", $ilike; if( $palm eq "false" ) { if( @row[7] eq '' ) { printf " ", $style, @row[7] ; } else { printf " ", $style, @row[7] ; } } printf "%s ", $style, @row[0] ; if( $palm eq "false" ) { printf "%s ", $style, $line ; } if( @row[6] eq '' ) { printf "%s ", $style, $title ; } else { printf "%s ", $style, $cgiparam->escapeHTML(@row[6]), @row[8], $title ; } if( $palm eq "false" ) { printf "%s ", $style, @row[4] ; } printf "%s", $style, @row[5] ; print "\n"; } } sub PrintTop() { print < tr.ILike { } tr.IHate { display: none } EOF } sub PrintBottom() { print <
ChannelTimeTitleRatingLength
View Only: EOF print < EOF my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); my $DTwjm = ( 1900 + $year ) . "-" . ( $mon + 1 ) . "-" . $mday; print "$DTwjm
"; foreach( '08', '09', 10...23 ) { my $hr = $_; foreach( "00", "30" ) { print "" . $hr . ':' . $_ ; } } print <
EOF } sub GenerateOptions() { my $sth_statement = @_[0]; my $sth = $dbh->prepare($sth_statement); $sth->execute(); while ( my @row = $sth->fetchrow_array ) { printf "