Skip to content

Commit

Permalink
Fixed issue #13185: Rendering issue when adding new questions (Preview)
Browse files Browse the repository at this point in the history
  • Loading branch information
lacrioque committed Jan 31, 2018
1 parent 306712a commit 0afbe28
Showing 1 changed file with 49 additions and 20 deletions.
69 changes: 49 additions & 20 deletions application/controllers/admin/database.php
Expand Up @@ -33,6 +33,12 @@ class database extends Survey_Common_Action
*/
private $iQuestionID;

/**
* @var integer Survey id
*/
private $iSurveyID;


private $updateableFields = [
'owner_id' => ['type'=> '', 'default' => false, 'dbname'=>false, 'active'=>true, 'required'=>[]],
'admin' => ['type'=> '', 'default' => false, 'dbname'=>false, 'active'=>true, 'required'=>[]],
Expand Down Expand Up @@ -98,7 +104,7 @@ class database extends Survey_Common_Action
public function index()
{
$sAction = Yii::app()->request->getPost('action');
$iSurveyID = (isset($_POST['sid'])) ? (int) $_POST['sid'] : (int) returnGlobal('sid');
$this->iSurveyID = (isset($_POST['sid'])) ? (int) $_POST['sid'] : (int) returnGlobal('sid');

$this->iQuestionGroupID = (int) returnGlobal('gid');
$this->iQuestionID = (int) returnGlobal('qid');
Expand All @@ -107,28 +113,29 @@ public function index()
$this->oFixCKeditor->fixCKeditor = true;
$this->oFixCKeditor->xssfilter = false;

if ($sAction == "updatedefaultvalues" && Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'update')) {
$this->actionUpdateDefaultValues($iSurveyID);
if ($sAction == "updatedefaultvalues" && Permission::model()->hasSurveyPermission($this->iSurveyID, 'surveycontent', 'update')) {
$this->actionUpdateDefaultValues($this->iSurveyID);
}
if ($sAction == "updateansweroptions" && Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'update')) {
$this->actionUpdateAnswerOptions($iSurveyID);
if ($sAction == "updateansweroptions" && Permission::model()->hasSurveyPermission($this->iSurveyID, 'surveycontent', 'update')) {
$this->actionUpdateAnswerOptions($this->iSurveyID);
}
if ($sAction == "updatesubquestions" && Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'update')) {
$this->actionSubQuestions($iSurveyID);
if ($sAction == "updatesubquestions" && Permission::model()->hasSurveyPermission($this->iSurveyID, 'surveycontent', 'update')) {
$this->actionSubQuestions($this->iSurveyID);
}
if (in_array($sAction, array('insertquestion', 'copyquestion')) && Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'create')) {
$this->actionInsertCopyQuestion($iSurveyID);
if (in_array($sAction, array('insertquestion', 'copyquestion')) && Permission::model()->hasSurveyPermission($this->iSurveyID, 'surveycontent', 'create')) {
$this->actionInsertCopyQuestion($this->iSurveyID);
}
if ($sAction == "updatequestion" && Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'update')) {
$this->actionUpdateQuestion($iSurveyID);
if ($sAction == "updatequestion" && Permission::model()->hasSurveyPermission($this->iSurveyID, 'surveycontent', 'update')) {
$this->actionUpdateQuestion($this->iSurveyID);
}
if (($sAction == "updatesurveylocalesettings") && (Permission::model()->hasSurveyPermission($iSurveyID, 'surveylocale', 'update') || Permission::model()->hasSurveyPermission($iSurveyID, 'surveysettings', 'update'))) {
$this->actionUpdateSurveyLocaleSettings($iSurveyID);
if (($sAction == "updatesurveylocalesettings") && (Permission::model()->hasSurveyPermission($this->iSurveyID, 'surveylocale', 'update') || Permission::model()->hasSurveyPermission($iSurveyID, 'surveysettings', 'update'))) {
$this->actionUpdateSurveyLocaleSettings($this->iSurveyID);
}
if (($sAction == "updatesurveylocalesettings_generalsettings") && (Permission::model()->hasSurveyPermission($iSurveyID, 'surveylocale', 'update') || Permission::model()->hasSurveyPermission($iSurveyID, 'surveysettings', 'update'))) {
$this->actionUpdateSurveyLocaleSettingsGeneralSettings($iSurveyID);
if (($sAction == "updatesurveylocalesettings_generalsettings") && (Permission::model()->hasSurveyPermission($this->iSurveyID, 'surveylocale', 'update') || Permission::model()->hasSurveyPermission($iSurveyID, 'surveysettings', 'update'))) {
$this->actionUpdateSurveyLocaleSettingsGeneralSettings($this->iSurveyID);
}


//$this->getController()->redirect(array("/admin"), "refresh");
}

Expand Down Expand Up @@ -157,6 +164,8 @@ public function _updateDefaultValues($qid, $sqid, $scale_id, $specialtype, $lang
DefaultValue::model()->updateByPk(array('sqid'=>$sqid, 'qid'=>$qid, 'specialtype'=>$specialtype, 'scale_id'=>$scale_id, 'language'=>$language), array('defaultvalue'=>$defaultvalue));
}
}
$surveyid = $iSurveyID;
updateFieldArray();
}

/**
Expand Down Expand Up @@ -317,14 +326,16 @@ private function actionUpdateAnswerOptions($iSurveyID)
} // for ($sortorderid=0;$sortorderid<$maxcount;$sortorderid++)
}

//This is SUPER important! Recalculating the Expression Manager state!
LimeExpressionManager::SetDirtyFlag();
LimeExpressionManager::UpgradeConditionsToRelevance($iSurveyID);
$this->_resetEM();

if (!Yii::app()->request->getPost('bFullPOST')) {
Yii::app()->setFlashMessage(gT("Not all answer options were saved. This usually happens due to server limitations ( PHP setting max_input_vars) - please contact your system administrator."), 'error');
} else {
Yii::app()->setFlashMessage(gT("Answer options were successfully saved."));
}
//This is SUPER important! Recalculating the Expression Manager state!
LimeExpressionManager::SetDirtyFlag();
if (Yii::app()->request->getPost('close-after-save') === 'true') {
$this->getController()->redirect(array('admin/questions/sa/view/surveyid/'.$iSurveyID.'/gid/'.$this->iQuestionGroupID.'/qid/'.$this->iQuestionID));
}
Expand Down Expand Up @@ -496,7 +507,11 @@ private function actionSubQuestions($iSurveyID)
}
}

LimeExpressionManager::UpgradeConditionsToRelevance($iSurveyID); // Do it only if there are no error ?
//This is SUPER important! Recalculating the Expression Manager state!
LimeExpressionManager::SetDirtyFlag();
LimeExpressionManager::UpgradeConditionsToRelevance($iSurveyID);
$this->_resetEM();

if (!isset($aErrors) || !count($aErrors)) {
if (!Yii::app()->request->getPost('bFullPOST')) {
Yii::app()->session['flashmessage'] = gT("Not all subquestions were saved. This usually happens due to server limitations ( PHP setting max_input_vars) - please contact your system administrator.");
Expand All @@ -505,8 +520,6 @@ private function actionSubQuestions($iSurveyID)
}
}

//This is SUPER important! Recalculating the Expression Manager state!
LimeExpressionManager::SetDirtyFlag();
if (Yii::app()->request->getPost('close-after-save') === 'true') {
$this->getController()->redirect(array('/admin/questions/sa/view/surveyid/'.$iSurveyID.'/gid/'.$this->iQuestionGroupID.'/qid/'.$this->iQuestionID));
}
Expand Down Expand Up @@ -764,6 +777,7 @@ private function actionUpdateQuestion($iSurveyID)
//This is SUPER important! Recalculating the Expression Manager state!
LimeExpressionManager::SetDirtyFlag();
LimeExpressionManager::UpgradeConditionsToRelevance($iSurveyID);
$this->_resetEM();

$closeAfterSave = Yii::app()->request->getPost('close-after-save') === 'true';

Expand Down Expand Up @@ -992,6 +1006,8 @@ private function actionUpdateSurveyLocaleSettings($iSurveyID)
}
//This is SUPER important! Recalculating the Expression Manager state!
LimeExpressionManager::SetDirtyFlag();
$this->_resetEM();

if (Yii::app()->request->getPost('responsejson', 0) == 1) {

$updatedFields = $this->updatedFields;
Expand Down Expand Up @@ -1101,6 +1117,8 @@ protected function actionUpdateSurveyLocaleSettingsGeneralSettings($iSurveyID)

//This is SUPER important! Recalculating the Expression Manager state!
LimeExpressionManager::SetDirtyFlag();
$this->_resetEM();

// This will force the generation of the entry for survey group
TemplateConfiguration::checkAndcreateSurveyConfig($iSurveyID);

Expand Down Expand Up @@ -1399,6 +1417,10 @@ private function actionInsertCopyQuestion($iSurveyID)
}

}

LimeExpressionManager::SetDirtyFlag();
LimeExpressionManager::UpgradeConditionsToRelevance($iSurveyID);
$this->_resetEM();
Question::model()->updateQuestionOrder($this->iQuestionGroupID, $iSurveyID);
Yii::app()->session['flashmessage'] = gT("Question was successfully added.");

Expand All @@ -1415,4 +1437,11 @@ private function actionInsertCopyQuestion($iSurveyID)
$this->getController()->redirect($redirectLink);
}

private function _resetEM(){
$oSurvey = Survey::model()->findByPk($this->iSurveyID);
LimeExpressionManager::SetDirtyFlag();
$oEM =& LimeExpressionManager::singleton();
LimeExpressionManager::StartSurvey($oSurvey->sid,'survey',$oSurvey->attributes,true,$debugLevel=0);

}
}

0 comments on commit 0afbe28

Please sign in to comment.