Ejemplo n.º 1
0
 public function postAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         try {
             // Test les eventuelles erreurs
             $errors = array();
             if (empty($datas['name'])) {
                 $errors[] = $this->_('Your name');
             }
             if ((empty($datas['email']) or !Zend_Validate::is($datas['email'], 'emailAddress')) && empty($datas['phone'])) {
                 $errors[] = $this->_('Your phone number or email address');
             }
             if (empty($datas['people'])) {
                 $errors[] = $this->_('The number of people');
             }
             if (empty($datas['date'])) {
                 $errors[] = $this->_('The date and time of the booking');
             }
             if (empty($datas['prestation'])) {
                 $errors[] = $this->_('The booking informations');
             }
             $store = new Booking_Model_Store();
             $store->find($datas['store'], 'store_id');
             if (!$store->getId()) {
                 throw new Exception($this->_('An error occurred during process. Please try again later.'));
             }
             //vérif value
             $booking = new Booking_Model_Booking();
             $booking->find($store->getBookingId(), 'booking_id');
             if (!$booking->getId() || $booking->getValueId() != $datas['option_value_id']) {
                 throw new Exception($this->_('An error occurred during process. Please try again later.'));
             }
             $dest_email = $store->getEmail();
             $app_name = $this->getApplication()->getName();
             $layout = $this->getLayout()->loadEmail('booking', 'send_email');
             $layout->getPartial('content_email')->setData($datas);
             $content = $layout->render();
             $mail = new Zend_Mail('UTF-8');
             $mail->setBodyHtml($content);
             $mail->setFrom($datas['email'], $datas['name']);
             $mail->addTo($dest_email, $app_name);
             $mail->setSubject($this->_("Message from your app %s", $app_name));
             $mail->send();
             if (!empty($errors)) {
                 $message = $this->_('Please fill out the following fields:<br />');
                 $message .= join('<br />', $errors);
                 $html = array('error' => 1, 'message' => $message);
             } else {
                 $html = array('success' => 1);
             }
         } catch (Exception $e) {
             $html = array('error' => 1, 'message' => $e->getMessage());
         }
         $this->_sendHtml($html);
     }
 }
Ejemplo n.º 2
0
 public function editpostAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         try {
             $application = $this->getApplication();
             $html = '';
             $isNew = true;
             // Test s'il y a une erreur dans la saisie
             if (empty($datas['store_name'])) {
                 throw new Exception($this->_('Please, choose a store'));
             }
             if (empty($datas['email'])) {
                 throw new Exception($this->_('Please enter a valid email address'));
             }
             // Test s'il y a un value_id
             if (empty($datas['value_id'])) {
                 throw new Exception($this->_('An error occurred during process. Please try again later.'));
             }
             // Récupère l'option_value en cours
             $option_value = new Application_Model_Option_Value();
             $option_value->find($datas['value_id']);
             $booking = new Booking_Model_Booking();
             $store = new Booking_Model_Store();
             $booking->find($datas['value_id'], 'value_id');
             // Si un id est passé en paramètre
             if (!empty($datas['store_id'])) {
                 $store->find($datas['store_id']);
                 if ($store->getId() and $booking->getValueId() != $option_value->getId()) {
                     // Envoi l'erreur
                     throw new Exception($this->_('An error occurred during process. Please try again later.'));
                 }
                 $isNew = !$store->getId();
             }
             $booking->setData($datas)->save();
             unset($datas['value_id']);
             $datas['booking_id'] = $booking->getId();
             $store->setData($datas)->save();
             $html = array('success' => '1', 'success_message' => $this->_('Infos successfully saved'), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0);
             if ($isNew) {
                 $html['row_html'] = $this->getLayout()->addPartial('row_' . $store->getId(), 'admin_view_default', 'booking/application/edit/row.phtml')->setCurrentStore($store)->setCurrentOptionValue($option_value)->toHtml();
             }
         } catch (Exception $e) {
             $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1);
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }