request->getQuery('surveyid'); $sLanguageCode = Yii::app()->request->getQuery('langcode'); $sToken = Token::sanitizeToken(Yii::app()->request->getQuery('token')); Yii::app()->loadHelper('database'); Yii::app()->loadHelper('sanitize'); //IF there is no survey id, redirect back to the default public page if (!$iSurveyID) { $this->redirect(array('/')); } $iSurveyID = (int) $iSurveyID; //Make sure it's an integer (protect from SQL injects) //Check that there is a SID // Get passed language from form, so that we dont lose this! if (!isset($sLanguageCode) || $sLanguageCode == "" || !$sLanguageCode) { $sBaseLanguage = Survey::model()->findByPk($iSurveyID)->language; } else { $sBaseLanguage = sanitize_languagecode($sLanguageCode); } Yii::app()->setLanguage($sBaseLanguage); $aSurveyInfo = getSurveyInfo($iSurveyID, $sBaseLanguage); if ($aSurveyInfo == false || !tableExists("{{tokens_{$iSurveyID}}}")) { throw new CHttpException(404, "The survey in which you are trying to participate does not seem to exist. It may have been deleted or the link you were given is outdated or incorrect."); } else { $sMessage = "
".gT('Please confirm that you want to opt out of this survey by clicking the button below.').'
'.gT("After confirmation you won't receive any invitations or reminders for this survey anymore.")."
';
$this->renderHtml($sMessage, $aSurveyInfo, $iSurveyID);
}
}
/**
* This function is run when opting out of an individual survey participants table. The other function /optout/participants
* opts the user out of ALL survey invitations from the system
*/
function actionremovetokens()
{
$iSurveyID = Yii::app()->request->getQuery('surveyid');
$sLanguageCode = Yii::app()->request->getQuery('langcode');
$sToken = Token::sanitizeToken(Yii::app()->request->getQuery('token'));
Yii::app()->loadHelper('database');
Yii::app()->loadHelper('sanitize');
if (!$iSurveyID) {
//IF there is no survey id, redirect back to the default public page
$this->redirect(array('/'));
}
$iSurveyID = (int) $iSurveyID; //Make sure it's an integer (protect from SQL injects)
//Check that there is a SID
// Get passed language from form, so that we dont lose this!
if (!isset($sLanguageCode) || $sLanguageCode == "" || !$sLanguageCode) {
$sBaseLanguage = Survey::model()->findByPk($iSurveyID)->language;
} else {
$sBaseLanguage = sanitize_languagecode($sLanguageCode);
}
Yii::app()->setLanguage($sBaseLanguage);
$aSurveyInfo = getSurveyInfo($iSurveyID, $sBaseLanguage);
if ($aSurveyInfo == false || !tableExists("{{tokens_{$iSurveyID}}}")) {
throw new CHttpException(404, "The survey in which you are trying to participate does not seem to exist. It may have been deleted or the link you were given is outdated or incorrect.");
} else {
LimeExpressionManager::singleton()->loadTokenInformation($iSurveyID, $sToken, false);
$oToken = Token::model($iSurveyID)->findByAttributes(array('token'=>$sToken));
if (!isset($oToken)) {
$sMessage = gT('You are not a participant in this survey.');
//throw new CHttpException(404, "You are not a participant in this survey.");
} else {
if (substr($oToken->emailstatus, 0, strlen('OptOut')) !== 'OptOut') {
$oToken->emailstatus = 'OptOut';
$oToken->save();
$sMessage = gT('You have been successfully removed from this survey.');
} else {
$sMessage = gT('You have already been removed from this survey.');
}
}
}
$this->renderHtml($sMessage, $aSurveyInfo, $iSurveyID);
}
/**
* This function is run when opting out of the participants system. The other function /optout/token
* opts the user out of just a single token/survey invite list
*/
function actionparticipants()
{
$iSurveyID = Yii::app()->request->getQuery('surveyid');
$sLanguageCode = Yii::app()->request->getQuery('langcode');
$sToken = Token::sanitizeToken(Yii::app()->request->getQuery('token'));
Yii::app()->loadHelper('database');
Yii::app()->loadHelper('sanitize');
if (!$iSurveyID) {
//IF there is no survey id, redirect back to the default public page
$this->redirect(array('/'));
}
$iSurveyID = (int) $iSurveyID; //Make sure it's an integer (protect from SQL injects)
//Check that there is a SID
// Get passed language from form, so that we dont lose this!
if (!isset($sLanguageCode) || $sLanguageCode == "" || !$sLanguageCode) {
$sBaseLanguage = Survey::model()->findByPk($iSurveyID)->language;
} else {
$sBaseLanguage = sanitize_languagecode($sLanguageCode);
}
Yii::app()->setLanguage($sBaseLanguage);
$aSurveyInfo = getSurveyInfo($iSurveyID, $sBaseLanguage);
if ($aSurveyInfo == false || !tableExists("{{tokens_{$iSurveyID}}}")) {
throw new CHttpException(404, "The survey in which you are trying to participate does not seem to exist. It may have been deleted or the link you were given is outdated or incorrect.");
} else {
LimeExpressionManager::singleton()->loadTokenInformation($iSurveyID, $sToken, false);
$oToken = Token::model($iSurveyID)->findByAttributes(array('token' => $sToken));
//START MM NEW 09/2018
$useremail = $oToken->email;
//END MM NEW 09/2018
if (!isset($oToken)) {
$sMessage = gT('You are not a participant in this survey.'); //MM CHECKED
} else {
if (substr($oToken->emailstatus, 0, strlen('OptOut')) !== 'OptOut') {
$oToken->emailstatus = 'OptOut';
$oToken->save();
$sMessage = gT('You have been successfully removed from this survey.');
} else {
$sMessage = gT('You have been already removed from this survey.');
}
//MM OLD: if(!empty($oToken->participant_id))
if(!empty($oToken->email)) //MM NEW
{
//Participant also exists in central db
//MM OLD: $oParticipant = Participant::model()->findByPk($oToken->participant_id);
$oParticipant = Participant::model()->findAll("email = '".$oToken->email."'"); //MM NEW
//Check if first (there can be several!) user exists at CPDB and has status blacklisted
//MM ORIG: if($oParticipant->blacklisted=="Y")
if($oParticipant[0]->blacklisted=="Y") //MM NEW
{
$sMessage .= "
";
$sMessage .= gT("You have already been removed from the central participants list for this site");
}
//user not blacklisted -> add new user to CPDB with blacklist = Y
else
{
/* MM OLD
$oParticipant->blacklisted='Y';
$oParticipant->save();
*/
/* MM START: Add not existing user to participant DB */
$aData = array();
$uuid = Participant::gen_uuid();
$aData['participant_id'] = $uuid;
$aData['firstname'] = $oToken->firstname;
$aData['lastname'] = $oToken->lastname;
$aData['email'] = $oToken->email;
$aData['blacklisted'] = "Y";
$aData['owner_uid'] = 1;
$aData['created_by'] = 1;
$result = Participant::model()->insertParticipant($aData);
//check if INSERT statement worked well
if (is_object($result))
{
$sMessage .= "
";
$sMessage .= "Sie sind aus dem Umfragetool erfolgreich ausgetragen worden und erhalten keine Umfragen mehr.";
}
/* MM END
$sMessage .= "
";
$sMessage .= gT("You have been removed from the central participants list for this site");
*/
}
}
//MM NEW 02/2018: Remove users from ALL surveys!
$oSurvey = new Survey;
//fake a superadmin user
$sUid = 1;
//get permissions to access all surveys
$oSurvey->permission($sUid);
//if new messages have to be added...
$sMessage .= "
";
//get all surveys
$aUserSurveys = $oSurvey->with(array('languagesettings'=>array('condition'=>'surveyls_language=language'), 'owner'))->findAll();
//error if no surveys exist
if (count($aUserSurveys) == 0)
{
return array('status' => 'No surveys found');
}
//check all survey details
foreach ($aUserSurveys as $oSurvey)
{
$oSurveyLanguageSettings = SurveyLanguageSetting::model()->findByAttributes(array('surveyls_survey_id' => $oSurvey->primaryKey, 'surveyls_language' => $oSurvey->language));
if (!isset($oSurveyLanguageSettings))
{
$aSurveyTitle = '';
} else
{
$aSurveyTitle = $oSurveyLanguageSettings->attributes['surveyls_title'];
}
//store all survey data here
$aData[] = array('sid'=>$oSurvey->primaryKey, 'surveyls_title'=>$aSurveyTitle, 'startdate'=>$oSurvey->attributes['startdate'], 'expires'=>$oSurvey->attributes['expires'], 'active'=>$oSurvey->attributes['active']);
}
//print_r($aData);
//die();
//loop through all the surveys we have loaded previously
foreach($aData as $surveydata)
{
if(!isset($surveydata['sid']))
{
break;
//this is the current survey ID
$iSurveyID = $surveydata['sid'];
//check if survey comes with a token table
if(tableExists("{{tokens_{$iSurveyID}}}"))
{
//check if there is a token entry with the given email address.
$oToken = Token::model($iSurveyID)->findByAttributes(array('email' => $useremail));
//no token, we do not care
if (!isset($oToken))
{
//DO NOTHING
//$sMessage = gT('You are not a participant in this survey (#'.$iSurveyID.').');
}
//token found at other survey -> check details
else
{
//set optout detail
if (substr($oToken->emailstatus, 0, strlen('OptOut')) !== 'OptOut')
{
$oToken->emailstatus = 'OptOut';
$oToken->save();
$sMessage .= "
";
$sMessage .= gT('Sie sind aus dieser Umfrage ebenfalls ausgetragen worden:');
$sMessage .= "
[$iSurveyID]";
}
}
} //survey uses tokens
}
} //loop surveys
//MM END 02/2018: Remove users from ALL surveys!
//these belong to above function
}
}
$this->renderHtml($sMessage, $aSurveyInfo, $iSurveyID);
}
/**
* Render something
*
* @param string $html
* @param array $aSurveyInfo
* @param int $iSurveyID
* @return void
*/
private function renderHtml($html, $aSurveyInfo, $iSurveyID)
{
$survey = Survey::model()->findByPk($iSurveyID);
$aSurveyInfo['include_content'] = 'optout';
$aSurveyInfo['optin_message'] = $html;
Template::model()->getInstance('', $iSurveyID);
Yii::app()->twigRenderer->renderTemplateFromFile(
"layout_global.twig",
array(
'oSurvey' => $survey,
'aSurveyInfo' => $aSurveyInfo
),
false
);
Yii::app()->end();
}
}