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(); } }
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"; } } }