diff --git a/application/controllers/admin/surveyadmin.php b/application/controllers/admin/surveyadmin.php index 892cdd3a439..47c430f444c 100644 --- a/application/controllers/admin/surveyadmin.php +++ b/application/controllers/admin/surveyadmin.php @@ -3,27 +3,28 @@ 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. -*/ + * 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. + */ /** -* survey -* -* @package LimeSurvey -* @author The LimeSurvey Project team -* @copyright 2011 -* @version $Id: surveyaction.php 12301 2012-02-02 08:51:43Z c_schmitz $ -* @access public -*/ + * survey + * + * @package LimeSurvey + * @author The LimeSurvey Project team + * @copyright 2011 + * @version $Id: surveyaction.php 12301 2012-02-02 08:51:43Z c_schmitz $ + * @access public + */ class SurveyAdmin extends Survey_Common_Action { /** @@ -69,7 +70,8 @@ public function deleteMultiple() 'ext.admin.survey.ListSurveysWidget.views.massive_actions._action_results', array( 'aResults' => $aResults, - 'successLabel' => gT('Deleted')) + 'successLabel' => gT('Deleted') + ) ); } @@ -105,11 +107,20 @@ public function regenquestioncodes($iSurveyID, $sSubAction) $iQuestionNumber = 1; $iGroupNumber = 0; $iGroupSequence = 0; - $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))); + $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) + ) + ); foreach ($oQuestions as $oQuestion) { if ($sSubAction == 'bygroup' && $iGroupNumber != $oQuestion->gid) { -//If we're doing this by group, restart the numbering when the group number changes + //If we're doing this by group, restart the numbering when the group number changes $iQuestionNumber = 1; $iGroupNumber = $oQuestion->gid; $iGroupSequence++; @@ -187,7 +198,7 @@ public function editsurveysettings($iSurveyID) if (is_null($iSurveyID) || !$iSurveyID) { - $this->getController()->error('Invalid survey ID'); + $this->getController()->error('Invalid survey ID'); } if (!Permission::model()->hasSurveyPermission($iSurveyID, 'surveysettings', 'read')) { @@ -196,7 +207,7 @@ public function editsurveysettings($iSurveyID) } if (Yii::app()->request->isPostRequest) { - $this->update($iSurveyID); + $this->update($iSurveyID); } $this->_registerScriptFiles(); @@ -271,7 +282,7 @@ public function importsurveyresources() if (!is_dir($destdir)) { - mkdir($destdir); + mkdir($destdir); } $aImportedFilesInfo = array(); @@ -305,9 +316,9 @@ public function importsurveyresources() $this->getController()->redirect(array('admin/survey/sa/editlocalsettings/surveyid/'.$iSurveyID)); } $aData = array( - 'aErrorFilesInfo' => $aErrorFilesInfo, - 'aImportedFilesInfo' => $aImportedFilesInfo, - 'surveyid' => $iSurveyID + 'aErrorFilesInfo' => $aErrorFilesInfo, + 'aImportedFilesInfo' => $aImportedFilesInfo, + 'surveyid' => $iSurveyID ); $aData['display']['menu_bars']['surveysummary'] = true; $this->_renderWrappedTemplate('survey', 'importSurveyResources_view', $aData); @@ -344,11 +355,9 @@ public function togglequickaction() case null: $save = SettingsUser::setUserSetting('quickaction_state', 1); break; - case 0: $save = SettingsUser::setUserSetting('quickaction_state', 1); break; - case 1: $save = SettingsUser::setUserSetting('quickaction_state', 0); break; @@ -426,7 +435,7 @@ public function view($iSurveyID, $gid = null, $qid = null) $aData['last_question_name'] = $qrrow['title']; if ($qrrow['question']) { - $aData['last_question_name'] .= ' : '.$qrrow['question']; + $aData['last_question_name'] .= ' : '.$qrrow['question']; } $aData['last_question_link'] = $this->getController()->createUrl("admin/questions/sa/view/surveyid/$iSurveyID/gid/$iGid/qid/$iQid"); @@ -459,7 +468,7 @@ public function getAjaxQuestionGroupArray($surveyid) $lastquestion = getGlobalSetting($setting_entry); $setting_entry = 'last_question_'.Yii::app()->user->getId().'_'.$iSurveyID.'_gid'; $lastquestiongroup = getGlobalSetting($setting_entry); - + $aGroups = QuestionGroup::model()->findAllByAttributes(array('sid' => $iSurveyID, "language" => $baselang), array('order'=>'group_order ASC')); $aGroupViewable = array(); @@ -909,7 +918,7 @@ public function editSurvey_json() $operation = Yii::app()->request->getPost('oper'); $iSurveyIDs = Yii::app()->request->getPost('id'); if ($operation == 'del') { -// If operation is delete , it will delete, otherwise edit it + // If operation is delete , it will delete, otherwise edit it foreach (explode(',', $iSurveyIDs) as $iSurveyID) { if (Permission::model()->hasSurveyPermission($iSurveyID, 'survey', 'delete')) { Survey::model()->deleteSurvey($iSurveyID); @@ -926,12 +935,12 @@ public function editSurvey_json() * @param string $subaction * @return void */ - public function rendersidemenulink($iSurveyID, $subaction) - { - $aViewUrls = $aData = $activePanels = []; - $menuaction = (string) $subaction; - $iSurveyID = (int) $iSurveyID; - $survey = Survey::model()->findByPk($iSurveyID); + public function rendersidemenulink($iSurveyID, $subaction) + { + $aViewUrls = $aData = $activePanels = []; + $menuaction = (string) $subaction; + $iSurveyID = (int) $iSurveyID; + $survey = Survey::model()->findByPk($iSurveyID); //Get all languages $grplangs = $survey->additionalLanguages; @@ -979,18 +988,18 @@ public function rendersidemenulink($iSurveyID, $subaction) $aViewUrls[] = $menuEntry->template; $this->_renderWrappedTemplate('survey', $aViewUrls, $aData); - } + } /** * Edit surveytexts and general settings */ - public function surveygeneralsettings($iSurveyID) - { - $aViewUrls = $aData = array(); - $aData['surveyid'] = $iSurveyID = sanitize_int($iSurveyID); - $survey = Survey::model()->findByPk($iSurveyID); - $aData['oSurvey'] = $survey; + public function surveygeneralsettings($iSurveyID) + { + $aViewUrls = $aData = array(); + $aData['surveyid'] = $iSurveyID = sanitize_int($iSurveyID); + $survey = Survey::model()->findByPk($iSurveyID); + $aData['oSurvey'] = $survey; @@ -1064,7 +1073,7 @@ public function surveygeneralsettings($iSurveyID) $aViewUrls[] = 'editLocalSettings_main_view'; $this->_renderWrappedTemplate('survey', $aViewUrls, $aData); - } + } /** * Load editing of local settings of a survey screen. @@ -1080,8 +1089,8 @@ public function editlocalsettings($iSurveyID) $survey = Survey::model()->findByPk($iSurveyID); $aData['oSurvey'] = $survey; $this->getController()->redirect( - Yii::app()->createUrl('admin/survey/sa/rendersidemenulink', ['surveyid' => $iSurveyID, 'subaction' => 'generalsettings']) - ); + Yii::app()->createUrl('admin/survey/sa/rendersidemenulink', ['surveyid' => $iSurveyID, 'subaction' => 'generalsettings']) + ); return; if (Permission::model()->hasSurveyPermission($iSurveyID, 'surveylocale', 'read') || Permission::model()->hasSurveyPermission($iSurveyID, 'surveysettings', 'read')) { @@ -1299,10 +1308,10 @@ public function copy() } } } - if(!empty($aImportResults['newsid'])) { + if (!empty($aImportResults['newsid'])) { $oSurvey = Survey::model()->findByPk($aImportResults['newsid']); LimeExpressionManager::SetDirtyFlag(); - $oEM =& LimeExpressionManager::singleton(); + $oEM = LimeExpressionManager::singleton(); // Why this @ ! @LimeExpressionManager::UpgradeConditionsToRelevance($aImportResults['newsid']); @LimeExpressionManager::StartSurvey($oSurvey->sid,'survey',$oSurvey->attributes,true); @@ -1314,7 +1323,7 @@ public function copy() } @LimeExpressionManager::FinishProcessingPage(); } - + $this->_renderWrappedTemplate('survey', 'importSurvey_view', $aData); } @@ -1443,7 +1452,7 @@ private function _reorderGroup($iSurveyID) $qid = (int) substr($ID, 1); $gid = (int) substr($parent, 1); if (!isset($aQuestionOrder[$gid])) { - $aQuestionOrder[$gid] = 0; + $aQuestionOrder[$gid] = 0; } $sBaseLanguage = Survey::model()->findByPk($iSurveyID)->language; @@ -1451,7 +1460,7 @@ private function _reorderGroup($iSurveyID) $oldGid = $oQuestion['gid']; if ($oldGid != $gid) { - fixMovedQuestionConditions($qid, $oldGid, $gid, $iSurveyID); + fixMovedQuestionConditions($qid, $oldGid, $gid, $iSurveyID); } Question::model()->updateAll(array('question_order' => $aQuestionOrder[$gid], 'gid' => $gid), 'qid=:qid', array(':qid' => $qid)); Question::model()->updateAll(array('gid' => $gid), 'parent_qid=:parent_qid', array(':parent_qid' => $qid)); @@ -1520,10 +1529,10 @@ private function _generalTabNewSurvey() //Degrade gracefully to $siteadmin details if anything is missing. if (empty($owner['full_name'])) { - $owner['full_name'] = getGlobalSetting('siteadminname'); + $owner['full_name'] = getGlobalSetting('siteadminname'); } if (empty($owner['email'])) { - $owner['email'] = getGlobalSetting('siteadminemail'); + $owner['email'] = getGlobalSetting('siteadminemail'); } //Bounce setting by default to global if it set globally @@ -1539,7 +1548,7 @@ private function _generalTabNewSurvey() $aData['sRadixDefault'] = $aLanguageDetails['radixpoint']; $aData['sDateFormatDefault'] = $aLanguageDetails['dateformat']; $aRadixPointData = []; - foreach (getRadixPointData() as $index=>$radixptdata) { + foreach (getRadixPointData() as $index => $radixptdata) { $aRadixPointData[$index] = $radixptdata['desc']; } $aData['aRadixPointData'] = $aRadixPointData; @@ -1764,7 +1773,7 @@ private function _tabResourceManagement($survey) return $aData; } - function expire($iSurveyID) + public function expire($iSurveyID) { $iSurveyID = (int) $iSurveyID; if (!Permission::model()->hasSurveyPermission($iSurveyID, 'surveysettings', 'update')) { @@ -1825,9 +1834,9 @@ public function getUrlParamsJSON($iSurveyID) $iSurveyID = (int) $iSurveyID; $sBaseLanguage = Survey::model()->findByPk($iSurveyID)->language; $sQuery = "select '' as act, up.*,q.title, sq.title as sqtitle, q.question, sq.question as sqquestion from {{survey_url_parameters}} up - left join {{questions}} q on q.qid=up.targetqid - left join {{questions}} sq on sq.qid=up.targetsqid - where up.sid={$iSurveyID} and (q.language='{$sBaseLanguage}' or q.language is null) and (sq.language='{$sBaseLanguage}' or sq.language is null)"; + left join {{questions}} q on q.qid=up.targetqid + left join {{questions}} sq on sq.qid=up.targetsqid + where up.sid={$iSurveyID} and (q.language='{$sBaseLanguage}' or q.language is null) and (sq.language='{$sBaseLanguage}' or sq.language is null)"; $oResult = Yii::app()->db->createCommand($sQuery)->queryAll(); $aSurveyParameters = SurveyURLParameter::model()->findAll('sid=:sid', [':sid' => $iSurveyID]); $aData = array( @@ -1888,7 +1897,8 @@ public function insert($iSurveyID = null) ) ), false, - false); + false + ); } Yii::app()->loadHelper("surveytranslator"); @@ -1920,48 +1930,48 @@ public function insert($iSurveyID = null) // Insert base settings into surveys table $aInsertData = array( - 'expires' => $sExpiryDate, - 'startdate' => $sStartDate, - 'template' => App()->request->getPost('template'), - 'owner_id' => Yii::app()->session['loginID'], - 'admin' => App()->request->getPost('admin'), - 'active' => 'N', - 'anonymized' => App()->request->getPost('anonymized') == '1' ? 'Y' : 'N', - 'faxto' => App()->request->getPost('faxto'), - 'format' => App()->request->getPost('format'), - 'savetimings' => App()->request->getPost('savetimings') == '1' ? 'Y' : 'N', - 'language' => App()->request->getPost('language', Yii::app()->session['adminlang']), - 'datestamp' => App()->request->getPost('datestamp') == '1' ? 'Y' : 'N', - 'ipaddr' => App()->request->getPost('ipaddr') == '1' ? 'Y' : 'N', - 'refurl' => App()->request->getPost('refurl') == '1' ? 'Y' : 'N', - 'usecookie' => App()->request->getPost('usecookie') == '1' ? 'Y' : 'N', - 'emailnotificationto' => App()->request->getPost('emailnotificationto'), - 'allowregister' => App()->request->getPost('allowregister') == '1' ? 'Y' : 'N', - 'allowsave' => App()->request->getPost('allowsave') == '1' ? 'Y' : 'N', - 'navigationdelay' => App()->request->getPost('navigationdelay'), - 'autoredirect' => App()->request->getPost('autoredirect') == '1' ? 'Y' : 'N', - 'showxquestions' => App()->request->getPost('showxquestions') == '1' ? 'Y' : 'N', - 'showgroupinfo' => App()->request->getPost('showgroupinfo'), - 'showqnumcode' => App()->request->getPost('showqnumcode'), - 'shownoanswer' => App()->request->getPost('shownoanswer') == '1' ? 'Y' : 'N', - 'showwelcome' => App()->request->getPost('showwelcome') == '1' ? 'Y' : 'N', - 'allowprev' => App()->request->getPost('allowprev') == '1' ? 'Y' : 'N', - 'questionindex' => App()->request->getPost('questionindex'), - 'nokeyboard' => App()->request->getPost('nokeyboard') == '1' ? 'Y' : 'N', - 'showprogress' => App()->request->getPost('showprogress') == '1' ? 'Y' : 'N', - 'printanswers' => App()->request->getPost('printanswers') == '1' ? 'Y' : 'N', - 'listpublic' => App()->request->getPost('listpublic') == '1' ? 'Y' : 'N', - 'htmlemail' => App()->request->getPost('htmlemail') == '1' ? 'Y' : 'N', - 'sendconfirmation' => App()->request->getPost('sendconfirmation') == '1' ? 'Y' : 'N', - 'tokenanswerspersistence' => App()->request->getPost('tokenanswerspersistence') == '1' ? 'Y' : 'N', - 'alloweditaftercompletion' => App()->request->getPost('alloweditaftercompletion') == '1' ? 'Y' : 'N', - 'usecaptcha' => Survey::transcribeCaptchaOptions(), - 'publicstatistics' => App()->request->getPost('publicstatistics') == '1' ? 'Y' : 'N', - 'publicgraphs' => App()->request->getPost('publicgraphs') == '1' ? 'Y' : 'N', - 'assessments' => App()->request->getPost('assessments') == '1' ? 'Y' : 'N', - 'emailresponseto' => App()->request->getPost('emailresponseto'), - 'tokenlength' => $iTokenLength, - 'gsid' => App()->request->getPost('gsid', '1'), + 'expires' => $sExpiryDate, + 'startdate' => $sStartDate, + 'template' => App()->request->getPost('template'), + 'owner_id' => Yii::app()->session['loginID'], + 'admin' => App()->request->getPost('admin'), + 'active' => 'N', + 'anonymized' => App()->request->getPost('anonymized') == '1' ? 'Y' : 'N', + 'faxto' => App()->request->getPost('faxto'), + 'format' => App()->request->getPost('format'), + 'savetimings' => App()->request->getPost('savetimings') == '1' ? 'Y' : 'N', + 'language' => App()->request->getPost('language', Yii::app()->session['adminlang']), + 'datestamp' => App()->request->getPost('datestamp') == '1' ? 'Y' : 'N', + 'ipaddr' => App()->request->getPost('ipaddr') == '1' ? 'Y' : 'N', + 'refurl' => App()->request->getPost('refurl') == '1' ? 'Y' : 'N', + 'usecookie' => App()->request->getPost('usecookie') == '1' ? 'Y' : 'N', + 'emailnotificationto' => App()->request->getPost('emailnotificationto'), + 'allowregister' => App()->request->getPost('allowregister') == '1' ? 'Y' : 'N', + 'allowsave' => App()->request->getPost('allowsave') == '1' ? 'Y' : 'N', + 'navigationdelay' => App()->request->getPost('navigationdelay'), + 'autoredirect' => App()->request->getPost('autoredirect') == '1' ? 'Y' : 'N', + 'showxquestions' => App()->request->getPost('showxquestions') == '1' ? 'Y' : 'N', + 'showgroupinfo' => App()->request->getPost('showgroupinfo'), + 'showqnumcode' => App()->request->getPost('showqnumcode'), + 'shownoanswer' => App()->request->getPost('shownoanswer') == '1' ? 'Y' : 'N', + 'showwelcome' => App()->request->getPost('showwelcome') == '1' ? 'Y' : 'N', + 'allowprev' => App()->request->getPost('allowprev') == '1' ? 'Y' : 'N', + 'questionindex' => App()->request->getPost('questionindex'), + 'nokeyboard' => App()->request->getPost('nokeyboard') == '1' ? 'Y' : 'N', + 'showprogress' => App()->request->getPost('showprogress') == '1' ? 'Y' : 'N', + 'printanswers' => App()->request->getPost('printanswers') == '1' ? 'Y' : 'N', + 'listpublic' => App()->request->getPost('listpublic') == '1' ? 'Y' : 'N', + 'htmlemail' => App()->request->getPost('htmlemail') == '1' ? 'Y' : 'N', + 'sendconfirmation' => App()->request->getPost('sendconfirmation') == '1' ? 'Y' : 'N', + 'tokenanswerspersistence' => App()->request->getPost('tokenanswerspersistence') == '1' ? 'Y' : 'N', + 'alloweditaftercompletion' => App()->request->getPost('alloweditaftercompletion') == '1' ? 'Y' : 'N', + 'usecaptcha' => Survey::transcribeCaptchaOptions(), + 'publicstatistics' => App()->request->getPost('publicstatistics') == '1' ? 'Y' : 'N', + 'publicgraphs' => App()->request->getPost('publicgraphs') == '1' ? 'Y' : 'N', + 'assessments' => App()->request->getPost('assessments') == '1' ? 'Y' : 'N', + 'emailresponseto' => App()->request->getPost('emailresponseto'), + 'tokenlength' => $iTokenLength, + 'gsid' => App()->request->getPost('gsid', '1'), ); //var_dump($aInsertData); @@ -2048,15 +2058,15 @@ public function insert($iSurveyID = null) Yii::app()->setFlashMessage($warning.gT("Your new survey was created."), 'info'); } return Yii::app()->getController()->renderPartial( - '/admin/super/_renderJson', - array( - 'data' => array( - 'redirecturl' => $redirecturl, - ) - ), - false, - false - ); + '/admin/super/_renderJson', + array( + 'data' => array( + 'redirecturl' => $redirecturl, + ) + ), + false, + false + ); } $this->getController()->redirect(Yii::app()->request->urlReferrer); @@ -2118,5 +2128,4 @@ protected function _renderWrappedTemplate($sAction = 'survey', $aViewUrls = arra { parent::_renderWrappedTemplate($sAction, $aViewUrls, $aData, $sRenderFile); } - }