Exemplo n.º 1
0
 /**
  * @Created By : Mahipal Singh Adhikari
  * @Created On : 8-Dec-2010
  * @Description: Used to display contact us page and send mails to Site Administrator
  */
 public function contactAction()
 {
     $identifire = $this->view->actionName;
     $page = new Application_Model_Page();
     $preview = false;
     $preview = $this->_getParam("preview");
     $page = $page->getStaticContent($identifire);
     $this->view->preview = $preview;
     $this->view->status = $page->getStatus();
     $this->view->title = $page->getTitle();
     $this->view->content = $page->getContent();
     $this->view->headTitle()->setSeparator(' - ');
     if ($page->getMetaTitle() == "") {
         $this->view->headTitle()->set($page->getTitle());
     } else {
         $this->view->headTitle()->set($page->getMetaTitle());
     }
     //append meta title and keywords
     $this->view->headMeta()->appendName('keywords', $page->getMetaKeyword());
     $this->view->headMeta()->appendName('description', $page->getMetaDescription());
     $this->view->headMeta()->appendName('title', $page->getMetaTitle());
     //submit information
     $form = new Application_Form_Contact();
     $elements = $form->getElements();
     $form->clearDecorators();
     foreach ($elements as $element) {
         $element->removeDecorator('label');
         $element->removeDecorator('dd');
     }
     $this->view->form = $form;
     if ($this->getRequest()->isPost()) {
         $params = $this->getRequest()->getPost();
         if ($form->isValid($params)) {
             //set user id if logged in else set 0 as default
             $user_id = 0;
             $userNs = new Zend_Session_Namespace('members');
             $user_id = $userNs->userId;
             //create contact model object
             $contactM = new Application_Model_Contact();
             //set values
             $contactM->setContactName($this->_getParam('contact_name'));
             $contactM->setContactEmail($this->_getParam('contact_email'));
             $contactM->setContactReason(nl2br($this->_getParam('contact_reason')));
             $contactM->setUserId($user_id);
             $contactM->setStatus(1);
             //save data
             $contact_id = $contactM->save();
             $message = "";
             if ($contact_id > 0) {
                 //send email to admin
                 $settings = new Admin_Model_GlobalSettings();
                 $admin_email = $settings->settingValue('admin_email');
                 //$admin_email = "*****@*****.**";
                 //set sender information
                 $mailOptions['sender_name'] = ucwords($this->_getParam('contact_name'));
                 $mailOptions['sender_email'] = $this->_getParam('contact_email');
                 $mailOptions['sender_comments'] = $this->_getParam('contact_reason');
                 //set receiver information
                 $mailOptions['receiver_email'] = $admin_email;
                 //$mailOptions['receiver_name']	= "Administrator";
                 //create mail class object and send the email
                 $Mail = new Base_Mail();
                 $Mail->sendContactusEmail($mailOptions);
                 $message = "Thanks! We have your feedback and will try and get in touch with you as soon as possible.";
             } else {
                 $message = "Error occured while sending email.";
             }
             //set falsh message and redirect user
             $_SESSION["flash_msg"] = $message;
             $this->_redirect($this->view->seoUrl('/index/contact/'));
         }
         //end of if
     }
     //end if
 }