Skip to content

Commit

Permalink
Fixed issue #04378: Copy question does not copy subquestions
Browse files Browse the repository at this point in the history
git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey@8779 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
c-schmitz committed Jun 2, 2010
1 parent ef58135 commit 442e652
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 61 deletions.
44 changes: 32 additions & 12 deletions admin/database.php
Expand Up @@ -737,29 +737,49 @@ function get_max_question_order($gid)
$databaseoutput .= "<script type=\"text/javascript\">\n<!--\n alert(\"".$clang->gT("Question could not be created.","js")."\\n".htmlspecialchars($connect->ErrorMsg())."\")\n //-->\n</script>\n";

}
if (returnglobal('copyanswers') == "Y")
if (returnglobal('copysubquestions') == "Y")
{
$q1 = "SELECT * FROM {$dbprefix}answers WHERE qid="
$aSQIDMappings=array();
$q1 = "SELECT * FROM {$dbprefix}questions WHERE parent_qid="
. returnglobal('oldqid')
. " ORDER BY code";
. " ORDER BY question_order";
$r1 = db_execute_assoc($q1); // Checked
$tablename=$dbprefix.'questions';
while ($qr1 = $r1->FetchRow())
{
if ($filterxsshtml)
$qr1['parent_qid']=$newqid;
if (isset($aSQIDMappings[$qr1['qid']]))
{
require_once("../classes/inputfilter/class.inputfilter_clean.php");
$myFilter = new InputFilter('','',1,1,1);
$qr1['answer']=$myFilter->process($qr1['answer']);
$qr1['qid']=$aSQIDMappings[$qr1['qid']];
db_switchIDInsert($tablename,true);
}
else
{
$qr1['answer'] = html_entity_decode($qr1['answer'], ENT_QUOTES, "UTF-8");
$oldqid=$qr1['qid'];
unset($qr1['qid']);
}
$sInsertSQL = $connect->GetInsertSQL($tablename,$qr1);
$ir1 = $connect->Execute($sInsertSQL); // Checked
if (isset($qr1['qid']))
{
db_switchIDInsert($tablename,false);
}
else
{
$aSQIDMappings[$oldqid]=$connect->Insert_ID($tablename,"qid");
}


// Fix bug with FCKEditor saving strange BR types
$qr1['answer']=fix_FCKeditor_text($qr1['answer']);

}
}

if (returnglobal('copyanswers') == "Y")
{
$q1 = "SELECT * FROM {$dbprefix}answers WHERE qid="
. returnglobal('oldqid')
. " ORDER BY code";
$r1 = db_execute_assoc($q1); // Checked
while ($qr1 = $r1->FetchRow())
{
$qr1 = array_map('db_quote', $qr1);
$i1 = "INSERT INTO {$dbprefix}answers (qid, code, answer, default_value, sortorder, language) "
. "VALUES ('$newqid', '{$qr1['code']}', "
Expand Down
41 changes: 15 additions & 26 deletions admin/questionhandling.php
Expand Up @@ -95,32 +95,21 @@

$editquestion .= questionjavascript($eqrow['type'])."</li>\n";


if ($eqrow['type'] == "J" || $eqrow['type'] == "I")
{
$editquestion .= "\t</ul>\n"
. "<p><input type='hidden' name='copyanswers' value='Y'>\n"
. "<input type='submit' value='".$clang->gT("Copy Question")."' />\n"
. "<input type='hidden' name='action' value='copynewquestion' />\n"
. "<input type='hidden' name='sid' value='$sid' />\n"
. "<input type='hidden' name='oldqid' value='$qid' />\n"
. "<input type='hidden' name='gid' value='$gid' />\n"
. "</form>\n";
}
else
{
$editquestion .= "<li><label for='copyanswers'>".$clang->gT("Copy Answers?")."</label>\n"
. "<input type='checkbox' class='checkboxbtn' checked='checked' id='copyanswers' name='copyanswers' value='Y' />"
. "</li>\n"
. "<li><label for='copyattributes'>".$clang->gT("Copy Attributes?")."</label>\n"
. "<input type='checkbox' class='checkboxbtn' checked='checked' id='copyattributes' name='copyattributes' value='Y' />"
. "</li></ul>\n"
. "<p><input type='submit' value='".$clang->gT("Copy Question")."' />\n"
. "<input type='hidden' name='action' value='copynewquestion' />\n"
. "<input type='hidden' name='sid' value='$surveyid' />\n"
. "<input type='hidden' name='oldqid' value='$qid' />\n"
. "\t</form>\n";
}
$editquestion .= "<li><label for='copysubquestions'>".$clang->gT("Copy subquestions?")."</label>\n"
. "<input type='checkbox' class='checkboxbtn' checked='checked' id='copysubquestions' name='copysubquestions' value='Y' />"
. "</li>\n";
$editquestion .= "<li><label for='copyanswers'>".$clang->gT("Copy answer options?")."</label>\n"
. "<input type='checkbox' class='checkboxbtn' checked='checked' id='copyanswers' name='copyanswers' value='Y' />"
. "</li>\n"
. "<li><label for='copyattributes'>".$clang->gT("Copy advanced settings?")."</label>\n"
. "<input type='checkbox' class='checkboxbtn' checked='checked' id='copyattributes' name='copyattributes' value='Y' />"
. "</li></ul>\n"
. "<p><input type='submit' value='".$clang->gT("Copy question")."' />\n"
. "<input type='hidden' name='action' value='copynewquestion' />\n"
. "<input type='hidden' name='sid' value='$surveyid' />\n"
. "<input type='hidden' name='oldqid' value='$qid' />\n"
. "\t</form>\n";

}


Expand Down
36 changes: 18 additions & 18 deletions qanda.php
Expand Up @@ -331,7 +331,7 @@ function setman_questionandcode($ia)
$qquery = "SELECT other FROM {$dbprefix}questions WHERE qid=".$ia[0]." AND language='".$_SESSION['s_lang']."' and parent_qid=0";
$qresult = db_execute_assoc($qquery); //Checked
while ($qrow = $qresult->FetchRow()) {$other = $qrow['other'];}
$subquestionquery = "SELECT title FROM {$dbprefix}questions WHERE parent_qid={$ia[0]} AND language='".$_SESSION['s_lang']."' ORDER BY question_order, question";
$subquestionquery = "SELECT title FROM {$dbprefix}questions WHERE parent_qid={$ia[0]} AND language='".$_SESSION['s_lang']."' ORDER BY question_order";
$sqresult = db_execute_assoc($subquestionquery); //Checked

while ($subquestionrow = $sqresult->FetchRow())
Expand Down Expand Up @@ -429,8 +429,7 @@ function setman_questionandcode_multiscale($ia)
."FROM {$dbprefix}questions "
."WHERE parent_qid={$ia[0]} "
."AND language='".$_SESSION['s_lang']."' "
."ORDER BY question_order, "
."question";
."ORDER BY question_order";
$subresult = db_execute_assoc($subquery); //Checked

// Get Answer Scale 1
Expand All @@ -439,7 +438,7 @@ function setman_questionandcode_multiscale($ia)
."WHERE qid={$ia[0]} "
."AND scale_id=0 "
."AND language='".$_SESSION['s_lang']."' "
."ORDER BY sortorder, answer";
."ORDER BY sortorder";
$ans1result = db_execute_assoc($ans1query); //Checked
$ans1count = $ans1result->RowCount();

Expand All @@ -449,7 +448,7 @@ function setman_questionandcode_multiscale($ia)
."WHERE qid={$ia[0]} "
."AND scale_id=1 "
."AND language='".$_SESSION['s_lang']."' "
."ORDER BY sortorder, answer";
."ORDER BY sortorder";
$ans2result = db_execute_assoc($ans2query); //Checked
$ans2count = $ans2result->RowCount();

Expand Down Expand Up @@ -2672,14 +2671,15 @@ function do_multiplechoice($ia)
{
global $dbprefix, $clang, $connect, $thissurvey;

// Find out if any quesitons have attributes which reference this questions
// Find out if any questions have attributes which reference this questions
// based on value of attribute. This could be array_filter and array_filter_exclude

$qaquery = "SELECT qid,attribute FROM ".db_table_name('question_attributes')." WHERE value=lower('".strtolower($ia[2])."')";
$attribute_ref=false;
$qaquery = "SELECT qid,attribute FROM ".db_table_name('question_attributes')." WHERE value LIKE '".strtolower($ia[2])."' and (attribute='array_filter' or attribute='array_filter_exclude')";
$qaresult = db_execute_assoc($qaquery); //Checked
while($qarow = $qaresult->FetchRow())
{
$qquery = "SELECT qid FROM ".db_table_name('questions')." WHERE sid=".$thissurvey['sid']." AND qid=".$qarow['qid'];
$qquery = "SELECT qid FROM ".db_table_name('questions')." WHERE sid=".$thissurvey['sid']." AND scale_id=0 AND qid=".$qarow['qid'];
$qresult = db_execute_assoc($qquery); //Checked
if ($qresult->RecordCount() > 0)
{
Expand Down Expand Up @@ -2783,11 +2783,11 @@ function excludeAllOthers$ia[1](value, doconditioncheck)
while($qrow = $qresult->FetchRow()) {$other = $qrow['other'];}

if ($qidattributes['random_order']==1) {
$ansquery = "SELECT * FROM ".db_table_name('questions')." WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random();
$ansquery = "SELECT * FROM ".db_table_name('questions')." WHERE parent_qid=$ia[0] AND scale_id=0 AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random();
}
else
{
$ansquery = "SELECT * FROM ".db_table_name('questions')." WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY question_order, question";
$ansquery = "SELECT * FROM ".db_table_name('questions')." WHERE parent_qid=$ia[0] AND scale_id=0 AND language='".$_SESSION['s_lang']."' ORDER BY question_order";
}

$ansresult = $connect->GetAll($ansquery); //Checked
Expand Down Expand Up @@ -3141,7 +3141,7 @@ function do_multiplechoice_withcomments($ia)
{
global $dbprefix, $clang, $thissurvey;

$qaquery = "SELECT qid,attribute FROM ".db_table_name('question_attributes')." WHERE value=lower('".strtolower($ia[2])."')";
$qaquery = "SELECT qid,attribute FROM ".db_table_name('question_attributes')." WHERE value='".strtolower($ia[2])."'";
$qaresult = db_execute_assoc($qaquery); //Checked
while($qarow = $qaresult->FetchRow())
{
Expand Down Expand Up @@ -3223,7 +3223,7 @@ function do_multiplechoice_withcomments($ia)
if ($qidattributes['random_order']==1) {
$ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random();
} else {
$ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY question_order, question";
$ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY question_order";
}
$ansresult = db_execute_assoc($ansquery); //Checked
$anscount = $ansresult->RecordCount()*2;
Expand Down Expand Up @@ -3500,7 +3500,7 @@ function do_multipleshorttext($ia)
}
else
{
$ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY question_order, question";
$ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY question_order";
}

$ansresult = db_execute_assoc($ansquery); //Checked
Expand Down Expand Up @@ -3805,7 +3805,7 @@ function do_multiplenumeric($ia)
}
else
{
$ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY question_order, question";
$ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY question_order";
}

$ansresult = db_execute_assoc($ansquery); //Checked
Expand Down Expand Up @@ -5740,7 +5740,7 @@ function do_array_multiflexi($ia)
}
else
{
$ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND scale_id=0 AND language='".$_SESSION['s_lang']."' ORDER BY question_order, question";
$ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND scale_id=0 AND language='".$_SESSION['s_lang']."' ORDER BY question_order";
}
$ansresult = db_execute_assoc($ansquery);
$anscount = $ansresult->RecordCount();
Expand Down Expand Up @@ -5984,7 +5984,7 @@ function do_array_flexiblecolumns($ia)
}
else
{
$ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY question_order, question";
$ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY question_order";
}
$ansresult = db_execute_assoc($ansquery); //Checked
$anscount = $ansresult->RecordCount();
Expand Down Expand Up @@ -6197,7 +6197,7 @@ function do_array_flexible_dual($ia)
}
else
{
$ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY question_order, question";
$ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY question_order";
}
$ansresult = db_execute_assoc($ansquery); //Checked
$anscount = $ansresult->RecordCount();
Expand Down Expand Up @@ -6500,7 +6500,7 @@ function do_array_flexible_dual($ia)
//no question attributes -> order by sortorder
else
{
$ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY question_order, question";
$ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY question_order";
}
$ansresult = db_execute_assoc($ansquery); //Checked
$anscount = $ansresult->RecordCount();
Expand Down
10 changes: 5 additions & 5 deletions statistics_user.php
Expand Up @@ -269,7 +269,7 @@
case "K": // Multiple Numerical
case "Q": // Multiple Short Text
//get answers
$query = "SELECT title as code, question as answer FROM ".db_table_name("questions")." WHERE parent_qid='$flt[0]' AND language = '{$language}' ORDER BY question_order, question";
$query = "SELECT title as code, question as answer FROM ".db_table_name("questions")." WHERE parent_qid='$flt[0]' AND language = '{$language}' ORDER BY question_order";
$result = db_execute_num($query) or safe_die ("Couldn't get answers!<br />$query<br />".$connect->ErrorMsg());

//go through all the (multiple) answers
Expand All @@ -286,7 +286,7 @@
case "F": // FlEXIBLE ARRAY
case "H": // ARRAY (By Column)
//get answers
$query = "SELECT title as code, question as answer FROM ".db_table_name("questions")." WHERE parent_qid='$flt[0]' AND language = '{$language}' ORDER BY question_order, question";
$query = "SELECT title as code, question as answer FROM ".db_table_name("questions")." WHERE parent_qid='$flt[0]' AND language = '{$language}' ORDER BY question_order";
$result = db_execute_num($query) or safe_die ("Couldn't get answers!<br />$query<br />".$connect->ErrorMsg());

//go through all the (multiple) answers
Expand All @@ -304,7 +304,7 @@
$allfields[] = $myfield;
break;
case ";": //ARRAY (Multi Flex) (Text)
$query = "SELECT title, question FROM ".db_table_name("questions")." WHERE parent_qid='$flt[0]' AND language='{$language}' ORDER BY question_order, question";
$query = "SELECT title, question FROM ".db_table_name("questions")." WHERE parent_qid='$flt[0]' AND language='{$language}' ORDER BY question_order";
$result = db_execute_num($query) or die ("Couldn't get answers!<br />$query<br />".$connect->ErrorMsg());
while ($row=$result->FetchRow())
{
Expand All @@ -318,7 +318,7 @@
}
break;
case ":": //ARRAY (Multi Flex) (Numbers)
$query = "SELECT title, question FROM ".db_table_name("questions")." WHERE parent_qid='$flt[0]' AND language = '{$language}' AND scale_id=0 ORDER BY question_order, question";
$query = "SELECT title, question FROM ".db_table_name("questions")." WHERE parent_qid='$flt[0]' AND language = '{$language}' AND scale_id=0 ORDER BY question_order";
$result = db_execute_num($query) or die ("Couldn't get answers!<br />$query<br />".$connect->ErrorMsg());

while ($row=$result->FetchRow())
Expand Down Expand Up @@ -352,7 +352,7 @@
break;
case "1": // MULTI SCALE
//get answers
$query = "SELECT title, question FROM ".db_table_name("questions")." WHERE parent_qid='$flt[0]' AND language='{$language}' ORDER BY question_order, question";
$query = "SELECT title, question FROM ".db_table_name("questions")." WHERE parent_qid='$flt[0]' AND language='{$language}' ORDER BY question_order";
$result = db_execute_num($query) or safe_die ("Couldn't get answers!<br />$query<br />".$connect->ErrorMsg());

//loop through answers
Expand Down

0 comments on commit 442e652

Please sign in to comment.