From 442e6527404256102e0b3e42f849f09fc7d4902e Mon Sep 17 00:00:00 2001 From: Carsten Schmitz Date: Wed, 2 Jun 2010 14:50:50 +0000 Subject: [PATCH] Fixed issue #04378: Copy question does not copy subquestions git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey@8779 b72ed6b6-b9f8-46b5-92b4-906544132732 --- admin/database.php | 44 +++++++++++++++++++++++++++----------- admin/questionhandling.php | 41 +++++++++++++---------------------- qanda.php | 36 +++++++++++++++---------------- statistics_user.php | 10 ++++----- 4 files changed, 70 insertions(+), 61 deletions(-) diff --git a/admin/database.php b/admin/database.php index 06e70c9563b..733db8f7816 100644 --- a/admin/database.php +++ b/admin/database.php @@ -737,29 +737,49 @@ function get_max_question_order($gid) $databaseoutput .= "\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']}', " diff --git a/admin/questionhandling.php b/admin/questionhandling.php index a9d2d475c96..2f9c30c5fb3 100644 --- a/admin/questionhandling.php +++ b/admin/questionhandling.php @@ -95,32 +95,21 @@ $editquestion .= questionjavascript($eqrow['type'])."\n"; - - if ($eqrow['type'] == "J" || $eqrow['type'] == "I") - { - $editquestion .= "\t\n" - . "

\n" - . "\n" - . "\n" - . "\n" - . "\n" - . "\n" - . "\n"; - } - else - { - $editquestion .= "

  • \n" - . "" - . "
  • \n" - . "
  • \n" - . "" - . "
  • \n" - . "

    \n" - . "\n" - . "\n" - . "\n" - . "\t\n"; - } + $editquestion .= "

  • \n" + . "" + . "
  • \n"; + $editquestion .= "
  • \n" + . "" + . "
  • \n" + . "
  • \n" + . "" + . "
  • \n" + . "

    \n" + . "\n" + . "\n" + . "\n" + . "\t\n"; + } diff --git a/qanda.php b/qanda.php index 030111ded6e..58742c79c5b 100644 --- a/qanda.php +++ b/qanda.php @@ -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()) @@ -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 @@ -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(); @@ -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(); @@ -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) { @@ -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 @@ -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()) { @@ -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; @@ -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 @@ -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 @@ -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(); @@ -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(); @@ -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(); @@ -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(); diff --git a/statistics_user.php b/statistics_user.php index f05cda7d896..0fc6c423149 100644 --- a/statistics_user.php +++ b/statistics_user.php @@ -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!
    $query
    ".$connect->ErrorMsg()); //go through all the (multiple) answers @@ -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!
    $query
    ".$connect->ErrorMsg()); //go through all the (multiple) answers @@ -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!
    $query
    ".$connect->ErrorMsg()); while ($row=$result->FetchRow()) { @@ -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!
    $query
    ".$connect->ErrorMsg()); while ($row=$result->FetchRow()) @@ -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!
    $query
    ".$connect->ErrorMsg()); //loop through answers