Skip to content

Commit

Permalink
Added feature: Question attributes are now real form elements when yo…
Browse files Browse the repository at this point in the history
…u add/edit a question

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_dev@7546 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
c-schmitz committed Aug 30, 2009
1 parent fe468ba commit 24e8460
Show file tree
Hide file tree
Showing 11 changed files with 329 additions and 253 deletions.
29 changes: 15 additions & 14 deletions admin/admin.php
Expand Up @@ -50,7 +50,7 @@



if ($action != 'showprintablesurvey')
if ($action != 'showprintablesurvey' && $action != 'ajaxquestionattributes')
{
$adminoutput = helpscreenscript();
$adminoutput .= "<table width='100%' border='0' cellpadding='0' cellspacing='0' >\n"
Expand Down Expand Up @@ -439,11 +439,11 @@

if (!isset($assessmentsoutput) && !isset($statisticsoutput) && !isset($browseoutput) && !isset($savedsurveyoutput) && !isset( $listcolumnoutput ) &&
!isset($dataentryoutput) && !isset($conditionsoutput) && !isset($importoldresponsesoutput) && !isset($exportspssoutput) && !isset($exportroutput) &&
!isset($vvoutput) && !isset($tokenoutput) && !isset($exportoutput) && !isset($templatesoutput) && !isset($iteratesurveyoutput) &&
!isset($vvoutput) && !isset($tokenoutput) && !isset($exportoutput) && !isset($templatesoutput) && !isset($iteratesurveyoutput) && $action!='ajaxquestionattributes' &&
(isset($surveyid) || $action=='listurveys' || $action=='personalsettings' || $action=='checksettings' || //Still to check
$action=='editsurvey' || $action=='updatesurvey' || $action=='ordergroups' ||
$action=='newsurvey' || $action=='listsurveys' ||
$action=='surveyrights' || $action=='quotas') )
$action=='surveyrights' || $action=='quotas' ))
{
if ($action=='editsurvey' || $action=='updatesurvey')
{
Expand All @@ -452,9 +452,9 @@
include('html.php');
}

if ($action=='addquestion' || $action=='copyquestion' || $action=='editquestion' ||
if ($action=='addquestion' || $action=='copyquestion' || $action=='editquestion' ||
$action=='orderquestions' || $action=='editattribute' || $action=='delattribute' ||
$action=='addattribute' )
$action=='addattribute' || $action=='ajaxquestionattributes')
{if($surrows['define_questions'] || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) {$_SESSION['FileManagerContext']="edit:question:$surveyid";include('questionhandling.php');}
else { include('access_denied.php');}
}
Expand All @@ -477,7 +477,7 @@
!isset($assessmentsoutput) && !isset($tokenoutput) && !isset($browseoutput) && !isset($exportspssoutput) && !isset($exportroutput) &&
!isset($dataentryoutput) && !isset($statisticsoutput)&& !isset($savedsurveyoutput) &&
!isset($exportoutput) && !isset($importoldresponsesoutput) && !isset($conditionsoutput) &&
!isset($vvoutput) && !isset($listcolumnoutput) && !isset($importlabelresources) && !isset($iteratesurveyoutput))
!isset($vvoutput) && !isset($listcolumnoutput) && !isset($importlabelresources) && !isset($iteratesurveyoutput) && $action!='ajaxquestionattributes' )
{
$adminoutput.= showadminmenu();
}
Expand All @@ -496,6 +496,7 @@
if (isset($answersummary )) {$adminoutput.= $answersummary;}
if (isset($cssummary )) {$adminoutput.= $cssummary;}
if (isset($listcolumnoutput)) {$adminoutput.= $listcolumnoutput;}
if (isset($ajaxoutput)) {$adminoutput.= $ajaxoutput;}


if (isset($editgroup)) {$adminoutput.= $editgroup;}
Expand Down Expand Up @@ -540,15 +541,15 @@
if (isset($exportroutput)) {$adminoutput.= $exportroutput;}


if (!isset($printablesurveyoutput) && ($subaction!='export'))
if (!isset($printablesurveyoutput) && $subaction!='export' && $action!='ajaxquestionattributes')
{
if (!isset($_SESSION['metaHeader'])) {$_SESSION['metaHeader']='';}
$adminoutput = getAdminHeader($_SESSION['metaHeader']).$adminoutput; // All future output is written into this and then outputted at the end of file
unset($_SESSION['metaHeader']);
$adminoutput.= "</td>\n".helpscreen()
. "\t</tr>\n"
. "</table>\n";
if (!isset($_SESSION['metaHeader'])) {$_SESSION['metaHeader']='';}

$adminoutput = getAdminHeader($_SESSION['metaHeader']).$adminoutput; // All future output is written into this and then outputted at the end of file
unset($_SESSION['metaHeader']);
$adminoutput.= "</td>\n".helpscreen()
. "\t</tr>\n"
. "</table>\n";
if(!isset($_SESSION['checksessionpost']))
$_SESSION['checksessionpost'] = '';
$adminoutput .= "<script type=\"text/javascript\">\n"
Expand Down
34 changes: 34 additions & 0 deletions admin/database.php
Expand Up @@ -423,6 +423,40 @@ function get_max_question_order($gid)
$attsql.='1=1';
db_execute_assoc($attsql) or safe_die ("Couldn't delete obsolete question attributes<br />".$attsql."<br />".$connect->ErrorMsg());


//now save all valid attributes
$validAttributes=$qattributes[$_POST['type']];
foreach ($validAttributes as $validAttribute)
{
if (isset($_POST[$validAttribute['name']]))
{

$query = "select qaid from ".db_table_name('question_attributes')."
WHERE attribute='".$validAttribute['name']."' AND qid=".$qid;
$result = $connect->Execute($query) or safe_die("Error updating attribute value<br />".$query."<br />".$connect->ErrorMsg());
if ($result->Recordcount()>0)
{
$query = "UPDATE ".db_table_name('question_attributes')."
SET value='{$_POST[$validAttribute['name']]}' WHERE attribute='".$validAttribute['name']."' AND qid=".$qid;
$result = $connect->Execute($query) or safe_die("Error updating attribute value<br />".$query."<br />".$connect->ErrorMsg());
}
else
{
$query = "INSERT into ".db_table_name('question_attributes')."
(qid, value, attribute) values ($qid,'{$_POST[$validAttribute['name']]}','{$validAttribute['name']}')";
$result = $connect->Execute($query) or safe_die("Error updating attribute value<br />".$query."<br />".$connect->ErrorMsg());
}
}
}

if (isset($_POST['attribute_value']) && (!empty($_POST['attribute_value']) || $_POST['attribute_value'] == "0"))
{
$query = "UPDATE ".db_table_name('question_attributes')."
SET value='{$_POST['attribute_value']}' WHERE qaid=".$postqaid." AND qid=".returnglobal('qid');
$result = $connect->Execute($query) or safe_die("Error<br />".$query."<br />".$connect->ErrorMsg());
}


$keepanswers = "1"; // Generally we try to keep answers if the question type has changed

// These are the questions types that have no answers and therefore we delete the answer in that case
Expand Down
72 changes: 1 addition & 71 deletions admin/html.php
Expand Up @@ -1217,7 +1217,7 @@
if (count(GetAdditionalLanguagesFromSurveyID($surveyid)) == 0)
{
$questionsummary .= "<a href=\"#\" accesskey='d' onclick=\"window.open('$scriptname?action=previewquestion&amp;sid=$surveyid&amp;qid=$qid', '_blank')\""
. "title=\"".$clang->gTview("Preview This Question")."\""
. "title=\"".$clang->gTview("Preview This Question")."\">"
. "<img src='$imagefiles/preview.png' alt='".$clang->gT("Preview This Question")."' name='previewquestionimg' /></a>\n"
. "<img src='$imagefiles/seperator.gif' alt='' />\n";
} else {
Expand Down Expand Up @@ -3573,74 +3573,4 @@ function replacenewline ($texttoreplace)

return $new_str;
}
/*
function questionjavascript($type, $qattributes)
{
$newquestion = "<script type='text/javascript'>\n"
. "<!--\n";
$jc=0;
$newquestion .= "var qtypes = new Array();\n";
$newquestion .= "var qnames = new Array();\n\n";
foreach ($qattributes as $key=>$val)
{
foreach ($val as $vl)
{
$newquestion .= "qtypes[$jc]='".$key."';\n";
$newquestion .= "qnames[$jc]='".$vl['name']."';\n";
$jc++;
}
}
$newquestion .= " function buildQTlist(type)
{
document.getElementById('QTattributes').style.display='none';
for (var i=document.getElementById('QTlist').options.length-1; i>=0; i--)
{
document.getElementById('QTlist').options[i] = null;
}
for (var i=0;i<qtypes.length;i++)
{
if (qtypes[i] == type)
{
document.getElementById('QTattributes').style.display='';
document.getElementById('QTlist').options[document.getElementById('QTlist').options.length] = new Option(qnames[i], qnames[i]);
}
}
}";
$newquestion .="\nfunction OtherSelection(QuestionType)\n"
. "{\n"
. "if (QuestionType == '') {QuestionType=document.getElementById('question_type').value;}\n"
. "if (QuestionType == 'M' || QuestionType == 'P' || QuestionType == 'L' || QuestionType == '!')\n"
. "{\n"
. "document.getElementById('OtherSelection').style.display = '';\n"
. "document.getElementById('LabelSets').style.display = 'none';\n"
. "document.getElementById('Validation').style.display = 'none';\n"
. "}\n"
. "else if (QuestionType == 'F' || QuestionType == 'H' || QuestionType == 'W' || QuestionType == 'Z')\n"
. "{\n"
. "document.getElementById('LabelSets').style.display = '';\n"
. "document.getElementById('OtherSelection').style.display = 'none';\n"
. "document.getElementById('Validation').style.display = 'none';\n"
. "}\n"
. "else if (QuestionType == 'S' || QuestionType == 'T' || QuestionType == 'U' || QuestionType == 'N' || QuestionType=='')\n"
. "{\n"
. "document.getElementById('Validation').style.display = '';\n"
. "document.getElementById('OtherSelection').style.display ='none';\n"
. "document.getElementById('ON').checked = true;\n"
. "document.getElementById('LabelSets').style.display='none';\n"
. "}\n"
. "else\n"
. "{\n"
. "document.getElementById('LabelSets').style.display = 'none';\n"
. "document.getElementById('OtherSelection').style.display = 'none';\n"
. "document.getElementById('ON').checked = true;\n"
. "document.getElementById('Validation').style.display = 'none';\n"
//. "document.addnewquestion.other[1].checked = true;\n"
. "}\n"
. "buildQTlist(QuestionType);\n"
. "}\n"
. "OtherSelection('$type');\n"
. "-->\n"
. "</script>\n";
} */
?>
2 changes: 1 addition & 1 deletion admin/login_check.php
Expand Up @@ -245,4 +245,4 @@
$adminoutput.= "</table>\n";
}

?>
?>

0 comments on commit 24e8460

Please sign in to comment.