public function viewAction()
 {
     SxCms_Acl::requireAcl('pageform', 'pageform.view');
     $pageformProxy = new SxModule_Pageform_Proxy();
     $pageform = $pageformProxy->getById((int) $this->_getParam('id'));
     $item = $pageform;
     $this->view->item = $item;
     if ($this->getRequest()->isPost()) {
         $data = $this->_getParam('pageform');
         $user = Zend_Auth::getInstance()->getIdentity();
         $subscription = new SxModule_Pageform_Subscription();
         $subscription->setPageformId($item->getId())->setUserId($user->getId())->setIp($this->getRequest()->getServer('REMOTE_ADDR'))->setAgent($this->getRequest()->getServer('HTTP_USER_AGENT'))->setEmailed(0)->setIsDone(0);
         foreach ($item->getField() as $field) {
             if (isset($data[$field->getKey()])) {
                 # Tijd instellen
                 if ($field->getFieldType() == 'text' && $field->getValidation() == 'time' && is_array($data[$field->getKey()])) {
                     $data[$field->getKey()] = $data[$field->getKey()]['hh'] . ':' . $data[$field->getKey()]['mm'];
                 }
                 # Tijd & datum instellen
                 if ($field->getFieldType() == 'text' && $field->getValidation() == 'datetime' && is_array($data[$field->getKey()])) {
                     $data[$field->getKey()] = $data[$field->getKey()]['date'] . ' ' . $data[$field->getKey()]['hh'] . ':' . $data[$field->getKey()]['mm'];
                 }
                 $metaObject = new SxModule_Pageform_Subscription_Meta();
                 $metaObject->setFieldId($field->getId())->setLabel($field->getTsl()->getName())->setName($field->getKey())->setValue($data[$field->getKey()])->setView($field->getFieldView());
                 $subscription->addMeta($metaObject);
             }
         }
         $fielderrors = APPLICATION_ROOT . '/application/var/locale/fielderrors.tmx';
         $validator = new SxModule_Pageform_Subscription_Validator();
         $validator->setTmx(new Zend_Translate('tmx', $fielderrors, $_SESSION['System']['lng']));
         if ($validator->validate($subscription, $pageform)) {
             $subscription->save();
         }
         $cache = Zend_Registry::get('cache');
         $cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, array('SxModule_Pageform_Subscription_getAll', 'SxModule_Pageform_Subscription_getAllAndPageformByUserId', 'SxModule_Pageform_Subscription_getAllAndPageform', 'SxModule_Pageform_Subscription_Id' . $item->getId()));
         $flashMessenger = $this->_helper->getHelper('FlashMessenger');
         $flashMessenger->addMessage($this->admin_tmx->_('itemcreated'));
         $this->_helper->redirector->gotoSimple('index', 'pageform');
     }
 }
 public function overviewAction()
 {
     $proxy = new SxCms_Page_Proxy();
     $page_id = $this->_getParam('page_id');
     $page_has_form = $proxy->getPageById($page_id, $this->_getParam('lng', 'nl'));
     if ($page_has_form->getPageform()) {
         $this->view->captchaId = $this->generateCaptcha();
         $pageformproxy = new SxModule_Pageform_Proxy();
         $subscription = new SxModule_Pageform_Subscription();
         $pageform = $pageformproxy->getActiveById($page_has_form->getPageform(), $_SESSION['System']['lng']);
         $this->view->pageform = $pageform;
         if ($this->getRequest()->isPost() && $this->_getParam('form_' . $page_id)) {
             $data = $this->_getParam('pageform');
             $subscription->setPageformId($pageform->getId())->setPageformname($pageform->getName())->setIp($this->getRequest()->getServer('REMOTE_ADDR'))->setAgent($this->getRequest()->getServer('HTTP_USER_AGENT'))->setLng($this->_getParam('lng'))->setUrl('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
             foreach ($pageform->getField() as $field) {
                 if (isset($data[$field->getKey()])) {
                     # Tijd instellen
                     if ($field->getFieldType() == 'text' && $field->getValidation() == 'time' && is_array($data[$field->getKey()])) {
                         $data[$field->getKey()] = $data[$field->getKey()]['hh'] . ':' . $data[$field->getKey()]['mm'];
                     }
                     # Tijd & datum instellen
                     if ($field->getFieldType() == 'text' && $field->getValidation() == 'datetime' && is_array($data[$field->getKey()])) {
                         $data[$field->getKey()] = $data[$field->getKey()]['date'] . ' ' . $data[$field->getKey()]['hh'] . ':' . $data[$field->getKey()]['mm'];
                     }
                 }
                 $metaObject = new SxModule_Pageform_Subscription_Meta();
                 $metaObject->setFieldId($field->getId())->setLabel($field->getTsl()->getName())->setName($field->getKey())->setValue(isset($data[$field->getKey()]) ? $data[$field->getKey()] : null);
                 $subscription->addMeta($metaObject);
             }
             $fielderrors = APPLICATION_ROOT . '/application/var/locale/fielderrors.tmx';
             $validator = new SxModule_Pageform_Subscription_Validator();
             $validator->setTmx(new Zend_Translate('tmx', $fielderrors, $_SESSION['System']['lng']));
             //$validator->setTmx( new Zend_Translate('tmx', APPLICATION_ROOT . '/application/var/locale/pageform.tmx', $_SESSION['System']['lng']) );
             $captchaOk = true;
             if ($pageform->getCaptcha()) {
                 $captchaOk = false;
                 $captcha = $this->_getParam('captcha');
                 if ($this->validateCaptcha($captcha)) {
                     $captchaOk = true;
                 }
             }
             $valid = false;
             if ($validator->validate($subscription, $pageform)) {
                 if ($pageform->getCaptcha()) {
                     if ($captchaOk) {
                         $valid = true;
                     }
                 } else {
                     $valid = true;
                 }
             }
             if (!$captchaOk) {
                 $this->view->capt_err = "Neem de captcha code correct over";
             }
             if ($valid) {
                 $subscription->save();
                 $config = Zend_Registry::get('config');
                 if ($pageform->getMailoption() == 1) {
                     $mail = new Zend_Mail('utf-8');
                     $mail->setSubject('Formulier verzonden op website: ' . $pageform->getName())->setFrom(Zend_Registry::get('config')->company->email, "formulier: " . $pageform->getName());
                     $view = new Zend_View();
                     $view->assign('subscription', $subscription);
                     $view->assign('config', $config);
                     $view->addScriptPath(APPLICATION_PATH . '/modules/default/views/scripts');
                     $body = $view->render('/__mail/_mailMessage.phtml');
                     $mail->setBodyHtml($body);
                     //                        $body = '<h1>Message information</h1>';
                     //                        $body .= 'Datum : ' . date('Y-m-d H:i:s') . "<br>";
                     //                        foreach ($subscription->getMeta() as $meta) {
                     //                            $body .= " " . $meta->getLabel() . ": " . $meta->getValue() . "<br>";
                     //                        }
                     //$view = new Zend_View();
                     //$view->assign('domain', $config->system->web->url);
                     //$view->assign('message', $body);
                     //$view->addScriptPath(APPLICATION_PATH . '/modules/default/views/scripts/__mail/');
                     //$mail_content =  $view->render('template.phtml');
                     $mail->setBodyHtml($body);
                     $mail->addTo($pageform->getMailto());
                     $mail->send();
                 }
                 if ($pageform->getTsl()->getConfirm() == 1) {
                     foreach ($subscription->getMeta() as $meta) {
                         if ($meta->getLabel() == $pageform->getTsl()->getConfirmto()) {
                             $sendto = $meta->getValue();
                         }
                     }
                     //$view = new Zend_View();
                     //$view->assign('domain', $config->system->web->url);
                     //$view->assign('message', $pageform->getTsl()->getConfirmcontent());
                     //$view->addScriptPath(APPLICATION_PATH . '/modules/default/views/scripts/__mail/');
                     //$mail_content =  $view->render('template.phtml');
                     $mail = new Zend_Mail('utf-8');
                     $mail->setSubject($pageform->getTsl()->getConfirmsubject())->setFrom(Zend_Registry::get('config')->company->email, Zend_Registry::get('config')->company->name);
                     $mail->setBodyHtml($body);
                     $mail->addTo($sendto);
                     $mail->send();
                 }
                 $subscription = new SxModule_Pageform_Subscription();
                 $this->view->message = "Bedankt, we hebben je bericht goed ontvangen. We zullen je zo spoedig mogelijk contacteren.";
             }
         }
         $this->view->form_slug = $this->_getParam('form_' . $page_id);
         $this->view->subscription = $subscription;
         $this->view->page = $page_has_form;
         $this->view->form_class = $this->_getParam('form_class');
         $this->view->page_id = $page_id;
         $this->view->messages = Sanmax_MessageStack::getInstance('SxModule_Pageform_Subscription');
     }
 }
Exemple #3
0
 public function validate(SxModule_Pageform_Subscription $object, SxModule_Pageform $pageform)
 {
     $this->validatePageformId($object->getPageformId());
     $msgr = Sanmax_MessageStack::getInstance($this->_namespace);
     foreach ($pageform->getField() as $field) {
         foreach ($object->getMeta() as $meta) {
             if ($field->getId() == $meta->getFieldId()) {
                 if ($field->getFieldType() == 'text' && $field->getValidation() == 'numeric') {
                     $this->validateNumeric($meta->getValue(), $field->getTsl()->getName(), 'common');
                 } elseif ($field->getFieldType() == 'text' && $field->getValidation() == 'numeric-required') {
                     $this->validateNumeric($meta->getValue(), $field->getTsl()->getName(), 'common');
                 } elseif ($field->getFieldType() == 'text' && $field->getValidation() == 'date') {
                     $this->validateDate($meta->getValue(), $field->getTsl()->getName(), 'common');
                 } elseif ($field->getFieldType() == 'text' && $field->getValidation() == 'date-required') {
                     $this->validateDate($meta->getValue(), $field->getTsl()->getName(), 'common');
                 } elseif ($field->getFieldType() == 'select' && $field->getValidation() == 'boolean') {
                     $this->validateBoolean($meta->getValue(), $field->getTsl()->getName(), 'common');
                 } elseif ($field->getFieldType() == 'radio' && $field->getValidation() == 'required') {
                     $options = array();
                     foreach ($field->getMeta() as $option) {
                         $options[] = $option->getTsl()->getValue();
                     }
                     $this->validateInArray($meta->getValue(), $field->getTsl()->getName(), $options, 'common', array(Zend_Validate_InArray::NOT_IN_ARRAY => sprintf($this->getTmx()->_('error.option.required'), $field->getTsl()->getName())));
                 } elseif ($field->getFieldType() == 'checkbox' && $field->getValidation() == 'required') {
                     $val = null;
                     if ($meta->getValue() && is_array($meta->getValue())) {
                         $val = reset($meta->getValue());
                     }
                     $options = array();
                     foreach ($field->getMeta() as $option) {
                         $options[] = $option->getTsl()->getValue();
                     }
                     $this->validateInArray($val, $field->getTsl()->getName(), $options, 'common', array(Zend_Validate_InArray::NOT_IN_ARRAY => sprintf($this->getTmx()->_('error.option.required'), $field->getTsl()->getName())));
                 } elseif ($field->getValidation() == 'text') {
                     $this->validateText($meta->getValue(), $field->getTsl()->getName(), 'common', array(Zend_Validate_StringLength::INVALID => sprintf($this->getTmx()->_('error.required'), $field->getTsl()->getName()), Zend_Validate_StringLength::TOO_LONG => sprintf($this->getTmx()->_('error.required.long'), $field->getTsl()->getName()), Zend_Validate_StringLength::TOO_SHORT => sprintf($this->getTmx()->_('error.required.short'), $field->getTsl()->getName())));
                 } elseif ($field->getValidation() == 'text-required') {
                     $this->validateTextRequired($meta->getValue(), $field->getTsl()->getName(), 'common', array(Zend_Validate_StringLength::INVALID => sprintf($this->getTmx()->_('error.required'), $field->getTsl()->getName()), Zend_Validate_StringLength::TOO_LONG => sprintf($this->getTmx()->_('error.required.long'), $field->getTsl()->getName()), Zend_Validate_StringLength::TOO_SHORT => sprintf($this->getTmx()->_('error.required.short'), $field->getTsl()->getName())));
                 } elseif ($field->getValidation() == 'file-required') {
                     $this->validateTextRequired($meta->getValue(), $field->getTsl()->getName(), 'common', array(Zend_Validate_StringLength::INVALID => sprintf($this->getTmx()->_('error.required'), $field->getTsl()->getName())));
                 } elseif ($field->getValidation() == 'textarea-required') {
                     $this->validateTextareaRequired($meta->getValue(), $field->getTsl()->getName(), 'common', array(Zend_Validate_StringLength::INVALID => sprintf($this->getTmx()->_('error.required'), $field->getTsl()->getName()), Zend_Validate_StringLength::TOO_LONG => sprintf($this->getTmx()->_('error.required.long'), $field->getTsl()->getName()), Zend_Validate_StringLength::TOO_SHORT => sprintf($this->getTmx()->_('error.required.short'), $field->getTsl()->getName())));
                 } elseif ($field->getValidation() == 'email') {
                     if ($meta->getValue() != "") {
                         $this->validateEmail($meta->getValue(), $field->getTsl()->getName(), 'common');
                     }
                 } elseif ($field->getValidation() == 'email-required') {
                     if ($meta->getValue() == '') {
                         $this->validateTextRequired($meta->getValue(), $field->getTsl()->getName(), 'common', array(Zend_Validate_StringLength::INVALID => sprintf($this->getTmx()->_('error.required'), $field->getTsl()->getName()), Zend_Validate_StringLength::TOO_LONG => sprintf($this->getTmx()->_('error.required.long'), $field->getTsl()->getName()), Zend_Validate_StringLength::TOO_SHORT => sprintf($this->getTmx()->_('error.required.short'), $field->getTsl()->getName())));
                     } else {
                         $this->validateEmail($meta->getValue(), $field->getTsl()->getName(), 'common');
                     }
                 } elseif ($field->getValidation() == 'select-option') {
                     $possible_answers = array();
                     foreach ($field->getMeta() as $field_meta) {
                         $possible_answers[] = $field_meta->getTsl()->getValue();
                     }
                     $this->validateInArray($meta->getValue(), $field->getTsl()->getName(), $possible_answers, 'common', array(Zend_Validate_InArray::NOT_IN_ARRAY => sprintf($this->getTmx()->_('error.option.required'), $field->getTsl()->getName())));
                 } else {
                     #die('No validation!'); // TODO: validatie checken!
                 }
             }
         }
     }
     if (!$msgr->getNamespaceMessages()) {
         return true;
     }
     return false;
 }
Exemple #4
0
 public function toArray(SxModule_Pageform_Subscription $item)
 {
     return array('pfsu_id' => (int) $item->getId(), 'pfsu_pageform_id' => (int) $item->getPageformId(), 'pfsu_pageformname' => $item->getPageformname(), 'pfsu_ip' => $item->getIp(), 'pfsu_agent' => $item->getAgent(), 'pfsu_date_created' => $item->getDateCreated(), 'pfsu_date_updated' => $item->getDateUpdated(), 'pfsu_lng' => $item->getLng(), 'pfsu_url' => $item->getUrl());
 }
 public function contentAction()
 {
     $this->view->messages = $this->_helper->flashMessenger->getMessages();
     $url = $this->_getParam('url');
     $proxy = new SxCms_Page_Proxy();
     $page = $proxy->getPageByUrl($url, null, $this->_getParam('lng', 'nl'));
     if ($page->getId() === false) {
         throw new Zend_Controller_Action_Exception('Page not found', 404);
     }
     $identity = Zend_Auth::getInstance()->getIdentity();
     if (!$page->isAllowed($identity)) {
         $this->_forward('unauthorized', 'index', null, array('url' => $this->view->url()));
         return;
     }
     if ($page->isExpired()) {
         throw new Zend_Controller_Action_Exception('Page expired', 404);
     }
     if ($page->getInvisible()) {
         throw new Zend_Controller_Action_Exception('Page expired', 404);
     }
     /** Gebruik Nederlandse vertaling indien nodig * */
     if ($page->hasContentFallback()) {
         $pageFallback = $proxy->getPageById($page->getId(), 'nl');
         $page->setContent($pageFallback->getContent());
     }
     $this->view->page = $page;
     $this->_helper->layout->setLayout($page->getLayout());
     if ($page->getType() == SxCms_Page::SUMMARY) {
         $children = $proxy->getPagesByParentId($page->getId(), null, $this->_getParam('lng', 'nl'), true, true);
         $childrenArr = array();
         foreach ($children as $child) {
             $pageFallback = false;
             if ($child->hasSummaryFallback()) {
                 $pageFallback = $proxy->getPageById($child->getId(), 'nl');
                 $child->setSummary($pageFallback->getSummary());
             }
             array_push($childrenArr, $child);
         }
         $this->view->children = $childrenArr;
         $this->renderScript('index/summary.phtml');
         return;
     }
     if ($page->getType() == SxCms_Page::ARTICLE) {
         $this->view->comment = new SxCms_Comment();
         $captchaSession = new Zend_Session_Namespace('captcha');
         $captchaSession->setExpirationHops(3);
         if ($captchaSession->token) {
             $captcha = $captchaSession->token;
         } else {
             $captcha = new Zend_Captcha_Image();
             $captcha->setName('captcha')->setWordLen(6)->setDotNoiseLevel(20)->setLineNoiseLevel(0)->setFont(APPLICATION_PATH . '/var/fonts/BRLNSR.TTF')->setImgDir(APPLICATION_ROOT . '/public_html/images/captcha');
             $captcha->generate();
             $captchaSession->token = $captcha;
         }
         $this->view->captcha = $captcha;
     }
     if ($page->getPageform()) {
         if ($this->getRequest()->isGet()) {
             $this->view->captchaId = $this->generateCaptcha();
         }
         $pageformproxy = new SxModule_Pageform_Proxy();
         $subscription = new SxModule_Pageform_Subscription();
         $pageform = $pageformproxy->getActiveById($page->getPageform(), $_SESSION['System']['lng']);
         $this->view->pageform = $pageform;
         if ($this->getRequest()->isPost() && $this->_getParam('comment-submit')) {
             $this->view->errors = array();
             $validator = new SxCms_Comment_BaseValidator();
             $validator->setCaptcha($captcha)->setUserCaptcha($this->_getParam('captcha'));
             $comment = new SxCms_Comment();
             $comment->setMessage($this->_getParam('message'));
             $author = new SxCms_Comment_Author();
             $author->setName($this->_getParam('name'))->setEmail($this->_getParam('email'))->setWebsite($this->_getParam('website'));
             $comment->setPage($page);
             $comment->setCommenter($author);
             if (!$validator->validate($comment)) {
                 $this->view->errors = $validator->getErrors();
                 $this->view->comment = $comment;
                 $this->view->userCaptcha = $this->_getParam('captcha');
             } else {
                 $mapper = new SxCms_Comment_DataMapper();
                 $mapper->save($comment);
                 $captchaSession->unsetAll();
                 $this->_helper->flashMessenger->addMessage('Uw bericht werd succcesvol verwerk.
                 Na goedkeuring door een administrator zal dit op de website verschijnen.');
                 $this->_helper->redirector->gotoRoute(array('url' => $page->getLink()), 'content');
             }
         }
         if ($this->getRequest()->isPost() && $this->_getParam('pageform-submit')) {
             $data = $this->_getParam('pageform');
             $subscription->setPageformId($pageform->getId())->setPageformname($pageform->getName())->setIp($this->getRequest()->getServer('REMOTE_ADDR'))->setAgent($this->getRequest()->getServer('HTTP_USER_AGENT'))->setLng($this->_getParam('lng'))->setUrl('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
             foreach ($pageform->getField() as $field) {
                 if (isset($data[$field->getKey()])) {
                     # Tijd instellen
                     if ($field->getFieldType() == 'text' && $field->getValidation() == 'time' && is_array($data[$field->getKey()])) {
                         $data[$field->getKey()] = $data[$field->getKey()]['hh'] . ':' . $data[$field->getKey()]['mm'];
                     }
                     # Tijd & datum instellen
                     if ($field->getFieldType() == 'text' && $field->getValidation() == 'datetime' && is_array($data[$field->getKey()])) {
                         $data[$field->getKey()] = $data[$field->getKey()]['date'] . ' ' . $data[$field->getKey()]['hh'] . ':' . $data[$field->getKey()]['mm'];
                     }
                 }
                 $metaObject = new SxModule_Pageform_Subscription_Meta();
                 $metaObject->setFieldId($field->getId())->setLabel($field->getTsl()->getName())->setName($field->getKey())->setValue(isset($data[$field->getKey()]) ? $data[$field->getKey()] : null);
                 $subscription->addMeta($metaObject);
             }
             $fielderrors = APPLICATION_ROOT . '/application/var/locale/fielderrors.tmx';
             $validator = new SxModule_Pageform_Subscription_Validator();
             $validator->setTmx(new Zend_Translate('tmx', $fielderrors, $_SESSION['System']['lng']));
             //$validator->setTmx( new Zend_Translate('tmx', APPLICATION_ROOT . '/application/var/locale/pageform.tmx', $_SESSION['System']['lng']) );
             $captchaOk = true;
             if ($pageform->getCaptcha()) {
                 $captchaOk = false;
                 $captcha = $this->_getParam('captcha');
                 if ($this->validateCaptcha($captcha)) {
                     $captchaOk = true;
                 }
             }
             $this->view->captchaId = $this->generateCaptcha();
             if ($captchaOk) {
                 if ($validator->validate($subscription, $pageform)) {
                     $subscription->save();
                     if ($pageform->getMailoption() == 1) {
                         $mail = new Zend_Mail('utf-8');
                         $mail->setSubject('Formulier verzonden op website: ' . $pageform->getName())->setFrom(Zend_Registry::get('config')->company->email, "formulier: " . $pageform->getName());
                         $body = 'Datum : ' . date('Y-m-d H:i:s') . "\n";
                         foreach ($subscription->getMeta() as $meta) {
                             $body .= " " . $meta->getLabel() . ": " . $meta->getValue() . "\n";
                         }
                         $mail->setBodyText($body);
                         $mail->addTo($pageform->getMailto());
                         $mail->send();
                     }
                     if ($pageform->getTsl()->getConfirm() == 1) {
                         foreach ($subscription->getMeta() as $meta) {
                             if ($meta->getLabel() == $pageform->getTsl()->getConfirmto()) {
                                 $sendto = $meta->getValue();
                             }
                         }
                         $mail = new Zend_Mail('utf-8');
                         $mail->setSubject($pageform->getTsl()->getConfirmsubject())->setFrom(Zend_Registry::get('config')->company->email, Zend_Registry::get('config')->company->name);
                         $mail->setBodyHtml($pageform->getTsl()->getConfirmcontent());
                         $mail->addTo($sendto);
                         $mail->send();
                     }
                     $subscription = new SxModule_Pageform_Subscription();
                     $this->view->message = "Formulier verzonden!";
                 } else {
                     $this->view->error = "Er ging iets mis...";
                     //var_dump($subscription->getMeta());
                     //exit;
                 }
             } else {
                 $this->view->error = "Neem de captcha code correct over...";
             }
         }
         $this->view->subscription = $subscription;
     }
     $this->view->mode = $this->_getParam('mode') ? $this->_getParam('mode') : '';
     $this->view->messages = Sanmax_MessageStack::getInstance('SxModule_Pageform_Subscription');
 }