Skip to content

Commit

Permalink
dev Import should be working now
Browse files Browse the repository at this point in the history
git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_dev_cs@8264 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
c-schmitz committed Jan 17, 2010
1 parent 6f88768 commit ae9da91
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 105 deletions.
14 changes: 8 additions & 6 deletions admin/database.php
Expand Up @@ -1162,12 +1162,14 @@ function get_max_question_order($gid)

$_POST['code_'.$codeids[$count]]=sanitize_paranoid_string($_POST['code_'.$codeids[$count]]);
// Now we insert the answers
$query = "INSERT INTO ".db_table_name('questions')." (title,question,parent_qid,question_order,language)
VALUES (".db_quoteall($_POST['code_'.$codeids[$count]]).", ".
db_quoteall($_POST['answer_'.$sortorderid]).", ".
db_quote($qid).", ".
db_quote($orderid).", ".
db_quoteall($langid).")";
$query = "INSERT INTO ".db_table_name('questions')." (sid, gid, title,question,parent_qid,question_order,language)
VALUES ( $surveyid,
$gid,"
.db_quoteall($_POST['code_'.$codeids[$count]]).", "
.db_quoteall($_POST['answer_'.$sortorderid]).", "
.db_quote($qid).", "
.db_quote($orderid).", "
.db_quoteall($langid).")";
if (!$result = $connect->Execute($query)) // Checked
{
$databaseoutput .= "<script type=\"text/javascript\">\n<!--\n alert(\"".$clang->gT("Failed to update answers","js")." - ".$query." - ".$connect->ErrorMsg()."\")\n //-->\n</script>\n";
Expand Down
4 changes: 2 additions & 2 deletions admin/html.php
Expand Up @@ -888,7 +888,7 @@
. "<div class='menubar-right'>\n"
. "<span class=\"boxcaption\">".$clang->gT("Questions").":</span><select class=\"listboxquestions\" name='qid' "
. "onchange=\"window.open(this.options[this.selectedIndex].value, '_top')\">"
. getquestions($surveyid,$gid,$qid)
. getQuestions($surveyid,$gid,$qid)
. "</select>\n";
if ($activated == "Y")
{
Expand Down Expand Up @@ -1638,7 +1638,7 @@
elseif (($activated != 'N' && $first) ) // If survey is activated and its not one of the above question types who allows modfying answers on active survey
{
$vasummary .= "<input type='hidden' name='code_{$row['question_order']}' value=\"{$row['title']}\" maxlength='5' size='5'"
." />{$row['code']}";
." />{$row['title']}";
$vasummary .= "<input type='hidden' id='previouscode_{$row['question_order']}' name='previouscode_{$row['question_order']}' value=\"{$row['title']}\" />";

}
Expand Down
90 changes: 47 additions & 43 deletions admin/importsurvey.php
Expand Up @@ -757,7 +757,7 @@
$csarray[$newlid]=$newcs;
}
//END CHECK FOR DUPLICATES
$labelreplacements[]=array($oldlid, $newlid);
$labelreplacements[$oldlid]=$newlid;
}
}

Expand Down Expand Up @@ -854,7 +854,7 @@
else
if ($currentqid==$questionrowdata['qid']) {$newquestion=false;}

if (!array_key_exists($questionrowdata["type"], $qtypes))
if (!array_key_exists($questionrowdata["type"], $qtypes))
{
$questionrowdata["type"] = strtoupper($questionrowdata["type"]);
if (!array_key_exists($questionrowdata["type"], $qtypes))
Expand Down Expand Up @@ -885,45 +885,23 @@
$questionrowdata['language']=$newlanguage;
}
$oldqid=$qid;
if (!isset($questionrowdata["lid1"]))
{
$questionrowdata["lid1"]=0;
}
// Now we will fix up the label id
$type = $questionrowdata["type"]; //Get the type
if ($type == "F" || $type == "H" || $type == "W" ||
$type == "Z" || $type == "1" || $type == ":" ||
$type == ";" )
{//IF this is a flexible label array, update the lid entry
if (isset($labelreplacements)) {
// We only replace once in each question label
// otherwise could lead to double substitution
// if a new lid collides with an older one
$already_replaced_label = false;
$already_replaced_label1 = false;
foreach ($labelreplacements as $lrp) {
if ($lrp[0] == $questionrowdata["lid"])
{
if (!$already_replaced_label)
{
$questionrowdata["lid"]=$lrp[1];
$already_replaced_label = true;
}
}
if ($lrp[0] == $questionrowdata["lid1"])
{
if (!$already_replaced_label1)
{
$questionrowdata["lid1"]=$lrp[1];
$already_replaced_label1 = true;
}
}
}
}
}

if ($importversion<143) {
if ((isset($questionrowdata['lid']) && $questionrowdata['lid']>0))
{
$oldlid1=$questionrowdata['lid'];
}
if ((isset($questionrowdata['lid1']) && $questionrowdata['lid1']>0))
{
$oldlid2=$questionrowdata['lid1'];
}
unset($questionrowdata['lid']);
unset($questionrowdata['lid1']);
}

if (!isset($questionrowdata["question_order"]) || $questionrowdata["question_order"]=='') {$questionrowdata["question_order"]=0;}
$other = $questionrowdata["other"]; //Get 'other' field value

$type = $questionrowdata['type'];
// translate internal links
$questionrowdata['title']=translink('survey', $surveyid, $newsid, $questionrowdata['title']);
$questionrowdata['question']=translink('survey', $surveyid, $newsid, $questionrowdata['question']);
Expand All @@ -942,6 +920,22 @@
$newqid=$connect->Insert_ID("{$dbprefix}questions","qid");
}


// Now we will fix up old label sets where they are used as answers
if ($importversion<143 && (isset($oldlid1) || isset($oldlid2)) && $qtypes[$type]['answerscales']>0)
{
$query="select * from ".db_table_name('labels')." where lid={$labelreplacements[$oldlid1]}";
$oldlabelsresult=db_execute_assoc($query);
while($labelrow=$oldlabelsresult->FetchRow())
{
$qinsert = "insert INTO ".db_table_name('answers')." (qid,code,answer,sortorder,language,assessment_value)
VALUES ($newqid,".db_quoteall($labelrow['code']).",".db_quoteall($labelrow['title']).",".db_quoteall($labelrow['sortorder']).",".db_quoteall($labelrow['language']).",".db_quoteall($labelrow['assessment_value']).")";
$qres = $connect->Execute($qinsert) or safe_die ($clang->gT("Error").": Failed to insert answer <br />\n$qinsert<br />\n".$connect->ErrorMsg());
}


}

$newrank=0;
$substitutions[]=array($oldsid, $oldgid, $oldqid, $newsid, $newgid, $newqid);

Expand Down Expand Up @@ -981,8 +975,18 @@

$newvalues=array_values($answerrowdata);
$newvalues=array_map(array(&$connect, "qstr"),$newvalues); // quote everything accordingly
$ainsert = "insert INTO {$dbprefix}answers (".implode(',',array_keys($answerrowdata)).") VALUES (".implode(',',$newvalues).")";
$ares = $connect->Execute($ainsert) or safe_die ($clang->gT("Error").": Failed to insert answer<br />\n$ainsert<br />\n".$connect->ErrorMsg());

// Now we will fix up old answer where they are really subquestions
if ($importversion<143 && $qtypes[$type]['subquestions']>0)
{
$qinsert = "insert INTO ".db_table_name('questions')." (parent_qid,title,question,question_order,language)
VALUES ({$answerrowdata['qid']},".db_quoteall($answerrowdata['code']).",".db_quoteall($answerrowdata['answer']).",".db_quoteall($answerrowdata['sortorder']).",".db_quoteall($answerrowdata['language']).")";
$qres = $connect->Execute($qinsert) or safe_die ($clang->gT("Error").": Failed to insert answer <br />\n$qinsert<br />\n".$connect->ErrorMsg());
}
else {
$ainsert = "insert INTO {$dbprefix}answers (".implode(',',array_keys($answerrowdata)).") VALUES (".implode(',',$newvalues).")";
$ares = $connect->Execute($ainsert) or safe_die ($clang->gT("Error").": Failed to insert answer<br />\n$ainsert<br />\n".$connect->ErrorMsg());
}

if ($type == "M" || $type == "P") {
$fieldnames[]=array("oldcfieldname"=>$oldsid."X".$oldgid."X".$oldqid,
Expand All @@ -1009,15 +1013,15 @@
elseif ($type == ":" || $type == ";" ) {
// read all label codes from $questionrowdata["lid"]
// for each one (as L) set SGQA_L
$labelq="SELECT DISTINCT code FROM {$dbprefix}labels WHERE lid=".$questionrowdata["lid"];
/* $labelq="SELECT DISTINCT code FROM {$dbprefix}labels WHERE lid=".$questionrowdata["lid"];
$labelqresult=db_execute_num($labelq) or safe_die("Died querying labelset $lid<br />$query2<br />".$connect->ErrorMsg());
while ($labelqrow=$labelqresult->FetchRow())
{
$fieldnames[]=array("oldcfieldname"=>$oldsid."X".$oldgid."X".$oldqid.$code."_".$labelqrow[0],
"newcfieldname"=>$newsid."X".$newgid."X".$newqid.$code."_".$labelqrow[0],
"oldfieldname"=>$oldsid."X".$oldgid."X".$oldqid.$code."_".$labelqrow[0],
"newfieldname"=>$newsid."X".$newgid."X".$newqid.$code."_".$labelqrow[0]);
}
} */
}
elseif ($type == "R") {
$newrank++;
Expand Down
24 changes: 12 additions & 12 deletions admin/statistics.php
Expand Up @@ -194,12 +194,13 @@
*
* b) "groups" -> group_name + group_order *
*/
$query = "SELECT ".db_table_name("questions").".*, group_name, group_order\n"
."FROM ".db_table_name("questions").", ".db_table_name("groups")."\n"
."WHERE ".db_table_name("groups").".gid=".db_table_name("questions").".gid\n"
."AND ".db_table_name("groups").".language='".$language."'\n"
."AND ".db_table_name("questions").".language='".$language."'\n"
."AND ".db_table_name("questions").".sid=$surveyid";
$query = "SELECT questions.*, groups.group_name, groups.group_order\n"
." FROM ".db_table_name("questions") ." as questions, ".db_table_name("groups")." as groups\n"
." WHERE groups.gid=questions.gid\n"
." AND groups.language='".$language."'\n"
." AND questions.language='".$language."'\n"
." AND questions.parent_qid=0\n"
." AND questions.sid=$surveyid";
$result = db_execute_assoc($query) or safe_die("Couldn't do it!<br />$query<br />".$connect->ErrorMsg());

//store all the data in $rows
Expand Down Expand Up @@ -813,7 +814,7 @@
$statisticsoutput .= "\t\t\t\t</tr>\n\t\t\t\t<tr>\n";

//get answers
$query = "SELECT code, answer FROM ".db_table_name("answers")." WHERE qid='$flt[0]' AND language='{$language}' ORDER BY sortorder, answer";
$query = "SELECT title as code, question FROM ".db_table_name("questions")." WHERE parent_qid='$flt[0]' AND language='{$language}' ORDER BY question_order, question";
$result = db_execute_num($query) or safe_die ("Couldn't get answers!<br />$query<br />".$connect->ErrorMsg());
$counter2=0;

Expand Down Expand Up @@ -867,7 +868,7 @@
//just like above only a different loop
case "B": // ARRAY OF 10 POINT CHOICE QUESTIONS
$statisticsoutput .= "\t\t\t\t</tr>\n\t\t\t\t<tr>\n";
$query = "SELECT code, answer FROM ".db_table_name("answers")." WHERE qid='$flt[0]' AND language='{$language}' ORDER BY sortorder, answer";
$query = "SELECT title, question FROM ".db_table_name("answers")." WHERE parent_qid='$flt[0]' AND language='{$language}' ORDER BY question_order, question";
$result = db_execute_num($query) or safe_die ("Couldn't get answers!<br />$query<br />".$connect->ErrorMsg());
$counter2=0;
while ($row=$result->FetchRow())
Expand Down Expand Up @@ -914,7 +915,7 @@
$statisticsoutput .= "\t\t\t\t</tr>\n\t\t\t\t<tr>\n";

//get answers
$query = "SELECT code, answer FROM ".db_table_name("answers")." WHERE qid='$flt[0]' AND language='{$language}' ORDER BY sortorder, answer";
$query = "SELECT title, question FROM ".db_table_name("answers")." WHERE parent_qid='$flt[0]' AND language='{$language}' ORDER BY question_order, question";
$result = db_execute_num($query) or safe_die ("Couldn't get answers!<br />$query<br />".$connect->ErrorMsg());
$counter2=0;

Expand Down Expand Up @@ -973,8 +974,7 @@
//similiar to the above one
case "E": // ARRAY OF Increase/Same/Decrease QUESTIONS
$statisticsoutput .= "\t\t\t\t</tr>\n\t\t\t\t<tr>\n";

$query = "SELECT code, answer FROM ".db_table_name("answers")." WHERE qid='$flt[0]' AND language='{$language}' ORDER BY sortorder, answer";
$query = "SELECT title, question FROM ".db_table_name("answers")." WHERE parent_qid='$flt[0]' AND language='{$language}' ORDER BY question_order, question";
$result = db_execute_num($query) or safe_die ("Couldn't get answers!<br />$query<br />".$connect->ErrorMsg());
$counter2=0;

Expand Down Expand Up @@ -1023,7 +1023,7 @@

case ";": //ARRAY (Multi Flex) (Text)
$statisticsoutput .= "\t\t\t\t</tr>\n\t\t\t\t<tr>\n";
$query = "SELECT code, answer FROM ".db_table_name("answers")." WHERE qid='$flt[0]' AND language='{$language}' ORDER BY sortorder, answer";
$query = "SELECT title, question FROM ".db_table_name("answers")." WHERE parent_qid='$flt[0]' AND language='{$language}' ORDER BY question_order, question";
$result = db_execute_num($query) or die ("Couldn't get answers!<br />$query<br />".$connect->ErrorMsg());
$counter2=0;
while ($row=$result->FetchRow())
Expand Down

0 comments on commit ae9da91

Please sign in to comment.