Beispiel #1
0
function makeEditForm($selfurl)
{
    // nice names for each field
    $formNames = array('cfg_incoming_path' => 'Kannel Incoming Path: ', 'cfg_username' => 'Username:'******'cfg_password' => 'Password:'******'cfg_global_sender' => 'Global Sender:', 'cfg_bearerbox_host' => 'Bearerbox IP:', 'cfg_sendsms_port' => 'Send SMS Port:', 'cfg_playsms_web' => 'PlaySMS web url:', 'cfg_restart_frequency' => 'Restart Kannel Regularly?');
    // infer the fields we're going to show
    // from the list of formNames
    $renderFields = array();
    foreach ($formNames as $field => $name) {
        $renderFields[] = $field;
    }
    // find the first record in the config table
    $do = DB_DataObject::factory('playsms_gwmodKannel_config');
    $do->get(1);
    // create the form with the user-showable names
    $fb = DB_DataObject_FormBuilder::create($do, array("fieldLabels" => $formNames, "fieldsToRender" => $renderFields));
    // set up enums
    $fb->enumFields = array('cfg_restart_frequency');
    $form = $fb->getForm("{$selfurl}");
    if ($form->validate()) {
        $err = "Gateway module configurations has been saved";
        print "<p><font color=red>{$err}</font><p>";
        $form->process(array(&$fb, 'processForm'), false);
    }
    $form->display();
    echo "<p/><hr/><p/>";
    echo "<a href=\"plugin/gateway/kannel/kannel-monitor/\">[ Monitor Status ]</a> \n";
    echo "<a href=\"{$selfurl}&op=manage_smsc\">[ Bind SMSC ]</a>";
}
Beispiel #2
0
function makeEditForm($selfurl)
{
    // nice names for each field
    $formNames = array('cfg_web_title' => 'Website title:', 'cfg_web_url' => 'Website URL:', 'cfg_email_service' => 'Website email', 'cfg_email_footer' => 'Forwarded email footer:', 'cfg_gateway_module' => 'Activated gateway module:', 'cfg_gateway_number' => 'Gateway number:', 'cfg_system_from' => 'System messages <br/> (e.g., balance updates) are sent from:', 'cfg_system_restart_frequency' => 'Restart the entire system regularly?');
    // infer the fields we're going to show
    // from the list of formNames
    $renderFields = array();
    foreach ($formNames as $field => $name) {
        $renderFields[] = $field;
    }
    // List of gateway plugins.
    // TODO: make this get listing of the gw plugin files
    // rather than be hard-coded
    $gw_mods = array("kannel" => "Kannel", "gnokii" => "Gnokii", "uplink" => "UpLink", "clickatell" => "ClickAtell");
    // find the first record in the config table
    $do = DB_DataObject::factory(playsms_tblConfig_main);
    $do->find();
    $do->fetch();
    // create the form with the user-showable names
    $fb = DB_DataObject_FormBuilder::create($do, array("fieldLabels" => $formNames, "fieldsToRender" => $renderFields));
    $fb->submitText = "Save";
    // set up gw_mod enum
    $fb->enumFields = array('cfg_gateway_module', 'cfg_system_restart_frequency');
    $fb->enumOptions = array('cfg_gateway_module' => $gw_mods);
    $form = $fb->getForm("{$selfurl}");
    if ($form->validate()) {
        $err = "Main configuration has been saved";
        print "<p><font color=red>{$err}</font><p>";
        $form->process(array(&$fb, 'processForm'), false);
    }
    $form->display();
}
Beispiel #3
0
function makeEditForm($selfurl, $id = null)
{
    // nice names for each field
    $formNames = array('frequency' => 'Frequency:', 'number' => 'To:<br/><font size="1">(number or group code, <br/>e.g., "admin")</font>', 'msg' => 'Message:');
    $do = DB_DataObject::factory(playsms_featAutoSend);
    if ($id) {
        $do->get($id);
    }
    $fb = DB_DataObject_FormBuilder::create($do, array("fieldLabels" => $formNames));
    $fb->enumFields = array('frequency');
    $form = $fb->getForm("{$selfurl}&op=edit");
    setupSmsCounting($form, 'msg', '__submit__');
    if ($form->validate()) {
        $form->process(array(&$fb, 'processForm'), false);
    }
    $form->display();
    ?>
    
    <a href="<?php 
    echo $selfurl;
    ?>
&op=list"><br><br>[back]</a>
    <?php 
}
Beispiel #4
0
 /**
  * DB_DataObject_FormBuilder::_generateForm()
  *
  * Builds a simple HTML form for the current DataObject. Internal function, called by
  * the public getForm() method. You can override this in child classes if needed, but
  * it's also possible to leave this as it is and just override the getForm() method
  * to simply fine-tune the auto-generated form object (i.e. add/remove elements, alter
  * options, add/remove rules etc.).
  * If a key with the same name as the current field is found in the fb_preDefElements
  * property, the QuickForm element object contained in that array will be used instead
  * of auto-generating a new one. This allows for complete step-by-step customizing of
  * your forms.
  *
  * Note for date fields: HTML_QuickForm allows passing of an options array to the
  * HTML_QuickForm_date element. You can define your own options array for date elements
  * in your DataObject-derived classes by defining a method "dateOptions($fieldName)".
  * FormBuilder will call that method whenever it encounters a date field and expects to
  * get back a valid options array.
  *
  * @param string $action   The form action. Optional. If set to false (default), PHP_SELF is used.
  * @param string $target   The window target of the form. Optional. Defaults to '_self'.
  * @param string $formName The name of the form, will be used in "id" and "name" attributes. If set to false (default), the class name is used
  * @param string $method   The submit method. Defaults to 'post'.
  * @return object
  * @access protected
  * @author Markus Wolff <*****@*****.**>
  * @author Fabien Franzen <*****@*****.**>
  */
 function &_generateForm($action = false, $target = '_self', $formName = false, $method = 'post')
 {
     if ($formName === false) {
         $formName = strtolower(get_class($this->_do));
     }
     if ($action === false) {
         $action = $_SERVER['PHP_SELF'];
     }
     // Retrieve the form object to use (may depend on the current renderer)
     $this->_form->_createFormObject($formName, $method, $action, $target);
     // Initialize array with default values
     //$formValues = $this->_do->toArray();
     if ($this->addFormHeader) {
         // Add a header to the form - set addFormHeader property to false to prevent this
         $this->_form->_addFormHeader(is_null($this->formHeaderText) ? $this->prettyName($this->_do->tableName()) : $this->formHeaderText);
     }
     // Go through all table fields and create appropriate form elements
     $keys = $this->_do->keys();
     // Reorder elements if requested, will return _getFieldsToRender if no reordering is needed
     $elements = $this->_reorderElements();
     //get elements to freeze
     $user_editable_fields = $this->_getUserEditableFields();
     if (is_array($user_editable_fields)) {
         $elements_to_freeze = array_diff(array_keys($elements), $user_editable_fields);
     } else {
         $elements_to_freeze = array();
     }
     if (!is_array($links = $this->_do->links())) {
         $links = array();
     }
     $pk = $this->_getPrimaryKey($this->_do);
     $rules = array();
     foreach ($elements as $key => $type) {
         // Check if current field is primary key. And primary key hiding is on. If so, make hidden field
         if (in_array($key, $keys) && $this->hidePrimaryKey == true) {
             $formValues[$key] = $this->_do->{$key};
             $element =& $this->_form->_createHiddenField($key);
         } else {
             unset($element);
             // Try to determine field types depending on object properties
             $notNull = $type & DB_DATAOBJECT_NOTNULL;
             if (in_array($key, $this->dateFields)) {
                 $type = DB_DATAOBJECT_DATE;
             } elseif (in_array($key, $this->timeFields)) {
                 $type = DB_DATAOBJECT_TIME;
             } elseif (in_array($key, $this->textFields)) {
                 $type = DB_DATAOBJECT_TXT;
             } elseif (in_array($key, $this->enumFields)) {
                 $type = DB_DATAOBJECT_FORMBUILDER_ENUM;
             } elseif (in_array($key, $this->booleanFields)) {
                 $type = DB_DATAOBJECT_BOOL;
             }
             if ($notNull || in_array($key, $this->fieldsRequired)) {
                 $type |= DB_DATAOBJECT_NOTNULL;
             }
             if (isset($this->preDefElements[$key]) && (is_object($this->preDefElements[$key]) || is_array($this->preDefElements[$key]))) {
                 // Use predefined form field, IMPORTANT: This may depend on the used renderer!!
                 $element =& $this->preDefElements[$key];
             } elseif (isset($links[$key])) {
                 // If this field links to another table, display selectbox or radiobuttons
                 $isRadio = isset($this->linkElementTypes[$key]) && $this->linkElementTypes[$key] == 'radio';
                 $opt = $this->getSelectOptions($key, false, !($type & DB_DATAOBJECT_NOTNULL), $isRadio ? $this->radioAddEmptyLabel : $this->selectAddEmptyLabel);
                 if ($isRadio) {
                     $element =& $this->_form->_createRadioButtons($key, $opt);
                 } else {
                     $element =& $this->_form->_createSelectBox($key, $opt);
                 }
                 unset($opt);
             }
             // No predefined object available, auto-generate new one
             $elValidator = false;
             $elValidRule = false;
             // Auto-detect field types depending on field's database type
             switch (true) {
                 case $type & DB_DATAOBJECT_BOOL:
                     if ($this->useAccessors && method_exists($this->_do, 'get' . $key)) {
                         $formValues[$key] = $this->_do->{'get' . $key}();
                     } else {
                         $formValues[$key] = $this->_do->{$key};
                     }
                     if ($formValues[$key] === 'f') {
                         $formValues[$key] = 0;
                     }
                     if (!isset($element)) {
                         $element =& $this->_form->_createCheckbox($key, null, null, $this->getFieldLabel($key));
                     }
                     break;
                 case $type & DB_DATAOBJECT_INT:
                     if ($this->useAccessors && method_exists($this->_do, 'get' . $key)) {
                         $formValues[$key] = $this->_do->{'get' . $key}();
                     } else {
                         $formValues[$key] = $this->_do->{$key};
                     }
                     if (!isset($element)) {
                         $element =& $this->_form->_createIntegerField($key);
                         $elValidator = 'numeric';
                     }
                     break;
                 case $type & DB_DATAOBJECT_DATE && $type & DB_DATAOBJECT_TIME:
                     $this->debug('DATE & TIME CONVERSION using callback for element ' . $key . ' (' . $this->_do->{$key} . ')!', 'FormBuilder');
                     if ($this->useAccessors && method_exists($this->_do, 'get' . $key)) {
                         $fieldValue = $this->_do->{'get' . $key}();
                     } else {
                         $fieldValue = $this->_do->{$key};
                     }
                     if ($this->isCallableAndExists($this->dateFromDatabaseCallback)) {
                         $formValues[$key] = call_user_func($this->dateFromDatabaseCallback, $fieldValue);
                     } else {
                         $this->debug('WARNING: dateFromDatabaseCallback callback not callable', 'FormBuilder');
                         $formValues[$key] = $fieldValue;
                     }
                     if (!isset($element)) {
                         $element =& $this->_form->_createDateTimeElement($key);
                     }
                     break;
                 case $type & DB_DATAOBJECT_DATE:
                     $this->debug('DATE CONVERSION using callback for element ' . $key . ' (' . $this->_do->{$key} . ')!', 'FormBuilder');
                     if ($this->useAccessors && method_exists($this->_do, 'get' . $key)) {
                         $fieldValue = $this->_do->{'get' . $key}();
                     } else {
                         $fieldValue = $this->_do->{$key};
                     }
                     if ($this->isCallableAndExists($this->dateFromDatabaseCallback)) {
                         $formValues[$key] = call_user_func($this->dateFromDatabaseCallback, $fieldValue);
                     } else {
                         $this->debug('WARNING: dateFromDatabaseCallback callback not callable', 'FormBuilder');
                         $formValues[$key] = $fieldValue;
                     }
                     if (!isset($element)) {
                         $element =& $this->_form->_createDateElement($key);
                     }
                     break;
                 case $type & DB_DATAOBJECT_TIME:
                     $this->debug('TIME CONVERSION using callback for element ' . $key . ' (' . $this->_do->{$key} . ')!', 'FormBuilder');
                     if ($this->useAccessors && method_exists($this->_do, 'get' . $key)) {
                         $fieldValue = $this->_do->{'get' . $key}();
                     } else {
                         $fieldValue = $this->_do->{$key};
                     }
                     if ($this->isCallableAndExists($this->dateFromDatabaseCallback)) {
                         $formValues[$key] = call_user_func($this->dateFromDatabaseCallback, $fieldValue);
                     } else {
                         $this->debug('WARNING: dateFromDatabaseCallback callback not callable', 'FormBuilder');
                         $formValues[$key] = $fieldValue;
                     }
                     if (!isset($element)) {
                         $element =& $this->_form->_createTimeElement($key);
                     }
                     break;
                 case $type & DB_DATAOBJECT_TXT || $type & DB_DATAOBJECT_BLOB:
                     if ($this->useAccessors && method_exists($this->_do, 'get' . $key)) {
                         $formValues[$key] = $this->_do->{'get' . $key}();
                     } else {
                         $formValues[$key] = $this->_do->{$key};
                     }
                     if (!isset($element)) {
                         $element =& $this->_form->_createTextArea($key);
                     }
                     break;
                 case $type & DB_DATAOBJECT_STR:
                     if ($this->useAccessors && method_exists($this->_do, 'get' . $key)) {
                         $formValues[$key] = $this->_do->{'get' . $key}();
                     } else {
                         $formValues[$key] = $this->_do->{$key};
                     }
                     if (!isset($element)) {
                         // If field content contains linebreaks, make textarea - otherwise, standard textbox
                         if (isset($this->_do->{$key}) && strlen($this->_do->{$key}) && strstr($this->_do->{$key}, "\n")) {
                             $element =& $this->_form->_createTextArea($key);
                         } else {
                             $element =& $this->_form->_createTextField($key);
                         }
                     }
                     break;
                 case $type & DB_DATAOBJECT_FORMBUILDER_CROSSLINK:
                     unset($element);
                     // generate crossLink stuff
                     /*if ($pk === false) {
                           return PEAR::raiseError('A primary key must exist in the base table when using crossLinks.');
                       }*/
                     $crossLink = $this->crossLinks[$key];
                     $groupName = $this->_sanitizeFieldName('__crossLink_' . $crossLink['table'] . '_' . $crossLink['fromField'] . '_' . $crossLink['toField']);
                     unset($crossLinkDo);
                     $crossLinkDo = DB_DataObject::factory($crossLink['table']);
                     if (PEAR::isError($crossLinkDo)) {
                         die($crossLinkDo->getMessage());
                     }
                     if (!is_array($crossLinkLinks = $crossLinkDo->links())) {
                         $crossLinkLinks = array();
                     }
                     list($linkedtable, $linkedfield) = explode(':', $crossLinkLinks[$crossLink['toField']]);
                     list($fromtable, $fromfield) = explode(':', $crossLinkLinks[$crossLink['fromField']]);
                     //if ($fromtable !== $this->_do->tableName()) error?
                     $all_options = $this->_getSelectOptions($linkedtable, false, false, false, $linkedfield);
                     $selected_options = array();
                     if (isset($this->_do->{$fromfield})) {
                         $crossLinkDo->{$crossLink['fromField']} = $this->_do->{$fromfield};
                         if ($this->isCallableAndExists($this->prepareLinkedDataObjectCallback)) {
                             call_user_func_array($this->prepareLinkedDataObjectCallback, array(&$crossLinkDo, $key));
                         }
                         if ($crossLinkDo->find() > 0) {
                             while ($crossLinkDo->fetch()) {
                                 $selected_options[$crossLinkDo->{$crossLink['toField']}] = clone $crossLinkDo;
                             }
                         }
                     }
                     if (isset($crossLink['type']) && $crossLink['type'] == 'select') {
                         unset($element);
                         $element =& $this->_form->_createSelectBox($groupName, $all_options, true);
                         $formValues[$groupName] = array_keys($selected_options);
                         // set defaults later
                         // ***X*** generate checkboxes
                     } else {
                         $element = array();
                         $rowNames = array();
                         foreach ($all_options as $optionKey => $value) {
                             if (isset($selected_options[$optionKey])) {
                                 if (!isset($formValues[$groupName])) {
                                     $formValues[$groupName] = array();
                                 }
                                 $formValues[$groupName][$optionKey] = $optionKey;
                             }
                             $crossLinkElement = $this->_form->_createCheckbox($groupName . '[' . $optionKey . ']', $value, $optionKey);
                             $elementNamePrefix = $this->elementNamePrefix . $groupName . '__' . $optionKey . '_';
                             $elementNamePostfix = '_' . $this->elementNamePostfix;
                             //']';
                             if (isset($crossLinkDo->fb_crossLinkExtraFields)) {
                                 $row = array(&$crossLinkElement);
                                 if (isset($selected_options[$optionKey])) {
                                     $extraFieldDo = $selected_options[$optionKey];
                                 } else {
                                     unset($extraFieldDo);
                                     $extraFieldDo = DB_DataObject::factory($crossLink['table']);
                                 }
                                 unset($tempFb);
                                 $tempFb =& DB_DataObject_FormBuilder::create($extraFieldDo, false, 'QuickForm', get_class($this));
                                 $extraFieldDo->fb_fieldsToRender = $crossLinkDo->fb_crossLinkExtraFields;
                                 $extraFieldDo->fb_elementNamePrefix = $elementNamePrefix;
                                 $extraFieldDo->fb_elementNamePostfix = $elementNamePostfix;
                                 $extraFieldDo->fb_linkNewValue = false;
                                 $this->_extraFieldsFb[$elementNamePrefix . $elementNamePostfix] =& $tempFb;
                                 $tempForm = $tempFb->getForm();
                                 $colNames = array('');
                                 foreach ($crossLinkDo->fb_crossLinkExtraFields as $extraField) {
                                     if ($tempForm->elementExists($elementNamePrefix . $extraField . $elementNamePostfix)) {
                                         $tempEl =& $tempForm->getElement($elementNamePrefix . $extraField . $elementNamePostfix);
                                         $colNames[$extraField] = $tempEl->getLabel();
                                     } else {
                                         $tempEl =& $this->_form->_createStaticField($elementNamePrefix . $extraField . $elementNamePostfix, 'Error - element not found for extra field ' . $extraField);
                                     }
                                     $row[] =& $tempEl;
                                     if (!isset($formValues[$groupName . '__extraFields'])) {
                                         $formValues[$groupName . '__extraFields'] = array();
                                     }
                                     if (!isset($formValues[$groupName . '__extraFields'][$optionKey])) {
                                         $formValues[$groupName . '__extraFields'][$optionKey] = array();
                                     }
                                     $formValues[$groupName . '__extraFields'][$optionKey][$extraField] = $tempEl->getValue();
                                     unset($tempEl);
                                 }
                                 $element[] = $row;
                                 unset($tempFb, $tempForm, $extraFieldDo, $row);
                                 $rowNames[] = '<label for="' . $crossLinkElement->getAttribute('id') . '">' . $value . '</label>';
                                 $crossLinkElement->setText('');
                             } elseif ($crossLink['collapse']) {
                                 $element[] = array(&$crossLinkElement);
                                 $rowNames[] = '<label for="' . $crossLinkElement->getAttribute('id') . '">' . $value . '</label>';
                                 $crossLinkElement->setText('');
                                 $colNames = array();
                             } else {
                                 $element[] =& $crossLinkElement;
                             }
                             unset($crossLinkElement);
                         }
                         if (isset($crossLinkDo->fb_crossLinkExtraFields) || $crossLink['collapse']) {
                             $this->_form->_addElementGrid($groupName, array_values($colNames), $rowNames, $element);
                         } else {
                             $this->_form->_addElementGroup($element, $groupName, $this->crossLinkSeparator);
                         }
                         if ($crossLink['collapse']) {
                             $this->_form->_collapseRecordList($groupName);
                         }
                         unset($element);
                         unset($rowNames);
                         unset($colNames);
                     }
                     break;
                 case $type & DB_DATAOBJECT_FORMBUILDER_TRIPLELINK:
                     unset($element);
                     /*if ($pk === false) {
                           return PEAR::raiseError('A primary key must exist in the base table when using tripleLinks.');
                       }*/
                     $tripleLink = $this->tripleLinks[$key];
                     $elName = $this->_sanitizeFieldName('__tripleLink_' . $tripleLink['table'] . '_' . $tripleLink['fromField'] . '_' . $tripleLink['toField1'] . '_' . $tripleLink['toField2']);
                     $freeze = array_search($elName, $elements_to_freeze);
                     unset($tripleLinkDo);
                     $tripleLinkDo = DB_DataObject::factory($tripleLink['table']);
                     if (PEAR::isError($tripleLinkDo)) {
                         die($tripleLinkDo->getMessage());
                     }
                     if (!is_array($tripleLinkLinks = $tripleLinkDo->links())) {
                         $tripleLinkLinks = array();
                     }
                     list($linkedtable1, $linkedfield1) = explode(':', $tripleLinkLinks[$tripleLink['toField1']]);
                     list($linkedtable2, $linkedfield2) = explode(':', $tripleLinkLinks[$tripleLink['toField2']]);
                     list($fromtable, $fromfield) = explode(':', $tripleLinkLinks[$tripleLink['fromField']]);
                     //if ($fromtable !== $this->_do->tableName()) error?
                     $all_options1 = $this->_getSelectOptions($linkedtable1, false, false, false, $linkedfield1);
                     $all_options2 = $this->_getSelectOptions($linkedtable2, false, false, false, $linkedfield2);
                     $selected_options = array();
                     if (isset($this->_do->{$fromfield})) {
                         $tripleLinkDo->{$tripleLink['fromField']} = $this->_do->{$fromfield};
                         if ($this->isCallableAndExists($this->prepareLinkedDataObjectCallback)) {
                             call_user_func_array($this->prepareLinkedDataObjectCallback, array(&$tripleLinkDo, $key));
                         }
                         if ($tripleLinkDo->find() > 0) {
                             while ($tripleLinkDo->fetch()) {
                                 $selected_options[$tripleLinkDo->{$tripleLink['toField1']}][] = $tripleLinkDo->{$tripleLink['toField2']};
                             }
                         }
                     }
                     $columnNames = array();
                     foreach ($all_options2 as $key2 => $value2) {
                         $columnNames[] = $value2;
                     }
                     $rows = array();
                     $rowNames = array();
                     $formValues[$key] = array();
                     foreach ($all_options1 as $key1 => $value1) {
                         $rowNames[] = $value1;
                         $row = array();
                         foreach ($all_options2 as $key2 => $value2) {
                             unset($tripleLinkElement);
                             $tripleLinkElement = $this->_form->_createCheckbox($elName . '[' . $key1 . '][' . $key2 . ']', '', $key2);
                             if (isset($selected_options[$key1])) {
                                 if (in_array($key2, $selected_options[$key1])) {
                                     $tripleLinkName = '__tripleLink_' . $tripleLink['table'] . '_' . $tripleLink['fromField'] . '_' . $tripleLink['toField1'] . '_' . $tripleLink['toField2'];
                                     if (!isset($formValues[$tripleLinkName][$key1])) {
                                         $formValues[$tripleLinkName][$key1] = array();
                                     }
                                     $formValues[$tripleLinkName][$key1][$key2] = $key2;
                                 }
                             }
                             $row[] =& $tripleLinkElement;
                         }
                         $rows[] =& $row;
                         unset($row);
                     }
                     $this->_form->_addElementGrid($elName, $columnNames, $rowNames, $rows);
                     unset($columnNames, $rowNames, $rows);
                     break;
                 case $type & DB_DATAOBJECT_FORMBUILDER_ENUM:
                     if ($this->useAccessors && method_exists($this->_do, 'get' . $key)) {
                         $formValues[$key] = $this->_do->{'get' . $key}();
                     } else {
                         $formValues[$key] = $this->_do->{$key};
                     }
                     if (!isset($element)) {
                         $isRadio = isset($this->linkElementTypes[$key]) && $this->linkElementTypes[$key] == 'radio';
                         if (isset($this->enumOptions[$key])) {
                             $options = $this->enumOptions[$key];
                         } else {
                             if ($this->isCallableAndExists($this->enumOptionsCallback)) {
                                 $options = call_user_func($this->enumOptionsCallback, $this->_do->__table, $key);
                             } else {
                                 $options =& PEAR::raiseError('enumOptionsCallback is an invalid callback');
                             }
                             if (PEAR::isError($options)) {
                                 return $options;
                             }
                         }
                         /*if (array_keys($options) === range(0, count($options)-1)) {
                               $newOptions = array();
                               foreach ($options as $value) {
                                   $newOptions[$value] = $value;
                               }
                               $options = $newOptions;
                           }*/
                         if (in_array($key, $this->selectAddEmpty) || !($type & DB_DATAOBJECT_NOTNULL)) {
                             $options = array('' => $isRadio ? $this->radioAddEmptyLabel : $this->selectAddEmptyLabel) + $options;
                         }
                         if (!$options) {
                             return PEAR::raiseError('There are no options defined for the enum field "' . $key . '". You may need to set the options in the enumOptions option or use your own enumOptionsCallback.');
                         }
                         $element = array();
                         if ($isRadio) {
                             $element =& $this->_form->_createRadioButtons($key, $options);
                         } else {
                             $element =& $this->_form->_createSelectBox($key, $options);
                         }
                         unset($options);
                     }
                     break;
                 case $type & DB_DATAOBJECT_FORMBUILDER_REVERSELINK:
                     unset($element);
                     $element = array();
                     $elName = $this->_sanitizeFieldName('__reverseLink_' . $this->reverseLinks[$key]['table'] . '_' . $this->reverseLinks[$key]['field']);
                     unset($do);
                     $do = DB_DataObject::factory($this->reverseLinks[$key]['table']);
                     if ($this->isCallableAndExists($this->prepareLinkedDataObjectCallback)) {
                         call_user_func_array($this->prepareLinkedDataObjectCallback, array(&$do, $key));
                     }
                     if (!is_array($rLinks = $do->links())) {
                         $rLinks = array();
                     }
                     $rPk = $this->_getPrimaryKey($do);
                     //$rFields = $do->table();
                     list($lTable, $lField) = explode(':', $rLinks[$this->reverseLinks[$key]['field']]);
                     $formValues[$elName] = array();
                     if ($this->reverseLinks[$key]['collapse']) {
                         $table = $rowNames = array();
                     }
                     /*
                     if (isset($this->linkElementTypes[$elName])
                         && $this->linkElementTypes[$elName] == 'subForm') {
                         // Do this to find only reverseLinks with the correct foreign key.
                         $do->{$this->reverseLinks[$key]['field']} = $this->_do->{$this->_getPrimaryKey($this->_do)};
                     }
                     */
                     if ($do->find()) {
                         while ($do->fetch()) {
                             $label = $this->getDataObjectString($do);
                             if ($do->{$this->reverseLinks[$key]['field']} == $this->_do->{$lField}) {
                                 $formValues[$elName][$do->{$rPk}] = $do->{$rPk};
                             } elseif ($rLinked =& $do->getLink($this->reverseLinks[$key]['field'])) {
                                 $label .= '<b>' . $this->reverseLinks[$key]['linkText'] . $this->getDataObjectString($rLinked) . '</b>';
                             }
                             if (isset($this->linkElementTypes[$elName]) && $this->linkElementTypes[$elName] == 'subForm') {
                                 unset($subFB, $subForm, $subFormEl);
                                 $subFB =& DB_DataObject_FormBuilder::create($do, false, 'QuickForm', get_class($this));
                                 $this->reverseLinks[$key]['FBs'][] =& $subFB;
                                 $subFB->elementNamePrefix = $elName;
                                 $subFB->elementNamePostfix = '_' . count($this->reverseLinks[$key]['FBs']);
                                 $subFB->createSubmit = false;
                                 $subFB->formHeaderText = $this->getDataObjectString($do);
                                 //$this->getFieldLabel($elName).' '.count($this->reverseLinks[$key]['FBs']);
                                 $do->fb_linkNewValue = false;
                                 $subForm =& $subFB->getForm();
                                 $this->reverseLinks[$key]['SFs'][] = $subForm;
                                 $subFormEl =& $this->_form->_createSubForm($elName . count($this->reverseLinks[$key]['FBs']), null, $subForm);
                                 $element[] =& $subFormEl;
                             } else {
                                 if ($this->reverseLinks[$key]['collapse']) {
                                     $table[] = array($this->_form->_createCheckbox($elName . '[' . $do->{$rPk} . ']', '', $do->{$rPk}));
                                     $rowNames[] = $label;
                                 } else {
                                     $element[] =& $this->_form->_createCheckbox($elName . '[' . $do->{$rPk} . ']', $label, $do->{$rPk});
                                 }
                             }
                         }
                     }
                     if (isset($this->reverseLinkNewValue[$elName]) && $this->reverseLinkNewValue[$elName] !== false) {
                         if (is_int($this->reverseLinkNewValue[$elName])) {
                             $totalSubforms = $this->reverseLinkNewValue[$elName];
                         } else {
                             $totalSubforms = 1;
                         }
                         for ($i = 0; $i < $totalSubforms; $i++) {
                             unset($subFB, $subForm, $subFormEl);
                             // Add a subform to add a new reverseLink record.
                             $do = DB_DataObject::factory($this->reverseLinks[$key]['table']);
                             $do->{$lField} = $this->_do->{$this->_getPrimaryKey($this->_do)};
                             $subFB =& DB_DataObject_FormBuilder::create($do, false, 'QuickForm', get_class($this));
                             $this->reverseLinks[$key]['FBs'][] =& $subFB;
                             $subFB->elementNamePrefix = $elName;
                             $subFB->elementNamePostfix = '_' . count($this->reverseLinks[$key]['FBs']);
                             $subFB->createSubmit = false;
                             $subFB->formHeaderText = 'New ' . (isset($do->fb_formHeaderText) ? $do->fb_formHeaderText : $this->prettyName($do->__table));
                             $do->fb_linkNewValue = false;
                             $subForm =& $subFB->getForm();
                             $this->reverseLinks[$key]['SFs'][] =& $subForm;
                             $subFormEl =& $this->_form->_createSubForm($elName . count($this->reverseLinks[$key]['FBs']), null, $subForm);
                             $element[] =& $subFormEl;
                         }
                     }
                     if ($this->reverseLinks[$key]['collapse']) {
                         $this->_form->_addElementGrid($elName, array(), $rowNames, $table);
                         $this->_form->_collapseRecordList($elName);
                     } else {
                         $this->_form->_addElementGroup($element, $elName, $this->crossLinkSeparator);
                     }
                     unset($element);
                     break;
                 case $type & DB_DATAOBJECT_FORMBUILDER_GROUP:
                     unset($element);
                     $element =& $this->_form->_createHiddenField($key . '__placeholder');
                     break;
                 default:
                     if ($this->useAccessors && method_exists($this->_do, 'get' . $key)) {
                         $formValues[$key] = $this->_do->{'get' . $key}();
                     } else {
                         $formValues[$key] = $this->_do->{$key};
                     }
                     if (!isset($element)) {
                         $element =& $this->_form->_createTextField($key);
                     }
             }
             // End switch
             //} // End else
             if ($elValidator !== false) {
                 if (!isset($rules[$key])) {
                     $rules[$key] = array();
                 }
                 $rules[$key][] = array('validator' => $elValidator, 'rule' => $elValidRule, 'message' => $this->ruleViolationMessage);
             }
             // End if
         }
         // End else
         //GROUP OR ELEMENT ADDITION
         if (isset($this->preDefGroups[$key]) && !($type & DB_DATAOBJECT_FORMBUILDER_GROUP)) {
             $group = $this->preDefGroups[$key];
             $groups[$group][] = $element;
         } elseif (isset($element)) {
             if (is_array($element)) {
                 $this->_form->_addElementGroup($element, $key);
             } else {
                 $this->_form->_addElement($element);
             }
         }
         // End if
         //SET AUTO-RULES IF NOT DEACTIVATED FOR THIS OR ALL ELEMENTS
         if (!$this->_excludeAllFromAutoRules && !in_array($key, $this->excludeFromAutoRules)) {
             //ADD REQURED RULE FOR NOT_NULL FIELDS
             if ((!in_array($key, $keys) || $this->hidePrimaryKey == false) && $type & DB_DATAOBJECT_NOTNULL && !in_array($key, $elements_to_freeze) && !($type & DB_DATAOBJECT_BOOL)) {
                 $this->_form->_setFormElementRequired($key);
                 $this->debug('Adding required rule for ' . $key);
             }
             // VALIDATION RULES
             if (isset($rules[$key])) {
                 $this->_form->_addFieldRules($rules[$key], $key);
                 $this->debug("Adding rule '{$rules[$key]}' to {$key}");
             }
         } else {
             $this->debug($key . ' excluded from auto-rules');
         }
     }
     // End foreach
     if ($this->linkNewValue) {
         $this->_form->_addRuleForLinkNewValues();
     }
     // Freeze fields that are not to be edited by the user
     $this->_form->_freezeFormElements($elements_to_freeze);
     //GROUP SUBMIT
     $flag = true;
     if (isset($this->preDefGroups['__submit__'])) {
         $group = $this->preDefGroups['__submit__'];
         if (count($groups[$group]) > 1) {
             $groups[$group][] =& $this->_form->_createSubmitButton('__submit__', $this->submitText);
             $flag = false;
         } else {
             $flag = true;
         }
     }
     //GROUPING
     if (isset($groups) && is_array($groups)) {
         //apply grouping
         reset($groups);
         while (list($grp, $elements) = each($groups)) {
             if (count($elements) == 1) {
                 $this->_form->_addElement($elements[0]);
                 $this->_form->_moveElementBefore($this->_form->_getElementName($elements[0]), $grp . '__placeholder');
             } elseif (count($elements) > 1) {
                 $this->_form->_addElementGroup($elements, $grp, '&nbsp;');
                 $this->_form->_moveElementBefore($grp, $grp . '__placeholder');
             }
         }
     }
     //ELEMENT SUBMIT
     if ($flag == true && $this->createSubmit == true) {
         $this->_form->_addSubmitButton('__submit__', $this->submitText);
     }
     $this->_form->_finishForm();
     // Assign default values to the form
     $fixedFormValues = array();
     foreach ($formValues as $key => $value) {
         $fixedFormValues[$this->getFieldName($key)] = $value;
     }
     $this->_form->_setFormDefaults($fixedFormValues);
     return $this->_form->getForm();
 }
Beispiel #5
0
 /**
  * Populates internal vars for linkNewValue
  *
  * @param  string the name of the element we're creating the form for
  * @param  string the name of the table to create the form for (linked table)
  */
 function _prepareForLinkNewValue($elName, $subTable)
 {
     if (!isset($this->_linkNewValueDOs[$elName])) {
         $this->_linkNewValueDOs[$elName] = DB_DataObject::factory($subTable);
         $this->_linkNewValueDOs[$elName]->fb_createSubmit = false;
         $this->_linkNewValueDOs[$elName]->fb_elementNamePrefix = $this->elementNamePrefix . $elName . '_' . $subTable . '__';
         $this->_linkNewValueDOs[$elName]->fb_elementNamePostfix = $this->elementNamePostfix;
         //$this->_linkNewValueDOs[$elName]->fb_linkNewValue = false;
         $this->_linkNewValueFBs[$elName] =& DB_DataObject_FormBuilder::create($this->_linkNewValueDOs[$elName], false, 'QuickForm', get_class($this->_fb));
         $this->_linkNewValueForms[$elName] =& $this->_linkNewValueFBs[$elName]->getForm();
         $this->_linkNewValueForms[$elName]->addElement('hidden', $this->elementNamePrefix . '__DB_DataObject_FormBuilder_linkNewValue__' . $elName . $this->elementNamePostfix, $subTable);
     }
 }
Beispiel #6
0
function makeEditAutoreplyForm($selfurl, $id = null)
{
    global $uid, $addText, $backText;
    $errNoSpaces = "You cannot have spaces in a keyword; keywords are separated <em>by</em> spaces.";
    $do = DB_DataObject::factory('playsms_featAutoreply');
    if ($id) {
        $do->get($id);
    } else {
        $do->uid = $uid;
    }
    $fb = DB_DataObject_FormBuilder::create($do, array('fieldsToRender' => array('autoreply_code')));
    $fb->submitText = "Save";
    $form = $fb->getForm("{$selfurl}&op=edit&id={$id}");
    $form->addRule('autoreply_code', $errNoSpaces, 'regex', '/^[^ ]+$/');
    if ($form->validate()) {
        $form->process(array(&$fb, 'processForm'), false);
        // if we're adding a new item, then forward
        // on to editing that item so that the user doesn't
        // add it over and over again
        header("Location: {$selfurl}&op=edit&id={$do->autoreply_id}");
    }
    $form->display();
    $addLink = "<a href=\"{$selfurl}&op=addScenario&autoreply_id={$id}\" title=\"Add Scenario\">[add scenario]</a>";
    $backLink = "<a href=\"{$selfurl}&op=list\">{$backText}</a>";
    // only show the add-scenario link if
    // we're not in the process of adding the autoreply
    if (isset($do->autoreply_id)) {
        echo "{$addLink} &nbsp;";
    }
    echo "{$backLink}";
    echo "<hr/>";
    if ($id) {
        echo genDelForm("delScenario", "{$selfurl}&op=delScenario");
        echo generateScenarios($selfurl, $id);
    }
}
 /**
  * DB_DataObject_FormBuilder::_generateForm()
  *
  * Builds a simple HTML form for the current DataObject. Internal function, called by
  * the public getForm() method. You can override this in child classes if needed, but
  * it's also possible to leave this as it is and just override the getForm() method
  * to simply fine-tune the auto-generated form object (i.e. add/remove elements, alter
  * options, add/remove rules etc.).
  * If a key with the same name as the current field is found in the fb_preDefElements
  * property, the QuickForm element object contained in that array will be used instead
  * of auto-generating a new one. This allows for complete step-by-step customizing of
  * your forms.
  *
  * Note for date fields: HTML_QuickForm allows passing of an options array to the
  * HTML_QuickForm_date element. You can define your own options array for date elements
  * in your DataObject-derived classes by defining a method "dateOptions($fieldName)".
  * FormBuilder will call that method whenever it encounters a date field and expects to
  * get back a valid options array.
  *
  * @param string $action   The form action. Optional. If set to false (default), PHP_SELF is used.
  * @param string $target   The window target of the form. Optional. Defaults to '_self'.
  * @param string $formName The name of the form, will be used in "id" and "name" attributes. If set to false (default), the class name is used
  * @param string $method   The submit method. Defaults to 'post'.
  * @return object
  * @access protected
  * @author Markus Wolff <*****@*****.**>
  * @author Fabien Franzen <*****@*****.**>
  */
 function &_generateForm($action = false, $target = '_self', $formName = false, $method = 'post')
 {
     if ($formName === false) {
         $formName = strtolower(get_class($this->_do));
     }
     if ($action === false) {
         $action = $_SERVER['PHP_SELF'];
     }
     // Retrieve the form object to use (may depend on the current renderer)
     $form =& $this->_createFormObject($formName, $method, $action, $target);
     // Initialize array with default values
     $formValues = $this->_do->toArray();
     // Add a header to the form - set addFormHeader property to false to prevent this
     $this->_addFormHeader($form);
     // Go through all table fields and create appropriate form elements
     $keys = $this->_do->keys();
     // Reorder elements if requested
     $elements = $this->_reorderElements();
     if ($elements == false) {
         //no sorting necessary
         $elements = $this->_getFieldsToRender();
     }
     //get elements to freeze
     $user_editable_fields = $this->_getUserEditableFields();
     if (is_array($user_editable_fields)) {
         $elements_to_freeze = array_diff(array_keys($elements), $user_editable_fields);
     } else {
         $elements_to_freeze = array();
     }
     $links = $this->_do->links();
     $pk = $this->_getPrimaryKey($this->_do);
     $rules = array();
     foreach ($elements as $key => $type) {
         // Check if current field is primary key. And primary key hiding is on. If so, make hidden field
         if (in_array($key, $keys) && $this->hidePrimaryKey == true) {
             $element =& $this->_createHiddenField($key);
         } else {
             unset($element);
             // Try to determine field types depending on object properties
             $notNull = $type & DB_DATAOBJECT_NOTNULL;
             if (in_array($key, $this->dateFields)) {
                 $type = DB_DATAOBJECT_DATE;
             } elseif (in_array($key, $this->timeFields)) {
                 $type = DB_DATAOBJECT_TIME;
             } elseif (in_array($key, $this->textFields)) {
                 $type = DB_DATAOBJECT_TXT;
             } elseif (in_array($key, $this->enumFields)) {
                 $type = DB_DATAOBJECT_FORMBUILDER_ENUM;
             } elseif (in_array($key, $this->booleanFields)) {
                 $type = DB_DATAOBJECT_BOOL;
             }
             if (isset($this->preDefElements[$key]) && (is_object($this->preDefElements[$key]) || is_array($this->preDefElements[$key]))) {
                 // Use predefined form field, IMPORTANT: This may depend on the used renderer!!
                 $element =& $this->preDefElements[$key];
             } elseif (is_array($links) && isset($links[$key])) {
                 // If this field links to another table, display selectbox or radiobuttons
                 $opt = $this->getSelectOptions($key, false, !$notNull);
                 if (isset($this->linkElementTypes[$key]) && $this->linkElementTypes[$key] == 'radio') {
                     $element =& $this->_createRadioButtons($key, $opt);
                 } else {
                     $element =& $this->_createSelectBox($key, $opt);
                 }
                 unset($opt);
             }
             // No predefined object available, auto-generate new one
             $elValidator = false;
             $elValidRule = false;
             // Auto-detect field types depending on field's database type
             switch (true) {
                 case $type & DB_DATAOBJECT_INT:
                     if (!isset($element)) {
                         $element =& $this->_createIntegerField($key);
                         $elValidator = 'numeric';
                     }
                     break;
                 case $type & DB_DATAOBJECT_DATE:
                     // TODO
                     $this->debug('DATE CONVERSION using callback for element ' . $key . ' (' . $this->_do->{$key} . ')!', 'FormBuilder');
                     $formValues[$key] = call_user_func($this->dateFromDatabaseCallback, $this->_do->{$key});
                     if (!isset($element)) {
                         $element =& $this->_createDateElement($key);
                     }
                     break;
                 case $type & (DB_DATAOBJECT_DATE | DB_DATAOBJECT_TIME):
                     $this->debug('DATE & TIME CONVERSION using callback for element ' . $key . ' (' . $this->_do->{$key} . ')!', 'FormBuilder');
                     $formValues[$key] = call_user_func($this->dateFromDatabaseCallback, $this->_do->{$key});
                     if (!isset($element)) {
                         $element =& $this->_createDateElement($key);
                     }
                     break;
                 case $type & DB_DATAOBJECT_TIME:
                     $this->debug('TIME CONVERSION using callback for element ' . $key . ' (' . $this->_do->{$key} . ')!', 'FormBuilder');
                     $formValues[$key] = call_user_func($this->dateFromDatabaseCallback, $this->_do->{$key});
                     if (!isset($element)) {
                         $element =& $this->_createTimeElement($key);
                     }
                     break;
                 case $type & DB_DATAOBJECT_BOOL:
                     $formValues[$key] = $this->_do->{$key};
                     if (!isset($element)) {
                         $element =& $this->_createCheckbox($key, null, null, $this->getFieldLabel($key));
                     }
                     break;
                 case $type & DB_DATAOBJECT_TXT:
                     if (!isset($element)) {
                         $element =& $this->_createTextArea($key);
                     }
                     break;
                 case $type & DB_DATAOBJECT_STR:
                     if (!isset($element)) {
                         // If field content contains linebreaks, make textarea - otherwise, standard textbox
                         if (isset($this->_do->{$key}) && strlen($this->_do->{$key}) && strstr($this->_do->{$key}, "\n")) {
                             $element =& $this->_createTextArea($key);
                         } else {
                             $element =& $this->_createTextField($key);
                         }
                     }
                     break;
                 case $type & DB_DATAOBJECT_FORMBUILDER_CROSSLINK:
                     unset($element);
                     // generate crossLink stuff
                     if ($pk === false) {
                         return PEAR::raiseError('A primary key must exist in the base table when using crossLinks.');
                     }
                     $crossLink = $this->crossLinks[$key];
                     $groupName = '__crossLink_' . $crossLink['table'];
                     $crossLinksDo = DB_DataObject::factory($crossLink['table']);
                     if (PEAR::isError($crossLinksDo)) {
                         die($crossLinksDo->getMessage());
                     }
                     $crossLinksLinks = $crossLinksDo->links();
                     list($linkedtable, $linkedfield) = explode(':', $crossLinksLinks[$crossLink['toField']]);
                     $all_options = $this->_getSelectOptions($linkedtable);
                     $selected_options = array();
                     if (isset($this->_do->{$pk}) && strlen($this->_do->{$pk})) {
                         $crossLinksDo->{$crossLink['fromField']} = $this->_do->{$pk};
                         if ($crossLinksDo->find() > 0) {
                             while ($crossLinksDo->fetch()) {
                                 $selected_options[$crossLinksDo->{$crossLink['toField']}] = clone $crossLinksDo;
                             }
                         }
                     }
                     if (isset($crossLink['type']) && $crossLink['type'] == 'select') {
                         unset($element);
                         $element =& $this->_createSelectBox($groupName, $all_options, true);
                         $formValues[$groupName] = array_keys($selected_options);
                         // set defaults later
                         // ***X*** generate checkboxes
                     } else {
                         $element = array();
                         $rowNames = array();
                         $colNames = array('');
                         foreach ($all_options as $optionKey => $value) {
                             $crossLinksElement = $this->_createCheckbox($groupName . '[' . $optionKey . ']', $value, $optionKey);
                             $elementNamePrefix = $this->elementNamePrefix . $groupName . '__extraFields' . $this->elementNamePostfix . '[' . $optionKey . '][';
                             $elementNamePostfix = ']';
                             if (isset($selected_options[$optionKey])) {
                                 if (!isset($formValues[$groupName])) {
                                     $formValues[$groupName] = array();
                                 }
                                 $formValues[$groupName][$optionKey] = $optionKey;
                             }
                             if (isset($crossLinksDo->fb_crossLinkExtraFields)) {
                                 $row = array(&$crossLinksElement);
                                 if (isset($selected_options[$optionKey])) {
                                     $extraFieldDo = $selected_options[$optionKey];
                                 } else {
                                     $extraFieldDo = DB_DataObject::factory($crossLink['table']);
                                 }
                                 $tempFb =& DB_DataObject_FormBuilder::create($extraFieldDo);
                                 $extraFieldDo->fb_fieldsToRender = $crossLinksDo->fb_crossLinkExtraFields;
                                 $extraFieldDo->fb_elementNamePrefix = $elementNamePrefix;
                                 $extraFieldDo->fb_elementNamePostfix = $elementNamePostfix;
                                 $tempForm = $tempFb->getForm();
                                 foreach ($crossLinksDo->fb_crossLinkExtraFields as $extraField) {
                                     if ($tempForm->elementExists($elementNamePrefix . $extraField . $elementNamePostfix)) {
                                         $tempEl =& $tempForm->getElement($elementNamePrefix . $extraField . $elementNamePostfix);
                                         $colNames[$extraField] = $tempEl->getLabel();
                                     } else {
                                         $tempEl =& $this->_createStaticField($elementNamePrefix . $extraField . $elementNamePostfix, 'Error - element not found for extra field ' . $extraField);
                                     }
                                     $row[] =& $tempEl;
                                     if (!isset($formValues[$groupName . '__extraFields'])) {
                                         $formValues[$groupName . '__extraFields'] = array();
                                     }
                                     if (!isset($formValues[$groupName . '__extraFields'][$optionKey])) {
                                         $formValues[$groupName . '__extraFields'][$optionKey] = array();
                                     }
                                     $formValues[$groupName . '__extraFields'][$optionKey][$extraField] = $tempEl->getValue();
                                     unset($tempEl);
                                 }
                                 $element[] = $row;
                                 unset($tempFb, $tempForm, $extraFieldDo, $row);
                                 $rowNames[] = '<label for="' . $crossLinksElement->getAttribute('id') . '">' . $value . '</label>';
                                 $crossLinksElement->setText('');
                             } else {
                                 $element[] = $crossLinksElement;
                             }
                             unset($crossLinksElement);
                         }
                         if (isset($crossLinksDo->fb_crossLinkExtraFields)) {
                             $this->_addElementTableToForm($form, $groupName, array_values($colNames), $rowNames, $element);
                         } else {
                             $this->_addElementGroupToForm($form, $element, $groupName, $this->crossLinkSeparator);
                         }
                         unset($element);
                         unset($rowNames);
                         unset($colNames);
                     }
                     break;
                 case $type & DB_DATAOBJECT_FORMBUILDER_TRIPLELINK:
                     unset($element);
                     if ($pk === false) {
                         return PEAR::raiseError('A primary key must exist in the base table when using tripleLinks.');
                     }
                     $tripleLink = $this->tripleLinks[$key];
                     $elName = '__tripleLink_' . $tripleLink['table'];
                     $freeze = array_search($elName, $elements_to_freeze);
                     $tripleLinkDo = DB_DataObject::factory($tripleLink['table']);
                     if (PEAR::isError($tripleLinkDo)) {
                         die($tripleLinkDo->getMessage());
                     }
                     $tripleLinksLinks = $tripleLinkDo->links();
                     $fromField = $tripleLink['fromField'];
                     $toField1 = $tripleLink['toField1'];
                     $toField2 = $tripleLink['toField2'];
                     list($linkedtable1, $linkedfield1) = explode(':', $tripleLinksLinks[$toField1]);
                     list($linkedtable2, $linkedfield2) = explode(':', $tripleLinksLinks[$toField2]);
                     $all_options1 = $this->_getSelectOptions($linkedtable1);
                     $all_options2 = $this->_getSelectOptions($linkedtable2);
                     $selected_options = array();
                     if (isset($this->_do->{$pk}) && strlen($this->_do->{$pk})) {
                         $tripleLinkDo->{$fromField} = $this->_do->{$pk};
                         if ($tripleLinkDo->find() > 0) {
                             while ($tripleLinkDo->fetch()) {
                                 $selected_options[$tripleLinkDo->{$toField1}][] = $tripleLinkDo->{$toField2};
                             }
                         }
                     }
                     $columnNames = array();
                     foreach ($all_options2 as $key2 => $value2) {
                         $columnNames[] = $value2;
                     }
                     $rows = array();
                     $rowNames = array();
                     $formValues[$key] = array();
                     foreach ($all_options1 as $key1 => $value1) {
                         $rowNames[] = $value1;
                         $row = array();
                         foreach ($all_options2 as $key2 => $value2) {
                             unset($tripleLinksElement);
                             $tripleLinksElement = $this->_createCheckbox($elName . '[' . $key1 . '][' . $key2 . ']', '', $key2);
                             if (isset($selected_options[$key1])) {
                                 if (in_array($key2, $selected_options[$key1])) {
                                     if (!isset($formValues['__tripleLink_' . $tripleLink['table']][$key1])) {
                                         $formValues['__tripleLink_' . $tripleLink['table']][$key1] = array();
                                     }
                                     $formValues['__tripleLink_' . $tripleLink['table']][$key1][$key2] = $key2;
                                 }
                             }
                             $row[] =& $tripleLinksElement;
                         }
                         $rows[] =& $row;
                         unset($row);
                     }
                     $this->_addElementTableToForm($form, $elName, $columnNames, $rowNames, $rows);
                     unset($columnNames, $rowNames, $rows);
                     break;
                 case $type & DB_DATAOBJECT_FORMBUILDER_ENUM:
                     if (!isset($element)) {
                         if (isset($this->enumOptions[$key])) {
                             $options = $this->enumOptions[$key];
                         } else {
                             $options = call_user_func($this->enumOptionsCallback, $this->_do->__table, $key);
                         }
                         if (in_array($key, $this->selectAddEmpty) || !$notNull) {
                             array_unshift($options, '');
                         }
                         if (!$options) {
                             return PEAR::raiseError('There are no options defined for the enum field "' . $key . '". You may need to set the options in the enumOptions option or use your own enumOptionsCallback.');
                         }
                         $element = array();
                         if (isset($this->linkElementTypes[$key]) && $this->linkElementTypes[$key] == 'radio') {
                             foreach ($options as $option) {
                                 $element =& $this->_createRadioButtons($key, $options);
                             }
                         } else {
                             $element =& $this->_createSelectBox($key, $options);
                         }
                         unset($options);
                     }
                     break;
                 case $type & DB_DATAOBJECT_FORMBUILDER_REVERSELINK:
                     unset($element);
                     $element = array();
                     $elName = '__reverseLink_' . $this->reverseLinks[$key]['table'] . '_' . $this->reverseLinks[$key]['field'];
                     $do = DB_DataObject::factory($this->reverseLinks[$key]['table']);
                     if (method_exists($this->_do, 'preparelinkeddataobject')) {
                         if ($this->useCallTimePassByReference) {
                             $this->_do->prepareLinkedDataObject(&$do, $key);
                         } else {
                             $this->_do->prepareLinkedDataObject($do, $key);
                         }
                     }
                     $rLinks = $do->links();
                     $rPk = $this->_getPrimaryKey($do);
                     //$rFields = $do->table();
                     list($lTable, $lField) = explode(':', $rLinks[$this->reverseLinks[$key]['field']]);
                     $formValues[$elName] = array();
                     if ($do->find()) {
                         while ($do->fetch()) {
                             $label = $this->getDataObjectString($do);
                             if ($do->{$this->reverseLinks[$key]['field']} == $this->_do->{$lField}) {
                                 $formValues[$elName][$do->{$rPk}] = $do->{$rPk};
                             } elseif ($rLinked =& $do->getLink($this->reverseLinks[$key]['field'])) {
                                 $label .= '<b>' . $this->reverseLinks[$key]['linkText'] . $this->getDataObjectString($rLinked) . '</b>';
                             }
                             $element[] =& $this->_createCheckbox($elName . '[' . $do->{$rPk} . ']', $label, $do->{$rPk});
                         }
                     }
                     $this->_addElementGroupToForm($form, $element, $elName, $this->crossLinkSeparator);
                     unset($element);
                     break;
                 default:
                     if (!isset($element)) {
                         $element =& $this->_createTextField($key);
                     }
             }
             // End switch
             //} // End else
             if ($elValidator !== false) {
                 if (!isset($rules[$key])) {
                     $rules[$key] = array();
                 }
                 $rules[$key][] = array('validator' => $elValidator, 'rule' => $elValidRule, 'message' => $this->ruleViolationMessage);
             }
             // End if
         }
         // End else
         //GROUP OR ELEMENT ADDITION
         if (isset($this->preDefGroups[$key])) {
             $group = $this->preDefGroups[$key];
             $groups[$group][] = $element;
         } elseif (isset($element)) {
             if (is_array($element)) {
                 $this->_addElementGroupToForm($form, $element, $key);
             } else {
                 $this->_addElementToForm($form, $element);
             }
         }
         // End if
         //ADD REQURED RULE FOR NOT_NULL FIELDS
         if ((!in_array($key, $keys) || $this->hidePrimaryKey == false) && $notNull && !in_array($key, $elements_to_freeze)) {
             $this->_setFormElementRequired($form, $key);
         }
         // VALIDATION RULES
         if (isset($rules[$key])) {
             $this->_addFieldRulesToForm($form, $rules[$key], $key);
         }
     }
     // End foreach
     // Freeze fields that are not to be edited by the user
     $this->_freezeFormElements($form, $elements_to_freeze);
     //GROUP SUBMIT
     $flag = true;
     if (isset($this->preDefGroups['__submit__'])) {
         $group = $this->preDefGroups['__submit__'];
         if (count($groups[$group]) > 1) {
             $groups[$group][] =& $this->_createSubmitButton('__submit__', $this->submitText);
             $flag = false;
         } else {
             $flag = true;
         }
     }
     //GROUPING
     if (isset($groups) && is_array($groups)) {
         //apply grouping
         reset($groups);
         while (list($grp, $elements) = each($groups)) {
             if (count($elements) == 1) {
                 $this->_addElementToForm($form, $elements[0]);
             } elseif (count($elements) > 1) {
                 $this->_addElementGroupToForm($form, $elements, $grp, '&nbsp;');
             }
         }
     }
     //ELEMENT SUBMIT
     if ($flag == true && $this->createSubmit == true) {
         $this->_addSubmitButtonToForm($form, '__submit__', $this->submitText);
     }
     //APPEND EXISTING FORM ELEMENTS
     if (is_a($this->_form, 'html_quickform') && $this->_appendForm == true) {
         // There somehow needs to be a new method in QuickForm that allows to fetch
         // a list of all element names currently registered in a form. Otherwise, there
         // will be need for some really nasty workarounds once QuickForm adopts PHP5's
         // new encapsulation features.
         reset($this->_form->_elements);
         while (list($elNum, $element) = each($this->_form->_elements)) {
             $this->_addElementToForm($form, $element);
         }
     }
     // Assign default values to the form
     $fixedFormValues = array();
     foreach ($formValues as $key => $value) {
         $fixedFormValues[$this->getFieldName($key)] = $value;
     }
     $this->_setFormDefaults($form, $fixedFormValues);
     return $form;
 }