· 9 years ago · Oct 17, 2016, 09:28 AM
1<?php
2
3if (!defined('BASEPATH'))
4 exit('No direct script access allowed');
5/*
6* LimeSurvey
7* Copyright (C) 2007-2011 The LimeSurvey Project Team / Carsten Schmitz
8* All rights reserved.
9* License: GNU/GPL License v2 or later, see LICENSE.php
10* LimeSurvey is free software. This version may have been modified pursuant
11* to the GNU General Public License, and as distributed it includes or
12* is derivative of works licensed under the GNU General Public License or
13* other free or open source software licenses.
14* See COPYRIGHT.php for copyright notices and details.
15*/
16
17/**
18* survey
19*
20* @package LimeSurvey
21* @author The LimeSurvey Project team
22* @copyright 2011
23* @version $Id: surveyaction.php 12301 2012-02-02 08:51:43Z c_schmitz $
24* @access public
25*/
26class SurveyAdmin extends Survey_Common_Action
27{
28 /**
29 * Initiates the survey action, checks for superadmin permission
30 *
31 * @access public
32 * @param CController $controller
33 * @param string $id
34 */
35 public function __construct($controller, $id)
36 {
37 parent::__construct($controller, $id);
38 }
39
40 /**
41 * Loads list of surveys and its few quick properties.
42 *
43 * @access public
44 * @return void
45 */
46 public function index()
47 {
48 $this->getController()->redirect(array('admin/survey/sa/listsurveys'));
49 }
50
51 /**
52 * Delete multiple survey
53 */
54 public function deleteMultiple()
55 {
56 $aSurveys = json_decode(Yii::app()->request->getPost('sItems'));
57 $aResults = array();
58 foreach($aSurveys as $iSurveyID)
59 {
60 $oSurvey = Survey::model()->findByPk($iSurveyID);
61 $aResults[$iSurveyID]['title'] = $oSurvey->correct_relation_defaultlanguage->surveyls_title;
62 $aResults[$iSurveyID]['result'] = $oSurvey->deleteSurvey($iSurveyID, $recursive=true);
63 }
64
65 Yii::app()->getController()->renderPartial('ext.admin.survey.ListSurveysWidget.views.massive_actions._delete_results', array('aResults'=>$aResults));
66 }
67
68 public function listsurveys()
69 {
70 $aData = array();
71 $aData['model'] = new Survey('search');
72 $aData['fullpagebar']['button']['newsurvey'] = true;
73 $this->_renderWrappedTemplate('survey', 'listSurveys_view', $aData);
74 }
75
76
77 public function regenquestioncodes($iSurveyID, $sSubAction )
78 {
79 if (!Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'update'))
80 {
81 Yii::app()->setFlashMessage(gT("You do not have permission to access this page."),'error');
82 $this->getController()->redirect(array('admin/survey','sa'=>'view','surveyid'=>$iSurveyID));
83 }
84 $oSurvey=Survey::model()->findByPk($iSurveyID);
85 if ($oSurvey->active=='Y')
86 {
87 Yii::app()->setFlashMessage(gT("You can't update question code for an active survey."),'error');
88 $this->getController()->redirect(array('admin/survey','sa'=>'view','surveyid'=>$iSurveyID));
89 }
90 //Automatically renumbers the "question codes" so that they follow
91 //a methodical numbering method
92 $iQuestionNumber = 1;
93 $iGroupNumber = 0;
94 $iGroupSequence = 0;
95 $oQuestions = Question::model()->with('groups')->findAll(array('select'=>'t.qid,t.gid','condition'=>"t.sid=:sid and t.language=:language and parent_qid=0",'order'=>'groups.group_order, question_order','params'=>array(':sid'=>$iSurveyID,':language'=>$oSurvey->language)));
96
97 foreach ($oQuestions as $oQuestion)
98 {
99 if ($sSubAction == 'bygroup' && $iGroupNumber != $oQuestion->gid)
100 { //If we're doing this by group, restart the numbering when the group number changes
101 $iQuestionNumber =1;
102 $iGroupNumber = $oQuestion->gid;
103 $iGroupSequence++;
104 }
105 $sNewTitle=(($sSubAction == 'bygroup') ? ('G' . $iGroupSequence ) : '')."Q".str_pad($iQuestionNumber, 5, "0", STR_PAD_LEFT);
106 Question::model()->updateAll(array('title'=>$sNewTitle),'qid=:qid',array(':qid'=>$oQuestion->qid));
107 $iQuestionNumber++;
108 $iGroupNumber = $oQuestion->gid;
109 }
110 Yii::app()->setFlashMessage(gT("Question codes were successfully regenerated."));
111 LimeExpressionManager::SetDirtyFlag(); // so refreshes syntax highlighting
112 $this->getController()->redirect(array('admin/survey/sa/view/surveyid/' . $iSurveyID));
113 }
114
115
116 /**
117 * This function prepares the view for a new survey
118 *
119 */
120 public function test(){
121 $this->_renderWrappedTemplate("test/");
122 }
123 public function newsurvey()
124 {
125 App()->getClientScript()->registerPackage('jqgrid');
126 if (!Permission::model()->hasGlobalPermission('surveys','create'))
127 {
128 Yii::app()->user->setFlash('error', gT("Access denied"));
129 $this->getController()->redirect(Yii::app()->request->urlReferrer);
130 }
131
132 $this->_registerScriptFiles();
133 Yii::app()->loadHelper('surveytranslator');
134 $esrow = $this->_fetchSurveyInfo('newsurvey');
135 // Default setting is to use the global Google Analytics key If one exists
136 $globalKey = getGlobalSetting('googleanalyticsapikey');
137 if($globalKey != ""){
138 $esrow['googleanalyticsapikey'] = "9999useGlobal9999";
139 $esrow['googleanalyticsapikeysetting'] = "G";
140 }
141
142 Yii::app()->loadHelper('admin/htmleditor');
143
144 $aViewUrls['output'] = PrepareEditorScript(false, $this->getController());
145 $aData = $this->_generalTabNewSurvey();
146 $aData['esrow'] = $esrow;
147 $aData = array_merge($aData, $this->_tabPresentationNavigation($esrow));
148 $aData = array_merge($aData, $this->_tabPublicationAccess($esrow));
149 $aData = array_merge($aData, $this->_tabNotificationDataManagement($esrow));
150 $aData = array_merge($aData, $this->_tabTokens($esrow));
151
152 $aViewUrls[] = 'newSurvey_view';
153
154 $arrayed_data = array();
155 $arrayed_data['data'] = $aData;
156 $arrayed_data['title_bar']['title'] = gT('New survey');
157 $arrayed_data['fullpagebar']['savebutton']['form'] = 'addnewsurvey';
158 $arrayed_data['fullpagebar']['saveandclosebutton']['form'] = 'addnewsurvey';
159 $arrayed_data['fullpagebar']['closebutton']['url'] = 'admin/index';
160 $arrayed_data['fullpagebar']['delete']['url'] = 'admin/index';
161 $this->_renderWrappedTemplate('survey', $aViewUrls, $arrayed_data);
162 }
163
164 public function fakebrowser()
165 {
166 Yii::app()->getController()->renderPartial('/admin/survey/newSurveyBrowserMessage', array());
167 }
168
169 /**
170 * This function prepares the view for editing a survey
171 *
172 */
173 public function editsurveysettings($iSurveyID)
174 {
175 $iSurveyID = (int) $iSurveyID;
176 if (is_null($iSurveyID) || !$iSurveyID)
177 $this->getController()->error('Invalid survey ID');
178
179 if (!Permission::model()->hasSurveyPermission($iSurveyID, 'surveysettings', 'read') && !Permission::model()->hasGlobalPermission('surveys','read'))
180 {
181 Yii::app()->user->setFlash('error', gT("Access denied"));
182 $this->getController()->redirect(Yii::app()->request->urlReferrer);
183 }
184
185 if(Yii::app()->request->isPostRequest)
186 $this->update($iSurveyID);
187 $this->_registerScriptFiles();
188
189 //Yii::app()->loadHelper('text');
190 Yii::app()->loadHelper('surveytranslator');
191
192 Yii::app()->session['FileManagerContext'] = "edit:survey:{$iSurveyID}";
193
194 Yii::app()->loadHelper('/admin/htmleditor');
195 initKcfinder();
196
197 $esrow = self::_fetchSurveyInfo('editsurvey', $iSurveyID);
198
199 $aData = array();
200 $aData['esrow'] = $esrow;
201 $aData = array_merge($aData, $this->_generalTabEditSurvey($iSurveyID, $esrow));
202 $aData = array_merge($aData, $this->_tabPresentationNavigation($esrow));
203 $aData = array_merge($aData, $this->_tabPublicationAccess($esrow));
204 $aData = array_merge($aData, $this->_tabNotificationDataManagement($esrow));
205 $aData = array_merge($aData, $this->_tabTokens($esrow));
206 $aData = array_merge($aData, $this->_tabPanelIntegration($esrow));
207 $aData = array_merge($aData, $this->_tabResourceManagement($iSurveyID));
208
209 $oResult = Question::model()->getQuestionsWithSubQuestions($iSurveyID, $esrow['language'], "({{questions}}.type = 'T' OR {{questions}}.type = 'Q' OR {{questions}}.type = 'T' OR {{questions}}.type = 'S')");
210
211 $aData['questions'] = $oResult;
212 $aData['display']['menu_bars']['surveysummary'] = "editsurveysettings";
213 $tempData = $aData;
214 $aData['data'] = $tempData;
215
216
217 $surveyinfo = Survey::model()->findByPk($iSurveyID)->surveyinfo;
218 $aData['title_bar']['title'] = $surveyinfo['surveyls_title']." (".gT("ID").":".$iSurveyID.")";
219 $aData['sidemenu']['state'] = false;
220 $aData['surveybar']['savebutton']['form'] = 'frmeditgroup';
221 $aData['surveybar']['closebutton']['url'] = 'admin/survey/sa/view/surveyid/'.$iSurveyID; // Close button
222
223 }
224
225 /**
226 * Function responsible to import survey resources from a '.zip' file.
227 *
228 * @access public
229 * @return void
230 */
231 public function importsurveyresources()
232 {
233 $iSurveyID = Yii::app()->request->getPost('surveyid');
234
235 if (!empty($iSurveyID))
236 {
237
238
239 if (Yii::app()->getConfig('demoMode'))
240 {
241 Yii::app()->user->setFlash('error',gT("Demo mode only: Uploading files is disabled in this system."));
242 $this->getController()->redirect(array('admin/survey/sa/editlocalsettings/surveyid/' . $iSurveyID));
243 }
244
245 // Create temporary directory
246 // If dangerous content is unzipped
247 // then no one will know the path
248 $extractdir = $this->_tempdir(Yii::app()->getConfig('tempdir'));
249 $zipfilename = $_FILES['the_file']['tmp_name'];
250 $basedestdir = Yii::app()->getConfig('uploaddir') . "/surveys";
251 $destdir = $basedestdir . "/$iSurveyID/";
252
253 Yii::app()->loadLibrary('admin.pclzip');
254 $zip = new PclZip($zipfilename);
255
256 if (!is_writeable($basedestdir))
257 {
258 Yii::app()->user->setFlash('error',sprintf(gT("Incorrect permissions in your %s folder."), $basedestdir));
259 $this->getController()->redirect(array('admin/survey/sa/editlocalsettings/surveyid/' . $iSurveyID));
260 }
261
262
263 if (!is_dir($destdir))
264 mkdir($destdir);
265
266 $aImportedFilesInfo = array();
267 $aErrorFilesInfo = array();
268
269 if (is_file($zipfilename))
270 {
271 if ($zip->extract($extractdir) <= 0)
272 {
273 Yii::app()->user->setFlash('error',gT("This file is not a valid ZIP file archive. Import failed. "). $zip->errorInfo(true) );
274 $this->getController()->redirect(array('admin/survey/sa/editlocalsettings/surveyid/' . $iSurveyID));
275 }
276 // now read tempdir and copy authorized files only
277 $folders = array('flash', 'files', 'images');
278 foreach ($folders as $folder)
279 {
280 list($_aImportedFilesInfo, $_aErrorFilesInfo) = $this->_filterImportedResources($extractdir . "/" . $folder, $destdir . $folder);
281 $aImportedFilesInfo = array_merge($aImportedFilesInfo, $_aImportedFilesInfo);
282 $aErrorFilesInfo = array_merge($aErrorFilesInfo, $_aErrorFilesInfo);
283 }
284
285 // Deletes the temp directory
286 rmdirr($extractdir);
287
288 // Delete the temporary file
289 unlink($zipfilename);
290
291 if (is_null($aErrorFilesInfo) && is_null($aImportedFilesInfo))
292 {
293 Yii::app()->user->setFlash('error',gT("This ZIP archive contains no valid Resources files. Import failed."));
294 $this->getController()->redirect(array('admin/survey/sa/editlocalsettings/surveyid/' . $iSurveyID));
295 }
296 }
297 else
298 {
299 Yii::app()->setFlashMessage(gT("An error occurred uploading your file. This may be caused by incorrect permissions for the application /tmp folder."),'error');
300 $this->getController()->redirect(array('admin/survey/sa/editlocalsettings/surveyid/' . $iSurveyID));
301 }
302 $aData = array(
303 'aErrorFilesInfo' => $aErrorFilesInfo,
304 'aImportedFilesInfo' => $aImportedFilesInfo,
305 'surveyid' => $iSurveyID
306 );
307 $aData['display']['menu_bars']['surveysummary'] = true;
308 $this->_renderWrappedTemplate('survey', 'importSurveyResources_view', $aData);
309 }
310 }
311
312 public function changetemplate($iSurveyID, $template)
313 {
314 $iSurveyID = sanitize_int($iSurveyID);
315 $sTemplate = sanitize_paranoid_string($template);
316
317 $survey = Survey::model()->findByPk($iSurveyID);
318 $survey->template = $sTemplate;
319 $survey->save();
320 }
321
322 public function togglequickaction()
323 {
324 $setting_entry = 'quickaction_'.Yii::app()->user->getId();
325 $quickactionstate = getGlobalSetting($setting_entry);
326
327 switch ($quickactionstate)
328 {
329 // if the quickaction state is not set, then it's the first time user click on the chevron, then the state must be set to 0
330 case null:
331 setGlobalSetting($setting_entry, 0);
332 break;
333
334 case 0:
335 setGlobalSetting($setting_entry, 1);
336 break;
337
338 case 1:
339 setGlobalSetting($setting_entry, 0);
340 break;
341 }
342 }
343
344 /**
345 * Load complete view of survey properties and actions specified by $iSurveyID
346 *
347 * @access public
348 * @param mixed $iSurveyID
349 * @param mixed $gid
350 * @param mixed $qid
351 * @return void
352 */
353 public function view($iSurveyID, $gid = null, $qid = null)
354 {
355 $beforeSurveyAdminView = new PluginEvent('beforeSurveyAdminView');
356 $beforeSurveyAdminView->set('surveyId', $iSurveyID);
357 App()->getPluginManager()->dispatchEvent($beforeSurveyAdminView);
358
359 // We load the panel packages for quick actions
360 $iSurveyID = sanitize_int($iSurveyID);
361 $survey = Survey::model()->findByPk($iSurveyID);
362 $baselang = $survey->language;
363
364 $aData = array('aAdditionalLanguages' => $survey->additionalLanguages);
365
366 // Reinit LEMlang and LEMsid: ensure LEMlang are set to default lang, surveyid are set to this survey id
367 // Ensure Last GetLastPrettyPrintExpression get info from this sid and default lang
368 LimeExpressionManager::SetEMLanguage($baselang);
369 LimeExpressionManager::SetSurveyId($iSurveyID);
370 LimeExpressionManager::StartProcessingPage(false,true);
371
372 $surveyinfo = $survey->surveyinfo;
373 $aData['title_bar']['title'] = $surveyinfo['surveyls_title']." (".gT("ID").":".$iSurveyID.")";
374 $aData["surveyinfo"] = $surveyinfo;
375 $aData['surveyid'] = $iSurveyID;
376 $aData['display']['surveysummary'] = true;
377
378 // Last survey visited
379 $setting_entry = 'last_survey_'.Yii::app()->user->getId();
380 setGlobalSetting($setting_entry, $iSurveyID);
381
382 $aData['surveybar']['buttons']['view']= true;
383 $aData['surveybar']['returnbutton']['url'] = $this->getController()->createUrl("admin/survey/sa/listsurveys");
384 $aData['surveybar']['returnbutton']['text'] = gT('Return to survey list');
385 $aData['sidemenu']["survey_menu"]=TRUE;
386
387 // We get the last question visited by user for this survey
388 $setting_entry = 'last_question_'.Yii::app()->user->getId().'_'.$iSurveyID;
389 $lastquestion = getGlobalSetting($setting_entry);
390 $setting_entry = 'last_question_'.Yii::app()->user->getId().'_'.$iSurveyID.'_gid';
391
392 // We get the list of templates
393
394
395 //$setting_entry = 'last_question_gid'.Yii::app()->user->getId().'_'.$iSurveyID;
396 $lastquestiongroup = getGlobalSetting($setting_entry);
397
398 if( $lastquestion != null && $lastquestiongroup != null)
399 {
400 $aData['showLastQuestion'] = true;
401 $iQid = $lastquestion;
402 $iGid = $lastquestiongroup;
403 $qrrow = Question::model()->findByAttributes(array('qid' => $iQid, 'gid' => $iGid, 'sid' => $iSurveyID, 'language' => $baselang));
404
405 $aData['last_question_name'] = $qrrow['title'];
406 if($qrrow['question'])
407 $aData['last_question_name'] .= ' : '.$qrrow['question'];
408
409 $aData['last_question_link'] = $this->getController()->createUrl("admin/questions/sa/view/surveyid/$iSurveyID/gid/$iGid/qid/$iQid");
410 }
411 else
412 {
413 $aData['showLastQuestion'] = false;
414 }
415
416 $this->_renderWrappedTemplate('survey', array(), $aData);
417 }
418
419
420
421 /**
422 * Load list question groups view for a specified by $iSurveyID
423 *
424 * @access public
425 * @param mixed $surveyid The survey ID
426 * @return void
427 */
428 public function listquestiongroups($surveyid)
429 {
430 $iSurveyID = sanitize_int($surveyid);
431 // Reinit LEMlang and LEMsid: ensure LEMlang are set to default lang, surveyid are set to this survey id
432 // Ensure Last GetLastPrettyPrintExpression get info from this sid and default lang
433 LimeExpressionManager::SetEMLanguage(Survey::model()->findByPk($iSurveyID)->language);
434 LimeExpressionManager::SetSurveyId($iSurveyID);
435 LimeExpressionManager::StartProcessingPage(false,true);
436
437 $surveyinfo = Survey::model()->findByPk($iSurveyID)->surveyinfo;
438 $aData = array();
439
440 $aData['surveyid'] = $iSurveyID;
441 $aData['display']['menu_bars']['listquestiongroups'] = true;
442 $aData['sidemenu']['questiongroups'] = true;
443 $aData['sidemenu']['listquestiongroups'] = true;
444 $aData['surveybar']['buttons']['newgroup'] = true;
445 $aData["surveyinfo"] = $surveyinfo;
446 $aData['title_bar']['title'] = $surveyinfo['surveyls_title']." (".gT("ID").":".$iSurveyID.")";
447
448 $baselang = Survey::model()->findByPk($iSurveyID)->language;
449 $model = new QuestionGroup('search');
450
451 if (isset($_GET['QuestionGroup']))
452 {
453 $model->attributes = $_GET['QuestionGroup'];
454 }
455
456 if (isset($_GET['pageSize']))
457 {
458 Yii::app()->user->setState('pageSize',(int)$_GET['pageSize']);
459 }
460
461 $model['sid'] = $iSurveyID;
462 $model['language'] = $baselang;
463 $aData['model'] = $model;
464
465 $this->_renderWrappedTemplate('survey', array(), $aData);
466 }
467
468
469 /**
470 * Load list questions view for a specified survey by $surveyid
471 *
472 * @access public
473 * @param mixed $surveyid
474 * @return html
475 */
476 public function listquestions($surveyid)
477 {
478 $iSurveyID = sanitize_int($surveyid);
479 // Reinit LEMlang and LEMsid: ensure LEMlang are set to default lang, surveyid are set to this survey id
480 // Ensure Last GetLastPrettyPrintExpression get info from this sid and default lang
481 LimeExpressionManager::SetEMLanguage(Survey::model()->findByPk($iSurveyID)->language);
482 LimeExpressionManager::SetSurveyId($iSurveyID);
483 LimeExpressionManager::StartProcessingPage(false,true);
484
485 $oSurvey = Survey::model()->findByPk($iSurveyID);
486 $aData = array();
487
488 $aData['oSurvey'] = $oSurvey;
489 $aData['surveyid'] = $iSurveyID;
490 $aData['display']['menu_bars']['listquestions'] = true;
491 $aData['sidemenu']['listquestions'] = true;
492 $aData['surveybar']['returnbutton']['url'] = $this->getController()->createUrl("admin/survey/sa/listsurveys");
493 $aData['surveybar']['returnbutton']['text'] = gT('Return to survey list');
494 $aData['surveybar']['buttons']['newquestion'] = true;
495
496 $surveyinfo = $oSurvey->surveyinfo;
497 $aData["surveyinfo"] = $surveyinfo;
498 $aData["surveyHasGroup"] = $oSurvey->groups;
499 $aData['title_bar']['title'] = $surveyinfo['surveyls_title']." (".gT("ID").":".$iSurveyID.")";
500
501 $this->_renderWrappedTemplate('survey', array(), $aData);
502 }
503
504
505 /**
506 * Function responsible to deactivate a survey.
507 *
508 * @access public
509 * @param int $iSurveyID
510 * @return void
511 */
512 public function deactivate($iSurveyID = null)
513 {
514 $iSurveyID = Yii::app()->request->getPost('sid', $iSurveyID);
515 $iSurveyID = sanitize_int($iSurveyID);
516 $surveyinfo = Survey::model()->findByPk($iSurveyID)->surveyinfo;
517 $date = date('YmdHis'); //'His' adds 24hours+minutes to name to allow multiple deactiviations in a day
518 $aData = array();
519
520 $aData['aSurveysettings'] = getSurveyInfo($iSurveyID);
521 $aData['surveyid'] = $iSurveyID;
522 $aData['title_bar']['title'] = $surveyinfo['surveyls_title']." (".gT("ID").":".$iSurveyID.")";
523 $aData['surveybar']['closebutton']['url'] = 'admin/survey/sa/view/surveyid/'.$iSurveyID; // Close button
524
525 if (Yii::app()->request->getPost('ok')=='')
526 {
527 if (!tableExists('survey_'.$iSurveyID))
528 {
529 $_SESSION['flashmessage'] = gT("Error: Response table does not exist. Survey cannot be deactivated.");
530 $this->getController()->redirect($this->getController()->createUrl("admin/survey/sa/view/surveyid/{$iSurveyID}"));
531 }
532 $aData['surveyid'] = $iSurveyID;
533 $aData['date'] = $date;
534 $aData['dbprefix'] = Yii::app()->db->tablePrefix;
535 $aData['step1'] = true;
536 }
537 else
538 {
539 //See if there is a tokens table for this survey
540 if (tableExists("{{tokens_{$iSurveyID}}}"))
541 {
542 $toldtable = Yii::app()->db->tablePrefix."tokens_{$iSurveyID}";
543 $tnewtable = Yii::app()->db->tablePrefix."old_tokens_{$iSurveyID}_{$date}";
544 if (Yii::app()->db->getDriverName() == 'pgsql')
545 {
546 $tidDefault = Yii::app()->db->createCommand("SELECT pg_attrdef.adsrc FROM pg_attribute JOIN pg_class ON (pg_attribute.attrelid=pg_class.oid) JOIN pg_attrdef ON(pg_attribute.attrelid=pg_attrdef.adrelid AND pg_attribute.attnum=pg_attrdef.adnum) WHERE pg_class.relname='$toldtable' and pg_attribute.attname='tid'")->queryScalar();
547 if(preg_match("/nextval\('(tokens_\d+_tid_seq\d*)'::regclass\)/", $tidDefault, $matches)){
548 $oldSeq = $matches[1];
549 Yii::app()->db->createCommand()->renameTable($oldSeq, $tnewtable . '_tid_seq');
550 $setsequence = "ALTER TABLE ".Yii::app()->db->quoteTableName($toldtable)." ALTER COLUMN tid SET DEFAULT nextval('{$tnewtable}_tid_seq'::regclass);";
551 Yii::app()->db->createCommand($setsequence)->query();
552 }
553 }
554
555 Yii::app()->db->createCommand()->renameTable($toldtable, $tnewtable);
556
557 $aData['tnewtable'] = $tnewtable;
558 $aData['toldtable'] = $toldtable;
559
560 // Reset the session of the survey when deactivating it
561 killSurveySession($iSurveyID);
562 }
563
564 //Remove any survey_links to the CPDB
565 SurveyLink::model()->deleteLinksBySurvey($iSurveyID);
566
567
568 // IF there are any records in the saved_control table related to this survey, they have to be deleted
569 SavedControl::model()->deleteSomeRecords(array('sid' => $iSurveyID)); //Yii::app()->db->createCommand($query)->query();
570 $sOldSurveyTableName = Yii::app()->db->tablePrefix."survey_{$iSurveyID}";
571 $sNewSurveyTableName = Yii::app()->db->tablePrefix."old_survey_{$iSurveyID}_{$date}";
572 $aData['sNewSurveyTableName']=$sNewSurveyTableName;
573
574 $query = "SELECT id FROM ".Yii::app()->db->quoteTableName($sOldSurveyTableName)." ORDER BY id desc";
575 $sLastID = Yii::app()->db->createCommand($query)->limit(1)->queryScalar();
576 //Update the autonumber_start in the survey properties
577 $new_autonumber_start = $sLastID + 1;
578 $survey = Survey::model()->findByAttributes(array('sid' => $iSurveyID));
579 $survey->autonumber_start = $new_autonumber_start;
580 $survey->save();
581 if (Yii::app()->db->getDriverName() == 'pgsql')
582 {
583 $idDefault = Yii::app()->db->createCommand("SELECT pg_attrdef.adsrc FROM pg_attribute JOIN pg_class ON (pg_attribute.attrelid=pg_class.oid) JOIN pg_attrdef ON(pg_attribute.attrelid=pg_attrdef.adrelid AND pg_attribute.attnum=pg_attrdef.adnum) WHERE pg_class.relname='$sOldSurveyTableName' and pg_attribute.attname='id'")->queryScalar();
584 if(preg_match("/nextval\('(survey_\d+_id_seq\d*)'::regclass\)/", $idDefault, $matches)){
585 $oldSeq = $matches[1];
586 Yii::app()->db->createCommand()->renameTable($oldSeq, $sNewSurveyTableName . '_id_seq');
587 $setsequence = "ALTER TABLE ".Yii::app()->db->quoteTableName($sOldSurveyTableName)." ALTER COLUMN id SET DEFAULT nextval('{{{$sNewSurveyTableName}}}_id_seq'::regclass);";
588 Yii::app()->db->createCommand($setsequence)->query();
589 }
590 }
591
592 Yii::app()->db->createCommand()->renameTable($sOldSurveyTableName, $sNewSurveyTableName);
593
594 $survey->active = 'N';
595 $survey->save();
596
597 $prow = Survey::model()->find('sid = :sid', array(':sid' => $iSurveyID));
598 if ($prow->savetimings == "Y")
599 {
600 $sOldTimingsTableName = Yii::app()->db->tablePrefix."survey_{$iSurveyID}_timings";
601 $sNewTimingsTableName = Yii::app()->db->tablePrefix."old_survey_{$iSurveyID}_timings_{$date}";
602 Yii::app()->db->createCommand()->renameTable($sOldTimingsTableName, $sNewTimingsTableName);
603 $aData['sNewTimingsTableName'] = $sNewTimingsTableName;
604 }
605
606 $aData['surveyid'] = $iSurveyID;
607 Yii::app()->db->schema->refresh();
608 }
609
610 $aData['sidemenu']['state'] = false;
611 $aData['surveybar']['closebutton'] = false;
612 $this->_renderWrappedTemplate('survey', 'deactivateSurvey_view', $aData);
613 }
614
615 /**
616 * Function responsible to activate survey.
617 *
618 * @access public
619 * @param int $iSurveyID
620 * @return void
621 */
622 public function activate($iSurveyID)
623 {
624 if (!Permission::model()->hasSurveyPermission($iSurveyID, 'surveyactivation', 'update')) die();
625
626 $iSurveyID = (int) $iSurveyID;
627
628 $aData = array();
629 $aData['sidemenu']['state'] = false;
630 $aData['aSurveysettings'] = getSurveyInfo($iSurveyID);
631 $aData['surveyid'] = $iSurveyID;
632 $surveyinfo = Survey::model()->findByPk($iSurveyID)->surveyinfo;
633 $aData['title_bar']['title'] = $surveyinfo['surveyls_title']." (".gT("ID").":".$iSurveyID.")";
634 // Redirect if this is not possible
635 if (!isset($aData['aSurveysettings']['active']) || $aData['aSurveysettings']['active'] == 'Y')
636 {
637 Yii::app()->setFlashMessage(gT("This survey is already active."),'error');
638 $this->getController()->redirect(array('admin/survey','sa'=>'view','surveyid'=>$iSurveyID));
639
640 } $qtypes = getQuestionTypeList('', 'array');
641 Yii::app()->loadHelper("admin/activate");
642
643 if (Yii::app()->request->getPost('ok')=='')
644 {
645 if (isset($_GET['fixnumbering']) && $_GET['fixnumbering'])
646 {
647 fixNumbering($_GET['fixnumbering'], $iSurveyID);
648 }
649
650 // Check consistency for groups and questions
651 $failedgroupcheck = checkGroup($iSurveyID);
652 $failedcheck = checkQuestions($iSurveyID, $iSurveyID, $qtypes);
653
654 $aData['failedcheck'] = $failedcheck;
655 $aData['failedgroupcheck'] = $failedgroupcheck;
656 $aData['aSurveysettings'] = getSurveyInfo($iSurveyID);
657
658 $this->_renderWrappedTemplate('survey', 'activateSurvey_view', $aData);
659 }
660 else
661 {
662 $survey = Survey::model()->findByAttributes(array('sid' => $iSurveyID));
663 if (!is_null($survey))
664 {
665 $survey->anonymized = Yii::app()->request->getPost('anonymized');
666 $survey->datestamp = Yii::app()->request->getPost('datestamp');
667 $survey->ipaddr = Yii::app()->request->getPost('ipaddr');
668 $survey->refurl = Yii::app()->request->getPost('refurl');
669 $survey->savetimings = Yii::app()->request->getPost('savetimings');
670 $survey->save();
671 Survey::model()->resetCache(); // Make sure the saved values will be picked up
672 }
673
674 $aResult=activateSurvey($iSurveyID);
675 $aViewUrls = array();
676 if (isset($aResult['error']))
677 {
678 $aViewUrls['output']= "<br />\n<div class='messagebox ui-corner-all'>\n";
679 if ($aResult['error']=='surveytablecreation')
680 {
681 $aViewUrls['output'].="<div class='alert alert-warning' role='alert'>".gT("The survey response table could not be created.")." ".gT("Usually this is caused by having too many (sub-)questions in your survey. Please try removing questions from your survey.")."</div>\n";
682 }
683 else
684 {
685 $aViewUrls['output'].="<div class='alert alert-success' role='alert'>".gT("Timings table could not be created.")."</div>\n";
686 }
687 if(App()->getConfig('debug')) {
688 $aViewUrls['output'].="<strong class='text-warning'>" .
689 gT("Database error!!")."\n " ."\n" .
690 "<pre>".var_export ($aResult['error'],true)."</pre>\n";
691 }
692
693 $aViewUrls['output'].="<a href='".Yii::app()->getController()->createUrl("admin/survey/sa/view/surveyid/".$iSurveyID)."'>".gT("Main Admin Screen")."</a>\n</strong><br/>" ;
694 }
695 else
696 {
697 $warning = (isset($aResult['warning']))?true:false;
698 $allowregister = ($survey->allowregister=='Y')?true:false;
699 $onclickAction = convertGETtoPOST(Yii::app()->getController()->createUrl("admin/tokens/sa/index/surveyid/".$iSurveyID));
700 $closedOnclickAction = convertGETtoPOST(Yii::app()->getController()->createUrl("admin/tokens/sa/index/surveyid/".$iSurveyID));
701 $noOnclickAction = convertGETtoPOST(Yii::app()->getController()->createUrl("admin/survey/sa/view/surveyid/".$iSurveyID));
702
703 $activationData = array(
704 'iSurveyID'=>$iSurveyID,
705 'warning'=>$warning,
706 'allowregister'=>$allowregister,
707 'onclickAction'=>$onclickAction,
708 'closedOnclickAction'=>$closedOnclickAction,
709 'noOnclickAction'=>$noOnclickAction,
710 );
711 $aViewUrls['output'] = $this->getController()->renderPartial('/admin/survey/_activation_feedback', $activationData, true);
712
713 }
714 $this->_renderWrappedTemplate('survey', $aViewUrls, $aData);
715 }
716 }
717
718 /**
719 * Function responsible to delete a survey.
720 *
721 * @access public
722 * @param int $iSurveyID
723 * @return html
724 */
725 public function delete($iSurveyID)
726 {
727 $aData = $aViewUrls = array();
728 $aData['surveyid'] = $iSurveyID = (int) $iSurveyID;
729 $aData['sidemenu']['state'] = false;
730 $surveyinfo = Survey::model()->findByPk($iSurveyID)->surveyinfo;
731 $aData['title_bar']['title'] = $surveyinfo['surveyls_title']." (".gT("ID").":".$iSurveyID.")";
732 $aData['sidemenu']['state'] = false;
733 $aData['issuperadmin'] = Permission::model()->hasGlobalPermission('superadmin','read');
734 $this->_deleteSurvey($iSurveyID);
735 Yii::app()->session['flashmessage'] = gT("Survey deleted.");
736 $this->getController()->redirect(array("admin/survey/sa/listsurveys"));
737
738
739
740
741 $this->_renderWrappedTemplate('survey', $aViewUrls, $aData);
742 }
743
744 /**
745 * Takes the edit call from the detailed survey view, which either deletes the survey information
746 */
747 public function editSurvey_json()
748 {
749 $operation = Yii::app()->request->getPost('oper');
750 $iSurveyIDs = Yii::app()->request->getPost('id');
751 if ($operation == 'del') // If operation is delete , it will delete, otherwise edit it
752 {
753 foreach(explode(',',$iSurveyIDs) as $iSurveyID)
754 {
755 if (Permission::model()->hasSurveyPermission($iSurveyID, 'survey', 'delete'))
756 {
757 $this->_deleteSurvey($iSurveyID);
758 }
759 }
760 }
761 }
762 /**
763 * Load editing of local settings of a survey screen.
764 *
765 * @access public
766 * @param int $iSurveyID
767 * @return void
768 */
769 public function editlocalsettings($iSurveyID)
770 {
771 $aViewUrls = $aData = array();
772
773 $aData['surveyid'] = $iSurveyID = sanitize_int($iSurveyID);
774
775 if (Permission::model()->hasSurveyPermission($iSurveyID, 'surveylocale', 'read') || Permission::model()->hasSurveyPermission($iSurveyID, 'surveysettings', 'read'))
776 {
777 $this->_registerScriptFiles();
778
779 if (Permission::model()->hasSurveyPermission($iSurveyID, 'surveylocale', 'update'))
780 {
781 Yii::app()->session['FileManagerContext'] = "edit:survey:{$iSurveyID}";
782 }
783 $grplangs = Survey::model()->findByPk($iSurveyID)->additionalLanguages;
784 $baselang = Survey::model()->findByPk($iSurveyID)->language;
785 array_unshift($grplangs, $baselang);
786
787 Yii::app()->loadHelper("admin/htmleditor");
788
789 $aData['scripts'] = PrepareEditorScript(false, $this->getController());
790 $aTabTitles = $aTabContents= array();
791
792 foreach ($grplangs as $i => $sLang)
793 {
794 // this one is created to get the right default texts fo each language
795 Yii::app()->loadHelper('database');
796 Yii::app()->loadHelper('surveytranslator');
797
798 $esrow = SurveyLanguageSetting::model()->findByPk(array('surveyls_survey_id' => $iSurveyID, 'surveyls_language' => $sLang))->getAttributes();
799 $aTabTitles[$sLang] = getLanguageNameFromCode($esrow['surveyls_language'], false);
800
801 if ($esrow['surveyls_language'] == Survey::model()->findByPk($iSurveyID)->language)
802 {
803 $aTabTitles[$sLang] .= '(' . gT("Base language") . ')';
804 }
805
806 $aData['esrow'] = $esrow;
807 $aData['action'] = "editsurveylocalesettings";
808 $aData['i'] = $i;
809 $aData['dateformatdetails'] = getDateFormatData(Yii::app()->session['dateformat']);
810 $aTabContents[$sLang] = $this->getController()->renderPartial('/admin/survey/editLocalSettings_view', $aData, true);
811 }
812
813 unset($aData['i']);
814
815 $aData['has_permissions'] = Permission::model()->hasSurveyPermission($iSurveyID, 'surveylocale', 'update');
816 $aData['surveyls_language'] = $esrow["surveyls_language"];
817 $aData['aTabContents'] = $aTabContents;
818 $aData['aTabTitles'] = $aTabTitles;
819
820 $esrow = self::_fetchSurveyInfo('editsurvey', $iSurveyID);
821 $aData['esrow'] = $esrow;
822
823 $aData = array_merge($aData, $this->_generalTabEditSurvey($iSurveyID, $esrow));
824 $aData = array_merge($aData, $this->_tabPresentationNavigation($esrow));
825 $aData = array_merge($aData, $this->_tabPublicationAccess($esrow));
826 $aData = array_merge($aData, $this->_tabNotificationDataManagement($esrow));
827 $aData = array_merge($aData, $this->_tabTokens($esrow));
828 $aData = array_merge($aData, $this->_tabPanelIntegration($esrow));
829 $aData = array_merge($aData, $this->_tabResourceManagement($iSurveyID));
830
831 $oResult = Question::model()->getQuestionsWithSubQuestions($iSurveyID, $esrow['language'], "({{questions}}.type = 'T' OR {{questions}}.type = 'Q' OR {{questions}}.type = 'T' OR {{questions}}.type = 'S')");
832
833 $aData['questions'] = $oResult;
834 $aData['display']['menu_bars']['surveysummary'] = "editsurveysettings";
835 $tempData = $aData;
836 $aData['settings_data'] = $tempData;
837
838 $aData['sidemenu']['state'] = false;
839 $surveyinfo = Survey::model()->findByPk($iSurveyID)->surveyinfo;
840 $aData['title_bar']['title'] = $surveyinfo['surveyls_title']." (".gT("ID").":".$iSurveyID.")";
841
842 $aData['surveybar']['savebutton']['form'] = 'globalsetting';
843 $aData['surveybar']['savebutton']['useformid'] = 'true';
844 if (Permission::model()->hasSurveyPermission($iSurveyID, 'surveysettings', 'update') || Permission::model()->hasSurveyPermission($iSurveyID, 'surveylocale', 'update'))
845 {
846 $aData['surveybar']['saveandclosebutton']['form'] = true;
847 }
848 else
849 {
850 unset($aData['surveybar']['savebutton']['form']);
851 }
852
853 $aData['surveybar']['closebutton']['url'] = 'admin/survey/sa/view/surveyid/'.$iSurveyID; // Close button
854
855 $aViewUrls[] = 'editLocalSettings_main_view';
856 }
857 else
858 {
859 Yii::app()->setFlashMessage(gT("You do not have permission to access this page."),'error');
860 $this->getController()->redirect(array('admin/survey','sa'=>'view','surveyid'=>$iSurveyID));
861 }
862
863 $this->_renderWrappedTemplate('survey', $aViewUrls, $aData);
864 }
865
866 /**
867 * Function responsible to import/copy a survey based on $action.
868 *
869 * @access public
870 * @return void
871 */
872 public function copy()
873 {
874 $action = Yii::app()->request->getParam('action');
875 $iSurveyID = sanitize_int(Yii::app()->request->getParam('sid'));
876
877 if ($action == "importsurvey" || $action == "copysurvey")
878 {
879 // Start the HTML
880 $sExtension = "";
881
882 if ($action == 'importsurvey')
883 {
884 $aData = array();
885 $aData['sHeader'] = gT("Import survey data");
886 $aData['sSummaryHeader'] = gT("Survey structure import summary");
887 $aPathInfo = pathinfo($_FILES['the_file']['name']);
888
889 if (isset($aPathInfo['extension']))
890 {
891 $sExtension = $aPathInfo['extension'];
892 }
893
894 }
895 elseif ($action == 'copysurvey')
896 {
897 $aData = array();
898 $aData['sHeader'] = gT("Copy survey");
899 $aData['sSummaryHeader'] = gT("Survey copy summary");
900 }
901 // Start traitment and messagebox
902 $aData['bFailed'] = false; // Put a var for continue
903 $sFullFilepath = '';
904 if ($action == 'importsurvey')
905 {
906
907 $sFullFilepath = Yii::app()->getConfig('tempdir') . DIRECTORY_SEPARATOR . randomChars(30).'.'.$sExtension;
908 if ($_FILES['the_file']['error']==1 || $_FILES['the_file']['error']==2)
909 {
910 $aData['sErrorMessage']=sprintf(gT("Sorry, this file is too large. Only files up to %01.2f MB are allowed."), getMaximumFileUploadSize()/1024/1024).'<br>';
911 $aData['bFailed'] = true;
912 }
913 elseif (!in_array(strtolower($sExtension),array('lss','txt','tsv','lsa')))
914 {
915 $aData['sErrorMessage'] = sprintf(gT("Import failed. You specified an invalid file type '%s'."), $sExtension);
916 $aData['bFailed'] = true;
917 }
918 elseif ($aData['bFailed'] || !@move_uploaded_file($_FILES['the_file']['tmp_name'], $sFullFilepath))
919 {
920 $aData['sErrorMessage'] = gT("An error occurred uploading your file. This may be caused by incorrect permissions for the application /tmp folder.");
921 $aData['bFailed'] = true;
922 }
923 }
924 elseif ($action == 'copysurvey')
925 {
926 $iSurveyID = sanitize_int(Yii::app()->request->getParam('copysurveylist'));
927 $aExcludes = array();
928
929 $sNewSurveyName = Yii::app()->request->getPost('copysurveyname');
930
931 if (Yii::app()->request->getPost('copysurveyexcludequotas') == "1")
932 {
933 $aExcludes['quotas'] = true;
934 }
935 if (Yii::app()->request->getPost('copysurveyexcludepermissions') == "1")
936 {
937 $aExcludes['permissions'] = true;
938 }
939 if (Yii::app()->request->getPost('copysurveyexcludeanswers') == "1")
940 {
941 $aExcludes['answers'] = true;
942 }
943 if (Yii::app()->request->getPost('copysurveyresetconditions') == "1")
944 {
945 $aExcludes['conditions'] = true;
946 }
947 if (Yii::app()->request->getPost('copysurveyresetstartenddate') == "1")
948 {
949 $aExcludes['dates'] = true;
950 }
951 if (!$iSurveyID)
952 {
953 $aData['sErrorMessage'] = gT("No survey ID has been provided. Cannot copy survey");
954 $aData['bFailed'] = true;
955 }
956 elseif(!Survey::model()->findByPk($iSurveyID))
957 {
958 $aData['sErrorMessage'] = gT("Invalid survey ID");
959 $aData['bFailed'] = true;
960 }
961 elseif (!Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'export') && !Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'export'))
962 {
963 $aData['sErrorMessage'] = gT("We are sorry but you don't have permissions to do this.");
964 $aData['bFailed'] = true;
965 }
966 else
967 {
968 Yii::app()->loadHelper('export');
969 $copysurveydata = surveyGetXMLData($iSurveyID, $aExcludes);
970 }
971 }
972
973 // Now, we have the survey : start importing
974 Yii::app()->loadHelper('admin/import');
975
976 if ($action == 'importsurvey' && !$aData['bFailed'])
977 {
978 $aImportResults=importSurveyFile($sFullFilepath,(Yii::app()->request->getPost('translinksfields')=='1'));
979 if (is_null($aImportResults))
980 {
981 $aImportResults=array(
982 'error'=>gT("Unknown error while reading the file, no survey created.")
983 );
984 }
985 }
986 elseif ($action == 'copysurvey' && !$aData['bFailed'])
987 {
988 $aImportResults = XMLImportSurvey('', $copysurveydata, $sNewSurveyName, sanitize_int(App()->request->getParam('copysurveyid')), (Yii::app()->request->getPost('copysurveytranslinksfields')=='1'));
989 if (isset($aExcludes['conditions']))
990 {
991 Question::model()->updateAll(array('relevance'=>'1'),'sid='.$aImportResults['newsid']);
992 QuestionGroup::model()->updateAll(array('grelevance'=>'1'),'sid='.$aImportResults['newsid']);
993 }
994 if (!isset($aExcludes['permissions']))
995 {
996 Permission::model()->copySurveyPermissions($iSurveyID,$aImportResults['newsid']);
997 }
998 }
999 else
1000 {
1001 $aData['bFailed'] = true;
1002 }
1003 if ($action == 'importsurvey' && isset($sFullFilepath) && file_exists($sFullFilepath))
1004 {
1005 unlink($sFullFilepath);
1006 }
1007 if (!$aData['bFailed'])
1008 {
1009 $aData['aImportResults'] = $aImportResults;
1010 $aData['action'] = $action;
1011 if(isset($aImportResults['newsid']))
1012 {
1013 $aData['sLink'] = $this->getController()->createUrl('admin/survey/sa/view/surveyid/' . $aImportResults['newsid']);
1014 }
1015 }
1016
1017 }
1018
1019 $this->_renderWrappedTemplate('survey', 'importSurvey_view', $aData);
1020 }
1021
1022 /**
1023 * questiongroup::organize()
1024 * Load ordering of question group screen.
1025 *
1026 * @param int $iSurveyID
1027 * @return void
1028 */
1029 public function organize($iSurveyID)
1030 {
1031 $request = Yii::app()->request;
1032
1033 $iSurveyID = (int) $iSurveyID;
1034
1035 $thereIsPostData = $request->getPost('orgdata') !== null;
1036 $userHasPermissionToUpdate = Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'update');
1037
1038 if (!$userHasPermissionToUpdate)
1039 {
1040 Yii::app()->user->setFlash('error', gT("Access denied"));
1041 $this->getController()->redirect(Yii::app()->request->urlReferrer);
1042 }
1043
1044 if ($thereIsPostData)
1045 {
1046 // Save the new ordering
1047 $this->_reorderGroup($iSurveyID);
1048
1049 $closeAfterSave = $request->getPost('close-after-save') === 'true';
1050 if ($closeAfterSave)
1051 {
1052 $this->getController()->redirect(array('admin/survey/sa/view/surveyid/' . $iSurveyID));
1053 }
1054 else
1055 {
1056 $this->_showReorderForm($iSurveyID);
1057 }
1058 }
1059 else
1060 {
1061 $this->_showReorderForm($iSurveyID);
1062 }
1063 }
1064
1065
1066 /**
1067 * Called via ajax request from survey summary quick action "Show questions group by group"
1068 *
1069 */
1070 public function changeFormat($iSurveyID, $format)
1071 {
1072 if ( Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'update') )
1073 {
1074 if(in_array($format, array('S','G','A')))
1075 {
1076 $survey = Survey::model()->findByPk($iSurveyID);
1077 $survey->format = $format;
1078 $survey->save();
1079 echo $survey->format;
1080 }
1081 }
1082 }
1083
1084 /**
1085 * Show the form for Organize question groups/questions
1086 *
1087 * @todo Change function name to _showOrganizeGroupsAndQuestions?
1088 * @param int $iSurveyID
1089 * @return void
1090 */
1091 private function _showReorderForm($iSurveyID)
1092 {
1093 $surveyinfo = Survey::model()->findByPk($iSurveyID)->surveyinfo;
1094 $aData['title_bar']['title'] = $surveyinfo['surveyls_title']." (".gT("ID").":".$iSurveyID.")";
1095
1096 // Prepare data for the view
1097 $sBaseLanguage = Survey::model()->findByPk($iSurveyID)->language;
1098 LimeExpressionManager::StartSurvey($iSurveyID, 'survey');
1099 LimeExpressionManager::StartProcessingPage(true, Yii::app()->baseUrl);
1100
1101 $aGrouplist = QuestionGroup::model()->getGroups($iSurveyID);
1102 $initializedReplacementFields = false;
1103
1104 $aData['organizebar']['savebuttonright'] = true;
1105 $aData['organizebar']['closebuttonright']['url'] = $this->getController()->createUrl("admin/survey/sa/view/", array('surveyid' => $iSurveyID));
1106 $aData['organizebar']['saveandclosebuttonright']['url'] = true;
1107
1108 foreach ($aGrouplist as $iGID => $aGroup)
1109 {
1110 LimeExpressionManager::StartProcessingGroup($aGroup['gid'], false, $iSurveyID);
1111 if (!$initializedReplacementFields) {
1112 templatereplace("{SITENAME}"); // Hack to ensure the EM sets values of LimeReplacementFields
1113 $initializedReplacementFields = true;
1114 }
1115
1116 $oQuestionData = Question::model()->getQuestions($iSurveyID, $aGroup['gid'], $sBaseLanguage);
1117
1118 $qs = array();
1119 $junk = array();
1120
1121 foreach ($oQuestionData->readAll() as $q)
1122 {
1123 $relevance = ($q['relevance'] == '') ? 1 : $q['relevance'];
1124 $question = '[{' . $relevance . '}] ' . $q['question'];
1125 LimeExpressionManager::ProcessString($question, $q['qid']);
1126 $q['question'] = viewHelper::stripTagsEM(LimeExpressionManager::GetLastPrettyPrintExpression());
1127 $q['gid'] = $aGroup['gid'];
1128 $qs[] = $q;
1129 }
1130 $aGrouplist[$iGID]['questions'] = $qs;
1131 LimeExpressionManager::FinishProcessingGroup();
1132 }
1133 LimeExpressionManager::FinishProcessingPage();
1134
1135 $aData['aGroupsAndQuestions'] = $aGrouplist;
1136 $aData['surveyid'] = $iSurveyID;
1137
1138 $this->_renderWrappedTemplate('survey', 'organizeGroupsAndQuestions_view', $aData);
1139 }
1140
1141 private function _reorderGroup($iSurveyID)
1142 {
1143 $AOrgData = array();
1144 parse_str(Yii::app()->request->getPost('orgdata'), $AOrgData);
1145
1146 $grouporder = 0;
1147 foreach ($AOrgData['list'] as $ID => $parent)
1148 {
1149 if ($parent == 'root' && $ID[0] == 'g') {
1150 QuestionGroup::model()->updateAll(array('group_order' => $grouporder), 'gid=:gid', array(':gid' => (int)substr($ID, 1)));
1151 $grouporder++;
1152 }
1153 elseif ($ID[0] == 'q')
1154 {
1155 $qid = (int)substr($ID, 1);
1156 $gid = (int)substr($parent, 1);
1157 if (!isset($aQuestionOrder[$gid]))
1158 $aQuestionOrder[$gid] = 0;
1159
1160 $sBaseLanguage = Survey::model()->findByPk($iSurveyID)->language;
1161 $oQuestion = Question::model()->findByPk(array("qid"=>$qid,'language'=>$sBaseLanguage));
1162 $oldGid = $oQuestion['gid'];
1163
1164 if($oldGid != $gid) {
1165 fixMovedQuestionConditions($qid,$oldGid,$gid,$iSurveyID);
1166 }
1167 Question::model()->updateAll(array('question_order' => $aQuestionOrder[$gid], 'gid' => $gid), 'qid=:qid', array(':qid' => $qid));
1168 Question::model()->updateAll(array('gid' => $gid), 'parent_qid=:parent_qid', array(':parent_qid' => $qid));
1169 $aQuestionOrder[$gid]++;
1170 }
1171 }
1172 LimeExpressionManager::SetDirtyFlag(); // so refreshes syntax highlighting
1173 Yii::app()->session['flashmessage'] = gT("The new question group/question order was successfully saved.");
1174 }
1175
1176 /**
1177 * survey::_fetchSurveyInfo()
1178 * Load survey information based on $action.
1179 * @param mixed $action
1180 * @param mixed $iSurveyID
1181 * @return
1182 */
1183 private function _fetchSurveyInfo($action, $iSurveyID=null)
1184 {
1185 if ($action == 'newsurvey')
1186 {
1187 $oSurvey=new Survey;
1188 }
1189 elseif ($action == 'editsurvey' && $iSurveyID)
1190 {
1191 $oSurvey = Survey::model()->findByPk($iSurveyID);
1192 }
1193
1194 if($oSurvey)
1195 {
1196 $attribs = $oSurvey->attributes;
1197 $attribs['googleanalyticsapikeysetting'] = $oSurvey->getGoogleanalyticsapikeysetting();
1198 return $attribs;
1199 }
1200 }
1201
1202 /**
1203 * survey::_generalTabNewSurvey()
1204 * Load "General" tab of new survey screen.
1205 * @return
1206 */
1207 private function _generalTabNewSurvey()
1208 {
1209 //Use the current user details for the default administrator name and email for this survey
1210 $user=User::model()->findByPk(Yii::app()->session['loginID']);
1211 $owner =$user->attributes;
1212
1213 //Degrade gracefully to $siteadmin details if anything is missing.
1214 if (empty($owner['full_name']))
1215 $owner['full_name'] = getGlobalSetting('siteadminname');
1216 if (empty($owner['email']))
1217 $owner['email'] = getGlobalSetting('siteadminemail');
1218
1219 //Bounce setting by default to global if it set globally
1220 if (getGlobalSetting('bounceaccounttype') != 'off')
1221 {
1222 $owner['bounce_email'] = getGlobalSetting('siteadminbounce');
1223 }
1224 else
1225 {
1226 $owner['bounce_email'] = $owner['email'];
1227 }
1228
1229 $aData['action'] = "newsurvey";
1230 $aData['owner'] = $owner;
1231 $aLanguageDetails= getLanguageDetails(Yii::app()->session['adminlang']);
1232 $aData['sRadixDefault'] = $aLanguageDetails['radixpoint'];
1233 $aData['sDateFormatDefault'] = $aLanguageDetails['dateformat'];
1234 foreach (getRadixPointData() as $index=>$radixptdata){
1235 $aRadixPointData[$index]=$radixptdata['desc'];
1236 }
1237 $aData['aRadixPointData']=$aRadixPointData;
1238
1239 foreach (getDateFormatData (0,Yii::app()->session['adminlang']) as $index => $dateformatdata)
1240 {
1241 $aDateFormatData[$index]=$dateformatdata['dateformat'];
1242 }
1243 $aData['aDateFormatData']=$aDateFormatData;
1244
1245 return $aData;
1246 }
1247
1248 /**
1249 * survey::_generalTabEditSurvey()
1250 * Load "General" tab of edit survey screen.
1251 * @param mixed $iSurveyID
1252 * @param mixed $esrow
1253 * @return
1254 */
1255 private function _generalTabEditSurvey($iSurveyID, $esrow)
1256 {
1257 $aData['action'] = "editsurveysettings";
1258 $aData['esrow'] = $esrow;
1259 $aData['surveyid'] = $iSurveyID;
1260
1261 // Get users, but we only need id and name (NOT password etc)
1262 $users = getUserList();
1263 $aData['users'] = array();
1264 foreach ($users as $user)
1265 {
1266 $aData['users'][$user['uid']] = $user['user'].($user['full_name']?' - '.$user['full_name']:'');
1267 }
1268 // Sort users by name
1269 asort($aData['users']);
1270 $beforeSurveySettings = new PluginEvent('beforeSurveySettings');
1271 $beforeSurveySettings->set('survey', $iSurveyID);
1272 App()->getPluginManager()->dispatchEvent($beforeSurveySettings);
1273 $aData['pluginSettings'] = $beforeSurveySettings->get('surveysettings');
1274 return $aData;
1275 }
1276
1277 /**
1278 * survey::_tabPresentationNavigation()
1279 * Load "Presentation & navigation" tab.
1280 * @param mixed $esrow
1281 * @return
1282 */
1283 private function _tabPresentationNavigation($esrow)
1284 {
1285 global $showxquestions, $showgroupinfo, $showqnumcode;
1286
1287 Yii::app()->loadHelper('globalsettings');
1288
1289 $shownoanswer = getGlobalSetting('shownoanswer') ? getGlobalSetting('shownoanswer') : 'Y';
1290
1291 $aData = array();
1292 $aData['esrow'] = $esrow;
1293 $aData['shownoanswer'] = $shownoanswer;
1294 $aData['showxquestions'] = $showxquestions;
1295 $aData['showgroupinfo'] = $showgroupinfo;
1296 $aData['showqnumcode'] = $showqnumcode;
1297 return $aData;
1298 }
1299
1300 /**
1301 * survey::_tabPublicationAccess()
1302 * Load "Publication * access control" tab.
1303 * @param mixed $esrow
1304 * @return
1305 */
1306 private function _tabPublicationAccess($esrow)
1307 {
1308 $aDateFormatDetails = getDateFormatData(Yii::app()->session['dateformat']);
1309 $startdate = '';
1310 if ($esrow['startdate'])
1311 {
1312 Yii::app()->loadLibrary('Date_Time_Converter');
1313 $datetimeobj = new Date_Time_Converter($esrow["startdate"],"Y-m-d H:i:s"); //new Date_Time_Converter($esrow['startdate'] , "Y-m-d H:i:s");
1314 $startdate = $datetimeobj->convert($aDateFormatDetails['phpdate'].' H:i');
1315 }
1316
1317 $expires = '';
1318 if ($esrow['expires'])
1319 {
1320 Yii::app()->loadLibrary('Date_Time_Converter');
1321 $datetimeobj = new Date_Time_Converter($esrow['expires'], "Y-m-d H:i:s"); //new Date_Time_Converter($esrow['expires'] , "Y-m-d H:i:s");
1322 $expires = $datetimeobj->convert($aDateFormatDetails['phpdate'].' H:i');
1323 }
1324 $aData['dateformatdetails']= $aDateFormatDetails;
1325 $aData['esrow'] = $esrow;
1326 $aData['startdate'] = $startdate;
1327 $aData['expires'] = $expires;
1328 return $aData;
1329 }
1330
1331 /**
1332 * survey::_tabNotificationDataManagement()
1333 * Load "Notification & data management" tab.
1334 * @param mixed $esrow
1335 * @return
1336 */
1337 private function _tabNotificationDataManagement($esrow)
1338 {
1339 $aData['esrow'] = $esrow;
1340 return $aData;
1341 }
1342
1343 /**
1344 * survey::_tabTokens()
1345 * Load "Tokens" tab.
1346 * @param mixed $esrow
1347 * @return
1348 */
1349 private function _tabTokens($esrow)
1350 {
1351 $aData = array();
1352 $aData['esrow'] = $esrow;
1353 return $aData;
1354 }
1355
1356 private function _tabPanelIntegration($esrow)
1357 {
1358 $aData = array();
1359 return $aData;
1360 }
1361
1362 /**
1363 * survey::_tabImport()
1364 * Load "Import" tab.
1365 * @param mixed $iSurveyID
1366 * @return
1367 */
1368 private function _tabImport()
1369 {
1370 $aData = array();
1371 return $aData;
1372 }
1373
1374 /**
1375 * survey::_tabCopy()
1376 * Load "Copy" tab.
1377 * @param mixed $iSurveyID
1378 * @return
1379 */
1380 private function _tabCopy()
1381 {
1382 $aData = array();
1383 return $aData;
1384 }
1385
1386 /**
1387 * survey::_tabResourceManagement()
1388 * Load "Resources" tab.
1389 * @param mixed $iSurveyID
1390 * @return
1391 */
1392 private function _tabResourceManagement($iSurveyID)
1393 {
1394 global $sCKEditorURL;
1395
1396 // TAB Uploaded Resources Management
1397 $ZIPimportAction = " onclick='if (validatefilename(this.form,\"" . gT('Please select a file to import!', 'js') . "\")) { this.form.submit();}'";
1398 if (!function_exists("zip_open"))
1399 {
1400 $ZIPimportAction = " onclick='alert(\"" . gT("The ZIP library is not activated in your PHP configuration thus importing ZIP files is currently disabled.", "js") . "\");'";
1401 }
1402
1403 $disabledIfNoResources = '';
1404 if (hasResources($iSurveyID, 'survey') === false)
1405 {
1406 $disabledIfNoResources = " disabled='disabled'";
1407 }
1408 //$aData['esrow'] = $esrow;
1409 $aData['ZIPimportAction'] = $ZIPimportAction;
1410 $aData['disabledIfNoResources'] = $disabledIfNoResources;
1411 $dqata['sCKEditorURL'] = $sCKEditorURL;
1412
1413 return $aData;
1414 }
1415
1416 function expire($iSurveyID)
1417 {
1418 $iSurveyID = (int) $iSurveyID;
1419 if (!Permission::model()->hasSurveyPermission($iSurveyID, 'surveysettings', 'update'))
1420 {
1421 die();
1422 }
1423 Yii::app()->session['flashmessage'] = gT("The survey was successfully expired by setting an expiration date in the survey settings.");
1424 Survey::model()->expire($iSurveyID);
1425 $this->getController()->redirect(array('admin/survey/sa/view/surveyid/' . $iSurveyID));
1426 }
1427
1428 function getUrlParamsJSON($iSurveyID)
1429 {
1430 $iSurveyID = (int) $iSurveyID;
1431 $sBaseLanguage = Survey::model()->findByPk($iSurveyID)->language;
1432 $sQuery = "select '' as act, up.*,q.title, sq.title as sqtitle, q.question, sq.question as sqquestion from {{survey_url_parameters}} up
1433 left join {{questions}} q on q.qid=up.targetqid
1434 left join {{questions}} sq on sq.qid=up.targetsqid
1435 where up.sid={$iSurveyID} and (q.language='{$sBaseLanguage}' or q.language is null) and (sq.language='{$sBaseLanguage}' or sq.language is null)";
1436 $oResult = Yii::app()->db->createCommand($sQuery)->queryAll();
1437 $i = 0;
1438 $aData = new stdClass();
1439 foreach ($oResult as $oRow)
1440 {
1441 $aData->rows[$i]['id'] = $oRow['id'];
1442 if (!is_null($oRow['question']))
1443 {
1444 $oRow['title'] .= ': ' . ellipsize(flattenText($oRow['question'], false, true), 43, .70);
1445 }
1446 else
1447 {
1448 $oRow['title'] = gT('(No target question)');
1449 }
1450
1451 if ($oRow['sqquestion'] != '')
1452 {
1453 $oRow['title'] .= (' - ' . ellipsize(flattenText($oRow['sqquestion'], false, true), 30, .75));
1454 }
1455 unset($oRow['sqquestion']);
1456 unset($oRow['sqtitle']);
1457 unset($oRow['question']);
1458
1459 $aData->rows[$i]['cell'] = array_values($oRow);
1460 $i++;
1461 }
1462
1463 $aData->page = 1;
1464 $aData->records = count($oResult);
1465 $aData->total = 1;
1466
1467 echo ls_json_encode($aData);
1468 }
1469
1470 /**
1471 * This private function deletes a survey
1472 * Important: If you change this function also change the remotecontrol XMLRPC function
1473 *
1474 * @param mixed $iSurveyID The survey ID to delete
1475 */
1476 private function _deleteSurvey($iSurveyID)
1477 {
1478 Survey::model()->deleteSurvey($iSurveyID);
1479 rmdirr(Yii::app()->getConfig('uploaddir') . '/surveys/' . $iSurveyID);
1480 }
1481
1482 /**
1483 * Executes registerScriptFile for all needed script/style files
1484 *
1485 * @return void
1486 */
1487 private function _registerScriptFiles()
1488 {
1489 $this->registerScriptFile( 'ADMIN_SCRIPT_PATH', 'surveysettings.js');
1490 App()->getClientScript()->registerPackage('jquery-json');
1491 App()->getClientScript()->registerPackage('jqgrid');
1492
1493 }
1494
1495 /**
1496 * Saves the new survey after the creation screen is submitted
1497 *
1498 * @param $iSurveyID The survey id to be used for the new survey. If already taken a new random one will be used.
1499 */
1500 function insert($iSurveyID=null)
1501 {
1502 if (Permission::model()->hasGlobalPermission('surveys','create'))
1503 {
1504 // Check if survey title was set
1505 if (Yii::app()->request->getPost('surveyls_title')=='')
1506 {
1507 Yii::app()->session['flashmessage'] = gT("Survey could not be created because it did not have a title");
1508 redirect($this->getController()->createUrl('admin'));
1509 return;
1510 }
1511
1512 Yii::app()->loadHelper("surveytranslator");
1513 // If start date supplied convert it to the right format
1514 $aDateFormatData = getDateFormatData(Yii::app()->session['dateformat']);
1515 $sStartDate = Yii::app()->request->getPost('startdate');
1516 if (trim($sStartDate) != '')
1517 {
1518 Yii::import('application.libraries.Date_Time_Converter');
1519 $converter = new Date_Time_Converter($sStartDate, $aDateFormatData['phpdate'] . ' H:i:s');
1520 $sStartDate = $converter->convert("Y-m-d H:i:s");
1521 }
1522
1523 // If expiry date supplied convert it to the right format
1524 $sExpiryDate = Yii::app()->request->getPost('expires');
1525 if (trim($sExpiryDate) != '')
1526 {
1527 Yii::import('application.libraries.Date_Time_Converter');
1528 $converter = new Date_Time_Converter($sExpiryDate, $aDateFormatData['phpdate'] . ' H:i:s');
1529 $sExpiryDate = $converter->convert("Y-m-d H:i:s");
1530 }
1531
1532 $iTokenLength=(int)Yii::app()->request->getPost('tokenlength');
1533 //token length has to be at least 5, otherwise set it to default (15)
1534 if($iTokenLength < 5)
1535 {
1536 $iTokenLength = 15;
1537 }
1538 if($iTokenLength > 36)
1539 {
1540 $iTokenLength = 36;
1541 }
1542
1543 // Insert base settings into surveys table
1544 $aInsertData = array(
1545 'expires' => $sExpiryDate,
1546 'startdate' => $sStartDate,
1547 'template' => App()->request->getPost('template'),
1548 'owner_id' => Yii::app()->session['loginID'],
1549 'admin' => App()->request->getPost('admin'),
1550 'active' => 'N',
1551 'anonymized' => App()->request->getPost('anonymized')=='1'?'Y':'N',
1552 'faxto' => App()->request->getPost('faxto'),
1553 'format' => App()->request->getPost('format'),
1554 'savetimings' => App()->request->getPost('savetimings')=='1'?'Y':'N',
1555 'language' => App()->request->getPost('language'),
1556 'datestamp' => App()->request->getPost('datestamp')=='1'?'Y':'N',
1557 'ipaddr' => App()->request->getPost('ipaddr')=='1'?'Y':'N',
1558 'refurl' => App()->request->getPost('refurl')=='1'?'Y':'N',
1559 'usecookie' => App()->request->getPost('usecookie')=='1'?'Y':'N',
1560 'emailnotificationto' => App()->request->getPost('emailnotificationto'),
1561 'allowregister' => App()->request->getPost('allowregister')=='1'?'Y':'N',
1562 'allowsave' => App()->request->getPost('allowsave')=='1'?'Y':'N',
1563 'navigationdelay' => App()->request->getPost('navigationdelay'),
1564 'autoredirect' => App()->request->getPost('autoredirect')=='1'?'Y':'N',
1565 'showxquestions' => App()->request->getPost('showxquestions')=='1'?'Y':'N',
1566 'showgroupinfo' => App()->request->getPost('showgroupinfo'),
1567 'showqnumcode' => App()->request->getPost('showqnumcode'),
1568 'shownoanswer' => App()->request->getPost('shownoanswer')=='1'?'Y':'N',
1569 'showwelcome' => App()->request->getPost('showwelcome')=='1'?'Y':'N',
1570 'allowprev' => App()->request->getPost('allowprev')=='1'?'Y':'N',
1571 'questionindex' => App()->request->getPost('questionindex'),
1572 'nokeyboard' => App()->request->getPost('nokeyboard')=='1'?'Y':'N',
1573 'showprogress' => App()->request->getPost('showprogress')=='1'?'Y':'N',
1574 'printanswers' => App()->request->getPost('printanswers')=='1'?'Y':'N',
1575 'listpublic' => App()->request->getPost('listpublic')=='1'?'Y':'N',
1576 'htmlemail' => App()->request->getPost('htmlemail')=='1'?'Y':'N',
1577 'sendconfirmation' => App()->request->getPost('sendconfirmation')=='1'?'Y':'N',
1578 'tokenanswerspersistence' => App()->request->getPost('tokenanswerspersistence')=='1'?'Y':'N',
1579 'alloweditaftercompletion' => App()->request->getPost('alloweditaftercompletion')=='1'?'Y':'N',
1580 'usecaptcha' => Survey::transcribeCaptchaOptions(),
1581 'publicstatistics' => App()->request->getPost('publicstatistics')=='1'?'Y':'N',
1582 'publicgraphs' => App()->request->getPost('publicgraphs')=='1'?'Y':'N',
1583 'assessments' => App()->request->getPost('assessments')=='1'?'Y':'N',
1584 'emailresponseto' => App()->request->getPost('emailresponseto'),
1585 'tokenlength' => $iTokenLength,
1586 'expectedresponses' => App()->request->getPost('expected'),
1587 'location' => App()->request->getPost('location'),
1588 'gender' => App()->request->getPost('gender'),
1589 'age' => App()->request->getPost('Age'),
1590 'maritalstatus' => App()->request->getPost('marital'),
1591 );
1592
1593 $warning = '';
1594 // make sure we only update emails if they are valid
1595 if (Yii::app()->request->getPost('adminemail', '') == ''
1596 || validateEmailAddress(Yii::app()->request->getPost('adminemail'))) {
1597 $aInsertData['adminemail'] = Yii::app()->request->getPost('adminemail');
1598 } else {
1599 $aInsertData['adminemail'] = '';
1600 $warning .= gT("Warning! Notification email was not updated because it was not valid.").'<br/>';
1601 }
1602 if (Yii::app()->request->getPost('bounce_email', '') == ''
1603 || validateEmailAddress(Yii::app()->request->getPost('bounce_email'))) {
1604 $aInsertData['bounce_email'] = Yii::app()->request->getPost('bounce_email');
1605 } else {
1606 $aInsertData['bounce_email'] = '';
1607 $warning .= gT("Warning! Bounce email was not updated because it was not valid.").'<br/>';
1608 }
1609
1610 if (!is_null($iSurveyID))
1611 {
1612 $aInsertData['wishSID'] = $iSurveyID;
1613 }
1614
1615 $iNewSurveyid = Survey::model()->insertNewSurvey($aInsertData);
1616 if (!$iNewSurveyid)
1617 die('Survey could not be created.');
1618
1619 // Prepare locale data for surveys_language_settings table
1620 $sTitle = Yii::app()->request->getPost('surveyls_title');
1621 $sDescription = Yii::app()->request->getPost('description');
1622 $sWelcome = Yii::app()->request->getPost('welcome');
1623 $sURLDescription = Yii::app()->request->getPost('urldescrip');
1624
1625 $sTitle = html_entity_decode($sTitle, ENT_QUOTES, "UTF-8");
1626 $sDescription = html_entity_decode($sDescription, ENT_QUOTES, "UTF-8");
1627 $sWelcome = html_entity_decode($sWelcome, ENT_QUOTES, "UTF-8");
1628 $sURLDescription = html_entity_decode($sURLDescription, ENT_QUOTES, "UTF-8");
1629
1630 // Fix bug with FCKEditor saving strange BR types
1631 $sTitle = fixCKeditorText($sTitle);
1632 $sDescription = fixCKeditorText($sDescription);
1633 $sWelcome = fixCKeditorText($sWelcome);
1634
1635
1636 // Insert base language into surveys_language_settings table
1637 $aInsertData = array(
1638 'surveyls_survey_id' => $iNewSurveyid,
1639 'surveyls_title' => $sTitle,
1640 'surveyls_description' => $sDescription,
1641 'surveyls_welcometext' => $sWelcome,
1642 'surveyls_language' => Yii::app()->request->getPost('language'),
1643 'surveyls_urldescription' => Yii::app()->request->getPost('urldescrip'),
1644 'surveyls_endtext' => Yii::app()->request->getPost('endtext'),
1645 'surveyls_url' => Yii::app()->request->getPost('url'),
1646 'surveyls_dateformat' => (int) Yii::app()->request->getPost('dateformat'),
1647 'surveyls_numberformat' => (int) Yii::app()->request->getPost('numberformat'),
1648 );
1649
1650 $langsettings = new SurveyLanguageSetting;
1651 $langsettings->insertNewSurvey($aInsertData);
1652 // Update survey permissions
1653 Permission::model()->giveAllSurveyPermissions(Yii::app()->session['loginID'], $iNewSurveyid);
1654 // Now create a new dummy group
1655 // $aInsertData=array();
1656 // $aInsertData[Survey::model()->findByPk($iNewSurveyid)->language]=array(
1657 // 'sid' => $iNewSurveyid,
1658 // 'group_name' => gt('My first question group','html',Survey::model()->findByPk($iNewSurveyid)->language),
1659 // 'description' => '',
1660 // 'group_order' => 1,
1661 // 'language' => Survey::model()->findByPk($iNewSurveyid)->language,
1662 // 'grelevance' => '1');
1663 // $iNewGroupID=QuestionGroup::model()->insertNewGroup($aInsertData);
1664 // Now create a new dummy question
1665 // $oQuestion= new Question;
1666 // $oQuestion->sid = $iNewSurveyid;
1667 // $oQuestion->gid = $iNewGroupID;
1668 // $oQuestion->type = 'T';
1669 // $oQuestion->title = 'Q00';
1670 // $oQuestion->question = gt('A first example question. Please answer this question:','html',Survey::model()->findByPk($iNewSurveyid)->language);
1671 // $oQuestion->help = gt('This is a question help text.','html',Survey::model()->findByPk($iNewSurveyid)->language);
1672 // $oQuestion->mandatory = 'N';
1673 // $oQuestion->relevance = '1';
1674 // $oQuestion->question_order = 1;
1675 // $oQuestion->language = Survey::model()->findByPk($iNewSurveyid)->language;
1676 // $oQuestion->save();
1677 // $iNewQuestionID=$oQuestion->qid;
1678
1679 Yii::app()->setFlashMessage($warning.gT("Your new survey was successfully created"),'info');
1680
1681 if (App()->request->getPost('saveandclose'))
1682 {
1683 $this->getController()->redirect(array("admin/questions/sa/view/surveyid/{$iNewSurveyid}/gid/{$iNewGroupID}/qid/{$iNewQuestionID}"));
1684 }
1685 else
1686 {
1687 $this->getController()->redirect(array('admin/survey/sa/editlocalsettings/surveyid/' . $iNewSurveyid));
1688 }
1689
1690 }
1691 }
1692
1693 /**
1694 * Renders template(s) wrapped in header and footer
1695 *
1696 * @param string $sAction Current action, the folder to fetch views from
1697 * @param string|array $aViewUrls View url(s)
1698 * @param array $aData Data to be passed on. Optional.
1699 */
1700 protected function _renderWrappedTemplate($sAction = 'survey', $aViewUrls = array(), $aData = array())
1701 {
1702 parent::_renderWrappedTemplate($sAction, $aViewUrls, $aData);
1703 }
1704
1705}