diff --git a/application/controllers/survey/index.php b/application/controllers/survey/index.php index 6082d594110..9447dd80437 100644 --- a/application/controllers/survey/index.php +++ b/application/controllers/survey/index.php @@ -69,18 +69,77 @@ public function action() // collect all data in this method to pass on later $redata = compact(array_keys(get_defined_vars())); - $this->_loadLimesurveyLang($surveyid); + $previewmode = false; + if (isset($param['action']) && (in_array($param['action'], array('previewgroup', 'previewquestion')))) { + + if (!$this->_canUserPreviewSurvey($surveyid)) { + + // @todo : throw a 401 + $aErrors = array(gT('Error')); + $message = gT("We are sorry but you don't have permissions to do this."); + if(Permission::getUserId()) { + throw new CHttpException(403, $message); + } + throw new CHttpException(401, $message); + } else { + if ((intval($param['qid']) && $param['action'] == 'previewquestion')) { + $previewmode = 'question'; + } + if ((intval($param['gid']) && $param['action'] == 'previewgroup')) { + $previewmode = 'group'; + } + } + } + + Yii::app()->setConfig('previewmode', $previewmode); + + + // Token Object + + //SEE IF SURVEY USES TOKENS + if ($oSurvey->hasTokensTable) { + $tokensexist = 1; + } else { + $tokensexist = 0; + unset($_POST['token']); + unset($param['token']); + unset($token); + unset($clienttoken); + } + + // Get token + if (!isset($token)) { + $token = $clienttoken; + } + + if ($tokensexist == 1 && isset($token) && $token != "" && tableExists("{{tokens_".$surveyid."}}") && !$previewmode) { + + // check also if it is allowed to change survey after completion + if ($thissurvey['alloweditaftercompletion'] == 'Y') { + $oToken = $tokenInstance = Token::model($surveyid)->editable()->findByAttributes(array('token' => $token)); + } else { + $oToken = $tokenInstance = Token::model($surveyid)->usable()->incomplete()->findByAttributes(array('token' => $token)); + } + if (empty($tokenInstance)) { + $oToken = Token::model($surveyid)->findByAttributes(array('token' => $token)); + } + } + + $this->_loadLimesurveyLang($surveyid); // Set the language of the survey, either from POST, GET parameter of session var // Keep the old value, because SetSurveyLanguage update $_SESSION $sOldLang = isset($_SESSION['survey_'.$surveyid]['s_lang']) ? $_SESSION['survey_'.$surveyid]['s_lang'] : ""; // Keep the old value, because SetSurveyLanguage update $_SESSION + if (!empty($param['lang'])) { $sDisplayLanguage = $param['lang']; // $param take lang from returnGlobal and returnGlobal sanitize langagecode } elseif (isset($_SESSION['survey_'.$surveyid]['s_lang'])) { $sDisplayLanguage = $_SESSION['survey_'.$surveyid]['s_lang']; - } elseif (Survey::model()->findByPk($surveyid)) { + } elseif ( !empty($clienttoken) ) { + $sDisplayLanguage = $oToken->language; + }elseif (Survey::model()->findByPk($surveyid)) { $sDisplayLanguage = Survey::model()->findByPk($surveyid)->language; } else { $sDisplayLanguage = Yii::app()->getConfig('defaultlang'); @@ -147,30 +206,6 @@ public function action() ); } - $previewmode = false; - if (isset($param['action']) && (in_array($param['action'], array('previewgroup', 'previewquestion')))) { - - if (!$this->_canUserPreviewSurvey($surveyid)) { - - // @todo : throw a 401 - $aErrors = array(gT('Error')); - $message = gT("We are sorry but you don't have permissions to do this."); - if(Permission::getUserId()) { - throw new CHttpException(403, $message); - } - throw new CHttpException(401, $message); - } else { - if ((intval($param['qid']) && $param['action'] == 'previewquestion')) { - $previewmode = 'question'; - } - if ((intval($param['gid']) && $param['action'] == 'previewgroup')) { - $previewmode = 'group'; - } - } - } - - Yii::app()->setConfig('previewmode', $previewmode); - if ($this->_surveyCantBeViewedWithCurrentPreviewAccess($surveyid, $isSurveyActive, $surveyExists)) { $bPreviewRight = $this->_userHasPreviewAccessSession($surveyid); @@ -178,7 +213,7 @@ public function action() $event = new PluginEvent('onSurveyDenied'); $event->set('surveyId', $surveyid); $event->set('reason', 'noPreviewPermission'); - + App()->getPluginManager()->dispatchEvent($event); if(Permission::getUserId()) { throw new CHttpException(403, gT("We are sorry but you don't have permissions to do this.")); @@ -259,12 +294,7 @@ public function action() //~ ), //~ )), false); - - } - // Get token - if (!isset($token)) { - $token = $clienttoken; } //GET BASIC INFORMATION ABOUT THIS SURVEY @@ -274,17 +304,6 @@ public function action() $thissurvey['templatedir'] = $beforeSurveyPageEvent->get('template'); } - //SEE IF SURVEY USES TOKENS - if ($oSurvey->hasTokensTable) { - $tokensexist = 1; - } else { - $tokensexist = 0; - unset($_POST['token']); - unset($param['token']); - unset($token); - unset($clienttoken); - } - //SET THE TEMPLATE DIRECTORY $oTemplate = Template::model()->getInstance('', $surveyid); $timeadjust = Yii::app()->getConfig("timeadjust"); @@ -435,20 +454,8 @@ public function action() // this check is done in buildsurveysession and error message // could be more interresting there (takes into accound captcha if used) if ($tokensexist == 1 && isset($token) && $token != "" && tableExists("{{tokens_".$surveyid."}}") && !$previewmode) { - - // check also if it is allowed to change survey after completion - if ($thissurvey['alloweditaftercompletion'] == 'Y') { - $tokenInstance = Token::model($surveyid)->editable()->findByAttributes(array('token' => $token)); - } else { - $tokenInstance = Token::model($surveyid)->usable()->incomplete()->findByAttributes(array('token' => $token)); - } - if (empty($tokenInstance)) { - - $oToken = Token::model($surveyid)->findByAttributes(array('token' => $token)); - if ($oToken) { - $now = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i:s", Yii::app()->getConfig("timeadjust")); // This can not happen (TokenInstance must fix this) diff --git a/application/helpers/frontend_helper.php b/application/helpers/frontend_helper.php index be3479e3a89..b8418beaef1 100644 --- a/application/helpers/frontend_helper.php +++ b/application/helpers/frontend_helper.php @@ -749,20 +749,6 @@ function buildsurveysession($surveyid, $preview = false) // Reset all the session variables and start again resetAllSessionVariables($surveyid); - - // Multi lingual support order : by REQUEST, if not by Token->language else by survey default language - if (returnGlobal('lang', true)) { - $language_to_set = returnGlobal('lang', true); - } elseif (isset($oTokenEntry) && $oTokenEntry) { - // If survey have token : we have a $oTokenEntry - // Can use $oTokenEntry = Token::model($surveyid)->findByAttributes(array('token'=>$clienttoken)); if we move on another function : this par don't validate the token validity - $language_to_set = $oTokenEntry->language; - } else { - $language_to_set = $thissurvey['language']; - } - - // Always SetSurveyLanguage : surveys controller SetSurveyLanguage too, if different : broke survey (#09769) - SetSurveyLanguage($surveyid, $language_to_set); UpdateGroupList($surveyid, $_SESSION['survey_'.$surveyid]['s_lang']); $totalquestions = $survey->countTotalQuestions; @@ -1296,6 +1282,7 @@ function renderRenderWayForm($renderWay, array $scenarios, $sTemplateViewPath, $ Yii::app()->getController()->createAction('captcha'); } $oSurvey = Survey::model()->findByPk($surveyid); + // Rendering layout_user_forms.twig $thissurvey = $oSurvey->attributes; $thissurvey["aForm"] = $aForm; @@ -1667,6 +1654,14 @@ function doAssessment($surveyid) $assessment['subtotal_score'] = (isset($subtotal)) ? $subtotal : ''; $assessment['total_score'] = (isset($total)) ? $total : ''; + // token data for placeholder replacements + $token = Token::model($surveyid)->findByAttributes(array('token' => $_SESSION['survey_'.$surveyid]['token'])); + if ($token !== null){ + $assessment['token']['email'] = $survey->anonymized === 'N'?$token->email:''; + $assessment['token']['firstname'] = $survey->anonymized === 'N'?$token->firstname:''; + $assessment['token']['lastname'] = $survey->anonymized === 'N'?$token->lastname:''; + $assessment['token']['token'] = $survey->anonymized === 'N'?$token->token:''; + } //$aDatas = array('total' => $total, 'assessment' => $assessment, 'subtotal' => $subtotal, ); return array('show'=>($assessment['subtotal']['show'] || $assessment['total']['show']), 'datas' => $assessment); @@ -1897,7 +1892,7 @@ function checkCompletedQuota($surveyid, $return = false) $thissurvey['aQuotas']['sUrlDescription'] = $sUrlDescription; $thissurvey['aQuotas']['sUrl'] = $sUrl; $thissurvey['active'] = 'Y'; - + $thissurvey['aQuotas']['hiddeninputs'] = '