Example #1
0
 /**
  * Add custom fields to menu item form for render a simple contact layout menu item
  */
 private function simpleContactLayout()
 {
     # dropdown for contacts
     $txtContact = $this->createElement("select", "contact")->setOrder($this->order++)->setLabel("CONTACT_SELECT")->setRequired(true);
     $mdlContact = new Contact_Model_Contact();
     $contactList = $mdlContact->getPublishedList();
     foreach ($contactList as $contact) {
         $title = $contact->first_name . ' ' . $contact->last_name;
         $title .= strlen($contact->con_position) > 0 ? ' [' . $contact->con_position . ']' : '';
         $txtContact->addMultiOption($contact->id, $title);
     }
     $this->addElement($txtContact);
     # we can add more conditions like set require for some fields or even show them
 }
 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')) {
                 $errors[] = $this->_('Your email');
             }
             if (empty($datas['info'])) {
                 $errors[] = $this->_('Your request');
             }
             $contact = new Contact_Model_Contact();
             $contact->find($this->getCurrentOptionValue()->getId(), 'value_id');
             if (!$contact->getId()) {
                 throw new Exception($this->_('An error occurred while sending your request. Please try again later.'));
             }
             $dest_email = $contact->getEmail();
             $app_name = $this->getApplication()->getName();
             $layout = $this->getLayout()->loadEmail('contact', '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 enter properly 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 postAction()
 {
     if ($data = Zend_Json::decode($this->getRequest()->getRawBody())) {
         try {
             if (empty($data['email'])) {
                 throw new Exception($this->_('Please enter your email address'));
             }
             if (!Zend_Validate::is($data['email'], 'EmailAddress')) {
                 throw new Exception($this->_('Please enter a valid email address'));
             }
             $customer = new Customer_Model_Customer();
             $customer->find(array('email' => $data['email'], "app_id" => $this->getApplication()->getId()));
             if (!$customer->getId()) {
                 throw new Exception("Your email address does not exist");
             }
             $admin_email = null;
             $password = Core_Model_Lib_String::generate(8);
             $contact = new Contact_Model_Contact();
             $contact_page = $this->getApplication()->getPage('contact');
             if ($contact_page->getId()) {
                 $contact->find($contact_page->getId(), 'value_id');
                 $admin_email = $contact->getEmail();
             }
             $customer->setPassword($password)->save();
             $sender = 'no-reply@' . Core_Model_Lib_String::format($this->getApplication()->getName(), true) . '.com';
             $layout = $this->getLayout()->loadEmail('customer', 'forgot_password');
             $layout->getPartial('content_email')->setCustomer($customer)->setPassword($password)->setAdminEmail($admin_email)->setApp($this->getApplication()->getName());
             $content = $layout->render();
             $mail = new Zend_Mail('UTF-8');
             $mail->setBodyHtml($content);
             $mail->setFrom($sender, $this->getApplication()->getName());
             $mail->addTo($customer->getEmail(), $customer->getName());
             $mail->setSubject($this->_('%s - Your new password', $this->getApplication()->getName()));
             $mail->send();
             $html = array("success" => 1, "message" => $this->_("Your new password has been sent to the entered email address"));
         } catch (Exception $e) {
             $html = array('error' => 1, 'message' => $e->getMessage());
         }
         $this->_sendHtml($html);
     }
     return $this;
 }
 protected function _sendNewAccountEmail($customer, $password)
 {
     $admin_email = null;
     $contact = new Contact_Model_Contact();
     $contact_page = $this->getApplication()->getPage('contact');
     $sender = 'no-reply@' . Core_Model_Lib_String::format($this->getApplication()->getName(), true) . '.com';
     if ($contact_page->getId()) {
         $contact->find($contact_page->getId(), 'value_id');
         $admin_email = $contact->getEmail();
     }
     $layout = $this->getLayout()->loadEmail('customer', 'create_account');
     $layout->getPartial('content_email')->setCustomer($customer)->setPassword($password)->setAdminEmail($admin_email)->setApp($this->getApplication()->getName());
     $content = $layout->render();
     $mail = new Zend_Mail('UTF-8');
     $mail->setBodyHtml($content);
     $mail->setFrom($sender, $this->getApplication()->getName());
     $mail->addTo($customer->getEmail(), $customer->getName());
     $mail->setSubject($this->_('%s - Account creation', $this->getApplication()->getName()));
     $mail->send();
     return $this;
 }
 public function editpostAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         try {
             $application = $this->getApplication();
             // Test s'il y a un value_id
             if (empty($datas['value_id'])) {
                 throw new Exception($this->_('An error occurred while saving your contact informations.'));
             }
             // Récupère l'option_value en cours
             $option_value = new Application_Model_Option_Value();
             $option_value->find($datas['value_id']);
             $html = '';
             $contact = new Contact_Model_Contact();
             $contact->find($option_value->getId(), 'value_id');
             if (!empty($datas['file'])) {
                 $relative_path = '/contact/cover/';
                 $folder = Application_Model_Application::getBaseImagePath() . $relative_path;
                 $file = Core_Model_Directory::getTmpDirectory(true) . '/' . $datas['file'];
                 if (!is_dir($folder)) {
                     mkdir($folder, 0777, true);
                 }
                 if (!copy($file, $folder . $datas['file'])) {
                     throw new exception($this->_('An error occurred while saving your picture. Please try againg later.'));
                 } else {
                     $datas['cover'] = $relative_path . $datas['file'];
                 }
             } else {
                 if (!empty($datas['remove_cover'])) {
                     $datas['cover'] = null;
                 }
             }
             $contact->setData($datas)->save();
             $html = array('success' => '1', 'success_message' => $this->_('Informations successfully saved'), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0);
         } catch (Exception $e) {
             $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1);
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }
 /**
  * View action for contact controller
  * @throws Exception
  */
 public function viewAction()
 {
     // action body
     try {
         $translate = Zend_Registry::get('Zend_Translate');
         $mdlContact = new Contact_Model_Contact();
         $frmContact = new Contact_Form_Contact(array('type' => 'public'));
         $params = $this->getRequest()->getParams();
         $contact = $mdlContact->find((int) $params['contact'])->current();
         if (!$contact) {
             throw new Exception($translate->translate("CONTACT_ROW_NOT_FOUND"));
         }
         if ($this->getRequest()->isPost()) {
             if ($frmContact->isValid($_POST)) {
                 $mdlAccount = new Acl_Model_Account();
                 $account = $mdlAccount->find((int) $contact->account_id)->current();
                 $emailTo = strlen($contact->email_to) > 1 ? $contact->email_to : $account->email;
                 $mail = new Zend_Mail();
                 $mail->setBodyText($frmContact->getElement('message')->getValue())->setFrom($frmContact->getElement('email')->getValue(), $frmContact->getElement('fullname')->getValue())->addTo($emailTo, $account->first_name . ' ' . $account->last_name)->setSubject($translate->translate('CONTACT_DEFAULT_SUBJECT'))->send();
                 $frmContact->reset();
             }
         } else {
             $fields = array();
             foreach ($frmContact->getElements() as $element) {
                 $fields[] = $element->getName();
             }
             $frmContact->addDisplayGroup($fields, 'form', array('legend' => "CONTACT"));
         }
         $frmContact->setAction($this->_request->getBaseUrl() . "/contact/contact/view");
         $this->view->frmContact = $frmContact;
     } catch (Exception $e) {
         #$this->_helper->flashMessenger->addMessage( array('type'=>'error', 'header'=>'', 'message' => $e->getMessage() ) );
         #$this->_helper->redirector( "index", "contact", "contact" );
         echo $e->getMessage();
     }
     return;
 }
 /**
  * View action for category controller
  * @throws Exception
  */
 public function viewAction()
 {
     // action body
     try {
         $translate = Zend_Registry::get('Zend_Translate');
         $params = $this->getRequest()->getParams();
         $mdlCategory = new Contact_Model_Category();
         $mdlContact = new Contact_Model_Contact();
         $category = $mdlCategory->find((int) $params['category'])->current();
         if (!$category) {
             throw new Exception($translate->translate("CONTACT_ROW_NOT_FOUND"));
         }
         $contactList = $mdlContact->getByCategory($category);
         $this->view->contacts = $contactList;
     } catch (Exception $e) {
         $this->_helper->flashMessenger->addMessage(array('type' => 'error', 'header' => '', 'message' => $e->getMessage()));
         $this->_helper->redirector("index", "contact", "contact");
     }
     return;
 }
 public function editpostAction()
 {
     if ($data = $this->getRequest()->getPost()) {
         try {
             $application = $this->getApplication();
             // Test s'il y a un value_id
             if (empty($data['value_id'])) {
                 throw new Exception($this->_('An error occurred while saving. Please try again later.'));
             }
             // Récupère l'option_value en cours
             $option_value = new Application_Model_Option_Value();
             $option_value->find($data['value_id']);
             $html = '';
             $contact = new Contact_Model_Contact();
             $contact->find($option_value->getId(), 'value_id');
             if (!empty($data['file'])) {
                 $file = pathinfo($data['file']);
                 $filename = $file['basename'];
                 $relative_path = $option_value->getImagePathTo();
                 $folder = Application_Model_Application::getBaseImagePath() . $relative_path;
                 $img_dst = $folder . '/' . $filename;
                 $img_src = Core_Model_Directory::getTmpDirectory(true) . '/' . $filename;
                 if (!is_dir($folder)) {
                     mkdir($folder, 0777, true);
                 }
                 if (!@copy($img_src, $img_dst)) {
                     throw new exception($this->_('An error occurred while saving your picture. Please try again later.'));
                 } else {
                     $data['cover'] = $relative_path . '/' . $filename;
                 }
             } else {
                 if (!empty($data['remove_cover'])) {
                     $data['cover'] = null;
                 }
             }
             $contact->setData($data);
             if ($contact->getStreet() and $contact->getPostcode() and $contact->getCity()) {
                 $latlon = Siberian_Google_Geocoding::getLatLng(array("street" => $contact->getStreet(), "postcode" => $contact->getPostcode(), "city" => $contact->getCity()));
                 if (!empty($latlon[0]) && !empty($latlon[1])) {
                     $contact->setLatitude($latlon[0])->setLongitude($latlon[1]);
                 }
             } else {
                 $contact->setLatitude(null)->setLongitude(null);
             }
             $contact->save();
             $html = array('success' => '1', 'success_message' => $this->_('Info successfully saved'), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0);
         } catch (Exception $e) {
             $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1);
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }
Example #9
0
 /**
  * Delete Page
  *
  * @param int $ids
  */
 public function delete(Contact_Model_Contact $contact)
 {
     //delete page
     $result = $this->_dbTable->getAdapter()->delete('contact', array('id = ?' => $contact->get_id()));
     return $result > 0;
 }