require "bracket_manager.pm"; sub print_update_tournament_score_form{ my $event_id = shift; my $tournament_id = shift; my %event_info = get_event_info($event_id); my %teamsa = get_league_teams($event_info{"League_ID"}); my %tournament_event_info = get_tournament_event_info($tournament_id); my $home_team = ""; my $away_team = ""; foreach $key (keys %teamsa){ $teams{$teamsa{$key}} = $key; } if ($event_info{"Home_Team"} == 0) { $home_team = $tournament_event_info{"ALT_TOP_BRACKET"}; }else{ $home_team = $teams{$event_info{"Home_Team"}}; } if ($event_info{"Away_Team"} == 0) { $away_team = $tournament_event_info{"ALT_BOTTOM_BRACKET"}; }else{ $away_team = $teams{$event_info{"Away_Team"}}; } my $home_score = $event_info{"Home_Score"}; my $away_score = $event_info{"Away_Score"}; if($home_score == -1){ $home_score = ""; } if($away_score == -1){ $away_score = ""; } print <<__HTML__;
__HTML__ if(($home_score != '')&&($away_score != '')){ print <<__HTML__; __HTML__ } print <<__HTML__;
Update Scores
$home_team
$away_team
    
 
__HTML__ } sub print_update_score_form{ my $event_id = shift; my $year = shift; my $month = shift; my $filter = shift; my %event_info = get_event_info($event_id); my %teamsa = get_league_teams($event_info{"League_ID"}); my $league_id = $event_info{"League_ID"}; my $org_id = $event_info{"Org_ID"}; my $home_team = ""; my $away_team = ""; foreach $key (keys %teamsa){ $teams{$teamsa{$key}} = $key; } %team_event_info = get_team_event_info_by_event_id($event_id); if($event_info{"Home_Team"} == 0){ $home_team = $team_event_info{"ALT_HOME_TEAM"}; }else{ $home_team = $teams{$event_info{"Home_Team"}}; } if($event_info{"Away_Team"} == 0){ $away_team = $team_event_info{"ALT_AWAY_TEAM"}; }else{ $away_team = $teams{$event_info{"Away_Team"}}; } my $home_score = $event_info{"Home_Score"}; my $away_score = $event_info{"Away_Score"}; my $notes = $event_info{"Notes"}; $notes =~ s/
/\n/g; #$notes =~ s/^GAME HIGHLIGHTS - //g; if($home_score == -1){ $home_score = ""; } if($away_score == -1){ $away_score = ""; } my $checked = "CHECKED"; my $starter_notes = "GAME HIGHLIGHTS - "; if(($home_score != '')&&($away_score != '')){ if($notes eq ""){ $checked = ""; $starter_notes = ""; }else{ $starter_notes = $notes; } } print <<__HTML__;
__HTML__ if(($home_score != '')&&($away_score != '')){ print <<__HTML__; __HTML__ } print <<__HTML__;
Update Scores
$away_team
$home_team
Enter Game Highlights/Notes
    
 
__HTML__ } sub get_event_info{ my $event_id = shift; my %return_hash = (); $dbh = get_dbh(); # prepare and execute query $query = "SELECT * FROM Calendar_Events WHERE `Key` = $event_id"; $sth = $dbh->prepare($query); $sth->execute(); # assign fields to variables $sth->bind_columns(\$ID, \$Org_ID, \$League_ID, \$Team_ID, \$Start_Date, \$End_Date, \$Event_Type, \$Home_Team, \$Home_Score, \$Away_Team, \$Away_Score, \$Desc, \$Location, \$Other_Location, \$Notes, \$Status); while($sth->fetch()) { $return_hash{"ID"} = $ID; $return_hash{"Org_ID"} = $Org_ID; $return_hash{"League_ID"} = $League_ID; $return_hash{"Team_ID"} = $Team_ID; $return_hash{"Start_Date"} = $Start_Date; $return_hash{"End_Date"} = $End_Date; $return_hash{"Event_Type"} = $Event_Type; $return_hash{"Home_Team"} = $Home_Team; $return_hash{"Home_Score"} = $Home_Score; $return_hash{"Away_Team"} = $Away_Team; $return_hash{"Away_Score"} = $Away_Score; $return_hash{"Desc"} = $Desc; $return_hash{"Location"} = $Location; $return_hash{"Other_Location"} = $Other_Location; $return_hash{"Notes"} = $Notes; } $sth->finish(); # disconnect from database $dbh->disconnect; return %return_hash; } sub print_calendar_update_event_form{ my $event_id = shift; my %event_info = get_event_info($event_id); my $update_notes = $event_info{"Notes"}; my $use_other = 1; $update_notes =~ s/
/\n/g; @hours = (1,2,3,4,5,6,7,8,9,10,11,12); @min = ("00","15","30","45"); @ampm = ("AM", "PM"); ($current_sdate, $current_stime) = split(/\s+/, $event_info{"Start_Date"}); ($current_shour, $current_smin, $current_sampm) = convert_time_to_display($current_stime); ($current_edate, $current_etime) = split(/\s+/, $event_info{"End_Date"}); ($current_ehour, $current_emin, $current_eampm) = convert_time_to_display($current_etime); $current_sdate = convert_date_to_display($current_sdate); %event_types = get_event_types(); %locations = get_locations($event_info{"Org_ID"}); %teams = get_league_teams($event_info{"League_ID"}); #$locations{"Other"} = 0; print <<__HTML__; __HTML__ print <<__HTML__;
Calendar Event
Event Type
Event Name
Home Team __HTML__ print "\n"; print <<__HTML__;
Visiting Team __HTML__ print "\n"; print <<__HTML__;
Date Click to insert Date
Start Time __HTML__ print "\n"; print "\n"; print "\n"; print <<__HTML__;
End Time __HTML__ print "\n"; print "\n"; print "\n"; print <<__HTML__;
Location
Other
Notes
__HTML__ print "\n"; } sub print_calendar_update_tournament_event_form{ my $event_id = shift; my %event_info = get_event_info($event_id); my $update_notes = $event_info{"Notes"}; $update_notes =~ s/
/\n/g; @hours = (1,2,3,4,5,6,7,8,9,10,11,12); @min = ("00","15","30","45"); @ampm = ("AM", "PM"); ($current_sdate, $current_stime) = split(/\s+/, $event_info{"Start_Date"}); ($current_shour, $current_smin, $current_sampm) = convert_time_to_display($current_stime); ($current_edate, $current_etime) = split(/\s+/, $event_info{"End_Date"}); ($current_ehour, $current_emin, $current_eampm) = convert_time_to_display($current_etime); $current_sdate = convert_date_to_display($current_sdate); %event_types = get_event_types(); %locations = get_locations($event_info{"Org_ID"}); %teams = get_league_teams($event_info{"League_ID"}); $locations{"Other"} = 0; print <<__HTML__; __HTML__ print <<__HTML__;
Calendar Event
Event Type2
Event Name
Home Team __HTML__ print "\n"; print <<__HTML__;
Visiting Team __HTML__ print "\n"; print <<__HTML__;
Date Click to insert Date
Start Time __HTML__ print "\n"; print "\n"; print "\n"; print <<__HTML__;
End Time __HTML__ print "\n"; print "\n"; print "\n"; print <<__HTML__;
Location
Other
Notes
__HTML__ print "\n"; } ################################################################# ## Print the Update Form ################################################################# sub print_calendar_event_form{ my $org_id = shift; my $league_id = shift; @hours = (1,2,3,4,5,6,7,8,9,10,11,12); @min = (00,15,30,45); @ampm = ("AM", "PM"); %event_types = get_event_types(); %locations = get_locations($org_id); %teams = get_league_teams($league_id); #$locations{"Other"} = 0; print <<__HTML__; __HTML__ print <<__HTML__;
Calendar Event
Event Type
Event Name
Home Team __HTML__ print "\n"; print <<__HTML__;
Visiting Team __HTML__ print "\n"; print <<__HTML__;
Date Click to insert Date
Start Time __HTML__ print "\n"; print "\n"; print "\n"; print <<__HTML__;
End Time __HTML__ print "\n"; print "\n"; print "\n"; print <<__HTML__;
Location
Other
Notes
__HTML__ print "\n"; } ################################################################# ## Print the Update Form ################################################################# sub print_calendar_event_form_with_fields{ my $org_id = shift; my $league_id = shift; @hours = (1,2,3,4,5,6,7,8,9,10,11,12); @min = (00,15,30,45); @ampm = ("AM", "PM"); %event_types = get_event_types(); %locations = get_locations($org_id); %teams = get_league_teams($league_id); #$locations{"Other"} = 0; $html = <<__HTML__; Ordinary CGI demo __HTML__ #print_style(); $html = <<__HTML__; __HTML__ $html .= <<__HTML__;
Calendar Event
Event Type
Event Name
Home Team __HTML__ $html .= "\n"; $html .= <<__HTML__;
Visiting Team __HTML__ $html .= "\n"; $html .= <<__HTML__;
Date Click to insert Date
Start Time __HTML__ $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= <<__HTML__;
End Time __HTML__ $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= <<__HTML__;
Location
Other
Notes
Calendar Event
Event Type
__HTML__ $html .= "\n"; return $html; } sub get_org_teams{ my $org_id = shift; my $dbh = get_dbh(); my $League_ID = ""; my $Team_Name = ""; my $Division_ID = ""; # prepare and execute query my $query = "SELECT a.`Key`, a.`League_ID`, a.`Team_Name`, a.`Division_ID` FROM `Team_Info` a, `League_Info` b WHERE a.`League_ID`=b.`Key` AND b.`ORG_ID`=$org_id ORDER BY Team_Name ASC"; #print "$query
\n"; my $sth = $dbh->prepare($query); my %return_hash; my $ID; my $event_type; $sth->execute(); # assign fields to variables $sth->bind_columns(\$ID, \$League_ID, \$Team_Name, \$Division_ID); # output name list to the browser while($sth->fetch()) { $return_hash{$ID} = $Team_Name; } $sth->finish(); # disconnect from database $dbh->disconnect; return %return_hash; } sub get_league_teams{ my $league_id = shift; my $dbh = get_dbh(); # prepare and execute query my $query = "SELECT * FROM Team_Info WHERE League_ID=$league_id ORDER BY Team_Name ASC"; #print "$query
\n"; my $sth = $dbh->prepare($query); my %return_hash; my $ID; my $event_type; $sth->execute(); # assign fields to variables $sth->bind_columns(\$ID, \$League_ID, \$Team_Name, \$Division_ID, \$Status); # output name list to the browser while($sth->fetch()) { $return_hash{$Team_Name} = $ID; } $sth->finish(); # disconnect from database $dbh->disconnect; return %return_hash; } sub get_league_teams_w_division{ my $league_id = shift; my $dbh = get_dbh(); my %return_hash = (); # prepare and execute query my $query = "SELECT * FROM Team_Info WHERE League_ID=$league_id ORDER BY Team_Name ASC"; my $sth = $dbh->prepare($query); my @return_array = (); my $ID; my $event_type; $sth->execute(); # assign fields to variables $sth->bind_columns(\$ID, \$League_ID, \$team_name, \$Division_ID, \$Status); # output name list to the browser while($sth->fetch()) { $return_hash{$team_name}{$team_name} = $ID; $return_hash{$team_name}{"Division_ID"} = $Division_ID; } $sth->finish(); # disconnect from database $dbh->disconnect; return %return_hash; } sub get_event_types{ my $dbh = get_dbh(); # prepare and execute query my $query = "SELECT * FROM event_type WHERE 1 ORDER BY event_type ASC"; my $sth = $dbh->prepare($query); my %return_hash = (); my $ID; my $event_type; $sth->execute(); # assign fields to variables $sth->bind_columns(\$ID, \$event_type); # output name list to the browser while($sth->fetch()) { $return_hash{$event_type} = $ID; } $sth->finish(); # disconnect from database $dbh->disconnect; return %return_hash; } sub get_locations_old{ my $Org_ID = shift; my $dbh = get_dbh(); # prepare and execute query my $query = "SELECT * FROM Location_Info WHERE Org_ID = $Org_ID AND Archived = 0 ORDER BY Location ASC"; my $sth = $dbh->prepare($query); my %return_hash = (); my $ID; my $Location; $sth->execute(); # assign fields to variables $sth->bind_columns(\$ID, \$Org_ID, \$Location, \$Address, \$Address_Link, \$Directions, \$Order, \$Archived); # output name list to the browser while($sth->fetch()) { $return_hash{$Location} = $ID; } $sth->finish(); # disconnect from database $dbh->disconnect; return %return_hash; } sub get_subscriber_locations{ my $Org_ID = shift; my $dbh = get_dbh(); # prepare and execute query my $query = "SELECT a.`Key`, a.`Location` FROM Location_Info a, Location_Subscriber_Link b WHERE b.`Org_ID` = '$Org_ID' AND a.`Key` = b.`Location_ID` AND a.`Archived` = 0 ORDER BY a.`Location` ASC"; my $sth = $dbh->prepare($query); my %return_hash = (); my $ID; my $Location; $sth->execute(); # assign fields to variables $sth->bind_columns(\$ID, \$Location); # output name list to the browser while($sth->fetch()) { $return_hash{$Location} = $ID; } $sth->finish(); # disconnect from database $dbh->disconnect; return %return_hash; } ############################################ # Get All Independent Teams and Leagues for ORG ############################################ sub get_leagues_and_independent_teams_by_org_b{ my $org_id = shift; my $dbh = get_dbh(); # prepare and execute query #my $query = "SELECT `Key`, `League_Name` FROM League_Info WHERE `Org_ID` = '$org_id'"; my $query = "SELECT `League_ID`, `Menu_Name` FROM Menu_Info WHERE `Org_ID` = '$org_id' AND (`Menu_Type` = 'league' OR `Menu_Type` = 'team')"; #print "SELECT: $query
\n"; my $sth = $dbh->prepare($query); my %return_hash = (); my $ID; $sth->execute(); # assign fields to variables $sth->bind_columns(\$ID, \$League_Name); # output name list to the browser while($sth->fetch()) { $return_hash{$League_Name} = $ID; } $sth->finish(); # disconnect from database $dbh->disconnect; return %return_hash; } sub get_leagues_that_subscribe_to_locations{ my $Org_ID = shift; my %orgs_that_subscribe_to_locations = get_orgs_that_subscribed_to_locations($Org_ID); my %leagues_that_subscribe = (); foreach my $subscribe_org (keys %orgs_that_subscribe_to_locations) { my $subscribe_org_short = get_org_short($subscribe_org); my %leagues_in_org = get_leagues_and_independent_teams_by_org_b($subscribe_org); foreach my $league (sort keys %leagues_in_org) { $leagues_that_subscribe{"$subscribe_org_short, $league"} = $leagues_in_org{$league}; } } return %leagues_that_subscribe; } sub get_orgs_that_subscribed_to_locations{ my $Org_ID = shift; my $dbh = get_dbh(); # prepare and execute query my $query = "SELECT DISTINCT(a.`Org_ID`) FROM `Location_Subscriber_Link` a, `Location_Info` b WHERE a.`Location_id` = b.`Key` AND b.`Org_ID` = '$org_id'"; my $sth = $dbh->prepare($query); my %return_hash = (); my $ID; my $Location; $sth->execute(); # assign fields to variables $sth->bind_columns(\$ORG_ID); # output name list to the browser while($sth->fetch()) { $return_hash{$ORG_ID} = 1; } $sth->finish(); # disconnect from database $dbh->disconnect; return %return_hash; } sub get_locations{ my $Org_ID = shift; my $dbh = get_dbh(); ######################################3 # Get This Org Locations ####################################### # prepare and execute query my $query = "SELECT * FROM Location_Info WHERE Org_ID = $Org_ID AND Archived = 0 ORDER BY Location ASC"; my $sth = $dbh->prepare($query); my %return_hash = (); my $ID; my $Location; $sth->execute(); # assign fields to variables $sth->bind_columns(\$ID, \$Org_ID, \$Location, \$Address, \$Address_Link, \$Directions, \$Order, \$Archived); # output name list to the browser while($sth->fetch()) { $return_hash{$Location} = $ID; } $sth->finish(); ######################################3 # Get Subscriber Locations # Note Subscriber will overwrite regular ####################################### # prepare and execute query $query = "SELECT a.`Key`, a.`Location` FROM Location_Info a, Location_Subscriber_Link b WHERE b.`Org_ID` = '$Org_ID' AND a.`Key` = b.`Location_ID` AND a.`Archived` = 0 ORDER BY a.`Location` ASC"; $sth = $dbh->prepare($query); $ID = ""; $Location = ""; $sth->execute(); # assign fields to variables $sth->bind_columns(\$ID, \$Location); # output name list to the browser while($sth->fetch()) { $return_hash{$Location} = $ID; } $sth->finish(); # disconnect from database $dbh->disconnect; return %return_hash; } ######################################3 # Get Locations with link # Note: These include archives ####################################### sub get_locations_with_link_no_archive{ my $Org_ID = shift; my $dbh = get_dbh(); # prepare and execute query my $query = "SELECT * FROM Location_Info WHERE Org_ID = $Org_ID AND Archived = 0 ORDER BY Location ASC"; my $sth = $dbh->prepare($query); my %return_hash = (); my $ID; my $Location; $sth->execute(); # assign fields to variables $sth->bind_columns(\$ID, \$Org_ID, \$Location, \$Address, \$Address_Link, \$Directions, \$Order, \$Archived); # output name list to the browser while($sth->fetch()) { $return_hash{$ID}{"Location"} = $Location; $return_hash{$ID}{"LINK"} = $Address_Link; $return_hash{$ID}{"ORG_ID"} = $Org_ID; } $sth->finish(); ######################################3 # Get Subscriber Locations # Note Subscriber will overwrite regular ####################################### # prepare and execute query $query = "SELECT a.`Key`, a.`Location`, a.`Address_Link`, a.`Org_ID` FROM Location_Info a, Location_Subscriber_Link b WHERE b.`Org_ID` = '$Org_ID' AND a.`Key` = b.`Location_ID` AND a.`Archived` = 0 ORDER BY a.`Location` ASC"; $sth = $dbh->prepare($query); $ID = ""; $Location = ""; $sth->execute(); # assign fields to variables $sth->bind_columns(\$ID, \$Location, \$Address_Link, \$Org_ID); # output name list to the browser while($sth->fetch()) { $return_hash{$ID}{"Location"} = $Location; $return_hash{$ID}{"LINK"} = $Address_Link; $return_hash{$ID}{"ORG_ID"} = $Org_ID; } $sth->finish(); # disconnect from database $dbh->disconnect; return %return_hash; } ######################################3 # Get Locations with link # Note: These include archives ####################################### sub get_locations_with_link{ my $Org_ID = shift; my $dbh = get_dbh(); # prepare and execute query my $query = "SELECT * FROM Location_Info WHERE Org_ID = $Org_ID ORDER BY Location ASC"; my $sth = $dbh->prepare($query); my %return_hash = (); my $ID; my $Location; $sth->execute(); # assign fields to variables $sth->bind_columns(\$ID, \$Org_ID, \$Location, \$Address, \$Address_Link, \$Directions, \$Order, \$Archived); # output name list to the browser while($sth->fetch()) { $return_hash{$ID}{"Location"} = $Location; $return_hash{$ID}{"LINK"} = $Address_Link; $return_hash{$ID}{"ORG_ID"} = $Org_ID; } $sth->finish(); ######################################3 # Get Subscriber Locations # Note Subscriber will overwrite regular ####################################### # prepare and execute query #my $query = "SELECT a.`Key`, a.`Location`, a.`Address_Link`, a.`Org_ID` FROM Location_Info a, Location_Subscriber_Link b WHERE b.`Org_ID` = '$Org_ID' AND a.`Key` = b.`Location_ID` AND a.`Archived` = 0 ORDER BY a.`Location` ASC"; $query = "SELECT a.`Key`, a.`Location`, a.`Address_Link`, a.`Org_ID` FROM Location_Info a, Location_Subscriber_Link b WHERE b.`Org_ID` = '$Org_ID' AND a.`Key` = b.`Location_ID` ORDER BY a.`Location` ASC"; $sth = $dbh->prepare($query); $ID = ""; $Location = ""; $sth->execute(); # assign fields to variables $sth->bind_columns(\$ID, \$Location, \$Address_Link, \$Org_ID); # output name list to the browser while($sth->fetch()) { $return_hash{$ID}{"Location"} = $Location; $return_hash{$ID}{"LINK"} = $Address_Link; $return_hash{$ID}{"ORG_ID"} = $Org_ID; } $sth->finish(); # disconnect from database $dbh->disconnect; return %return_hash; } sub get_locations_with_link_old{ my $Org_ID = shift; my $dbh = get_dbh(); # prepare and execute query my $query = "SELECT * FROM Location_Info WHERE Org_ID = $Org_ID ORDER BY Location ASC"; my $sth = $dbh->prepare($query); my %return_hash = (); my $ID; my $Location; $sth->execute(); # assign fields to variables $sth->bind_columns(\$ID, \$Org_ID, \$Location, \$Address, \$Address_Link, \$Directions, \$Order, \$Archived); # output name list to the browser while($sth->fetch()) { $return_hash{$ID}{"Location"} = $Location; $return_hash{$ID}{"LINK"} = $Address_Link; } $sth->finish(); # disconnect from database $dbh->disconnect; return %return_hash; } sub print_start_header{ my $title = shift; print <<__HTML__; Content-type: text/html $title __HTML__ } ############################################# # Convert Time for Database Entry ############################################# sub convert_time{ my $hour = shift; my $min = shift; my $ampm = lc(shift); ########################################## # If ampm = pm add 12 hours for 24 hour time # unless its noon. ########################################## if($ampm eq "pm"){ if($hour != 12){ $hour = $hour + 12; } ########################################## # If 12 am, hours = 0 ########################################## }else{ if($hour == 12){ $hour = 0; } } $hour = sprintf("%02d", $hour); $min = sprintf("%02d", $min); my $return_string = $hour . ":" . $min . ":00"; return $return_string; } sub convert_date{ my $old_date = shift; my ($month, $day, $year) = split(/\//,$old_date); $month = sprintf("%02d", $month); $day = sprintf("%02d", $day); my $return_string = $year . "-" . $month . "-" . $day; return $return_string; } sub convert_date_to_display{ my $old_date = shift; my ($year, $month, $day) = split(/-/,$old_date); $month = sprintf("%1d", $month); $day = sprintf("%1d", $day); my $return_string = $month . "/" . $day . "/" . $year; return $return_string; } sub convert_time_to_display{ my $time = shift; my $hour; my $min; my $sec; my $ampm; my @return_array = (); ($hour, $min, $sec) = split(/:/,$time); if($hour > 12){ $hour = $hour - 12; $ampm = "PM"; }elsif($hour == 0){ $hour = 12; $ampm = "AM"; }elsif($hour == 12){ $ampm = "PM"; }else{ $ampm = "AM"; } $hour = sprintf("%1d", $hour); #$min = sprintf("%1d", $min); push(@return_array, $hour); push(@return_array, $min); push(@return_array, $ampm); #return ($hour, min, $ampm); return @return_array; } 1;