$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 (!$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);