Example #1
0
 public function editAction()
 {
     // web page title
     $this->view->title = "Edition de formulaire";
     // Tests if the user has permissions
     if ($this->view->aclIsAllowed($this->_name, 'manage', true)) {
         // set variables needed for the process
         $formID = $this->_getParam('formID');
         $returnAction = $this->_getParam('return');
         $pageID = $this->_getParam('pageID');
         $blockID = $this->_getParam('blockID');
         $baseDir = $this->view->baseUrl();
         if (empty($formID) && !empty($blockID)) {
             $formID = Cible_FunctionsBlocks::getBlockParameter($blockID, '1');
         }
         // Define the url where to return
         if ($returnAction) {
             $returnUrl = "/form/index/{$returnAction}";
         } elseif ($pageID) {
             $returnUrl = "/page/index/index/ID/{$pageID}";
         } else {
             $returnUrl = "/form/index/list/";
         }
         //Add specific js file
         $this->view->headScript()->appendFile($this->view->locateFile('headerFormActions.js'));
         $this->view->headScript()->appendFile($this->view->locateFile('tiny_mce/tiny_mce.js'));
         $oNotifications = new FormNotificationObject();
         $recipients = $oNotifications->getAll(null, true, $formID);
         // Get data for the current form
         $oForm = new FormObject();
         $data = $oForm->populate($formID, $this->getCurrentEditLanguage());
         //Generate the form for the back button
         $formBack = new FormBackButton(array('baseDir' => $baseDir, 'cancelUrl' => "{$baseDir}{$returnUrl}", 'disableAction' => false));
         $formBack->removeElement('submitSave');
         $formBack->getElement('cancel')->setDecorators(array('ViewHelper', array(array('data' => 'HtmlTag'), array('tag' => 'li')), array(array('row' => 'HtmlTag'), array('tag' => 'ul', 'openOnly' => true, 'class' => 'actions-buttons'))))->setOrder(1);
         $this->view->formBack = $formBack;
         //Generate the form
         $form = new FormForm(array('baseDir' => $baseDir, 'cancelUrl' => "{$baseDir}{$returnUrl}", 'formID' => $formID, 'disableAction' => true, 'recipients' => $recipients));
         $this->view->form = $form;
         //Add question type data
         $oQuestion = new FormQuestionTypeObject();
         $questionData = $oQuestion->getAll($this->getCurrentEditLanguage());
         $this->view->questionType = $questionData;
         // action: If not post action (send modification)
         if (!$this->_request->isPost()) {
             //Populate the for with data from db
             $form->populate($data);
         } else {
             // Get data sent
             $formData = $this->_request->getPost();
             if ($form->isValid($formData)) {
                 $languages = Cible_FunctionsGeneral::getAllLanguage();
                 var_dump($languages);
                 exit;
                 // and save value in db
                 $oForm->save($formID, $formData, $this->getCurrentEditLanguage());
                 $oForm->save($formID, $formData, $this->getCurrentEditLanguage());
                 $this->_redirect($returnUrl);
             }
         }
     }
 }
Example #2
0
 public function formAction()
 {
     $formId = 0;
     $_blockID = $this->_request->getParam('BlockID');
     $_params = Cible_FunctionsBlocks::getBlockParameters($_blockID);
     $_recipient = (int) $_params[0]['P_Value'];
     $params['id'] = $_recipient;
     $params['langId'] = $this->getCurrentEditLanguage();
     $oForm = new FormObject($params);
     $data = $oForm->getFormData();
     $this->_formTitle = $data['form']['FI_Title'];
     $form = new FormFront(null, $data);
     $hasCaptcha = $form->getHasCaptcha();
     $isValidCaptcha = true;
     //Get form parameters and test if need to be logged to submit
     //@todo: Create the process in second phase.
     $hasProfileLogged = false;
     $lastPage = false;
     $sendNotification = $form->getSendNotification();
     // If the user submit the form
     if ($this->_request->isPost()) {
         // get submitted data
         $formData = $this->_request->getPost();
         // The form is valid
         if ($form->isValid($formData)) {
             // Test if he captcha value is ok
             if ($hasCaptcha) {
                 $_captcha = $form->getElement('captcha');
                 $isValidCaptcha = $_captcha->isValid($_POST['captcha'], $_POST);
             }
             // If correct captcha or have no captcha
             if ($hasCaptcha && $isValidCaptcha || !$hasCaptcha) {
                 // Test if the user has to be logged (and have a profile)
                 if ($hasProfileLogged) {
                     //TODO: Create the process to save data
                     // test if it's a multi page form and if it's the last page
                     $lastPage = false;
                     if (!$lastPage) {
                         /* TODO: Load the next form and display it.
                          * Exit this process.
                          */
                     }
                 }
                 /* Send an email to the recipient int the notification list
                  * of the form.
                  */
                 // create a the mail content
                 $_config = Zend_Registry::get('config');
                 $formTest = $form->populate($formData);
                 $emailContent = $this->_emailRender($formTest);
                 $this->view->assign('formMail', $emailContent);
                 $view = $this->getHelper('ViewRenderer')->view;
                 $html = $view->render('index/emailToSend.phtml');
                 if ($sendNotification) {
                     $formId = $params['id'];
                     // Retrieve the recipent list and the sender
                     $oNotification = new FormNotificationObject();
                     $sender = $_config->form->sender;
                     $recipients = $oNotification->getNotificationEmails($formId);
                     // Create the email and send it
                     $mail = new Zend_Mail('utf-8');
                     $mail->setBodyHtml($html)->setFrom($sender, $_config->site->title)->setSubject($this->_formTitle);
                     foreach ($recipients as $recipient) {
                         $mail->addTo($recipient['FN_Email']);
                     }
                     $mail->send();
                     $this->renderScript('index/forms-contact-thank-you.phtml');
                 } else {
                     $this->renderScript('index/form-error-notification.phtml');
                 }
             }
         } else {
             $form->populate($formData);
         }
     }
     $this->view->assign($this->_name, $form);
 }