function preGenerateForm(&$fb, &$obj) { $info = $obj->_getPluginsDef(); $info = $info['images']; HTML_QuickForm::registerElementType('imagefile', 'HTML/QuickForm/imagefile.php', 'HTML_QuickForm_imagefile'); foreach ($info as $k => $v) { $v = key_exists(0, $v) ? $v[0] : $v; switch (true) { case $v['x'] && $v['y']: $newSize = $v['x'] . ' X ' . $v['y'] . ' pixels'; break; case $v['x'] && !$v['y']: $newSize = $v['x'] . ' ' . __('pixels wide (proportions kept)'); break; case !$v['x'] && $v['y']: $newSize = $v['y'] . ' ' . __('pixels high (proportions kept)'); break; default: $newSize = ''; break; } $obj->fb_fieldLabels[$k] = array($obj->fb_fieldLabels[$k], 'note' => $newSize ? '. ' . __('Image will be resized to %s', array($newSize)) : ''); if (!empty($obj->{$k})) { //TODO move this to postGenerateForm (like in upload plugin) $obj->fb_fieldLabels[$k]['unit'] = '<input type="checkbox" name="__image_delete_' . $k . '" value="1" />' . __('Delete current'); } $obj->fb_preDefElements[$k] =& MyQuickForm::createElement('imagefile', $obj->fb_elementNamePrefix . $k . $obj->fb_elementNamePostfix, $obj->fb_fieldLabels[$k], array('showimage' => $v['showimage']), SITE_URL . WWW_IMAGES_FOLDER . $info[$k][0]['path'] . '/'); } }
function &_createSelectBox($fieldName, $options, $multiple = false) { if ($multiple) { $element = MyQuickForm::createElement($this->_getQFType('multiselect'), $this->_fb->getFieldName($fieldName), $this->_fb->getFieldLabel($fieldName), $options, array('multiple' => 'multiple')); } else { $element = MyQuickForm::createElement($this->_getQFType('select'), $this->_fb->getFieldName($fieldName), $this->_fb->getFieldLabel($fieldName), $options); $attr = $this->_getAttributes('select', $fieldName); $element->updateAttributes($attr); if (isset($this->linkNewValue[$fieldName])) { $links = $this->_fb->_do->links(); if (isset($links[$fieldName])) { list($table, ) = explode(':', $links[$fieldName]); $element->addOption($this->linkNewValueText, $this->linkNewValueText); $element->updateAttributes(array('onchange' => 'db_do_fb_' . $this->_fb->getFieldName($fieldName) . '__subForm_display(this)')); $element->updateAttributes(array('id' => $element->getName())); $this->_prepareForLinkNewValue($fieldName, $table); $subFormElement = self::createElement($this->_getQFType('subForm'), $this->_fb->getFieldName($fieldName) . '__subForm', '', $this->_linkNewValueForms[$fieldName]); $subFormElement->setPreValidationCallback(array(&$subFormElement, 'preValidationCallback')); $subFormElement->linkNewValueText = $this->linkNewValueText; $subFormElement->selectName = $this->_fb->getFieldName($fieldName); $el =& $this->_form->addElement('hidden', $this->_fb->getFieldName($fieldName) . '__subForm__displayed'); $el->updateAttributes(array('id' => $el->getName())); $element = MyQuickForm::createElement('group', $this->_fb->getFieldName($fieldName), $this->_fb->getFieldLabel($fieldName), array($element, $subFormElement), '', false); } } } return $element; }
public function preGenerateForm(&$fb, &$obj) { $uploadFields = $obj->_getPluginsDef(); $uploadFields = $uploadFields['upload']; $upFields = array_keys($uploadFields); foreach ($upFields as $k) { $obj->fb_preDefElements[$k] = MyQuickForm::createElement('file', $obj->fb_elementNamePrefix . $k . $obj->fb_elementNamePostfix, $obj->fb_fieldsLabel[$k]); } }
public function after_form($form, $fb) { $obj = $fb->_do; $defs = $obj->_getPluginsDef(); $defs = $defs['user']; if ($form->elementExists($fb->elementNamePrefix . $defs['pwd'] . $fb->elementNamePostfix)) { $pwd = $form->getElement($fb->elementNamePrefix . $defs['pwd'] . $fb->elementNamePostfix); $pwd->setLabel($obj->fb_fieldLabels[$defs['pwd']] . __('(Vérification)')); $pwd->setValue(''); $pwd2 = MyQuickForm::createElement('password', $fb->elementNamePrefix . $defs['pwd'] . '2' . $fb->elementNamePostfix, $obj->fb_fieldLabels[$defs['pwd']]); if (empty($obj->id)) { $form->addRule($fb->elementNamePrefix . $defs['pwd'] . $fb->elementNamePostfix, __('user.register.error.required_password'), 'required'); $form->addRule($fb->elementNamePrefix . $defs['pwd'] . '2' . $fb->elementNamePostfix, __('user.register.error.required_password'), 'required'); } $form->insertElementBefore($pwd2, $fb->elementNamePrefix . $defs['pwd'] . $fb->elementNamePostfix); $form->addRule(array($fb->elementNamePrefix . $defs['pwd'] . '2' . $fb->elementNamePostfix, $fb->elementNamePrefix . $defs['pwd'] . $fb->elementNamePostfix), __('user.register.error.unmatched_password'), 'compare'); $form->addFormRule(array($this, 'checkUniqueLogin')); } $form->setDefaults(array($fb->elementNamePrefix . $defs['pwd'] . $fb->elementNamePostfix => '', $fb->elementNamePrefix . $defs['pwd'] . '2' . $fb->elementNamePostfix => '')); $this->_obj = $fb->_do; }
public static function &getSearchForm($do, $module) { MyQuickForm::registerElementType('advandate', 'HTML/QuickForm/advandate.php', 'HTML_QuickForm_advandate'); $form = new MyQuickForm('formSearch', 'GET', self::getQueryParams(array(), array('page', '_c_'), false)); $fields = $_GET; unset($fields['_c_']); unset($fields['page']); unset($fields['module']); unset($fields['action']); unset($fields['filterField']); unset($fields['filterValue']); if (count($fields) == 0) { Log::info('caching search form'); $cache = true; } else { Log::info('NO SEARCH FORM CACHING'); $cache = false; } $cacheName = 'searchform_' . $module; $options = array('caching' => $cache, 'cacheDir' => APP_ROOT . 'app/' . APP_NAME . '/cache/forms/', 'lifeTime' => 3600, 'fileNameProtection' => false); $cache = new Cache_Lite($options); if ($_cachedData = $cache->get($cacheName)) { Mreg::append('autoloadcallback', array(array('MyQuickForm', 'autoloadElements'))); $_cachedData = unserialize($_cachedData); foreach ($_cachedData as $element) { $form->addElement($element); } } else { $do->fb_selectAddEmpty = array(); if (is_array($do->links())) { foreach ($do->links() as $field => $link) { $do->fb_selectAddEmpty[] = $field; } } if (is_array($do->fb_enumFields)) { foreach ($do->fb_enumFields as $field) { $do->fb_selectAddEmpty[] = $field; } } $do->fb_formHeaderText = __('Search'); $do->fb_submitText = '>>'; $do->fb_linkNewValue = false; $formBuilder =& MyFB::create($do); $formBuilder->_cacheOptions = array('name' => 'office_searchform', 'cacheDir' => APP_ROOT . 'app/' . APP_NAME . '/cache/forms/'); $formBuilder->preGenerateFormCallback = array($do, 'prepareSearchForm'); $do->prepareSearchForm($fb); $do->fb_userEditableFields = $do->fb_fieldsToRender; $table = $do->table(); foreach ($do->fb_fieldsToRender as $field) { if ($table[$field] & DB_DATAOBJECT_DATE || $table[$field] & DB_DATAOBJECT_TIME) { $label = $do->fb_fieldLabels[$field] ? $do->fb_fieldLabels[$field] : $field; $do->fb_preDefElements[$field] = MyQuickForm::createElement('advandate', $field, $label, array("language" => T::getLang())); } } $formBuilder->postGenerateFormCallback = array($do, 'postPrepareSearchForm'); $formBuilder->useForm($form); $formBuilder->getForm(); foreach ($form->_elements as $elem) { $cached[] = $elem; } if ($cache) { $cache->save(serialize($cached)); } } $form->_rules = array(); $form->_formRules = array(); $form->_required = array(); self::addHiddenFields($form, array('search', 'page', '__dontpaginate', '_c_'), true); $form->addElement('checkbox', '__dontpaginate', 'Afficher les résultats sur une seule page'); return $form; }
public function preGenerateForm(&$fb, &$obj) { $obj->fb_preDefElements['filename'] = MyQuickForm::createElement('file', $obj->fb_elementNamePrefix . 'filename' . $obj->fb_elementNamePostfix, $obj->fb_fieldsLabel['filename']); }
public function postPrepareSearchForm($form, $obj) { $archiver_archived = MyQuickForm::createElement('select', 'archiver_archived', __('Archived'), array('' => __('No'), 'B' => __('Both'), 'O' => __('Yes'))); $form->insertElementBefore($archiver_archived, '__submit__'); }
function postGenerateReminder(&$form, &$fb) { $do = $fb->_do; $defs = $do->_getPluginsDef(); $defs = $defs['user']; $elt = MyQuickForm::createElement('static', 'remindertext', '', __('user.reminder.text')); $form->insertElementBefore($elt, $fb->elementNamePrefix . $defs['email'] . $fb->elementNamePostfix); }
/** * Adds tag checkboxes to form passed as first parameter * 2nd parameter is the actual name of the fields used to add tags * @param HTML_QuickForm * @param string default _tags */ public function addTagsToForm(HTML_QuickForm $form, $fieldname, DB_DataObject $obj) { $tags = DB_DataObject::factory('tag'); $tags->archived = 0; // @todo add this field to tags table $tag_record = DB_DataObject::factory('tag_record'); $tags->joinAdd($tag_record); $tags->whereAdd("tag_record.tagged_table = '" . $obj->__table . "'"); $tags->selectAdd(); $tags->selectAdd('tag.*'); $tags->groupBy('tag.strip'); if ($tags->find()) { while ($tags->fetch()) { $taglist[$tags->id] = $tags->strip; } foreach ($taglist as $id => $strip) { $arr[] = MyQuickForm::createElement('checkbox', $fieldname . '[' . $id . ']', '', $strip); $arr2[] = MyQuickForm::createElement('checkbox', 'exc_' . $fieldname . '[' . $id . ']', '', $strip); } $grp = MyQuickForm::createElement('group', $fieldname, __('Including Tags'), $arr, null, false); $grp2 = MyQuickForm::createElement('group', 'exc_' . $fieldname, __('Excluding Tags'), $arr2, null, false); if ($form->elementExists('__submit__')) { $form->insertElementBefore($grp, '__submit__'); $form->insertElementBefore($grp2, '__submit__'); } else { $form->addElement($grp); $form->addElement($grp2); } } }
public function postGenerateFormGrouped($form, $fb, $info, $langs, $obj) { $lang = $langs[0]; $elements = $obj->_i18nfbs[$lang]->_reorderElements(); if (is_array($obj->fb_fieldsToRender)) { $iFields = array_intersect($info, $obj->fb_fieldsToRender); } else { $iFields = $info; } $allLangs = array_diff($langs, array($this->getDefaultLang($obj))); array_unshift($allLangs, $this->getDefaultLang($obj)); $langs = $allLangs; foreach ($iFields as $field) { $fields = array(); foreach ($langs as $lang) { $completename = $obj->fb_elementNamePrefix . $field . $obj->fb_elementNamePostfix; $elem = $form->getElement($completename . '_' . $lang); $elem->setAttribute('rel', $completename); if ($lang == $this->getDefaultLang($obj)) { $class = 'translatesource field_' . $lang; $id = 'autotransid_' . $completename; } else { $class = 'autotranslate source_autotransid_' . $completename . ' field_' . $lang; $id = 'autotransid_' . $completename . '_' . $lang; } $elem->setAttribute('class', $elem->getAttribute('class') . ($elem->getAttribute('class') ? ' ' : '') . $class); $elem->setAttribute('id', $id); $label = $elem->getLabel(); if (is_array($label)) { $sublabel = $label[0]; } else { $sublabel = $label; } $elem->setLabel($sublabel . '(' . $lang . ')'); $fields[] = $elem; $form->removeElement($completename . '_' . $lang); } if (!$form->elementExists('__submit__')) { $form->addElement('group', $completename . '_group', $label, $fields, ''); } else { $form->insertElementBefore(MyQuickForm::createElement('group', $completename . '_group', $label, $fields), '__submit__'); } if (in_array($field, $fb->fieldsRequired) || $elements[$field] & DB_DATAOBJECT_NOTNULL) { $form->addGroupRule($completename . '_group', $fb->requiredRuleMessage, 'required', null, 1); } } }