Skip to content

Commit

Permalink
Refactored ajaxquestionattributes() function
Browse files Browse the repository at this point in the history
git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_ci@11005 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
c-schmitz committed Sep 18, 2011
1 parent 4b0c517 commit 292515c
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 80 deletions.
115 changes: 37 additions & 78 deletions application/controllers/admin/question.php
Expand Up @@ -1792,106 +1792,65 @@ function delete()

/**
* question::ajaxquestionattributes()
* This function prepares the data for the advanced question attributes view
*
* @return
*/
function ajaxquestionattributes()
{
$this->load->model('questions_model');
$surveyid = $this->input->post("sid");
$languages=array_merge(array(GetBaseLanguageFromSurveyID($surveyid)),GetAdditionalLanguagesFromSurveyID($surveyid));
$qid = $this->input->post("qid");
$thissurvey=getSurveyInfo($surveyid);
$type=$this->input->post('question_type');
if ($qid != "undefined")

$aLanguages=array_merge(array(GetBaseLanguageFromSurveyID($surveyid)),GetAdditionalLanguagesFromSurveyID($surveyid));
$thissurvey=getSurveyInfo($surveyid);
if ($qid != "undefined") // question already exists
{
$attributesettings=getQuestionAttributeValues($qid, $type);
//$attributesettings=getQuestionAttributeValues($qid, $type);
$aAttributesWithValues=$this->questions_model->getAdvancedSettingsWithValues($qid, $type, $surveyid);
}
$availableattributes=questionAttributes();
if (isset($availableattributes[$type]))
else // question is just created
{
uasort($availableattributes[$type],'CategorySort');
$ajaxoutput = '';
$currentfieldset='';
foreach ($availableattributes[$type] as $qa)
{
$aAttributesWithValues=questionAttributes();
if (!isset($aAttributesWithValues[$type])) die('Invalid question type');
$aAttributesWithValues=$aAttributesWithValues[$type];
}
uasort($aAttributesWithValues,'CategorySort');

if ($currentfieldset!=$qa['category'])
{
if ($currentfieldset!='')
{
$ajaxoutput.='</ul></fieldset>';
}
$ajaxoutput.="<fieldset>\n";
$ajaxoutput.="<legend>{$qa['category']}</legend>\n<ul>";
$currentfieldset=$qa['category'];
}
foreach ($languages as $language)
$aAttributesPrepared=array();
foreach ($aAttributesWithValues as $iKey=>$aAttribute)
{
if ($aAttribute['i18n']==false)
{
$aAttributesPrepared[]=$aAttribute;
}
else // $qa['i18n'] == true
{
foreach($aLanguages as $sLanguage)
{

if ($qa['i18n']==false)
{
if (isset($attributesettings[$qa['name']]))
{
$value=$attributesettings[$qa['name']];
}
else
{
$value=$qa['default'];
}
$sFieldName =$qa['name'];
}
else // $qa['i18n'] == true
$aAttributeModified=$aAttribute;
$aAttributeModified['name']=$aAttributeModified['name'].'_'.$sLanguage;
$aAttributeModified['language']=$sLanguage;
if ($aAttributeModified['readonly']==true && $thissurvey['active']=='N')
{
if (isset($attributesettings[$qa['name']][$language]))
{
$value=$attributesettings[$qa['name']][$language];
}
else
{
$value=$qa['default'];
}
$sFieldName =$qa['name'].'_'.$language;
$aAttributeModified['readonly']==false;
}

$ajaxoutput .= "<li>"
."<label for='{$sFieldName}' title='".$qa['help']."'>".$qa['caption'];
if ($qa['i18n']==true) $ajaxoutput .=" ($language)";
$ajaxoutput.="</label>";

if (isset($qa['readonly']) && $qa['readonly']==true && $thissurvey['active']=='Y')
if (isset($aAttributeModified[$sLanguage]['value']))
{
$ajaxoutput .= "$value";
$aAttributeModified['value']=$aAttributeModified[$sLanguage]['value'];
}
else
{
switch ($qa['inputtype']){
case 'singleselect': $ajaxoutput .="<select id='{$sFieldName}' name='{$sFieldName}'>";
foreach($qa['options'] as $optionvalue=>$optiontext)
{
$ajaxoutput .="<option value='{$optionvalue}' ";
if ($value==$optionvalue)
{
$ajaxoutput .=" selected='selected' ";
}
$ajaxoutput .=">{$optiontext}</option>";
}
$ajaxoutput .="</select>";
break;
case 'text': $ajaxoutput .="<input type='text' id='{$sFieldName}' name='{$sFieldName}' value='{$value}' />";
break;
case 'integer': $ajaxoutput .="<input type='text' id='{$sFieldName}' name='{$sFieldName}' value='{$value}' />";
break;
case 'textarea':$ajaxoutput .= "<textarea id='{$sFieldName}' name='{$sFieldName}'>{$value}</textarea>";
break;
}
$aAttributeModified['value']=$aAttributeModified['default'];
}
$ajaxoutput .="</li>\n";
if ($qa['i18n']==false) break;
$aAttributesPrepared[]=$aAttributeModified;
}
}
$ajaxoutput .= "</ul></fieldset>";
echo $ajaxoutput;
}


$aData['attributedata']=$aAttributesPrepared;
$this->load->view('admin/survey/Question/advanced_settings_view',$aData);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions application/core/Survey_Common_Controller.php
Expand Up @@ -109,9 +109,9 @@ function _questionbar($surveyid,$gid,$qid,$action)
$data['clang'] = $clang;
$data['qrrow'] = $qrrow;
$data['baselang'] = $baselang;
$AttributesWithValues=$this->questions_model->getAdvancedSettingsWithValues($qid, $qrrow['type'], $surveyid, $baselang);
$aAttributesWithValues=$this->questions_model->getAdvancedSettingsWithValues($qid, $qrrow['type'], $surveyid, $baselang);
$DisplayArray=array();
foreach ($AttributesWithValues as $aAttribute)
foreach ($aAttributesWithValues as $aAttribute)
{
if (($aAttribute['i18n']==false && isset($aAttribute['value']) && $aAttribute['value']!=$aAttribute['default']) || ($aAttribute['i18n']==true && isset($aAttribute['value'][$baselang]) && $aAttribute['value'][$baselang]!=$aAttribute['default']))
{
Expand Down
55 changes: 55 additions & 0 deletions application/views/admin/survey/Question/advanced_settings_view.php
@@ -0,0 +1,55 @@
<?php
$currentfieldset='';
foreach ($attributedata as $aAttribute)
{
if ($currentfieldset!=$aAttribute['category'])
{
if ($currentfieldset!='')
{?>
</ul></fieldset>'; <?php
}
$currentfieldset=$aAttribute['category'];
?>
<fieldset>
<legend><?php echo $aAttribute['category'];?></legend>
<ul>
<?php
}?>
<li>
<label for='<?php echo $aAttribute['name'];?>' title='<?php echo $aAttribute['help'];?>'><?php echo $aAttribute['caption'];
if ($aAttribute['i18n']==true) { ?> (<?php echo $aAttribute['language'] ?>)<?php }?>
</label>
<?php
if ($aAttribute['readonly'])
{
echo $aAttribute['value'];
}
else
{
switch ($aAttribute['inputtype']){
case 'singleselect': echo "<select id='{$aAttribute['name']}' name='{$aAttribute['name']}'>";
foreach($aAttribute['options'] as $sOptionvalue=>$sOptiontext)
{
echo "<option value='{$sOptionvalue}' ";
if ($aAttribute['value']==$sOptionvalue)
{
echo " selected='selected' ";
}
echo ">{$sOptiontext}</option>";
}
echo "</select>";
break;
case 'text':?> <input type='text' id='<?php echo $aAttribute['name'];?>' name='<?php echo $aAttribute['name'];?>' value='<?php echo $aAttribute['value'];?>' />
<?php
break;
case 'integer':?> <input type='text' id='<?php echo $aAttribute['name'];?>' name='<?php echo $aAttribute['name'];?>' value='<?php echo $aAttribute['value'];?>' />
<?php
break;
case 'textarea':?> <textarea id='<?php echo $aAttribute['name'];?>' name='<?php echo $aAttribute['name'];?>'><?php echo $aAttribute['value'];?>' </textarea>
<?php
break;
}
}?>
</li>
<?php }?>
</ul></fieldset>

0 comments on commit 292515c

Please sign in to comment.