예제 #1
0
 public function indexAction()
 {
     $vista = Services::get('vista_rest');
     $this->view->listas = $vista->getListasBusca();
     $form = new Site_Form_FaleConoscoForm();
     $this->view->form = $form;
     $this->view->bodyClass = 'pg-interna';
     $params = $this->_request->getParams();
     $this->view->headScript()->appendFile($this->view->serverUrl() . BASEDIR . '/res/js/faleconosco.js');
     $acao = $this->getRequest()->getParam('acao');
     $this->view->proposta = $acao == 'proposta';
     $this->view->subject = $this->getRequest()->getParam('s');
     if ($this->_request->isPost()) {
         try {
             $vista = Services::get('vista_rest');
             $vista->getAuthEmail();
             $smtpData = $vista->getResult();
             $config = array('auth' => 'login', 'username' => $smtpData['user'], 'password' => $smtpData['pass'], 'port' => $smtpData['port']);
             //                print_r($smtpData); exit;
             $transport = new Zend_Mail_Transport_Smtp($smtpData['smtp'], $config);
             Zend_Mail::setDefaultTransport($transport);
             $html = new Zend_View();
             $html->setScriptPath(APPLICATION_PATH . '/modules/site/views/scripts/fale-conosco/');
             $html->data = $params;
             $emailBody = $html->render('email-body.phtml');
             $mail = new Zend_Mail('UTF-8');
             $configData = Gravi_Service_ImochatService::getSiteConfig();
             $config = $configData['config'];
             $mail->setBodyHtml($emailBody);
             $mail->setFrom($config['contact_email'], $params['nome']);
             //              Teste Local
             //                $mail->addTo('*****@*****.**', 'AG3');
             $mail->addTo($config['contact_email'], 'AG3');
             $assunto = isset($params['assunto']) ? $params['assunto'] : '';
             $subjects = array('contato' => 'SITE AG3 - ' . $assunto . ' - CONTATO PELO SITE', 'interesse' => 'SITE AG3 - ' . $assunto . ' - INTERESSE EM IMÓVEL', 'ligamos' => 'SITE AG3 - ' . $assunto . ' - LIGAMOS PARA VOCÊ');
             $subject = 'contato';
             if (isset($params['subject']) && isset($subjects[$params['subject']])) {
                 $subject = $params['subject'];
             }
             if (isset($params['curriculo'])) {
                 $filename = $params['curriculo-name'];
                 $ext = pathinfo($filename, PATHINFO_EXTENSION);
                 $allowed = array('doc', 'docx', 'pdf', 'xls', 'xlsx', 'odt', 'zip', 'rar');
                 if (!in_array($ext, $allowed)) {
                     $this->_helper->layout()->disableLayout();
                     $this->_helper->viewRenderer->setNoRender(true);
                     echo 'O currículo enviado está em um formato não aceito!';
                     return;
                 }
                 $file = explode(',', $params['curriculo']);
                 $base64 = $file[1];
                 $data = explode(':', $file[0]);
                 $mime = str_replace(';base64', '', $data[1]);
                 $at = $mail->createAttachment(base64_decode($base64));
                 $at->type = $mime;
                 $at->disposition = Zend_Mime::DISPOSITION_INLINE;
                 $at->encoding = Zend_Mime::ENCODING_BASE64;
                 $at->filename = $filename;
             }
             $location = Gravi_Geolocation::getVisitorLocation();
             $contactData = array('client_name' => $params['nome'], 'email' => $params['email'], 'phone' => $params['fone'], 'message' => $params['mensagem']);
             foreach (array('city' => 'city', 'region' => 'region', 'lat' => 'lat', 'lon' => 'lng', 'isp' => 'isp', 'query' => 'ip') as $info => $dest) {
                 !isset($location[$info]) || ($contactData[$dest] = $location[$info]);
             }
             if (in_array($params['subject'], array('interesse', 'oferta'))) {
                 $contactData['property_id'] = $params['imovel'];
                 Gravi_Service_ImochatService::SaveSiteOffer($contactData);
             } else {
                 Gravi_Service_ImochatService::SaveSiteContact($contactData);
             }
             $mail->setSubject($subjects[$subject]);
             $mail->send();
             $this->view->success = true;
             if ($this->_request->isXmlHttpRequest()) {
                 $this->_helper->layout()->disableLayout();
                 $this->_helper->viewRenderer->setNoRender(true);
                 echo 'Sua mensagem foi enviada. Obrigado!';
                 return;
             }
         } catch (Exception $e) {
             print_r($e->getMessage());
             exit;
         }
     }
 }
예제 #2
0
 public function savePropertyView($id)
 {
     $session = new Zend_Session_Namespace('imochat_token');
     $token = $session->data['access_token'];
     $this->restClient->setUrl($this->config['url']);
     $this->restClient->setUri('/rest/newpropertyview?token=' . $token);
     $this->restClient->addParam('property_id', $id);
     $this->restClient->setMethod('post');
     $http = new Zend_Controller_Request_Http();
     $ip = $http->getServer('REMOTE_ADDR');
     $location = Gravi_Geolocation::getVisitorLocation();
     $this->restClient->addParam('ip', $ip);
     foreach (array('city' => 'city', 'region' => 'region', 'lat' => 'lat', 'lon' => 'lng', 'isp' => 'isp') as $locationField => $destination) {
         !isset($location[$locationField]) || $this->restClient->addParam($destination, $location[$locationField]);
     }
     $this->restClient->execute();
 }