DBObj)) { $this->DBObj = SiteMap::getObj('FormMail/FormMail.php'); } } function getNames() { $this->_initDBObj(); $names = array(); $list = $this->DBObj->getList4Grid(); foreach ($list['list'] as $value) { $names[] = $value['name']; } return $names; } function _getOptions($list) { $options = array(); $lang = $this->options['lang']; foreach ((array)$list[$lang] as $value) { $options[$value] = $value; } return $options; } function getForm(&$Doc, $id, $lang) { require_once 'class/Form/Form.class.php'; $this->_initDBObj(); $form = new Form($Doc); $formArr = $this->DBObj->getFromDB($id); $form->setTitle($formArr['title'][$lang] ); $FormMail_Field = SiteMap::getObj('FormMail/Field/Field.php', $id); $list = $FormMail_Field->getList4Grid(array('order_by' => 'sorter')); $form->setRequiredNote($FormMail_Field->getErrorMsg('required_note', $lang, '')); foreach ($list['list'] AS $field){ $field = $FormMail_Field->getFromDB($field['id']); $label = $field['label'][$lang]; $type = $field['type']; $name = "fild[{$field['id']}]"; switch ($type) { case 'select': $form->addElement($type, $name, $label, array('' => 'Select One') + $this->_getOptions($field['value']) ); break; case 'checkbox': $form->addElement('advcheckbox', $name, $label, '', null, array('Off', 'On') ); break; case 'checkboxes': $checkboxes = array(); $i = 0; foreach ((array)$field['value'][$lang] as $value){ $checkboxes[] = Form::createElement('checkbox', $value, '', $value, array('value' => $value) ); $i++; } $form->addGroup($checkboxes,$name, $label, '
'); break; case 'radioboxes': $radioboxes = array(); $i = 0; foreach ($this->_getOptions($field['value']) as $value){ $radioboxes[] = Form::createElement('radio', null, null, $value, $value); $i++; } $form->addGroup($radioboxes,$name, $label, '
'); break; case 'textarea': $form->addElement($type, $name, $label, array('cols'=>30, 'rows'=>8) ); break; default: // case 'text': $form->addElement($type, $name, $label, array('size'=>30,) ); break; } foreach ((array)$field['valid'] as $valid) { if ('file' == $type){ if ('required' == $valid){ $form->addRule($name, $FormMail_Field->getErrorMsg($valid, $lang, $label), 'uploadedfile'); } }else { $form->addRule($name, $FormMail_Field->getErrorMsg($valid, $lang, $label), $valid); $form->addRule($name, $FormMail_Field->getErrorMsg($valid, $lang, $label), $valid, null, 'client'); } } } $form->setCancelType(FORM_CBT_RESET); $form->setSubmitTitle('Send'); $form->addElement('hidden', 'action', 'submit' ); return $form; } function _tplPref($id_fm) { $tpl = $this->DBObj->getFromDB($id_fm, "frm_tpl[{$this->options['lang']}]"); $pos = strpos($tpl, $this->_tagTpl); if (false === $pos){ $pref = $tpl; }else { $pref = substr($tpl, 0, $pos); } return array('tpl' => 'text.tpl', 'text' => $pref); } function _tplSuff($id_fm) { $tpl = $this->DBObj->getFromDB($id_fm, "frm_tpl[{$this->options['lang']}]"); $pos = strpos($tpl, $this->_tagTpl); if (false === $pos){ $suff = ''; }else { $suff = substr($tpl, $pos); $suff = str_replace($this->_tagTpl, '', $suff); } return array('tpl' => 'text.tpl', 'text' => $suff); } function exec(&$Doc) { require_once 'class/Form/Form.class.php'; $this->_initDBObj(); $id_fm = $this->DBObj->getIdByName($this->options['name']); $form = $this->getForm(&$Doc, $id_fm, $this->options['lang']); switch ($_REQUEST['action']){ case 'thank': $Doc->addContent( array('tpl' => 'text.tpl', 'text' => $this->DBObj->getFromDB($id_fm, "thank_msg[{$this->options['lang']}]") ) ); break; case 'submit': if ($form->validate()){ $FormMail_Req = SiteMap::getObj('FormMail/Req/Req.php', $id_fm); $FormMail_Req->initFromForm($form); $FormMail_Req->save($this->options['lang']); require_once 'class/HTTP.php'; skHTTP::redirect(Constant::get('BASE_URL').'/'.CURR_PAGE.'?action=thank'); }else { $Doc->addContent($this->_tplPref($id_fm)); $form->exec(); $Doc->addContent($this->_tplSuff($id_fm)); } break; default: $Doc->addContent($this->_tplPref($id_fm)); $form->exec(); $Doc->addContent($this->_tplSuff($id_fm)); break; } } } ?>