/**
  * Instantiates a SupportedContentControl
  *
  * @param XhtmlElement $o_all_content
  */
 public function __construct(XhtmlElement $o_all_content)
 {
     parent::XhtmlElement('div');
     $this->SetCssClass('supportedContentContainer');
     $o_all_content->AddCssClass('supportedContent');
     $this->AddControl($o_all_content);
 }
 /**
  * Add a link to the panel
  *
  * @param string $s_text
  * @param string $s_url
  */
 public function AddLink($s_text, $s_url, $class = "")
 {
     $link = new XhtmlAnchor(htmlentities($s_text, ENT_QUOTES, "UTF-8", false), $s_url);
     $item = new XhtmlElement('li', $link);
     if ($class) {
         $item->AddCssClass($class);
     }
     $this->a_links[] = $item;
 }
 /**
  * Sets up controls for page 4 of the wizard
  * @param Match $match
  * @return void
  */
 private function CreateHighlightsControls(Match $match)
 {
     $b_got_teams = !(is_null($match->GetHomeTeam()) || is_null($match->GetAwayTeam()));
     // Move CSS class to div element
     $match_outer_1 = new XhtmlElement('div');
     $match_outer_1->SetCssClass('matchResultEdit panel');
     $match_outer_2 = new XhtmlElement('div');
     $match_box = new XhtmlElement('div');
     $this->AddControl($match_outer_1);
     $match_outer_1->AddControl($match_outer_2);
     $match_outer_2->AddControl($match_box);
     $o_title_inner_1 = new XhtmlElement('span', "Match highlights");
     $o_title_inner_2 = new XhtmlElement('span', $o_title_inner_1);
     $o_title_inner_3 = new XhtmlElement('span', $o_title_inner_2);
     $o_heading = new XhtmlElement('h2', $o_title_inner_3);
     $match_box->AddControl($o_heading);
     # Who's playing?
     $o_home_name = new TextBox($this->GetNamingPrefix() . 'Home');
     $o_away_name = new TextBox($this->GetNamingPrefix() . 'Away');
     $o_home_name->SetMode(TextBoxMode::Hidden());
     $o_away_name->SetMode(TextBoxMode::Hidden());
     if (!is_null($match->GetHomeTeam())) {
         $o_home_name->SetText($match->GetHomeTeam()->GetId() . MatchHighlightsEditControl::DATA_SEPARATOR . $match->GetHomeTeam()->GetName());
     }
     if (!is_null($match->GetAwayTeam())) {
         $o_away_name->SetText($match->GetAwayTeam()->GetId() . MatchHighlightsEditControl::DATA_SEPARATOR . $match->GetAwayTeam()->GetName());
     }
     $this->AddControl($o_home_name);
     $this->AddControl($o_away_name);
     # When? (for validator message only)
     $when = new TextBox($this->GetNamingPrefix() . 'Date', $match->GetStartTime());
     $when->SetMode(TextBoxMode::Hidden());
     $this->AddControl($when);
     # Who won?
     $o_winner = new XhtmlSelect($this->GetNamingPrefix() . 'Result');
     $o_winner->AddControl(new XhtmlOption("Don't know", ''));
     $result_types = array(MatchResult::HOME_WIN, MatchResult::AWAY_WIN, MatchResult::TIE, MatchResult::ABANDONED);
     foreach ($result_types as $result_type) {
         if ($b_got_teams) {
             $o_winner->AddControl(new XhtmlOption($this->NameTeams(MatchResult::Text($result_type), $match->GetHomeTeam(), $match->GetAwayTeam()), $result_type));
         } else {
             $o_winner->AddControl(new XhtmlOption(MatchResult::Text($result_type), $result_type));
         }
     }
     if ($this->IsValidSubmit()) {
         if ($match->Result()->GetResultType() == MatchResult::UNKNOWN and !is_null($match->Result()->GetHomeRuns()) and !is_null($match->Result()->GetAwayRuns())) {
             # If match result is not known but we can guess from the entered scores, select it
             if ($match->Result()->GetHomeRuns() > $match->Result()->GetAwayRuns()) {
                 $o_winner->SelectOption(MatchResult::HOME_WIN);
             } else {
                 if ($match->Result()->GetHomeRuns() < $match->Result()->GetAwayRuns()) {
                     $o_winner->SelectOption(MatchResult::AWAY_WIN);
                 } else {
                     if ($match->Result()->GetHomeRuns() == $match->Result()->GetAwayRuns()) {
                         $o_winner->SelectOption(MatchResult::TIE);
                     }
                 }
             }
         } else {
             $o_winner->SelectOption($match->Result()->GetResultType());
         }
     }
     $o_win_part = new FormPart('Who won?', $o_winner);
     $match_box->AddControl($o_win_part);
     # Get current player of match
     $player = $match->Result()->GetPlayerOfTheMatch();
     $home_player = $match->Result()->GetPlayerOfTheMatchHome();
     $away_player = $match->Result()->GetPlayerOfTheMatchAway();
     $current_pom = MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_NONE;
     if ($player instanceof Player) {
         $current_pom = MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_OVERALL;
     } else {
         if ($home_player instanceof Player or $away_player instanceof Player) {
             $current_pom = MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_HOME_AND_AWAY;
         }
     }
     # Choose from different types of player of the match
     require_once 'xhtml/forms/radio-button.class.php';
     $pom_container = new XhtmlElement('fieldset', new XhtmlElement('legend', 'Player of the match', 'formLabel'));
     $pom_container->SetCssClass('formPart');
     $pom_options = new XhtmlElement('div', null, 'formControl radioButtonList');
     $pom_options->SetXhtmlId($this->GetNamingPrefix() . "PlayerOptions");
     $pom_container->AddControl($pom_options);
     $match_box->AddControl($pom_container);
     $pom_options->AddControl(new RadioButton($this->GetNamingPrefix() . 'POM' . MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_NONE, $this->GetNamingPrefix() . 'POM', "none chosen", MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_NONE, $current_pom == MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_NONE, $this->IsValidSubmit()));
     $pom_options->AddControl(new RadioButton($this->GetNamingPrefix() . 'POM' . MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_OVERALL, $this->GetNamingPrefix() . 'POM', "yes, one chosen", MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_OVERALL, $current_pom == MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_OVERALL, $this->IsValidSubmit()));
     $pom_options->AddControl(new RadioButton($this->GetNamingPrefix() . 'POM' . MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_HOME_AND_AWAY, $this->GetNamingPrefix() . 'POM', "yes, one from each team", MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_HOME_AND_AWAY, $current_pom == MatchHighlightsEditControl::PLAYER_OF_THE_MATCH_HOME_AND_AWAY, $this->IsValidSubmit()));
     # Controls for entering a single player of the match
     $player_name = new TextBox($this->GetNamingPrefix() . 'Player', $player instanceof Player ? $player->GetName() : '', $this->IsValidSubmit());
     $player_name->SetMaxLength(100);
     $player_name->AddCssClass("player");
     $player_name->AddCssClass("team" . $match->GetHomeTeamId());
     $player_name->AddCssClass("team" . $match->GetAwayTeamId());
     $player_name->AddAttribute("autocomplete", "off");
     $player_box = new XhtmlElement("div", $player_name);
     $player_team = new XhtmlSelect($this->GetNamingPrefix() . "PlayerTeam", " playing for", $this->IsValidSubmit());
     $player_team->SetCssClass("playerTeam");
     # for JS
     $player_team->AddControl(new XhtmlOption("Don't know", ""));
     $player_team->AddControl(new XhtmlOption($match->GetHomeTeam()->GetName(), $match->GetHomeTeamId()));
     $player_team->AddControl(new XhtmlOption($match->GetAwayTeam()->GetName(), $match->GetAwayTeamId()));
     if ($player instanceof Player) {
         $player_team->SelectOption($player->Team()->GetId());
     }
     $player_box->AddControl($player_team);
     $player_part = new FormPart("Player's name", $player_box);
     $player_part->SetXhtmlId($this->GetNamingPrefix() . "OnePlayer");
     $player_part->GetLabel()->AddAttribute("for", $player_name->GetXhtmlId());
     $match_box->AddControl($player_part);
     # Controls for entering home and away players of the match
     $home_box = new TextBox($this->GetNamingPrefix() . 'PlayerHome', $home_player instanceof Player ? $home_player->GetName() : '', $this->IsValidSubmit());
     $home_box->SetMaxLength(100);
     $home_box->AddCssClass("player");
     $home_box->AddCssClass("team" . $match->GetHomeTeamId());
     $home_box->AddAttribute("autocomplete", "off");
     $home_part = new FormPart($this->NameTeams('Home player', $match->GetHomeTeam(), $match->GetAwayTeam()), $home_box);
     $home_part->SetCssClass("formPart multiPlayer");
     $match_box->AddControl($home_part);
     $away_box = new TextBox($this->GetNamingPrefix() . 'PlayerAway', $away_player instanceof Player ? $away_player->GetName() : '', $this->IsValidSubmit());
     $away_box->SetMaxLength(100);
     $away_box->AddCssClass("player");
     $away_box->AddCssClass("team" . $match->GetAwayTeamId());
     $away_box->AddAttribute("autocomplete", "off");
     $away_part = new FormPart($this->NameTeams('Away player', $match->GetHomeTeam(), $match->GetAwayTeam()), $away_box);
     $away_part->SetCssClass("formPart multiPlayer");
     $match_box->AddControl($away_part);
     # Any comments?
     $comments = new TextBox($this->GetNamingPrefix() . 'Comments', '', $this->IsValidSubmit());
     $comments->SetMode(TextBoxMode::MultiLine());
     $comments->AddAttribute('class', 'matchReport');
     $comments_label = new XhtmlElement('label');
     $comments_label->AddAttribute('for', $comments->GetXhtmlId());
     $comments_label->AddCssClass('matchReport');
     $comments_label->AddControl('Add a match report:');
     $match_box->AddControl($comments_label);
     $match_box->AddControl($comments);
     if ($match->GetLastAudit() != null) {
         require_once "data/audit-control.class.php";
         $match_box->AddControl(new AuditControl($match->GetLastAudit(), "match"));
     }
     $this->SetButtonText('Save match');
 }
 protected function CreateControls()
 {
     $o_match = $this->GetDataObject();
     /* @var $o_match Match */
     $b_got_teams = !(is_null($o_match->GetHomeTeam()) || is_null($o_match->GetAwayTeam()));
     $b_future = ($o_match->GetId() and $o_match->GetStartTime() > gmdate('U'));
     // Move CSS class to div element
     $o_match_outer_1 = new XhtmlElement('div');
     if ($this->GetCssClass()) {
         $o_match_outer_1->SetCssClass('matchResultEdit ' . $this->GetCssClass());
     } else {
         $o_match_outer_1->SetCssClass('matchResultEdit');
     }
     $this->SetCssClass('');
     $o_match_outer_2 = new XhtmlElement('div');
     $o_match_box = new XhtmlElement('div');
     $this->AddControl($o_match_outer_1);
     $o_match_outer_1->AddControl($o_match_outer_2);
     $o_match_outer_2->AddControl($o_match_box);
     if ($this->GetShowHeading()) {
         $s_heading = str_replace('{0}', $o_match->GetTitle(), $this->GetHeading());
         $s_heading = str_replace('{1}', Date::BritishDate($o_match->GetStartTime(), false), $s_heading);
         $o_title_inner_1 = new XhtmlElement('span', htmlentities($s_heading, ENT_QUOTES, "UTF-8", false));
         $o_title_inner_2 = new XhtmlElement('span', $o_title_inner_1);
         $o_title_inner_3 = new XhtmlElement('span', $o_title_inner_2);
         $o_heading = new XhtmlElement($this->b_in_section ? 'h3' : 'h2', $o_title_inner_3);
         $o_match_box->AddControl($o_heading);
     }
     # Who's playing?
     $o_home_name = new TextBox($this->GetNamingPrefix() . 'Home');
     $o_away_name = new TextBox($this->GetNamingPrefix() . 'Away');
     $o_home_name->SetMode(TextBoxMode::Hidden());
     $o_away_name->SetMode(TextBoxMode::Hidden());
     if (!is_null($o_match->GetHomeTeam())) {
         $o_home_name->SetText($o_match->GetHomeTeam()->GetId() . ";" . $o_match->GetHomeTeam()->GetName());
     }
     if (!is_null($o_match->GetAwayTeam())) {
         $o_away_name->SetText($o_match->GetAwayTeam()->GetId() . ";" . $o_match->GetAwayTeam()->GetName());
     }
     $this->AddControl($o_home_name);
     $this->AddControl($o_away_name);
     # When? (for validator message only)
     $when = new TextBox($this->GetNamingPrefix() . 'Date', $o_match->GetStartTime());
     $when->SetMode(TextBoxMode::Hidden());
     $this->AddControl($when);
     # Who batted first?
     if (!$b_future) {
         $o_bat_first = new XhtmlSelect($this->GetNamingPrefix() . 'BatFirst');
         $o_bat_first->AddControl(new XhtmlOption("Don't know", ''));
         if ($b_got_teams) {
             $o_bat_first->AddControl(new XhtmlOption($o_match->GetHomeTeam()->GetName(), 'home'));
             $o_bat_first->AddControl(new XhtmlOption($o_match->GetAwayTeam()->GetName(), 'away'));
         } else {
             $o_bat_first->AddControl(new XhtmlOption('Home team', 'home'));
             $o_bat_first->AddControl(new XhtmlOption('Away team', 'away'));
         }
         if (!is_null($o_match->Result()->GetHomeBattedFirst())) {
             if ($o_match->Result()->GetHomeBattedFirst()) {
                 $o_bat_first->SelectOption('home');
             } else {
                 $o_bat_first->SelectOption('away');
             }
         }
         $o_bat_part = new FormPart('Who batted first?', $o_bat_first);
         $o_match_box->AddControl($o_bat_part);
     }
     # Who won?
     $o_winner = new XhtmlSelect($this->GetNamingPrefix() . 'Result');
     $o_winner->AddControl(new XhtmlOption($b_future ? 'The match will go ahead' : "Don't know", ''));
     $result_types = array(MatchResult::HOME_WIN, MatchResult::AWAY_WIN, MatchResult::HOME_WIN_BY_FORFEIT, MatchResult::AWAY_WIN_BY_FORFEIT, MatchResult::TIE, MatchResult::POSTPONED, MatchResult::CANCELLED, MatchResult::ABANDONED);
     if ($o_match->GetMatchType() == MatchType::TOURNAMENT_MATCH) {
         # You don't postpone a match in a tournament for another day
         unset($result_types[array_search(MatchResult::POSTPONED, $result_types, true)]);
     }
     foreach ($result_types as $result_type) {
         if (!$b_future or MatchResult::PossibleInAdvance($result_type)) {
             if ($b_got_teams) {
                 $o_winner->AddControl(new XhtmlOption($this->NameTeams(MatchResult::Text($result_type), $o_match->GetHomeTeam(), $o_match->GetAwayTeam()), $result_type));
             } else {
                 $o_winner->AddControl(new XhtmlOption(MatchResult::Text($result_type), $result_type));
             }
         }
     }
     $o_winner->SelectOption($o_match->Result()->GetResultType());
     $o_win_part = new FormPart($b_future ? 'Will it happen?' : 'Who won?', $o_winner);
     $o_match_box->AddControl($o_win_part);
     # If the match has already happened
     if (!$b_future) {
         # What did each team score?
         $this->CreateTeamScoreControls($o_match_box, 'Home', $o_match, $o_match->GetHomeTeam(), $o_match->Result()->GetHomeRuns(), $o_match->Result()->GetHomeWickets());
         $this->CreateTeamScoreControls($o_match_box, 'Away', $o_match, $o_match->GetAwayTeam(), $o_match->Result()->GetAwayRuns(), $o_match->Result()->GetAwayWickets());
         # Any comments?
         $comments = new TextBox($this->GetNamingPrefix() . 'Comments', '', $this->IsValidSubmit());
         $comments->SetMode(TextBoxMode::MultiLine());
         $comments->AddAttribute('class', 'matchReport');
         $comments_label = new XhtmlElement('label');
         $comments_label->AddAttribute('for', $comments->GetXhtmlId());
         $comments_label->AddCssClass('matchReport');
         $comments_label->AddControl('Add a match report:');
         $o_match_box->AddControl($comments_label);
         $o_match_box->AddControl($comments);
     }
     # Show audit data
     if ($o_match->GetLastAudit() != null) {
         require_once "data/audit-control.class.php";
         $o_match_box->AddControl(new AuditControl($o_match->GetLastAudit(), "match"));
     }
 }
 public function CreateControls()
 {
     $this->AddCssClass('form');
     require_once 'xhtml/forms/textbox.class.php';
     $this->SetButtonText('Save school');
     $school = $this->GetDataObject();
     /* @var $school School */
     # Get ground id
     $ground_id = new TextBox('ground-id', $school->Ground()->GetId(), $this->IsValidSubmit());
     $ground_id->SetMode(TextBoxMode::Hidden());
     $this->AddControl($ground_id);
     # add name
     $name_box = new TextBox('school-name', $school->Ground()->GetAddress()->GetPaon(), $this->IsValidSubmit());
     $name_box->AddAttribute('maxlength', 100);
     $name_box->AddAttribute('autocomplete', "off");
     $name = new XhtmlElement('label', 'School name');
     $name->AddAttribute('for', $name_box->GetXhtmlId());
     $this->AddControl($name);
     $this->AddControl($name_box);
     # add street
     $street_box = new TextBox('street', $school->Ground()->GetAddress()->GetStreetDescriptor(), $this->IsValidSubmit());
     $street_box->AddAttribute('maxlength', 250);
     $street_box->AddAttribute('autocomplete', "off");
     $street_box->AddCssClass("street");
     $street = new XhtmlElement('label', 'Road');
     $street->AddAttribute('for', $street_box->GetXhtmlId());
     $this->AddControl($street);
     $this->AddControl($street_box);
     # add locality
     $locality_box = new TextBox('locality', $school->Ground()->GetAddress()->GetLocality(), $this->IsValidSubmit());
     $locality_box->AddAttribute('maxlength', 250);
     $locality_box->AddAttribute('autocomplete', "off");
     $locality_box->AddCssClass("town");
     $locality = new XhtmlElement('label', 'Part of town');
     $locality->AddAttribute('for', $locality_box->GetXhtmlId());
     $this->AddControl($locality);
     $this->AddControl($locality_box);
     # add town
     $town_box = new TextBox('town', $school->Ground()->GetAddress()->GetTown(), $this->IsValidSubmit());
     $town_box->AddAttribute('maxlength', 100);
     $town_box->AddAttribute('autocomplete', "off");
     $town_box->AddCssClass("town");
     $town = new XhtmlElement('label', 'Town or village');
     $town->AddAttribute('for', $town_box->GetXhtmlId());
     $this->AddControl($town);
     $this->AddControl($town_box);
     # add administrative area
     $county_box = new TextBox('county', $school->Ground()->GetAddress()->GetAdministrativeArea(), $this->IsValidSubmit());
     $county_box->AddAttribute('maxlength', 100);
     $county_box->AddAttribute('autocomplete', "off");
     $county_box->AddCssClass("county");
     $county = new XhtmlElement('label', 'County');
     $county->AddAttribute('for', $county_box->GetXhtmlId());
     $this->AddControl($county);
     $this->AddControl($county_box);
     # add postcode
     $postcode_box = new TextBox('postcode', $school->Ground()->GetAddress()->GetPostcode(), $this->IsValidSubmit());
     $postcode_box->AddAttribute('maxlength', 8);
     $postcode_box->AddAttribute('autocomplete', "off");
     $postcode_box->AddCssClass("postcode");
     $postcode = new XhtmlElement('label', 'Postcode');
     $postcode->AddAttribute('for', $postcode_box->GetXhtmlId());
     $this->AddControl($postcode);
     $this->AddControl($postcode_box);
     # add lat/long
     $latitude = new TextBox('latitude', $school->Ground()->GetAddress()->GetLatitude(), $this->IsValidSubmit());
     $latitude->SetMode(TextBoxMode::Hidden());
     $this->AddControl($latitude);
     $longitude = new TextBox('longitude', $school->Ground()->GetAddress()->GetLongitude(), $this->IsValidSubmit());
     $longitude->SetMode(TextBoxMode::Hidden());
     $this->AddControl($longitude);
     $geoprecision = new TextBox('geoprecision', $school->Ground()->GetAddress()->GetGeoPrecision(), $this->IsValidSubmit());
     $geoprecision->SetMode(TextBoxMode::Hidden());
     $this->AddControl($geoprecision);
     # placeholder for client-side map
     $map = new XhtmlElement('div', null, "#map");
     $map->AddCssClass("map");
     $this->AddControl($map);
 }
 protected function CreateControls()
 {
     $o_match = $this->GetDataObject();
     if (is_null($o_match)) {
         $o_match = new Match($this->GetSettings());
     }
     /* @var $o_match Match */
     /* @var $o_team Team */
     $b_got_home = !is_null($o_match->GetHomeTeam());
     $b_got_away = !is_null($o_match->GetAwayTeam());
     $b_is_new_match = !(bool) $o_match->GetId();
     $b_is_tournament_match = false;
     if ($this->i_match_type == MatchType::TOURNAMENT_MATCH) {
         $b_is_tournament_match = $this->tournament instanceof Match;
     } else {
         if ($o_match->GetMatchType() == MatchType::TOURNAMENT_MATCH and $o_match->GetTournament() instanceof Match) {
             $this->SetTournament($o_match->GetTournament());
             $this->SetMatchType($o_match->GetMatchType());
             $b_is_tournament_match = true;
         }
     }
     $o_match_outer_1 = new XhtmlElement('div');
     $o_match_outer_1->SetCssClass('MatchFixtureEdit');
     $o_match_outer_1->AddCssClass($this->GetCssClass());
     $this->SetCssClass('');
     $o_match_outer_1->SetXhtmlId($this->GetNamingPrefix());
     $o_match_outer_2 = new XhtmlElement('div');
     $o_match_box = new XhtmlElement('div');
     $this->AddControl($o_match_outer_1);
     $o_match_outer_1->AddControl($o_match_outer_2);
     $o_match_outer_2->AddControl($o_match_box);
     if ($this->GetShowHeading()) {
         $s_heading = str_replace('{0}', MatchType::Text($this->i_match_type), $this->GetHeading());
         # Add match type if required
         $o_title_inner_1 = new XhtmlElement('span', htmlentities($s_heading, ENT_QUOTES, "UTF-8", false));
         $o_title_inner_2 = new XhtmlElement('span', $o_title_inner_1);
         $o_title_inner_3 = new XhtmlElement('span', $o_title_inner_2);
         $o_match_box->AddControl(new XhtmlElement('h2', $o_title_inner_3, "medium large"));
     }
     # Offer choice of season if appropriate
     $season_count = $this->seasons->GetCount();
     if ($season_count == 1 and $this->i_match_type != MatchType::PRACTICE) {
         $o_season_id = new TextBox($this->GetNamingPrefix() . 'Season', $this->seasons->GetFirst()->GetId());
         $o_season_id->SetMode(TextBoxMode::Hidden());
         $o_match_box->AddControl($o_season_id);
     } elseif ($season_count > 1 and $this->i_match_type != MatchType::PRACTICE) {
         $o_season_id = new XhtmlSelect($this->GetNamingPrefix() . 'Season', '', $this->IsValidSubmit());
         foreach ($this->Seasons()->GetItems() as $season) {
             $o_season_id->AddControl(new XhtmlOption($season->GetCompetitionName(), $season->GetId()));
         }
         $o_match_box->AddControl(new FormPart('Competition', $o_season_id));
     }
     # Start date and time
     $match_time_known = (bool) $o_match->GetStartTime();
     if (!$match_time_known) {
         # if no date set, use specified default
         if ($this->i_default_time) {
             $o_match->SetStartTime($this->i_default_time);
             if ($b_is_tournament_match) {
                 $o_match->SetIsStartTimeKnown(false);
             }
         } else {
             # if no date set and no default, default to today at 6.30pm BST
             $i_now = gmdate('U');
             $o_match->SetStartTime(gmmktime(17, 30, 00, (int) gmdate('n', $i_now), (int) gmdate('d', $i_now), (int) gmdate('Y', $i_now)));
         }
     }
     $o_date = new DateControl($this->GetNamingPrefix() . 'Start', $o_match->GetStartTime(), $o_match->GetIsStartTimeKnown(), $this->IsValidSubmit());
     $o_date->SetShowTime(true);
     $o_date->SetRequireTime(false);
     $o_date->SetMinuteInterval(5);
     # if no date set and only one season to choose from, limit available dates to the length of that season
     if (!$match_time_known and $season_count == 1) {
         if ($this->Seasons()->GetFirst()->GetStartYear() == $this->Seasons()->GetFirst()->GetEndYear()) {
             $i_mid_season = gmmktime(0, 0, 0, 6, 30, $this->Seasons()->GetFirst()->GetStartYear());
         } else {
             $i_mid_season = gmmktime(0, 0, 0, 12, 31, $this->Seasons()->GetFirst()->GetStartYear());
         }
         $season_dates = Season::SeasonDates($i_mid_season);
         $season_start_month = gmdate('n', $season_dates[0]);
         $season_end_month = gmdate('n', $season_dates[1]);
         if ($season_start_month) {
             $o_date->SetMonthStart($season_start_month);
         }
         if ($season_end_month) {
             $o_date->SetMonthEnd($season_end_month + 1);
         }
         // TODO: need a better way to handle this, allowing overlap. Shirley has indoor matches until early April.
         $season_start_year = $this->Seasons()->GetFirst()->GetStartYear();
         $season_end_year = $this->Seasons()->GetFirst()->GetEndYear();
         if ($season_start_year) {
             $o_date->SetYearStart($season_start_year);
         }
         if ($season_end_year) {
             $o_date->SetYearEnd($season_end_year);
         }
     }
     if ($b_is_tournament_match) {
         $o_date->SetShowDate(false);
         $o_date->SetShowTime(false);
         $o_match_box->AddControl($o_date);
     } else {
         $o_date_part = new FormPart('When?', $o_date);
         $o_date_part->SetIsFieldset(true);
         $o_match_box->AddControl($o_date_part);
     }
     # Who's playing?
     if ($this->i_match_type == MatchType::PRACTICE and isset($this->context_team)) {
         $home_id = new TextBox($this->GetNamingPrefix() . 'Home', $this->context_team->GetId());
         $home_id->SetMode(TextBoxMode::Hidden());
         $away_id = new TextBox($this->GetNamingPrefix() . 'Away', $this->context_team->GetId());
         $away_id->SetMode(TextBoxMode::Hidden());
         $o_match_box->AddControl($home_id);
         $o_match_box->AddControl($away_id);
     } else {
         $o_home_list = new XhtmlSelect($this->GetNamingPrefix() . 'Home');
         $o_away_list = new XhtmlSelect($this->GetNamingPrefix() . 'Away');
         $first_real_team_index = 0;
         if ($this->b_user_is_admin) {
             # Option of not specifying teams is currently admin-only
             # Value of 0 is important because PHP sees it as boolean negative, but it can be used as the indexer of an array in JavaScript
             $o_home_list->AddControl(new XhtmlOption("Don't know yet", '0'));
             $o_away_list->AddControl(new XhtmlOption("Don't know yet", '0'));
             $first_real_team_index = 1;
         }
         foreach ($this->a_teams as $group_name => $teams) {
             foreach ($teams as $o_team) {
                 $home_option = new XhtmlOption($o_team->GetName(), $o_team->GetId());
                 if (is_string($group_name) and $group_name) {
                     $home_option->SetGroupName($group_name);
                 }
                 $o_home_list->AddControl($home_option);
                 $away_option = new XhtmlOption($o_team->GetName(), $o_team->GetId());
                 if (is_string($group_name) and $group_name) {
                     $away_option->SetGroupName($group_name);
                 }
                 $o_away_list->AddControl($away_option);
             }
         }
         $o_home_part = new FormPart('Home team', $o_home_list);
         $o_away_part = new FormPart('Away team', $o_away_list);
         $o_match_box->AddControl($o_home_part);
         $o_match_box->AddControl($o_away_part);
         if ($b_got_home) {
             $o_home_list->SelectOption($o_match->GetHomeTeamId());
         }
         if (!$b_got_home and $b_is_new_match) {
             // if no home team data, select the first team by default
             // unless editing a match, in which case it may be correct to have no teams (eg cup final)
             $o_home_list->SelectIndex($first_real_team_index);
         }
         if (!$b_got_away and $b_is_new_match) {
             // if no away team data, select the second team as the away team so that it's not the same as the first
             // unless editing a match, in which case it may be correct to have no teams (eg cup final).
             $o_away_list->SelectIndex($first_real_team_index + 1);
             // if there was a home team but not an away team, make sure we don't select the home team against itself
             if ($b_got_home and $o_away_list->GetSelectedValue() == (string) $o_match->GetHomeTeamId()) {
                 $o_away_list->SelectIndex($first_real_team_index);
             }
         } else {
             if ($b_got_away) {
                 $o_away_list->SelectOption($o_match->GetAwayTeamId());
             }
             if (!$b_is_new_match) {
                 # Note which away team was previously saved, even if it's "not known" - this is for JavaScript to know it shouldn't auto-change the away team
                 $away_saved = new TextBox($this->GetNamingPrefix() . 'SavedAway', $o_match->GetAwayTeamId());
                 $away_saved->SetMode(TextBoxMode::Hidden());
                 $o_match_box->AddControl($away_saved);
                 unset($away_saved);
             }
         }
     }
     # Where?
     # If tournament match, assume same ground as tournament. Otherwise ask the user for ground.
     if ($b_is_tournament_match) {
         $ground = new TextBox($this->GetNamingPrefix() . 'Ground', $this->tournament->GetGroundId() ? $this->tournament->GetGroundId() : $o_match->GetGroundId());
         $ground->SetMode(TextBoxMode::Hidden());
         $o_match_box->AddControl($ground);
     } else {
         $o_ground_list = new XhtmlSelect($this->GetNamingPrefix() . 'Ground');
         $o_ground_list->AddControl(new XhtmlOption("Don't know", -1));
         $o_ground_list->AddControl(new XhtmlOption('Not listed (type the address in the notes field)', -2));
         # Promote home grounds for this season to the top of the list
         $a_home_ground_ids = array();
         foreach ($this->a_teams as $teams) {
             foreach ($teams as $o_team) {
                 $a_home_ground_ids[$o_team->GetId()] = $o_team->GetGround()->GetId();
             }
         }
         $a_home_grounds = array();
         $a_other_grounds = array();
         /* @var $o_ground Ground */
         foreach ($this->a_grounds as $o_ground) {
             if (array_search($o_ground->GetId(), $a_home_ground_ids) > -1) {
                 $a_home_grounds[] = $o_ground;
             } else {
                 $a_other_grounds[] = $o_ground;
             }
         }
         # Add home grounds
         foreach ($a_home_grounds as $o_ground) {
             $option = new XhtmlOption($o_ground->GetNameAndTown(), $o_ground->GetId());
             $option->SetGroupName('Home grounds');
             $o_ground_list->AddControl($option);
         }
         # Add away grounds
         foreach ($a_other_grounds as $o_ground) {
             $option = new XhtmlOption($o_ground->GetNameAndTown(), $o_ground->GetId());
             $option->SetGroupName('Away grounds');
             $o_ground_list->AddControl($option);
         }
         # Select ground
         if ($o_match->GetGroundId()) {
             $o_ground_list->SelectOption($o_match->GetGroundId());
         } elseif ($this->i_match_type == MatchType::PRACTICE and isset($this->context_team)) {
             $o_ground_list->SelectOption($this->context_team->GetGround()->GetId());
         }
         $o_ground_part = new FormPart('Where?', $o_ground_list);
         $o_match_box->AddControl($o_ground_part);
         # Note which grounds belong to which teams, for use by match-fixture-edit-control.js to select a ground when the home team is changed
         # Format is 1,2;2,3;4,5
         # where ; separates each team, and for each team the first number identifies the team and the second is the ground
         $s_team_ground = '';
         foreach ($a_home_ground_ids as $i_team => $i_ground) {
             if ($s_team_ground) {
                 $s_team_ground .= ';';
             }
             $s_team_ground .= $i_team . ',' . $i_ground;
         }
         $o_hidden = new TextBox($this->GetNamingPrefix() . 'TeamGround', $s_team_ground);
         $o_hidden->SetMode(TextBoxMode::Hidden());
         $o_match_box->AddControl($o_hidden);
         unset($o_hidden);
         # Note which ground was previously saved - this is for JavaScript to know it shouldn't auto-change the ground
         if (!$b_is_new_match) {
             $o_hidden = new TextBox($this->GetNamingPrefix() . 'SavedGround', $o_match->GetGroundId());
             $o_hidden->SetMode(TextBoxMode::Hidden());
             $o_match_box->AddControl($o_hidden);
             unset($o_hidden);
         }
     }
     # Notes
     $o_notes = new TextBox($this->GetNamingPrefix() . 'Notes', $o_match->GetNotes());
     $o_notes->SetMode(TextBoxMode::MultiLine());
     $o_notes_part = new FormPart('Notes', $o_notes);
     $o_match_box->AddControl($o_notes_part);
     # Remember match type, tournament and short URL
     $o_type = new TextBox($this->GetNamingPrefix() . 'MatchType', $this->GetMatchType());
     $o_type->SetMode(TextBoxMode::Hidden());
     $o_match_box->AddControl($o_type);
     if ($b_is_tournament_match) {
         $tourn_box = new TextBox($this->GetNamingPrefix() . 'Tournament', $this->tournament->GetId());
         $tourn_box->SetMode(TextBoxMode::Hidden());
         $o_match_box->AddControl($tourn_box);
     }
     $o_short_url = new TextBox($this->GetNamingPrefix() . 'ShortUrl', $o_match->GetShortUrl());
     $o_short_url->SetMode(TextBoxMode::Hidden());
     $o_match_box->AddControl($o_short_url);
     # Note the context team - to be picked up by JavaScript to enable auto-changing of away team if
     # context team is not selected as home team
     if (isset($this->context_team)) {
         $context_team_box = new TextBox($this->GetNamingPrefix() . 'ContextTeam', $this->context_team->GetId());
         $context_team_box->SetMode(TextBoxMode::Hidden());
         $o_match_box->AddControl($context_team_box);
     }
 }
 /**
  * Creates standard controls used by most data edit forms
  *
  */
 protected function OnPreRender()
 {
     require_once 'xhtml/forms/textbox.class.php';
     require_once 'xhtml/forms/checkbox.class.php';
     require_once 'xhtml/forms/xhtml-select.class.php';
     # add id
     if (is_object($this->o_data_object) and method_exists($this->o_data_object, 'GetId') and $this->o_data_object->GetId()) {
         $o_id_box = new TextBox($this->s_naming_prefix . 'item', (string) $this->o_data_object->GetId());
         $o_id_box->SetMode(TextBoxMode::Hidden());
         $this->AddControl($o_id_box);
     }
     # Add save button if building the form
     # Add at top of form to trap enter key
     if ($this->b_render_base_element) {
         $o_buttons = new XhtmlElement('div');
         $o_buttons->AddCssClass($this->show_buttons_at_top ? 'buttonGroup buttonGroupTop' : 'buttonGroup aural');
         $o_save = new XhtmlElement('input');
         $o_save->SetEmpty(true);
         $o_save->AddAttribute('type', 'submit');
         $o_save->SetXhtmlId($this->GetNamingPrefix() . 'DataEditSave');
         $o_save->AddAttribute('name', $o_save->GetXhtmlId());
         $o_buttons->AddControl($o_save);
         if ($this->show_buttons_at_top and $this->GetAllowCancel()) {
             require_once 'xhtml/forms/button.class.php';
             $o_buttons->AddControl(new Button($this->GetNamingPrefix() . 'DataEditCancel', 'Cancel'));
         }
         $this->AddControl($o_buttons);
     }
     # fire event for child class to create its controls
     $this->CreateControls();
     # Add a second save button
     if ($this->b_render_base_element) {
         $o_save->AddAttribute('value', $this->GetButtonText());
         # Allow button text to be set late
         $o_save2 = clone $o_save;
         $o_save2->SetXhtmlId($this->GetNamingPrefix() . 'DataEditSave2');
         $o_save2->AddAttribute('name', $o_save2->GetXhtmlId());
         $o_save2->AddCssClass('primary');
         $o_buttons2 = new XhtmlElement('div');
         $o_buttons2->SetCssClass('buttonGroup');
         $o_buttons2->AddControl($o_save2);
         if ($this->GetAllowCancel()) {
             if (!$this->show_buttons_at_top) {
                 require_once 'xhtml/forms/button.class.php';
             }
             $cancel = new Button($this->GetNamingPrefix() . 'DataEditCancel2', 'Cancel');
             $cancel->SetCssClass('cancel');
             $o_buttons2->AddControl($cancel);
         }
         $this->AddControl($o_buttons2);
     }
     # Add page number if it's not the default
     if ($this->current_page != 1) {
         $page = new TextBox($this->GetNamingPrefix() . 'Page', $this->GetCurrentPage(), $this->IsValidSubmit());
         $page->SetMode(TextBoxMode::Hidden());
         $this->AddControl($page);
     }
     # to be valid, should all be in a div
     $o_container = new XhtmlElement('div');
     $o_container->SetControls($this->GetControls());
     if (!$this->b_render_base_element) {
         $o_container->SetCssClass($this->GetCssClass());
         $o_container->SetXhtmlId($this->GetXhtmlId());
     }
     $a_controls = array();
     $a_controls[] = $o_container;
     $this->SetControls($a_controls);
 }
 private function AddMetadata(Match $match, XhtmlElement $li)
 {
     $li->AddCssClass('vevent');
     # hCalendar
     $li->AddAttribute("typeof", "schema:SportsEvent");
     $li->AddAttribute("about", $match->GetLinkedDataUri());
     $meta = new XhtmlElement('span');
     $meta->SetCssClass('metadata');
     # hCalendar end date
     if ($match->GetStartTime() and $match->GetIsStartTimeKnown()) {
         $end_date = $this->CreateEndDate($match);
         $meta->AddControl($end_date);
     }
     # hCalendar location
     if (!is_null($match->GetGround())) {
         $ground = new XhtmlElement('span', htmlentities($match->GetGround()->GetNameAndTown(), ENT_QUOTES, "UTF-8", false));
         $ground->SetCssClass('location');
         $meta->AddControl(' at ');
         $meta->AddControl($ground);
     }
     # hCalendar description
     $hcal_desc = new XhtmlElement('span');
     $hcal_desc->SetCssClass('description');
     $i_seasons = $match->Seasons()->GetCount();
     if ($i_seasons) {
         $meta->AddControl(' in ');
         $seasons = $match->Seasons()->GetItems();
         for ($i = 0; $i < $i_seasons; $i++) {
             $b_last = ($i > 0 and $i == $i_seasons - 1);
             if ($i > 0 and !$b_last) {
                 $hcal_desc->AddControl(', ');
             } elseif ($b_last) {
                 $hcal_desc->AddControl(' and ');
             }
             $hcal_desc->AddControl(htmlentities($seasons[$i]->GetCompetitionName(), ENT_QUOTES, "UTF-8", false));
         }
     }
     if (!$match->GetIsStartTimeKnown()) {
         $hcal_desc->AddControl('. Start time not known');
     }
     if ($hcal_desc->CountControls()) {
         $meta->AddControl($hcal_desc);
     }
     # hCalendar timestamp
     $meta->AddControl('. At ');
     $hcal_stamp = new XhtmlElement('abbr', htmlentities(Date::Time(gmdate('U')), ENT_QUOTES, "UTF-8", false));
     $hcal_stamp->SetTitle(Date::Microformat());
     $hcal_stamp->SetCssClass('dtstamp');
     $meta->AddControl($hcal_stamp);
     # hCalendar GUID
     $meta->AddControl(' match ');
     $hcal_guid = new XhtmlElement('span', htmlentities($match->GetLinkedDataUri(), ENT_QUOTES, "UTF-8", false));
     $hcal_guid->SetCssClass('uid');
     $meta->AddControl($hcal_guid);
     # hCalendar status
     $s_status = 'CONFIRMED';
     switch ($match->Result()->GetResultType()) {
         case MatchResult::CANCELLED:
         case MatchResult::POSTPONED:
         case MatchResult::AWAY_WIN_BY_FORFEIT:
         case MatchResult::HOME_WIN_BY_FORFEIT:
             $s_status = 'CANCELLED';
     }
     $meta->AddControl(' is ');
     $status = new XhtmlElement('span', $s_status);
     $status->SetCssClass('status');
     $meta->AddControl($status);
     $meta->AddControl('.');
     $li->AddControl($meta);
 }