public function indexAction()
 {
     $data = $this->getRequest()->getPost('data');
     //print_r($this->_fields);
     //create form object
     $form = new Contact_Form_Generic($data, null, $this->_fields, $this->getRequest());
     //postback - save?
     if ($this->_formHelper->isSave()) {
         //check if valid
         if ($form->isValid()) {
             $values = $form->getValues();
             $subscription = new Contact_Model_Subscription();
             //exist?
             if (!Contact_Model_SubscriptionMapper::getInstance()->findByEmail($values['email'], $subscription)) {
                 //persist
                 $subscription->setOptions($values);
                 $subscription->set_code(md5(uniqid()))->set_status('pending')->set_lang(CURR_LANG);
                 Contact_Model_SubscriptionMapper::getInstance()->save($subscription);
             }
             $data = $subscription->toArray();
             $data['new_status'] = $values['subscribe'] == 'yes' ? 'subscribed' : 'unsubscribed';
             //set custom email subject
             if ($data['new_status'] == 'unsubscribed' && isset($this->_formParams['email']['subject_respond_un'])) {
                 $this->_formParams['email']['subject_respond'] = $this->_formParams['email']['subject_respond_un'];
             }
             $data['link'] = $this->view->serverUrl() . $this->view->url(array('module' => 'contact', 'controller' => 'subscribe-generic', 'action' => 'status', 'id' => $subscription->get_id(), 'code' => $subscription->get_code(), 'new_status' => $data['new_status'], 'lang' => CURR_LANG));
             //send email
             $this->sendContactEmail($data, $this->_fields, CURR_LANG);
             //sending done, return success
             return $this->_formHelper->returnSuccess($this->view->url(array('module' => 'contact', 'controller' => $this->_request->getControllerName(), 'action' => 'landing', 'status' => $data['new_status'])), $this->translate('Thank you for the submission'));
         } else {
             $this->_formHelper->returnError($form->getMessages());
         }
     } else {
         //set default values
         Contact_Form_Generic::setDefaultValues($this->_fields, $data);
     }
     $this->view->data = $data;
     $this->view->fields = $this->_fields;
     $this->view->formParams = $this->_formParams;
     $this->view->formId = $this->_formId;
     if (isset($this->_formParams['template'])) {
         $this->renderScript($this->_formParams['template']);
     }
 }
 protected function _loadParams()
 {
     $this->_globalSettings = HCMS_Utils::loadThemeConfig('config.php', 'contact');
     $fieldTypes = HCMS_Utils::loadThemeConfig('types.php', 'contact');
     if (!isset($this->_globalSettings['forms'][$this->_formId])) {
         throw new Exception("Form not found");
     }
     $this->_formParams = $this->_globalSettings['forms'][$this->_formId];
     $this->_fields = Contact_Form_Generic::getFieldsArr($fieldTypes, $this->_formParams['fields']);
 }
 protected function _loadParams()
 {
     $this->_globalSettings = HCMS_Utils::loadThemeConfig('config.php', 'contact');
     $fieldTypes = HCMS_Utils::loadThemeConfig('types.php', 'contact');
     if ($this->_request->getParam('form_id')) {
         $this->_formId = $this->_request->getParam('form_id');
     }
     if (!isset($this->_globalSettings['forms'][$this->_formId])) {
         throw new Exception("Form not found");
     }
     $this->_formParams = $this->_globalSettings['forms'][$this->_formId];
     $this->_fields = Contact_Form_Generic::getFieldsArr($fieldTypes, $this->_formParams['fields']);
     $this->_entityClassName = $this->getEntityClassName();
     $this->_mapperClassName = $this->getMapperClassName();
     $this->_columns = $this->getColumns();
     $this->view->columns = $this->_columns;
     $this->view->formId = $this->_formId;
 }
 public function indexAction()
 {
     $data = $this->getRequest()->getPost('data');
     //print_r($this->_fields);
     //create form object
     $form = new Contact_Form_Generic($data, null, $this->_fields, $this->getRequest());
     $entityClassName = $this->getEntityClassName();
     $mapperClassName = $this->getMapperClassName();
     //postback - save?
     if ($this->_formHelper->isSave()) {
         //check if valid
         if ($form->isValid()) {
             $values = $form->getValues();
             if ($this->hasFileUpload()) {
                 $this->relocateUploadedFiles($values);
                 $this->_genericFileHelper->pmcCleaner();
             }
             //persist data
             if (isset($this->_formParams['db']['save']) && $this->_formParams['db']['save']) {
                 $contact = new $entityClassName($values);
                 $contact->set_application_id($this->_applicationId)->set_language(CURR_LANG)->set_form_id($this->_formId)->set_posted(HCMS_Utils_Time::timeTs2Mysql(time()));
                 $mapperClassName::getInstance()->save($contact);
             }
             //send email
             $this->sendContactEmail($values, $this->_fields, CURR_LANG);
             //sending done, return success
             return $this->redirectLanding();
         } else {
             $this->_formHelper->returnError($form->getMessages());
         }
     } else {
         //set default values
         Contact_Form_Generic::setDefaultValues($this->_fields, $data);
     }
     $this->view->data = $data;
     $this->view->fields = $this->_fields;
     $this->view->formParams = $this->_formParams;
     $this->view->formId = $this->_formId;
     if (isset($this->_formParams['template'])) {
         $this->renderScript($this->_formParams['template']);
     }
 }
 public function editAction()
 {
     //load params
     $this->_globalSettings = HCMS_Utils::loadThemeConfig('config.php', 'contact');
     $fieldTypes = HCMS_Utils::loadThemeConfig('types.php', 'contact');
     if ($this->_request->getParam('form_id')) {
         $this->_formId = $this->_request->getParam('form_id');
     }
     if (!isset($this->_globalSettings['forms'][$this->_formId])) {
         throw new Exception("Form not found");
     }
     $this->_formParams = $this->_globalSettings['forms'][$this->_formId];
     $this->_fields = Contact_Form_Generic::getFieldsArr($fieldTypes, $this->_formParams['fields']);
     $data = $this->getRequest()->getPost('data');
     $id = $this->_getParam('id');
     //check if cancel button is pressed
     if ($this->_formHelper->isCancel()) {
         //cancel form
         return $this->_formHelper->returnCancel($this->view->url(array('action' => 'index')), $this->translate('Action canceled'));
     }
     //create form object
     $form = new Contact_Form_AdminSubscribe($data);
     //postback - save?
     if ($this->_formHelper->isSave()) {
         //check if valid
         if ($form->isValid()) {
             $values = $form->getValues();
             $subscription = new Contact_Model_Subscription($values);
             if (isset($data['id'])) {
                 $oldSubscription = new Contact_Model_Subscription();
                 if (Contact_Model_SubscriptionMapper::getInstance()->find($data['id'], $oldSubscription) && $oldSubscription->get_status() != $subscription->get_status()) {
                     $dt = date("Y-m-d H:i:s");
                     switch ($subscription->get_status()) {
                         case 'subscribed':
                             $subscription->set_subscribed_dt($dt);
                             break;
                         case 'unsubscribed':
                             $subscription->set_unsubscribed_dt($dt);
                             break;
                         default:
                             break;
                     }
                 }
             }
             Contact_Model_SubscriptionMapper::getInstance()->save($subscription);
             //sending done, return success
             return $this->_formHelper->returnSuccess($this->view->url(array('action' => 'index')), $this->translate('Saved'));
         } else {
             $this->_formHelper->returnError($form->getMessages());
         }
     } elseif (!$this->_formHelper->getRequest()->isPost()) {
         //edit action
         if (isset($id) && $id > 0) {
             $subscription = new Contact_Model_Subscription();
             if (!Contact_Model_SubscriptionMapper::getInstance()->find($id, $subscription)) {
                 throw new Exception("Record not found");
             }
             //fetch data
             $data = $subscription->toArray();
             //populate form with data
             $form->setData($data);
         }
     }
     $this->view->data = $data;
     $this->view->fields = $this->_fields;
     $this->view->formParams = $this->_formParams;
     $this->view->formId = $this->_formId;
 }