public function postAction()
 {
     if ($data = Zend_Json::decode($this->getRequest()->getRawBody())) {
         try {
             $errors = array();
             if (empty($data['name'])) {
                 $errors[] = $this->_('Your name');
             }
             if ((empty($data['email']) or !Zend_Validate::is($data['email'], 'emailAddress')) && empty($data['phone'])) {
                 $errors[] = $this->_('Your phone number or email address');
             }
             if (empty($data['people'])) {
                 $errors[] = $this->_('The number of people');
             }
             if (empty($data['date'])) {
                 $errors[] = $this->_('The date and time of the booking');
             }
             if (empty($data['prestation'])) {
                 $errors[] = $this->_('The booking information');
             }
             //                $date = new Zend_Date($data['date']);
             //                if(!empty($data['date']) AND $date->compare(Zend_Date::now(), Zend_Date::DATES) < 0) throw new Exception($this->_('Please, enter a date greater than today'));
             $store = new Booking_Model_Store();
             $store->find($data['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()) {
                 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($data);
             $content = $layout->render();
             $mail = new Zend_Mail('UTF-8');
             $mail->setBodyHtml($content);
             $mail->setFrom($data['email'], $data['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: ');
                 $message .= join(' - ', $errors);
                 $html = array('error' => 1, 'message' => $message);
             } else {
                 $html = array("success" => 1, "message" => $this->_("Thank you for your request. We'll answer you as soon as possible."));
             }
         } catch (Exception $e) {
             $html = array('error' => 1, 'message' => $e->getMessage());
         }
         $this->_sendHtml($html);
     }
 }
 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);
     }
 }
 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));
     }
 }