gT("Error: You have to enter a code for this question.","js")."')\">\n" . "\n\n" . "\t\n" . "\t\t\n" . "\t
" . "\t\t".$clang->gT("Add Question")."\n" . "\t\t
\n"; $newquestionoutput .= "\t".'
'."\n"; $newquestionoutput .= "\t".'

'.$clang->gT("Add Question")."

\n"; $newquestionoutput .= "" . "\t\n" . "\t\t\n" . "\t\t\n" . "\t\n" . "\t\t\n" . "\t\t\n" . "\t\n" . "\t\n" . "\t\t\n" . "\t\t\n" . "\t\n" . "\t\n" . "\t\t\n" . "\t\t\n" . "\t\n"; $newquestionoutput .= "\t\n" . "\t\t\n" . "\t\t\n" . "\t\n"; $newquestionoutput .= "\t\n" . "\t\t\n" . "\t\t\n" . "\t\t\n" . "\t\t\n" . "\t\n"; $newquestionoutput .= "\t\n" . "\t\t\n" . "\t\t\n" . "\t\n"; $newquestionoutput .= "\t\n" . "\t\t\n" . "\t\t\n" . "\t\n"; //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); if ($oqresult->RecordCount()) { $newquestionoutput .= "\t\n" . "\t\t\n" . "\t\t\n" . "\t\n"; } else {$newquestionoutput .= "";} //Question attributes $qattributes=questionAttributes(); $newquestionoutput .= "\t\n"; $newquestionoutput .= "\t\n" . "\t\t
".$clang->gT("Code:")."" . " ".$clang->gT("Required")."
".$clang->gT("Question:")."" . getEditor("question-text","question", "[".$clang->gT("Question:", "js")."]",$surveyid,$gid,'',$action) ."
".$clang->gT("Help:")."" . getEditor("question-help","help", "[".$clang->gT("Help:", "js")."]",$surveyid,$gid,'',$action) ."
".$clang->gT("Type:")."
".$clang->gT("Validation:")."\n" . "\t\t\n" . "\t\t
".$clang->gT("Mandatory:")."\n" . "\t\t\t" . "  \n" . "\t\t\t" . "\n" . "\t\t
".$clang->gT("Position:")."\n" . "\t\t\t\n" . "\t\t
".$clang->gT("Question Attributes:")."
"; if (isset($eqrow)) {$newquestionoutput .= questionjavascript($eqrow['type'], $qattributes);} else {$newquestionoutput .= questionjavascript('', $qattributes);} $newquestionoutput .= "\n" . "\t\n" . "\t\n" . "\t\n" . "\t\n" . "
\n" . "
\n" // End TAB . "\t\n"; // Import TAB $newquestionoutput .='

'.$clang->gT("Import Question")."

\n"; $newquestionoutput .= "" . "\t
\n" . "\n\t" . "\t" . "\t\t\n" . "\t\t\n" . "\t\t\t\t\n" . "\t\t\n" . "\t
".$clang->gT("Select CSV File").":
".$clang->gT("Convert Resources links ?")."
\n" . "\t\n" . "\t\n" . "\t\n" . "\t
\n\n" ."\n"; $newquestionoutput .='
'; } if ($action == "copyquestion") { $questlangs = GetAdditionalLanguagesFromSurveyID($surveyid); $baselang = GetBaseLanguageFromSurveyID($surveyid); array_unshift($questlangs,$baselang); $qattributes=questionAttributes(); $editquestion = PrepareEditorScript(); $editquestion .= "\n\t
" . "\t\t".$clang->gT("Copy Question")."
\n" . "
\n" . '
'; 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" . "\t\t\n" . "\t\t\n" . "\t\n"; $editquestion .= "\t\n" . "\t\t\n" . "\t\t\n" . "\t\n"; $editquestion .= "\t\n" . "\t\t\n" . "\t\t\n" . "\t\t\n" . "\t\n" . "\t\t\n" . "\t\t\n" . "\t\n"; $editquestion .= "\t\n" . "\t\t\n"; $editquestion .= "\t\t\n"; $editquestion .= "\t\n" . "\t\t\n" . "\t\t\n" . "\t\n" . "\t\t\n" . "\t\t\n" . "\t\t\n" . "
".$clang->gT("Type:")."
".$clang->gT("Validation:")."\n" . "\t\t\n" . "\t\t
".$clang->gT("Group:")."
".$clang->gT("Mandatory:")."\n" . "\t\t\t".$clang->gT("Yes")." gT("No")." \n" . "\t
"; $editquestion .= questionjavascript($eqrow['type'], $qattributes); if ($eqrow['type'] == "J" || $eqrow['type'] == "I") { $editquestion .= "\t
\n" . "\t\t\n" . "\t\t\n" . "\t\t\n" . "\t\t\n" . "\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" . '
'; $eqrow = $eqresult->FetchRow(); // there should be only one datarow, therefore we don't need a 'while' construct here. // Todo: handler in case that record is not found $editquestion .= '

'.getLanguageNameFromCode($eqrow['language'],false); $editquestion .= '('.$clang->gT("Base Language").')'; $eqrow = array_map('htmlspecialchars', $eqrow); $editquestion .= '

'; $editquestion .= "\t
".$clang->gT("Code:")."\n" . "\t\t\n" . "\t
\n"; $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 .= '
'; $aqquery = "SELECT * FROM {$dbprefix}questions WHERE sid=$surveyid AND gid=$gid AND qid=$qid AND language != '{$baselang}'"; $aqresult = db_execute_assoc($aqquery); while (!$aqresult->EOF) { $aqrow = $aqresult->FetchRow(); $editquestion .= '

'.getLanguageNameFromCode($aqrow['language'],false); $aqrow = array_map('htmlspecialchars', $aqrow); $editquestion .= '

'; $editquestion .= "\t
".$clang->gT("Question:")."\n" . "\t\t\n" . getEditor("question-text","question_".$aqrow['language'], "[".$clang->gT("Question:", "js")."](".$aqrow['language'].")",$surveyid,$gid,$qid,$action) . "\t
\n" . "\t
".$clang->gT("Help:")."\n" . "\t\t\n" . getEditor("question-help","help_".$aqrow['language'], "[".$clang->gT("Help:", "js")."](".$aqrow['language'].")",$surveyid,$gid,$qid,$action) . "\t
\n" . "\t
 \n" . "\t\t \n" . "\t
\n"; $editquestion .= '

'; } //question type: $editquestion .= "\t\n" . "\t\t\n"; if ($activated != "Y") { $editquestion .= "\t\t\n"; } else { $qtypelist=getqtypelist('','array'); $editquestion .= "\t\t\n"; } $editquestion .="\t\n" . "\t\t\n" . "\t\t\n" . "\t\t\n" . "\t\n" . "\t\n" . "\t\n" . "\t\t\n" . "\t\n"; $editquestion .= "\t\n" . "\t\t\n"; if ($activated != "Y") { $editquestion .= "\t\t\n"; } $editquestion .= "\t\n"; $editquestion .= "\t\n" . "\t\t\n" . "\t\t\n"; $editquestion .= "\t\n" . "\t\t\n" . "\t\t\n" . "\t\n"; $editquestion .= "\t
".$clang->gT("Question Type:")."{$qtypelist[$eqrow['type']]} - ".$clang->gT("Cannot be modified (Survey is active)")."\n" . "\t\t\t\n" . "\t\t
".$clang->gT("Group:")."
".$clang->gT("Other:")."\n" . "\t\t\t".$clang->gT("No")."\n"; } else { $editquestion .= " [{$eqrow['other']}] - ".$clang->gT("Cannot be modified")." - ".$clang->gT("Survey is currently active.")."\n" . "\t\t\t
".$clang->gT("Mandatory:")."\n" . "\t\t\t".$clang->gT("No")."\n" . "\t
".$clang->gT("Validation:")."\n" . "\t\t\n" . "\t\t
\n" . "\t\n" . "\t\n" . "\t
\n" . "\t\n"; $qidattributes=getQuestionAttributes($qid); $editquestion .= "\t\t\t
\n"; $editquestion .= "\t\t\t
".$clang->gT("Question Attributes:")."
\n"; foreach ($qidattributes as $qa) { $editquestion .= "\t\t\t" ."
" ."
" ."
" .$qa['attribute']." \n \n \n \n \n" ."\t\t\t
" . "\t\n" . "\t\n" . "\t\n" . "\t\n" . "\t\n" . "
\n" . "
\n
"; } $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.= "\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; } ?>