/**
  * 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();
 }