/**
  * 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 CreateControls()
 {
     $this->AddCssClass('legacy-form');
     /* @var $team Team */
     /* @var $comp Competition */
     $season = $this->GetDataObject();
     /* @var $season Season */
     require_once 'xhtml/forms/form-part.class.php';
     require_once 'xhtml/forms/textbox.class.php';
     require_once 'xhtml/forms/radio-button.class.php';
     require_once 'xhtml/forms/checkbox.class.php';
     # Show fewer options for a new season than when editing, beacause a new season gets settings copied from last year to save time
     $b_is_new_season = !(bool) $season->GetId();
     # Add competition
     $comp = $season->GetCompetition();
     $competition = new TextBox($this->GetNamingPrefix() . 'competition', $comp->GetId());
     $competition->SetMode(TextBoxMode::Hidden());
     $this->AddControl($competition);
     # Make current short URL available, because then it can match the suggested one and be left alone
     $short_url = new TextBox($this->GetNamingPrefix() . 'ShortUrl', $season->GetShortUrl());
     $short_url->SetMode(TextBoxMode::Hidden());
     $this->AddControl($short_url);
     # add years
     $start_box = new TextBox('start', is_null($season->GetStartYear()) ? Date::Year(gmdate('U')) : $season->GetStartYear(), $this->IsValidSubmit());
     $start_box->AddAttribute('maxlength', 4);
     $start = new FormPart('Year season starts', $start_box);
     $this->AddControl($start);
     $summer = new RadioButton('summer', 'when', 'Summer season', 0);
     $winter = new RadioButton('winter', 'when', 'Winter season', 1);
     if ($season->GetEndYear() > $season->GetStartYear()) {
         $winter->SetChecked(true);
     } else {
         $summer->SetChecked(true);
     }
     $when = new XhtmlElement('div', $summer);
     $when->AddControl($winter);
     $when->SetCssClass('formControl');
     $when_legend = new XhtmlElement('legend', 'Time of year');
     $when_legend->SetCssClass('formLabel');
     $when_fs = new XhtmlElement('fieldset', $when_legend);
     $when_fs->SetCssClass('formPart');
     $when_fs->AddControl($when);
     $this->AddControl($when_fs);
     # add intro
     $intro_box = new TextBox('intro', $season->GetIntro(), $this->IsValidSubmit());
     $intro_box->SetMode(TextBoxMode::MultiLine());
     $intro = new FormPart('Introduction', $intro_box);
     $this->AddControl($intro);
     if (!$b_is_new_season) {
         # add types of matches
         if (!$this->IsPostback() or $this->b_saving_new and $this->IsValidSubmit()) {
             foreach ($season->MatchTypes()->GetItems() as $i_type) {
                 $this->match_types_editor->DataObjects()->Add(new IdValue($i_type, ucfirst(MatchType::Text($i_type))));
             }
         }
         $this->AddControl(new FormPart('Match types', $this->match_types_editor));
         # add results
         $result_container = new XhtmlElement('div');
         $result_box = new TextBox('results', $season->GetResults(), $this->IsValidSubmit());
         $result_box->SetMode(TextBoxMode::MultiLine());
         $result_container->AddControl($result_box);
         $result = new FormPart('Results', $result_container);
         $result->GetLabel()->AddAttribute('for', $result_box->GetXhtmlId());
         $this->AddControl($result);
         # Add rules table
         $rules = new XhtmlTable();
         $rules->SetCaption('Points for each result');
         $header = new XhtmlRow(array('Result', 'Points for home team', 'Points for away team'));
         $header->SetIsHeader(true);
         $rules->AddRow($header);
         foreach ($this->result_types as $result) {
             /* @var $result MatchResult */
             # Shouldn't ever need to assign points to a postponed match
             if ($result->GetResultType() == MatchResult::POSTPONED) {
                 continue;
             }
             # Populate result with points from season rule
             $season->PossibleResults()->ResetCounter();
             while ($season->PossibleResults()->MoveNext()) {
                 if ($season->PossibleResults()->GetItem()->GetResultType() == $result->GetResultType()) {
                     $result->SetHomePoints($season->PossibleResults()->GetItem()->GetHomePoints());
                     $result->SetAwayPoints($season->PossibleResults()->GetItem()->GetAwayPoints());
                     break;
                 }
             }
             # Create table row
             $home_box = new TextBox($this->GetNamingPrefix() . 'Result' . $result->GetResultType() . 'Home', $result->GetHomePoints(), $this->IsValidSubmit());
             $away_box = new TextBox($this->GetNamingPrefix() . 'Result' . $result->GetResultType() . 'Away', $result->GetAwayPoints(), $this->IsValidSubmit());
             $home_box->AddAttribute('class', 'pointsBox');
             $away_box->AddAttribute('class', 'pointsBox');
             $result_row = new XhtmlRow(array(MatchResult::Text($result->GetResultType()), $home_box, $away_box));
             $rules->AddRow($result_row);
         }
         $result_container->AddControl($rules);
         # Add points adjustments
         $this->adjustments_editor->SetTeams($season->GetTeams());
         if (!$this->IsPostback() or $this->b_saving_new and $this->IsValidSubmit()) {
             $this->adjustments_editor->DataObjects()->SetItems($season->PointsAdjustments()->GetItems());
         }
         $result_container->AddControl($this->adjustments_editor);
         # Show league table?
         $table = new CheckBox('showTable', 'Show results table', 1, $season->GetShowTable());
         $this->AddControl($table);
         $this->AddControl(new CheckBox('runsScored', 'Include runs scored', 1, $season->GetShowTableRunsScored()));
         $this->AddControl(new CheckBox('runsConceded', 'Include runs conceded', 1, $season->GetShowTableRunsConceded()));
         # add teams
         if (!$this->IsPostback() or $this->b_saving_new and $this->IsValidSubmit()) {
             $teams_in_season = array();
             foreach ($season->GetTeams() as $team) {
                 $teams_in_season[] = new TeamInSeason($team, $season, is_object($season->TeamsWithdrawnFromLeague()->GetItemByProperty('GetId', $team->GetId())));
             }
             $this->teams_editor->DataObjects()->SetItems($teams_in_season);
         }
         $this->AddControl(new FormPart('Teams', $this->teams_editor));
     }
 }
 /**
  * Adds controls to edit a team score
  *
  * @param XhtmlElement $o_container
  * @param string $s_id_prefix
  * @param Match $o_match
  * @param Team $o_team
  * @param int $i_runs
  * @param int $i_wickets
  */
 private function CreateTeamScoreControls($o_container, $s_team_role, Match $o_match, Team $o_team = null, $i_runs, $i_wickets)
 {
     $o_box = new XhtmlElement('div');
     $o_runs = new TextBox($this->GetNamingPrefix() . $s_team_role . 'Runs', $i_runs);
     $o_runs->SetCssClass("numeric");
     if ($i_runs == null) {
         $o_runs->PopulateData();
     }
     $s_runs_label = (is_null($o_team) ? $s_team_role : $o_team->GetName()) . ' score';
     $o_part = new FormPart($s_runs_label, $o_box);
     $o_box->AddControl($o_runs);
     $o_part->GetLabel()->AddAttribute('for', $o_runs->GetXhtmlId());
     $o_wickets = new XhtmlSelect($this->GetNamingPrefix() . $s_team_role . 'Wickets', ' for ');
     $o_wickets->SetBlankFirst(true);
     $max_wickets = $o_match->GetMaximumPlayersPerTeam() - 2;
     $season_dates = Season::SeasonDates($o_match->GetStartTime());
     # working with GMT
     if (Date::Year($season_dates[0]) != Date::Year($season_dates[1])) {
         # outdoor needs maximum-2, but indoor needs maximum-1 cos last batter can play on.
         # if there's any chance it's indoor use maximum-1
         $max_wickets = $o_match->GetMaximumPlayersPerTeam() - 1;
     }
     for ($i = 0; $i <= $max_wickets; $i++) {
         $o_wickets->AddControl(new XhtmlOption($i));
     }
     $o_wickets->AddControl(new XhtmlOption('all out', -1));
     $o_wickets->SelectOption($i_wickets);
     $o_box->AddControl($o_wickets);
     $o_container->AddControl($o_part);
 }