Skip to content

Commit

Permalink
Fixed issue #09467: Regenerate question code still usuable with activ…
Browse files Browse the repository at this point in the history
…ated 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
Dev: from master c93a025
  • Loading branch information
Shnoulle committed Jan 20, 2015
1 parent 87be3d2 commit 5cf7d64
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 36 deletions.
62 changes: 29 additions & 33 deletions application/controllers/admin/surveyadmin.php
Expand Up @@ -66,42 +66,38 @@ public function index()

public function regenquestioncodes($iSurveyID, $sSubAction )
{
if (Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'update'))
if (!Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'update'))
{

//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(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(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'] = 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(gT("Question codes were successfully regenerated."));
LimeExpressionManager::SetDirtyFlag(); // so refreshes syntax highlighting
$this->getController()->redirect(array('admin/survey/sa/view/surveyid/' . $iSurveyID));
}

Expand Down
9 changes: 6 additions & 3 deletions application/views/admin/survey/surveybar_view.php
Expand Up @@ -125,11 +125,13 @@
<?php if ($conditionscount>0){?>
<a href="<?php echo $this->createUrl("/admin/conditions/sa/index/subaction/resetsurveylogic/surveyid/{$surveyid}"); ?>">
<img src='<?php echo $sImageURL;?>resetsurveylogic_30.png' alt=''/><?php eT("Reset conditions");?></a>
<?php } else {?>
<?php } else {?>
<a href="#" onclick="alert('<?php eT("Currently there are no conditions configured for this survey.", "js"); ?>');" >
<img src='<?php echo $sImageURL;?>resetsurveylogic_disabled_30.png' alt=''/> <?php eT("Reset conditions");?></a>
<?php } ?>
</li><li>
<?php } ?>
</li>
<?php if(!$activated) { ?>
<li>
<a href="#">
<img src='<?php echo $sImageURL;?>resetsurveylogic_30.png' alt=''/><?php eT("Regenerate question codes");?></a>
<ul>
Expand All @@ -142,6 +144,7 @@
</ul>
</li>
<?php } ?>
<?php } ?>
</ul>
</li>
<?php } ?>
Expand Down

0 comments on commit 5cf7d64

Please sign in to comment.