function OnLoadPageData()
 {
     # Require an API key to include personal contact details to avoid spam bots picking them up
     $api_keys = $this->GetSettings()->GetApiKeys();
     $valid_key = false;
     if (isset($_GET['key']) and in_array($_GET['key'], $api_keys)) {
         $valid_key = true;
     }
     $data = array();
     $data[] = array("Match id", "Title", "Start time", "Latitude", "Longitude", "Website", "Description");
     require_once 'stoolball/match-manager.class.php';
     require_once "search/match-search-adapter.class.php";
     $match_manager = new MatchManager($this->GetSettings(), $this->GetDataConnection());
     $match_manager->FilterByDateStart(gmdate("U"));
     $match_manager->ReadByMatchId();
     while ($match_manager->MoveNext()) {
         $match = $match_manager->GetItem();
         $adapter = new MatchSearchAdapter($match);
         /* @var $match Match */
         # Add this match to the data array
         $data[] = array($match->GetId(), $match->GetTitle(), $match->GetStartTime(), $match->GetGround() instanceof Ground ? $match->GetGround()->GetAddress()->GetLatitude() : "", $match->GetGround() instanceof Ground ? $match->GetGround()->GetAddress()->GetLongitude() : "", "https://" . $this->GetSettings()->GetDomain() . $match->GetNavigateUrl(), $adapter->GetSearchDescription());
     }
     unset($match_manager);
     require_once "data/csv.class.php";
     CSV::PublishData($data);
     # Test code only. Comment out CSV publish line above to enable display as a table.
     require_once "xhtml/tables/xhtml-table.class.php";
     $table = new XhtmlTable();
     $table->BindArray($data, false, false);
     echo $table;
 }
 function OnLoadPageData()
 {
     # Require an API key to include personal contact details to avoid spam bots picking them up
     $api_keys = $this->GetSettings()->GetApiKeys();
     $valid_key = false;
     if (isset($_GET['key']) and in_array($_GET['key'], $api_keys)) {
         $valid_key = true;
     }
     $data = array();
     $data[] = array("Club/ facility name", "Address 1", "Address 2", "Address 3", "Address 4", "Address 5", "City", "Postcode", "Country", "Tel", "Email", "Website", "Activities", "Opening times");
     require_once 'stoolball/team-manager.class.php';
     $team_manager = new TeamManager($this->GetSettings(), $this->GetDataConnection());
     $team_manager->FilterByActive(true);
     $team_manager->FilterByTeamType(array(Team::REGULAR));
     $team_manager->ReadById();
     while ($team_manager->MoveNext()) {
         /* @var $team Team */
         $team = $team_manager->GetItem();
         # NHS choices can only import records with a postcode
         if (!$team->GetGround()->GetAddress()->GetPostcode()) {
             continue;
         }
         $address = array();
         if ($team->GetGround()->GetAddress()->GetSaon()) {
             $address[] = $team->GetGround()->GetAddress()->GetSaon();
         }
         if ($team->GetGround()->GetAddress()->GetPaon()) {
             $address[] = $team->GetGround()->GetAddress()->GetPaon();
         }
         if ($team->GetGround()->GetAddress()->GetStreetDescriptor()) {
             $address[] = $team->GetGround()->GetAddress()->GetStreetDescriptor();
         }
         if ($team->GetGround()->GetAddress()->GetLocality()) {
             $address[] = $team->GetGround()->GetAddress()->GetLocality();
         }
         if ($team->GetGround()->GetAddress()->GetAdministrativeArea()) {
             $address[] = $team->GetGround()->GetAddress()->GetAdministrativeArea();
         }
         $data[] = array($team->GetName() . " Stoolball Club", isset($address[0]) ? $address[0] : "", isset($address[1]) ? $address[1] : "", isset($address[2]) ? $address[2] : "", isset($address[3]) ? $address[3] : "", isset($address[4]) ? $address[4] : "", $team->GetGround()->GetAddress()->GetTown(), $team->GetGround()->GetAddress()->GetPostcode(), "England", $valid_key ? $team->GetContactPhone() : "", $valid_key ? $team->GetContactEmail() : "", $team->GetWebsiteUrl() ? $team->GetWebsiteUrl() : "https://" . $this->GetSettings()->GetDomain() . $team->GetNavigateUrl(), "stoolball", preg_replace('/\\[[^]]+\\]/', "", $team->GetPlayingTimes()));
     }
     unset($team_manager);
     require_once "data/csv.class.php";
     CSV::PublishData($data);
     # Test code only. Comment out CSV publish line above to enable display as a table.
     require_once "xhtml/tables/xhtml-table.class.php";
     $table = new XhtmlTable();
     $table->BindArray($data, false, false);
     echo $table;
 }
 function OnLoadPageData()
 {
     # Require an API key to include personal contact details to avoid spam bots picking them up
     $api_keys = $this->GetSettings()->GetApiKeys();
     $valid_key = false;
     if (isset($_GET['key']) and in_array($_GET['key'], $api_keys)) {
         $valid_key = true;
     }
     $data = array();
     $data[] = array("Team id", "Team name", "Player type", "Home ground name", "Street name", "Locality", "Town", "Administrative area", "Postcode", "Country", "Latitude", "Longitude", "Contact phone", "Contact email", "Website", "Description");
     require_once 'stoolball/team-manager.class.php';
     $team_manager = new TeamManager($this->GetSettings(), $this->GetDataConnection());
     $team_manager->FilterByActive(true);
     $team_manager->FilterByTeamType(array(Team::REGULAR));
     $team_manager->ReadById();
     while ($team_manager->MoveNext()) {
         $team = $team_manager->GetItem();
         /* @var $team Team */
         # Spogo can only import records with contact details
         if (!$team->GetContactPhone() and !$team->GetContactEmail()) {
             continue;
         }
         # Combine free text fields into a description field
         $description = $team->GetIntro();
         if ($description) {
             $description .= "\n\n";
         }
         if ($team->GetPlayingTimes()) {
             $description .= $team->GetPlayingTimes() . "\n\n";
         }
         if ($team->GetCost()) {
             $description .= $team->GetCost();
         }
         # Add this team to the data array
         $data[] = array($team->GetId(), $team->GetName() . " Stoolball Club", PlayerType::Text($team->GetPlayerType()), $team->GetGround()->GetAddress()->GetPaon(), $team->GetGround()->GetAddress()->GetStreetDescriptor(), $team->GetGround()->GetAddress()->GetLocality(), $team->GetGround()->GetAddress()->GetTown(), $team->GetGround()->GetAddress()->GetAdministrativeArea(), $team->GetGround()->GetAddress()->GetPostcode(), "England", $team->GetGround()->GetAddress()->GetLatitude(), $team->GetGround()->GetAddress()->GetLongitude(), $valid_key ? $team->GetContactPhone() : "", $valid_key ? $team->GetContactEmail() : "", $team->GetWebsiteUrl() ? $team->GetWebsiteUrl() : "https://" . $this->GetSettings()->GetDomain() . $team->GetNavigateUrl(), trim(html_entity_decode(strip_tags($description), ENT_QUOTES)));
     }
     unset($team_manager);
     require_once "data/csv.class.php";
     CSV::PublishData($data);
     # Test code only. Comment out CSV publish line above to enable display as a table.
     require_once "xhtml/tables/xhtml-table.class.php";
     $table = new XhtmlTable();
     $table->BindArray($data, false, false);
     echo $table;
 }
 function OnLoadPageData()
 {
     # Sanitise the name of the requested statistic
     $this->which_statistic = preg_replace("/[^a-z0-9-]/", "", $_GET["statistic"]);
     # Set up statistics manager
     $statistics_manager = new StatisticsManager($this->GetSettings(), $this->GetDataConnection());
     # Configure the requested statistic
     switch ($this->which_statistic) {
         case "individual-scores":
             require_once "stoolball/statistics/individual-scores.class.php";
             $this->statistic = new IndividualScores($statistics_manager);
             break;
         case "most-runs":
             require_once "stoolball/statistics/most-runs.class.php";
             $this->statistic = new MostRuns($statistics_manager);
             break;
         case "batting-average":
             require_once "stoolball/statistics/batting-average.class.php";
             $this->statistic = new BattingAverage($statistics_manager);
             break;
         case "batting-strike-rate":
             require_once "stoolball/statistics/batting-strike-rate.class.php";
             $this->statistic = new BattingStrikeRate($statistics_manager);
             break;
         case "bowling-performances":
             require_once "stoolball/statistics/bowling-performances.class.php";
             $this->statistic = new BowlingPerformances($statistics_manager);
             break;
         case "most-wickets":
             require_once "stoolball/statistics/most-wickets.class.php";
             $this->statistic = new MostWickets($statistics_manager);
             break;
         case "most-wickets-by-bowler-and-catcher":
             require_once "stoolball/statistics/most-wickets-by-bowler-and-catcher.class.php";
             $this->statistic = new MostWicketsForBowlerAndCatcher($statistics_manager);
             break;
         case "bowling-average":
             require_once "stoolball/statistics/bowling-average.class.php";
             $this->statistic = new BowlingAverage($statistics_manager);
             break;
         case "economy-rate":
             require_once "stoolball/statistics/economy-rate.class.php";
             $this->statistic = new EconomyRate($statistics_manager);
             break;
         case "bowling-strike-rate":
             require_once "stoolball/statistics/bowling-strike-rate.class.php";
             $this->statistic = new BowlingStrikeRate($statistics_manager);
             break;
         case "most-catches":
             require_once "stoolball/statistics/most-catches.class.php";
             $this->statistic = new MostCatches($statistics_manager);
             break;
         case "most-catches-in-innings":
             require_once "stoolball/statistics/most-catches-in-innings.class.php";
             $this->statistic = new MostCatchesInAnInnings($statistics_manager);
             break;
         case "most-run-outs":
             require_once "stoolball/statistics/most-run-outs.class.php";
             $this->statistic = new MostRunOuts($statistics_manager);
             break;
         case "most-run-outs-in-innings":
             require_once "stoolball/statistics/most-run-outs-in-innings.class.php";
             $this->statistic = new MostRunOutsInAnInnings($statistics_manager);
             break;
         case "player-performances":
             require_once "stoolball/statistics/player-performances.class.php";
             $this->statistic = new PlayerPerformances($statistics_manager);
             break;
         case "player-of-match":
             require_once "stoolball/statistics/player-of-match.class.php";
             $this->statistic = new PlayerOfTheMatch($statistics_manager);
             break;
         case "most-player-of-match":
             require_once "stoolball/statistics/most-player-of-match.class.php";
             $this->statistic = new MostPlayerOfTheMatch($statistics_manager);
             break;
         default:
             $matches = array();
             $is_match = preg_match("/^most-scores-of-([0-9]+)\$/", $this->which_statistic, $matches);
             if ($is_match === 1) {
                 $match_scores_of = $matches[1];
                 require_once "stoolball/statistics/most-scores-of.class.php";
                 $this->statistic = new MostScoresOf($match_scores_of, $statistics_manager);
             }
             $is_match = preg_match("/^most-([0-9][0-9]?)-wickets\$/", $this->which_statistic, $matches);
             if ($is_match === 1) {
                 $how_many_wickets = $matches[1];
                 require_once "stoolball/statistics/most-wicket-hauls-of.class.php";
                 $this->statistic = new \Stoolball\Statistics\MostWicketHaulsOf($how_many_wickets, $statistics_manager);
             }
             break;
     }
     # Is this a request for CSV data?
     $csv = (isset($_GET["format"]) and $_GET["format"] == "csv");
     if ($csv) {
         $statistics_manager->OutputAsCsv($this->statistic->ColumnHeaders());
     }
     # Apply player filter first because it can be used to limit the choices for other filters
     if ($this->statistic->SupportsFilterByPlayer()) {
         $this->filter .= StatisticsFilter::ApplyPlayerFilter($this->GetSettings(), $this->GetDataConnection(), $statistics_manager);
     }
     # Apply filters common to all statistics
     $this->filter_control = new StatisticsFilterControl();
     if ($this->statistic->SupportsFilterByBattingPosition()) {
         $filter_batting_position = StatisticsFilter::SupportBattingPositionFilter($statistics_manager);
         $this->filter_control->SupportBattingPositionFilter($filter_batting_position);
         $this->filter .= $filter_batting_position[2];
     }
     $match_type_filter_description = "";
     # If player filter applied, no point filtering by player type because they're associated with a team of one player type.
     # There is the edge case of a ladies team playing in a mixed match, but it would be more confusing than useful to offer it.
     if (!isset($_GET['player'])) {
         $filter_player_type = StatisticsFilter::SupportPlayerTypeFilter($statistics_manager);
         $this->filter_control->SupportPlayerTypeFilter($filter_player_type);
         $match_type_filter_description .= $filter_player_type[2];
     }
     $filter_match_type = StatisticsFilter::SupportMatchTypeFilter($statistics_manager);
     $this->filter_control->SupportMatchTypeFilter($filter_match_type);
     $match_type_filter_description .= $filter_match_type[2];
     $this->filter .= StatisticsFilter::CombineMatchTypeDescriptions($match_type_filter_description);
     # If player filter applied, no point filtering by team. Check for player filter is stricter than this
     # but this is good enough. If this applies, but the player filter isn't applied, it's because someone
     # is playing with the query string, so that's tough.
     if (!isset($_GET['player'])) {
         $filter_team = StatisticsFilter::SupportTeamFilter($statistics_manager);
         $this->filter_control->SupportTeamFilter($filter_team);
         $this->filter .= $filter_team[2];
     }
     $filter_opposition = StatisticsFilter::SupportOppositionFilter($statistics_manager);
     $this->filter_control->SupportOppositionFilter($filter_opposition);
     $this->filter .= $filter_opposition[2];
     $filter_competition = StatisticsFilter::SupportCompetitionFilter($statistics_manager);
     $this->filter_control->SupportCompetitionFilter($filter_competition);
     $this->filter .= $filter_competition[2];
     $this->filter .= StatisticsFilter::ApplySeasonFilter($this->GetSettings(), $this->GetDataConnection(), $statistics_manager);
     $filter_ground = StatisticsFilter::SupportGroundFilter($statistics_manager);
     $this->filter_control->SupportGroundFilter($filter_ground);
     $this->filter .= $filter_ground[2];
     $filter_date = StatisticsFilter::SupportDateFilter($statistics_manager);
     if (!is_null($filter_date[0])) {
         $this->filter_control->SupportAfterDateFilter($filter_date[0]);
     }
     if (!is_null($filter_date[1])) {
         $this->filter_control->SupportBeforeDateFilter($filter_date[1]);
     }
     $this->filter .= $filter_date[2];
     $this->filter .= StatisticsFilter::ApplyTournamentFilter($this->GetSettings(), $this->GetDataConnection(), $statistics_manager);
     $filter_innings = StatisticsFilter::SupportInningsFilter($statistics_manager);
     $this->filter_control->SupportInningsFilter($filter_innings[1]);
     $this->filter .= $filter_innings[2];
     $filter_won_match = StatisticsFilter::SupportMatchResultFilter($statistics_manager);
     $this->filter_control->SupportMatchResultFilter($filter_won_match[1]);
     $this->filter .= $filter_won_match[2];
     # Configure paging of results
     if (!$csv and $this->statistic->SupportsPagedResults()) {
         require_once 'data/paged-results.class.php';
         $this->paging = new PagedResults();
         $this->paging->SetPageName($this->which_statistic);
         $this->paging->SetQueryString(preg_replace("/statistic={$this->which_statistic}&?/", "", $this->paging->GetQueryString()));
         $this->paging->SetPageSize(50);
         $this->paging->SetResultsTextSingular($this->statistic->ItemTypeSingular());
         $this->paging->SetResultsTextPlural($this->statistic->ItemTypePlural());
         $statistics_manager->FilterByPage($this->paging->GetPageSize(), $this->paging->GetCurrentPage());
     }
     $this->data = $this->statistic->ReadStatistic();
     if (is_array($this->data)) {
         if ($csv) {
             require_once "data/csv.class.php";
             CSV::PublishData($this->data);
         } else {
             $this->paging->SetTotalResults(array_shift($this->data));
         }
     }
     unset($statistics_manager);
 }