/** * 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 OnPageInit() { parent::OnPageInit(); # Set up form, which must exist to be validated $this->form = new XhtmlForm(); $fs1 = new XhtmlElement('fieldset', new XhtmlElement('legend', 'Your team name')); $this->form->AddControl($fs1); $o_team = new TextBox('team', isset($_POST['team']) ? $_POST['team'] : ''); $o_team->SetMaxLength(200); $o_team_part = new FormPart('Team name', $o_team); $o_team_part->SetIsRequired(true); $fs1->AddControl($o_team_part); $o_club = new TextBox('club', isset($_POST['club']) ? $_POST['club'] : ''); $o_club->SetMaxLength(200); $o_club_part = new FormPart('Club (if different)', $o_club); $fs1->AddControl($o_club_part); $fs2 = new XhtmlElement('fieldset', new XhtmlElement('legend', 'Where and when you play')); $this->form->AddControl($fs2); $o_ground = new TextBox('ground', isset($_POST['ground']) ? $_POST['ground'] : ''); $o_ground->SetMode(TextBoxMode::MultiLine()); $o_ground_part = new FormPart('Address of playing field', $o_ground); $o_ground_part->SetIsRequired(true); $fs2->AddControl($o_ground_part); $o_prac = new TextBox('pracNight', isset($_POST['pracNight']) ? $_POST['pracNight'] : ''); $o_prac->SetMaxLength(50); $o_prac_part = new FormPart('Practice night', $o_prac); $fs2->AddControl($o_prac_part); $o_match = new TextBox('matchNight', isset($_POST['matchNight']) ? $_POST['matchNight'] : ''); $o_match->SetMaxLength(100); $o_match_part = new FormPart('Match nights', $o_match); $fs2->AddControl($o_match_part); $o_league = new TextBox('leagues', isset($_POST['leagues']) ? $_POST['leagues'] : ''); $o_league->SetMode(TextBoxMode::MultiLine()); $o_league_part = new FormPart('League(s) or friendlies you play in', $o_league); $fs2->AddControl($o_league_part); $fs3 = new XhtmlElement('fieldset', new XhtmlElement('legend', 'Contact details for Stoolball England to use')); $this->form->AddControl($fs3); $o_contact = new TextBox('contact', isset($_POST['contact']) ? $_POST['contact'] : ''); $o_contact->SetMaxLength(150); $o_contact_part = new FormPart('Contact name', $o_contact); $o_contact_part->SetIsRequired(true); $fs3->AddControl($o_contact_part); $o_contact_addr = new TextBox('address', isset($_POST['address']) ? $_POST['address'] : ''); $o_contact_addr->SetMode(TextBoxMode::MultiLine()); $o_contact_addr_part = new FormPart('Contact address', $o_contact_addr); $fs3->AddControl($o_contact_addr_part); $o_contact_phone = new TextBox('contactPhone', isset($_POST['contactPhone']) ? $_POST['contactPhone'] : ''); $o_contact_phone->SetMaxLength(50); $o_contact_phone_part = new FormPart('Contact phone number', $o_contact_phone); $fs3->AddControl($o_contact_phone_part); $o_contact_e = new TextBox('email', isset($_POST['email']) ? $_POST['email'] : ''); $o_contact_e_part = new FormPart('Contact email', $o_contact_e); $o_contact_e_part->SetIsRequired(true); $fs3->AddControl($o_contact_e_part); $fs4 = new XhtmlElement('fieldset', new XhtmlElement('legend', 'Contact details for the website'), '#publicContact'); $fs4->SetCssClass("radioButtonList"); $this->form->AddControl($fs4); $public1 = new RadioButton('publicAbove', 'public', 'Same as above', 'Same', $this->IsPostback() ? isset($_POST['public']) and $_POST['public'] == 'Same' : true); $public3 = new RadioButton('publicDiff', 'public', 'Display different contact details on the website', 'Different', $this->IsPostback() ? isset($_POST['public']) and $_POST['public'] == 'Different' : false); $public2 = new RadioButton('publicNone', 'public', 'Don\'t display any contact details (not recommended)', 'None', $this->IsPostback() ? isset($_POST['public']) and $_POST['public'] == 'None' : false); $fs4->AddControl($public1); $fs4->AddControl($public3); $fs4->AddControl($public2); $public_contact = new TextBox('publicContact', isset($_POST['publicContact']) ? $_POST['publicContact'] : ''); $public_contact->SetMode(TextBoxMode::MultiLine()); $public_contact_part = new FormPart('Contact details for the website', $public_contact); $public_contact_part->SetXhtmlId('publicContactPart'); $fs4->AddControl($public_contact_part); $fs5 = new XhtmlElement('fieldset', new XhtmlElement('legend', 'Anything else you\'d like on your team\'s page')); $this->form->AddControl($fs5); $o_notes = new TextBox('notes', isset($_POST['notes']) ? $_POST['notes'] : ''); $o_notes->SetMode(TextBoxMode::MultiLine()); $o_notes_part = new FormPart('Other details', $o_notes); $fs5->AddControl($o_notes_part); $o_buttons = new XhtmlElement('div'); $o_buttons->SetCssClass('buttonGroup'); $o_submit = new Button('send', 'Send email'); $o_buttons->AddControl($o_submit); $this->form->AddControl($o_buttons); # Set up validation require_once 'data/validation/required-field-validator.class.php'; require_once 'data/validation/length-validator.class.php'; require_once 'data/validation/email-validator.class.php'; $a_validators = array(); $a_validators[] = new RequiredFieldValidator(array('team'), 'A team name is required'); $a_validators[] = new LengthValidator(array('team'), 'Your team name is too long', 0, 200); $a_validators[] = new LengthValidator(array('club'), 'Your club name is too long', 0, 200); $a_validators[] = new RequiredFieldValidator(array('ground'), 'A playing field address is required'); $a_validators[] = new LengthValidator(array('ground'), 'The playing field address is too long', 0, 2000); $a_validators[] = new RequiredFieldValidator(array('contact'), 'A contact name for the team is required'); $a_validators[] = new LengthValidator(array('pracNight'), 'Practice night must be 50 characters or less', 0, 50); $a_validators[] = new LengthValidator(array('matchNight'), 'Match nights must be 100 characters or less', 0, 100); $a_validators[] = new LengthValidator(array('leagues'), 'Your league or friendly group(s) must be 2000 characters or less', 0, 2000); $a_validators[] = new LengthValidator(array('contact'), 'Your contact name is too long', 0, 150); $a_validators[] = new LengthValidator(array('address'), 'The contact address is too long', 0, 2000); $a_validators[] = new LengthValidator(array('contactPhone'), 'The contact phone number is too long', 0, 50); $a_validators[] = new RequiredFieldValidator(array('email'), 'A contact email for the team is required'); $a_validators[] = new EmailValidator('email', 'Please enter a valid email address'); $a_validators[] = new LengthValidator('publicContact', 'You\'ve put too much in the "website contact details" box. Please make the text shorter.', 0, 10000); $a_validators[] = new LengthValidator('notes', 'You\'ve put too much in the "other details" box. Please make the text shorter.', 0, 10000); foreach ($a_validators as $o_v) { $this->form->AddValidator($o_v); unset($o_v); } $this->RegisterControlForValidation($this->form); }