function OnLoadPageData()
 {
     # new data manager
     $manager = new MatchManager($this->GetSettings(), $this->GetDataConnection());
     # get matches
     $i_one_day = 86400;
     $i_start = gmdate('U') - $i_one_day * 1;
     # yesterday
     $i_end = gmdate('U') + $i_one_day * 365;
     # in the next year
     # Check for player type
     $this->player_type = null;
     if (isset($_GET['player'])) {
         $this->player_type = PlayerType::Parse($_GET['player']);
     }
     $a_player_types = is_null($this->player_type) ? null : array($this->player_type);
     if ($this->player_type == PlayerType::JUNIOR_MIXED) {
         $a_player_types[] = PlayerType::GIRLS;
         $a_player_types[] = PlayerType::BOYS;
     }
     $manager->FilterByMatchType(array(MatchType::TOURNAMENT));
     $manager->FilterByPlayerType($a_player_types);
     $manager->FilterByDateStart($i_start);
     $manager->FilterByDateEnd($i_end);
     $manager->ReadMatchSummaries();
     $this->a_matches = $manager->GetItems();
     unset($manager);
 }
 private function ReadMatchData($start_date)
 {
     require_once 'stoolball/match-manager.class.php';
     $match_manager = new MatchManager($this->GetSettings(), $this->GetDataConnection());
     $match_manager->FilterByDateStart($start_date);
     $match_manager->FilterByMatchType(array(MatchType::CUP, MatchType::FRIENDLY, MatchType::LEAGUE, MatchType::PRACTICE, MatchType::TOURNAMENT));
     $match_manager->ReadByMatchId();
     $data = $match_manager->GetItems();
     unset($match_manager);
     return $data;
 }
 function OnLoadPageData()
 {
     # new data manager
     $manager = new MatchManager($this->GetSettings(), $this->GetDataConnection());
     # Check for month value
     if (isset($_GET['month']) and is_numeric($_GET['month'])) {
         # Make sure it looks real
         $i_day = (int) date('d', $_GET['month']);
         $i_year = (int) date('Y', $_GET['month']);
         $i_month = (int) date('m', $_GET['month']);
         if ($i_year >= 2000 and $i_year <= 2050 and $i_month >= 1 and $i_month <= 12 and $i_day == 1) {
             # Read start date specified by user, which will be with DST applied because users don't think in UTC
             $i_start = $_GET['month'];
             $i_end = mktime(11, 59, 59, $i_month, date('t', $_GET['month']), $i_year);
             # Convert to UTC, as that's how match dates are stored
             $i_end = gmdate('U', $i_end);
             $manager->FilterByDateStart($i_start);
             $manager->FilterByDateEnd($i_end);
         }
     } else {
         # get next few matches
         $i_one_day = 86400;
         $i_start = gmdate('U') - $i_one_day * 1;
         # yesterday
         $manager->FilterByDateStart($i_start);
         $manager->FilterByMaximumResults(50);
     }
     # Check for match type
     $i_match_type = null;
     if (isset($_GET['type']) and is_numeric($_GET['type'])) {
         $i_match_type = (int) $_GET['type'];
         if ($i_match_type < 0 or $i_match_type > 50) {
             $i_match_type = null;
         }
     }
     $a_match_types = is_null($i_match_type) ? null : array($i_match_type);
     $manager->FilterByMatchType($a_match_types);
     # Check for player type
     $i_player_type = null;
     if (isset($_GET['player']) and is_numeric($_GET['player'])) {
         $i_player_type = (int) $_GET['player'];
         if ($i_player_type < 0 or $i_player_type > 50) {
             $i_player_type = null;
         }
     }
     $a_player_types = is_null($i_player_type) ? null : array($i_player_type);
     $manager->FilterByPlayerType($a_player_types);
     $manager->ReadMatchSummaries();
     $this->a_matches = $manager->GetItems();
     $this->a_months = $manager->ReadMatchMonths();
     # tidy up
     unset($manager);
 }
 function OnLoadPageData()
 {
     /* @var $o_last_match Match */
     /* @var $season Season */
     /* @var $team Team */
     # First best guess at where user came from is the page field posted back,
     # second best is tournaments page. Either can be tampered with, so there will be
     # a check later before they're used for redirection. If there's a context
     # season or team its URL will be read from the db and overwrite this later.
     if (isset($_POST['page'])) {
         $this->destination_url_if_cancelled = $_POST['page'];
     } else {
         $this->destination_url_if_cancelled = "/tournaments";
     }
     # new data manager
     $match_manager = new MatchManager($this->GetSettings(), $this->GetDataConnection());
     $match_manager->FilterByMatchType(array(MatchType::TOURNAMENT));
     # Check whether cancel was clicked
     if ($this->IsPostback() and $this->editor->CancelClicked()) {
         # new tournament, nothing saved yet, so just send user back where they came from
         $this->Cancel();
     }
     # Save match
     if ($this->IsPostback() and $this->IsValid()) {
         # Get posted match
         $this->tournament = $this->editor->GetDataObject();
         # Save match
         $match_manager->SaveFixture($this->tournament);
         if (count($this->tournament->GetAwayTeams())) {
             $match_manager->SaveTeams($this->tournament);
         }
         if ($this->season instanceof Season) {
             $this->tournament->Seasons()->Add($this->season);
             $match_manager->SaveSeasons($this->tournament, true);
         }
         http_response_code(303);
         $this->Redirect($this->tournament->AddTournamentTeamsUrl());
     }
     if (isset($this->season)) {
         $season_manager = new SeasonManager($this->GetSettings(), $this->GetDataConnection());
         $season_manager->ReadById(array($this->season->GetId()));
         $this->season = $season_manager->GetFirst();
         $this->editor->SetContextSeason($this->season);
         $this->destination_url_if_cancelled = $this->season->GetNavigateUrl();
         unset($season_manager);
         # If we're adding a match to a season, get last game in season for its date
         $match_manager->ReadLastInSeason($this->season->GetId());
     }
     if (isset($this->team)) {
         # Get more information about the team itself
         require_once 'stoolball/team-manager.class.php';
         $team_manager = new TeamManager($this->GetSettings(), $this->GetDataConnection());
         $team_manager->ReadById(array($this->team->GetId()));
         $this->team = $team_manager->GetFirst();
         $this->editor->SetContextTeam($this->team);
         $this->destination_url_if_cancelled = $this->team->GetNavigateUrl();
         # Get the last game already scheduled for the team to use its date
         $match_manager->ReadLastForTeam($this->team->GetId());
         # Read teams played in the last year in order to get their grounds, which will be put at the top of the select list
         $team_manager->ReadRecentOpponents(array($this->team->GetId()), 12);
         $this->editor->ProbableTeams()->SetItems($team_manager->GetItems());
         unset($team_manager);
     }
     # Use the date of the most recent tournament if it was this year, otherwise just use the default of today
     $o_last_match = $match_manager->GetFirst();
     if (is_object($o_last_match) and gmdate('Y', $o_last_match->GetStartTime()) == gmdate('Y')) {
         if ($o_last_match->GetIsStartTimeKnown()) {
             # If the last match has a time, use it
             $this->editor->SetDefaultTime($o_last_match->GetStartTime());
         } else {
             # If the last match has no time, use 11am BST
             $this->editor->SetDefaultTime(gmmktime(10, 0, 0, gmdate('m', $o_last_match->GetStartTime()), gmdate('d', $o_last_match->GetStartTime()), gmdate('Y', $o_last_match->GetStartTime())));
         }
     }
     unset($match_manager);
     # Get grounds
     $o_ground_manager = new GroundManager($this->GetSettings(), $this->GetDataConnection());
     $o_ground_manager->ReadAll();
     $a_grounds = $o_ground_manager->GetItems();
     $this->editor->Grounds()->SetItems($a_grounds);
     unset($o_ground_manager);
 }
$i_end = gmdate('U') + $i_one_day * $days;
# Check for player type
$player_type = null;
$player_types = null;
if (isset($_GET['player'])) {
    $player_type = PlayerType::Parse($_GET['player']);
    if (!is_null($player_type)) {
        $player_types = array($player_type);
        if ($player_type == PlayerType::JUNIOR_MIXED) {
            $player_types[] = PlayerType::GIRLS;
            $player_types[] = PlayerType::BOYS;
        }
        $player_type = PlayerType::Text($player_type) . " ";
    }
}
$manager->FilterByMatchType(array(MatchType::TOURNAMENT));
$manager->FilterByPlayerType($player_types);
$manager->SortBy("date_changed DESC");
$manager->FilterByDateStart($i_start);
$manager->FilterByDateEnd($i_end);
$manager->ReadMatchSummaries();
$matches = $manager->GetItems();
unset($manager);
$database->Disconnect();
$title = 'Stoolball tournaments';
if ($player_type) {
    $title = $player_type . strtolower($title);
}
$feedData = array('title' => $title, 'description' => "New or updated " . strtolower($player_type) . "stoolball tournaments on the Stoolball England website", 'link' => 'http://www.stoolball.org.uk/tournaments', 'charset' => 'utf-8', "language" => "en-GB", "author" => "Stoolball England", "image" => "https://www.stoolball.org.uk/images/feed-ident.gif", 'entries' => array());
# Option to tweet new entries to a user, for use with www.iftt.com
$tweet = isset($_GET['format']) && $_GET['format'] === "tweet";
    public function OnLoadPageData()
    {
        $i_one_day = 86400;
        $i_start = gmdate('U') - $i_one_day * 1;
        # yesterday
        $i_end = gmdate('U') + $i_one_day * 365;
        # this year
        # Check for player type
        $player_type = null;
        if (isset($_GET['player']) and is_numeric($_GET['player'])) {
            $player_type = (int) $_GET['player'];
        }
        $a_player_types = is_null($player_type) ? null : array($player_type);
        if ($player_type == PlayerType::JUNIOR_MIXED) {
            $a_player_types[] = PlayerType::GIRLS;
            $a_player_types[] = PlayerType::BOYS;
        }
        $manager = new MatchManager($this->GetSettings(), $this->GetDataConnection());
        $manager->FilterByMatchType(array(MatchType::TOURNAMENT));
        $manager->FilterByPlayerType($a_player_types);
        $manager->FilterByDateStart($i_start);
        $manager->FilterByDateEnd($i_end);
        $manager->ReadMatchSummaries();
        $tournaments = $manager->GetItems();
        unset($manager);
        ?>
$(function()
{
	// Make the placeholder big enough for a map
	var mapControl = document.getElementById("map");
	mapControl.style.width = '100%';
	mapControl.style.height = '400px';

	// Create the map
	var myLatlng = new google.maps.LatLng(51.07064141136184, -0.31114161014556885); // Horsham
	var myOptions = {
		zoom : $(window).width() > 400 ? 9 : 8,
		center : myLatlng,
		mapTypeId : google.maps.MapTypeId.ROADMAP
	};
	var map = new google.maps.Map(mapControl, myOptions);
	var markers = [];
	var info;
<?php 
        # There might be multiple tournaments at one ground. Rearrange tournaments so that they're indexed by ground.
        $grounds = array();
        foreach ($tournaments as $tournament) {
            /* @var $tournament Match */
            $ground_id = $tournament->GetGroundId();
            if (!array_key_exists($ground_id, $grounds)) {
                $grounds[$ground_id] = array();
            }
            $grounds[$ground_id][] = $tournament;
        }
        foreach ($grounds as $tournaments) {
            /* @var $ground Ground */
            $ground = $tournaments[0]->GetGround();
            if (!is_object($ground) or !$ground->GetAddress()->GetLatitude() or !$ground->GetAddress()->GetLongitude()) {
                continue;
            }
            $content = "'<div class=\"map-info\">' +\n\t'<h2>" . str_replace("'", "\\'", $ground->GetNameAndTown()) . "</h2>";
            foreach ($tournaments as $tournament) {
                /* @var $tournament Match */
                $title = $tournament->GetTitle() . ", " . Date::BritishDate($tournament->GetStartTime(), false, true, false);
                $content .= '<p><a href="' . $tournament->GetNavigateUrl() . '">' . str_replace("'", "\\'", $title) . '</a></p>';
            }
            $content .= "</div>'";
            # And marker and click event to trigger info window. Wrap info window in function to isolate marker, otherwise the last marker
            # is always used for the position of the info window.
            echo "var marker = new google.maps.Marker({\n\t\t\tposition : new google.maps.LatLng(" . $ground->GetAddress()->GetLatitude() . "," . $ground->GetAddress()->GetLongitude() . "),\n\t\t\tshadow: Stoolball.Maps.WicketShadow(),\n\t\t\ticon: Stoolball.Maps.WicketIcon(),\n\t\t\ttitle : '" . str_replace("'", "\\'", $ground->GetNameAndTown()) . "'\n\t\t  });\n\t\t  markers.push(marker);\n\n\t\t  (function(marker){\n\t\t\t  google.maps.event.addListener(marker, 'click', function()\n\t\t\t  {\n\t\t\t  \tvar content = {$content};\n\t\t\t  \tif (!info) info = new google.maps.InfoWindow();\n\t\t\t  \tinfo.setContent(content);\n\t\t\t  \tinfo.open(map, marker);\n\t\t\t  });\n\t\t  })(marker);\n\t\t  ";
        }
        ?>
	var style = [{
        url: '/images/features/map-markers.gif',
        height: 67,
        width: 31,
        textColor: '#ffffff',
        textSize: 10
      }];
	var clusterer = new MarkerClusterer(map, markers, { 'gridSize': 30, styles: style });
});
<?php 
        exit;
    }
 function OnLoadPageData()
 {
     /* @var $o_last_match Match */
     /* @var $season Season */
     /* @var $team Team */
     # new data manager
     $o_match_manager = new MatchManager($this->GetSettings(), $this->GetDataConnection());
     # Collect season to add this match to, starting with the URL
     # get season and teams (was at this stage because editor needed teams to build its
     # posted data object, but that's no longer the case so probably could be later if needed)
     if (isset($this->i_season_id)) {
         $season_manager = new SeasonManager($this->GetSettings(), $this->GetDataConnection());
         $season_manager->ReadById(array($this->i_season_id));
         $this->season = $season_manager->GetFirst();
         unset($season_manager);
         $this->edit->Seasons()->Add($this->season);
         # If there are at least 2 teams in the season, show only those teams, otherwise show all teams of the relevant player type
         if (count($this->season->GetTeams()) > 1) {
             $this->edit->SetTeams(array($this->season->GetTeams()));
         } else {
             require_once 'stoolball/team-manager.class.php';
             $team_manager = new TeamManager($this->GetSettings(), $this->GetDataConnection());
             $team_manager->FilterByPlayerType(array($this->season->GetCompetition()->GetPlayerType()));
             $team_manager->ReadTeamSummaries();
             $this->edit->SetTeams(array($team_manager->GetItems()));
             unset($team_manager);
         }
     }
     # Not elseif, because when you've added a match there's a season, but we still need this to run to populate
     # the choices for the next match to be added
     if ($this->team instanceof Team) {
         # Otherwise it should be a team.
         # Get more information about the team itself
         require_once 'stoolball/team-manager.class.php';
         $team_manager = new TeamManager($this->GetSettings(), $this->GetDataConnection());
         $team_manager->ReadById(array($this->team->GetId()));
         $this->team = $team_manager->GetFirst();
         if (!is_null($this->team)) {
             $this->edit->SetContextTeam($this->team);
             $season_ids = array();
             $team_groups = array();
             $a_exclude_team_ids = array();
             $team_manager->FilterByActive(true);
             # Add the home team first
             $team_groups[] = array($this->team);
             $a_exclude_team_ids[] = $this->team->GetId();
             # Get the seasons this team is in...
             $season_manager = new SeasonManager($this->GetSettings(), $this->GetDataConnection());
             if ($this->i_match_type == MatchType::FRIENDLY) {
                 # For a friendly, any group of teams they play with is fine
                 $season_manager->ReadCurrentSeasonsByTeamId(array($this->team->GetId()));
             } else {
                 # For anything else, get the seasons *for this type of match*
                 $season_manager->ReadCurrentSeasonsByTeamId(array($this->team->GetId()), array($this->i_match_type));
             }
             $seasons = $season_manager->GetItems();
             unset($season_manager);
             $this->edit->Seasons()->Clear();
             # on postback, the season just added is already there, so clear to prevent a duplicate
             foreach ($seasons as $season) {
                 $this->edit->Seasons()->Add($season);
                 $season_ids[] = $season->GetId();
             }
             #... and their opponent teams in those seasons
             if (count($season_ids)) {
                 $team_manager->FilterExceptTeams($a_exclude_team_ids);
                 $team_manager->ReadBySeasonId($season_ids);
                 $season_teams = $team_manager->GetItems();
                 if (count($season_teams)) {
                     $team_groups['This season\'s teams'] = $season_teams;
                 }
                 foreach ($season_teams as $team) {
                     $a_exclude_team_ids[] = $team->GetId();
                 }
             }
             # ...and if this is a friendly it could be any other team
             if ($this->i_match_type == MatchType::FRIENDLY) {
                 # get any other teams they played in the last 2 years, and combine with existing results
                 $team_manager->FilterExceptTeams($a_exclude_team_ids);
                 $team_manager->ReadRecentOpponents(array($this->team->GetId()), 24);
                 $recent_opponents = $team_manager->GetItems();
                 if (count($recent_opponents)) {
                     $team_groups['Recent opponents'] = $recent_opponents;
                 }
                 foreach ($recent_opponents as $team) {
                     $a_exclude_team_ids[] = $team->GetId();
                 }
                 # get any other teams they might play, and combine with existing results
                 $team_manager->FilterExceptTeams($a_exclude_team_ids);
                 $team_manager->ReadAll();
                 $team_groups['Other teams'] = $team_manager->GetItems();
             }
             # What if there are still no opponents to choose from? In that case select all teams.
             if (count($team_groups) == 1) {
                 $team_manager->FilterExceptTeams($a_exclude_team_ids);
                 $team_manager->ReadAll();
                 $team_groups[] = $team_manager->GetItems();
             }
             # Offer those teams to select from
             if ($total_groups = count($team_groups)) {
                 # If only two groups (home team + 1 group), don't group teams. Remove the only key from the array.
                 if ($total_groups == 2) {
                     $keys = array_keys($team_groups);
                     $team_groups = array($team_groups[$keys[0]], $team_groups[$keys[1]]);
                 }
                 $this->edit->SetTeams($team_groups);
             }
         }
         unset($team_manager);
     }
     # Save match
     if ($this->IsPostback() and $this->IsValid()) {
         # Get posted match
         $this->match = $this->edit->GetDataObject();
         if (!$this->IsRefresh()) {
             # Save match
             $o_match_manager->SaveFixture($this->match);
             $o_match_manager->SaveSeasons($this->match, true);
             $o_match_manager->NotifyMatchModerator($this->match->GetId());
             # Update 'next 5 matches'
             $o_match_manager->ReadNext();
             $this->a_next_matches = $o_match_manager->GetItems();
         }
         # Reset control for new match
         $this->edit->SetDataObject(new Match($this->GetSettings()));
     }
     $o_match_manager->FilterByMatchType(array($this->i_match_type));
     if (isset($this->i_season_id)) {
         # If we're adding a match to a season, get last game in season for its date
         $o_match_manager->ReadLastInSeason($this->season->GetId());
     } else {
         if ($this->team instanceof Team) {
             # Get the last game already scheduled for the team to use its date
             $o_match_manager->ReadLastForTeam($this->team->GetId());
         }
     }
     $o_last_match = $o_match_manager->GetFirst();
     if (is_object($o_last_match)) {
         $current_season = Season::SeasonDates();
         if (gmdate('Y', $o_last_match->GetStartTime()) < gmdate('Y', $current_season[0])) {
             # If the last match this team played was last season, use the time but not the date
             $this->edit->SetDefaultTime(gmmktime(gmdate('H', $o_last_match->GetStartTime()), gmdate('i', $o_last_match->GetStartTime()), 0, gmdate('m'), gmdate('d'), gmdate('Y')));
         } else {
             # If the last match was this season and has a time, use it
             if ($o_last_match->GetIsStartTimeKnown()) {
                 $this->edit->SetDefaultTime($o_last_match->GetStartTime());
             } else {
                 # If the last match has no time, use 6.30pm BST
                 $this->edit->SetDefaultTime(gmmktime(17, 30, 0, gmdate('m', $o_last_match->GetStartTime()), gmdate('d', $o_last_match->GetStartTime()), gmdate('Y', $o_last_match->GetStartTime())));
             }
         }
     }
     unset($o_match_manager);
     # Get grounds
     $o_ground_manager = new GroundManager($this->GetSettings(), $this->GetDataConnection());
     $o_ground_manager->ReadAll();
     $a_grounds = $o_ground_manager->GetItems();
     $this->edit->SetGrounds($a_grounds);
     unset($o_ground_manager);
 }