/
index.php
687 lines (578 loc) · 29.8 KB
/
index.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
<?php
if (!defined('BASEPATH')) {
exit('No direct script access allowed');
}
/*
* LimeSurvey
* Copyright (C) 2007-2011 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.
*/
class index extends CAction
{
public $oTemplate;
public function run()
{
useFirebug();
$this->action();
}
public function action()
{
global $surveyid;
global $thissurvey, $thisstep;
global $clienttoken, $tokensexist, $token;
$this->_loadRequiredHelpersAndLibraries();
$param = $this->_getParameters(func_get_args(), $_POST);
$surveyid = $param['sid'];
$thisstep = $param['thisstep'];
$move = getMove();
$clienttoken = trim($param['token']);
$oSurvey = Survey::model()->findByPk($surveyid);
if (empty($oSurvey)) {
$event = new PluginEvent('onSurveyDenied');
$event->set('surveyId', $surveyid);
$event->set('reason', 'surveyDoesNotExist');
App()->getPluginManager()->dispatchEvent($event);
throw new CHttpException(404, gT("The survey in which you are trying to participate does not seem to exist."));
/* Alt solution */
//~ header("HTTP/1.0 404 Not Found",true,404);
//~ Yii::app()->twigRenderer->renderTemplateFromFile("layout_errors.twig",
//~ array('aSurveyInfo' =>array(
//~ 'aError'=>array(
//~ 'error'=>gT('404: Not Found'),
//~ 'title'=>gT('This survey does not seem to exist'),
//~ 'message'=>gT("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.")
//~ ),
//~ )), false);
}
Yii::app()->setConfig('surveyID', $surveyid);
Yii::app()->setConfig('move', $move);
App()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts') . "survey_runtime.js");
if (is_null($thissurvey) && !is_null($surveyid)) {
$thissurvey = getSurveyInfo($surveyid);
}
// unused vars in this method (used in methods using compacted method vars)
$loadname = $param['loadname'];
$loadpass = $param['loadpass'];
$sitename = Yii::app()->getConfig('sitename');
if (isset($param['newtest']) && $param['newtest'] == "Y") {
killSurveySession($surveyid);
resetQuestionTimers($surveyid);
}
$surveyExists = ($oSurvey != null);
$isSurveyActive = ($surveyExists && $oSurvey->isActive);
// collect all data in this method to pass on later
$redata = compact(array_keys(get_defined_vars()));
$previewmode = false;
if (isset($param['action']) && (in_array($param['action'], array('previewgroup', 'previewquestion')))) {
if (!$this->_canUserPreviewSurvey($surveyid)) {
$aErrors = array(gT('Error'));
$message = gT("We are sorry but you don't have permissions to do this.", 'unescaped');
if (Permission::model()->getUserId()) {
throw new CHttpException(403, $message);
}
throw new CHttpException(401, $message);
} else {
killSurveySession($surveyid);
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
// Get token
if (!isset($token) && isset($clienttoken)) {
$token = $clienttoken;
}
//SEE IF SURVEY USES TOKENS
if ($oSurvey->hasTokensTable) {
$tokensexist = 1;
}
// maintenance mode
$sMaintenanceMode = getGlobalSetting('maintenancemode');
if ($sMaintenanceMode == 'hard') {
if ($previewmode === false) {
Yii::app()->twigRenderer->renderTemplateFromFile("layout_maintenance.twig", array('oSurvey' => Survey::model()->findByPk($surveyid), 'aSurveyInfo' => $thissurvey), false);
}
} elseif ($sMaintenanceMode == 'soft') {
if ($move === null) {
if ($previewmode === false) {
Yii::app()->twigRenderer->renderTemplateFromFile("layout_maintenance.twig", array('oSurvey' => Survey::model()->findByPk($surveyid), 'aSurveyInfo' => $thissurvey), false);
}
}
}
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));
}
if (empty($oToken)) {
// #16142 quick fix : unset invalid token
$token = null;
}
}
$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
$sDisplayLanguage = Yii::app()->getConfig('defaultlang');
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 (!empty($oToken)) {
$sDisplayLanguage = $oToken->language;
} elseif ($oSurvey) {
$sDisplayLanguage = $oSurvey->language;
}
if ($surveyid && $surveyExists) {
SetSurveyLanguage($surveyid, $sDisplayLanguage);
}
/* Launch beforeSurveyPage before all renderExitMessage */
$beforeSurveyPageEvent = new PluginEvent('beforeSurveyPage');
$beforeSurveyPageEvent->set('surveyId', $surveyid);
App()->getPluginManager()->dispatchEvent($beforeSurveyPageEvent);
if ($this->_isClientTokenDifferentFromSessionToken($clienttoken, $surveyid)) {
$sReloadUrl = $this->getController()->createUrl("/survey/index/sid/{$surveyid}", array('token' => $clienttoken, 'lang' => App()->language, 'newtest' => 'Y'));
$aErrors = array(gT('Access code mismatch'));
$asMessage = array(gT('The access code you provided doesn\'t match the one in your session.'));
$aUrl = array(
'url' => $sReloadUrl,
'type' => 'restart-survey',
'description' => gT("Click here to start the survey.")
);
killSurveySession($surveyid);
App()->getController()->renderExitMessage(
$surveyid,
'restart-survey',
$asMessage,
$aUrl,
$aErrors
);
$this->_createNewUserSessionAndRedirect($surveyid, $redata, __LINE__, $asMessage);
} elseif (!$clienttoken) {
$clienttoken = isset($_SESSION['survey_' . $surveyid]['token']) ? $_SESSION['survey_' . $surveyid]['token'] : ""; // Fix for #12003
}
if ($tokensexist != 1) {
$tokensexist = 0;
unset($_POST['token']);
unset($param['token']);
unset($token);
unset($clienttoken);
}
// No test for response update
if ($this->_isSurveyFinished($surveyid) && ($thissurvey['alloweditaftercompletion'] != 'Y' || $thissurvey['tokenanswerspersistence'] != 'Y')) {
$aReloadUrlParam = array('lang' => App()->language, 'newtest' => 'Y');
if (!empty($clienttoken)) {
$aReloadUrlParam['token'] = $clienttoken;
}
$aErrors = array(gT('Previous session is set to be finished.'));
$aMessage = array(gT('Your browser reports that it was used previously to answer this survey. We are resetting the session so that you can start from the beginning.'),);
$aUrl = array(
'url' => $this->getController()->createUrl("/survey/index/sid/{$surveyid}", $aReloadUrlParam),
'type' => 'restart-survey',
'description' => gT("Click here to start the survey.")
);
killSurveySession($surveyid);
App()->getController()->renderExitMessage(
$surveyid,
'restart-survey',
$aMessage,
$aUrl,
$aErrors
);
}
if ($this->_surveyCantBeViewedWithCurrentPreviewAccess($surveyid, $isSurveyActive, $surveyExists)) {
$bPreviewRight = $this->_userHasPreviewAccessSession($surveyid);
if ($bPreviewRight === false) {
$event = new PluginEvent('onSurveyDenied');
$event->set('surveyId', $surveyid);
$event->set('reason', 'noPreviewPermission');
App()->getPluginManager()->dispatchEvent($event);
if (Permission::model()->getUserId()) {
throw new CHttpException(403, gT("We are sorry but you don't have permissions to do this.", 'unescaped'));
}
throw new CHttpException(401, gT("We are sorry but you don't have permissions to do this.", 'unescaped'));
}
}
// TODO can this be moved to the top?
// (Used to be global, used in ExpressionManager, merged into amVars. If not filled in === '')
// can this be added in the first computation of $redata?
if (isset($_SESSION['survey_' . $surveyid]['srid'])) {
$saved_id = $_SESSION['survey_' . $surveyid]['srid'];
}
// recompute $redata since $saved_id used to be a global
$redata = compact(array_keys(get_defined_vars()));
if ($this->_didSessionTimeout($surveyid)) {
$aErrors = array(gT('We are sorry but your session has expired.'));
$aMessage = array(
gT("Either you have been inactive for too long, you have cookies disabled for your browser, or there were problems with your connection."),
);
$aReloadUrlParam = array('lang' => App()->language, 'newtest' => 'Y');
if (!empty($clienttoken)) {
$aReloadUrlParam['token'] = $clienttoken;
}
$aUrl = array(
'url' => $this->getController()->createUrl("/survey/index/sid/{$surveyid}", $aReloadUrlParam),
'type' => 'restart-survey',
'description' => gT("Click here to start the survey.")
);
$event = new PluginEvent('onSurveyDenied');
$event->set('surveyId', $surveyid);
$event->set('reason', 'sessionExpired');
App()->getPluginManager()->dispatchEvent($event);
App()->getController()->renderExitMessage(
$surveyid,
'session-timeout',
$aMessage,
$aUrl,
$aErrors
);
};
//CHECK FOR REQUIRED INFORMATION (sid)
if ($surveyid && $surveyExists) {
LimeExpressionManager::SetSurveyId($surveyid); // must be called early - it clears internal cache if a new survey is being used
if ($previewmode) {
LimeExpressionManager::SetPreviewMode($previewmode);
}
// Update the Session var only if needed
if (App()->language != $sOldLang) {
UpdateGroupList($surveyid, App()->language); // to refresh the language strings in the group list session variable
updateFieldArray(); // to refresh question titles and question text
}
}
//GET BASIC INFORMATION ABOUT THIS SURVEY
$thissurvey = getSurveyInfo($surveyid, $_SESSION['survey_' . $surveyid]['s_lang']);
EmCacheHelper::init($thissurvey);
/* Unsure it still work, and surely better in afterFindSurvey */
if (!is_null($beforeSurveyPageEvent->get('template'))) {
$thissurvey['templatedir'] = $beforeSurveyPageEvent->get('template');
}
//SET THE TEMPLATE DIRECTORY
$oTemplate = Template::model()->getInstance('', $surveyid);
$timeadjust = Yii::app()->getConfig("timeadjust");
//MAKE SURE SURVEY HASN'T EXPIRED
if ($thissurvey['expiry'] != '' and dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i:s", $timeadjust) > $thissurvey['expiry'] && $thissurvey['active'] != 'N' && !$previewmode) {
$aErrors = array(gT('Error'));
$aMessage = array(
gT("We are sorry but the survey is expired and no longer available.")
);
$event = new PluginEvent('onSurveyDenied');
$event->set('surveyId', $surveyid);
$event->set('reason', 'surveyNoLongerAvailable');
App()->getPluginManager()->dispatchEvent($event);
App()->getController()->renderExitMessage(
$surveyid,
'survey-expiry',
$aMessage,
null,
$aErrors
);
}
//MAKE SURE SURVEY IS ALREADY VALID
if ($thissurvey['startdate'] != '' and dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i:s", $timeadjust) < $thissurvey['startdate'] && $thissurvey['active'] != 'N' && !$previewmode) {
$aErrors = array(gT('Error'));
$aMessage = array(
gT("This survey is not yet started.")
);
$event = new PluginEvent('onSurveyDenied');
$event->set('surveyId', $surveyid);
$event->set('reason', 'surveyNotYetStarted');
App()->getPluginManager()->dispatchEvent($event);
App()->getController()->renderExitMessage(
$surveyid,
'survey-notstart',
$aMessage,
null,
$aErrors
);
}
//CHECK FOR PREVIOUSLY COMPLETED COOKIE
//If cookies are being used, and this survey has been completed, a cookie called "PHPSID[sid]STATUS" will exist (ie: SID6STATUS) and will have a value of "COMPLETE"
$sCookieName = "LS_" . $surveyid . "_STATUS";
if (!$previewmode && isset($_COOKIE[$sCookieName]) && $_COOKIE[$sCookieName] == "COMPLETE" && $thissurvey['usecookie'] == "Y" && $tokensexist != 1) {
$aErrors = array(gT('Error'));
$aMessage = array(
gT("You have already completed this survey.")
);
$event = new PluginEvent('onSurveyDenied');
$event->set('surveyId', $surveyid);
$event->set('reason', 'alreadyCompleted');
App()->getPluginManager()->dispatchEvent($event);
App()->getController()->renderExitMessage(
$surveyid,
'survey-notstart',
$aMessage,
null,
$aErrors
);
}
//LOAD SAVED SURVEY
if (Yii::app()->request->getParam('loadall') == "reload") {
$aLoadErrorMsg = array();
$sLoadName = Yii::app()->request->getParam('loadname');
$sLoadPass = Yii::app()->request->getParam('loadpass');
if (isset($sLoadName) && !$sLoadName) {
$aLoadErrorMsg['name'] = gT("You did not provide a name.");
}
if (isset($sLoadPass) && !$sLoadPass) {
$aLoadErrorMsg['password'] = gT("You did not provide a password.");
}
if (!$isSurveyActive) {
$aLoadErrorMsg['password'] = gT("You cannot reload responses because the survey is not activated, yet.");
}
// if security question answer is incorrect
// Not called if scid is set in GET params (when using email save/reload reminder URL)
// && Yii::app()->request->isPostRequest ?
if (isCaptchaEnabled('saveandloadscreen', $thissurvey['usecaptcha']) && is_null(Yii::app()->request->getQuery('scid'))) {
$sLoadSecurity = Yii::app()->request->getPost('loadsecurity');
if (empty($sLoadSecurity)) {
$aLoadErrorMsg['captchaempty'] = gT("You did not answer to the security question.");
} elseif (
!Yii::app()->request->getPost('loadsecurity')
|| !isset($_SESSION['survey_' . $surveyid]['secanswer'])
|| Yii::app()->request->getPost('loadsecurity') != $_SESSION['survey_' . $surveyid]['secanswer']
) {
$aLoadErrorMsg['captcha'] = gT("The answer to the security question is incorrect.");
}
}
if (empty($aLoadErrorMsg)) {
LimeExpressionManager::SetDirtyFlag();
buildsurveysession($surveyid);
if (loadanswers()) {
Yii::app()->setConfig('move', 'reload');
$move = "reload"; // veyRunTimeHelper use $move in $arg
} else {
$aLoadErrorMsg['matching'] = gT("There is no matching saved response.");
}
randomizationGroupsAndQuestions($surveyid);
initFieldArray($surveyid, $_SESSION['survey_' . $surveyid]['fieldmap']);
}
if (count($aLoadErrorMsg)) {
Yii::app()->setConfig('move', "loadall"); // Show loading form
}
}
//Allow loading of saved survey
if (Yii::app()->getConfig('move') == "loadall") {
/* Construction of the form */
$aLoadForm['aCaptcha']['show'] = false;
// save current survey data when clicking on "Load unfinished survey"
Yii::import('application.helpers.SurveyRuntimeHelper');
$SurveyRuntimeHelper = new SurveyRuntimeHelper();
$SurveyRuntimeHelper->saveAllIfNeeded();
if (isCaptchaEnabled('saveandloadscreen', $oSurvey->usecaptcha)) {
$aLoadForm['aCaptcha']['show'] = true;
$aLoadForm['aCaptcha']['sImageUrl'] = Yii::app()->getController()->createUrl('/verification/image', array('sid' => $surveyid));
}
if (!empty($clienttoken)) {
$aLoadForm['sHiddenField'] = CHtml::hiddenField('token', $clienttoken);
}
$aLoadForm['aErrors'] = empty($aLoadErrorMsg) ? null : $aLoadErrorMsg; // Set tit to null if empty
$thissurvey['aLoadForm'] = $aLoadForm;
//$oTemplate->registerAssets();
$thissurvey['include_content'] = 'load';
Yii::app()->twigRenderer->renderTemplateFromFile("layout_global.twig", array('oSurvey' => Survey::model()->findByPk($surveyid), 'aSurveyInfo' => $thissurvey), false);
}
//check if token is in a valid time frame
//Check if TOKEN is used for EVERY PAGE
//This function fixes a bug where users able to submit two surveys/votes
//by checking that the token has not been used at each page displayed.
// bypass only this check at first page (Step=0) because
// 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) {
if (empty($tokenInstance) && $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)
if ($oToken->completed != 'N' && !empty($oToken->completed)) {
$sError = gT("This invitation has already been used.");
} elseif ($oToken->usesleft < 1) {
$sError = gT("This invitation has no uses left.");
} elseif (strtotime($now) < strtotime($oToken->validfrom)) {
$sError = gT("This invitation is not valid yet.");
} elseif (strtotime($now) > strtotime($oToken->validuntil)) {
$sError = gT("This invitation is not valid anymore.");
} else {
// This can not happen
$sError = gT("This is a controlled survey. You need a valid access code to participate.");
}
$aMessage = array(
gT("We are sorry but you are not allowed to enter this survey.")
);
$event = new PluginEvent('onSurveyDenied');
$event->set('surveyId', $surveyid);
$event->set('reason', 'invalidToken');
App()->getPluginManager()->dispatchEvent($event);
App()->getController()->renderExitMessage(
$surveyid,
'survey-notstart',
$aMessage,
null,
array($sError)
);
}
}
//Check to see if a refering URL has been captured.
if (!isset($_SESSION['survey_' . $surveyid]['refurl'])) {
$_SESSION['survey_' . $surveyid]['refurl'] = getReferringUrl(); // do not overwrite refurl
}
// Let's do this only if
// - a saved answer record hasn't been loaded through the saved feature
// - the survey is not anonymous
// - the survey is active
// - a token information has been provided
// - the survey is setup to allow token-response-persistence
if (!isset($_SESSION['survey_' . $surveyid]['srid']) && $thissurvey['anonymized'] == "N" && $thissurvey['active'] == "Y" && isset($token) && $token != '') {
// load previous answers if any (dataentry with nosubmit)
$oResponses = Response::model($surveyid)->findAllByAttributes(array(
'token' => $token
), array('order' => 'id DESC'));
if (!empty($oResponses)) {
/**
* We fire the response selection event when at least 1 response was found.
* If there is just 1 response the plugin still has to option to choose
* NOT to use it.
*/
$event = new PluginEvent('beforeLoadResponse');
$event->set('responses', $oResponses);
$event->set('surveyId', $surveyid);
App()->pluginManager->dispatchEvent($event);
$oResponse = $event->get('response');
// If $oResponse is false we act as if no response was found.
// This allows a plugin to deny continuing a response.
if ($oResponse !== false) {
// If plugin does not set a response we use the first one found, (this replicates pre-plugin behavior)
if (!isset($oResponse) && (!isset($oResponses[0]->submitdate) || $thissurvey['alloweditaftercompletion'] == 'Y') && $thissurvey['tokenanswerspersistence'] == 'Y') {
$oResponse = $oResponses[0];
}
if (isset($oResponse)) {
$_SESSION['survey_' . $surveyid]['srid'] = $oResponse->id;
if (!empty($oResponse->lastpage)) {
$_SESSION['survey_' . $surveyid]['LEMtokenResume'] = true;
// If the response was completed and user is allowed to edit after completion start at the beginning and not at the last page - just makes more sense
if (!($oResponse->submitdate && $thissurvey['alloweditaftercompletion'] == 'Y')) {
$_SESSION['survey_' . $surveyid]['step'] = $oResponse->lastpage;
}
}
buildsurveysession($surveyid);
// alloweditaftercompletion
if (!empty($oResponse->submitdate)) {
$_SESSION['survey_' . $surveyid]['maxstep'] = $_SESSION['survey_' . $surveyid]['totalsteps'];
}
loadanswers();
randomizationGroupsAndQuestions($surveyid);
initFieldArray($surveyid, $_SESSION['survey_' . $surveyid]['fieldmap']);
}
}
}
}
// Preview action : Preview right already tested before
if ($previewmode == 'previewgroup' || $previewmode == 'previewquestion') {
// Unset all SESSION: be sure to have the last version
unset($_SESSION['fieldmap-' . $surveyid . App()->language]); // Needed by createFieldMap: else fieldmap can be outdated
unset($_SESSION['survey_' . $surveyid]);
if ($param['action'] == 'previewgroup') {
$thissurvey['format'] = 'G';
} elseif ($param['action'] == 'previewquestion') {
$thissurvey['format'] = 'S';
}
buildsurveysession($surveyid, true);
randomizationGroupsAndQuestions($surveyid, true);
initFieldArray($surveyid, $_SESSION['survey_' . $surveyid]['fieldmap']);
}
// Reset the question timers in preview
if (!$isSurveyActive || $previewmode) {
resetQuestionTimers($surveyid);
}
sendCacheHeaders();
//Send local variables to the appropriate survey type
unset($redata);
$redata = compact(array_keys(get_defined_vars()));
Yii::import('application.helpers.SurveyRuntimeHelper');
$tmp = new SurveyRuntimeHelper();
// try {
$tmp->run($surveyid, $redata);
// } catch (WrongTemplateVersionException $ex) {
// echo $ex->getMessage();
// }
}
private function _getParameters($args = array(), $post = array())
{
$param = array();
if (@$args[0] == __CLASS__) {
array_shift($args);
}
$iArgCount = count($args);
if ($iArgCount % 2 == 0) {
for ($i = 0; $i < $iArgCount; $i += 2) {
//Sanitize input from URL with returnGlobal
$param[$args[$i]] = returnGlobal($args[$i], true);
}
}
// Need some $param (else PHP notice)
foreach (array('lang', 'action', 'newtest', 'qid', 'gid', 'sid', 'loadname', 'loadpass', 'scid', 'thisstep', 'move', 'token') as $sNeededParam) {
$param[$sNeededParam] = returnGlobal($sNeededParam, true);
}
return $param;
}
private function _loadRequiredHelpersAndLibraries()
{
//Load helpers, libraries and config vars
Yii::app()->loadHelper("database");
Yii::app()->loadHelper("frontend");
Yii::app()->loadHelper("surveytranslator");
}
private function _loadLimesurveyLang($mvSurveyIdOrBaseLang)
{
$oSurvey = Survey::model()->findByPk($mvSurveyIdOrBaseLang);
if ($oSurvey) {
$baselang = $oSurvey->language;
} elseif (!empty($mvSurveyIdOrBaseLang)) {
$baselang = $mvSurveyIdOrBaseLang;
} else {
$baselang = Yii::app()->getConfig('defaultlang');
}
App()->setLanguage($baselang);
}
private function _isClientTokenDifferentFromSessionToken($clientToken, $surveyid)
{
return $clientToken != '' && isset($_SESSION['survey_' . $surveyid]['token']) && $clientToken != $_SESSION['survey_' . $surveyid]['token'];
}
private function _isSurveyFinished($surveyid)
{
return isset($_SESSION['survey_' . $surveyid]['finished']) && $_SESSION['survey_' . $surveyid]['finished'] === true;
}
private function _surveyCantBeViewedWithCurrentPreviewAccess($surveyid, $bIsSurveyActive, $bSurveyExists)
{
$bSurveyPreviewRequireAuth = Yii::app()->getConfig('surveyPreview_require_Auth');
return $surveyid && $bIsSurveyActive === false && $bSurveyExists && isset($bSurveyPreviewRequireAuth) && $bSurveyPreviewRequireAuth == true && !$this->_canUserPreviewSurvey($surveyid);
}
private function _didSessionTimeout($surveyid)
{
return (!isset($_SESSION['survey_' . $surveyid]['step']) && null !== App()->request->getPost('thisstep'));
}
function _canUserPreviewSurvey($iSurveyID)
{
return Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'read');
}
function _userHasPreviewAccessSession($iSurveyID)
{
return (isset($_SESSION['USER_RIGHT_PREVIEW']) && ($_SESSION['USER_RIGHT_PREVIEW'] == $iSurveyID));
}
}
/* End of file survey.php */
/* Location: ./application/controllers/survey.php */