$survey = eZSurvey::fetch($surveyID); if (!$survey || !$survey->published() || !$survey->enabled() || !$survey->valid()) { return $Module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel'); } if ($http->hasPostVariable('SurveyCancelButton')) { $Module->redirectTo($survey->attribute('redirect_cancel')); return; } $validation = array(); $survey->processViewActions($validation); if ($http->hasPostVariable('SurveyStoreButton') && $validation['error'] == false) { $user = eZUser::currentUser(); if ($survey->attribute('persistent')) { $result = eZSurveyResult::instance($surveyID, $user->id()); } else { $result = eZSurveyResult::instance($surveyID); } $result->setAttribute('user_id', $user->id()); $http = eZHTTPTool::instance(); $sessionID = $http->sessionID(); $result->setAttribute('user_session_id', $sessionID); $result->storeResult(); if ($http->hasPostVariable('SurveyReceiverID')) { $surveyList = $survey->fetchQuestionList(); $mailTo = $surveyList[$http->postVariable('SurveyReceiverID')]->answer(); $tpl_email = eZTemplate::factory(); $tpl_email->setVariable('survey', $survey); $tpl_email->setVariable('survey_questions', $surveyList); $templateResult = $tpl_email->fetch('design:survey/mail.tpl'); $subject = $tpl_email->variable('subject'); $mail = new eZMail();
function processViewActions($objectAttribute, &$survey, &$validation) { $http = eZHTTPTool::instance(); $actionContinue = false; $postNodeID = self::PREFIX_ATTRIBUTE . '_ezsurvey_node_id_' . $objectAttribute->attribute('id'); $postContentObjectAttributeID = self::PREFIX_ATTRIBUTE . '_ezsurvey_contentobjectattribute_id_' . $objectAttribute->attribute('id'); $postSurveyID = self::PREFIX_ATTRIBUTE . '_ezsurvey_id_' . $objectAttribute->attribute('id'); $continueViewActions = true; if ($survey->attribute('one_answer') == 1) { $user = eZUser::currentUser(); if ($user->isLoggedIn() === true) { $contentObjectID = $objectAttribute->attribute('contentobject_id'); $contentClassAttributeID = $objectAttribute->attribute('contentclassattribute_id'); $languageCode = $objectAttribute->attribute('language_code'); $surveyID = $survey->attribute('id'); $exist = eZSurveyResult::exist($surveyID, $user->attribute('contentobject_id'), $contentObjectID, $contentClassAttributeID, $languageCode); if ($exist === true) { $continueViewActions = false; } } else { $continueViewActions = false; } } if ($continueViewActions === true) { if ($http->hasPostVariable($postNodeID) and $http->hasPostVariable($postContentObjectAttributeID) and $http->hasPostVariable($postSurveyID)) { $surveyID = $http->postVariable($postSurveyID); $contentObjectAttributeID = $http->postVariable($postContentObjectAttributeID); $nodeID = $http->postVariable($postNodeID); $node = eZContentObjectTreeNode::fetch($nodeID); if (get_class($node) == 'eZContentObjectTreeNode' and $node->canRead() === true) { // verify that our attribute is included in this node. $dataMap = $node->dataMap(); foreach ($dataMap as $attribute) { $attributeObjectID = $attribute->attribute('id'); if ($attributeObjectID == $contentObjectAttributeID) { $actionContinue = true; break; } } } else { if (get_class($node) == 'eZContentObjectTreeNode') { eZDebug::writeWarning("Not enough permissions to read node with ID: " . $nodeID . ".", 'eZSurveyType::processViewActions'); } else { eZDebug::writeWarning("node with ID: " . $nodeID . " does not exist.", 'eZSurveyType::processViewActions'); return false; } } } else { eZDebug::writeWarning("All the postvariables {$postNodeID}, {$postContentObjectAttributeID} and {$postSurveyID} need to be supplied.", 'eZSurveyType::processViewActions'); return false; } $nodeID = $http->postVariable($postNodeID); $node = eZContentObjectTreeNode::fetch($nodeID); if ($actionContinue === true) { $survey = eZSurvey::fetch($surveyID); $status = $survey->validateContentObjectAttributeID($contentObjectAttributeID); if (!$survey or !$survey->published() or !$survey->enabled() or !$survey->valid()) { eZDebug::writeWarning('Survey is not valid', 'eZSurveyType::processViewActions'); return; } $params = array('prefix_attribute' => self::PREFIX_ATTRIBUTE, 'contentobjectattribute_id' => $contentObjectAttributeID); $variableArray = $survey->processViewActions($validation, $params); $postSurveyStoreButton = self::PREFIX_ATTRIBUTE . '_ezsurvey_store_button_' . $contentObjectAttributeID; $user = eZUser::currentUser(); if ($survey->attribute('persistent')) { $result = eZSurveyResult::instance($surveyID, $user->id()); } else { $result = eZSurveyResult::instance($surveyID); } $result->setAttribute('user_id', $user->id()); $http = eZHTTPTool::instance(); $sessionID = $http->sessionID(); $result->setAttribute('user_session_id', $sessionID); if ($http->hasPostVariable($postSurveyStoreButton) && $validation['error'] == false) { $result->storeResult($params); $postReceiverID = self::PREFIX_ATTRIBUTE . '_ezsurvey_receiver_id_' . $contentObjectAttributeID; if ($http->hasPostVariable($postReceiverID) and $questionList = $survey->fetchQuestionList() and $postReceiverQuestionID = $http->postVariable($postReceiverID) and isset($questionList[$postReceiverQuestionID])) { $mailTo = $questionList[$postReceiverQuestionID]->answer(); $emailSenderList = explode('_', $questionList[$postReceiverQuestionID]->attribute('text3')); if (isset($emailSenderList[1]) and $emailSenderID = $emailSenderList[1] and is_numeric($emailSenderID) and $emailSenderID > 0 and isset($questionList[$emailSenderID]) and $senderQuestion = $questionList[$emailSenderID] and $senderQuestion->attribute('type') == 'EmailEntry' and eZMail::validate($senderQuestion->attribute('answer'))) { $emailSender = $senderQuestion->attribute('answer'); } else { $ini = eZINI::instance(); $emailSender = $ini->variable('MailSettings', 'EmailSender'); if (!$emailSender) { $emailSender = $ini->variable('MailSettings', 'AdminEmail'); } } require_once 'kernel/common/template.php'; $tpl_email = templateInit(); $tpl_email->setVariable('survey', $survey); $tpl_email->setVariable('survey_questions', $questionList); $tpl_email->setVariable('survey_node', $node); $templateResult = $tpl_email->fetch('design:survey/mail.tpl'); $subject = $tpl_email->variable('subject'); $mail = new eZMail(); $mail->setSenderText($emailSender); $mail->setReceiver($mailTo); $mail->setSubject($subject); $mail->setBody($templateResult); $mailResult = eZMailTransport::send($mail); } $survey->executeBeforeLastRedirect($node); $href = trim($survey->attribute('redirect_submit')); $module = $GLOBALS['module']; if ($module instanceof eZModule) { if (trim($href) != "") { if (preg_match("/^http:\\/\\/.+/", $href)) { $module->redirectTo($href); } else { $originalHref = $href; $status = eZURI::transformURI($href); if ($status === true) { // Need to keep the original href, since it's // already changed here. $module->redirectTo($originalHref); } else { $http->redirect($href); } } } } } else { if ($validation['error'] == true and $survey->attribute('persistent') == true) { // Fix prevous results. $validation['post_variables']['active'] = true; $validation['post_variables']['variables'] = $variableArray; } } } } else { eZDebug::writeWarning('Answer for survey with userid: ' . $user->id() . ' does already exist', 'eZSurveyType::processViewActions'); $validation['one_answer']['warning'] = true; } }
if ($http->hasPostVariable('ExportCSVButton')) { $href = 'survey/export/' . $contentObjectID . '/' . $contentClassAttributeID . '/' . $languageCode; $status = eZURI::transformURI($href); if ($status === true) { $http->redirect($href); } } if (is_numeric($surveyResultID)) { $surveyResult = eZSurveyResult::fetch($surveyResultID); if (get_class($surveyResult) != 'eZSurveyResult') { return $Module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel'); } $countListArray = eZSurveyResult::fetchSurveyResultCount($contentObjectID, $contentClassAttributeID, $languageCode); $countList = $countListArray['result']; } else { $resultList = eZSurveyResult::fetchResultArray($contentObjectID, $contentClassAttributeID, $languageCode, $offset, $limit, $countList); if (count($resultList) < 1) { return $Module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel'); } $surveyResult = $resultList[0]; } $surveyID = $surveyResult->attribute('survey_id'); $survey = eZSurvey::fetch($surveyID); if (!$survey) { return $Module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel'); } $surveyList = $survey->fetchQuestionList(); // $countList = $survey->resultCount(); $tpl = eZTemplate::factory(); $tpl->setVariable('contentobject_id', $contentObjectID); $tpl->setVariable('contentclassattribute_id', $contentClassAttributeID);
function &fetchQuestionResultList($user = false) { if (!$this->attribute('persistent')) { $value = 0; return $value; } if (!$user) { $user = eZUser::instance(); } if (!$user->attribute('is_logged_in')) { $value = 0; return $value; } $userID = $user->attribute('contentobject_id'); $surveyResultDefinition = eZSurveyResult::definition(); $result = eZPersistentObject::fetchObject($surveyResultDefinition, null, array('survey_id' => $this->ID, 'user_id' => $userID)); if (!$result) { $value = 0; return $value; } $isPersistent = $this->Persistent == 1 ? true : false; return $result->fetchQuestionResultList(false, $isPersistent); }
function &fetchAlreadyPosted($survey_id, $user_id = false) { if ($user_id === false) { $user_id = eZUser::currentUserID(); } return array('result' => eZPersistentObject::fetchObject(eZSurveyResult::definition(), null, array('survey_id' => $survey_id, 'user_id' => $user_id)) ? true : false); }
// /*! \file export.php */ $Module = $Params['Module']; $contentObjectID = $Params['ContentObjectID']; $contentClassAttributeID = $Params['ContentClassAttributeID']; $languageCode = $Params['LanguageCode']; $survey = eZSurvey::fetchByObjectInfo($contentObjectID, $contentClassAttributeID, $languageCode); if (!is_object($survey)) { return $Module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel'); } // $surveyID = $survey->attribute( 'id' ); // $db = eZDB::instance(); // $db->setIsSQLOutputEnabled( false ); // $http = eZHTTPTool::instance(); $output = eZSurveyResult::exportCSV($contentObjectID, $contentClassAttributeID, $languageCode); if ($output !== false) { $contentLength = strlen($output); header("Pragma: "); header("Cache-Control: "); header("Content-Length: {$contentLength}"); // header( "Content-Type: application/vnd.ms-excel" ); header("Content-Type: text/comma-separated-values"); header("X-Powered-By: eZ Publish"); header("Content-disposition: attachment; filename=export.csv"); // header( "Content-Transfer-Encoding: binary" ); ob_end_clean(); print $output; } else { echo ezpI18n::tr('survey', 'No results'); echo "\n";
// may use this file in accordance with the "eZ Publish professional licence" // version 2 Agreement provided with the Software. // // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING // THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR // PURPOSE. // // The "eZ Publish professional licence" version 2 is available at // http://ez.no/ez_publish/licences/professional/ and in the file // PROFESSIONAL_LICENCE included in the packaging of this file. // For pricing of this licence please contact us via e-mail to licence@ez.no. // Further contact information is available at http://ez.no/company/contact/. // // The "GNU General Public License" (GPL) is available at // http://www.gnu.org/copyleft/gpl.html. // // Contact licence@ez.no if any conditions of this licencing isn't clear to // you. // /*! \file rremove.php */ $http = eZHTTPTool::instance(); $Module = $Params['Module']; $resultID = $Params['ResultID']; $surveyResult = eZSurveyResult::fetch($resultID); $surveyID = 0; if ($surveyResult) { $surveyID = $surveyResult->attribute('survey_id'); $surveyResult->remove(); } $Module->redirectTo('survey/result_list/' . $surveyID);
/*! \file result.php */ $Module = $Params['Module']; // $surveyID = $Params['SurveyID']; $contentObjectID = $Params['ContentObjectID']; $contentClassAttributeID = $Params['ContentClassAttributeID']; $languageCode = $Params['LanguageCode']; $count = 0; $survey = eZSurvey::fetchByObjectInfo($contentObjectID, $contentClassAttributeID, $languageCode); if (!is_object($survey)) { return $Module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel'); } $surveyID = $survey->attribute('id'); // $survey = eZSurvey::fetch( $surveyID ); if (!$survey) { return $Module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel'); } $surveyList = $survey->fetchQuestionList(); $count = eZSurveyResult::fetchResult($contentObjectID, $contentClassAttributeID, $languageCode); require_once 'kernel/common/template.php'; $tpl = templateInit(); $tpl->setVariable('contentobject_id', $contentObjectID); $tpl->setVariable('contentclassattribute_id', $contentClassAttributeID); $tpl->setVariable('language_code', $languageCode); $tpl->setVariable('survey_questions', $surveyList); $tpl->setVariable('survey_metadata', array()); $tpl->setVariable('count', $count); $Result = array(); $Result['left_menu'] = 'design:parts/survey/menu.tpl'; $Result['content'] = $tpl->fetch('design:survey/result.tpl'); $Result['path'] = array(array('url' => '/survey/list', 'text' => ezpI18n::tr('survey', 'Survey')), array('url' => false, 'text' => ezpI18n::tr('survey', 'Result overview')));
if (!$surveyResult) { return $Module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel'); } $survey = eZSurvey::fetch($surveyResult->attribute('survey_id')); if (!$survey) { return $Module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel'); } $validation = array(); $contentObjectID = $survey->attribute('contentobject_id'); $contentObjectAttributeID = $survey->attribute('contentobjectattribute_id'); $contentClassAttributeID = $survey->attribute('contentclassattribute_id'); $languageCode = $survey->attribute('language_code'); $params = array('prefix_attribute' => eZSurveyType::PREFIX_ATTRIBUTE, 'contentobjectattribute_id' => $contentObjectAttributeID); $survey->processViewActions($validation, $params); if ($http->hasPostVariable('SurveyStoreButton') && $validation['error'] == false) { $result = eZSurveyResult::instance($surveyResult->attribute('survey_id'), $surveyResult->attribute('user_id')); $result->storeResult($params); $Module->redirectTo('/survey/result_list/' . $contentObjectID . '/' . $contentClassAttributeID . '/' . $languageCode); } else { if ($http->hasPostVariable('SurveyCancelButton')) { $Module->redirectTo('/survey/result_list/' . $contentObjectID . '/' . $contentClassAttributeID . '/' . $languageCode); } } require_once 'kernel/common/template.php'; $tpl = templateInit(); $tpl->setVariable('prefix_attribute', eZSurveyType::PREFIX_ATTRIBUTE); $tpl->setVariable('contentobject_id', $contentObjectID); $tpl->setVariable('contentobjectattribute_id', $contentObjectAttributeID); $tpl->setVariable('contentclassattribute_id', $contentClassAttributeID); $tpl->setVariable('language_code', $languageCode); $tpl->setVariable('preview', false);