/**
  * Create new TeamNameControl
  * @param Team $team
  * @param string $container_element
  */
 public function __construct(Team $team, $container_element)
 {
     parent::XhtmlElement($container_element);
     $name = $team->GetName();
     $type = is_null($team->GetPlayerType()) ? '' : PlayerType::Text($team->GetPlayerType());
     if ($type and strpos(strtolower(str_replace("'", '', $name)), strtolower(str_replace("'", '', $type))) !== false) {
         $type = "";
     }
     $town = (is_null($team->GetGround()) or is_null($team->GetGround()->GetAddress())) ? "" : $team->GetGround()->GetAddress()->GetTown();
     if ($town and strpos(strtolower($name), strtolower($town)) !== false) {
         $town = "";
     }
     if ($type or $town) {
         $html = '<span property="schema:name">' . htmlentities($name, ENT_QUOTES, "UTF-8", false) . '</span>';
         if ($town) {
             $html .= htmlentities(", {$town}", ENT_QUOTES, "UTF-8", false);
         }
         if ($type) {
             $html .= htmlentities(" ({$type})", ENT_QUOTES, "UTF-8", false);
         }
         $this->AddControl($html);
     } else {
         $this->AddAttribute("property", "schema:name");
         $this->AddControl(htmlentities($name, ENT_QUOTES, "UTF-8", false));
     }
 }
 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", "Match type", "Overs", "Player type", "Players per team", "Latitude", "Longitude", "SAON", "PAON", "Town", "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(), Date::Microformat($match->GetStartTime()), MatchType::Text($match->GetMatchType()), $match->GetOvers(), PlayerType::Text($match->GetPlayerType()), $match->GetMaximumPlayersPerTeam(), $match->GetGround() instanceof Ground ? $match->GetGround()->GetAddress()->GetLatitude() : "", $match->GetGround() instanceof Ground ? $match->GetGround()->GetAddress()->GetLongitude() : "", $match->GetGround() instanceof Ground ? $match->GetGround()->GetAddress()->GetSaon() : "", $match->GetGround() instanceof Ground ? $match->GetGround()->GetAddress()->GetPaon() : "", $match->GetGround() instanceof Ground ? $match->GetGround()->GetAddress()->GetTown() : "", "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 OnPrePageLoad()
 {
     $title = "Stoolball tournaments";
     if ($this->player_type) {
         $this->player_type_text = PlayerType::Text($this->player_type) . " ";
         if ($this->player_type == PlayerType::JUNIOR_MIXED) {
             $this->player_type_text = "Junior ";
         }
         $title = $this->player_type_text . strtolower($title);
     }
     $this->SetPageTitle($title);
     $this->SetPageDescription("See all the " . strtolower($this->player_type_text) . " stoolball tournaments taking place in the next year.");
     $this->SetContentConstraint(StoolballPage::ConstrainBox());
 }
 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 OnPrePageLoad()
 {
     $title = "Map of stoolball tournaments";
     # Check for player type
     $this->player_type = null;
     if (isset($_GET['player'])) {
         $this->player_type = PlayerType::Parse($_GET['player']);
         $this->player_type_text = PlayerType::Text($this->player_type) . " ";
         if ($this->player_type == PlayerType::JUNIOR_MIXED) {
             $this->player_type_text = "Junior ";
         }
         $title = "Map of " . strtolower($this->player_type_text) . " stoolball tournaments";
     }
     $this->SetPageTitle($title);
     $this->SetPageDescription("See a map of all the " . strtolower($this->player_type_text) . " stoolball tournaments taking place in the next year.");
     $this->LoadClientScript("/scripts/lib/markerclusterer_compiled.js");
     $this->LoadClientScript('/scripts/maps-3.js');
     $this->LoadClientScript("map.js.php?player=" . $this->player_type, true);
 }
 function OnPrePageLoad()
 {
     # Check for player type
     $this->player_type = null;
     if (isset($_GET['player'])) {
         if ($_GET['player'] == "past") {
             $this->player_type = 0;
             $this->player_type_text = "Past ";
         } else {
             $this->player_type = PlayerType::Parse($_GET['player']);
             $this->player_type_text = PlayerType::Text($this->player_type) . " ";
             if ($this->player_type == PlayerType::JUNIOR_MIXED) {
                 $this->player_type_text = "Junior ";
             }
         }
     }
     $this->SetPageTitle("Map of " . strtolower($this->player_type_text) . " stoolball teams");
     $this->SetPageDescription("See a map of all the " . strtolower($this->player_type_text) . "stoolball teams currently playing.");
     $this->LoadClientScript("/scripts/lib/markerclusterer_compiled.js");
     $this->LoadClientScript('/scripts/maps-3.js');
     $this->LoadClientScript("map.js.php?player=" . $this->player_type, true);
 }
 function OnLoadPageData()
 {
     # new data manager
     $team_manager = new TeamManager($this->GetSettings(), $this->GetDataConnection());
     $team_manager->FilterByActive(true);
     # Check for player type
     $this->player_type = null;
     if (isset($_GET['player'])) {
         if ($_GET['player'] == "past") {
             $this->player_type = 0;
             $team_manager->FilterByActive(false);
         } else {
             $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;
             }
             $team_manager->FilterByPlayerType($a_player_types);
         }
     }
     if (isset($_GET['area']) and $_GET["area"]) {
         $this->administrative_area = preg_replace('/[^a-z]/', "", strtolower($_GET['area']));
         if ($this->administrative_area) {
             $team_manager->FilterByAdministrativeArea(array($this->administrative_area));
         }
     }
     # Get the counties for the filter
     $this->areas = $team_manager->ReadAdministrativeAreas();
     if ($this->administrative_area) {
         # read all teams matching the applied filter
         $team_manager->ReadTeamSummaries();
         $this->teams = $team_manager->GetItems();
     }
     unset($team_manager);
 }
    /* @var $tournament Match */
    $description = PlayerType::Text($tournament->GetPlayerType()) . " tournament";
    if ($tournament->GetQualificationType() === MatchQualification::OPEN_TOURNAMENT) {
        $description = Html::Encode("Any team may enter this " . strtolower($description));
    } else {
        if ($tournament->GetQualificationType() === MatchQualification::CLOSED_TOURNAMENT) {
            $description .= " for invited or qualifying teams only";
        }
    }
    $description .= ". ";
    if ($tournament->GetIsMaximumPlayersPerTeamKnown()) {
        $description .= Html::Encode($tournament->GetMaximumPlayersPerTeam() . " players per team. ");
    }
    if ($tournament->GetIsOversKnown()) {
        $description .= Html::Encode("Matches are " . $tournament->GetOvers() . " overs. ");
    }
    if ($tournament->GetGround()) {
        $description .= "<br /><br />This tournament will take place at " . Html::Encode($tournament->GetGround()->GetNameAndTown()) . ". ";
    }
    if ($tournament->GetNotes()) {
        $description .= "<br /><br />" . Html::Encode($tournament->GetNotes());
    }
    $medium = $tweet ? "twitter" : "rss";
    $feedData["entries"][] = array('title' => $item_title, 'description' => $description, 'link' => "http://" . $settings->GetDomain() . $tournament->GetNavigateUrl() . "?utm_source=stoolballengland&amp;utm_medium=" . $medium . "&amp;utm_campaign=tournaments", 'guid' => $tournament->GetLinkedDataUri(), "lastUpdate" => $tournament->GetLastAudit()->GetTime(), "category" => array(array("term" => strtolower(PlayerType::Text($tournament->GetPlayerType())))));
}
// create our feed object and import the data
$feed = Zend_Feed::importArray($feedData, 'rss');
// set the Content Type of the document
header('Content-type: text/xml');
// echo the contents of the RSS xml document
echo $feed->send();
 /**
  * Creates the controls when the editor is in its season view
  *
  */
 private function CreateSeasonControls(Match $match, XhtmlElement $match_box)
 {
     /* @var $season Season */
     $css_class = 'TournamentEdit checkBoxList';
     if ($this->GetCssClass()) {
         $css_class .= ' ' . $this->GetCssClass();
     }
     $match_outer_1 = new XhtmlElement('div');
     $match_outer_1->SetCssClass($css_class);
     $this->SetCssClass('');
     $match_outer_1->SetXhtmlId($this->GetNamingPrefix());
     $match_outer_2 = new XhtmlElement('div');
     $this->AddControl($match_outer_1);
     $match_outer_1->AddControl($match_outer_2);
     $match_outer_2->AddControl($match_box);
     $heading = 'Select seasons';
     if ($this->show_step_number) {
         $heading .= ' &#8211; step 3 of 3';
     }
     $o_title_inner_1 = new XhtmlElement('span', $heading);
     $o_title_inner_2 = new XhtmlElement('span', $o_title_inner_1);
     $o_title_inner_3 = new XhtmlElement('span', $o_title_inner_2);
     $match_box->AddControl(new XhtmlElement('h2', $o_title_inner_3, "large"));
     # Preserve match title, because we need it to send the email when the seasons are saved
     $title = new TextBox($this->GetNamingPrefix() . 'Title', $match->GetTitle(), $this->IsValidSubmit());
     $title->SetMode(TextBoxMode::Hidden());
     $match_box->AddControl($title);
     # If the list of seasons includes ones in which the only match type is tournament, then
     # they're annual tournaments like Expo and Seaford. Although those tournaments can be listed
     # in other seasons (they're of interest to the league teams), we don't want other tournaments
     # listed on pages which are supposed to be just about those annual tournaments. So exclude them
     # from the collection of possible seasons. Next bit of code will add them back in for any
     # tournaments which actually are meant to be in those seasons.
     $seasons = $this->seasons->GetItems();
     $len = count($seasons);
     for ($i = 0; $i < $len; $i++) {
         # Make sure only seasons which contain tournaments are listed. Necessary to include all match types
         # in the Seasons() collection from the database so that we can test what other match types seasons support.
         if (!$seasons[$i]->MatchTypes()->Contains(MatchType::TOURNAMENT)) {
             unset($seasons[$i]);
             continue;
         }
         if ($seasons[$i]->MatchTypes()->GetCount() == 1 and $seasons[$i]->MatchTypes()->GetFirst() == MatchType::TOURNAMENT) {
             unset($seasons[$i]);
         }
     }
     $this->seasons->SetItems($seasons);
     # If the list of possible seasons doesn't include the one(s) the match is already in,
     # or the ones the context team plays in, add those to the list of possibles
     $a_season_ids = array();
     foreach ($this->seasons as $season) {
         $a_season_ids[] = $season->GetId();
     }
     foreach ($match->Seasons() as $season) {
         if (!in_array($season->GetId(), $a_season_ids, true)) {
             $this->seasons->Insert($season);
             $a_season_ids[] = $season->GetId();
         }
     }
     if (isset($this->context_team)) {
         $match_year = Date::Year($match->GetStartTime());
         foreach ($this->context_team->Seasons() as $team_in_season) {
             /* @var $team_in_season TeamInSeason */
             if (!in_array($team_in_season->GetSeasonId(), $a_season_ids, true) and ($team_in_season->GetSeason()->GetStartYear() == $match_year or $team_in_season->GetSeason()->GetEndYear() == $match_year)) {
                 $this->seasons->Insert($team_in_season->GetSeason());
                 $a_season_ids[] = $team_in_season->GetSeasonId();
             }
         }
     }
     require_once 'xhtml/forms/checkbox.class.php';
     $seasons_list = '';
     if ($this->seasons->GetCount()) {
         # Sort the seasons by name, because they've been messed up by the code above
         $this->seasons->SortByProperty('GetCompetitionName');
         $match_box->AddControl(new XhtmlElement('p', 'Tick all the places we should list your tournament:'));
         $match_box->AddControl('<div class="radioButtonList">');
         foreach ($this->seasons as $season) {
             # Select season if it's one of the seasons the match is already in
             $b_season_selected = false;
             foreach ($match->Seasons() as $match_season) {
                 $b_season_selected = ($b_season_selected or $match_season->GetId() == $season->GetId());
             }
             /* @var $season Season */
             $box = new CheckBox($this->GetNamingPrefix() . 'Season' . $season->GetId(), $season->GetCompetitionName(), $season->GetId(), $b_season_selected, $this->IsValidSubmit());
             $seasons_list .= $season->GetId() . ';';
             $match_box->AddControl($box);
         }
         $match_box->AddControl('</div>');
         # Remember all the season ids to make it much easier to find the data on postback
         $seasons = new TextBox($this->GetNamingPrefix() . 'Seasons', $seasons_list, $this->IsValidSubmit());
         $seasons->SetMode(TextBoxMode::Hidden());
         $match_box->AddControl($seasons);
     } else {
         $match_month = 'in ' . Date::MonthAndYear($match->GetStartTime());
         $type = strtolower(PlayerType::Text($match->GetPlayerType()));
         $match_box->AddControl(new XhtmlElement('p', "Unfortunately we don't have details of any {$type} competitions {$match_month} to list your tournament in."));
         $match_box->AddControl(new XhtmlElement('p', 'Please click \'Save tournament\' to continue.'));
     }
 }
 /**
  * Suggests a short URL to use to view the team
  *
  * @param int $i_preference
  * @return string
  */
 public function SuggestShortUrl($i_preference = 1)
 {
     # Base the short URL on the team name
     $s_url = strtolower(html_entity_decode($this->GetName()));
     # Remove punctuation
     $s_url = preg_replace('/[^a-z0-9 ]/i', '', $s_url);
     # Remove noise words
     $s_url = preg_replace(array('/\\bstoolball\\b/i', '/\\bclub\\b/i', '/\\bladies\\b/i', '/\\bmixed\\b/i', '/\\bsports\\b/i'), '', $s_url);
     # Apply preference
     if ($i_preference == 2) {
         # Append player type
         $s_url .= strtolower(html_entity_decode(PlayerType::Text($this->GetPlayerType())));
         $s_url = preg_replace('/[^a-z0-9 ]/i', '', $s_url);
     } else {
         if ($i_preference > 2) {
             $s_url = ShortUrl::SuggestShortUrl($s_url, $i_preference, 2, 'team');
         }
     }
     # Remove spaces
     $s_url = str_replace(' ', '-', trim($s_url));
     return $this->GetShortUrlPrefix() . $s_url;
 }
 /**
  * Get the player types available for filtering, and if a player type parameter is in the query string apply player type filter
  * @param StatisticsManager $statistics_manager
  * @return Array containing player types, current player type id, and text for filter description
  */
 public static function SupportPlayerTypeFilter(StatisticsManager $statistics_manager)
 {
     require_once "stoolball/player-type.enum.php";
     $player_types = array(PlayerType::LADIES, PlayerType::MIXED, PlayerType::GIRLS, PlayerType::JUNIOR_MIXED);
     $filter_data = array($player_types, null, "");
     if (isset($_GET['player-type']) and is_numeric($_GET['player-type'])) {
         if (in_array($_GET['player-type'], $player_types)) {
             $statistics_manager->FilterByPlayerType(array((int) $_GET['player-type']));
             $filter_data[1] = (int) $_GET['player-type'];
             $filter_data[2] .= "in " . strtolower(PlayerType::Text((int) $_GET['player-type'])) . " matches ";
         }
     }
     return $filter_data;
 }
 function CreateControls()
 {
     require_once 'xhtml/xhtml-element.class.php';
     require_once 'xhtml/forms/form-part.class.php';
     require_once 'xhtml/forms/textbox.class.php';
     $this->AddCssClass('legacy-form');
     $o_comp = $this->GetDataObject();
     /* @var $o_type IdValue */
     /* @var $o_comp Competition */
     /* @var $o_season Season */
     # add name
     $o_name_box = new TextBox('name', $o_comp->GetName(), $this->IsValidSubmit());
     $o_name_box->AddAttribute('maxlength', 100);
     $o_name = new FormPart('Competition name', $o_name_box);
     $this->AddControl($o_name);
     # Add seasons once competition saved
     if ($o_comp->GetId()) {
         $a_seasons = $o_comp->GetSeasons();
         $o_season_part = new FormPart('Seasons');
         $o_season_control = new Placeholder();
         # List exisiting seasons
         if (is_array($a_seasons) and count($a_seasons)) {
             $o_seasons = new XhtmlElement('ul');
             foreach ($a_seasons as $o_season) {
                 $o_season_link = new XhtmlAnchor(Html::Encode($o_season->GetName()), $o_season->GetEditSeasonUrl());
                 $o_seasons->AddControl(new XhtmlElement('li', $o_season_link));
             }
             $o_season_control->AddControl($o_seasons);
         }
         $o_new_season = new XhtmlAnchor('Add season', '/play/competitions/seasonedit.php?competition=' . $o_comp->GetId());
         $o_season_control->AddControl($o_new_season);
         $o_season_part->SetControl($o_season_control);
         $this->AddControl($o_season_part);
     }
     # Still going?
     $this->AddControl(new CheckBox('active', 'This competition is still played', 1, $o_comp->GetIsActive(), $this->IsValidSubmit()));
     # add player type
     $o_type_list = new XhtmlSelect('playerType', null, $this->IsValidSubmit());
     $o_type_list->AddControl(new XhtmlOption(PlayerType::Text(PlayerType::MIXED), PlayerType::MIXED));
     $o_type_list->AddControl(new XhtmlOption(PlayerType::Text(PlayerType::LADIES), PlayerType::LADIES));
     $o_type_list->AddControl(new XhtmlOption(PlayerType::Text(PlayerType::JUNIOR_MIXED), PlayerType::JUNIOR_MIXED));
     $o_type_list->AddControl(new XhtmlOption(PlayerType::Text(PlayerType::GIRLS), PlayerType::GIRLS));
     $o_type_list->AddControl(new XhtmlOption(PlayerType::Text(PlayerType::MEN), PlayerType::MEN));
     $o_type_list->AddControl(new XhtmlOption(PlayerType::Text(PlayerType::BOYS), PlayerType::BOYS));
     if (!is_null($o_comp->GetPlayerType()) and $this->IsValidSubmit()) {
         $o_type_list->SelectOption($o_comp->GetPlayerType());
     }
     $o_type_part = new FormPart('Player type', $o_type_list);
     $this->AddControl($o_type_part);
     # add players per team
     $players_box = new TextBox('players', $o_comp->GetMaximumPlayersPerTeam(), $this->IsValidSubmit());
     $players_box->SetMaxLength(2);
     $players = new FormPart('Max players in league/cup team', $players_box);
     $this->AddControl($players);
     # add overs
     $overs_box = new TextBox('overs', $o_comp->GetOvers(), $this->IsValidSubmit());
     $overs_box->SetMaxLength(2);
     $overs = new FormPart('Overs per innings', $overs_box);
     $this->AddControl($overs);
     # category
     $cat_select = new CategorySelectControl($this->categories, $this->IsValidSubmit());
     $cat_select->SetXhtmlId($this->GetNamingPrefix() . 'category');
     if (!is_null($o_comp->GetCategory()) and $this->IsValidSubmit()) {
         $cat_select->SelectOption($o_comp->GetCategory()->GetId());
     }
     $this->AddControl(new FormPart('Category', $cat_select));
     # add intro
     $o_intro_box = new TextBox('intro', $o_comp->GetIntro(), $this->IsValidSubmit());
     $o_intro_box->SetMode(TextBoxMode::MultiLine());
     $o_intro = new FormPart('Introduction', $o_intro_box);
     $this->AddControl($o_intro);
     # add contact info
     $o_contact_box = new TextBox('contact', $o_comp->GetContact(), $this->IsValidSubmit());
     $o_contact_box->SetMode(TextBoxMode::MultiLine());
     $o_contact = new FormPart('Contact details', $o_contact_box);
     $this->AddControl($o_contact);
     # Add notification email
     $o_notify_box = new TextBox('notification', $o_comp->GetNotificationEmail(), $this->IsValidSubmit());
     $o_notify_box->SetMaxLength(200);
     $o_notify = new FormPart('Notification email', $o_notify_box);
     $this->AddControl($o_notify);
     # add website
     $o_website_box = new TextBox('website', $o_comp->GetWebsiteUrl(), $this->IsValidSubmit());
     $o_website_box->SetMaxLength(250);
     $o_website = new FormPart('Website', $o_website_box);
     $this->AddControl($o_website);
     # Remember short URL
     $o_short_url = new TextBox($this->GetNamingPrefix() . 'ShortUrl', $o_comp->GetShortUrl(), $this->IsValidSubmit());
     $this->AddControl(new FormPart('Short URL', $o_short_url));
 }
 function CreateControls()
 {
     $this->AddCssClass('form');
     /* @var $club Club */
     /* @var $competition Competition */
     /* @var $season Season */
     /* @var $ground Ground */
     require_once 'xhtml/forms/textbox.class.php';
     require_once 'xhtml/forms/checkbox.class.php';
     require_once 'stoolball/season-select.class.php';
     $team = $this->GetDataObject();
     $this->SetButtonText('Save team');
     /* @var $team Team */
     $is_once_only = $team->GetTeamType() == Team::ONCE;
     if ($this->is_admin) {
         # add club
         $club_list = new XhtmlSelect('club', null, $this->IsValidSubmit());
         $club_list->SetBlankFirst(true);
         foreach ($this->a_clubs as $club) {
             if ($club instanceof Club) {
                 $opt = new XhtmlOption($club->GetName(), $club->GetId());
                 $club_list->AddControl($opt);
                 unset($opt);
             }
         }
         if (!is_null($team->GetClub()) and $this->IsValidSubmit()) {
             $club_list->SelectOption($team->GetClub()->GetId());
         }
         $club_label = new XhtmlElement('label', 'Club');
         $club_label->AddAttribute('for', $club_list->GetXhtmlId());
         $this->AddControl($club_label);
         $this->AddControl($club_list);
     }
     if ($this->is_admin or $is_once_only) {
         # add name
         $name_box = new TextBox('name', $team->GetName(), $this->IsValidSubmit());
         $name_box->AddAttribute('maxlength', 100);
         $name = new XhtmlElement('label', 'Team name');
         $name->AddAttribute('for', $name_box->GetXhtmlId());
         $this->AddControl($name);
         $this->AddControl($name_box);
     }
     if ($this->is_admin) {
         # add player type
         $type_list = new XhtmlSelect('playerType', null, $this->IsValidSubmit());
         $type_list->AddControl(new XhtmlOption(PlayerType::Text(PlayerType::MIXED), PlayerType::MIXED));
         $type_list->AddControl(new XhtmlOption(PlayerType::Text(PlayerType::LADIES), PlayerType::LADIES));
         $type_list->AddControl(new XhtmlOption(PlayerType::Text(PlayerType::JUNIOR_MIXED), PlayerType::JUNIOR_MIXED));
         $type_list->AddControl(new XhtmlOption(PlayerType::Text(PlayerType::GIRLS), PlayerType::GIRLS));
         $type_list->AddControl(new XhtmlOption(PlayerType::Text(PlayerType::MEN), PlayerType::MEN));
         $type_list->AddControl(new XhtmlOption(PlayerType::Text(PlayerType::BOYS), PlayerType::BOYS));
         if (!is_null($team->GetPlayerType()) and $this->IsValidSubmit()) {
             $type_list->SelectOption($team->GetPlayerType());
         }
         $type_part = new XhtmlElement('label', 'Player type');
         $type_part->AddAttribute('for', $type_list->GetXhtmlId());
         $this->AddControl($type_part);
         $this->AddControl($type_list);
         # Remember short URL
         $short_url = new TextBox($this->GetNamingPrefix() . 'ShortUrl', $team->GetShortUrl(), $this->IsValidSubmit());
         $short_url_label = new XhtmlElement('label', 'Short URL');
         $short_url_label->AddAttribute('for', $short_url->GetXhtmlId());
         $this->AddControl($short_url_label);
         $this->AddControl($short_url);
     }
     # add intro
     $intro_box = new TextBox('intro', $team->GetIntro(), $this->IsValidSubmit());
     $intro_box->SetMode(TextBoxMode::MultiLine());
     $intro = new XhtmlElement('label', 'Introduction');
     $intro->AddAttribute('for', $intro_box->GetXhtmlId());
     $this->AddControl($intro);
     $this->AddControl('<p class="label-hint">If you need to change your team name, please email us.</p>');
     $this->AddControl($intro_box);
     if (!$is_once_only) {
         # Can we join in?
         $team_type = new XhtmlSelect('team_type', null, $this->IsValidSubmit());
         $team_type->AddControl(new XhtmlOption("plays regularly", Team::REGULAR, $team->GetTeamType() == Team::REGULAR));
         $team_type->AddControl(new XhtmlOption("represents a league or group", Team::REPRESENTATIVE, $team->GetTeamType() == Team::REPRESENTATIVE));
         $team_type->AddControl(new XhtmlOption("closed group (example: only staff can join a work team)", Team::CLOSED_GROUP, $team->GetTeamType() == Team::CLOSED_GROUP));
         $team_type->AddControl(new XhtmlOption("plays occasionally", Team::OCCASIONAL, $team->GetTeamType() == Team::OCCASIONAL));
         $team_type->AddControl(new XhtmlOption("school year group(s)", Team::SCHOOL_YEARS, $team->GetTeamType() == Team::SCHOOL_YEARS));
         $team_type->AddControl(new XhtmlOption("school club (eg after school)", Team::SCHOOL_CLUB, $team->GetTeamType() == Team::SCHOOL_CLUB));
         $team_type->AddControl(new XhtmlOption("other school team", Team::SCHOOL_OTHER, $team->GetTeamType() == Team::SCHOOL_OTHER));
         $type_label = new XhtmlElement('label', "Type of team");
         $type_label->AddAttribute('for', $team_type->GetXhtmlId());
         $this->AddControl($type_label);
         $this->AddControl('<p class="label-hint">We use this to decide when to list your team.</p>');
         $this->AddControl($team_type);
         $school_years_data = $this->GetDataObject()->GetSchoolYears();
         $school_years = new XhtmlElement("fieldset", null, "school-years");
         $school_years->AddControl(new XhtmlElement("legend", "Select the school year(s) this team represents"));
         $school_years->AddControl(new XhtmlElement("p", "For example, if Years 7 and 8 play together, select both. If Year 9 also plays, but separately, create a separate Year 9 team."));
         $school_years->AddControl(new CheckBox('year1', 'Year 1', 1, array_key_exists(1, $school_years_data) and $school_years_data[1], $this->IsValidSubmit()));
         $school_years->AddControl(new CheckBox('year2', 'Year 2', 1, array_key_exists(2, $school_years_data) and $school_years_data[2], $this->IsValidSubmit()));
         $school_years->AddControl(new CheckBox('year3', 'Year 3', 1, array_key_exists(3, $school_years_data) and $school_years_data[3], $this->IsValidSubmit()));
         $school_years->AddControl(new CheckBox('year4', 'Year 4', 1, array_key_exists(4, $school_years_data) and $school_years_data[4], $this->IsValidSubmit()));
         $school_years->AddControl(new CheckBox('year5', 'Year 5', 1, array_key_exists(5, $school_years_data) and $school_years_data[5], $this->IsValidSubmit()));
         $school_years->AddControl(new CheckBox('year6', 'Year 6', 1, array_key_exists(6, $school_years_data) and $school_years_data[6], $this->IsValidSubmit()));
         $school_years->AddControl(new CheckBox('year7', 'Year 7', 1, array_key_exists(7, $school_years_data) and $school_years_data[7], $this->IsValidSubmit()));
         $school_years->AddControl(new CheckBox('year8', 'Year 8', 1, array_key_exists(8, $school_years_data) and $school_years_data[8], $this->IsValidSubmit()));
         $school_years->AddControl(new CheckBox('year9', 'Year 9', 1, array_key_exists(9, $school_years_data) and $school_years_data[9], $this->IsValidSubmit()));
         $school_years->AddControl(new CheckBox('year10', 'Year 10', 1, array_key_exists(10, $school_years_data) and $school_years_data[10], $this->IsValidSubmit()));
         $school_years->AddControl(new CheckBox('year11', 'Year 11', 1, array_key_exists(11, $school_years_data) and $school_years_data[11], $this->IsValidSubmit()));
         $school_years->AddControl(new CheckBox('year11', 'Year 12', 1, array_key_exists(12, $school_years_data) and $school_years_data[12], $this->IsValidSubmit()));
         $this->AddControl($school_years);
         $this->AddControl(new CheckBox('playing', 'This team still plays matches', 1, $team->GetIsActive(), $this->IsValidSubmit()));
         # add ground
         $ground_list = new XhtmlSelect('ground', null, $this->IsValidSubmit());
         foreach ($this->a_grounds as $ground) {
             if ($ground instanceof Ground) {
                 $opt = new XhtmlOption($ground->GetNameAndTown(), $ground->GetId());
                 $ground_list->AddControl($opt);
                 unset($opt);
             }
         }
         $ground = $team->GetGround();
         if (is_numeric($ground->GetId()) and $this->IsValidSubmit()) {
             $ground_list->SelectOption($ground->GetId());
         }
         $ground_label = new XhtmlElement('label', 'Where do you play?');
         $ground_label->AddAttribute('for', $ground_list->GetXhtmlId());
         $this->AddControl($ground_label);
         $this->AddControl('<p class="label-hint">If your ground isn\'t listed, please email us the address.</p>');
         $this->AddControl($ground_list);
     }
     # Add seasons
     $this->AddControl(new XhtmlElement('label', 'Leagues and competitions'));
     $this->AddControl('<p class="label-hint">We manage the leagues and competitions you\'re listed in. Please email us with any changes.</p>');
     if (!$is_once_only) {
         # add times
         $times_box = new TextBox('times', $team->GetPlayingTimes(), $this->IsValidSubmit());
         $times_box->SetMode(TextBoxMode::MultiLine());
         $times = new XhtmlElement("label", 'Which days of the week do you play, and at what time?');
         $times->AddAttribute('for', $times_box->GetXhtmlId());
         $this->AddControl($times);
         $this->AddControl($times_box);
     }
     # add cost
     $year_box = new TextBox('yearCost', $team->GetCost(), $this->IsValidSubmit());
     $year_box->SetMode(TextBoxMode::MultiLine());
     $year = new XhtmlElement('label', 'Cost to play');
     $year->AddAttribute('for', $year_box->GetXhtmlId());
     $this->AddControl($year);
     $this->AddControl('<p class="label-hint">Do you have an annual membership fee? Match fees? Special rates for juniors?</p>');
     $this->AddControl($year_box);
     # add contact info
     $contact_box = new TextBox('contact', $team->GetContact(), $this->IsValidSubmit());
     $contact_box->SetMode(TextBoxMode::MultiLine());
     $contact = new XhtmlElement('label', 'Contact details for the public');
     $contact->AddAttribute('for', $contact_box->GetXhtmlId());
     $this->AddControl($contact);
     $this->AddControl('<p class="label-hint">We recommend you publish a phone number and email so new players can get in touch.</p>');
     $this->AddControl($contact_box);
     $private_box = new TextBox('private', $team->GetPrivateContact(), $this->IsValidSubmit());
     $private_box->SetMode(TextBoxMode::MultiLine());
     $private = new XhtmlElement('label', 'Contact details for Stoolball England (if different)');
     $private->AddAttribute('for', $private_box->GetXhtmlId());
     $this->AddControl($private);
     $this->AddControl('<p class="label-hint">We won\'t share this with anyone else.</p>');
     $this->AddControl($private_box);
     # add website url
     $website_url_box = new TextBox('websiteUrl', $team->GetWebsiteUrl(), $this->IsValidSubmit());
     $website_url_box->AddAttribute('maxlength', 250);
     $website_url = new XhtmlElement('label', 'Team website');
     $website_url->AddAttribute('for', $website_url_box->GetXhtmlId());
     $this->AddControl($website_url);
     $this->AddControl($website_url_box);
 }
 /**
  * Suggests a short URL to use to view the competition
  *
  * @param int $i_preference
  * @return string
  */
 public function SuggestShortUrl($i_preference = 1)
 {
     $s_url = strtolower(html_entity_decode($this->GetName()));
     # Remove punctuation
     $s_url = preg_replace('/[^a-z ]/i', '', $s_url);
     # Remove noise words
     $s_url = preg_replace(array('/\\bstoolball\\b/i', '/\\bleague\\b/i', '/\\bladies\\b/i', '/\\bmixed\\b/i', '/\\bdistrict\\b/i', '/\\bthe\\b/i', '/\\band\\b/i', '/\\bin\\b/i', '/\\bwith\\b/i', '/\\bassociation\\b/i', '/\\bdivision\\b/i', '/\\bcounty\\b/i', '/\\bfriendlies\\b/i'), '', $s_url);
     # Apply preference
     if ($i_preference == 2) {
         # Append player type
         $s_url .= strtolower(html_entity_decode(PlayerType::Text($this->GetPlayerType())));
         $s_url = preg_replace('/[^a-z0-9 ]/i', '', $s_url);
     } else {
         if ($i_preference > 2) {
             $s_url = ShortUrl::SuggestShortUrl($s_url, $i_preference, 2);
         }
     }
     # Remove spaces
     $s_url = str_replace(' ', '', $s_url);
     return $s_url;
 }
    function OnPageLoad()
    {
        $is_tournament = $this->match->GetMatchType() == MatchType::TOURNAMENT;
        $class = $is_tournament ? "match" : "match vevent";
        ?>
        <div class="$class" typeof="schema:SportsEvent" about="<?php 
        echo Html::Encode($this->match->GetLinkedDataUri());
        ?>
">
        <?php 
        require_once 'xhtml/navigation/tabs.class.php';
        $tabs = array('Summary' => '');
        if ($is_tournament) {
            $tabs['Tournament statistics'] = $this->match->GetNavigateUrl() . '/statistics';
            # Make sure the reader knows this is a tournament, and the player type
            $says_tournament = strpos(strtolower($this->match->GetTitle()), 'tournament') !== false;
            $player_type = PlayerType::Text($this->match->GetPlayerType());
            $says_player_type = strpos(strtolower($this->match->GetTitle()), strtolower(rtrim($player_type, '\''))) !== false;
            $page_title = $this->match->GetTitle() . ", " . Date::BritishDate($this->match->GetStartTime(), false);
            if (!$says_tournament and !$says_player_type) {
                $page_title .= ' (' . $player_type . ' stoolball tournament)';
            } else {
                if (!$says_tournament) {
                    $page_title .= ' stoolball tournament';
                } else {
                    if (!$says_player_type) {
                        $page_title .= ' (' . $player_type . ')';
                    }
                }
            }
            $heading = new XhtmlElement('h1', $page_title);
            $heading->AddAttribute("property", "schema:name");
            echo $heading;
        } else {
            if ($this->match->GetMatchType() == MatchType::TOURNAMENT_MATCH) {
                $tabs['Match statistics'] = $this->match->GetNavigateUrl() . '/statistics';
                $tabs['Tournament statistics'] = $this->match->GetTournament()->GetNavigateUrl() . '/statistics';
                $page_title = $this->match->GetTitle() . " in the " . $this->match->GetTournament()->GetTitle();
            } else {
                $tabs['Statistics'] = $this->match->GetNavigateUrl() . '/statistics';
                $page_title = $this->match->GetTitle();
            }
            $o_title = new XhtmlElement('h1', Html::Encode($page_title));
            $o_title->AddAttribute("property", "schema:name");
            # hCalendar
            $o_title->SetCssClass('summary');
            $o_title_meta = new XhtmlElement('span', ' (stoolball)');
            $o_title_meta->SetCssClass('metadata');
            $o_title->AddControl($o_title_meta);
            if ($this->match->GetMatchType() !== MatchType::TOURNAMENT_MATCH) {
                $o_title->AddControl(", " . Date::BritishDate($this->match->GetStartTime(), false));
            }
            echo $o_title;
        }
        echo new Tabs($tabs);
        ?>
        <div class="box tab-box">
            <div class="dataFilter"></div>
            <div class="box-content">
        <?php 
        if ($is_tournament) {
            require_once 'stoolball/tournaments/tournament-control.class.php';
            echo new TournamentControl($this->GetSettings(), $this->match);
        } else {
            require_once 'stoolball/matches/match-control.class.php';
            echo new MatchControl($this->GetSettings(), $this->match);
        }
        $this->DisplayComments();
        $this->ShowSocial();
        ?>
            </div>
        </div>
        </div>
        <?php 
        $this->AddSeparator();
        # add/edit/delete options
        $user_is_admin = AuthenticationManager::GetUser()->Permissions()->HasPermission(PermissionType::MANAGE_MATCHES);
        $user_is_owner = AuthenticationManager::GetUser()->GetId() == $this->match->GetAddedBy()->GetId();
        $panel = new UserEditPanel($this->GetSettings(), 'this match');
        $panel->AddCssClass("with-tabs");
        if ($user_is_admin or $user_is_owner) {
            $link_text = $is_tournament ? 'tournament' : 'match';
            $panel->AddLink('edit this ' . $link_text, $this->match->GetEditNavigateUrl());
        } else {
            if ($this->match->GetMatchType() != MatchType::PRACTICE and !$is_tournament) {
                $panel->AddLink('update result', $this->match->GetEditNavigateUrl());
            }
        }
        if ($is_tournament) {
            $panel->AddCssClass("with-tabs");
            if ($user_is_admin or $user_is_owner) {
                $panel->AddLink('add or remove teams', $this->match->EditTournamentTeamsUrl());
            }
            $panel->AddLink('add or remove matches', $this->match->GetEditTournamentMatchesUrl());
            if (count($this->match->GetMatchesInTournament())) {
                $panel->AddLink('update results', $this->match->GetNavigateUrl() . "/matches/results");
            }
        }
        if ($user_is_admin or $user_is_owner) {
            if ($is_tournament) {
                $panel->AddLink('edit where to list this tournament', $this->match->EditTournamentCompetitionsUrl());
            }
            $link_text = $is_tournament ? 'tournament' : 'match';
            $panel->AddLink('delete this ' . $link_text, $this->match->GetDeleteNavigateUrl());
        }
        if ($this->match->GetMatchType() != MatchType::TOURNAMENT_MATCH and $this->match->GetStartTime() > time()) {
            $link_text = $is_tournament ? 'tournament' : 'match';
            $panel->AddLink("add {$link_text} to your calendar", $this->match->GetCalendarNavigateUrl());
        }
        echo $panel;
        if ($this->has_player_stats) {
            $tournament = $is_tournament ? $this->match : $this->match->GetTournament();
            require_once 'stoolball/statistics-highlight-table.class.php';
            echo new StatisticsHighlightTable($this->best_batting, $this->most_runs, $this->best_bowling, $this->most_wickets, $this->most_catches, "tournament");
            echo '<p class="playerSummaryMore"><a href="' . $tournament->GetNavigateUrl() . '/statistics">Tournament statistics</a></p>';
        }
    }
 private function CreateLinkToMatch(Match $match)
 {
     $text = $match->GetTitle();
     # Add player type for tournaments
     if ($match->GetPlayerType() and $match->GetMatchType() === MatchType::TOURNAMENT and strpos(strtolower($match->GetTitle()), strtolower(PlayerType::Text($match->GetPlayerType()))) === false) {
         $text .= ' (' . htmlentities(PlayerType::Text($match->GetPlayerType()), ENT_QUOTES, "UTF-8", false) . ')';
     }
     $link = new XhtmlAnchor();
     $link->AddControl(htmlentities($text, ENT_QUOTES, "UTF-8", false));
     $link->SetNavigateUrl($match->GetNavigateUrl());
     if ($this->b_microformats) {
         $link->SetCssClass('summary url');
         # hCalendar
         $link->AddAttribute("rel", "schema:url");
         $link->AddAttribute("property", "schema:name");
         $title_meta = new XhtmlElement('span', ' (stoolball)');
         $title_meta->SetCssClass('metadata');
         $link->AddControl($title_meta);
     }
     return $link;
 }
 function OnPreRender()
 {
     /* @var $match Match */
     /* @var $o_home Team */
     /* @var $o_away Team */
     $match = $this->match;
     $player_type = PlayerType::Text($match->GetPlayerType());
     # Show time and place
     $date = new XhtmlElement('p', 'When: ' . $match->GetStartTimeFormatted());
     $date->AddAttribute("property", "schema:startDate");
     $date->AddAttribute("datatype", "xsd:date");
     $date->AddAttribute("content", Date::Microformat($match->GetStartTime()));
     $this->AddControl($date);
     # If we know the time and place, show when the sun sets
     # TODO: assumes UK
     if ($match->GetGround() instanceof Ground and $match->GetGround()->GetAddress()->GetLatitude() and $match->GetGround()->GetAddress()->GetLongitude()) {
         $date->AddControl(' <span class="sunset">sunset ' . Date::Time(date_sunset($match->GetStartTime(), SUNFUNCS_RET_TIMESTAMP, $match->GetGround()->GetAddress()->GetLatitude(), $match->GetGround()->GetAddress()->GetLongitude())) . '</span>');
     }
     $ground = $match->GetGround();
     if (is_object($ground)) {
         $ground_link = new XhtmlElement('a', $ground->GetNameAndTown());
         $ground_link->AddAttribute('href', $ground->GetNavigateUrl());
         $ground_link->SetCssClass('location');
         # hCalendar
         $ground_link->AddAttribute("typeof", "schema:Place");
         $ground_link->AddAttribute("about", $ground->GetLinkedDataUri());
         $ground_link->AddAttribute("rel", "schema:url");
         $ground_link->AddAttribute("property", "schema:name");
         $ground_control = new XhtmlElement('p', 'Where: ');
         $ground_control->AddAttribute("rel", "schema:location");
         $ground_control->AddControl($ground_link);
         $this->AddControl($ground_control);
     }
     # Format
     if ($match->GetIsOversKnown()) {
         $this->AddControl(new XhtmlElement("p", "Matches are " . $match->GetOvers() . " overs."));
     }
     # Add teams
     $a_teams = $match->GetAwayTeams();
     if (!is_array($a_teams)) {
         $a_teams = array();
     }
     if (!is_null($match->GetHomeTeam())) {
         array_unshift($a_teams, $match->GetHomeTeam());
     }
     # shouldn't be home teams any more, but doesn't hurt!
     $how_many_teams = count($a_teams);
     $qualification = $match->GetQualificationType();
     if ($qualification === MatchQualification::OPEN_TOURNAMENT) {
         $qualification = "Any " . strtolower($player_type) . " team may enter this tournament. ";
     } else {
         if ($qualification === MatchQualification::CLOSED_TOURNAMENT) {
             $qualification = "Only invited or qualifying teams may enter this tournament. ";
         } else {
             $qualification = "";
         }
     }
     $show_spaces_left = ($match->GetMaximumTeamsInTournament() and gmdate('U') < $match->GetStartTime() and $match->GetQualificationType() !== MatchQualification::CLOSED_TOURNAMENT);
     if ($match->GetIsMaximumPlayersPerTeamKnown() or $show_spaces_left or $how_many_teams or $qualification) {
         $this->AddControl(new XhtmlElement('h2', 'Teams'));
     }
     $who_can_play = "";
     if ($match->GetIsMaximumPlayersPerTeamKnown()) {
         $who_can_play = Html::Encode($match->GetMaximumPlayersPerTeam() . " players per team. ");
     }
     $who_can_play .= Html::Encode($qualification);
     if ($show_spaces_left) {
         $who_can_play .= '<strong class="spaces-left">' . $match->GetSpacesLeftInTournament() . " spaces left.</strong>";
     }
     if ($who_can_play) {
         $this->AddControl("<p>" . trim($who_can_play) . "</p>");
     }
     if ($how_many_teams) {
         $teams = new TeamListControl($a_teams);
         $this->AddControl('<div rel="schema:performers">' . $teams . '</div>');
     }
     # Add matches
     $a_matches = $match->GetMatchesInTournament();
     if (is_array($a_matches) && count($a_matches)) {
         $o_hmatches = new XhtmlElement('h2', 'Matches');
         $matches = new MatchListControl($a_matches);
         $matches->AddAttribute("rel", "schema:subEvents");
         $this->AddControl($o_hmatches);
         $this->AddControl($matches);
     }
     # Add notes
     if ($match->GetNotes() or $match->Seasons()->GetCount() > 0) {
         $this->AddControl(new XhtmlElement('h2', 'Notes'));
     }
     if ($match->GetNotes()) {
         $s_notes = XhtmlMarkup::ApplyCharacterEntities($match->GetNotes());
         require_once 'email/email-address-protector.class.php';
         $protector = new EmailAddressProtector($this->settings);
         $s_notes = $protector->ApplyEmailProtection($s_notes, AuthenticationManager::GetUser()->IsSignedIn());
         $s_notes = XhtmlMarkup::ApplyHeadings($s_notes);
         $s_notes = XhtmlMarkup::ApplyParagraphs($s_notes);
         $s_notes = XhtmlMarkup::ApplyLists($s_notes);
         $s_notes = XhtmlMarkup::ApplySimpleTags($s_notes);
         $s_notes = XhtmlMarkup::ApplyLinks($s_notes);
         if (strpos($s_notes, '<p>') > -1) {
             $this->AddControl($s_notes);
         } else {
             $this->AddControl(new XhtmlElement('p', $s_notes));
         }
     }
     # Show details of the seasons
     if ($match->Seasons()->GetCount() == 1) {
         $season = $match->Seasons()->GetFirst();
         $season_name = new XhtmlAnchor($season->GetCompetitionName(), $season->GetNavigateUrl());
         $b_the = !(stristr($season->GetCompetitionName(), 'the ') === 0);
         $this->AddControl(new XhtmlElement('p', 'This tournament is listed in ' . ($b_the ? 'the ' : '') . $season_name->__toString() . '.'));
     } elseif ($match->Seasons()->GetCount() > 1) {
         $this->AddControl(new XhtmlElement('p', 'This tournament is listed in the following seasons: '));
         $season_list = new XhtmlElement('ul');
         $this->AddControl($season_list);
         $seasons = $match->Seasons()->GetItems();
         $total_seasons = count($seasons);
         for ($i = 0; $i < $total_seasons; $i++) {
             $season = $seasons[$i];
             /* @var $season Season */
             $season_name = new XhtmlAnchor($season->GetCompetitionName(), $season->GetNavigateUrl());
             $li = new XhtmlElement('li', $season_name);
             if ($i < $total_seasons - 2) {
                 $li->AddControl(new XhtmlElement('span', ', ', 'metadata'));
             } else {
                 if ($i < $total_seasons - 1) {
                     $li->AddControl(new XhtmlElement('span', ' and ', 'metadata'));
                 }
             }
             $season_list->AddControl($li);
         }
     }
 }
    /**
     * Build the form
     */
    protected function OnPreRender()
    {
        $this->AddControl('<div id="statisticsFilter" class="panel"><div><div><h2><span><span><span>Filter these statistics</span></span></span></h2>');
        # Track whether to show or hide this filter
        $filter = '<input type="hidden" id="filter" name="filter" value="';
        $filter .= (isset($_GET["filter"]) and $_GET["filter"] == "1") ? 1 : 0;
        $filter .= '" />';
        $this->AddControl($filter);
        $type_filters = array();
        # Support player type filter
        if (is_array($this->player_type_filter)) {
            require_once "stoolball/player-type.enum.php";
            $player_type_list = new XhtmlSelect("player-type");
            $blank = new XhtmlOption("any players", "");
            $player_type_list->AddControl($blank);
            foreach ($this->player_type_filter[0] as $player_type) {
                $player_type_list->AddControl(new XhtmlOption(strtolower(PlayerType::Text($player_type)), $player_type, $player_type === $this->player_type_filter[1]));
            }
            $label = new XhtmlElement("label", "Type of players", "aural");
            $label->AddAttribute("for", $player_type_list->GetXhtmlId());
            $type_filters[] = $label;
            $type_filters[] = $player_type_list;
        }
        # Support match type filter
        if (is_array($this->match_type_filter)) {
            require_once "stoolball/match-type.enum.php";
            $match_type_list = new XhtmlSelect("match-type");
            $blank = new XhtmlOption("any match", "");
            $match_type_list->AddControl($blank);
            foreach ($this->match_type_filter[0] as $match_type) {
                $match_type_list->AddControl(new XhtmlOption(str_replace(" match", "", MatchType::Text($match_type)), $match_type, $match_type === $this->match_type_filter[1]));
            }
            $label = new XhtmlElement("label", "Type of competition", "aural");
            $label->AddAttribute("for", $match_type_list->GetXhtmlId());
            $type_filters[] = $label;
            $type_filters[] = $match_type_list;
        }
        if (count($type_filters)) {
            $type = new XhtmlElement("fieldset", new XhtmlElement("legend", "Match type", "formLabel"), "formPart");
            $controls = new XhtmlElement("div", null, "formControl");
            foreach ($type_filters as $control) {
                $controls->AddControl($control);
            }
            $type->AddControl($controls);
            $this->AddControl($type);
        }
        # Support team filter
        if (is_array($this->team_filter)) {
            $team_list = new XhtmlSelect("team");
            $blank = new XhtmlOption("any team", "");
            $team_list->AddControl($blank);
            foreach ($this->team_filter[0] as $team) {
                $team_list->AddControl(new XhtmlOption($team->GetName(), $team->GetId(), $team->GetId() == $this->team_filter[1]));
            }
            $this->AddControl(new FormPart("Team", $team_list));
        }
        # Support opposition team filter
        if (is_array($this->opposition_filter)) {
            $opposition_list = new XhtmlSelect("opposition");
            $blank = new XhtmlOption("any team", "");
            $opposition_list->AddControl($blank);
            foreach ($this->opposition_filter[0] as $team) {
                $opposition_list->AddControl(new XhtmlOption($team->GetName(), $team->GetId(), $team->GetId() == $this->opposition_filter[1]));
            }
            $this->AddControl(new FormPart("Against", $opposition_list));
        }
        # Support ground filter
        if (is_array($this->ground_filter)) {
            $ground_list = new XhtmlSelect("ground");
            $blank = new XhtmlOption("any ground", "");
            $ground_list->AddControl($blank);
            foreach ($this->ground_filter[0] as $ground) {
                $ground_list->AddControl(new XhtmlOption($ground->GetNameAndTown(), $ground->GetId(), $ground->GetId() == $this->ground_filter[1]));
            }
            $this->AddControl(new FormPart("Ground", $ground_list));
        }
        # Support competition filter
        if (is_array($this->competition_filter)) {
            $competition_list = new XhtmlSelect("competition");
            $blank = new XhtmlOption("any competition", "");
            $competition_list->AddControl($blank);
            foreach ($this->competition_filter[0] as $competition) {
                $competition_list->AddControl(new XhtmlOption($competition->GetName(), $competition->GetId(), $competition->GetId() == $this->competition_filter[1]));
            }
            $this->AddControl(new FormPart("Competition", $competition_list));
        }
        # Support date filter
        # Use text fields rather than HTML 5 date fields because then we can accept dates like "last Tuesday"
        # which PHP will understand. Jquery calendar is at least  as good as native date pickers anyway.
        $date_fields = '<div class="formPart">
			<label for="from" class="formLabel">From date</label>
			<div class="formControl twoFields">
			<input type="text" class="date firstField" id="from" name="from" placeholder="any date" autocomplete="off"';
        if (!$this->IsValid()) {
            $date_fields .= ' value="' . (isset($_GET["from"]) ? $_GET["from"] : "") . '"';
        } else {
            if ($this->after_date_filter) {
                $date_fields .= ' value="' . Date::BritishDate($this->after_date_filter, false, true, false) . '"';
            }
        }
        $date_fields .= ' />
			<label for="to">Up to date
			<input type="text" class="date" id="to" name="to" placeholder="any date" autocomplete="off"';
        if (!$this->IsValid()) {
            $date_fields .= ' value="' . (isset($_GET["to"]) ? $_GET["to"] : "") . '"';
        } else {
            if ($this->before_date_filter) {
                $date_fields .= ' value="' . Date::BritishDate($this->before_date_filter, false, true, false) . '"';
            }
        }
        $date_fields .= ' /></label>
			</div>
			</div>';
        $this->AddControl($date_fields);
        # Support innings filter
        $innings_list = new XhtmlSelect("innings");
        $innings_list->AddControl(new XhtmlOption("either innings", ""));
        $innings_list->AddControl(new XhtmlOption("first innings", 1, 1 == $this->innings_filter));
        $innings_list->AddControl(new XhtmlOption("second innings", 2, 2 == $this->innings_filter));
        $this->AddControl('<div class="formPart">
        <label for="innings" class="formLabel">Innings</label>
        <div class="formControl">' . $innings_list . '</div>' . '</div>');
        # Support batting position filter
        if (is_array($this->batting_position_filter)) {
            $batting_position_list = new XhtmlSelect("batpos");
            $blank = new XhtmlOption("any position", "");
            $batting_position_list->AddControl($blank);
            foreach ($this->batting_position_filter[0] as $batting_position) {
                $batting_position_list->AddControl(new XhtmlOption($batting_position == 1 ? "opening" : $batting_position, $batting_position, $batting_position == $this->batting_position_filter[1]));
            }
            $this->AddControl('<div class="formPart">
			<label for="batpos" class="formLabel">Batting at</label>
			<div class="formControl">' . $batting_position_list . '</div>' . '</div>');
        }
        # Support match result filter
        $result_list = new XhtmlSelect("result");
        $result_list->AddControl(new XhtmlOption("any result", ""));
        $result_list->AddControl(new XhtmlOption("win", 1, 1 === $this->match_result_filter));
        $result_list->AddControl(new XhtmlOption("tie", 0, 0 === $this->match_result_filter));
        $result_list->AddControl(new XhtmlOption("lose", -1, -1 === $this->match_result_filter));
        $this->AddControl('<div class="formPart">
        <label for="result" class="formLabel">Match result</label>
        <div class="formControl">' . $result_list . '</div>' . '</div>');
        # Preserve the player filter if applied
        if (isset($_GET["player"]) and is_numeric($_GET["player"])) {
            $this->AddControl('<input type="hidden" name="player" id="player" value="' . $_GET["player"] . '" />');
        }
        $this->AddControl('<p class="actions"><input type="submit" value="Apply filter" /></p>');
        $this->AddControl('</div></div></div>');
    }