#!/bin/env perl # AUTHORS # Sean Forman # Hans Van Slooten # $Date $ # $Author $ # $Rev $ # Copyright 2000-2016, SPORTS REFERENCE, LLC All rights reserved. # Get the site lib directory. use FindBin qw($Bin); use lib "$Bin/../lib"; use Carp; use FindBin qw($Bin); use Modern::Perl '2010'; use Smart::Comments '####'; use lib "$Bin/../lib"; use SR::Defaults; use SR::Statline; use SRlocal::Constants; use SRlocal::DB; use SRlocal::Formatting; use SRlocal::Leagues; use SRlocal::Stats; use SRlocal::Templates; chomp($0); #### [] Starting: "$Bin/$0 " . join(' ',@ARGV) MAIN: { # Connect to the database. our $dbh = get_site_db_connection($Bin); our $site_params_ref = get_site_params($Bin); my $srtemplates = new SRlocal::Templates; ##################################################################################### ##################################################################################### my $q = new CGI; my $day, my $month, my $year; if ( $q && ( defined $q->param('date') && $q->param('date') =~ /([0-9]+).([0-9]+)/ ) ) { $day = $2; $month = $1; $year = 105; } elsif ($q && is_nonempty_print( $q->param('day') ) =~ /[^0-9]/ || $q->param('month') =~ /[^0-9]/ || $q->param('day') !~ /[0-9]/ || $q->param('month') !~ /[0-9]/ || !$q->param('day') || !$q->param('month') ) { ( $day, $month, $year ) = (localtime)[ 3, 4, 5 ]; $month++; } else { ( $day, $month, $year ) = ( $q->param('day'), $q->param('month'), (localtime)[5] ); } our $date_text = convert_sql_date_to_full_date( ( $year + 1900 ) . '-' . $month . '-' . $day, { exclude_year => $TRUE } ); my $page_title = sprintf qq{Players born on %s}, $date_text; my $yah = generate_you_are_here( [ qq{Frivolities}, qq{$page_title} ] ); # Build the page start my %model; $model{header} = { page_title => $page_title, you_are_here => $yah, qi_section => 'friv', page_url => $SRlocal::Constants::SITE_URL . '/friv/birthdays.cgi', use_default_keywords => $FALSE, page_label => $page_title, page_description => $page_title, #og_image => get_headshot_image($player_id, $site_params_ref), #og_type => 'Athlete', }; # Start the page_content div. $model{inner_nav} = [ { index => $TRUE, label => "Frivolities Index", link => "/friv/" } ]; ##################################################################################### push @{ $model{pagecontent} }, _get_other_days( $dbh, $srtemplates, '1904-' . $month . '-' . $day ); push @{ $model{pagecontent} }, _get_other_dates_header( $srtemplates, $month, $day ); my $query = <<"END_SQL"; SELECT bio.player_ID, $defn_of_statlines{player_name}{select}, $defn_of_statlines{multi_general_summary}{select}, $defn_of_statlines{multi_player_season_simple}{select}, birth_year FROM bio INNER JOIN players USING (player_ID) LEFT JOIN career_batting AS a USING (player_ID) LEFT JOIN career_pitching AS b USING (player_ID) WHERE birth_day=? AND birth_month=? AND (a.age IS NULL OR a.age=0) AND (b.age IS NULL OR b.age=0) ORDER BY birth_year DESC END_SQL my @stats = ( qw(ranker player birth_year), @{ $defn_of_statlines{multi_general_summary}{list} }, @{ $defn_of_statlines{multi_player_season_simple}{list} }, qw(franchises) ); $STATLINE_DEFAULTS{franchises}{justify} = 'left'; # Prepare and execute the query. my $sth = $dbh->prepare($query); #### Preparing Query $sth->execute( $day, $month ) || croak( "Query: Explain\n $query\n\n failed: " . $dbh->errstr . "\n\n" ); #### Executing Query my $output = ''; # See if our query returned any rows. If it didn't, we're done. if ( $sth->rows ) { my $table_id = 'birthday_stats'; my %table_defn = ( table_id => 'birthday_stats', title => 'Players Born On ' . $date_text, comment_by_default => $FALSE, table_cols_to_freeze => 2 ); # We have some rows, so moving on... # Use Statline to start the table and get the table header. $output .= generate_statline_header_wrap( \%table_defn ); $output .= generate_statline_header( \@stats ); my $line_count = 0; # Loop through the query results. while ( my $tmp = $sth->fetchrow_hashref ) { $tmp->{franchises} = gtrc( $dbh, 'majors_appearances INNER JOIN majors_team USING (year_ID, team_ID)', { 'majors_appearances.player_ID' => $tmp->{player_ID} }, 'GROUP_CONCAT(distinct franch_ID)' ); $line_count++; $tmp->{ranker} = $line_count; # Use Statline to add the season stat lines. $output .= generate_statline( \@stats, $tmp ); } # We're done with the season stats. $sth->finish; #### Query Finished $output .= generate_statline_footer_wrap( \%table_defn ); push @{ $model{pagecontent} }, $output; } my $content = $srtemplates->process( 'Pages/General.tt2', \%model ); print $q->header; print $content; } ################################################################### # Usage : zzzz # Purpose : zzzz # Returns : zzzz # Parameters : zzzz # Throws : zzzz # See Also : zzzz # Comments : zzzz ################################################################### sub _get_other_dates_header { my ( $srtemplates, $month, $day ) = @_; my $output = ''; my @months = map { { val => $_, label => $MONTH_NAMES{$_} } } sort keys %MONTH_NAMES; my %form_params = ( method => 'get', action => 'birthdays.cgi', id => 'birthdays', class => 'no_chosen', linear => $TRUE, fields => [ { label => 'Month', name => 'month', type => 'dropdown', choices => \@months, default => $month, }, { label => 'Day', name => 'day', type => 'dropdown', start => 1, end => 31, default => $day }, { type => 'submit', val => 'Find Birthdays' } ] ); my $form_template = $srtemplates->process( 'Partials/Forms/Form.tt2', \%form_params ); $output .= $form_template; # Add a link to see today's birthdays. if ( $month != (localtime)[4] + 1 || $day != (localtime)[3] ) { $output .= qq{(See today's birthdays)}; } return output_content_section( { srtemplates => $srtemplates, content => $output } ); } ################################################################### # Usage : zzzz # Purpose : zzzz # Returns : zzzz # Parameters : zzzz # Throws : zzzz # See Also : zzzz # Comments : zzzz ################################################################### sub _get_other_days { my ( $dbh, $srtemplates, $day ) = @_; my $query = <<"END_SQL"; SELECT DATE_FORMAT("$day", "%M %e") as name_today, DATE_FORMAT(DATE_SUB("$day", INTERVAL 1 DAY), "%M %e") as name_yesterday, DATE_FORMAT(DATE_ADD("$day", INTERVAL 1 DAY), "%M %e") as name_tomorrow, DATE_FORMAT(DATE_ADD("$day", INTERVAL 1 DAY), "%m-%d") as value_tomorrow, DATE_FORMAT(DATE_SUB("$day", INTERVAL 1 DAY), "%m-%d") as value_yesterday END_SQL # print stderr "$query\n"; my $sth = $dbh->prepare($query); $sth->execute; my $tmp = $sth->fetchrow_hashref; my $name_today = $tmp->{name_today}; my $name_yesterday = $tmp->{name_yesterday}; my $name_tomorrow = $tmp->{name_tomorrow}; my $value_tomorrow = $tmp->{value_tomorrow}; my $value_yesterday = $tmp->{value_yesterday}; $sth->finish; my $prevnext = { prev => { link => qq{/friv/birthdays.cgi?date=$value_yesterday}, label => $name_yesterday }, next => { link => qq{/friv/birthdays.cgi?date=$value_tomorrow}, label => $name_tomorrow } }; my $nav = $srtemplates->process( 'Partials/ContentSection/PrevNext.tt2', $prevnext ); return $nav; }