/**
  * 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');
 }
 function OnPreRender()
 {
     if ($this->b_show_date) {
         # create dropdown menu for day of month
         $o_day = new XhtmlSelect($this->GetXhtmlId() . '_day', '', $this->b_page_valid);
         if (!$this->GetRequireDate()) {
             $o_day->AddControl(new XhtmlOption());
         }
         for ($i = 1; $i <= 31; $i++) {
             $o_day->AddControl(new XhtmlOption($i, $i));
         }
         if ($this->i_timestamp != null and !($this->b_page_valid === false)) {
             $o_day->SelectOption(date('j', $this->i_timestamp));
         }
         # create label, and add controls
         $o_day_label = new XhtmlElement('label', 'Day');
         $o_day_label->AddAttribute('for', $o_day->GetXhtmlId());
         $o_day_label->SetCssClass('aural');
         $this->AddControl($o_day_label);
         $this->AddControl($o_day);
         # create dropdown menu for month
         $o_month = new XhtmlSelect($this->GetXhtmlId() . '_month', '', $this->b_page_valid);
         if (!$this->GetRequireDate()) {
             $o_month->AddControl(new XhtmlOption());
         }
         if ($this->month_end > $this->month_start) {
             for ($i = $this->month_start; $i <= $this->month_end; $i++) {
                 $s_monthname = date('F', gmmktime(0, 0, 0, $i, 1, 0));
                 $o_month->AddControl(new XhtmlOption($s_monthname, $i));
             }
         } else {
             # Support order of  Oct, Nov, Dec, Jan, Feb Mar
             for ($i = $this->month_start; $i <= 12; $i++) {
                 $s_monthname = date('F', gmmktime(0, 0, 0, $i, 1, 0));
                 $o_month->AddControl(new XhtmlOption($s_monthname, $i));
             }
             for ($i = 1; $i <= $this->month_end; $i++) {
                 $s_monthname = date('F', gmmktime(0, 0, 0, $i, 1, 0));
                 $o_month->AddControl(new XhtmlOption($s_monthname, $i));
             }
         }
         if ($this->i_timestamp != null and !($this->b_page_valid === false)) {
             $o_month->SelectOption(date('n', $this->i_timestamp));
         }
         # create label, and add controls
         $o_month_label = new XhtmlElement('label', 'Month');
         $o_month_label->AddAttribute('for', $o_month->GetXhtmlId());
         $o_month_label->SetCssClass('aural');
         $this->AddControl($o_month_label);
         $this->AddControl($o_month);
         # create dropdown for year
         if ($this->GetRequireDate() and $this->year_start == $this->year_end) {
             # If there's only one possible value for year and it's required, just hard-code it
             $o_year = new TextBox($this->GetXhtmlId() . '_year', $this->year_start, $this->b_page_valid);
             $o_year->SetMode(TextBoxMode::Hidden());
             $this->AddControl($o_year);
             $this->AddControl(' ' . $this->year_start);
         } else {
             $o_year = new XhtmlSelect($this->GetXhtmlId() . '_year', '', $this->b_page_valid);
             if (!$this->GetRequireDate()) {
                 $o_year->AddControl(new XhtmlOption());
             }
             for ($i = $this->year_start; $i <= $this->year_end; $i++) {
                 $o_option = new XhtmlOption($i, $i);
                 $o_year->AddControl($o_option);
             }
             if ($this->i_timestamp != null and !($this->b_page_valid === false)) {
                 $o_year->SelectOption(date('Y', $this->i_timestamp));
             }
             # create label, and add controls
             $o_year_label = new XhtmlElement('label', 'Year');
             $o_year_label->AddAttribute('for', $o_year->GetXhtmlId());
             $o_year_label->SetCssClass('aural');
             $this->AddControl($o_year_label);
             $this->AddControl($o_year);
         }
     } else {
         $o_day = new TextBox($this->GetXhtmlId() . '_day');
         $o_day->SetMode(TextBoxMode::Hidden());
         $o_day->SetText(date('j', $this->i_timestamp));
         $this->AddControl($o_day);
         $o_month = new TextBox($this->GetXhtmlId() . '_month');
         $o_month->SetMode(TextBoxMode::Hidden());
         $o_month->SetText(date('n', $this->i_timestamp));
         $this->AddControl($o_month);
         $o_year = new TextBox($this->GetXhtmlId() . '_year');
         $o_year->SetMode(TextBoxMode::Hidden());
         $o_year->SetText(date('Y', $this->i_timestamp));
         $this->AddControl($o_year);
     }
     if ($this->b_show_time) {
         if ($this->b_show_date) {
             $this->AddControl(' ');
         }
         $this->AddControl('<span class="time">');
         if ($this->b_show_date) {
             $this->AddControl('at ');
         }
         # create dropdown menu for hour
         $o_hour = new XhtmlSelect($this->GetXhtmlId() . '_hour', '', $this->b_page_valid);
         if (!$this->GetRequireTime()) {
             $o_hour->AddControl(new XhtmlOption());
         }
         for ($i = 1; $i <= 12; $i++) {
             $o_hour->AddControl(new XhtmlOption($i, $i));
         }
         if ($this->i_timestamp != null and $this->b_time_known and !($this->b_page_valid === false)) {
             $o_hour->SelectOption(date('g', $this->i_timestamp));
         }
         # create label, and add controls
         $o_hour_label = new XhtmlElement('label', 'Hour');
         $o_hour_label->AddAttribute('for', $o_hour->GetXhtmlId());
         $o_hour_label->SetCssClass('aural');
         $this->AddControl($o_hour_label);
         $this->AddControl($o_hour);
         # create dropdown menu for minute
         $o_minute = new XhtmlSelect($this->GetXhtmlId() . '_minute', '', $this->b_page_valid);
         if (!$this->GetRequireTime()) {
             $o_minute->AddControl(new XhtmlOption());
         }
         for ($i = 0; $i <= 59; $i++) {
             if ($i % $this->i_minute_interval == 0) {
                 $s_minute = $i > 9 ? (string) $i : "0" . (string) $i;
                 $o_minute->AddControl(new XhtmlOption($s_minute, $s_minute));
             }
         }
         if ($this->i_timestamp != null and $this->b_time_known and !($this->b_page_valid === false)) {
             $o_minute->SelectOption(date('i', $this->i_timestamp));
         }
         # create label, and add controls
         $o_min_label = new XhtmlElement('label', 'Minutes');
         $o_min_label->AddAttribute('for', $o_minute->GetXhtmlId());
         $o_min_label->SetCssClass('aural');
         $this->AddControl($o_min_label);
         $this->AddControl($o_minute);
         # create dropdown menu for am/pm
         $o_ampm = new XhtmlSelect($this->GetXhtmlId() . '_ampm', '', $this->b_page_valid);
         if (!$this->GetRequireTime()) {
             $o_ampm->AddControl(new XhtmlOption());
         }
         $o_ampm->AddControl(new XhtmlOption('am', 'am'));
         $o_ampm->AddControl(new XhtmlOption('pm', 'pm'));
         if ($this->i_timestamp != null and $this->b_time_known and !($this->b_page_valid === false)) {
             $o_ampm->SelectOption(date('a', $this->i_timestamp));
         }
         # create label, and add controls
         $o_ampm_label = new XhtmlElement('label', 'AM or PM');
         $o_ampm_label->AddAttribute('for', $o_ampm->GetXhtmlId());
         $o_ampm_label->SetCssClass('aural');
         $this->AddControl($o_ampm_label);
         $this->AddControl($o_ampm);
         $this->AddControl('</span>');
     } else {
         $o_hour = new TextBox($this->GetXhtmlId() . '_hour');
         $o_hour->SetMode(TextBoxMode::Hidden());
         if ($this->b_time_known) {
             $o_hour->SetText(date('g', $this->i_timestamp));
         }
         $this->AddControl($o_hour);
         $o_minute = new TextBox($this->GetXhtmlId() . '_minute');
         $o_minute->SetMode(TextBoxMode::Hidden());
         if ($this->b_time_known) {
             $o_minute->SetText(date('i', $this->i_timestamp));
         }
         $this->AddControl($o_minute);
         $o_ampm = new TextBox($this->GetXhtmlId() . '_ampm');
         $o_ampm->SetMode(TextBoxMode::Hidden());
         if ($this->b_time_known) {
             $o_ampm->SetText(date('a', $this->i_timestamp));
         }
         $this->AddControl($o_ampm);
     }
 }
 protected function OnPreRender()
 {
     require_once 'xhtml/forms/textbox.class.php';
     parent::AddControl('<div>');
     # div inside form required by XHTML
     # persist params as requested
     foreach ($this->a_persisted_params as $s_param) {
         $s_param = trim($s_param);
         $a_fields = $this->IsPostback() ? $_POST : $_GET;
         if (isset($a_fields[$s_param])) {
             $o_param_box = new TextBox($s_param);
             $o_param_box->SetText($a_fields[$s_param]);
             $o_param_box->SetMode(TextBoxMode::Hidden());
             parent::AddControl($o_param_box);
             unset($o_param_box);
         }
     }
     # add default buttons
     if ($this->b_show_buttons_at_top) {
         parent::AddControl($this->CreateDefaultButtons());
     }
     # display validator errors
     if (!$this->IsValid() and $this->GetShowValidationErrors()) {
         require_once 'data/validation/validation-summary.class.php';
         $a_controls = array($this);
         parent::AddControl(new ValidationSummary($a_controls));
     }
     # Adjust headings
     if ($this->b_show_sections) {
         foreach ($this->a_edit_controls as $o_control) {
             $o_control->SetIsInSection(true);
         }
     } else {
         foreach ($this->a_section_headings as $o_heading) {
             $i_key = array_search($o_heading, $this->a_controls_to_render, true);
             if (!($i_key === false)) {
                 if (array_key_exists($i_key, $this->a_controls_to_render)) {
                     unset($this->a_controls_to_render[$i_key]);
                 }
             }
         }
     }
     # Add the edit controls themselves, one at a time so that they're streamed
     foreach ($this->a_controls_to_render as $control) {
         parent::AddControl($control);
     }
     # add ids
     $a_items = $this->GetDataObjects();
     $s_item_ids = '';
     foreach ($a_items as $o_data_object) {
         if (is_object($o_data_object) and method_exists($o_data_object, 'GetId')) {
             if ($s_item_ids) {
                 $s_item_ids .= ';';
             }
             $s_item_ids .= $o_data_object->GetId();
         }
     }
     if ($s_item_ids) {
         $o_id_box = new TextBox('items', $s_item_ids);
         $o_id_box->SetMode(TextBoxMode::Hidden());
         parent::AddControl($o_id_box);
     }
     # add default buttons
     parent::AddControl($this->CreateDefaultButtons());
     parent::AddControl('</div>');
     # div inside form required by XHTML
 }
 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"));
     }
 }
 /**
  * Creates, and re-populates on postback, non-editable text with an associated id
  *
  * @param string $s_validated_value
  * @param string $s_name
  * @param int $i_row_count
  * @param int $i_total_rows
  * @param bool $b_required
  * @return TextBox
  */
 protected function CreateNonEditableText($i_validated_id, $s_validated_value, $s_name, $i_row_count, $i_total_rows)
 {
     # Establish current status
     $b_is_add_row = is_null($i_row_count);
     $b_repopulate_add_row = (!$this->IsValid() or $this->DeleteClicked() or $this->IsUnrelatedInternalPostback());
     # Create text boxes
     $textbox_id = new TextBox($this->GetNamingPrefix() . $s_name . $i_row_count);
     $textbox_id->SetMode(TextBoxMode::Hidden());
     $textbox_value = new TextBox($this->GetNamingPrefix() . $s_name . 'Value' . $i_row_count);
     $textbox_value->SetMode(TextBoxMode::Hidden());
     # Repopulate the previous value
     # If this is the row used to add a new related item...
     if ($b_is_add_row) {
         # ...if we repopulate, it'll be with the exact value posted,
         # as validation has either failed or not occurred
         if ($b_repopulate_add_row and isset($_POST[$textbox_id->GetXhtmlId()])) {
             $textbox_id->SetText($_POST[$textbox_id->GetXhtmlId()]);
         }
         if ($b_repopulate_add_row and isset($_POST[$textbox_value->GetXhtmlId()])) {
             $textbox_value->SetText($_POST[$textbox_value->GetXhtmlId()]);
         }
     } else {
         if ($this->IsValid()) {
             if ($this->AddClicked() and $i_row_count == $this->i_row_added) {
                 # If a new row was posted, is valid, and is now displayed here, need to get the posted value from the add row
                 $s_textbox_id_in_add_row = substr($textbox_id->GetXhtmlId(), 0, strlen($textbox_id->GetXhtmlId()) - strlen($i_row_count));
                 if (isset($_POST[$s_textbox_id_in_add_row])) {
                     $textbox_id->SetText($_POST[$s_textbox_id_in_add_row]);
                 }
                 $s_textbox_value_in_add_row = substr($textbox_value->GetXhtmlId(), 0, strlen($textbox_value->GetXhtmlId()) - strlen($i_row_count));
                 if (isset($_POST[$s_textbox_value_in_add_row])) {
                     $textbox_value->SetText($_POST[$s_textbox_value_in_add_row]);
                 } else {
                     # If the add row doesn't populate the item name as well as the item id, it can be passed in as the validated value
                     $textbox_value->SetText($s_validated_value);
                 }
             } else {
                 # Even though the editor as a whole is valid, this row wasn't validated
                 # so just restore the previous value
                 if (isset($_POST[$textbox_id->GetXhtmlId()])) {
                     $textbox_id->SetText($_POST[$textbox_id->GetXhtmlId()]);
                 } else {
                     # Won't be in $_POST when page is first loaded
                     $textbox_id->SetText($i_validated_id);
                 }
                 # Even though the editor as a whole is valid, this row wasn't validated
                 # so just restore the previous value
                 if (isset($_POST[$textbox_value->GetXhtmlId()])) {
                     $textbox_value->SetText($_POST[$textbox_value->GetXhtmlId()]);
                 } else {
                     # Won't be in $_POST when page is first loaded
                     $textbox_value->SetText($s_validated_value);
                 }
             }
         } else {
             # Repopulate with the exact value posted, as validation has failed
             $textbox_id->SetText($_POST[$textbox_id->GetXhtmlId()]);
             $textbox_value->SetText($_POST[$textbox_value->GetXhtmlId()]);
         }
     }
     # Return textboxes so that other things can be done to them - eg add a CSS class or maxlength
     $placeholder = new Placeholder();
     $placeholder->AddControl($textbox_id);
     $placeholder->AddControl($textbox_value);
     $placeholder->AddControl($textbox_value->GetText());
     return $placeholder;
 }