diff --git a/admin/importsurvey.php b/admin/importsurvey.php index 78637274d5b..b7a80c222a4 100644 --- a/admin/importsurvey.php +++ b/admin/importsurvey.php @@ -35,30 +35,32 @@ */ // A FILE TO IMPORT A DUMPED SURVEY FILE, AND CREATE A NEW SURVEY -$the_path="$homedir"; -$the_full_file_path=$homedir."/".$the_file_name; +$the_path = "$homedir"; +$the_full_file_path = $homedir . "/" . $the_file_name; if (!@copy($the_file, $the_path . "/" . $the_file_name)) { - echo "
Something went horribly wrong. See system administrator."; + echo "
Something went horribly wrong. See system administrator.
\n"; + echo "\n\n"; exit; } // IF WE GOT THIS FAR, THEN THE FILE HAS BEEN UPLOADED SUCCESFULLY -echo "\n
IMPORTING FILE
File succesfully uploaded

"; -echo "\nReading File...
"; -$handle=fopen($the_full_file_path, "r"); +echo "
\nIMPORTING FILE
File succesfully uploaded

\n"; +echo "Reading File...
\n"; +$handle = fopen($the_full_file_path, "r"); while (!feof($handle)) { - $buffer=fgets($handle); - $bigarray[]=$buffer; + $buffer = fgets($handle); + $bigarray[] = $buffer; } fclose($handle); if (!$bigarray[0] == "# SURVEYOR SURVEY DUMP") { - echo "This is NOT a Surveyor Dump File. Import aborted!"; + echo "This is NOT a Surveyor Dump File. Import aborted!\n"; + echo "\n\n"; exit; } @@ -66,111 +68,112 @@ { unset($bigarray[$i]); } -$bigarray=array_values($bigarray); +$bigarray = array_values($bigarray); //TABLES -$stoppoint=array_search("# NEW TABLE\n", $bigarray); +$stoppoint = array_search("# NEW TABLE\n", $bigarray); for ($i=0; $i<=$stoppoint+2; $i++) { - if ($i<$stoppoint-1) {$tablearray[]=$bigarray[$i];} + if ($i<$stoppoint-1) {$tablearray[] = $bigarray[$i];} unset($bigarray[$i]); } -$bigarray=array_values($bigarray); +$bigarray = array_values($bigarray); //GROUPS -$stoppoint=array_search("# NEW TABLE\n", $bigarray); +$stoppoint = array_search("# NEW TABLE\n", $bigarray); for ($i=0; $i<=$stoppoint+2; $i++) { - if ($i<$stoppoint-1) {$grouparray[]=$bigarray[$i];} + if ($i<$stoppoint-1) {$grouparray[] = $bigarray[$i];} unset($bigarray[$i]); } -$bigarray=array_values($bigarray); +$bigarray = array_values($bigarray); //QUESTIONS -$stoppoint=array_search("# NEW TABLE\n", $bigarray); +$stoppoint = array_search("# NEW TABLE\n", $bigarray); for ($i=0; $i<=$stoppoint+2; $i++) { - if ($i<$stoppoint-1) {$questionarray[]=$bigarray[$i];} + if ($i<$stoppoint-1) {$questionarray[] = $bigarray[$i];} unset($bigarray[$i]); } -$bigarray=array_values($bigarray); +$bigarray = array_values($bigarray); //ANSWERS -$stoppoint=count($bigarray); +$stoppoint = count($bigarray); for ($i=0; $i<=$stoppoint+2; $i++) { - if ($i<$stoppoint-1) {$answerarray[]=$bigarray[$i];} + if ($i<$stoppoint-1) {$answerarray[] = $bigarray[$i];} unset($bigarray[$i]); } -$bigarray=array_values($bigarray); +$bigarray = array_values($bigarray); -$countsurveys=count($tablearray); -$countgroups=count($grouparray); -$countquestions=count($questionarray); -$countanswers=count($answerarray); +$countsurveys = count($tablearray); +$countgroups = count($grouparray); +$countquestions = count($questionarray); +$countanswers = count($answerarray); -echo "SURVEY SUMMARY:
"; -echo ""; +echo "SURVEY SUMMARY:
\n"; +echo "\n"; // CREATE SURVEY -$sid=substr($tablearray[0], strpos($tablearray[0], "('")+2, (strpos($tablearray[0], "',")-(strpos($tablearray[0], "('")+2))); -$insert=str_replace("('$sid'", "(''", $tablearray[0]); -//$insert=substr($insert, 0, -1); -$iresult=mysql_query($insert) or die("Insert of imported survey completely failed
$insert

".mysql_error()); +$sid = substr($tablearray[0], strpos($tablearray[0], "('")+2, (strpos($tablearray[0], "',")-(strpos($tablearray[0], "('")+2))); +$insert = str_replace("('$sid'", "(''", $tablearray[0]); +//$insert = substr($insert, 0, -1); +$iresult = mysql_query($insert) or die("Insert of imported survey completely failed
\n$insert

\n" . mysql_error() . "\n"); //GET NEW SID -$sidquery="SELECT sid FROM surveys ORDER BY sid DESC LIMIT 1"; -$sidres=mysql_query($sidquery); -while ($srow=mysql_fetch_row($sidres)){$newsid=$srow[0];} +$sidquery = "SELECT sid FROM surveys ORDER BY sid DESC LIMIT 1"; +$sidres = mysql_query($sidquery); +while ($srow = mysql_fetch_row($sidres)) {$newsid = $srow[0];} // DO GROUPS, QUESTIONS FOR GROUPS, THEN ANSWERS FOR QUESTIONS IN A NESTED FORMAT! foreach ($grouparray as $ga) { - $gid=substr($ga, strpos($ga, "('")+2, (strpos($ga, "',")-(strpos($ga, "('")+2))); - $ginsert=str_replace("('$gid', '$sid',", "('', '$newsid',", $ga); - //$ginsert=substr($ginsert, 0, -1); - $gres=mysql_query($ginsert); + $gid = substr($ga, strpos($ga, "('")+2, (strpos($ga, "',")-(strpos($ga, "('")+2))); + $ginsert = str_replace("('$gid', '$sid',", "('', '$newsid',", $ga); + //$ginsert = substr($ginsert, 0, -1); + $gres = mysql_query($ginsert); //GET NEW GID - $gidquery="SELECT gid FROM groups ORDER BY gid DESC LIMIT 1"; - $gidres=mysql_query($gidquery); - while ($grow=mysql_fetch_row($gidres)){$newgid=$grow[0];} + $gidquery = "SELECT gid FROM groups ORDER BY gid DESC LIMIT 1"; + $gidres = mysql_query($gidquery); + while ($grow = mysql_fetch_row($gidres)) {$newgid = $grow[0];} //NOW DO NESTED QUESTIONS FOR THIS GID foreach ($questionarray as $qa) { - $sidpos=", '$sid'"; - $start=strpos($qa, "$sidpos")+2+strlen($sid)+5; - $end=strpos($qa, "'", $start)-$start; - if (substr($qa, $start, $end)==$gid) + $sidpos = ", '$sid'"; + $start = strpos($qa, "$sidpos")+2+strlen($sid)+5; + $end = strpos($qa, "'", $start)-$start; + if (substr($qa, $start, $end) == $gid) { - $qid=substr($qa, strpos($qa, "('")+2, (strpos($qa, "',")-(strpos($qa, "('")+2))); - $qinsert=str_replace("('$qid', '$sid', '$gid',", "('$newsid', '$newgid',", $qa); - $qinsert=str_replace("(`qid`, ", "(", $qinsert); - //$qinsert=substr(trim($qinsert), 0, -1); - //echo "$qinsert
"; - $qres=mysql_query($qinsert) or die ("ERROR: Failed to insert question
$qinsert
".mysql_error()); + $qid = substr($qa, strpos($qa, "('")+2, (strpos($qa, "',")-(strpos($qa, "('")+2))); + $qinsert = str_replace("('$qid', '$sid', '$gid',", "('$newsid', '$newgid',", $qa); + $qinsert = str_replace("(`qid`, ", "(", $qinsert); + //$qinsert = substr(trim($qinsert), 0, -1); + //echo "$qinsert
\n"; + $qres = mysql_query($qinsert) or die ("ERROR: Failed to insert question
\n$qinsert
\n".mysql_error()."\n"); //GET NEW GID - $qidquery="SELECT qid FROM questions ORDER BY qid DESC LIMIT 1"; - $qidres=mysql_query($qidquery); - while ($qrow=mysql_fetch_row($qidres)) {$newqid=$qrow[0];} + $qidquery = "SELECT qid FROM questions ORDER BY qid DESC LIMIT 1"; + $qidres = mysql_query($qidquery); + while ($qrow = mysql_fetch_row($qidres)) {$newqid = $qrow[0];} //NOW DO NESTED ANSWERS FOR THIS QID foreach ($answerarray as $aa) { - $qidpos="('"; - $astart=strpos($aa, "$qidpos")+2; - $aend=strpos($aa, "'", $astart)-$astart; + $qidpos = "('"; + $astart = strpos($aa, "$qidpos")+2; + $aend = strpos($aa, "'", $astart)-$astart; if (substr($aa, $astart, $aend) == ($qid)) { - $ainsert=str_replace("('$qid", "('$newqid", $aa); - //$ainsert=substr(trim($ainsert), 0, -1); - $ares=mysql_query($ainsert) or die ("ERROR: Failed to insert answer
$ainsert
".mysql_error()); + $ainsert = str_replace("('$qid", "('$newqid", $aa); + //$ainsert = substr(trim($ainsert), 0, -1); + $ares = mysql_query($ainsert) or die ("ERROR: Failed to insert answer
\n$ainsert
\n".mysql_error()."\n"); } } } } } -echo "Survey Import has been completed. Administration"; +echo "Survey Import has been completed. Administration"; +echo "\n"; unlink($the_full_file_path); ?> \ No newline at end of file