_html = ''; $this->_object = NULL; $this->_css = ''; $this->_script = ''; $this->_js = ''; $this->_messages = ''; $this->_selectCheck = false; $this->_dateTime = false; } public function renderForm($display = true, $action = NULL, $method = 'POST', $enctype = 'multipart/form-data'){ $this->generateForms(); $this->_script .= ''; if ($this->_selectCheck) $this->includeSelectCheck(); if ($this->_dateTime) $this->includeDateTime(); $this->addFilters(); $form = '' . $this->_script . ($this->_messages ? implode("\n", $this->_messages) : '') . $this->_html . $this->_js; // display user js after render form if ($display) echo $form; return $form; } public function generateForms($action = NULL, $method = 'POST', $enctype = 'multipart/form-data'){ if (!$this->_forms || empty($this->_forms)) return; if (!$method) $method = 'POST'; if (!$enctype) $enctype = 'multipart/form-data'; foreach ($this->_forms as $form) { $action = isset($form['action']) ? $form['action'] : $action; $method = isset($form['method']) ? $form['method'] : $method; $enctype = isset($form['enctype']) ? $form['enctype'] : $enctype; $css = isset($form['style']) ? $form['style'] : ''; // OPEN FORM $this->_html .= '
'; $id = (isset($form['id']) && $form['id']) ? $form['id'] : false; $img = (isset($form['img']) && $form['img']) ? $form['img'] : false; $css = (isset($form['css']) && $form['css']) ? $form['css'] : false; if (!isset($form['fieldsets'])){ $form['fieldsets'] = array( array( 'legend' => $form['legend'], 'id' => $id, 'img' => $img, 'css' => $css, 'inputs' => $form['inputs'], 'actions' => $form['actions'] ) ); } foreach ($form['fieldsets'] as $fieldset) { $id = (isset($fieldset['id']) && $fieldset['id']) ? $fieldset['id'] : false; $img = (isset($fieldset['img']) && $fieldset['img']) ? $fieldset['img'] : false; $css = (isset($fieldset['css']) && $fieldset['css']) ? $fieldset['css'] : false; // OPEN FIELDSET $this->openFieldset($fieldset['legend'], $id, $img, $css); foreach ($fieldset['inputs'] as $input) $this->addInput($input); if (isset($fieldset['actions']) && $fieldset['actions']){ $this->_html .= '
'; foreach ($fieldset['actions'] as $action) $this->addAction($action); $this->_html .= '
'; } $this->closeFieldset(); } $this->_html .= '
'; } } public function addJs($js){ $this->_js .= $js; } public function addCss($css){ $this->_css .= $css; } public function addInput($input){ if (!isset($input['type'])) return false; $html = (isset($input['html']) && $input['html']) ? $input['html'] : NULL; switch ($input['type']) { case 'text': $this->inputText($input); break; case 'select': $this->inputSelect($input); break; case 'select-styled': $this->inputSelectStyled($input); break; case 'bool': case 'radio': $this->inputBool($input); break; case 'checkbox': $this->inputCheckbox($input); break; case 'date': $this->inputDate($input); break; case 'textarea': $this->inputRte($input); break; case 'checkList': case 'selectCheck': $this->selectCheck($input); break; case 'file': $this->inputFile($input); break; case 'hidden': $this->inputHidden($input); break; case 'html': $this->_html .= $input['value']; break; default: return false; } } public function addAction($action){ if (!isset($action['type']) || !isset($action['name'])) return false; $css = (isset($action['css']) && $action['css']) ? $action['css'] : NULL; switch ($action['type']) { case 'button': $this->inputButton($action); break; case 'submit': $this->inputSubmit($action); break; default: return false; } } public function includeSelectCheck(){ $this->_css .= ' a.multiSelect { background: #FFF url('.__PS_BASE_URI__.'adm/helpers/includes/dropdown.gif) right -1px no-repeat; border: 1px solid #e0d0b1; padding-right: 20px; position: relative; cursor: default; text-decoration: none; color: black; display: -moz-inline-stack; display: inline-block; vertical-align: top; margin-top: 2px; } a.multiSelect:link, a.multiSelect:visited, a.multiSelect:hover, a.multiSelect:active { color: black; text-decoration: none; } a.multiSelect span { margin: 1px 0px 1px 3px; overflow: hidden; display: -moz-inline-stack; display: inline-block; white-space: nowrap; font-size: 12px; } a.multiSelect.hover { background-image: url('.__PS_BASE_URI__.'adm/helpers/includes/dropdown_hover.gif); } a.multiSelect.active, a.multiSelect.focus { border: inset 1px #000000; } a.multiSelect.active { background-image: url('.__PS_BASE_URI__.'adm/helpers/includes/dropdown_active.gif); } .multiSelectOptions { margin-top: -1px; overflow-y: auto; overflow-x: hidden; border: solid 1px #b2b2b2; background: #ffffff; } .multiSelectOptions label { padding: 0px 2px; display: block; white-space: nowrap; float: none; text-align: left; width: auto; } .multiSelectOptions label.optGroup { font-weight: bold; } .multiSelectOptions .optGroupContainer label { padding-left: 10px; font-size: 12px; color: #333333; padding: 2px 0px; } .multiSelectOptions.optGroupHasCheckboxes .optGroupContainer label { padding-left: 18px; } .multiSelectOptions input { vertical-align: middle; margin-right: 5px; } .multiSelectOptions label.checked { background-color: #dce5f8; } .multiSelectOptions label.optGroup { color: #000000; font-size: 12px; margin-bottom: 2px; } .multiSelectOptions label.selectAll { border-bottom: dotted 1px #cccccc; font-size: 12px; color: #333333; padding-top: 2px; margin: 0px 0px 6px; } .multiSelectOptions label.hover { background-color: #3399ff; color: #ffffff; }'; $this->_script .= ' '; } public function includeDateTime(){ $this->_css .= ' .ui-timepicker-div .ui-widget-header { margin-bottom: 8px; } .ui-timepicker-div dl { text-align: left; } .ui-timepicker-div dl dt { height: 25px; margin-bottom: -25px; } .ui-timepicker-div dl dd { margin: 0 10px 10px 65px; } .ui-timepicker-div td { font-size: 90%; } .ui-tpicker-grid-label { background: none; border: none; margin: 0; padding: 0; }'; $this->_script .= ' '; $this->_js .= ' '; } public function addFilters(){ $this->_script .= ' '; } public function openFieldset($legend, $id = NULL, $img_src='../img/admin/edit.gif', $css = false){ $this->_html .= ' '.$legend.'
'; } public function closeFieldset($legend, $img_src='../img/admin/edit.gif'){ $this->_html .= '
'; } public function inputText($p = array()){ if (isset($p['lang']) && $p['lang'] === true) return $this->inputTextL($p); $default_value = (isset($p['default']) ? $p['default'] : ''); $disabled = ((isset($p['disabled']) && $p['disabled']) ? 'disabled="disabled"' : ''); $this->_html .= ''.$p['label'].'
' . ((isset($p['required']) && $p['required']) ? ' *' : '') . ' ' . ((isset($p['hint']) && $p['hint']) ? '

'.$p['hint'].'

' : '') . ' ' . ((isset($p['help']) && $p['help']) ? '

'.$p['help'].'

' : '') . ' ' . ((isset($p['html']) && $p['html']) ? $p['html'] : '') . '
'; } public function inputTextL($p = array()){ $default_value = (isset($p['default']) ? $p['default'] : ''); $this->_html .= ''.$p['label'].'
'; foreach ($this->_languages AS $language){ $default_lang = (is_array($p['default'])) ? $p['default'][(int)$language['id_lang']] : $default_value; $this->_html .= '
' . ((isset($p['required']) && $p['required']) ? ' *' : '') . ' ' . ((isset($p['hint']) && $p['hint']) ? '

'.$p['hint'].'

' : '') . ' ' . ((isset($p['html']) && $p['html']) ? $p['html'] : '') . '
'; } $this->_html .= '

'; } public function inputFile($p = array()){ $this->_html .= ''.$p['label'].'
' . ((isset($p['required']) && $p['required']) ? ' *' : '') . ' ' . ((isset($p['hint']) && $p['hint']) ? '

'.$p['hint'].'

' : '') . ' ' . ((isset($p['html']) && $p['html']) ? $p['html'] : '') . '

'; } public function inputSelect($p = array()){ $disabled = ((isset($p['disabled']) && $p['disabled']) ? 'disabled="disabled"' : ''); $this->_html .= ''.$p['label'].'
' . ((isset($p['filter']) && $p['filter']) ? '

 ' : '') . ' ' . ((isset($p['html']) && $p['html']) ? $p['html'] : '') . '
'; } public function inputSelectStyled($p = array()){ $disabled = ((isset($p['disabled']) && $p['disabled']) ? 'disabled="disabled"' : ''); $this->_html .= ''.$p['label'].'
' . ((isset($p['filter']) && $p['filter']) ? '

 ' : '') . ' ' . ((isset($p['html']) && $p['html']) ? $p['html'] : '') . '
'; } public function inputBool($p = array()){ $checked = ((isset($p['default']) && $p['default']) ? $p['default'] : false); if ($this->_object) $checked = $this->_object->{$p['name']}; $this->_html .= ''.$p['label'].'
' . (isset($p['label_on']) && $p['label_on'] ? ' ' : '') . ' ' . (isset($p['label_off']) && $p['label_off'] ? ' ' : '') . '
' . ((isset($p['hint']) && $p['hint']) ? '

'.$p['hint'].'

' : '') . ' ' . ((isset($p['html']) && $p['html']) ? $p['html'] : '') . '
'; } public function inputCheckbox($p = array()){ $checked = ((isset($p['checked']) && $p['checked']) ? $p['checked'] : false); if ($this->_object) $checked = $this->_object->{$p['name']}; $this->_html .= ''.$p['label'].'
' . (isset($p['text']) && $p['text'] ? '' : '') . '
' . ((isset($p['hint']) && $p['hint']) ? '

'.$p['hint'].'

' : '') . ' ' . ((isset($p['html']) && $p['html']) ? $p['html'] : '') . '
'; } public function inputDate($p = array()){ $this->_dateTime = true; $default = ((isset($p['default']) && $p['default']) ? $p['default'] : ''); $this->_html .= ''.$p['label'].'
' . ((isset($p['required']) && $p['required']) ? ' *' : '') . '
' . ((isset($p['html']) && $p['html']) ? $p['html'] : '') . '
'; } public function inputRte($p = array()){ $this->_html .= ''.$p['label'].'
'; foreach ($this->_languages AS $language){ $default_lang = (is_array($p['default'])) ? $p['default'][(int)$language['id_lang']] : ''; $this->_html .= '
' . ((isset($p['required']) && $p['required']) ? ' *' : '') . '
'; } $this->_html .= ' ' . ((isset($p['html']) && $p['html']) ? $p['html'] : '') . '

'; } public function selectCheck($p = array()){ $this->_selectCheck = true; $size = ((isset($p['size']) && $p['size']) ? (int) $p['size'] : 5); $this->_html .= ''.$p['label'].'
' . ((isset($p['filter']) && $p['filter']) ? '

' : '') . ' ' . ((isset($p['html']) && $p['html']) ? $p['html'] : '') . '
'; } public function inputButton($p = array()){ $css = isset($p['css']) && $p['css'] ? $p['css'] : false; $this->_html .= ' '.$p['label'].' '; } public function inputSubmit($p = array()){ $css = isset($p['css']) && $p['css'] ? $p['css'] : false; $this->_html .= ' '; } public function inputHidden($p = array()){ $id = ((isset($p['id']) && $p['id']) ? $p['id'] : $p['name']); $this->_html .= ' '; } public function displayError($message){ $this->_messages[] = '
' . $message . '
'; } public function displayMessage($message){ return $this->_messages[] = '
' . $message . '
'; } public function displayConf($message){ return $this->_messages[] = '
' . $message . '
'; } }