Ejemplo n.º 1
0
 public function indexAction()
 {
     $frmContact = new Contact_Form_Contact();
     if ($this->_request->isPost() && $frmContact->isValid($_POST)) {
         // get the posted data
         $sender = $frmContact->getValue('name');
         $email = $frmContact->getValue('email');
         $subject = $frmContact->getValue('subject');
         $message = $frmContact->getValue('message');
         // load the template
         $htmlMessage = $this->view->partial('templates/default.phtml', $frmContact->getValues());
         $mail = new Zend_Mail();
         // configure and create the SMTP connection
         $config = array('auth' => 'login', 'username' => 'myusername', 'password' => 'password');
         $transport = new Zend_Mail_Transport_Smtp('mail.server.com', $config);
         // set the subject
         $mail->setSubject($subject);
         // set the message's from address to the person who submitted the form
         $mail->setFrom($email, $sender);
         // for the sake of this example you can hardcode the recipient
         $mail->addTo('*****@*****.**', 'webmaster');
         // add the file attachment
         $fileControl = $frmContact->getElement('attachment');
         if ($fileControl->isUploaded()) {
             $attachmentName = $fileControl->getFileName();
             $fileStream = file_get_contents($attachmentName);
             // create the attachment
             $attachment = $mail->createAttachment($fileStream);
             $attachment->filename = basename($attachmentName);
         }
         // it is important to provide a text only version in addition to the html message
         $mail->setBodyHtml($htmlMessage);
         $mail->setBodyText($message);
         //send the message, now using SMTP transport
         $result = $mail->send($transport);
         // inform the view with the status
         $this->view->messageProcessed = true;
         if ($result) {
             $this->view->sendError = false;
         } else {
             $this->view->sendError = true;
         }
     }
     $frmContact->setAction('/contact');
     $frmContact->setMethod('post');
     $this->view->form = $frmContact;
 }
Ejemplo n.º 2
0
 /**
  * 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;
 }
Ejemplo n.º 3
0
 /**
  * Configuration action
  */
 public function configAction()
 {
     //read data from request
     $data = $this->getRequest()->getPost('data');
     $inputHashChangePost = $this->_request->getParam('inputHashChangePost');
     $inputHashChangeGet = $this->_request->getParam('inputHashChangeGet');
     //check if cancel button is pressed
     if ($this->_formHelper->isCancel()) {
         //cancel form
         return $this->_formHelper->returnCancel($this->view->url(array('action' => 'index')), $this->translate('Action canceled'));
     }
     if ($this->getRequest()->getParam("type") == 'contact') {
         $module_name = "contact";
     } else {
         if ($this->getRequest()->getParam("type") == 'newsletter') {
             $module_name = "newsletter";
         } else {
             if ($this->getRequest()->getParam("type") == 'blog') {
                 $module_name = "blog";
             } else {
                 throw new Exception("Contact module not found");
             }
         }
     }
     //read contact module
     $module = new Application_Model_Module();
     if (!Application_Model_ModuleMapper::getInstance()->findByCode($module_name, $module)) {
         throw new Exception("Contact module not found");
     }
     $this->view->data = array('email' => $module->get_settings('email'));
     $this->view->data['type'] = $module_name;
     $this->view->emailTransportTypeOptions = Application_Model_Application::getEmailTransportTypeOptions();
     //postback - save?
     if ($this->_formHelper->isSave()) {
         $formToEmails = new Contact_Form_ConfigToEmailsWrapper($data['email']['to_emails']);
         $formParameters = new Contact_Form_ConfigParameters($data['email']['parameters'], null, $data['email']['transport']);
         if ($module_name == 'contact') {
             $formEmail = new Contact_Form_ConfigEmail($data['email']);
         } elseif ($module_name == 'newsletter') {
             $formEmail = new Contact_Form_ConfigEmailNewsletter($data['email']);
         } elseif ($module_name == 'blog') {
             $formEmail = new Blog_Form_ConfigEmail($data['email']);
         }
         //check if valid
         if ($formEmail->isValid() && $formParameters->isValid() && $formToEmails->isValid()) {
             $data['email'] = $formEmail->getValues();
             $data['email']['parameters'] = $formParameters->getValues();
             $data['email']['to_emails'] = $formToEmails->getValues();
             $lang = new Translation_Model_Lang();
             if (!Translation_Model_LangMapper::getInstance()->findByCode(CURR_LANG, $lang)) {
                 throw new Exception('No language for this code.');
             }
             Translation_Model_TranslationMapper::getInstance()->save('mailtextRespondContactTranslationkey', $lang->get_id(), $data['email']['mailtext_respond_contact'], 'global');
             $data['email']['mailtext_respond_contact'] = 'mailtextRespondContactTranslationkey';
             Translation_Model_TranslationMapper::getInstance()->save('landingPageText', $lang->get_id(), $data['email']['landing_page_text'], 'global');
             $data['email']['landing_page_text'] = 'landingPageText';
             Translation_Model_TranslationMapper::getInstance()->save('subjectContactTranslationkey', $lang->get_id(), $data['email']['subject_contact'], 'global');
             $data['email']['subject_contact'] = 'subjectContactTranslationkey';
             //create module entity object
             $settings = $module->get_settings();
             $settings['email'] = $data['email'];
             $module->set_settings(json_encode($settings));
             $module->set_data(json_encode($module->get_data()));
             //new entity
             Application_Model_ModuleMapper::getInstance()->save($module);
             //save done, return success
             return $this->_formHelper->returnSuccess($this->view->url(array('action' => 'config', 'inputHashChangeGet' => $inputHashChangePost)), $this->translate('Configuration saved.'));
         } else {
             //we have errors - return json or continue
             $messages = $formEmail->getMessages();
             $messages['parameters'] = $formParameters->getMessages();
             $messages['to_emails'] = $formToEmails->getMessages();
             $this->view->data = $data;
             $this->_formHelper->returnError($messages);
         }
     }
     if (isset($inputHashChangeGet) && $inputHashChangeGet != '') {
         $this->view->inputHashChange = $inputHashChangeGet;
     } else {
         $this->view->inputHashChange = "email-config";
     }
     //country assign
     $countries = new Application_Model_Country();
     $countries = Application_Model_CountryMapper::getInstance()->getAllCountries(CURR_LANG);
     $this->view->countries = $countries;
     $this->view->languages = Application_Model_TranslateMapper::getInstance()->getLanguages();
     $this->view->fields = Contact_Form_Contact::getFields();
 }