Example #1
0
 function showtypeAction()
 {
     $this->_helper->layout->disableLayout();
     $a_array = array(7130 => 1, 7156 => 1, 5813 => 1, 7169 => 1, 7170 => 1, 7171 => 1, 7172 => 1, 7228 => 1, 7246 => 1);
     $b_array = array(7128 => 1, 7140 => 1, 7141 => 1, 7151 => -2, 7152 => -1, 7153 => 0, 7154 => 1, 7155 => 2);
     $c_array = array(7158 => 1, 5815 => 1, 5816 => 1, 5817 => 1);
     $d_array = array(7246 => 1, 7177 => 3, 7205 => 1, 7228 => 1);
     $e_array = array(7133 => 1, 7181 => 1, 7182 => 1, 7188 => 1, 7189 => 1, 7190 => 1, 7191 => 1, 7192 => 1, 7193 => 1, 7199 => 1, 7200 => 1, 7201 => 1, 7202 => 1, 7203 => 1, 7204 => 1);
     $f_array = array(7209 => 2, 7210 => 1, 7215 => 2, 7216 => 1, 7233 => 1);
     $score_array = array('A' => 0, 'B' => 0, 'C' => 0, 'D' => 0, 'E' => 0, 'F' => 0);
     $accessCode = $this->_request->getParam('accessCode');
     $indicate2Connect = new Indicate2_Connect();
     $response = $indicate2Connect->getAnswerSetForAccessCode(array($accessCode));
     if (isset($response->AnswerSetType)) {
         if (isset($response->AnswerSetType->AnswerType)) {
             if (is_array($response->AnswerSetType->AnswerType)) {
                 foreach ($response->AnswerSetType->AnswerType as $answer) {
                     if (is_array($answer->AnswerText)) {
                         foreach ($answer->AnswerText as $answerText) {
                             $key = base64_decode($answerText);
                             if (is_numeric($key)) {
                                 $this->calculate_score(&$score_array, $key, $a_array, 'A');
                                 $this->calculate_score(&$score_array, $key, $b_array, 'B');
                                 $this->calculate_score(&$score_array, $key, $c_array, 'C');
                                 $this->calculate_score(&$score_array, $key, $d_array, 'D');
                                 $this->calculate_score(&$score_array, $key, $e_array, 'E');
                                 $this->calculate_score(&$score_array, $key, $f_array, 'F');
                             }
                         }
                     } else {
                         $key = base64_decode($answer->AnswerText);
                         if (is_numeric($key)) {
                             $this->calculate_score(&$score_array, $key, $a_array, 'A');
                             $this->calculate_score(&$score_array, $key, $b_array, 'B');
                             $this->calculate_score(&$score_array, $key, $c_array, 'C');
                             $this->calculate_score(&$score_array, $key, $d_array, 'D');
                             $this->calculate_score(&$score_array, $key, $e_array, 'E');
                             $this->calculate_score(&$score_array, $key, $f_array, 'F');
                         }
                     }
                 }
             }
         }
     } else {
     }
     $max = 0;
     foreach ($score_array as $key => $value) {
         if ($value > $max) {
             $max = $value;
         }
     }
     if ($max < 3) {
         $this->view->type = 'C';
     } else {
         $this->view->type = array_search($max, $score_array);
     }
     $this->view->accessCode = $accessCode;
 }
 function admingetaccesscodeAction()
 {
     $surveyId = (int) $this->_request->getParam('surveyId');
     //$consumer = $this->_currentUser;
     $email = $this->_request->getParam('email');
     $indicate2Connect = new Indicate2_Connect();
     $accesscode = $indicate2Connect->createParticipation($email, $surveyId);
     $this->_helper->layout->disableLayout();
     $this->_helper->json($accesscode);
 }
Example #3
0
 public function testAction()
 {
     // post
     if ($this->_request->isPost()) {
         $formData = $this->_request->getPost();
         //get survey
         $surveyId = $this->view->surveyId = $formData['survey_id'];
         if ($formData['language'] == 'en') {
             $surveyId = $formData['survey_' . $surveyId . '_en'];
         }
         $db = Zend_Registry::get('db');
         $selectEmail = $db->select();
         $selectEmail->from('consumer', array('email', 'province', 'city', 'address1', 'phone'))->join('poll_participation', 'poll_participation.consumer_id = consumer.id', null)->join('profile_survey', 'profile_survey.id = poll_participation.poll_id', null)->joinLeft('consumer_extra_info', 'consumer_extra_info.consumer_id = consumer.id')->limit(0);
         if ($formData['language'] == 'en') {
             $selectEmail->where("language_pref = 'en'")->where('profile_survey.i2_survey_id_en = ?', $surveyId);
         } else {
             $selectEmail->where("language_pref != 'en'")->where('profile_survey.i2_survey_id = ?', $surveyId);
         }
         $emailArray = $db->fetchAll($selectEmail);
         $emailList = array();
         $this->view->consumerExtraInfoArray = array();
         foreach ($emailArray as $email) {
             array_push($emailList, $email['email']);
             $this->view->consumerExtraInfoArray[$email['email']] = array($email['province'], $email['city'], $email['address1'], $email['phone'], $email['gender'], $email['birthdate'], $email['profession'], $email['education'], $email['have_children'], $email['children_birth_year'], $email['income'], $email['online_shopping'], $email['use_extra_bonus_for']);
         }
         if (count($emailList) > 0) {
             $indicate2Connect = new Indicate2_Connect();
             $response = $indicate2Connect->getAnswerSetForParticipant($surveyId, $emailList);
             $this->view->surveyQuestionArray = $response->QuestionType;
             $this->view->surveyArray = $response->AnswerSetType;
         } else {
             $this->view->surveyQuestionArray = null;
             $this->view->surveyArray = null;
         }
         //			Zend_Debug::dump($response);
         //			return;
         $this->_helper->layout->disableLayout();
     }
 }
 function acceptinvitationAction()
 {
     if ($this->autoAccountBinding() == false) {
         return;
     }
     $consumer = $this->_currentUser;
     $campaignModel = new Campaign();
     $campaign_id = (int) $this->_request->getParam('campaign_id', 0);
     $campaign = $campaignModel->fetchRow("id=" . $campaign_id);
     $surveyId = $campaign->pre_campaign_survey;
     $indicate2Connect = new Indicate2_Connect();
     $accesscode = $indicate2Connect->createParticipation($consumer['email'], $surveyId);
     $this->view->survey_id = $surveyId;
     $this->view->campaign_name = $campaign->name;
     $this->view->campaign_id = $campaign_id;
     $this->view->accesscode = $accesscode;
     $config = Zend_Registry::get('config');
     $this->view->filloutPage = $config->indicate2->home . "/core/" . $accesscode . "/theme/wildfire/callback/acceptinvitationdo";
 }
 function thankyouAction()
 {
     $this->view->activeTab = 'Polls';
     $this->view->title = $this->view->title = $this->view->translate("Wildfire") . " - " . $this->view->translate("Thanks_For_Poll");
     $consumer = $this->_currentUser;
     $id = (int) $this->_request->getParam('survey', 0);
     $profileSurveyModel = new ProfileSurvey();
     $profileSurvey = $profileSurveyModel->fetchRow("i2_survey_id =" . $id . " or " . "i2_survey_id_en =" . $id);
     // $this->view->point = $profileSurvey->points;
     //check history to prevent multiple participation
     $db = Zend_Registry::get('db');
     $select1 = $db->select();
     $select1->from("poll_participation", "count(*)");
     $select1->where("poll_participation.poll_id = ?", $profileSurvey->id);
     $select1->where("poll_participation.consumer_id = ?", $consumer->id);
     $participationCount = $db->fetchOne($select1);
     if ($participationCount == 0) {
         // check ws
         $indicate2Connect = new Indicate2_Connect();
         $ids = array($id);
         $wsResult = $indicate2Connect->getAnswerSetCount($consumer->email, $ids);
         // Zend_Debug::dump($wsResult."------------".$profileSurvey->points);die;
         if ($wsResult > 0) {
             // add poll participation
             $currentTime = date("Y-m-d H:i:s");
             $pollParticipationModel = new PollParticipation();
             $pollParticipation = $pollParticipationModel->createRow();
             $pollParticipation->poll_id = $profileSurvey->id;
             $pollParticipation->consumer_id = $consumer->id;
             $pollParticipation->date = $currentTime;
             $pollParticipation->save();
             // add points
             $pointRecordModel = new RewardPointTransactionRecord();
             $point = $pointRecordModel->createRow();
             $point->consumer_id = $consumer->id;
             $point->transaction_id = 3;
             $point->date = $currentTime;
             $point->point_amount = $profileSurvey->points;
             $point->save();
             //2011-05-13 change the rank of consumer
             $rankModel = new Rank();
             $rankModel->changeConsumerRank($consumer->id);
             $this->view->point = $point->point_amount;
         } else {
             // add poll participation
             $currentTime = date("Y-m-d H:i:s");
             $pollParticipationModel = new PollParticipation();
             $pollParticipation = $pollParticipationModel->createRow();
             $pollParticipation->poll_id = $profileSurvey->id;
             $pollParticipation->consumer_id = $consumer->id;
             $pollParticipation->date = $currentTime;
             $pollParticipation->save();
             // add points
             $pointRecordModel = new RewardPointTransactionRecord();
             $point = $pointRecordModel->createRow();
             $point->consumer_id = $consumer->id;
             $point->transaction_id = 3;
             $point->date = $currentTime;
             $point->point_amount = $profileSurvey->points;
             $point->save();
             //2011-05-13 change the rank of consumer
             $rankModel = new Rank();
             $rankModel->changeConsumerRank($consumer->id);
             $this->view->point = $point->point_amount;
         }
     }
 }
 public function admindownloadsurveyAction()
 {
     // post
     if ($this->_request->isPost()) {
         $formData = $this->_request->getPost();
         //get survey
         $surveyId = $this->view->surveyId = $formData['survey_id'];
         if ($formData['language'] == 'en') {
             $surveyId = $formData['survey_' . $surveyId . '_en'];
         }
         $db = Zend_Registry::get('db');
         $selectEmail = $db->select();
         $selectEmail->from('consumer', array('email', 'province', 'city', 'address1', 'phone'))->join('poll_participation', 'poll_participation.consumer_id = consumer.id', null)->join('profile_survey', 'profile_survey.id = poll_participation.poll_id', null)->joinLeft('consumer_extra_info', 'consumer_extra_info.consumer_id = consumer.id')->limit(0);
         if ($formData['language'] == 'en') {
             $selectEmail->where("language_pref = 'en'")->where('profile_survey.i2_survey_id_en = ?', $surveyId);
         } else {
             $selectEmail->where("language_pref != 'en'")->where('profile_survey.i2_survey_id = ?', $surveyId);
         }
         $emailArray = $db->fetchAll($selectEmail);
         $emailList = array();
         $this->view->consumerExtraInfoArray = array();
         foreach ($emailArray as $email) {
             array_push($emailList, $email['email']);
             $this->view->consumerExtraInfoArray[$email['email']] = array($email['province'], $email['city'], $email['address1'], $email['phone'], $email['gender'], $email['birthdate'], $email['profession'], $email['education'], $email['have_children'], $email['children_birth_year'], $email['income'], $email['online_shopping'], $email['use_extra_bonus_for']);
         }
         if (count($emailList) > 0) {
             $indicate2Connect = new Indicate2_Connect();
             $response = $indicate2Connect->getAnswerSetForParticipant($surveyId, $emailList);
             $this->view->surveyQuestionArray = $response->QuestionType;
             $this->view->surveyArray = $response->AnswerSetType;
         } else {
             $this->view->surveyQuestionArray = null;
             $this->view->surveyArray = null;
         }
         //			Zend_Debug::dump($response);
         //			return;
         $this->_helper->layout->disableLayout();
         //download...
         header("Content-type:application/vnd.ms-excel; charset=gb18030");
         header("Content-Disposition:filename=survey_" . $this->view->surveyId . "_" . date("Y-m-d H-i-s") . ".xls");
         $tag = array();
         $i = -1;
         // print qestions:
         echo "Email" . "\t";
         foreach ($this->view->surveyQuestionArray as $surveyQuestion) {
             echo iconv("UTF-8", "gb18030", $surveyQuestion->QuestionText) . "\t";
             if (isset($surveyQuestion->SelectionQuestionOptionType) && is_array($surveyQuestion->SelectionQuestionOptionType) && !empty($surveyQuestion->SelectionQuestionOptionType)) {
                 for ($temp = 0; $temp < count($surveyQuestion->SelectionQuestionOptionType) - 1; $temp++) {
                     echo "\t";
                 }
             }
         }
         echo "\n";
         $textQuestionArray = array();
         echo "Email" . "\t";
         foreach ($this->view->surveyQuestionArray as $surveyQuestion) {
             if (isset($surveyQuestion->SelectionQuestionOptionType) && is_array($surveyQuestion->SelectionQuestionOptionType) && !empty($surveyQuestion->SelectionQuestionOptionType)) {
                 foreach ($surveyQuestion->SelectionQuestionOptionType as $selectionQuestionOptionTypeTemp) {
                     echo iconv("UTF-8", "gb18030", $selectionQuestionOptionTypeTemp->OptionText) . "\t";
                     $tag[++$i] = $selectionQuestionOptionTypeTemp->OptionId;
                 }
             } else {
                 echo iconv("UTF-8", "gb18030", $surveyQuestion->QuestionText) . "\t";
                 $tag[++$i] = $surveyQuestion->QuestionId;
                 $textQuestionArray[$surveyQuestion->QuestionId] = 1;
             }
         }
         echo "province" . "\t";
         echo "city" . "\t";
         echo "address1" . "\t";
         echo "phone" . "\t";
         echo "gender" . "\t";
         echo "birthdate" . "\t";
         echo "profession" . "\t";
         echo "education" . "\t";
         echo "have_children" . "\t";
         echo "children_birth_year" . "\t";
         echo "income" . "\t";
         echo "online_shopping" . "\t";
         echo "use_extra_bonus_for" . "\t";
         echo "\n";
         // print answers:
         // include more than one survey
         if (isset($this->view->surveyArray) && is_array($this->view->surveyArray) && !empty($this->view->surveyArray)) {
             foreach ($this->view->surveyArray as $surveys) {
                 $temp = array();
                 echo $surveys->ParticipantEmail . "\t";
                 // more than one answer in the survey
                 if (isset($surveys->AnswerType) && is_array($surveys->AnswerType) && !empty($surveys->AnswerType)) {
                     foreach ($surveys->AnswerType as $question) {
                         if (isset($question->AnswerText) && is_array($question->AnswerText) && !empty($question->AnswerText)) {
                             foreach ($question->AnswerText as $text) {
                                 $temp[$text] = "1\t";
                             }
                         } else {
                             if (array_key_exists($question->QuestionId, $textQuestionArray)) {
                                 $temp[$question->QuestionId] = isset($question->AnswerText) ? iconv("UTF-8", "gb18030", preg_replace('/[\\n\\r\\t]/', ' ', base64_decode($question->AnswerText))) . "\t" : "\t";
                             } else {
                                 $temp[iconv("UTF-8", "gb18030", preg_replace('/[\\n\\r\\t]/', ' ', base64_decode($question->AnswerText)))] = "1\t";
                             }
                         }
                     }
                 } else {
                     // only one answer in the survey
                     if (isset($surveys->AnswerType->AnswerText) && is_array($surveys->AnswerType->AnswerText) && !empty($surveys->AnswerType->AnswerText)) {
                         foreach ($surveys->AnswerType->AnswerText as $text) {
                             $temp[$text] = "1\t";
                         }
                     } else {
                         if (array_key_exists($surveys->AnswerType->QuestionId, $textQuestionArray)) {
                             $temp[$surveys->AnswerType->QuestionId] = isset($surveys->AnswerType->AnswerText) ? iconv("UTF-8", "gb18030", preg_replace('/[\\n\\r\\t]/', ' ', base64_decode($surveys->AnswerType->AnswerText))) . "\t" : "\t";
                         } else {
                             $temp[iconv("UTF-8", "gb18030", preg_replace('/[\\n\\r\\t]/', ' ', base64_decode($surveys->AnswerType->AnswerText)))] = "1\t";
                         }
                     }
                 }
                 // print
                 for ($i = 0; $i < count($tag); $i++) {
                     echo isset($temp[$tag[$i]]) ? $temp[$tag[$i]] : "\t";
                 }
                 //
                 foreach ($this->view->consumerExtraInfoArray[$surveys->ParticipantEmail] as $consumerExtraInfo) {
                     echo isset($consumerExtraInfo) ? iconv("UTF-8", "gb18030", preg_replace('/[\\n\\r\\t]/', ' ', $consumerExtraInfo)) . "\t" : "\t";
                 }
                 echo "\n";
             }
         } else {
             // include only one survey
             $survey = $this->view->surveyArray;
             echo $surveys->ParticipantEmail . "\t";
             // more than one answer in the survey
             if (isset($survey->AnswerType) && is_array($survey->AnswerType) && !empty($survey->AnswerType)) {
                 foreach ($survey->AnswerType as $question) {
                     if (isset($question->AnswerText) && is_array($question->AnswerText) && !empty($question->AnswerText)) {
                         foreach ($question->AnswerText as $text) {
                             $temp[$text] = "1\t";
                         }
                     } else {
                         if (array_key_exists($question->QuestionId, $textQuestionArray)) {
                             $temp[$question->QuestionId] = isset($question->AnswerText) ? iconv("UTF-8", "gb18030", preg_replace('/[\\n\\r\\t]/', ' ', base64_decode($question->AnswerText))) . "\t" : "\t";
                         } else {
                             $temp[iconv("UTF-8", "gb18030", preg_replace('/[\\n\\r\\t]/', ' ', base64_decode($question->AnswerText)))] = "1\t";
                         }
                     }
                 }
             } else {
                 // only one answer in the survey
                 if (isset($survey->AnswerType->AnswerText) && is_array($survey->AnswerType->AnswerText) && !empty($survey->AnswerType->AnswerText)) {
                     foreach ($surveys->AnswerType->AnswerText as $text) {
                         $temp[$text] = "1\t";
                     }
                 } else {
                     if (array_key_exists($surveys->AnswerType->QuestionId, $textQuestionArray)) {
                         $temp[$surveys->AnswerType->QuestionId] = isset($surveys->AnswerType->AnswerText) ? iconv("UTF-8", "gb18030", preg_replace('/[\\n\\r\\t]/', ' ', base64_decode($surveys->AnswerType->AnswerText))) . "\t" : "\t";
                     } else {
                         $temp[iconv("UTF-8", "gb18030", preg_replace('/[\\n\\r\\t]/', ' ', base64_decode($surveys->AnswerType->AnswerText)))] = "1\t";
                     }
                 }
             }
             // print
             for ($i = 0; $i < count($tag); $i++) {
                 echo isset($temp[$tag[$i]]) ? $temp[$tag[$i]] : "\t";
             }
             //
             foreach ($this->view->consumerExtraInfoArray[$surveys->ParticipantEmail] as $consumerExtraInfo) {
                 echo isset($consumerExtraInfo) ? iconv("UTF-8", "gb18030", preg_replace('/[\\n\\r\\t]/', ' ', $consumerExtraInfo)) . "\t" : "\t";
             }
             echo "\n";
         }
     }
 }
 function postcampaignAction()
 {
     $this->view->activeTab = 'Campaign';
     $consumer = $this->_currentUser;
     $campaignModel = new Campaign();
     $id = (int) $this->_request->getParam('id', 0);
     $campaign = $campaignModel->fetchRow("id=" . $id);
     $this->view->title = $this->view->title = $this->view->translate("Wildfire") . " - " . $campaign->name;
     $this->view->name = $campaign->name;
     $langNamespace = new Zend_Session_Namespace('Lang');
     $lang = $langNamespace->lang;
     if ($lang == 'en') {
         $surveyId = $campaign->post_campaign_survey_en;
     } else {
         $surveyId = $campaign->post_campaign_survey;
     }
     //check static file
     $testEnv = Zend_Registry::get('testEnv');
     $file = "./surveys/" . $surveyId . ".phtml";
     // if static file not exist, go to the normal flow
     if ($testEnv != 0 || file_exists($file) == false) {
         // connect to webservice, get the page
         $indicate2Connect = new Indicate2_Connect();
         $accesscode = $indicate2Connect->createParticipation($consumer->email, $surveyId);
         $config = Zend_Registry::get('config');
         $this->view->filloutPage = $config->indicate2->home . "/c/" . $accesscode . "/theme/wildfire";
         if ($testEnv == 0) {
             //save the page to static file
             if ($data = @file_get_contents($this->view->filloutPage)) {
                 //                Zend_Debug::dump($data);
                 set_time_limit(10);
                 ignore_user_abort(true);
                 Zend_Debug::dump(file_put_contents($file, $data));
             } else {
                 Zend_Debug::dump('Get remote page error!');
             }
         }
     } else {
         $this->view->file = $file;
         $this->view->surveyId = $surveyId;
     }
     $this->view->includeCrystalCss = true;
 }
Example #8
0
 function adminreportAction()
 {
     $this->_helper->layout->setLayout("layout_admin");
     $sms_id = (int) $this->_request->getParam('sms_id');
     $smsSql = "select b.* from spark_sms as a, spark_sms as b where a.id=" . $sms_id . " and b.consumer_id=a.consumer_id and b.id-a.id>-5 and b.id-a.id<5 order by b.id";
     $db = Zend_Registry::get('db');
     $rs = $db->fetchAll($smsSql);
     $sms = '';
     $consumer_id = 0;
     $smsIds = array();
     foreach ($rs as $row) {
         array_push($smsIds, $row['id']);
         $sms .= $row['text'];
         $consumer_id = $row['consumer_id'];
     }
     //update sms state
     $ids = implode(",", $smsIds);
     //Zend_Debug::dump($ids);
     $updateSql = $db->prepare("update spark_sms set state='Reported' where id in (" . $ids . ")");
     $updateSql->execute();
     $campaign_id = (int) $this->_request->getParam('cam_id');
     //whether participate in the campaign
     $campaigninvitationModel = new CampaignInvitation();
     $campaigninvitation = $campaigninvitationModel->fetchRow('campaign_id = ' . $campaign_id . ' and consumer_id' . ' =' . $consumer_id);
     if ($campaigninvitation == null) {
         $this->_helper->redirector('index', 'home');
     }
     //get lang
     $consumerModel = new Consumer();
     $consumer = $consumerModel->fetchRow("id=" . $consumer_id);
     //get i2_survey_id
     $campaignModel = new Campaign();
     $campaign = $campaignModel->fetchRow("id=" . $campaign_id);
     $langNamespace = new Zend_Session_Namespace('Lang');
     $lang = $langNamespace->lang;
     if ($consumer->language_pref == 'en') {
         $surveyId = $campaign->i2_survey_id_en;
     } else {
         $surveyId = $campaign->i2_survey_id;
     }
     $this->view->campaing_name = $campaign->name;
     $indicate2Connect = new Indicate2_Connect();
     $accesscode = $indicate2Connect->createParticipation($consumer->email, $surveyId);
     //save list in session
     $reportNamespace = new Zend_Session_Namespace('AgentReports');
     $reportNamespace->{$accesscode} = $consumer_id;
     $source = $accesscode . "_source";
     $reportNamespace->{$source} = "sms";
     $config = Zend_Registry::get('config');
     $this->view->filloutPage = $config->indicate2->home . "/c/" . $accesscode . "/theme/wildfire";
     $this->view->id = $consumer->id;
     $this->view->name = $consumer->name;
     $this->view->sms = $sms;
     $this->view->includeCrystalCss = true;
 }
 public function clientimpressionAction()
 {
     ini_set('display_errors', 1);
     $frontController = Zend_Controller_Front::getInstance();
     $frontController->throwExceptions(true);
     // filter!
     if (!$this->clientdashboardfilter()) {
         return;
     }
     $this->view->activeTab = 'clientimpression';
     include 'open-flash-chart.php';
     $request = $this->getRequest();
     if ($request->isPost()) {
         $formData = $request->getPost();
         $campaign_id = $formData['campaign_id'];
     } else {
         $campaign_id = $request->getParam('id');
     }
     $this->_helper->layout->setLayout($this->getCampaignTemplate($campaign_id));
     $this->view->campaign_id = $campaign_id;
     // get date from db
     $db = Zend_Registry::get('db');
     $select = $db->select();
     $select->from('report', array('left(create_date,10) as date', 'accesscode'))->where('report.campaign_id = ?', $campaign_id)->where('report.state = "APPROVED"')->order('date');
     $results = $db->fetchAll($select);
     $accesscodeDbMatchArray = array();
     foreach ($results as $result) {
         $accesscodeDbMatchArray[$result['accesscode']] = $result['date'];
     }
     $accesscodeArray = array_keys($accesscodeDbMatchArray);
     $campaignModel = new Campaign();
     $campaign = $campaignModel->fetchRow('id = ' . $campaign_id);
     // get impression value from ws
     $db = Zend_Registry::get('db');
     $select = $db->select();
     $select->from('dashboard_mapping');
     $select->where('survey_id = ?', $campaign->i2_survey_id);
     $select->where('mark="FRIENDS"');
     $mappings = $db->fetchRow($select);
     $indicate2Connect = new Indicate2_Connect();
     $response = $indicate2Connect->getAnswerSetForSurvey(array($campaign->i2_survey_id, $campaign->i2_survey_id_en), null, array(array('ContextIndex' => $mappings['context_index'], 'QuestionIndex' => $mappings['question_index'])), 0);
     //        Zend_Debug::dump($mappings);die;
     $optionArray = array();
     if (isset($response->QuestionType) && is_array($response->QuestionType)) {
         foreach ($response->QuestionType as $questionType) {
             foreach ($questionType->SelectionQuestionOptionType as $optionObject) {
                 //get min value, like '11-15' = 11
                 $optionArray[$optionObject->OptionId] = (int) $optionObject->OptionText;
             }
         }
     } else {
         if (isset($response->QuestionType->SelectionQuestionOptionType)) {
             foreach ($response->QuestionType->SelectionQuestionOptionType as $optionObject) {
                 //get min value, like '11-15' = 11
                 if ($optionObject->OptionText == '>=10') {
                     $optionArray[$optionObject->OptionId] = 10;
                 }
                 $optionArray[$optionObject->OptionId] = (int) $optionObject->OptionText;
             }
         }
     }
     $answerArray = array();
     $i = 0;
     if (isset($response->AnswerSetType)) {
         foreach ($response->AnswerSetType as $answerObject) {
             $answerArray[$i++] = array($answerObject->AccessCode, iconv("UTF-8", "gb18030", preg_replace('/[\\n\\r\\t]/', ' ', base64_decode($answerObject->AnswerType->AnswerText))));
         }
     }
     // create x axis date value (endDate = expireDate/now + 10 days)
     $this->view->startDate = $startDate = date("Y-m-d", strtotime($campaign->create_date));
     if (strtotime($campaign->expire_date) > strtotime(date("Y-m-d"))) {
         $this->view->xmax = $endDate = date("Y-m-d", strtotime("+10 days", strtotime(date("Y-m-d"))));
     } else {
         $this->view->xmax = $endDate = date("Y-m-d", strtotime("+10 days", strtotime($campaign->expire_date)));
     }
     if ($request->isPost()) {
         $formData = $request->getPost();
         $this->view->xmax = $endDate = $formData['x_max'];
     }
     $resultArray = array();
     $xDateArrayLength = 0;
     while (1) {
         $resultArray[$startDate] = 0;
         $startDate = date("Y-m-d", strtotime("+1 days", strtotime($startDate)));
         $xDateArrayLength++;
         if ($startDate == $endDate) {
             $resultArray[$startDate] = 0;
             $xDateArrayLength++;
             break;
         }
     }
     //var_dump($resultArray);die;
     // set sparks initial impressions for each campaign, it should be added if a new campaign is lanuched!
     switch ($campaign_id) {
         case '1':
             $staticsparks = array(50, 110);
             break;
         case '2':
             $staticsparks = array(50, 150, 250, 400, 450);
             break;
         case '3':
             $staticsparks = array(100, 350, 750, 1200, 1500);
             break;
         case '4':
             $staticsparks = array(50, 200, 250);
             break;
         case '5':
             $staticsparks = array(50, 150);
             break;
         case '6':
             $staticsparks = array(50, 150, 350, 500, 900, 1700, 2300, 2500);
             break;
         case '7':
             $staticsparks = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 50, 150, 350, 500, 900, 1038);
             break;
         case '8':
             $staticsparks = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 150, 300, 450, 600, 750, 900, 1000);
             break;
         case '9':
             $staticsparks = array(0, 0, 0, 150, 300, 450, 600, 750, 900, 1000);
             break;
         case '10':
             $staticsparks = array(0, 0, 0, 0, 0, 0, 0, 0, 150, 300, 450, 600, 750, 900, 1000);
             break;
         case '13':
             $staticsparks = array(0, 0, 0, 0, 0, 0, 50, 100, 150, 300, 450, 600, 750, 900, 1200);
             break;
         default:
             break;
     }
     for ($temp = count($staticsparks); $temp < $xDateArrayLength; $temp++) {
         $staticsparks[$temp] = $staticsparks[$temp - 1];
     }
     // set everyday impression by using ws data
     foreach ($answerArray as $answer) {
         if (!isset($accesscodeDbMatchArray[$answer[0]])) {
             continue;
         }
         if (date("Y-m-d", strtotime($accesscodeDbMatchArray[$answer[0]])) > date("Y-m-d", strtotime($this->view->xmax))) {
             continue;
         }
         if (!array_key_exists($accesscodeDbMatchArray[$answer[0]], $resultArray)) {
             $resultArray[$accesscodeDbMatchArray[$answer[0]]] = $optionArray[$answer[1]];
         } else {
             $resultArray[$accesscodeDbMatchArray[$answer[0]]] += $optionArray[$answer[1]];
         }
     }
     //Zend_Debug::dump($optionArray);
     //Zend_Debug::dump($resultArray);
     //Zend_Debug::dump($answerArray);
     //Zend_Debug::dump($accesscodeDbMatchArray);
     // set line value
     $sparks = 0;
     $data_1 = array();
     $data_2min = array();
     $data_2max = array();
     $data_3min = array();
     $data_3max = array();
     $i = 0;
     $data_1[0] = $data_2max[0] = $data_2min[0] = $data_3min[0] = $data_3max[0] = $accumulate = 0;
     $temp = 0;
     foreach ($resultArray as $result) {
         if ($result != 0) {
             $xTodayLength = $temp;
         }
         $temp++;
     }
     foreach ($resultArray as $result) {
         if ($i == 0) {
             $i++;
             continue;
         }
         $accumulate = $result + $accumulate;
         $data_1[$i] = $accumulate + $staticsparks[$i];
         $data_2min[$i] = floor($accumulate * 2.5 + $staticsparks[$i]);
         $data_2max[$i] = $accumulate * 5 + $staticsparks[$i];
         $data_2avg[$i] = $accumulate * 3.75;
         $data_3min[$i] = floor($data_2avg[$i] * 3) + $data_2min[$i];
         $data_3max[$i] = floor($data_2avg[$i] * 4) + $data_2max[$i];
         $max = $data_3max[$i];
         if ($i == $xTodayLength) {
             break;
         }
         $i++;
     }
     // set max y axis value
     $dateArray = array_keys($resultArray);
     $y = new y_axis();
     if ($request->isPost()) {
         $formData = $request->getPost();
         $max = $formData['y_max'];
     } else {
         if ($max < 10000) {
             $max = ceil($max / 100) * 100;
         } else {
             $max = ceil($max / 1000) * 1000;
         }
     }
     $y->set_range(0, $max, $max / 10);
     $this->view->ymax = $max;
     // draw lines
     $x = new x_axis();
     $x_labels = new x_axis_labels();
     $x_labels->set_labels($dateArray);
     $x_labels->set_steps(floor($xDateArrayLength / 42) + 1);
     $x_labels->rotate(40);
     $x->set_labels($x_labels);
     $line_1_default_dot = new dot();
     $line_1_default_dot->colour('#007DCD')->tooltip('#x_label#: #val#');
     $line_1 = new line();
     $line_1->set_default_dot_style($line_1_default_dot);
     $line_1->set_values($data_1);
     $line_1->set_colour("#007DCD");
     $line_1->set_width(1);
     $line_2min_default_dot = new dot();
     $line_2min_default_dot->colour('#81C909')->tooltip('#x_label#: #val#');
     $line_2min = new line();
     $line_2min->set_default_dot_style($line_2min_default_dot);
     $line_2min->set_values($data_2min);
     $line_2min->set_colour("#81C909");
     $line_2min->set_width(1);
     $line_2_default_dot = new dot();
     $line_2_default_dot->colour('#81C909')->tooltip('#x_label#: #val#');
     $line_2 = new line();
     $line_2->set_default_dot_style($line_2_default_dot);
     $line_2->set_values($data_2max);
     $line_2->set_colour("#81C909");
     $line_2->set_width(1);
     $line_3_default_dot = new dot();
     $line_3_default_dot->colour('#FF0000')->tooltip('#x_label#: #val#');
     $line_3 = new line();
     $line_3->set_default_dot_style($line_3_default_dot);
     $line_3->set_values($data_3min);
     $line_3->set_colour("#FF0000");
     $line_3->set_width(1);
     $line_3max_default_dot = new dot();
     $line_3max_default_dot->colour('#FF0000')->tooltip('#x_label#: #val#');
     $line_3max = new line();
     $line_3max->set_default_dot_style($line_3max_default_dot);
     $line_3max->set_values($data_3max);
     $line_3max->set_colour("#FF0000");
     $line_3max->set_width(1);
     //tags
     $tags = new ofc_tags();
     $tags->font("Verdana", 10)->colour("#2F2F2F")->align_x_right();
     $this->view->chart = new open_flash_chart();
     // create event
     $campaignEventModel = new CampaignEvent();
     $campaignEvents = $campaignEventModel->fetchAll('campaign_id = ' . $campaign_id, 'event_date');
     $eventTotal = count($campaignEvents);
     $eventTemp = 0;
     foreach ($campaignEvents as $campaignEvent) {
         $eventDate = floor((strtotime($campaignEvent->event_date) - strtotime($campaign->create_date)) / 86400);
         $eventDescription = $campaignEvent->event_name;
         // event line
         $eventline = new scatter_line('#C5BE97', 1);
         $def = new hollow_dot();
         $def->size(0)->halo_size(0);
         $eventline->set_default_dot_style($def);
         $v = array(new scatter_value($eventDate, 0), new scatter_value($eventDate, $this->view->ymax));
         $eventline->set_values($v);
         $this->view->chart->add_element($eventline);
         // event description
         $tagAndArrow_Yvalue = 1 - ($eventTotal - $eventTemp++) / 10;
         if ($tagAndArrow_Yvalue == 0) {
             $tagAndArrow_Yvalue = 0.1;
         }
         $tag_xvalue = $eventDate + 2;
         $t = new ofc_tag($tag_xvalue, $this->view->ymax * $tagAndArrow_Yvalue);
         $t->text($eventDescription)->style(false, false, false, 1.0)->padding(0, 0);
         $tags->append_tag($t);
         // event arrow
         $arrowStart_x = $tag_xvalue;
         $arrowStart_y = $this->view->ymax * $tagAndArrow_Yvalue;
         $arrowEnd_x = $tag_xvalue - 1.5;
         $arrowEnd_y = $this->view->ymax * $tagAndArrow_Yvalue;
         $arrowColor = '#000000';
         $arrowBarbLength = 7;
         $a = new ofc_arrow($arrowStart_x, $arrowStart_y, $arrowEnd_x, $arrowEnd_y, $arrowColor, $arrowBarbLength);
         $this->view->chart->add_element($a);
     }
     $this->view->chart->add_element($line_1);
     $this->view->chart->add_element($line_2min);
     $this->view->chart->add_element($line_2);
     $this->view->chart->add_element($line_3);
     $this->view->chart->add_element($line_3max);
     $this->view->chart->add_element($tags);
     $this->view->chart->set_y_axis($y);
     $this->view->chart->set_x_axis($x);
     $this->view->chart->set_bg_colour('#FFFFFF');
 }
 function acceptAction()
 {
     $db = Zend_Registry::get('db');
     $request = $this->getRequest();
     $campaignId = (int) $this->_request->getParam('id', 0);
     $consumer = $this->_currentUser;
     if ($campaignId > 0) {
         // check if precampaign poll is finished
         $select1 = $db->select();
         $select1->from('campaign', 'pre_campaign_survey');
         $select1->where('campaign.id = ?', $campaignId);
         $previewCamSurvey = $db->fetchOne($select1);
         $indicate2Connect = new Indicate2_Connect();
         $ids = array($previewCamSurvey);
         $wsResult = $indicate2Connect->getAnswerSetCount($consumer->email, $ids);
         //			Zend_Debug::dump($wsResult);
         if ($wsResult == 0) {
             $this->_redirect('campaign/precampaign/survey/' . $previewCamSurvey);
         } else {
             $campaignInvitationModel = new CampaignInvitation();
             $campaignInvitation = $campaignInvitationModel->fetchRow("campaign_id=" . $campaignId . " and consumer_id=" . $consumer->id);
             $id = $campaignInvitation->id;
             //				Zend_Debug::dump($campaignInvitation);
             $campaignInvitation->state = "ACCEPTED";
             $campaignInvitation->save();
             $result = $db->fetchOne("SELECT COUNT(*) FROM campaign_participation WHERE campaign_invitation_id=:t1", array('t1' => $id));
             if ($result == 0) {
                 //create participation
                 $campaignParticipationModel = new CampaignParticipation();
                 $currentTime = date("Y-m-d H:i:s");
                 $row = $campaignParticipationModel->createRow();
                 $row->campaign_invitation_id = $id;
                 $row->accept_date = $currentTime;
                 $row->save();
             }
             $this->_redirect('campaigninvitation/index');
         }
     }
     $this->_helper->layout->disableLayout();
 }
 function adminreportAction()
 {
     $request = $this->getRequest();
     if ($request->isPost()) {
         $formData = $this->_request->getPost();
         $consumer_id = $formData['consumer_id'];
         $campaign_id = $formData['campaign_id'];
         $comment = $formData['phone_comments'];
         $source = $formData['source'];
         //whether participate in the campaign
         $campaigninvitationModel = new CampaignInvitation();
         $campaigninvitation = $campaigninvitationModel->fetchRow('campaign_id = ' . $campaign_id . ' and consumer_id' . ' =' . $consumer_id);
         if ($campaigninvitation == null) {
             //$this->_helper->redirector('index','home');
         }
         //get i2_survey_id
         $campaignModel = new Campaign();
         $campaign = $campaignModel->fetchRow("id=" . $campaign_id);
         $langNamespace = new Zend_Session_Namespace('Lang');
         $lang = $langNamespace->lang;
         if ($lang == 'en') {
             $surveyId = $campaign->i2_survey_id_en;
         } else {
             $surveyId = $campaign->i2_survey_id;
         }
         $this->view->campaing_name = $campaign->name;
         $this->view->id = $campaign_id;
         $indicate2Connect = new Indicate2_Connect();
         $accesscode = $indicate2Connect->createParticipation('', $surveyId);
         $config = Zend_Registry::get('config');
         $this->view->filloutPage = $config->indicate2->home . "/c/" . $accesscode . "/theme/wildfire";
         //save list in session
         $reportNamespace = new Zend_Session_Namespace('AgentReports');
         $source_key = $accesscode . '_source';
         $reportNamespace->{$source_key} = $source;
         $reportNamespace->{$accesscode} = $consumer_id;
         $this->view->includeCrystalCss = true;
     }
 }