Skip to content

Commit

Permalink
Fixed issue #6683: Advanced multilingual settings not saved for new q…
Browse files Browse the repository at this point in the history
…uestion
  • Loading branch information
c-schmitz committed Oct 11, 2012
1 parent 0038f30 commit 77cf91b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 7 deletions.
64 changes: 57 additions & 7 deletions application/controllers/admin/database.php
Expand Up @@ -508,20 +508,70 @@ function index($sa = null)
} else {
$qattributes = questionAttributes();
$validAttributes = $qattributes[Yii::app()->request->getPost('type')];
$aLanguages=array_merge(array(Survey::model()->findByPk($surveyid)->language),Survey::model()->findByPk($surveyid)->additionalLanguages);

foreach ($validAttributes as $validAttribute)
{
if (Yii::app()->request->getPost($validAttribute['name']))
if ($validAttribute['i18n'])
{
$data = array(
'qid' => $qid,
'value' => Yii::app()->request->getPost($validAttribute['name']),
'attribute' => $validAttribute['name']
);
foreach ($aLanguages as $sLanguage)
{// TODO sanitise XSS
$value=Yii::app()->request->getPost($validAttribute['name'].'_'.$sLanguage);
$result = Question_attributes::model()->findAllByAttributes(array('attribute'=>$validAttribute['name'], 'qid'=>$qid, 'language'=>$sLanguage));
if (count($result)>0)
{
if ($value!='')
{
Question_attributes::model()->updateAll(array('value'=>$value), 'attribute=:attribute AND qid=:qid AND language=:language', array(':attribute'=>$validAttribute['name'], ':qid'=>$qid, ':language'=>$sLanguage));
}
else
{
Question_attributes::model()->deleteAll('attribute=:attribute AND qid=:qid AND language=:language', array(':attribute'=>$validAttribute['name'], ':qid'=>$qid, ':language'=>$sLanguage));
}
}
elseif($value!='')
{
$attribute = new Question_attributes;
$attribute->qid = $qid;
$attribute->value = $value;
$attribute->attribute = $validAttribute['name'];
$attribute->language = $sLanguage;
$attribute->save();
}
}
}
else
{
$value=Yii::app()->request->getPost($validAttribute['name']);

Question_attributes::model()->insertRecords($data);
if ($validAttribute['name']=='multiflexible_step' && trim($value)!='') {
$value=floatval($value);
if ($value==0) $value=1;
};

$result = Question_attributes::model()->findAllByAttributes(array('attribute'=>$validAttribute['name'], 'qid'=>$qid));
if (count($result)>0)
{
if($value!=$validAttribute['default'] && trim($value)!="")
{
Question_attributes::model()->updateAll(array('value'=>$value),'attribute=:attribute AND qid=:qid', array(':attribute'=>$validAttribute['name'], ':qid'=>$qid));
}
else
{
Question_attributes::model()->deleteAll('attribute=:attribute AND qid=:qid', array(':attribute'=>$validAttribute['name'], ':qid'=>$qid));
}
}
elseif($value!=$validAttribute['default'] && trim($value)!="")
{
$attribute = new Question_attributes;
$attribute->qid = $qid;
$attribute->value = $value;
$attribute->attribute = $validAttribute['name'];
$attribute->save();
}
}
}

}
Questions::model()->updateQuestionOrder($gid, $surveyid);
Yii::app()->session['flashmessage'] = $clang->gT("Question was successfully added.");
Expand Down
4 changes: 4 additions & 0 deletions application/helpers/common_helper.php
Expand Up @@ -3371,6 +3371,7 @@ function questionAttributes($returnByName=false)
'category'=>$clang->gT('Location'),
'sortorder'=>100,
'inputtype'=>'singleselect',
'default'=>0,
'options'=>array(0=>$clang->gT('Yes'),
1=>$clang->gT('No')),
"help"=>$clang->gT("Store the city?"),
Expand All @@ -3381,6 +3382,7 @@ function questionAttributes($returnByName=false)
'readonly_when_active'=>true,
'category'=>$clang->gT('Location'),
'sortorder'=>100,
'default'=>0,
'inputtype'=>'singleselect',
'options'=>array(0=>$clang->gT('Yes'),
1=>$clang->gT('No')),
Expand All @@ -3393,6 +3395,7 @@ function questionAttributes($returnByName=false)
'category'=>$clang->gT('Location'),
'sortorder'=>100,
'inputtype'=>'singleselect',
'default'=>0,
'options'=>array(0=>$clang->gT('Yes'),
1=>$clang->gT('No')),
"help"=>$clang->gT("Store the postal code?"),
Expand All @@ -3404,6 +3407,7 @@ function questionAttributes($returnByName=false)
'category'=>$clang->gT('Location'),
'sortorder'=>100,
'inputtype'=>'singleselect',
'default'=>0,
'options'=>array(0=>$clang->gT('Yes'),
1=>$clang->gT('No')),
"help"=>$clang->gT("Store the country?"),
Expand Down

0 comments on commit 77cf91b

Please sign in to comment.