function CreateControls()
 {
     require_once 'xhtml/xhtml-element.class.php';
     require_once 'xhtml/forms/form-part.class.php';
     require_once 'xhtml/forms/textbox.class.php';
     $this->AddCssClass('legacy-form');
     $o_comp = $this->GetDataObject();
     /* @var $o_type IdValue */
     /* @var $o_comp Competition */
     /* @var $o_season Season */
     # add name
     $o_name_box = new TextBox('name', $o_comp->GetName(), $this->IsValidSubmit());
     $o_name_box->AddAttribute('maxlength', 100);
     $o_name = new FormPart('Competition name', $o_name_box);
     $this->AddControl($o_name);
     # Add seasons once competition saved
     if ($o_comp->GetId()) {
         $a_seasons = $o_comp->GetSeasons();
         $o_season_part = new FormPart('Seasons');
         $o_season_control = new Placeholder();
         # List exisiting seasons
         if (is_array($a_seasons) and count($a_seasons)) {
             $o_seasons = new XhtmlElement('ul');
             foreach ($a_seasons as $o_season) {
                 $o_season_link = new XhtmlAnchor(Html::Encode($o_season->GetName()), $o_season->GetEditSeasonUrl());
                 $o_seasons->AddControl(new XhtmlElement('li', $o_season_link));
             }
             $o_season_control->AddControl($o_seasons);
         }
         $o_new_season = new XhtmlAnchor('Add season', '/play/competitions/seasonedit.php?competition=' . $o_comp->GetId());
         $o_season_control->AddControl($o_new_season);
         $o_season_part->SetControl($o_season_control);
         $this->AddControl($o_season_part);
     }
     # Still going?
     $this->AddControl(new CheckBox('active', 'This competition is still played', 1, $o_comp->GetIsActive(), $this->IsValidSubmit()));
     # add player type
     $o_type_list = new XhtmlSelect('playerType', null, $this->IsValidSubmit());
     $o_type_list->AddControl(new XhtmlOption(PlayerType::Text(PlayerType::MIXED), PlayerType::MIXED));
     $o_type_list->AddControl(new XhtmlOption(PlayerType::Text(PlayerType::LADIES), PlayerType::LADIES));
     $o_type_list->AddControl(new XhtmlOption(PlayerType::Text(PlayerType::JUNIOR_MIXED), PlayerType::JUNIOR_MIXED));
     $o_type_list->AddControl(new XhtmlOption(PlayerType::Text(PlayerType::GIRLS), PlayerType::GIRLS));
     $o_type_list->AddControl(new XhtmlOption(PlayerType::Text(PlayerType::MEN), PlayerType::MEN));
     $o_type_list->AddControl(new XhtmlOption(PlayerType::Text(PlayerType::BOYS), PlayerType::BOYS));
     if (!is_null($o_comp->GetPlayerType()) and $this->IsValidSubmit()) {
         $o_type_list->SelectOption($o_comp->GetPlayerType());
     }
     $o_type_part = new FormPart('Player type', $o_type_list);
     $this->AddControl($o_type_part);
     # add players per team
     $players_box = new TextBox('players', $o_comp->GetMaximumPlayersPerTeam(), $this->IsValidSubmit());
     $players_box->SetMaxLength(2);
     $players = new FormPart('Max players in league/cup team', $players_box);
     $this->AddControl($players);
     # add overs
     $overs_box = new TextBox('overs', $o_comp->GetOvers(), $this->IsValidSubmit());
     $overs_box->SetMaxLength(2);
     $overs = new FormPart('Overs per innings', $overs_box);
     $this->AddControl($overs);
     # category
     $cat_select = new CategorySelectControl($this->categories, $this->IsValidSubmit());
     $cat_select->SetXhtmlId($this->GetNamingPrefix() . 'category');
     if (!is_null($o_comp->GetCategory()) and $this->IsValidSubmit()) {
         $cat_select->SelectOption($o_comp->GetCategory()->GetId());
     }
     $this->AddControl(new FormPart('Category', $cat_select));
     # add intro
     $o_intro_box = new TextBox('intro', $o_comp->GetIntro(), $this->IsValidSubmit());
     $o_intro_box->SetMode(TextBoxMode::MultiLine());
     $o_intro = new FormPart('Introduction', $o_intro_box);
     $this->AddControl($o_intro);
     # add contact info
     $o_contact_box = new TextBox('contact', $o_comp->GetContact(), $this->IsValidSubmit());
     $o_contact_box->SetMode(TextBoxMode::MultiLine());
     $o_contact = new FormPart('Contact details', $o_contact_box);
     $this->AddControl($o_contact);
     # Add notification email
     $o_notify_box = new TextBox('notification', $o_comp->GetNotificationEmail(), $this->IsValidSubmit());
     $o_notify_box->SetMaxLength(200);
     $o_notify = new FormPart('Notification email', $o_notify_box);
     $this->AddControl($o_notify);
     # add website
     $o_website_box = new TextBox('website', $o_comp->GetWebsiteUrl(), $this->IsValidSubmit());
     $o_website_box->SetMaxLength(250);
     $o_website = new FormPart('Website', $o_website_box);
     $this->AddControl($o_website);
     # Remember short URL
     $o_short_url = new TextBox($this->GetNamingPrefix() . 'ShortUrl', $o_comp->GetShortUrl(), $this->IsValidSubmit());
     $this->AddControl(new FormPart('Short URL', $o_short_url));
 }
 /**
  * Creates, and re-populates on postback, text displaying one property of a related data item
  *
  * @param string $s_validated_value
  * @param string $s_name
  * @param int $i_row_count
  * @param int $i_total_rows
  * @param string[] $a_display_values
  * @return Placeholder
  */
 protected function CreateDisplayText($s_validated_value, $s_name, $i_row_count, $i_total_rows, $a_display_values = null)
 {
     $textbox = $this->CreateTextBox($s_validated_value, $s_name, $i_row_count, $i_total_rows);
     $textbox->SetMode(TextBoxMode::Hidden());
     $container = new Placeholder($textbox);
     if (is_array($a_display_values) and array_key_exists($textbox->GetText(), $a_display_values)) {
         # This path used on initial load request, and when controlling editor's save button is clicked when a row is being added
         # Textbox value is the key to an array of values
         $container->AddControl($a_display_values[$textbox->GetText()]->__toString());
         $textbox->SetText($textbox->GetText() . RelatedIdEditor::VALUE_DIVIDER . $a_display_values[$textbox->GetText()]->__toString());
     } else {
         # Copy textbox value, remove prepended id, and use as display text
         $s_value = $textbox->GetText();
         $i_pos = strpos($s_value, RelatedIdEditor::VALUE_DIVIDER);
         if ($i_pos) {
             $s_value = substr($s_value, $i_pos + strlen(RelatedIdEditor::VALUE_DIVIDER));
         }
         $container->AddControl(ucfirst($s_value));
     }
     return $container;
 }
 /**
  * Create a table row to add or edit a match
  *
  * @param object $data_object
  * @param int $i_row_count
  * @param int $i_total_rows
  */
 protected function AddItemToTable($data_object = null, $i_row_count = null, $i_total_rows = null)
 {
     /* @var $data_object Match */
     $b_has_data_object = !is_null($data_object);
     // Which match?
     if (is_null($i_row_count)) {
         $order = $this->CreateTextBox(null, 'MatchOrder', null, $i_total_rows);
         $order->AddAttribute("type", "number");
         $order->SetCssClass("numeric");
         $this->max_sort_order++;
         $order->SetText($this->max_sort_order);
         $home_control = $this->AddTeamList('HomeTeamId', $b_has_data_object ? $data_object->GetHomeTeamId() : '', $i_total_rows);
         $away_control = $this->AddTeamList('AwayTeamId', $b_has_data_object ? $data_object->GetAwayTeamId() : '', $i_total_rows);
         $match_control = new Placeholder();
         $match_control->AddControl($home_control);
         $match_control->AddControl(" v ");
         $match_control->AddControl($away_control);
         $this->AddRowToTable(array($order, $match_control));
     } else {
         # Display the match title. When the add button is used, we need to get the team names for the new match because they weren't posted.
         if ($b_has_data_object) {
             $this->EnsureTeamName($data_object->GetHomeTeam());
             $this->EnsureTeamName($data_object->GetAwayTeam());
         }
         $match_order = $b_has_data_object ? $data_object->GetOrderInTournament() : null;
         if (is_null($match_order)) {
             $match_order = $this->max_sort_order + 1;
         }
         if ($match_order > $this->max_sort_order) {
             $this->max_sort_order = $match_order;
         }
         $order = $this->CreateTextBox($match_order, 'MatchOrder', $i_row_count, $i_total_rows);
         $order->AddAttribute("type", "number");
         $order->SetCssClass("numeric");
         $match_control = $this->CreateNonEditableText($b_has_data_object ? $data_object->GetId() : null, $b_has_data_object ? $data_object->GetTitle() : '', 'MatchId', $i_row_count, $i_total_rows);
         # If the add button is used, remember the team ids until the final save is requested
         $home_team_id = $this->CreateTextBox($data_object->GetHomeTeamId(), 'HomeTeamId', $i_row_count, $i_total_rows);
         $home_team_id->SetMode(TextBoxMode::Hidden());
         $away_team_id = $this->CreateTextBox($data_object->GetAwayTeamId(), 'AwayTeamId', $i_row_count, $i_total_rows);
         $away_team_id->SetMode(TextBoxMode::Hidden());
         $container = new Placeholder();
         $container->SetControls(array($match_control, $home_team_id, $away_team_id));
         $this->AddRowToTable(array($order, $container));
     }
 }
 /**
  * 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;
 }
 /**
  * @return bool
  * @param XhtmlOption $o_control
  * @desc Add an XhtmlOption to this list
  */
 function AddControl($o_control)
 {
     /* @var $o_control XhtmlOption */
     if ($this->b_page_valid === false and isset($_POST[$this->GetXhtmlId()]) and $o_control instanceof XhtmlOption and $o_control->GetAttribute('value') == $_POST[$this->GetXhtmlId()]) {
         $o_control->AddAttribute('selected', 'selected');
     }
     parent::AddControl($o_control);
 }