#!/usr/bin/perl -w # Sean Forman # sean-forman@sports-reference.com # $Date $ # $Author $ # $Rev $ # Copyright 2000-2014, SPORTS REFERENCE, LLC All rights reserved. # Get the site lib directory. use FindBin qw($Bin); use lib "$Bin/../lib"; # Change this to just three hashes to show all debugging. Comment out # to drop comments from output. #use Smart::Comments '####'; use Carp; use CGI; # Connect to our login info use SR::Defaults; use SR::Statline; use SR::Auth::Users; use SR::Auth::Sponsor; # Include our local and global SR modules. use SRlocal::DB; use SRlocal::Constants; use SRlocal::Stats; use SRlocal::Templates; use Data::Dumper; use SRlocal::PlayIndex; #use SRlocal::PlayIndex::Subscribe; use SRlocal::PlayIndex::Constants; use SRlocal::PlayIndex::Statdefine; chomp($0); #### [] Starting: "$Bin/$0 " . join(' ',@ARGV) MAIN: { my $q = new CGI; print $q->header( -charset => 'utf-8' ); # make connections our $dbh = get_site_db_connection( $Bin, $SRlocal::PlayIndex::Constants::PI_DSN ); our $dbhSR = get_site_db_connection( $Bin, 'SR' ); our $site_params_ref = get_site_params($Bin); our $srtemplates = new SRlocal::Templates; ################################################################## # Get our data out and set up our request. ################################################################## our %user = (); if ( $ENV{'HTTP_COOKIE'} ) { %user = %{ SR::Auth::Users::get_user($q) }; } # my $sub_level = SRlocal::PlayIndex::Subscribe::subscriber_level( $dbhSR, # $user{user_ID}, 'pi_subscribe' ); my %sub_info = %{ SR::Auth::Sponsor::pi_sub_info($user{user_ID}) }; # $sub_info{level} = $sub_level; # $sub_info{level_desc} = SRlocal::PlayIndex::Subscribe::subscriber_level_desc{$sub_level}; my %model = (); my $you_are_here = generate_you_are_here( [ q{Play Index}, q{Home}, ] ); $model{header} = { page_title => 'Play Index Home', page_url => $SRlocal::Constants::SITE_URL."/play-index/", page_description => 'List of all Play Index searches users can do', you_are_here => $you_are_here, qi_section => "amateurs", }; # Header, body, footer. # print SRlocal::PlayIndex::Formatting::generate_play_index_header( # $user{user_ID}, # $sub_level, # { site_root_dir => $site_params_ref->{site_root_dir}, # javascript => $js, # onload => $onload, # page_title => $title, # dbh => $dbhSR, # show_js => $TRUE, # use_front_container => $TRUE, # } # ); ################################################################## ################################################################### # # put in the page logic. # # we are asking to delete a saved report. if ( is_empty_zero( $q->param('delete') ) ) { _delete_report( $dbh, { linkID => $q->param('delete'), user => $user{user_ID}, } ); } my $user_saved_queries_html = $EMPTY_STR; if ($sub_info{level}) { $user_saved_queries_html = _user_saved_queries( $dbh, $user{user_ID} ); } # $model{inner_nav} = (); # my $inner_nav_links = [ # { label => , link => }, # ]; #push(@{$model{pagecontent}}, '
'.Dumper(%sub_info).'
'); push(@{$model{pagecontent}}, $srtemplates->process( 'Local/Sections/PlayIndex_Index.tt2', { user_saved_queries => $user_saved_queries_html, sub_info => \%sub_info, user => \%user, } )); # print output_site_footer_script( # { serve_as_cgi_script => $TRUE, # site_root_dir => $site_params_ref->{site_root_dir}, # } # ); my $output = $srtemplates->process( 'Pages/General.tt2', \%model ); print $output; # cleanup and exit. $dbhSR->disconnect; $dbh->disconnect; } ################################################################### # Usage : _delete_report() # Purpose : delete a previously saved report. # Returns : nothing # Parameters : # Throws : ################################################################### sub _delete_report { my ( $dbh, $ref ) = @_; my $return = $EMPTY_STR; my $query = sprintf qq{DELETE FROM saved_queries_full WHERE userID=%s AND linkID=%s}, $dbh->quote( $ref->{user} ), $dbh->quote( $ref->{linkID} ); $dbh->do($query); return scalar $return; } ################################################################### # Usage : zzzz # Purpose : zzzz # Returns : zzzz # Parameters : zzzz # Throws : zzzz # See Also : zzzz # Comments : zzzz ################################################################### sub _user_saved_queries { my ( $dbh, $user ) = @_; my $query = <<"END_HTML"; SELECT linkID, title, date_saved, (date_saved >= DATE_SUB(CURRENT_DATE(), INTERVAL 31 day)) as is_recent FROM saved_queries_full WHERE userID=? ORDER BY date_saved DESC, title END_HTML my $sth_q = $dbh->prepare($query); $sth_q->execute($user); my @recent = (); my @not_recent = (); while ( my $tmp = $sth_q->fetchrow_hashref ) { $row_output = sprintf( qq{%s: %s} . qq{   } . qq{http://bbref.com/pi/shareit/%s (Delete)\n}, $tmp->{date_saved}, is_nonempty_print( $tmp->{title} ), $tmp->{linkID}, $tmp->{linkID}, $tmp->{linkID} ); if ( $tmp->{is_recent} ) { push( @recent, $row_output ); } else { push( @not_recent, $row_output ); } } my $output = $EMPTY_STR; $output .= '

Saved Reports from the last 30 days

'; $output .= ''; $output .= join( "\n", @recent ); $output .= '
'; if (@not_recent) { my $count = scalar @not_recent; $output .= 'View Older Reports ('.$count.')'; $output .= qq{}; $output .= join( "", @not_recent ); $output .= ''; } $output .= qq{

You can save your reports and get an easy-to-use link, so you can share the full report with anyone. Just click on the Share tooltips above any report you generate to start the process.\n}; return $output; }