Ejemplo n.º 1
0
 public function manageformAction()
 {
     $formForm = new Application_Form_Form();
     $formPageConversionMapper = Application_Model_Mappers_FormPageConversionMapper::getInstance();
     $pageMapper = Application_Model_Mappers_PageMapper::getInstance();
     if ($this->getRequest()->isPost()) {
         if ($formForm->isValid($this->getRequest()->getParams())) {
             $formPageConversionModel = new Application_Model_Models_FormPageConversion();
             $formData = $this->getRequest()->getParams();
             $form = new Application_Model_Models_Form($this->getRequest()->getParams());
             $contactEmail = $form->getContactEmail();
             $validEmail = $this->validateEmail($contactEmail);
             if (isset($validEmail['error'])) {
                 $this->_helper->response->fail(Tools_Content_Tools::proccessFormMessagesIntoHtml(array('contactEmail' => $validEmail['error']), get_class($formForm)));
             }
             if (isset($formData['thankyouTemplate']) && $formData['thankyouTemplate'] != 'select') {
                 $trackingPageUrl = $this->_createTrackingPage($formData['name'], $formData['thankyouTemplate']);
             }
             $this->_addConversionCode();
             $formPageConversionModel->setFormName($formData['name']);
             $formPageConversionModel->setPageId($formData['pageId']);
             $formPageConversionModel->setConversionCode($formData['trackingCode']);
             $formPageConversionMapper->save($formPageConversionModel);
             Application_Model_Mappers_FormMapper::getInstance()->save($form);
             $this->_helper->cache->clean('', '', array(Widgets_Form_Form::WFORM_CACHE_TAG));
             $this->_helper->response->success($this->_helper->language->translate('Form saved'));
         } else {
             $this->_helper->response->fail(Tools_Content_Tools::proccessFormMessagesIntoHtml($formForm->getMessages(), get_class($formForm)));
         }
     }
     $formName = filter_var($this->getRequest()->getParam('name'), FILTER_SANITIZE_STRING);
     $pageId = $this->getRequest()->getParam('pageId');
     $trackingPageName = 'form-' . $formName . '-thank-you';
     $trackingPageUrl = $this->_helper->page->filterUrl($trackingPageName);
     $trackingPageExist = $pageMapper->findByUrl($trackingPageUrl);
     if (!empty($trackingPageExist)) {
         $trackingPageResultUrl = $trackingPageUrl;
     }
     $form = Application_Model_Mappers_FormMapper::getInstance()->findByName($formName);
     $mailTemplates = Tools_Mail_Tools::getMailTemplatesHash();
     $regularPageTemplates = Application_Model_Mappers_TemplateMapper::getInstance()->findByType(Application_Model_Models_Template::TYPE_REGULAR);
     $conversionCode = $formPageConversionMapper->getConversionCode($formName, $pageId);
     if (!empty($conversionCode)) {
         $formForm->getElement('trackingCode')->setValue($conversionCode[0]->getConversionCode());
     }
     $formForm->getElement('name')->setValue($formName);
     $formForm->getElement('replyMailTemplate')->setMultioptions(array_merge(array(0 => 'select template'), $mailTemplates));
     if ($form !== null) {
         $formForm->populate($form->toArray());
     }
     $this->view->trackingPageUrl = $trackingPageResultUrl;
     $this->view->regularTemplates = $regularPageTemplates;
     $this->view->pageId = $pageId;
     $this->view->formForm = $formForm;
     $this->view->helpSection = 'editform';
 }
Ejemplo n.º 2
0
 public function actionmailsAction()
 {
     if ($this->getRequest()->isPost()) {
         $actions = $this->getRequest()->getParam('actions', false);
         if ($actions !== false) {
             $removeActions = array();
             foreach ($actions as $action) {
                 if (isset($action['delete']) && $action['delete'] === "true") {
                     array_push($removeActions, $action['id']);
                     continue;
                 }
                 //add trigger automatically if not exists
                 //if(($exists = Application_Model_Mappers_EmailTriggersMapper::getInstance()->findByTriggerName($action['trigger'])->current()) === null) {
                 //    Application_Model_Mappers_EmailTriggersMapper::getInstance()->registerTrigger($action['trigger']);
                 // }
                 Application_Model_Mappers_EmailTriggersMapper::getInstance()->save($action);
             }
             if (!empty($removeActions)) {
                 Application_Model_Mappers_EmailTriggersMapper::getInstance()->delete($removeActions);
             }
             $this->_helper->response->success($this->_helper->language->translate('Changes saved'));
             return true;
         }
     }
     $pluginsTriggers = Tools_Plugins_Tools::fetchPluginsTriggers();
     $systemTriggers = Tools_System_Tools::fetchSystemtriggers();
     $triggers = is_array($pluginsTriggers) ? array_merge($systemTriggers, $pluginsTriggers) : $systemTriggers;
     $recipients = Application_Model_Mappers_EmailTriggersMapper::getInstance()->getReceivers(true);
     $this->view->recipients = array_combine($recipients, $recipients);
     $this->view->mailTemplates = Tools_Mail_Tools::getMailTemplatesHash();
     $this->view->triggers = $triggers;
     $this->view->actionsOptions = array_merge(array('0' => $this->_helper->language->translate('Select event area')), array_combine(array_keys($triggers), array_map(function ($trigger) {
         return str_replace('-', ' ', ucfirst($trigger));
     }, array_keys($triggers))));
     $this->view->actions = Application_Model_Mappers_EmailTriggersMapper::getInstance()->fetchArray();
 }