/
OptinController.php
117 lines (106 loc) · 3.83 KB
/
OptinController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
* LimeSurvey
* Copyright (C) 2013 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
*
*
*/
/**
* optin
*
* @package LimeSurvey
* @copyright 2011
* @access public
*/
class OptinController extends LSYii_Controller {
function actiontokens($surveyid, $token, $langcode = '')
{
Yii::app()->loadHelper('database');
Yii::app()->loadHelper('sanitize');
$sLanguageCode = $langcode;
$iSurveyID = $surveyid;
$sToken = $token;
$sToken = sanitize_token($sToken);
if (!$iSurveyID)
{
$this->redirect(array('/'));
}
$iSurveyID = (int)$iSurveyID;
//Check that there is a SID
// Get passed language from form, so that we dont loose this!
if (!isset($sLanguageCode) || $sLanguageCode == "" || !$sLanguageCode)
{
$baselang = Survey::model()->findByPk($iSurveyID)->language;
Yii::import('application.libraries.Limesurvey_lang', true);
$clang = new Limesurvey_lang($baselang);
}
else
{
$sLanguageCode = sanitize_languagecode($sLanguageCode);
Yii::import('application.libraries.Limesurvey_lang', true);
$clang = new Limesurvey_lang($sLanguageCode);
$baselang = $sLanguageCode;
}
Yii::app()->lang = $clang;
$thissurvey=getSurveyInfo($iSurveyID,$baselang);
if ($thissurvey == false || !tableExists("{{tokens_{$iSurveyID}}}"))
{
$html = $clang->gT('This survey does not seem to exist.');
}
else
{
$tokenInstance = Token::model(null, $iSurveyID)->findByAttributes(array('token' => $token));
if (!isset($tokenInstance))
{
$html = $clang->gT('You are not a participant in this survey.');
}
else
{
if ($tokenInstance->emailstatus =='OptOut')
{
$tokenInstance->emailstatus = 'OK';
$tokenInstance->save();
$html = $clang->gT('You have been successfully added back to this survey.');
}
elseif ($tokenInstance->emailstatus == 'OK')
{
$html = $clang->gT('You are already a part of this survey.');
}
else
{
$html = $clang->gT('You have been already removed from this survey.');
}
}
}
//PRINT COMPLETED PAGE
if (!$thissurvey['templatedir'])
{
$thistpl=getTemplatePath(Yii::app()->getConfig("defaulttemplate"));
}
else
{
$thistpl=getTemplatePath($thissurvey['templatedir']);
}
$this->_renderHtml($html,$thistpl,$clang,$thissurvey);
}
private function _renderHtml($html,$thistpl, $oLanguage, $aSurveyInfo)
{
sendCacheHeaders();
doHeader();
$aSupportData=array('thissurvey'=>$aSurveyInfo, 'clang'=>$oLanguage);
echo templatereplace(file_get_contents($thistpl.DIRECTORY_SEPARATOR.'startpage.pstpl'),array(), $aSupportData);
$data['html'] = $html;
$data['thistpl'] = $thistpl;
$this->render('/opt_view',$data);
echo templatereplace(file_get_contents($thistpl.DIRECTORY_SEPARATOR.'endpage.pstpl'),array(), $aSupportData);
doFooter();
}
}