Doc = &$Doc;
$action = ($action == '') ? Constant::get('BASE_URL').'/'.CURR_PAGE_FULL : $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_basic_img', 'class/Form/Element/html_editor_basic_img.php', 'HTML_QuickForm_html_editor_basic_img' );
$this->registerElementType('html_editor_forum', 'class/Form/Element/html_editor_forum.php', 'HTML_QuickForm_html_editor_forum' );
$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('timecalendar', 'class/Form/Element/timecalendar.php', 'HTML_QuickForm_timecalendar');
$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('input', 'HTML/QuickForm/input.php', 'HTML_QuickForm_input');
$this->registerElementType('advmultiselect', 'HTML/QuickForm/advmultiselect.php', 'HTML_QuickForm_advmultiselect');
$this->registerElementType('multi_checkbox', 'class/Form/Element/multi_checkbox.php', 'HTML_QuickForm_multi_checkbox');
$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('extended_html_editor', 'class/Form/Element/extended_html_editor.php', 'HTML_QuickForm_extended_html_editor');
$this->registerElementType('extended_html_editor_basic', 'class/Form/Element/extended_html_editor_basic.php', 'HTML_QuickForm_extended_html_editor_basic');
$this->registerElementType('extended_button', 'class/Form/Element/extended_button.php', 'FRWD_QuickForm_extended_button');
$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 setButtonGroupCallback($callback)
{
if (!is_callable($callback)) {
die('Provided callback is not callable');
}
$this->_buttonGroupCallback = $callback;
return $this;
}
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 'class/Form/Renderer/ArraySmarty.php';
$renderer =& new Form_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);
return true;
}
function _execRendArr()
{
require_once 'class/Form/Renderer/Array.php';
$renderer =& new Form_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);
return true;
}
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($insertButtons = true)
{
$form_array = array();
if ($insertButtons) {
$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()
{
if (null !== $this->_buttonGroupCallback) {
call_user_func($this->_buttonGroupCallback, $this);
return true;
}
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 = "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' => $s ));
break;
default:
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);
}
return true;
}
function addRuleRequired($elements, $side = 'both', $opt = array('postfix' => ' is required'))
{
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;
}
}
return true;
}
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 &insertElementAfter(&$element, $nameBefore)
{
if (!empty($this->_duplicateIndex[$nameBefore])) {
$error = PEAR::raiseError(null, QUICKFORM_INVALID_ELEMENT_NAME, null, E_USER_WARNING, 'Several elements named "' . $nameBefore . '" exist in HTML_QuickForm::insertElementBefore().', 'HTML_QuickForm_Error', true);
return $error;
} elseif (!$this->elementExists($nameBefore)) {
$error = PEAR::raiseError(null, QUICKFORM_NONEXIST_ELEMENT, null, E_USER_WARNING, "Element '$nameBefore' does not exist in HTML_QuickForm::insertElementBefore()", 'HTML_QuickForm_Error', true);
return $error;
}
$elementName = $element->getName();
$targetIdx = $this->_elementIndex[$nameBefore];
// == ���������� targetIdx �� ��������� ������� ==============
$indexList = array_values($this->_elementIndex);
if (false !== ($pIndex = array_search($targetIdx, $indexList))) {
if (isset($indexList[$pIndex+1])) {
$targetIdx = $indexList[$pIndex+1];
}
}
// =========================================================
$duplicate = false;
// Like in addElement(), check that it's not an incompatible duplicate
if (!empty($elementName) && isset($this->_elementIndex[$elementName])) {
if ($this->_elements[$this->_elementIndex[$elementName]]->getType() != $element->getType()) {
$error = PEAR::raiseError(null, QUICKFORM_INVALID_ELEMENT_NAME, null, E_USER_WARNING, "Element '$elementName' already exists in HTML_QuickForm::insertElementBefore()", 'HTML_QuickForm_Error', true);
return $error;
}
$duplicate = true;
}
// Move all the elements after added back one place, reindex _elementIndex and/or _duplicateIndex
$elKeys = array_keys($this->_elements);
for ($i = end($elKeys); $i >= $targetIdx; $i--) {
if (isset($this->_elements[$i])) {
$currentName = $this->_elements[$i]->getName();
$this->_elements[$i + 1] =& $this->_elements[$i];
if ($this->_elementIndex[$currentName] == $i) {
$this->_elementIndex[$currentName] = $i + 1;
} else {
$dupIdx = array_search($i, $this->_duplicateIndex[$currentName]);
$this->_duplicateIndex[$currentName][$dupIdx] = $i + 1;
}
unset($this->_elements[$i]);
}
}
// Put the element in place finally
$this->_elements[$targetIdx] =& $element;
if (!$duplicate) {
$this->_elementIndex[$elementName] = $targetIdx;
} else {
$this->_duplicateIndex[$elementName][] = $targetIdx;
}
$element->onQuickFormEvent('updateValue', null, $this);
if ($this->_freezeAll) {
$element->freeze();
}
// If not done, the elements will appear in reverse order
ksort($this->_elements);
return $element;
}
function initElements()
{
foreach ($this->_elements as &$element) {
if (!$element->getAttribute('id')) {
$id = $element->getName();
if (substr($id, -2) == '[]') {
$id = substr($id, 0, strlen($id) - 2);
}
if (strstr($id, ']')) {
$id = trim($id, ']');
$id = str_replace('][', '-', $id);
$id = str_replace('[', '-', $id);
}
$element->setAttribute('id', $id);
}
}
}
}
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;
}