_html = ''; $this->_object = NULL; $this->_css = ''; $this->_style = ''; $this->_script = ''; $this->_js = ''; $this->_messages = ''; $this->_select2 = false; $this->_inputMask = false; $this->_inputSwitch = false; $this->_inputWizard = false; $this->_inputTag = false; $this->_dateTime = false; } public function renderStyle() { $this->_style .= ''; return $this->_style; } public function renderScript() { $this->_script .= ''; $this->_script .= ''; $this->_script .= ''; if ($this->_select2) { $this->_script .= ''; } if ($this->_inputMask) { $this->_script .= ''; } if ($this->_inputTag) { $this->_script .= ''; } if ($this->_inputSwitch) { $this->_script .= ''; } if ($this->_inputWizard) { $this->_script .= ''; } $this->_script .= ''; $this->_script .= $this->_js; return $this->_script; } public function renderForm($display = true, $action = NULL, $method = 'POST', $enctype = 'multipart/form-data'){ $this->generateForms(); $form = ($this->_messages ? implode("\n", $this->_messages) : '') . $this->_html; 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) { $class_div = isset($form['class_div']) ? $form['class_div'] : ''; $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'] : ''; $class = isset($form['class']) ? $form['class'] : ''; $id = (isset($form['id']) && $form['id']) ? $form['id'] : false; $icon = (isset($form['icon']) && $form['icon']) ? $form['icon'] : false; $title = (isset($form['title']) && $form['title']) ? $form['title'] : ''; // OPEN FORM $this->_html .= '

'.($icon?$icon:'').$title.'

'; if(isset($form['information'])) { $this->_html .= '

'.$form['information'].'

'; } if (isset($form['sections'])){ foreach ($form['sections'] as $section) { $id = (isset($section['id']) && $section['id']) ? $section['id'] : false; $icon = (isset($section['icon']) && $section['icon']) ? $section['icon'] : false; $css = (isset($section['css']) && $section['css']) ? $section['css'] : false; $class = (isset($section['class']) && $section['class']) ? $section['class'] : false; $title = (isset($section['title']) && $section['title']) ? $section['title'] : ''; // OPEN section $this->openSection($title, $id, $icon, $class, $css); foreach ($section['inputs'] as $input) { $this->addInput($input); } if (isset($section['actions']) && $section['actions']){ $this->_html .= '
'; foreach ($section['actions'] as $action) { $this->addAction($action); } $this->_html .= '
'; } $this->closeSection(); } } if (isset($form['html']) && $form['html']){ $this->_html .= $form['html']; } if (isset($form['actions']) && $form['actions']){ $this->_html .= '
'; foreach ($form['actions'] as $action) { $this->addAction($action); } $this->_html .= '
'; } $this->_html .= '
'; } } public function generateInput($input) { $this->addInput($input); $result = $this->_html; $this->_html = ''; return $result; } 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 'simpleText': $this->inputSimpleText($input); break; case 'tag': $this->inputTag($input); break; case 'select': $this->inputSelect($input); break; case 'select2': $this->inputSelect2($input); break; case 'select-styled': $this->inputSelectStyled($input); break; case 'simpleDate': $this->inputSimpleDate($input); break; case 'bool': case 'radio': $this->inputBool($input); break; case 'radio2': $this->inputRadio($input); break; case 'checkbox': $this->inputCheckbox($input); break; case 'switch': $this->inputSwitch($input); break; case 'textarea': $this->inputTextarea($input); break; case 'rte': $this->inputRte($input); break; case 'file': $this->inputFile($input); break; case 'uploadImage': $this->inputUploadImage($input); break; case 'button': $this->inputButton($input); break; case 'submit': $this->inputSubmit($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 openSection($legend='', $id = NULL, $icon = '', $class = '',$css = false){ $this->_html .= ''; if(!empty($legend)) { $this->_html .= '

'.$legend.'

'; } } public function closeSection(){ $this->_html .= ''; } 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 inputTextAddon($p = array()) { $this->_html .='
'.(isset($p['label']) && $p['label'] ?'':'').'
'.(isset($p['before']) && $p['before'] ?'
'.$p['before'].'
':'').' '.(isset($p['after']) && $p['after'] ?'
'.$p['after'].'
':'').'
'; } public function inputSimpleText($p = array()) { $this->_html .='
'; } public function inputTag($p = array()) { $this->_html .='

'.(isset($p['info']) ? $p['info'] : '').'

'; } public function inputSimpleDate($p = array()) { if(isset($p['period']) && $p['period']) { $this->_html .='
'; } $this->_html .='
'.(isset($p['label']) && $p['label'] ?'':'').'
'.(isset($p['before']) && $p['before'] ?'
'.$p['before'].'
':'').' '.(isset($p['after']) && $p['after'] ?'
'.$p['after'].'
':'').'
'; if(isset($p['period']) && $p['period']) { $this->_html .='
'.(isset($p['label-to']) && $p['label-to'] ?'':'').'
'.(isset($p['before-to']) && $p['before-to'] ?'
'.$p['before-to'].'
':'').' '.(isset($p['after-to']) && $p['after-to'] ?'
'.$p['after-to'].'
':'').'
'; } } public function inputSelect2($p = array()) { $all_opt = array(); $this->_html .='
'.(isset($p['label'])?'':'').'
'; if((isset($p['option_all']) && $p['option_all']) || (isset($p['option_clear']) && $p['option_clear'])) { $this->_html .='
'.((isset($p['option_all']) && $p['option_all'])?'':'').' '.((isset($p['option_clear']) && $p['option_clear'])?'':''); if(isset($p['buttons']) && is_array($p['buttons'])){ foreach ($p['buttons'] as $button) { $this->_html .=''; } } $this->_html .='
'; } $this->_html .='
'; if(isset($p['multiple']) && $p['multiple']){ $this->_html .=''; } else { $this->_html .=''; } } public function inputUploadImage($p = array()) { if(isset($p['lang']) && $p['lang']) { return $this->inputUploadImageL($p); } $this->_html .='
'.(isset($p['label'])?'':'').'
Ouvrir
'.(isset($p['help'])?'

'.$p['help'].'

':'').'
'; $this->_js .= ' '; } public function inputUploadImageL($p = array()) { $defaultLanguage = (isset($p['default_language']) && $p['default_language'])? $p['default_language'] : 2; $this->_html .='
'; //$this->_html .= $this->displayFlags($p['languages'], $defaultLanguage, $p['id_langs'], $p['name'],true,false,$p['link_flag_img'],'table'); //$this->_html .= ' $this->_js .= ' '; } public function inputSwitch($p = array()) { $this->_html .='
'.(isset($p['label'])?'':'').'
'; // '.$p['title'].' } 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 .= '
' . ((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'] : ''); $defaultLanguage = $p['default_language'] ? $p['default_language'] : 2; $this->_html .= '
'; foreach ($p['languages'] as $language) { $default_lang = (is_array($p['default'])) ? $p['default'][(int)$language['id_lang']] : $default_value; $this->_html .= '
'; } $this->_html .= '
'.((isset($p['help']) && $p['help']) ? ''.$p['help'].'' : '').'
'; } public function inputTextarea($p = array()){ if (isset($p['lang']) && $p['lang'] === true) { return $this->inputTextareaL($p); } } public function inputTextareaL($p = array()){ $default_value = (isset($p['default']) ? $p['default'] : ''); $defaultLanguage = $p['default_language'] ? $p['default_language'] : 2; $this->_html .= '
'; foreach ($p['languages'] as $language) { $default_lang = (is_array($p['default'])) ? $p['default'][(int)$language['id_lang']] : $default_value; $this->_html .= '
'; } $this->_html .= '
'; } public function inputFile($p = array()){ $this->_html .= '
' . ((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 .= '
' . ((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); $this->_html .= '
'; } public function inputRadio($p = array()) { $this->_html .= '
'; foreach($p['options'] as $key => $option) { $this->_html .= ''; } $this->_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 inputButtonLink($p = array()){ $css = isset($p['css']) && $p['css'] ? $p['css'] : false; $class = isset($p['css']) && $p['css'] ? $p['css'] : false; $this->_html .= ' '.$p['label'].' '; } public function inputButton($p = array()){ $label = isset($p['label']) && $p['label'] ? $p['label'] : false; $css = isset($p['css']) && $p['css'] ? $p['css'] : false; $class = isset($p['class']) && $p['class'] ? $p['class'] : false; $this->_html .= ' '; } public function inputSubmit($p = array()){ $label = isset($p['label']) && $p['label'] ? $p['label'] : false; $css = isset($p['css']) && $p['css'] ? $p['css'] : false; $class = isset($p['class']) && $p['class'] ? $p['class'] : false; if($label) { $this->_html .= '
'; } $this->_html .= ' '; if($label) { $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 . '
'; } public static function echoConfirmation($message){ echo ''; } public static function echoError($message){ echo ''; } public static function displaySuccess($message){ echo '
'.$message.'
'; } public static function displayWarning($message){ echo '
'.$message.'
'; } public static function displayErrors($message){ echo '
'.$message.'
'; } public function displayFlags($languages, $default_language, $ids, $id, $return = false, $use_vars_instead_of_ids = false, $link_flag_img = "../img/l/", $display ='block') { if (sizeof($languages) == 1) return false; $output = '
Choose language:
'; foreach ($languages as $language) { if($use_vars_instead_of_ids) $output .= ''.$language['name'].' '; else $output .= ''.$language['name'].' '; } $output .= '
'; if ($return) return $output; echo $output; } }