Doc = &$Doc; $action = ($action == '') ? Constant::get('BASE_URL').'/'.CURR_PAGE : $action; $this->HTML_QuickForm($formName, $method, $action, $target, $attributes, $trackSubmit); $this->registerElementType('html_editor', 'class/Form/Element/html_editor.php', 'HTML_QuickForm_html_editor' ); $this->registerElementType('html_editor_basic', 'class/Form/Element/html_editor_basic.php', 'HTML_QuickForm_html_editor_basic' ); $this->registerElementType('html_editor_minimal', 'class/Form/Element/html_editor_minimal.php', 'HTML_QuickForm_html_editor_minimal' ); $this->registerElementType('html_editor_simple', 'class/Form/Element/html_editor_simple.php', 'HTML_QuickForm_html_editor_simple' ); $this->registerElementType('file_db', 'class/Form/Element/file_db.php', 'HTML_QuickForm_file_db' ); $this->registerElementType('img_db', 'class/Form/Element/img_db.php', 'HTML_QuickForm_img_db' ); $this->registerElementType('select_edit', 'class/Form/Element/select_edit.php', 'HTML_QuickForm_selectEdit' ); $this->registerElementType('calendar', 'class/Form/Element/calendar.php', 'HTML_QuickForm_calendar'); $this->registerElementType('color_picker', 'class/Form/Element/color_picker.php', 'HTML_QuickForm_color_picker'); $this->registerElementType('grid', 'class/Form/Element/grid.php', 'HTML_QuickForm_grid'); $this->registerElementType('advmultiselect', 'HTML/QuickForm/advmultiselect.php', 'HTML_QuickForm_advmultiselect'); $this->registerElementType('extended_text', 'class/Form/Element/extended_text.php','HTML_QuickForm_extended_text'); $this->registerElementType('extended_password', 'class/Form/Element/extended_password.php','HTML_QuickForm_extended_password'); $this->registerElementType('extended_select', 'class/Form/Element/extended_select.php','HTML_QuickForm_extended_select'); $this->registerElementType('flash_editor', 'class/Form/Element/flash_editor.php', 'HTML_QuickForm_flash_editor'); $this->registerRule('in_array', 'html_quickform_rule_in_array', 'HTML_QuickForm_Rule_in_array', 'class/Form/Rule/in_array.php' ); $this->registerRule('item_name', 'html_quickform_rule_regexapp', 'HTML_QuickForm_Rule_RegexApp', 'class/Form/Rule/RegexApp.php' ); $this->registerRule('alias', 'html_quickform_rule_regexapp', 'HTML_QuickForm_Rule_RegexApp', 'class/Form/Rule/RegexApp.php' ); $this->registerRule('date_check', 'html_quickform_rule_date', 'HTML_QuickForm_Rule_Date', 'class/Form/Rule/date.php' ); } function setReturnForm($var) { $this->return_form_arr = (bool)$var; return $this->return_form_arr; } function getReturnForm() { return $this->return_form_arr; } function setCancelType($type) { $this->cancelType = $type; } function setTitle($title) { $this->_title = $title; } function getTitle() { return $this->_title; } function setCSS2Elems($list) { foreach (array_keys($list) as $key) { $class = $list[$key]->getAttribute('class'); if (!empty($class)){ continue; } if (is_callable(array($list[$key], 'setButtonAttributes')) ){ if (!isset($list[$key]->_addButtonAttributes['class'])){ $list[$key]->setButtonAttributes('add', array('class' => 'btn')); } if (!isset($list[$key]->_removeButtonAttributes['class'])){ $list[$key]->setButtonAttributes('remove', array('class' => 'btn')); } if (!isset($list[$key]->_allButtonAttributes['class'])){ $list[$key]->setButtonAttributes('all', array('class' => 'btn')); } if (!isset($list[$key]->_noneButtonAttributes['class'])){ $list[$key]->setButtonAttributes('none', array('class' => 'btn')); } if (!isset($list[$key]->_toggleButtonAttributes['class'])){ $list[$key]->setButtonAttributes('toggle', array('class' => 'btn')); } if (!isset($list[$key]->_downButtonAttributes['class'])){ $list[$key]->setButtonAttributes('down', array('class' => 'btn')); } if (!isset($list[$key]->_downButtonAttributes['class'])){ $list[$key]->setButtonAttributes('movedown', array('class' => 'btn')); } if (!isset($list[$key]->_upButtonAttributes['class'])){ $list[$key]->setButtonAttributes('up', array('class' => 'btn')); } if (!isset($list[$key]->_upButtonAttributes['class'])){ $list[$key]->setButtonAttributes('moveup', array('class' => 'btn')); } } switch ($list[$key]->getType()) { case 'group': $elements = Form::setCSS2Elems( $list[$key]->getElements() ); $list[$key]->getElements($elements) ; break; case 'text': case 'autocomplete': case 'password': $atr = array('class' => 'inp_width'); $list[$key]->updateAttributes($atr) ; break; case 'button': case 'reset': case 'submit': case 'xbutton': $atr = array('class' => 'btn'); $list[$key]->updateAttributes($atr) ; break; case 'checkbox': $atr = array('class' => 'inp_chkbx'); $list[$key]->updateAttributes($atr) ; break; case 'radio': $atr = array('class' => 'inp_radio'); $list[$key]->updateAttributes($atr) ; break; } } return $list; } function _execRendArrSmarty() { require_once 'HTML/QuickForm/Renderer/ArraySmarty.php'; $renderer =& new HTML_QuickForm_Renderer_ArraySmarty($this->getTpl(), true); $this->accept($renderer); $item = $renderer->toArray(); $item['title'] = $this->getTitle(); $item['style_pref'] = $this->style_pref; $item['tpl'] = $this->getTpl(); $this->_setStartFocus(); if ($this->return_form_arr) { return $item; } $this->Doc->addContent($item); } function _execRendArr() { require_once 'HTML/QuickForm/Renderer/Array.php'; $renderer =& new HTML_QuickForm_Renderer_Array(true, true); $this->accept($renderer); $item = $renderer->toArray(); $item['title'] = $this->getTitle(); $item['style_pref'] = $this->style_pref; $item['tpl'] = $this->getTpl(); $this->_setStartFocus(); if ($this->return_form_arr) { return $item; } $this->Doc->addContent($item); } function _setStartFocus() { return true; } function _execRendDef() { $renderer =& $this->defaultRenderer(); $this->accept($renderer); echo $renderer->toHtml(); } function setTpl($tpl) { $this->tpl = (string)$tpl; } function getTpl() { $tpl = SiteMap::getPath2ClassTpl('form', $this->tpl, 'smarty-dynamic.tpl', $this->name); return $tpl; } function setSubmitTitle($submitTitle) { $this->submitTitle = (string)$submitTitle; } function getSubmitTitle() { return $this->submitTitle; } function setRendType($rendType) { $rendTypes = array(); $rendTypes[] = FORM_RENDERER_DEFAULT; $rendTypes[] = FORM_RENDERER_ARRAY; $rendTypes[] = FORM_RENDERER_ARRAY_SMARTY; if (in_array($rendType, $rendTypes)){ $this->_rendType = intval($rendType); return true; }else { return false; } } function exec() { $form_array = array(); $this->_insertButton(); $this->_elements = $this->setCSS2Elems($this->_elements); $requiredNote = $this->_requiredNote; if ( 0 == count($this->_required)){ $this->_requiredNote = ''; } switch ($this->_rendType) { case FORM_RENDERER_DEFAULT: $this->_execRendDef(); break; case FORM_RENDERER_ARRAY: $form_array = $this->_execRendArr(); break; case FORM_RENDERER_ARRAY_SMARTY: $form_array = $this->_execRendArrSmarty(); break; default: return false; break; } $this->_requiredNote = $requiredNote; if ($this->return_form_arr) { return $form_array; } return true; } function _insertButton() { require_once ('HTML/QuickForm/submit.php'); $buttons = array(); $buttons[] = new HTML_QuickForm_submit('submit', $this->submitTitle); switch ($this->cancelType){ case FORM_CBT_RESET: require_once ('HTML/QuickForm/reset.php'); $buttons[] = new HTML_QuickForm_reset('cancel_btn', $this->cancelTitle); break; case FORM_CBT_CANCEL: require_once ('HTML/QuickForm/button.php'); $s = "document.location.href = '"; if ($this->cancelUrl) { $s .= $this->cancelUrl; } else { $s .= Constant::get('BASE_URL').'/'.CURR_PAGE."?action=cancel"; } $s .= "'"; $buttons[] = new HTML_QuickForm_button('cancel_btn', $this->cancelTitle, // array('onclick' => "window.navigate('".Constant::get('BASE_URL').'/'.CURR_PAGE."?action=cancel')" ) array('onclick' => $s ) ); break; } $this->addGroup($buttons, 'submit_grp'); return true; } function getElements() { return $this->_elements; } function removeElements($elements) { if(!is_array($elements)) { $elements = func_get_args(); } if(!is_array($elements) || empty($elements)) { return false; } foreach ($elements as $name) { $this->removeElement($name); } } function addRuleRequired($elements, $side = 'both', $opt = array('postfix' => ' is required')) { $elements = (array)$elements; return $this->addRuleEx($elements, $opt['postfix'], 'required', null, $side); } function addRuleEx($elements, $postfix, $rule, $param = NULL, $side = 'both', $opt = array('prefix' => '')) { if(!is_array($elements) || empty($elements)) return false; foreach ($elements as $name) { if (!$this->elementExists($name)) { if (defined('DEBUG') && DEBUG){ vdie('Element Not Exists: '.$name); } continue; } $el = &$this->getElement($name); $label = $el->getLabel(); switch ($side) { case 'client': $this->addRule($name, @$opt['prefix'] . $label . $postfix, $rule, $param, 'client'); break; case 'server': $this->addRule($name, @$opt['prefix'] . $label . $postfix, $rule, $param, 'server'); break; case 'both': $this->addRule($name, @$opt['prefix'] . $label . $postfix, $rule, $param, 'client'); $this->addRule($name, @$opt['prefix'] . $label . $postfix, $rule, $param, 'server'); break; } } } function removeRules() { $args = func_get_args(); if (empty($args)){ $this->_required = array(); $this->_rules = array(); $this->_errors = array(); return; } if (is_array($args[0])) { $args = $args[0]; } foreach ($args as $k=>$v){ foreach ($this->_required as $rk=>$rv) if ($rv == $v) unset($this->_required[$rk]); unset($this->_rules[$v], $this->_errors[$v]); } } } // модифікатори для смарті function getlabel($el) { if ($el['required']){ return '*'.$el['label']; }else{ return $el['label']; } } function geterror($el, $delimiter = '') { if ($el['error']) return ''.$el['error'].''.$delimiter; } function gethtml($el, $display_error = true) { $ret = NULL; if ($display_error && $el['error']) $ret= ''.$el['error'].'
'; $ret.=$el['html']; return $ret; }