#!/usr/bin/perl -w # AUTHORS # Sean Forman # Hans Van Slooten # $Date: 2017-04-05 17:01:54 -0400 (Wed, 05 Apr 2017) $ # $Author: hvs $ # $Rev: 50641 $ # $HeadURL: http://svn.sports-reference.com/svn/br_repos/br/trunk/teams/scripts/tgl.cgi $ # Copyright 2000-2017, SPORTS REFERENCE, INC. All rights reserved. use Carp; use CGI::Fast qw(:standard); use FindBin qw($Bin); use Modern::Perl '2010'; use lib "$Bin/../lib"; use SR::Defaults; use SR::Statline; use SRlocal::Constants; use SRlocal::DB; use SRlocal::Formatting; use SRlocal::GenTemplate; use SRlocal::Stats; use SRlocal::Teams; use SRlocal::Teams::Fetch; use SRlocal::Teams::Model; use SRlocal::Templates; chomp($0); MAIN: { # Connect to the database. our $dbh = get_site_db_connection($Bin); $dbh->{mysql_auto_reconnect} = $TRUE; our $site_params_ref = get_site_params($Bin); our $srtemplates = new SRlocal::Templates; ##################################################################################### # Check to see if they want the highlighting checked or not. LOOPER: while ( my $q = new CGI::Fast ) { my $shared_value = $q->param('share'); # Determine if we have a batting, fielding, or pitching gamelog, # batting is default. my ( $log_type, $log_type_long, $team_id, $log_type_name, $log_type_dir, $table_id, ); if ( is_nonempty_print( $q->param('t') ) eq 'p' ) { $table_id = 'pitching_gamelog'; $log_type = 'p'; $log_type_long = 'pitch'; $team_id = $q->param('team') ? $q->param('team') : 'PHI'; $log_type_name = 'Pitching'; $log_type_dir = 'pitch/'; } elsif ( is_nonempty_print( $q->param('t') ) eq 'f' ) { $table_id = 'fielding_gamelog'; $log_type = 'f'; $log_type_long = 'field'; $team_id = $q->param('team') ? $q->param('team') : 'PHI'; $log_type_name = 'Fielding'; $log_type_dir = 'field/'; } else { $table_id = 'batting_gamelog'; $log_type = 'b'; $log_type_long = 'bat'; $team_id = $q->param('team') ? $q->param('team') : 'PHI'; $log_type_name = 'Batting'; $log_type_dir = 'bat/'; } my $is_postseason_log = $q->param('post'); $log_type_long .= '-post' if ($is_postseason_log); ######## CUSTOMIZE # for the year, we use the one given or the player's last year if # none if given. If a year is less than the first retro year, we # then use the first retro year. my $year_id = $q->param('year') ? $q->param('year') : $CURRENT_YEAR; # validate year. $year_id = $CURRENT_YEAR if $year_id !~ /^[1-2][0-9]{3}$/; $year_id = $year_id < $FIRST_YEAR_RETRO ? $FIRST_YEAR_RETRO : $year_id; $year_id = '' if ($is_postseason_log); # this is needed for the js to work for guys like O'Neill. my $sth = fetch_teams( $dbh, { team_id => $team_id, year => $year_id } ); my $row = $sth->fetchrow_hashref; while ( $row && $sth->fetchrow_hashref ) { ## Should only be one, but loop to clear out the resultset just in case. } if ( !$row ) { print $q->redirect('/404.html'); next; } my $team_name = $row->{name}; my $team_link = sprintf qq{/teams/%s/%s.shtml}, $team_id, $year_id; ##################################################################################### my $page_title = ( $is_postseason_log ? 'Postseason ' : '' ) . $log_type_name . ' Gamelogs'; my $you_are_here_array = [ qq{Teams}, qq{$year_id $team_name}, qq{$page_title} ]; my $url = '/gl/teams/' . $team_id . '/' . $log_type_dir . $year_id . '.htm'; my %model; $model{team_id} = $team_id; $model{year_id} = $year_id; $model{bio} = { data => $row }; $model{nick} = $row->{nickname}; #$model{active} = $tmp->{active}; ## Hack for menu #$model{bio} = { is_active => $model{active} eq 'Y' }; #$model{NA_assoc} = $tmp->{NA_assoc}; $model{pagecontent} = []; ## Define the site header values within a hash and send the ## hash to the header script. $model{header} = { page_title => $year_id . ' ' . $team_name . ' ' . $page_title, page_url => $SRlocal::Constants::SITE_URL . "/teams/tgl.cgi?team=$team_id&t=$log_type&year=$year_id", you_are_here => generate_you_are_here($you_are_here_array), qi_section => 'teams', use_default_keywords => $FALSE, page_description => $year_id . ' ' . $team_name . ' ' . $page_title, }; build_team_summary_model( $dbh, $srtemplates, \%model, $log_type . 'gl' ); ## Build the innernav for this franchise $model{inner_nav} = build_team_menu( $dbh, \%model, $log_type_long, $model{year_id} ); my $javascript = my $onload = $EMPTY_STR; ## Build up the file name. my $file = $site_params_ref->{site_root_dir} . $url; ## Load the gamelog from disk if ( open( my $FH, '<', $file ) ) { my $gl = ''; while (<$FH>) { $gl .= $_ } close($FH); ## Display the gamelog push @{ $model{pagecontent} }, $gl; } else { push @{ $model{pagecontent} }, qq{
No Data for this season, Sorry!
\n}; } # Add the tips and tricks to the bottom (not for fielding because no row summing) push @{ $model{pagecontent} }, html_get_rowsum_tricks_note($srtemplates); # Generate the page. my $output = $srtemplates->process( 'Pages/Team.tt2', \%model ); # Display the page the user. print "CONTENT-TYPE:text/html\n\n"; print $output; } $dbh->disconnect; }