From c93a02511fbc9a9c2cefa073e08ef8b78954b27b Mon Sep 17 00:00:00 2001 From: Denis Chenu Date: Tue, 20 Jan 2015 18:03:50 +0100 Subject: [PATCH] Fixed issue #09467: Regenerate question code still usuable with activated survey Dev: update regenerate with Yii, control if able and remove the menu if not Dev: find only question of the default language , updateAll apply to other language --- application/controllers/admin/surveyadmin.php | 65 +++++++++---------- .../views/admin/survey/surveybar_view.php | 25 ++++--- 2 files changed, 46 insertions(+), 44 deletions(-) diff --git a/application/controllers/admin/surveyadmin.php b/application/controllers/admin/surveyadmin.php index 5ad9c733c24..13becfb8bae 100644 --- a/application/controllers/admin/surveyadmin.php +++ b/application/controllers/admin/surveyadmin.php @@ -66,43 +66,40 @@ public function index() public function regenquestioncodes($iSurveyID, $sSubAction ) { - if (Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'update')) + $clang = $this->getController()->lang; + if (!Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'update')) { - $clang = $this->getController()->lang; - - //Automatically renumbers the "question codes" so that they follow - //a methodical numbering method - $iQuestionNumber=1; - $iGroupNumber=0; - $iSequence=0; - $sQuery="SELECT a.qid, a.gid\n" - ."FROM {{questions}} as a, {{groups}} g " - ."WHERE a.gid=g.gid AND a.sid={$iSurveyID} AND a.parent_qid=0 " - ."GROUP BY a.gid, a.qid, g.group_order, question_order " - ."ORDER BY g.group_order, question_order"; - $arResult=dbExecuteAssoc($sQuery) or safe_die ("Error: ".$connect->ErrorMsg()); // Checked - $grows = array(); //Create an empty array in case FetchRow does not return any rows - foreach ($arResult->readAll() as $grow) {$grows[] = $grow;} // Get table output into array - foreach($grows as $grow) - { - //Go through all the questions - if ($sSubAction == 'bygroup' && (!isset($iGroupNumber) || $iGroupNumber != $grow['gid'])) - { //If we're doing this by group, restart the numbering when the group number changes - $iQuestionNumber=1; - $iGroupNumber = $grow['gid']; - $iSequence++; - } - $usql="UPDATE {{questions}} " - ."SET title='".(($sSubAction == 'bygroup') ? ('G' . $iSequence ) : '')."Q".str_pad($iQuestionNumber, 5, "0", STR_PAD_LEFT)."'\n" - ."WHERE qid=".$grow['qid']; - //$databaseoutput .= "[$sql]"; - $uresult=dbExecuteAssoc($usql) or safe_die("Error: ".$connect->ErrorMsg()); // Checked - $iQuestionNumber++; - $iGroupNumber=$grow['gid']; + Yii::app()->setFlashMessage($clang->gT("No access."),'error'); + $this->getController()->redirect(array('admin/survey','sa'=>'view','surveyid'=>$iSurveyID)); + } + $oSurvey=Survey::model()->findByPk($iSurveyID); + if ($oSurvey->active=='Y') + { + Yii::app()->setFlashMessage($clang->gT("You can't update question code for an active survey."),'error'); + $this->getController()->redirect(array('admin/survey','sa'=>'view','surveyid'=>$iSurveyID)); + } + //Automatically renumbers the "question codes" so that they follow + //a methodical numbering method + $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))); + 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 + $iQuestionNumber=1; + $iGroupNumber = $oQuestion->gid; + $iGroupSequence++; } - $_SESSION['flashmessage'] = $clang->gT("Question codes were successfully regenerated."); - LimeExpressionManager::SetDirtyFlag(); // so refreshes syntax highlighting + $sNewTitle=(($sSubAction == 'bygroup') ? ('G' . $iGroupSequence ) : '')."Q".str_pad($iQuestionNumber, 5, "0", STR_PAD_LEFT); + Question::model()->updateAll(array('title'=>$sNewTitle),'qid=:qid',array(':qid'=>$oQuestion->qid)); + $iQuestionNumber++; + $iGroupNumber=$oQuestion->gid; } + + Yii::app()->setFlashMessage($clang->gT("Question codes were successfully regenerated.")); + LimeExpressionManager::SetDirtyFlag(); // so refreshes syntax highlighting $this->getController()->redirect(array('admin/survey/sa/view/surveyid/' . $iSurveyID)); } diff --git a/application/views/admin/survey/surveybar_view.php b/application/views/admin/survey/surveybar_view.php index 60780ade9d9..ac93245b00d 100644 --- a/application/views/admin/survey/surveybar_view.php +++ b/application/views/admin/survey/surveybar_view.php @@ -125,20 +125,25 @@ ');" > eT("Reset conditions");?> - -
  • - - eT("Regenerate question codes");?> -
  • +