';
foreach ($questlangs as $language)
{
$egquery = "SELECT * FROM ".db_table_name('questions')." WHERE sid=$surveyid AND gid=$gid AND qid=$qid and language=".db_quoteall($language);
$egresult = db_execute_assoc($egquery);
$eqrow = $egresult->FetchRow();
$eqrow = array_map('htmlspecialchars', $eqrow);
$editquestion .= '
'.getLanguageNameFromCode($eqrow['language'],false);
if ($eqrow['language']==GetBaseLanguageFromSurveyID($surveyid))
{
$editquestion .= "(".$clang->gT("Base Language").") "
. "\t
".$clang->gT("Code:")." \n"
. "\t\t ".$clang->gT("Note: You MUST enter a new question code!")."\n"
. "\t
\n";
}
else {
$editquestion .= '';
}
$editquestion .= "\t
".$clang->gT("Question:")." \n"
. "\t\t\n"
. getEditor("question-text","question_".$eqrow['language'], "[".$clang->gT("Question:", "js")."](".$eqrow['language'].")",$surveyid,$gid,$qid,$action)
. "\t
\n"
. "\t
".$clang->gT("Help:")." \n"
. "\t\t\n"
. getEditor("question-help","help_".$eqrow['language'], "[".$clang->gT("Help:", "js")."](".$eqrow['language'].")",$surveyid,$gid,$qid,$action)
. "\t
\n"
. "\t
\n"
. "\t\t\n"
. "\t
\n";
$editquestion .= '
';
}
$editquestion .= "\t
\n";
}
else
{
$editquestion .= "
".$clang->gT("Copy Answers?")." \n"
. "\t\t
"
. "\n"
. "\t\n"
. "\t
\n"
. "\t\t".$clang->gT("Copy Attributes?")." \n"
. "\t\t "
. " \n"
. "\t \n"
. "\t
\n"
. "\t\t \n"
. "\t\t \n"
. "\t\t \n"
. "\t\t \n"
. "\t \n"
. "\n\n";
}
}
if ($action == "editquestion" || $action == "editattribute" || $action == "delattribute" || $action == "addattribute")
{
$questlangs = GetAdditionalLanguagesFromSurveyID($surveyid);
$baselang = GetBaseLanguageFromSurveyID($surveyid);
$questlangs[] = $baselang;
$questlangs = array_flip($questlangs);
$egquery = "SELECT * FROM ".db_table_name('questions')." WHERE sid=$surveyid AND gid=$gid AND qid=$qid";
$egresult = db_execute_assoc($egquery);
while ($esrow = $egresult->FetchRow())
{
if(!array_key_exists($esrow['language'], $questlangs)) // Language Exists, BUT ITS NOT ON THE SURVEY ANYMORE.
{
$egquery = "DELETE FROM ".db_table_name('questions')." WHERE sid='{$surveyid}' AND gid='{$gid}' AND qid='{$qid}' AND language='".$esrow['language']."'";
$egresultD = $connect->Execute($egquery);
} else {
$questlangs[$esrow['language']] = 99;
}
if ($esrow['language'] == $baselang) $basesettings = array('lid' => $esrow['lid'], 'lid1' => $esrow['lid1'],'question_order' => $esrow['question_order'],'other' => $esrow['other'],'mandatory' => $esrow['mandatory'],'type' => $esrow['type'],'title' => $esrow['title'],'preg' => $esrow['preg'],'question' => $esrow['question'],'help' => $esrow['help']);
}
while (list($key,$value) = each($questlangs))
{
if ($value != 99)
{
if ($databasetype=='odbc_mssql') {@$connect->Execute("SET IDENTITY_INSERT ".db_table_name('questions')." ON");}
$egquery = "INSERT INTO ".db_table_name('questions')." (qid, sid, gid, type, title, question, preg, help, other, mandatory, lid, lid1, question_order, language)"
." VALUES ('{$qid}','{$surveyid}', '{$gid}', '{$basesettings['type']}', '{$basesettings['title']}',"
." '{$basesettings['question']}', '{$basesettings['preg']}', '{$basesettings['help']}', '{$basesettings['other']}', '{$basesettings['mandatory']}', '{$basesettings['lid']}', '{$basesettings['lid1']}', '{$basesettings['question_order']}','{$key}')";
$egresult = $connect->Execute($egquery);
if ($databasetype=='odbc_mssql') {@$connect->Execute("SET IDENTITY_INSERT ".db_table_name('questions')." OFF");}
}
}
$eqquery = "SELECT * FROM {$dbprefix}questions WHERE sid=$surveyid AND gid=$gid AND qid=$qid AND language='{$baselang}'";
$eqresult = db_execute_assoc($eqquery);
$editquestion = PrepareEditorScript();
$editquestion .= "
\n\t"
. "\t\t".$clang->gT("Edit Question")."
\n"
. "
\n"
. "\t\n";
$qidattributes=getQuestionAttributes($qid);
$editquestion .= "\t\t\t
\n";
foreach ($qidattributes as $qa)
{
$editquestion .= "\t\t\t";
}
$editquestion .= "
";
$editquestion .= questionjavascript($eqrow['type'], $qattributes);
}
//Constructing the interface here...
if($action == "orderquestions")
{
if (isset($_POST['questionordermethod']))
{
switch($_POST['questionordermethod'])
{
// Pressing the Up button
case $clang->gT("Up", "unescaped"):
$newsortorder=$postsortorder-1;
$oldsortorder=$postsortorder;
$cdquery = "UPDATE ".db_table_name('questions')." SET question_order=-1 WHERE gid=$gid AND question_order=$newsortorder";
$cdresult=$connect->Execute($cdquery) or safe_die($connect->ErrorMsg());
$cdquery = "UPDATE ".db_table_name('questions')." SET question_order=$newsortorder WHERE gid=$gid AND question_order=$oldsortorder";
$cdresult=$connect->Execute($cdquery) or safe_die($connect->ErrorMsg());
$cdquery = "UPDATE ".db_table_name('questions')." SET question_order='$oldsortorder' WHERE gid=$gid AND question_order=-1";
$cdresult=$connect->Execute($cdquery) or safe_die($connect->ErrorMsg());
break;
// Pressing the Down button
case $clang->gT("Dn", "unescaped"):
$newsortorder=$postsortorder+1;
$oldsortorder=$postsortorder;
$cdquery = "UPDATE ".db_table_name('questions')." SET question_order=-1 WHERE gid=$gid AND question_order=$newsortorder";
$cdresult=$connect->Execute($cdquery) or safe_die($connect->ErrorMsg());
$cdquery = "UPDATE ".db_table_name('questions')." SET question_order='$newsortorder' WHERE gid=$gid AND question_order=$oldsortorder";
$cdresult=$connect->Execute($cdquery) or safe_die($connect->ErrorMsg());
$cdquery = "UPDATE ".db_table_name('questions')." SET question_order=$oldsortorder WHERE gid=$gid AND question_order=-1";
$cdresult=$connect->Execute($cdquery) or safe_die($connect->ErrorMsg());
break;
}
}
if ((!empty($_POST['questionmovefrom']) || (isset($_POST['questionmovefrom']) && $_POST['questionmovefrom'] == '0')) && (!empty($_POST['questionmoveto']) || (isset($_POST['questionmoveto']) && $_POST['questionmoveto'] == '0')))
{
$newpos=$_POST['questionmoveto'];
$oldpos=$_POST['questionmovefrom'];
if($newpos > $oldpos)
{
//Move the question we're changing out of the way
$cdquery = "UPDATE ".db_table_name('questions')." SET question_order=-1 WHERE gid=$gid AND question_order=$oldpos";
$cdresult=$connect->Execute($cdquery) or safe_die($connect->ErrorMsg());
//Move all question_orders that are less than the newpos down one
$cdquery = "UPDATE ".db_table_name('questions')." SET question_order=question_order-1 WHERE gid=$gid AND question_order > 0 AND question_order <= $newpos";
$cdresult=$connect->Execute($cdquery) or safe_die($connect->ErrorMsg());
//Renumber the question we're changing
$cdquery = "UPDATE ".db_table_name('questions')." SET question_order=$newpos WHERE gid=$gid AND question_order=-1";
$cdresult=$connect->Execute($cdquery) or safe_die($connect->ErrorMsg());
}
if(($newpos+1) < $oldpos)
{
//echo "Newpos $newpos, Oldpos $oldpos";
//Move the question we're changing out of the way
$cdquery = "UPDATE ".db_table_name('questions')." SET question_order=-1 WHERE gid=$gid AND question_order=$oldpos";
$cdresult=$connect->Execute($cdquery) or safe_die($connect->ErrorMsg());
//Move all question_orders that are later than the newpos up one
$cdquery = "UPDATE ".db_table_name('questions')." SET question_order=question_order+1 WHERE gid=$gid AND question_order > ".$newpos." AND question_order <= $oldpos";
$cdresult=$connect->Execute($cdquery) or safe_die($connect->ErrorMsg());
//Renumber the question we're changing
$cdquery = "UPDATE ".db_table_name('questions')." SET question_order=".($newpos+1)." WHERE gid=$gid AND question_order=-1";
$cdresult=$connect->Execute($cdquery) or safe_die($connect->ErrorMsg());
}
}
//Get the questions for this group
$baselang = GetBaseLanguageFromSurveyID($surveyid);
$oqquery = "SELECT * FROM ".db_table_name('questions')." WHERE sid=$surveyid AND gid=$gid AND language='".$baselang."' order by question_order" ;
$oqresult = db_execute_assoc($oqquery);
$orderquestions = "
\n\t"
. "\t\t".$clang->gT("Change Question Order")." "
. "
\n";
$questioncount = $oqresult->RecordCount();
$oqarray = $oqresult->GetArray();
$minioqarray=$oqarray;
// Get the condition dependecy array for all questions in this array and group
$questdepsarray = GetQuestDepsForConditions($surveyid,$gid);
if (!is_null($questdepsarray))
{
$orderquestions .= "
".$clang->gT("Warning").": ".$clang->gT("Current group is using conditional questions")."".$clang->gT("Re-ordering questions in this group is restricted to ensure that questions on which conditions are based aren't reordered after questions having the conditions set")." ".$clang->gT("See the conditions marked on the following questions").":";
}
$orderquestions .= "
";
for($i=0; $i < $questioncount ; $i++) //Assumes that all question orders start with 0
{
$downdisabled = "";
$updisabled = "";
//Check if question is relied on as a condition dependency by the next question, and if so, don't allow moving down
if ( !is_null($questdepsarray) && $i < $questioncount-1 &&
array_key_exists($oqarray[$i+1]['qid'],$questdepsarray) &&
array_key_exists($oqarray[$i]['qid'],$questdepsarray[$oqarray[$i+1]['qid']]) )
{
$downdisabled = "disabled=\"true\" class=\"disabledbtn\"";
}
//Check if question has a condition dependency on the preceding question, and if so, don't allow moving up
if ( !is_null($questdepsarray) && $i !=0 &&
array_key_exists($oqarray[$i]['qid'],$questdepsarray) &&
array_key_exists($oqarray[$i-1]['qid'],$questdepsarray[$oqarray[$i]['qid']]) )
{
$updisabled = "disabled=\"true\" class=\"disabledbtn\"";
}
//Move to location
$orderquestions.="\n" ;
$orderquestions.="\t\n";
$orderquestions.="".$clang->gT("Place after..")." \n";
//Display the "position at beginning" item
if(!is_null($questdepsarray) && $i != 0 &&
!array_key_exists($oqarray[$i]['qid'], $questdepsarray))
{
$orderquestions.="".$clang->gT("At beginning")." \n";
}
//Find out if there are any dependencies
$max_start_order=0;
if ( !is_null($questdepsarray) && $i!=0 &&
array_key_exists($oqarray[$i]['qid'], $questdepsarray)) //This should find out if there are any dependencies
{
foreach($questdepsarray[$oqarray[$i]['qid']] as $key=>$val) {
//qet the question_order value for each of the dependencies
foreach($minioqarray as $mo) {
if($mo['qid'] == $key && $mo['question_order'] > $max_start_order) //If there is a matching condition, and the question order for that condition is higher than the one already set:
{
$max_start_order = $mo['question_order']; //Set the maximum question condition to this
}
}
}
}
//Find out if any questions use this as a dependency
$max_end_order=$questioncount+1;
if ( !is_null($questdepsarray))
{
//There doesn't seem to be any choice but to go through the questdepsarray one at a time
//to find which question has a dependence on this one
foreach($questdepsarray as $qdarray)
{
if (array_key_exists($oqarray[$i]['qid'], $qdarray))
{
$cqidquery = "SELECT question_order
FROM ".db_table_name('conditions').", ".db_table_name('questions')."
WHERE ".db_table_name('conditions').".qid=".db_table_name('questions').".qid
AND cid=".$qdarray[$oqarray[$i]['qid']][0];
$cqidresult = db_execute_assoc($cqidquery);
$cqidrow = $cqidresult->FetchRow();
$max_end_order=$cqidrow['question_order'];
}
}
}
$minipos=$minioqarray[0]['question_order']; //Start at the very first question_order
foreach($minioqarray as $mo)
{
if($minipos >= $max_start_order && $minipos < $max_end_order)
{
$orderquestions.="".$mo['title']." \n";
}
$minipos++;
}
$orderquestions.=" \n";
$orderquestions.= "\t \n";
if ($i < $questioncount-1)
{
// Fill the sortorder hiddenfield so we know what field is moved down
$orderquestions.= "\t \n";
}
$orderquestions.= "".$oqarray[$i]['title']." : ".$oqarray[$i]['question'];
$orderquestions.= " \n" ;
}
$orderquestions.=" \n"
. " \n"
. " \n"
. "\t "
. "\t "
. "" ;
$orderquestions .="
" ;
}
function questionjavascript($type, $qattributes)
{
$newquestionoutput = "\n";
return $newquestionoutput;
}
?>