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
  • Loading branch information
Shnoulle committed Jan 20, 2015
1 parent fee7fcb commit c93a025
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 44 deletions.
65 changes: 31 additions & 34 deletions application/controllers/admin/surveyadmin.php
Expand Up @@ -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));
}

Expand Down
25 changes: 15 additions & 10 deletions application/views/admin/survey/surveybar_view.php
Expand Up @@ -125,20 +125,25 @@
<?php } else {?>
<a href="#" onclick="alert('<?php $clang->eT("Currently there are no conditions configured for this survey.", "js"); ?>');" >
<img src='<?php echo $sImageURL;?>resetsurveylogic_disabled_30.png' alt=''/> <?php $clang->eT("Reset conditions");?></a>
<?php } ?>
</li><li>
<a href="#">
<img src='<?php echo $sImageURL;?>resetsurveylogic_30.png' alt=''/><?php $clang->eT("Regenerate question codes");?></a>
<ul>
<?php } ?>
</li>
<?php if(!$activated) { ?>
<li>
<a href="#">
<img src='<?php echo $sImageURL;?>resetsurveylogic_30.png' alt=''/><?php $clang->eT("Regenerate question codes");?></a>
<ul>
<li>
<a href="<?php echo $this->createUrl("/admin/survey/regenquestioncodes/surveyid/{$surveyid}/subaction/straight"); ?>">
<img src='<?php echo $sImageURL;?>resetsurveylogic_30.png' alt=''/><?php $clang->eT("Straight");?></a></li>
<a href="<?php echo $this->createUrl("/admin/survey/regenquestioncodes/surveyid/{$surveyid}/subaction/straight"); ?>">
<img src='<?php echo $sImageURL;?>resetsurveylogic_30.png' alt=''/><?php $clang->eT("Straight");?></a>
</li>
<li>
<a href="<?php echo $this->createUrl("/admin/survey/regenquestioncodes/surveyid/{$surveyid}/subaction/bygroup"); ?>">
<img src='<?php echo $sImageURL;?>resetsurveylogic_30.png' alt=''/><?php $clang->eT("By question group");?></a></li>
</ul>
<a href="<?php echo $this->createUrl("/admin/survey/regenquestioncodes/surveyid/{$surveyid}/subaction/bygroup"); ?>">
<img src='<?php echo $sImageURL;?>resetsurveylogic_30.png' alt=''/><?php $clang->eT("By question group");?></a>
</li>
</ul>
</li>
<?php } ?>
<?php } ?>
</ul>
</li>
<?php } ?>
Expand Down

0 comments on commit c93a025

Please sign in to comment.