diff --git a/include/limesurvey/admin/access_denied.php b/include/limesurvey/admin/access_denied.php
new file mode 100644
index 00000000..937de1d7
--- /dev/null
+++ b/include/limesurvey/admin/access_denied.php
@@ -0,0 +1,141 @@
+".$clang->gT("Access denied!")."
\n";
+
+ $action=returnglobal('action');
+ if ( $action == "dumpdb" )
+ {
+ $accesssummary .= "
".$clang->gT("You are not allowed dump the database!")."
";
+ $accesssummary .= "".$clang->gT("Continue")."
\n";
+ }
+ elseif($action == "dumplabel")
+ {
+ $accesssummary .= "".$clang->gT("You are not allowed export a label set!")."
";
+ $accesssummary .= "".$clang->gT("Continue")."
\n";
+ }
+ elseif($action == "edituser")
+ {
+ $accesssummary .= $clang->gT("You are not allowed to change user data!");
+ $accesssummary .= "
".$clang->gT("Continue")."
\n";
+ }
+ elseif($action == "newsurvey")
+ {
+ $accesssummary .= "".$clang->gT("You are not allowed to create new surveys!")."
";
+ $accesssummary .= "".$clang->gT("Continue")."
\n";
+ }
+ elseif($action == "deletesurvey")
+ {
+ $accesssummary .= "".$clang->gT("You are not allowed to delete this survey!")."
";
+ $accesssummary .= "".$clang->gT("Continue")."
\n";
+ }
+ elseif($action == "addquestion")
+ {
+ $accesssummary .= "".$clang->gT("You are not allowed to add new questions for this survey!")."
";
+ $accesssummary .= "".$clang->gT("Continue")."
\n";
+ }
+ elseif($action == "activate")
+ {
+ $accesssummary .= "".$clang->gT("You are not allowed to activate this survey!")."
";
+ $accesssummary .= "".$clang->gT("Continue")."
\n";
+ }
+ elseif($action == "deactivate")
+ {
+ $accesssummary .= "".$clang->gT("You are not allowed to deactivate this survey!")."
";
+ $accesssummary .= "".$clang->gT("Continue")."
\n";
+ }
+ elseif($action == "addgroup")
+ {
+ $accesssummary .= "".$clang->gT("You are not allowed to add a group to this survey!")."
";
+ $accesssummary .= "".$clang->gT("Continue")."
\n";
+ }
+ elseif($action == "ordergroups")
+ {
+ $accesssummary .= "".$clang->gT("You are not allowed to order groups in this survey!")."
";
+ $accesssummary .= "".$clang->gT("Continue")."
\n";
+ }
+ elseif($action == "editsurvey")
+ {
+ $accesssummary .= "".$clang->gT("You are not allowed to edit this survey!")."
";
+ $accesssummary .= "".$clang->gT("Continue")."
\n";
+ }
+ elseif($action == "editgroup")
+ {
+ $accesssummary .= "".$clang->gT("You are not allowed to edit groups in this survey!")."
";
+ $accesssummary .= "".$clang->gT("Continue")."
\n";
+ }
+ elseif($action == "browse_response" || $action == "listcolumn" || $action == "vvexport" || $action == "vvimport")
+ {
+ $accesssummary .= "".$clang->gT("You are not allowed to browse responses!")."
";
+ $accesssummary .= "".$clang->gT("Continue")."
\n";
+ }
+ elseif($action == "assessment")
+ {
+ $accesssummary .= "".$clang->gT("You are not allowed to set assessment rules!")."
";
+ $accesssummary .= "".$clang->gT("Continue")."
\n";
+ }
+ elseif($action == "delusergroup")
+ {
+ $accesssummary .= "".$clang->gT("You are not allowed to delete this group!")."
";
+ $accesssummary .= "".$clang->gT("Continue")."
\n";
+ }
+ elseif($action == "importsurvey")
+ {
+ $accesssummary .= "".$clang->gT("You are not allowed to import a survey!")."
";
+ $accesssummary .= "".$clang->gT("Continue")."
\n";
+ }
+
+ elseif($action == "importgroup")
+ {
+ $accesssummary .= "".$clang->gT("You are not allowed to import a group!")."
";
+ $accesssummary .= "".$clang->gT("Continue")."
\n";
+ }
+ elseif($action == "importquestion")
+ {
+ $accesssummary .= "".$clang->gT("You are not allowed to to import a question!")."
";
+ $accesssummary .= "".$clang->gT("Continue")."
\n";
+ }
+ elseif($action == "CSRFwarn")
+ {
+ $accesssummary .= "".$clang->gT("Security Alert").": ".$clang->gT("Someone may be trying to use your LimeSurvey session (CSRF attack suspected). If you just clicked on a malicious link, please report this to your system administrator.")."
";
+ $accesssummary .= "".$clang->gT("Continue")."
\n";
+ }
+ elseif($action == "FakeGET")
+ {
+ $accesssummary .= "".$clang->gT("Security Alert").": ".$clang->gT("Someone may be trying to use your LimeSurvey session by using dangerous GET requests (CSRF attack suspected). If you just clicked on a malicious link, please report this to your system administrator.")."
";
+ $accesssummary .= "".$clang->gT("Continue")."
\n";
+ }
+ else
+ {
+ $accesssummary .= "
".$clang->gT("You are not allowed to perform this operation!")."
\n";
+ if(!empty($sid))
+ $accesssummary .= "
gT("Continue")."
\n";
+ }
+ else
+ $accesssummary .= "
".$clang->gT("Continue")."
\n";
+ }
+
+ }
+?>
diff --git a/include/limesurvey/admin/activate.php b/include/limesurvey/admin/activate.php
new file mode 100644
index 00000000..0bd6acb0
--- /dev/null
+++ b/include/limesurvey/admin/activate.php
@@ -0,0 +1,550 @@
+".$connect->ErrorMsg());
+ while ($row=$result->FetchRow()) {$lastqid=$row['qid'];}
+ $newqid=$lastqid+1;
+ $query = "UPDATE {$dbprefix}questions SET qid=$newqid WHERE qid=$oldqid";
+ $result = $connect->Execute($query) or safe_die($query."
".$connect->ErrorMsg());
+ //Update conditions.. firstly conditions FOR this question
+ $query = "UPDATE {$dbprefix}conditions SET qid=$newqid WHERE qid=$oldqid";
+ $result = $connect->Execute($query) or safe_die($query."
".$connect->ErrorMsg());
+ //Now conditions based upon this question
+ $query = "SELECT cqid, cfieldname FROM {$dbprefix}conditions WHERE cqid=$oldqid";
+ $result = db_execute_assoc($query) or safe_die($query."
".$connect->ErrorMsg());
+ while ($row=$result->FetchRow())
+ {
+ $switcher[]=array("cqid"=>$row['cqid'], "cfieldname"=>$row['cfieldname']);
+ }
+ if (isset($switcher))
+ {
+ foreach ($switcher as $switch)
+ {
+ $query = "UPDATE {$dbprefix}conditions
+ SET cqid=$newqid,
+ cfieldname='".str_replace("X".$oldqid, "X".$newqid, $switch['cfieldname'])."'
+ WHERE cqid=$oldqid";
+ $result = $connect->Execute($query) or safe_die($query."
".$connect->ErrorMsg());
+ }
+ }
+ //Now question_attributes
+ $query = "UPDATE {$dbprefix}question_attributes SET qid=$newqid WHERE qid=$oldqid";
+ $result = $connect->Execute($query) or safe_die($query."
".$connect->ErrorMsg());
+ //Now answers
+ $query = "UPDATE {$dbprefix}answers SET qid=$newqid WHERE qid=$oldqid";
+ $result = $connect->Execute($query) or safe_die($query."
".$connect->ErrorMsg());
+ }
+ //CHECK TO MAKE SURE ALL QUESTION TYPES THAT REQUIRE ANSWERS HAVE ACTUALLY GOT ANSWERS
+ //THESE QUESTION TYPES ARE:
+ // # "L" -> LIST
+ // # "O" -> LIST WITH COMMENT
+ // # "M" -> MULTIPLE OPTIONS
+ // # "P" -> MULTIPLE OPTIONS WITH COMMENTS
+ // # "A", "B", "C", "E", "F", "H", "^" -> Various Array Types
+ // # "R" -> RANKING
+ // # "U" -> FILE CSV MORE
+ // # "I" -> FILE CSV ONE
+ // # "1" -> MULTI SCALE
+
+
+
+ $chkquery = "SELECT qid, question, gid FROM {$dbprefix}questions WHERE sid={$_GET['sid']} AND type IN ('L', 'O', 'M', 'P', 'A', 'B', 'C', 'E', 'F', 'R', 'J', '!', '^', '1')";
+ $chkresult = db_execute_assoc($chkquery) or safe_die ("Couldn't get list of questions
$chkquery
".$connect->ErrorMsg());
+ while ($chkrow = $chkresult->FetchRow())
+ {
+ $chaquery = "SELECT * FROM {$dbprefix}answers WHERE qid = {$chkrow['qid']} ORDER BY sortorder, answer";
+ $charesult=$connect->Execute($chaquery);
+ $chacount=$charesult->RecordCount();
+ if (!$chacount > 0)
+ {
+ $failedcheck[]=array($chkrow['qid'], $chkrow['question'], ": ".$clang->gT("This question is a multiple answer type question but has no answers."), $chkrow['gid']);
+ }
+ }
+
+ //NOW CHECK THAT ALL QUESTIONS HAVE A 'QUESTION TYPE' FIELD
+ $chkquery = "SELECT qid, question, gid FROM {$dbprefix}questions WHERE sid={$_GET['sid']} AND type = ''";
+ $chkresult = db_execute_assoc($chkquery) or safe_die ("Couldn't check questions for missing types
$chkquery
".$connect->ErrorMsg());
+ while ($chkrow = $chkresult->FetchRow())
+ {
+ $failedcheck[]=array($chkrow['qid'], $chkrow['question'], ": ".$clang->gT("This question does not have a question 'type' set."), $chkrow['gid']);
+ }
+
+
+
+
+ //CHECK THAT FLEXIBLE LABEL TYPE QUESTIONS HAVE AN "LID" SET
+ $chkquery = "SELECT qid, question, gid FROM {$dbprefix}questions WHERE sid={$_GET['sid']} AND type IN ('F', 'H', 'W', 'Z', '1') AND (lid = 0 OR lid is null)";
+ $chkresult = db_execute_assoc($chkquery) or safe_die ("Couldn't check questions for missing LIDs
$chkquery
".$connect->ErrorMsg());
+ while($chkrow = $chkresult->FetchRow()){
+ $failedcheck[]=array($chkrow['qid'], $chkrow['question'], ": ".$clang->gT("This question requires a Labelset, but none is set."), $chkrow['gid']);
+ } // while
+
+ //CHECK THAT FLEXIBLE LABEL TYPE QUESTIONS HAVE AN "LID1" SET FOR MULTI SCALE
+ $chkquery = "SELECT qid, question, gid FROM {$dbprefix}questions WHERE sid={$_GET['sid']} AND (type ='1') AND (lid1 = 0 OR lid1 is null)";
+ $chkresult = db_execute_assoc($chkquery) or safe_die ("Couldn't check questions for missing LIDs
$chkquery
".$connect->ErrorMsg());
+ while($chkrow = $chkresult->FetchRow()){
+ $failedcheck[]=array($chkrow['qid'], $chkrow['question'], ": ".$clang->gT("This question requires a second Labelset, but none is set."), $chkrow['gid']);
+ } // while
+
+
+ //NOW check that all used labelsets have all necessary languages
+ $chkquery = "SELECT qid, question, gid, lid FROM {$dbprefix}questions WHERE sid={$_GET['sid']} AND type IN ('F', 'H', 'W', 'Z', '1') AND (lid > 0) AND (lid is not null)";
+ $chkresult = db_execute_assoc($chkquery) or safe_die ("Couldn't check questions for missing LID languages
$chkquery
".$connect->ErrorMsg());
+ $slangs = GetAdditionalLanguagesFromSurveyID($surveyid);
+ $baselang = GetBaseLanguageFromSurveyID($surveyid);
+ array_unshift($slangs,$baselang);
+ while ($chkrow = $chkresult->FetchRow())
+ {
+ foreach ($slangs as $surveylanguage)
+ {
+ $chkquery2 = "SELECT lid FROM {$dbprefix}labels WHERE language='$surveylanguage' AND (lid = {$chkrow['lid']}) ";
+ $chkresult2 = db_execute_assoc($chkquery2);
+ if ($chkresult2->RecordCount()==0)
+ {
+ $failedcheck[]=array($chkrow['qid'], $chkrow['question'], ": ".$clang->gT("The labelset used in this question does not exists or is missing a translation."), $chkrow['gid']);
+ }
+ } //foreach
+ } //while
+
+ //CHECK THAT ALL CONDITIONS SET ARE FOR QUESTIONS THAT PRECEED THE QUESTION CONDITION
+ //A: Make an array of all the qids in order of appearance
+ // $qorderquery="SELECT * FROM {$dbprefix}questions, {$dbprefix}groups WHERE {$dbprefix}questions.gid={$dbprefix}groups.gid AND {$dbprefix}questions.sid={$_GET['sid']} ORDER BY {$dbprefix}groups.sortorder, {$dbprefix}questions.title";
+ // $qorderresult=$connect->Execute($qorderquery) or safe_die("Couldn't generate a list of questions in order
$qorderquery
".$connect->ErrorMsg());
+ // $qordercount=$qorderresult->RecordCount();
+ // $c=0;
+ // while ($qorderrow=$qorderresult->FetchRow())
+ // {
+ // $qidorder[]=array($c, $qorderrow['qid']);
+ // $c++;
+ // }
+ //TO AVOID NATURAL SORT ORDER ISSUES, FIRST GET ALL QUESTIONS IN NATURAL SORT ORDER, AND FIND OUT WHICH NUMBER IN THAT ORDER THIS QUESTION IS
+ $qorderquery = "SELECT * FROM {$dbprefix}questions WHERE sid=$surveyid AND type not in ('S', 'D', 'T', 'Q')";
+ $qorderresult = db_execute_assoc($qorderquery) or safe_die ("$qorderquery
".$connect->ErrorMsg());
+ $qrows = array(); //Create an empty array in case FetchRow does not return any rows
+ while ($qrow = $qorderresult->FetchRow()) {$qrows[] = $qrow;} // Get table output into array
+ usort($qrows, 'CompareGroupThenTitle'); // Perform a case insensitive natural sort on group name then question title of a multidimensional array
+ $c=0;
+ foreach ($qrows as $qr)
+ {
+ $qidorder[]=array($c, $qrow['qid']);
+ $c++;
+ }
+ $qordercount="";
+ //1: Get each condition's question id
+ $conquery= "SELECT {$dbprefix}conditions.qid, cqid, {$dbprefix}questions.question, "
+ . "{$dbprefix}questions.gid "
+ . "FROM {$dbprefix}conditions, {$dbprefix}questions, {$dbprefix}groups "
+ . "WHERE {$dbprefix}conditions.qid={$dbprefix}questions.qid "
+ . "AND {$dbprefix}questions.gid={$dbprefix}groups.gid ORDER BY {$dbprefix}conditions.qid";
+ $conresult=db_execute_assoc($conquery) or safe_die("Couldn't check conditions for relative consistency
$conquery
".$connect->ErrorMsg());
+ //2: Check each conditions cqid that it occurs later than the cqid
+ while ($conrow=$conresult->FetchRow())
+ {
+ $cqidfound=0;
+ $qidfound=0;
+ $b=0;
+ while ($b<$qordercount)
+ {
+ if ($conrow['cqid'] == $qidorder[$b][1])
+ {
+ $cqidfound = 1;
+ $b=$qordercount;
+ }
+ if ($conrow['qid'] == $qidorder[$b][1])
+ {
+ $qidfound = 1;
+ $b=$qordercount;
+ }
+ if ($qidfound == 1)
+ {
+ $failedcheck[]=array($conrow['qid'], $conrow['question'], ": ".$clang->gT("This question has a condition set, however the condition is based on a question that appears after it."), $conrow['gid']);
+ }
+ $b++;
+ }
+ }
+ //CHECK THAT ALL THE CREATED FIELDS WILL BE UNIQUE
+ $fieldmap=createFieldMap($surveyid, "full");
+ if (isset($fieldmap))
+ {
+ foreach($fieldmap as $fielddata)
+ {
+ $fieldlist[]=$fielddata['fieldname'];
+ }
+ $fieldlist=array_reverse($fieldlist); //let's always change the later duplicate, not the earlier one
+ }
+ $checkKeysUniqueComparison = create_function('$value','if ($value > 1) return true;');
+ @$duplicates = array_keys (array_filter (array_count_values($fieldlist), $checkKeysUniqueComparison));
+ if (isset($duplicates))
+ {
+ foreach ($duplicates as $dup)
+ {
+ $badquestion=arraySearchByKey($dup, $fieldmap, "fieldname", 1);
+ $fix = "[Click Here to Fix]";
+ $failedcheck[]=array($badquestion['qid'], $badquestion['question'], ": Bad duplicate fieldname $fix", $badquestion['gid']);
+ }
+ }
+
+ //IF ANY OF THE CHECKS FAILED, PRESENT THIS SCREEN
+ if (isset($failedcheck) && $failedcheck)
+ {
+ $activateoutput .= "
\n\n";
+ $activateoutput .= "\t\t\t\t| ".$clang->gT("Activate Survey")." ($surveyid) |
\n";
+ $activateoutput .= "\t\n";
+ $activateoutput .= "\t\t\n";
+ $activateoutput .= "\t\t\t".$clang->gT("Error")." \n";
+ $activateoutput .= "\t\t\t".$clang->gT("Survey does not pass consistency check")."\n";
+ $activateoutput .= "\t\t | \n";
+ $activateoutput .= "\t
\n";
+ $activateoutput .= "\t\n";
+ $activateoutput .= "\t\t\n";
+ $activateoutput .= "\t\t\t".$clang->gT("The following problems have been found:")." \n";
+ $activateoutput .= "\t\t\t\n";
+ foreach ($failedcheck as $fc)
+ {
+ $activateoutput .= "\t\t\t\t- Question qid-{$fc[0]} (\"{$fc[1]}\"){$fc[2]}
\n";
+ }
+ $activateoutput .= "\t\t\t \n";
+ $activateoutput .= "\t\t\t".$clang->gT("The survey cannot be activated until these problems have been resolved.")."\n";
+ $activateoutput .= "\t\t | \n";
+ $activateoutput .= "\t
\n";
+ $activateoutput .= "
\n";
+
+ return;
+ }
+
+ $activateoutput .= "
\n
\n";
+
+}
+else
+{
+ //Create the survey responses table
+ $createsurvey = "id I NOTNULL AUTO PRIMARY,\n";
+ $createsurvey .= " submitdate T,\n";
+ $createsurvey .= " startlanguage C(20) NOTNULL ,\n";
+ //Check for any additional fields for this survey and create necessary fields (token and datestamp)
+ $pquery = "SELECT private, allowregister, datestamp, ipaddr, refurl FROM {$dbprefix}surveys WHERE sid={$postsid}";
+ $presult=db_execute_assoc($pquery);
+ while($prow=$presult->FetchRow())
+ {
+ if ($prow['private'] == "N")
+ {
+ $createsurvey .= " token C(36),\n";
+ $surveynotprivate="TRUE";
+ }
+ if ($prow['allowregister'] == "Y")
+ {
+ $surveyallowsregistration="TRUE";
+ }
+ if ($prow['datestamp'] == "Y")
+ {
+ $createsurvey .= " datestamp T NOTNULL,\n";
+ $createsurvey .= " startdate T NOTNULL,\n";
+ }
+ if ($prow['ipaddr'] == "Y")
+ {
+ $createsurvey .= " ipaddr X,\n";
+ }
+ //Check to see if 'refurl' field is required.
+ if ($prow['refurl'] == "Y")
+ {
+ $createsurvey .= " refurl X,\n";
+ }
+ }
+ //Get list of questions for the base language
+ $aquery = " SELECT * FROM ".db_table_name('questions').", ".db_table_name('groups')
+ ." WHERE ".db_table_name('questions').".gid=".db_table_name('groups').".gid "
+ ." AND ".db_table_name('questions').".sid={$postsid} "
+ ." AND ".db_table_name('groups').".language='".GetbaseLanguageFromSurveyid($postsid). "' "
+ ." AND ".db_table_name('questions').".language='".GetbaseLanguageFromSurveyid($postsid). "' "
+ ." ORDER BY ".db_table_name('groups').".group_order, title";
+ $aresult = db_execute_assoc($aquery);
+ while ($arow=$aresult->FetchRow()) //With each question, create the appropriate field(s)
+ {
+ if ( substr($createsurvey, strlen($createsurvey)-2, 2) != ",\n") {$createsurvey .= ",\n";}
+
+ if ($arow['type'] != "M" && $arow['type'] != "A" && $arow['type'] != "B" &&
+ $arow['type'] != "C" && $arow['type'] != "E" && $arow['type'] != "F" &&
+ $arow['type'] != "H" && $arow['type'] != "P" && $arow['type'] != "R" &&
+ $arow['type'] != "Q" && $arow['type'] != "^" && $arow['type'] != "J" &&
+ $arow['type'] != "K" && $arow['type'] != "1")
+ {
+ $createsurvey .= " `{$arow['sid']}X{$arow['gid']}X{$arow['qid']}`";
+ switch($arow['type'])
+ {
+ case "N": //NUMERICAL
+ $createsurvey .= " C(20)";
+ break;
+ case "S": //SHORT TEXT
+ if ($databasetype=='mysql') {$createsurvey .= " X";}
+ else {$createsurvey .= " C(255)";}
+ break;
+ case "L": //LIST (RADIO)
+ case "!": //LIST (DROPDOWN)
+ case "W":
+ case "Z":
+ $createsurvey .= " C(5)";
+ if ($arow['other'] == "Y")
+ {
+ $createsurvey .= ",\n`{$arow['sid']}X{$arow['gid']}X{$arow['qid']}other` X";
+ }
+ break;
+ case "I": // CSV ONE
+ $createsurvey .= " C(5)";
+ break;
+ case "O": //DROPDOWN LIST WITH COMMENT
+ $createsurvey .= " C(5),\n `{$arow['sid']}X{$arow['gid']}X{$arow['qid']}comment` X";
+ break;
+ case "T": //LONG TEXT
+ $createsurvey .= " X";
+ break;
+ case "U": //HUGE TEXT
+ $createsurvey .= " X";
+ break;
+ case "D": //DATE
+ $createsurvey .= " D";
+ break;
+ case "5": //5 Point Choice
+ case "G": //Gender
+ case "Y": //YesNo
+ case "X": //Boilerplate
+ $createsurvey .= " C(1)";
+ break;
+ }
+ }
+ elseif ($arow['type'] == "M" || $arow['type'] == "A" || $arow['type'] == "B" ||
+ $arow['type'] == "C" || $arow['type'] == "E" || $arow['type'] == "F" ||
+ $arow['type'] == "H" || $arow['type'] == "P" || $arow['type'] == "^")
+ {
+ //MULTI ENTRY
+ $abquery = "SELECT a.*, q.other FROM {$dbprefix}answers as a, {$dbprefix}questions as q"
+ ." WHERE a.qid=q.qid AND sid={$postsid} AND q.qid={$arow['qid']} "
+ ." AND a.language='".GetbaseLanguageFromSurveyid($postsid). "' "
+ ." AND q.language='".GetbaseLanguageFromSurveyid($postsid). "' "
+ ." ORDER BY a.sortorder, a.answer";
+ $abresult=db_execute_assoc($abquery) or safe_die ("Couldn't get perform answers query
$abquery
".$connect->ErrorMsg());
+ while ($abrow=$abresult->FetchRow())
+ {
+ $createsurvey .= " `{$arow['sid']}X{$arow['gid']}X{$arow['qid']}{$abrow['code']}` C(5),\n";
+ if ($abrow['other']=="Y") {$alsoother="Y";}
+ if ($arow['type'] == "P")
+ {
+ $createsurvey .= " `{$arow['sid']}X{$arow['gid']}X{$arow['qid']}{$abrow['code']}comment` X,\n";
+ }
+ }
+ if ((isset($alsoother) && $alsoother=="Y") && ($arow['type']=="M" || $arow['type']=="P" || $arow['type']=="1")) //Sc: check!
+ {
+ $createsurvey .= " `{$arow['sid']}X{$arow['gid']}X{$arow['qid']}other` C(255),\n";
+ if ($arow['type']=="P")
+ {
+ $createsurvey .= " `{$arow['sid']}X{$arow['gid']}X{$arow['qid']}othercomment` X,\n";
+ }
+ }
+ }
+ elseif ($arow['type'] == "Q")
+ {
+ $abquery = "SELECT a.*, q.other FROM {$dbprefix}answers as a, {$dbprefix}questions as q WHERE a.qid=q.qid AND sid={$postsid} AND q.qid={$arow['qid']} "
+ ." AND a.language='".GetbaseLanguageFromSurveyid($postsid). "' "
+ ." AND q.language='".GetbaseLanguageFromSurveyid($postsid). "' "
+ ." ORDER BY a.sortorder, a.answer";
+ $abresult=db_execute_assoc($abquery) or safe_die ("Couldn't get perform answers query
$abquery
".$connect->ErrorMsg());
+ while ($abrow = $abresult->FetchRow())
+ {
+ $createsurvey .= " `{$arow['sid']}X{$arow['gid']}X{$arow['qid']}{$abrow['code']}`";
+ if ($databasetype=='mysql')
+ {
+ $createsurvey .= " X";
+ }
+ else
+ {
+ $createsurvey .= " C(255)";
+ }
+ $createsurvey .= ",\n";
+ }
+ }
+
+ elseif ($arow['type'] == "K") //Multiple Numeric - replica of multiple short text, except numbers only
+ {
+ $abquery = "SELECT a.*, q.other FROM {$dbprefix}answers as a, {$dbprefix}questions as q WHERE a.qid=q.qid AND sid={$postsid} AND q.qid={$arow['qid']} "
+ ." AND a.language='".GetbaseLanguageFromSurveyid($postsid). "' "
+ ." AND q.language='".GetbaseLanguageFromSurveyid($postsid). "' "
+ ." ORDER BY a.sortorder, a.answer";
+ $abresult=db_execute_assoc($abquery) or safe_die ("Couldn't get perform answers query
$abquery
".$connect->ErrorMsg());
+ while ($abrow = $abresult->FetchRow())
+ {
+ $createsurvey .= " `{$arow['sid']}X{$arow['gid']}X{$arow['qid']}{$abrow['code']}` C(20),\n";
+ }
+ } //End if ($arow['type'] == "K")
+/* elseif ($arow['type'] == "J")
+ {
+ $abquery = "SELECT {$dbprefix}answers.*, {$dbprefix}questions.other FROM {$dbprefix}answers, {$dbprefix}questions WHERE {$dbprefix}answers.qid={$dbprefix}questions.qid AND sid={$_GET['sid']} AND {$dbprefix}questions.qid={$arow['qid']} ORDER BY {$dbprefix}answers.sortorder, {$dbprefix}answers.answer";
+ $abresult=db_execute_assoc($abquery) or safe_die ("Couldn't get perform answers query
$abquery
".$connect->ErrorMsg());
+ while ($abrow = $abresultt->FetchRow())
+ {
+ $createsurvey .= " `{$arow['sid']}X{$arow['gid']}X{$arow['qid']}{$abrow['code']}` C(5),\n";
+ }
+ }*/
+ elseif ($arow['type'] == "R")
+ {
+ //MULTI ENTRY
+ $abquery = "SELECT a.*, q.other FROM {$dbprefix}answers as a, {$dbprefix}questions as q"
+ ." WHERE a.qid=q.qid AND sid={$postsid} AND q.qid={$arow['qid']} "
+ ." AND a.language='".GetbaseLanguageFromSurveyid($postsid). "' "
+ ." AND q.language='".GetbaseLanguageFromSurveyid($postsid). "' "
+ ." ORDER BY a.sortorder, a.answer";
+ $abresult=$connect->Execute($abquery) or safe_die ("Couldn't get perform answers query
$abquery
".$connect->ErrorMsg());
+ $abcount=$abresult->RecordCount();
+ for ($i=1; $i<=$abcount; $i++)
+ {
+ $createsurvey .= " `{$arow['sid']}X{$arow['gid']}X{$arow['qid']}$i` C(5),\n";
+ }
+ }
+ elseif ($arow['type'] == "1")
+ {
+ $abquery = "SELECT a.*, q.other FROM {$dbprefix}answers as a, {$dbprefix}questions as q"
+ ." WHERE a.qid=q.qid AND sid={$postsid} AND q.qid={$arow['qid']} "
+ ." AND a.language='".GetbaseLanguageFromSurveyid($postsid). "' "
+ ." AND q.language='".GetbaseLanguageFromSurveyid($postsid). "' "
+ ." ORDER BY a.sortorder, a.answer";
+ $abresult=db_execute_assoc($abquery) or safe_die ("Couldn't get perform answers query
$abquery
".$connect->ErrorMsg());
+ $abcount=$abresult->RecordCount();
+ while ($abrow = $abresult->FetchRow())
+ {
+ $abmultiscalequery = "SELECT a.*, q.other FROM {$dbprefix}answers as a, {$dbprefix}questions as q, {$dbprefix}labels as l"
+ ." WHERE a.qid=q.qid AND sid={$postsid} AND q.qid={$arow['qid']} "
+ ." AND l.lid=q.lid AND sid={$postsid} AND q.qid={$arow['qid']} AND l.title = '' "
+ ." AND l.language='".GetbaseLanguageFromSurveyid($postsid). "' "
+ ." AND q.language='".GetbaseLanguageFromSurveyid($postsid). "' ";
+ $abmultiscaleresult=$connect->Execute($abmultiscalequery) or safe_die ("Couldn't get perform answers query
$abmultiscalequery
".$connect->ErrorMsg());
+ $abmultiscaleresultcount =$abmultiscaleresult->RecordCount();
+ $abmultiscaleresultcount = 1;
+ for ($j=0; $j<=$abmultiscaleresultcount; $j++)
+ {
+ $createsurvey .= " `{$arow['sid']}X{$arow['gid']}X{$arow['qid']}{$abrow['code']}#$j` C(5),\n";
+ }
+ }
+ }
+ }
+
+ // If last question is of type MCABCEFHP^QKJR let's get rid of the ending coma in createsurvey
+ $createsurvey = rtrim($createsurvey, ",\n")."\n"; // Does nothing if not ending with a comma
+ $tabname = "{$dbprefix}survey_{$postsid}"; # not using db_table_name as it quotes the table name (as does CreateTableSQL)
+
+ $taboptarray = array('mysql' => 'TYPE='.$databasetabletype.' CHARACTER SET utf8 COLLATE utf8_unicode_ci');
+ $dict = NewDataDictionary($connect);
+ $sqlarray = $dict->CreateTableSQL($tabname, $createsurvey, $taboptarray);
+ $execresult=$dict->ExecuteSQLArray($sqlarray,1);
+ if ($execresult==0 || $execresult==1)
+ {
+ $activateoutput .= "
\n\n" .
+ "| ".$clang->gT("Activate Survey")." ($surveyid) |
\n" .
+ "\n" .
+ "".$clang->gT("Survey could not be actived.")." \n" .
+ "".$clang->gT("Main Admin Screen")."\n" .
+ "DB ".$clang->gT("Error").": \n" . $connect->ErrorMsg() . "\n" .
+ "$createsurvey \n" .
+ " |
\n" .
+ "