diff --git a/application/controllers/admin/database.php b/application/controllers/admin/database.php index c0e5871a1b6..718d6075fac 100644 --- a/application/controllers/admin/database.php +++ b/application/controllers/admin/database.php @@ -35,14 +35,10 @@ function index($sa = null) $action=Yii::app()->request->getPost('action'); $clang = $this->getController()->lang; - $postsid=returnGlobal('sid'); - $postgid=returnGlobal('gid'); - $postqid=returnGlobal('qid'); - $postqaid=returnGlobal('qaid'); $databaseoutput = ''; - $surveyid = returnGlobal('sid'); - $gid = returnGlobal('gid'); - $qid = returnGlobal('qid'); + $surveyid = Yii::app()->request->getPost('sid'); + $gid = Yii::app()->request->getPost('gid'); + $qid = Yii::app()->request->getPost('qid'); // if $action is not passed, check post data. if(Yii::app()->getConfig('filterxsshtml') && Yii::app()->session['USER_RIGHT_SUPERADMIN'] != 1) @@ -113,7 +109,7 @@ function index($sa = null) { if (Yii::app()->request->getPost('defaultanswerscale_0_'.$language.'_0')) { - $this->_updateDefaultValues($postqid,0,0,'',$language,Yii::app()->request->getPost('defaultanswerscale_0_'.$language.'_0'),true); + $this->_updateDefaultValues($qid,0,0,'',$language,Yii::app()->request->getPost('defaultanswerscale_0_'.$language.'_0'),true); } } } @@ -145,13 +141,6 @@ function index($sa = null) $qproperties=$q->questionProperties(); $scalecount=$qproperties['answerscales']; - $count=0; - $invalidCode = 0; - $duplicateCode = 0; - - //require_once("../classes/inputfilter/class.inputfilter_clean.php"); - //$myFilter = new InputFilter('','',1,1,1); - //First delete all answers Answers::model()->deleteAllByAttributes(array('qid'=>$qid)); @@ -210,9 +199,6 @@ function index($sa = null) LimeExpressionManager::UpgradeConditionsToRelevance($surveyid); - if ($invalidCode == 1) $databaseoutput .= "\n"; - if ($duplicateCode == 1) $databaseoutput .= "\n"; - Yii::app()->session['flashmessage']= $clang->gT("Answer options were successfully saved."); if ($databaseoutput != '') @@ -239,8 +225,7 @@ function index($sa = null) $resrow = Questions::model()->with('question_types')->findByAttributes(array('qid'=>$qid)); $q = createQuestion($resrow->question_types['class']); - $qproperties=$q->questionProperties(); - $scalecount=$qproperties['answerscales']; + $scalecount=$q->questionProperties('subquestions'); $clang = $this->getController()->lang; // First delete any deleted ids @@ -281,28 +266,7 @@ function index($sa = null) $oldcodes[$postkey[2]][]=$postvalue; } } - $count=0; - $invalidCode = 0; - $duplicateCode = 0; - $dupanswers = array(); - /* - for ($scale_id=0;$scale_id<$scalecount;$scale_id++) - { - - // Find duplicate codes and add these to dupanswers array - $foundCat=array_count_values($codes); - foreach($foundCat as $key=>$value){ - if($value>=2){ - $dupanswers[]=$key; - } - } - } - */ - //require_once("../classes/inputfilter/class.inputfilter_clean.php"); - //$myFilter = new InputFilter('','',1,1,1); - - //$insertqids=array(); //? $insertqid =array(); for ($scale_id=0;$scale_id<$scalecount;$scale_id++) { @@ -326,7 +290,7 @@ function index($sa = null) { if (!isset($insertqid[$scale_id][$position])) { - $insertqid[$position]=Questions::model()->insertRecords(array('sid'=>$surveyid, 'gid'=>$gid, 'question_order'=>$position+1,'title'=>$codes[$scale_id][$position],'question'=>$subquestionvalue,'parent_qid'=>$qid,'language'=>$language,'scale_id'=>$scale_id)); + $insertqid[$scale_id][$position]=Questions::model()->insertRecords(array('sid'=>$surveyid, 'gid'=>$gid, 'question_order'=>$position+1,'title'=>$codes[$scale_id][$position],'question'=>$subquestionvalue,'parent_qid'=>$qid,'language'=>$language,'scale_id'=>$scale_id)); } else { @@ -474,7 +438,7 @@ function index($sa = null) $oldqid = $qr1['qid']; unset($qr1['qid']); } - $qr1['gid'] = $postgid; + $qr1['gid'] = $gid; $iInsertID = Questions::model()->insertRecords($qr1); if (!isset($qr1['qid'])) { @@ -779,39 +743,6 @@ function index($sa = null) Questions::model()->deleteAllByAttributes(array('parent_qid' => $qid), 'scale_id >= :scale_id', array(':scale_id' => $iSubquestionScales)); Yii::app()->session['flashmessage'] = $clang->gT("Question was successfully saved."); - // } - // else - // { - // - // // There are conditions constraints: alert the user - // $errormsg=""; - // if (!is_null($array_result['notAbove'])) - // { - // $errormsg.=$clang->gT("This question relies on other question's answers and can't be moved above groupId:","js") - // . " " . $array_result['notAbove'][0][0] . " " . $clang->gT("in position","js")." ".$array_result['notAbove'][0][1]."\\n" - // . $clang->gT("See conditions:")."\\n"; - // - // foreach ($array_result['notAbove'] as $notAboveCond) - // { - // $errormsg.="- cid:". $notAboveCond[3]."\\n"; - // } - // - // } - // if (!is_null($array_result['notBelow'])) - // { - // $errormsg.=$clang->gT("Some questions rely on this question's answers. You can't move this question below groupId:","js") - // . " " . $array_result['notBelow'][0][0] . " " . $clang->gT("in position","js")." ".$array_result['notBelow'][0][1]."\\n" - // . $clang->gT("See conditions:")."\\n"; - // - // foreach ($array_result['notBelow'] as $notBelowCond) - // { - // $errormsg.="- cid:". $notBelowCond[3]."\\n"; - // } - // } - // - // $databaseoutput .= "\n"; - // $gid= $oldgid; // group move impossible ==> keep display on oldgid - // } } else { @@ -895,7 +826,7 @@ function index($sa = null) 'surveyls_numberformat' => Yii::app()->request->getPost('numberformat_'.$langname) ); - Surveys_languagesettings::model()->updateByPk(array('surveyls_survey_id'=>$postsid, 'surveyls_language'=>$langname), $data); + Surveys_languagesettings::model()->updateByPk(array('surveyls_survey_id'=>$surveyid, 'surveyls_language'=>$langname), $data); } } Yii::app()->session['flashmessage'] = $clang->gT("Survey text elements successfully saved."); diff --git a/application/controllers/admin/surveyadmin.php b/application/controllers/admin/surveyadmin.php index fcb4cc6a3a7..5b7810e4b0e 100644 --- a/application/controllers/admin/surveyadmin.php +++ b/application/controllers/admin/surveyadmin.php @@ -172,9 +172,21 @@ function editsurveysettings($iSurveyID) $aData = array_merge($aData, $this->_tabPanelIntegration($esrow)); $aData = array_merge($aData, $this->_tabResourceManagement($iSurveyID)); - $oResult = Questions::model()->getQuestionsWithSubQuestions($iSurveyID, $esrow['language'], "({{questions}}.type = 'T' OR {{questions}}.type = 'Q' OR {{questions}}.type = 'S')"); //AJS - - $aData['questions'] = $oResult; + $oResult = Questions::model()->with('groups')->with('question_types')->with('parents')->findAllByAttributes(array('sid' => $iSurveyID, 'language' => $esrow['language']), array('index' => 'qid', 'order' => 'group_order, t.question_order')); + foreach ($oResult as $result) + { + $q = createQuestion(empty($result->question_types['class']) ? $oResult[$result['parent_qid']]->question_types['class'] : $result->question_types['class'] ); + if ($q->questionProperties('subquestions') && $result['parent_qid']) + { + $questions[] = array('qid' => $result['parent_qid'], 'sqid' => $result['qid'], 'title' => $result->parents['title'], 'question' => $result->parents['question'], 'sqquestion' => $result['question']); + } + else if ($q->questionProperties('hasdefaultvalues') && !$q->questionProperties('subquestions')) + { + $questions[] = array('qid' => $result['qid'], 'title' => $result['title'], 'question' => $result['question']); + } + } + + $aData['questions'] = $questions; $aData['display']['menu_bars']['surveysummary'] = "editsurveysettings"; $aData['data'] = $aData; @@ -1376,18 +1388,18 @@ function getUrlParamsJSON($iSurveyID) Yii::app()->loadHelper('database'); $oResult = dbExecuteAssoc("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 q.qid=up.targetqid + left join {{questions}} sq on sq.qid=up.targetsqid where up.sid={$iSurveyID}"); $i = 0; foreach ($oResult->readAll() as $oRow) { $aData->rows[$i]['id'] = $oRow['id']; - $oRow['title'] = $oRow['title'] . ': ' . ellipsize(flattenText($oRow['question'], false, true), 43, .70); + $oRow['title'] .= ': ' . ellipsize(flattenText($oRow['question'], false, true), 43, .70); if ($oRow['sqquestion'] != '') { - echo (' - ' . ellipsize(flattenText($oRow['sqquestion'], false, true), 30, .75)); + $oRow['title'] .= (' - ' . ellipsize(flattenText($oRow['sqquestion'], false, true), 30, .75)); } unset($oRow['sqquestion']); unset($oRow['sqtitle']); diff --git a/application/models/Questions.php b/application/models/Questions.php index 8cd0840a4a5..19d7044feee 100644 --- a/application/models/Questions.php +++ b/application/models/Questions.php @@ -214,25 +214,6 @@ function getSubQuestions($parent_qid) ->query(); } - function getQuestionsWithSubQuestions($iSurveyID, $sLanguage, $sCondition = FALSE) - { - $command = Yii::app()->db->createCommand() - ->select('{{questions}}.*, q.qid as sqid, q.title as sqtitle, q.question as sqquestion, ' . '{{groups}}.*') - ->from($this->tableName()) - ->leftJoin('{{questions}} q', "q.parent_qid = {{questions}}.qid AND q.language = {{questions}}.language") - ->join('{{groups}}', "{{groups}}.gid = {{questions}}.gid AND {{questions}}.language = {{groups}}.language"); - $command->where("({{questions}}.sid = '$iSurveyID' AND {{questions}}.language = '$sLanguage' AND {{questions}}.parent_qid = 0)"); - if ($sCondition != FALSE) - { - $command->where("({{questions}}.sid = :iSurveyID AND {{questions}}.language = :sLanguage AND {{questions}}.parent_qid = 0) AND {$sCondition}") - ->bindParam(":iSurveyID", $iSurveyID, PDO::PARAM_STR) - ->bindParam(":sLanguage", $sLanguage, PDO::PARAM_STR); - } - $command->order("{{groups}}.group_order asc, {{questions}}.question_order asc"); - - return $command->query()->readAll(); - } - /** * Insert an array into the questions table * Returns false if insertion fails, otherwise the new QID diff --git a/application/views/admin/survey/editSurvey_view.php b/application/views/admin/survey/editSurvey_view.php index 790e4d5292e..659c1f84398 100644 --- a/application/views/admin/survey/editSurvey_view.php +++ b/application/views/admin/survey/editSurvey_view.php @@ -36,8 +36,8 @@