Ejemplo n.º 1
0
 function getreplyAction()
 {
     $this->_helper->layout->disableLayout();
     $result = null;
     if ($this->_request->isPost()) {
         $formData = $this->_request->getPost();
         $reportId = $formData['report_id'];
         $replyModel = new Reply();
         $reply = $replyModel->fetchRow('report_id = ' . $reportId);
         if (isset($reply)) {
             $result->content = $reply->content;
         }
         $this->_helper->json($result);
     }
 }
Ejemplo n.º 2
0
 function adminreportbatchreplysendAction()
 {
     $this->_helper->layout->setLayout("layout_admin");
     ini_set('display_errors', 1);
     $frontController = Zend_Controller_Front::getInstance();
     $frontController->throwExceptions(true);
     if ($this->_request->isPost()) {
         $form = new ReplyReportForm();
         $formData = $this->_request->getPost();
         if ($form->isValid($formData)) {
             //print_r($formData);die;
             $reportSource = $this->_request->getParam('report_source');
             // sms report:
             if ($reportSource == 'sms') {
                 $db = Zend_Registry::get('db');
                 $select = $db->select();
                 $select->from('consumer', '*');
                 $select->where('id = ?', $this->_request->getParam('consumer_id'));
                 $consumer = $db->fetchAll($select);
                 // 1.send reply
                 $msmStr = $form->getValue('message');
                 $len = strlen($msmStr);
                 for ($i = 0, $msmStrLen = 0; $i < $len; $i++, $msmStrLen++) {
                     if (ord($msmStr[$i]) >= 128) {
                         $i = $i + 2;
                     }
                 }
                 if ($msmStrLen > 70) {
                     $this->view->batchId = $formData['batch_id'];
                     $this->view->showMessage = 'Reply fail: The sms should be short then 70 characters.';
                     return;
                 }
                 include_once 'sms.inc.php';
                 $newclient = new SMS();
                 $apitype = 0;
                 $msg = iconv("UTF-8", "GB2312", $form->getValue('message'));
                 $respxml = $newclient->sendSMS($form->getValue('email'), $msg, date("Y-m-d H:i:s"), $apitype);
                 // 2.save reply
                 $replyModel = new Reply();
                 $reply = $replyModel->fetchRow('report_id = ' . $this->_request->getParam('report_id'));
                 //check reply condition!
                 if ($reply != null && $reply->status == 'SENT') {
                     $this->view->showMessage = "Reply fail: the reply has been sent!";
                     return;
                 }
                 if ($reply == null) {
                     $replyModel = new Reply();
                     $reply = $replyModel->createRow();
                 }
                 $currentTime = date("Y-m-d H:i:s");
                 $reply->date = $currentTime;
                 $reply->subject = $form->getValue('subject');
                 $reply->content = $form->getValue('message');
                 $reply->from = $config->smtp->report->mail->username;
                 $reply->campaign_id = $formData['campaign_id'];
                 $reply->report_id = $formData['report_id'];
                 $reply->to = $form->getValue('email');
                 $reply->status = 'SENT';
                 //2011-04-08 ham.bao separate the sessions with admin
                 $reply->admin_id = $this->_currentAdmin->id;
                 //$reply->usetime =$formData['usetime'];
                 $reply->save();
                 // 3.grade
                 $report_id = (int) $this->_request->getParam('report_id');
                 $this->saveReportReward($report_id, $form->getValue('grade'));
                 // 4.update notes for report
                 //$this->saveTags($report_id,$formData ['report_id']);
                 $this->saveTags($report_id, $formData['note']);
                 $this->view->batchId = $formData['batch_id'];
                 $this->updateBatchTotaltime($formData['batch_id'], $addtive);
                 $this->view->showMessage = $this->view->translate('Admin_Reply_the_report_successfully');
                 return;
             }
             // email report:
             //1. config
             $config = Zend_Registry::get('config');
             /* 
             $smtpSender = new Zend_Mail_Transport_Smtp(
             			$config->smtp->report->mail->server,
             			array(
             				'username'=> $config->smtp->report->mail->username,
             				'password'=> $config->smtp->report->mail->password,
             				'auth'=> $config->smtp->report->mail->auth,
             				'ssl' => $config->smtp->report->mail->ssl,
             			               			'port' => $config->smtp->report->mail->port));
             Zend_Mail::setDefaultTransport($smtpSender);
             $mail = new Zend_Mail('utf-8');
             */
             $db = Zend_Registry::get('db');
             $select = $db->select();
             $select->from('consumer', '*');
             $select->where('email = ?', $form->getValue('email'));
             $consumer = $db->fetchAll($select);
             if ($consumer[0] != null) {
                 /*
                 //2.get "Your story" from report
                 $reportId = $formData['report_id'];
                 				    	$reportModel = new Report();
                 				    	$report = $reportModel->find($reportId)->current();
                 				    	$config = Zend_Registry::get('config');
                 				    	$url_zh = $config->indicate2->home."/report/showAnswer/accessCode/".$report['accesscode']."/questionId/645";
                 $url_en = $config->indicate2->home."/report/showAnswer/accessCode/".$report['accesscode']."/questionId/707";
                 $contents = file_get_contents($url_zh).file_get_contents($url_en);
                 				    	$contents = trim($contents);
                 $contents = preg_replace('/\s(?=\s)/', '', $contents);
                 $contents = preg_replace('/[\n\r\t]/', ' ', $contents);
                 $contents = preg_replace('/&nbsp;/', '', $contents);	
                 preg_match_all ("|<div class.*answer_content.*>(.*)</[^>]+>|U", $contents, $out, PREG_PATTERN_ORDER);
                 
                 					    //3.create email and send
                 $emailSubject = $this->view->translate('Admin_Reply_WOM_Report_Subject');
                 if($consumer[0]['language_pref'] != null && $consumer[0]['language_pref'] == 'en'){
                 	$emailBody = $this->view->translate('Admin_Reply_WOM_Report_Body_en');
                 }else{
                 	$emailBody = $this->view->translate('Admin_Reply_WOM_Report_Body_zh');
                 }
                 
                 $stringChange = array(
                 	'?USERNAME?' => $consumer[0]['name'],
                 	'?YOURSTORY?' => $out[1][0],
                 	'?MYRESPONSE?' => $form->getValue('message'));
                 $emailBody = strtr($emailBody,$stringChange);
                 	
                 $langNamespace = new Zend_Session_Namespace('Lang');
                 	if($langNamespace->lang == 'en' || $langNamespace->lang == 'EN'){
                 		$mail->setSubject($emailSubject);
                 	}else{
                 		$mail->setSubject("=?UTF-8?B?".base64_encode($emailSubject)."?=");
                 	}
                 $mail->setBodyText($emailBody);
                 $mail->addTo($form->getValue('email'));
                 $mail->setFrom($config->smtp->report->mail->username, $this->view->translate('Wildfire'));
                 //send!
                 $mail->send();
                 */
                 //4.save reply
                 $replyModel = new Reply();
                 $reply = $replyModel->fetchRow('report_id = ' . $this->_request->getParam('report_id'));
                 //check reply condition!
                 if ($reply != null && $reply->status == 'SENT') {
                     $this->view->showMessage = "Reply fail: the reply has been sent!";
                     return;
                 }
                 if ($reply == null) {
                     $replyModel = new Reply();
                     $reply = $replyModel->createRow();
                 }
                 $currentTime = date("Y-m-d H:i:s");
                 $reply->date = $currentTime;
                 $reply->subject = $form->getValue('subject');
                 $reply->content = $form->getValue('message');
                 $reply->from = $config->smtp->report->mail->username;
                 $reply->campaign_id = $formData['campaign_id'];
                 $reply->report_id = $formData['report_id'];
                 $reply->to = $form->getValue('email');
                 $reply->status = 'SENT';
                 //2011-04-08 ham.bao separate the sessions with admin
                 $reply->admin_id = $this->_currentAdmin->id;
                 $reply->usetime = $form->getValue('usetime');
                 $reply->save();
                 // 5.grade
                 $report_id = (int) $this->_request->getParam('report_id');
                 $this->saveReportReward($report_id, $form->getValue('grade'));
                 // 6.update notes for report
                 $this->saveTags($report_id, $formData['note']);
                 // 7.update batch reply time
                 $addtive = $addtive = $formData['usetime'] - $reply->usetime;
                 $this->updateBatchTotaltime($formData['batch_id'], $addtive);
                 $this->view->showMessage = $this->view->translate('Admin_Reply_the_report_successfully');
                 //2.get "Your story" from report
                 $reportId = $formData['report_id'];
                 $reportModel = new Report();
                 $report = $reportModel->find($reportId)->current();
                 $config = Zend_Registry::get('config');
                 $url_zh = $config->indicate2->home . "/report/showAnswer/accessCode/" . $report['accesscode'] . "/questionId/2293";
                 // $url_zh = $config->indicate2->home."/report/showAnswer/accessCode/".$report['accesscode']."/questionId/645";
                 $url_en = $config->indicate2->home . "/report/showAnswer/accessCode/" . $report['accesscode'] . "/questionId/707";
                 $url_other = $config->indicate2->home . "/report/showAnswer/accessCode/" . $report['accesscode'] . "/questionId/77";
                 $contents = file_get_contents($url_zh) . file_get_contents($url_en) . file_get_contents($url_other);
                 $contents = trim($contents);
                 $contents = preg_replace('/\\s(?=\\s)/', '', $contents);
                 $contents = preg_replace('/[\\n\\r\\t]/', ' ', $contents);
                 $contents = preg_replace('/&nbsp;/', '', $contents);
                 preg_match_all("|<div class.*answer_content.*>(.*)</[^>]+>|U", $contents, $out, PREG_PATTERN_ORDER);
                 //3.create email and send
                 $smtpSender = new Zend_Mail_Transport_Smtp($config->smtp->report->mail->server, array('username' => $config->smtp->report->mail->username, 'password' => $config->smtp->report->mail->password, 'auth' => $config->smtp->report->mail->auth, 'ssl' => $config->smtp->report->mail->ssl, 'port' => $config->smtp->report->mail->port));
                 Zend_Mail::setDefaultTransport($smtpSender);
                 $mail = new Zend_Mail('utf-8');
                 $emailSubject = $this->view->translate('Admin_Reply_WOM_Report_Subject');
                 if ($consumer[0]['language_pref'] != null && $consumer[0]['language_pref'] == 'en') {
                     $emailBody = $this->view->translate('Admin_Reply_WOM_Report_Body_en');
                 } else {
                     $emailBody = $this->view->translate('Admin_Reply_WOM_Report_Body_zh');
                 }
                 $stringChange = array('?USERNAME?' => $consumer[0]['name'], '?YOURSTORY?' => $out[1][0], '?MYRESPONSE?' => $form->getValue('message'));
                 $emailBody = strtr($emailBody, $stringChange);
                 $langNamespace = new Zend_Session_Namespace('Lang');
                 if ($langNamespace->lang == 'en' || $langNamespace->lang == 'EN') {
                     $mail->setSubject($emailSubject);
                 } else {
                     $mail->setSubject("=?UTF-8?B?" . base64_encode($emailSubject) . "?=");
                 }
                 $mail->setBodyText($emailBody);
                 $mail->addTo($form->getValue('email'));
                 $mail->setFrom($config->smtp->report->mail->username, $this->view->translate('Wildfire'));
                 //send!
                 $mail->send();
                 $this->view->batchId = $formData['batch_id'];
                 $this->view->showMessage = $this->view->translate('Admin_Reply_the_report_successfully');
             } else {
                 $this->view->showMessage = "Reply fail: this email doesn't exist in DB!";
             }
         } else {
             $this->view->showMessage = 'Reply fail: please input the right data!';
         }
     } else {
         $this->view->showMessage = "err!";
     }
 }
Ejemplo n.º 3
0
 function ajaxreportAction()
 {
     $this->_helper->layout->disableLayout();
     $config = Zend_Registry::get('config');
     $db = Zend_Registry::get('db');
     $select = $db->select();
     //tag for report
     $selectTags = $db->select();
     $selectTags->from('tags', array('name', 'id', 'sort'))->where("module = 'REPORT'")->order('sort');
     $this->view->tags = $db->fetchAll($selectTags);
     //organize tag list
     $tagHash = array();
     foreach ($this->view->tags as $tag) {
         $tagHash[$tag['id']] = $tag['name'];
     }
     // get reports
     $select->from('report', array('id', 'accesscode', 'create_date'))->where('consumer_id = ?', $this->_request->getParam('uid'))->order('create_date desc');
     $oldreportArray = $db->fetchAll($select);
     $replyModel = new Reply();
     $this->view->oldreports = array();
     $i = 1;
     foreach ($oldreportArray as $oldreport) {
         $oldTags = '';
         $this->view->oldreports[$oldreport["accesscode"]]['url'] = $config->indicate2->home . "/report/showAnswer/accessCode/" . $oldreport["accesscode"];
         $reply = $replyModel->fetchRow('report_id = ' . $oldreport['id']);
         if ($reply['admin_id'] != null) {
             $adminModel = new Admin();
             $admin = $adminModel->fetchRow('id = ' . $reply['admin_id']);
             $adminname = $admin['name'];
         } else {
             $adminname = '';
         }
         $this->view->oldreports[$oldreport["accesscode"]]['id'] = $oldreport['id'];
         $this->view->oldreports[$oldreport["accesscode"]]['create_date'] = $oldreport['create_date'];
         $this->view->oldreports[$oldreport["accesscode"]]['adminname'] = $adminname;
         $this->view->oldreports[$oldreport["accesscode"]]['replydate'] = $reply['date'];
         $this->view->oldreports[$oldreport["accesscode"]]['replycontent'] = $reply['content'];
         //tag
         $oldreportTagSelect = $db->select();
         $oldreportTagSelect->from('report_tag', 'tag_id')->where('report_tag.report_id = ?', $oldreport['id']);
         $oldreportTag = $db->fetchAll($oldreportTagSelect);
         foreach ($oldreportTag as $tag) {
             $oldTags .= $this->view->translate('Report_Tag_' . $tagHash[$tag['tag_id']]) . " ";
         }
         $this->view->oldreports[$oldreport["accesscode"]]['tag'] = $oldTags;
     }
 }