function CreateControls()
 {
     /* @var $o_email Zend_Mail */
     $this->AddCssClass('legacy-form');
     $o_email = $this->GetDataObject();
     if (!is_object($o_email)) {
         $o_email = new Zend_Mail('UTF-8');
     }
     # Who to send to
     $i_address_count = count($this->a_addresses);
     if ($i_address_count > 1) {
         $o_who = new XhtmlElement('fieldset', new XhtmlElement('legend', 'Why are you contacting us?'));
         $o_who->SetCssClass('radioButtonList');
         $i = 0;
         foreach ($this->a_addresses as $s_addr => $s_reason) {
             $o_radio = new XhtmlElement('input');
             $o_radio->SetEmpty(true);
             $o_radio->AddAttribute('type', 'radio');
             $o_radio->AddAttribute('name', 'to');
             $o_radio->AddAttribute('value', md5($s_addr));
             $o_radio->SetXhtmlId('to' . $i);
             if ($this->IsPostback()) {
                 if (isset($_POST['to']) and $_POST['to'] == md5($s_addr)) {
                     $o_radio->AddAttribute('checked', 'checked');
                 }
             } else {
                 if (!$i) {
                     $o_radio->AddAttribute('checked', 'checked');
                 }
             }
             $o_label = new XhtmlElement('label', $o_radio);
             $o_label->AddAttribute('for', $o_radio->GetXhtmlId());
             $o_label->AddControl($s_reason);
             $o_who->AddControl($o_label);
             $i++;
         }
         $this->AddControl($o_who);
     }
     # Your details
     $o_details = new XhtmlElement('fieldset');
     $o_details->AddControl(new XhtmlElement('legend', 'Your details'));
     $this->AddControl($o_details);
     $o_name = new TextBox('fromName', '', $this->IsValidSubmit());
     $o_name->SetMaxLength(100);
     $o_name_part = new FormPart('Name', $o_name);
     $o_details->AddControl($o_name_part);
     $o_from = new TextBox('from', '', $this->IsValidSubmit());
     $o_from->AddAttribute("type", "email");
     $o_from->SetMaxLength(250);
     $o_from_part = new FormPart('Email address', $o_from);
     $o_from_part->SetIsRequired(true);
     $o_details->AddControl($o_from_part);
     # Your email
     $o_message = new XhtmlElement('fieldset');
     $o_message->AddControl(new XhtmlElement('legend', 'Your email'));
     $this->AddControl($o_message);
     $o_subj = new TextBox('subject', '', $this->IsValidSubmit());
     $o_subj->SetMaxLength(250);
     $o_subj_part = new FormPart('Subject', $o_subj);
     $o_message->AddControl($o_subj_part);
     $o_body = new TextBox('body', '', $this->IsValidSubmit());
     $o_body->SetMode(TextBoxMode::MultiLine());
     $o_body_part = new FormPart('Your message', $o_body);
     $o_body_part->SetIsRequired(true);
     $o_message->AddControl($o_body_part);
     # Options
     $o_opt = new XhtmlElement('fieldset', null, "radioButtonList");
     $o_opt->AddControl(new XhtmlElement('legend', 'Options', "aural"));
     $this->AddControl($o_opt);
     $o_opt->AddControl(new CheckBox('cc', 'Send me a copy', 1, false, $this->IsValidSubmit()));
     $o_opt->AddControl(new CheckBox('reply', "I'd like a reply", 1, true, $this->IsValidSubmit()));
 }
 /**
  * Adds populated controls as a new table row
  *
  * @param XhtmlElement[] $a_controls
  * @param bool $b_enabled
  * @return XhtmlRow
  */
 protected function AddRowToTable($a_controls, $b_enabled = true)
 {
     # Add action button to controls for table
     $button = new XhtmlElement('input');
     if (!$b_enabled) {
         $button->AddAttribute('disabled', 'disabled');
     }
     $last_cell_data = new Placeholder($button);
     $s_id = '';
     if (!is_null($this->current_data_object)) {
         # Get methods for data objects
         $s_id_method = $this->s_id_method;
         $s_date_modified_method = $this->s_date_modified_method;
         # Update button
         $button->AddAttribute('value', 'Delete');
         $button->SetXhtmlId($this->GetNamingPrefix() . 'DeleteRelated' . $this->i_current_row_identifier);
         # Hidden - id of related item
         $s_id = $this->current_data_object->{$s_id_method}();
         $s_id = $s_id ? $s_id : $this->i_current_row_identifier;
         $id_box = new TextBox($this->GetNamingPrefix() . 'RelatedId' . $this->i_current_row_identifier, $s_id);
         $id_box->SetMode(TextBoxMode::Hidden());
         $last_cell_data->AddControl($id_box);
         # Hidden - when was relationship to item updated?
         $b_track_modified_date = ($s_date_modified_method and method_exists($this->current_data_object, $s_date_modified_method));
         if ($b_track_modified_date) {
             $updated_box = new TextBox($this->GetNamingPrefix() . 'RelatedUpdated' . $this->i_current_row_identifier, $this->current_data_object->{$s_date_modified_method}());
             $updated_box->SetMode(TextBoxMode::Hidden());
             $last_cell_data->AddControl($updated_box);
         }
         # Hidden - check whether item updated
         $check_box = new TextBox($this->GetNamingPrefix() . 'Check' . $this->i_current_row_identifier, $this->GetDataObjectHash($this->current_data_object));
         $check_box->SetMode(TextBoxMode::Hidden());
         $last_cell_data->AddControl($check_box);
     } else {
         $button->AddAttribute('value', 'Add');
         $button->SetXhtmlId($this->GetNamingPrefix() . 'AddRelated');
     }
     $button->AddAttribute('type', 'submit');
     $button->SetEmpty(true);
     $button->AddAttribute('name', $button->GetXhtmlId());
     $this->RegisterInternalButton($button->GetXhtmlId());
     # Create table row and add to table
     $a_controls[] = $last_cell_data;
     $row = new XhtmlRow($a_controls);
     if (!$b_enabled) {
         $row->SetCssClass('unavailable');
     }
     $this->table->AddRow($row);
     return $row;
 }
 /**
  * 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);
 }
 protected function OnPreRender()
 {
     # Build up child option controls for the select list
     $options = array();
     # Add blank option if requested
     if ($this->b_blank) {
         $options[] = new XhtmlOption();
     }
     # Loop through options, converting group names to option groups
     $current_group_name = '';
     $current_group = null;
     foreach ($this->GetControls() as $option) {
         /* @var $option XhtmlOption */
         # Same group as last option
         if ($option->GetGroupName() === $current_group_name) {
             if ($current_group_name) {
                 # Add option to the group
                 $current_group->AddControl($option);
             } else {
                 # It's not in a group
                 $options[] = $option;
             }
         } else {
             # Different group than last option
             if (!is_null($current_group)) {
                 $options[] = $current_group;
             }
             # If it's another group, create the group
             if ($option->GetGroupName()) {
                 $current_group_name = $option->GetGroupName();
                 $current_group = new XhtmlElement('optgroup', $option);
                 $current_group->AddAttribute('label', $current_group_name);
             } else {
                 # If we're now out of a group, clear the current groups
                 $current_group_name = '';
                 $current_group = null;
                 $options[] = $option;
             }
         }
     }
     # Add the final group, if there is one
     if (!is_null($current_group)) {
         $options[] = $current_group;
     }
     # Move child controls into select list
     $this->o_select->SetControls($options);
     $no_controls = array();
     $this->SetControls($no_controls);
     # Add select list to this control
     if ($this->GetLabel()) {
         if ($this->b_hide_label) {
             $o_label = new XhtmlElement('label');
             $o_label->SetCssClass('aural');
             $o_label->AddAttribute('for', $this->o_select->GetXhtmlId());
             $o_label->AddControl($this->GetLabel() . ' ');
             $this->AddControl($o_label);
             $this->AddControl($this->o_select);
         } else {
             $o_label = new XhtmlElement('label');
             $o_label->AddAttribute('for', $this->o_select->GetXhtmlId());
             $o_label->AddControl($this->GetLabel() . ' ');
             $o_label->AddControl($this->o_select);
             $this->AddControl($o_label);
         }
     } else {
         $this->AddControl($this->o_select);
     }
     parent::OnPreRender();
 }