".$clang->gT("Copy Question")."\n" . "
gT("Error: You have to enter a question code.",'js')."');\">\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
  • \n" . " ".$clang->gT("Note: You MUST enter a new question code!")."\n" . "\t
  • \n"; } else { $editquestion .= '
      '; } $editquestion .= "\t
    • \n" . "\n" . getEditor("question-text","question_".$eqrow['language'], "[".$clang->gT("Question:", "js")."](".$eqrow['language'].")",$surveyid,$gid,$qid,$action) . "\t
    • \n" . "\t
    • \n" . "\n" . getEditor("question-help","help_".$eqrow['language'], "[".$clang->gT("Help:", "js")."](".$eqrow['language'].")",$surveyid,$gid,$qid,$action) . "\t
    • \n"; $editquestion .= '
'; } $editquestion .= "\t
\n" . "

\n" . "\n" . "\n" . "\n" . "\t

\n"; } if ($action == "editdefaultvalues") { $questlangs = GetAdditionalLanguagesFromSurveyID($surveyid); $baselang = GetBaseLanguageFromSurveyID($surveyid); array_unshift($questlangs,$baselang); $questionrow=$connect->GetRow("SELECT type, other, title, question, same_default FROM ".db_table_name('questions')." WHERE sid=$surveyid AND gid=$gid AND qid=$qid AND language='$baselang'"); $qtproperties=getqtypelist('','array'); $editdefvalues="
".$clang->gT('Edit default answer values')."
" . '
' . "
\n"; foreach ($questlangs as $language) { $editdefvalues .= '

'.getLanguageNameFromCode($language,false).'

'; $editdefvalues.="
    "; // If there are answerscales if ($qtproperties[$questionrow['type']]['answerscales']>0) { for ($scale_id=0;$scale_id<$qtproperties[$questionrow['type']]['answerscales'];$scale_id++) { $editdefvalues.="
  • "; } else { $editdefvalues.=sprintf($clang->gT('Default answer value:'),$scale_id).""; } $defaultvalue=$connect->GetOne("SELECT defaultvalue FROM ".db_table_name('defaultvalues')." WHERE qid=$qid AND specialtype='' and scale_id={$scale_id} AND language='{$language}'"); $editdefvalues.="
  • "; } } } // If there are subquestions and no answerscales if ($qtproperties[$questionrow['type']]['answerscales']==0 && $qtproperties[$questionrow['type']]['subquestions']>0) { for ($scale_id=0;$scale_id<$qtproperties[$questionrow['type']]['subquestions'];$scale_id++) { $sqquery = "SELECT * FROM ".db_table_name('questions')." WHERE sid=$surveyid AND gid=$gid AND parent_qid=$qid and language=".db_quoteall($language)." and scale_id=0 order by question_order"; $sqresult = db_execute_assoc($sqquery); $sqrows = $sqresult->GetRows(); if ($qtproperties[$questionrow['type']]['subquestions']>1) { $editdefvalues.="
    ".sprintf($clang->gT('Default answer for scale %s:'),$scale_id)."
    "; } if ($questionrow['type']=='M' || $questionrow['type']=='P') { $options=array(''=>$clang->gT(''),'Y'=>$clang->gT('Checked')); } $editdefvalues.="
      "; foreach ($sqrows as $aSubquestion) { $defaultvalue=$connect->GetOne("SELECT defaultvalue FROM ".db_table_name('defaultvalues')." WHERE qid=$qid AND specialtype='' and sqid={$aSubquestion['qid']} and scale_id={$scale_id} AND language='{$language}'"); $editdefvalues.="
    • "; $editdefvalues.="

      \n" . "\t

      \n" . "\t"; $editdefvalues.="

    • "; } if ($action == "editquestion" || $action=="addquestion") { $adding=($action=="addquestion"); $questlangs = GetAdditionalLanguagesFromSurveyID($surveyid); $baselang = GetBaseLanguageFromSurveyID($surveyid); $questlangs[] = $baselang; $questlangs = array_flip($questlangs); if (!$adding) { $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('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']); } } if ($egresult==false or $egresult->RecordCount()==0) { safe_die('Invalid question id'); } while (list($key,$value) = each($questlangs)) { if ($value != 99) { db_switchIDInsert('questions',true); $egquery = "INSERT INTO ".db_table_name('questions')." (qid, sid, gid, type, title, question, preg, help, other, mandatory, question_order, language)" ." VALUES ('{$qid}','{$surveyid}', '{$gid}', '{$basesettings['type']}', '{$basesettings['title']}'," ." '{$basesettings['question']}', '{$basesettings['preg']}', '{$basesettings['help']}', '{$basesettings['other']}', '{$basesettings['mandatory']}', '{$basesettings['question_order']}','{$key}')"; $egresult = $connect->Execute($egquery); db_switchIDInsert('questions',false); } } $eqquery = "SELECT * FROM {$dbprefix}questions WHERE sid=$surveyid AND gid=$gid AND qid=$qid AND language='{$baselang}'"; $eqresult = db_execute_assoc($eqquery); } $js_admin_includes[] = '../scripts/jquery/jquery.dd.js'; $css_admin_includes[] = '../scripts/jquery/dd.css'; $editquestion = PrepareEditorScript(); $qtypelist=getqtypelist('','array'); $qDescToCode = 'qDescToCode = {'; $qCodeToInfo = 'qCodeToInfo = {'; foreach ($qtypelist as $qtype=>$qdesc){ $qDescToCode .= " '{$qdesc['description']}' : '{$qtype}', \n"; $qCodeToInfo .= " '{$qtype}' : '".json_encode($qdesc)."', \n"; } $qTypeOutput = "$qDescToCode 'null':'null' }; \n $qCodeToInfo 'null':'null' };"; $editquestion .= "\n
      "; if (!$adding) {$editquestion .=$clang->gT("Edit question");} else {$editquestion .=$clang->gT("Add a new question");}; $editquestion .= "
      \n"; if (!$adding) { $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 } else { $eqrow['language']=$baselang; $eqrow['title']=''; $eqrow['question']=''; $eqrow['help']=''; $eqrow['type']='T'; $eqrow['lid']=0; $eqrow['lid1']=0; $eqrow['gid']=$gid; $eqrow['other']='N'; $eqrow['mandatory']='N'; $eqrow['preg']=''; } $editquestion .= "
      \n"; $editquestion .= "
      gT("Error: You have to enter a question code.",'js')."');\">\n"; $editquestion .= '
      '; $eqrow = array_map('htmlspecialchars', $eqrow); $editquestion .= "\t
      ".$clang->gT("Code:")."\n" . "\n" . "\t
      \n"; $editquestion .= "\t
      ".$clang->gT("Question:")."\n" . "\n" . getEditor("question-text","question_".$eqrow['language'], "[".$clang->gT("Question:", "js")."](".$eqrow['language'].")",$surveyid,$gid,$qid,$action) . "\t
      \n" . "\t
      ".$clang->gT("Help:")."\n" . "\n" . getEditor("question-help","help_".$eqrow['language'], "[".$clang->gT("Help:", "js")."](".$eqrow['language'].")",$surveyid,$gid,$qid,$action) . "\t
      \n" . "\t
       \n" . " \n" . "\t
      \n"; $editquestion .= ' 
      '; if (!$adding) { $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 .= '
      '; $aqrow = array_map('htmlspecialchars', $aqrow); $editquestion .= "\t
      ".$clang->gT("Question:")."\n" . "\n" . getEditor("question-text","question_".$aqrow['language'], "[".$clang->gT("Question:", "js")."](".$aqrow['language'].")",$surveyid,$gid,$qid,$action) . "\t
      \n" . "\t
      ".$clang->gT("Help:")."\n" . "\n" . getEditor("question-help","help_".$aqrow['language'], "[".$clang->gT("Help:", "js")."](".$aqrow['language'].")",$surveyid,$gid,$qid,$action) . "\t
      \n"; $editquestion .= '
      '; } } else { $addlanguages=GetAdditionalLanguagesFromSurveyID($surveyid); foreach ($addlanguages as $addlanguage) { $editquestion .= '
      '; $editquestion .= ''; $editquestion .= "\t
      ".$clang->gT("Question:")."\n" . "\n" . getEditor("question-text","question_".$addlanguage, "[".$clang->gT("Question:", "js")."](".$addlanguage.")",$surveyid,$gid,$qid,$action) . "\t
      \n" . "\t
      ".$clang->gT("Help:")."\n" . "\n" . getEditor("question-help","help_".$addlanguage, "[".$clang->gT("Help:", "js")."](".$addlanguage.")",$surveyid,$gid,$qid,$action) . "\t
      \n" . "\t
       \n" . " \n" . "\t
      \n"; $editquestion .= '
      '; } } //question type: $editquestion .= "\t
        \n" . "
      • \n"; if ($activated != "Y") { $editquestion .= "\n"; } else { $qtypelist=getqtypelist('','array'); $editquestion .= "{$qtypelist[$eqrow['type']]['description']} - ".$clang->gT("Cannot be changed (survey is active)")."\n" . "\n"; } $editquestion .="\t
      • \n"; if (!$adding) {$qattributes=questionAttributes();} else { $qattributes=array(); } if ($activated != "Y") { $editquestion .= "\t
      • \n" . "\t\n" . "
      • \n"; } else { $editquestion .= "\t
      • \n" . "\t\n" . getgroupname($eqrow['gid'])." - ".$clang->gT("Cannot be changed (survey is active)")."\n" . "\t" . "
      • \n"; } $editquestion .= "\t
      • \n" . "\n"; if ($activated != "Y") { $editquestion .= "".$clang->gT("No")."gT("Cannot be changed (survey is active)")."\n" . "\t\n"; } $editquestion .= "\t
      • \n"; $editquestion .= "\t
      • \n" . "\n" . "\t".$clang->gT("No")."\n"; $editquestion .= "\t
      • \n" . "\n" . "\n" . "\t
      • "; if ($adding) { //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."' and parent_qid=0 order by question_order" ; $oqresult = db_execute_assoc($oqquery); if ($oqresult->RecordCount()) { // select questionposition $editquestion .= "\t
      • \n" . "\n" . "\t\n" . "
      • \n"; } else { $editquestion .= ""; } } $editquestion .="
      \n"; $editquestion .= '

      '.$clang->gT("Show advanced settings").'

      ' .'' ."

      "; if ($adding) { $editquestion .="\t\n"; } else { $editquestion .= "\t\n" . "\t"; } $editquestion .= "\t

      \n" . "
      \n"; if ($adding) { // Import dialogue if (bHasSurveyPermission($surveyid,'surveycontent','import')) { $editquestion .= "
      ".$clang->gT("...or import a question")."
      \n" . "\t
      \n" . "
        \n" . "\t
      • \n" . "\t\n" . "\t\n" . "\t
      • \n" . "\t
      • \n" . "\t\n" . "\t\n" . "\t
      • \n" . "
      \n" . "

      \n" . "\n" . "\n" . "\n" . "\n" ."

      \n\n"; } $editquestion .= "\n"; } $editquestion .= questionjavascript($eqrow['type']); } //Constructing the interface here... if($action == "orderquestions") { if (isset($_POST['questionordermethod'])) { switch($_POST['questionordermethod']) { // Pressing the Up button case 'up': $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 'down': $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=(int)$_POST['questionmoveto']; $oldpos=(int)$_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 > $oldpos 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."' and parent_qid=0 order by question_order" ; $oqresult = db_execute_assoc($oqquery); $orderquestions = "
      ".$clang->gT("Change Question Order")."
      "; $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=\"disabledUpDnBtn\""; } //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=\"disabledUpDnBtn\""; } //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'].": ".FlattenText($oqarray[$i]['question']); $orderquestions.= "
      • \n" ; } $orderquestions.="
      \n" . "\n" . "\n" . "\n" . "\t" . "\t" . "
      " ; $orderquestions .="
      " ; } function questionjavascript($type) { $newquestionoutput = "\n"; return $newquestionoutput; } if ($action == "ajaxlabelsetdetails") { $lid=returnglobal('lid'); $query='select * from '.db_table_name('labelsets').' where lid='.$lid; $labelsetdata=$connect->GetArray($query); $labelsetlanguages=explode(' ',$labelsetdata[0]['languages']); foreach ($labelsetlanguages as $language){ $query='select * from '.db_table_name('labels').' where lid='.$lid." and language='{$language}' order by sortorder"; $labels=$connect->GetArray($query); $resultdata[]=array($language=>array($labels,getLanguageNameFromCode($language,false))); } echo json_encode($resultdata); } if ($action == "ajaxlabelsetpicker") { $match=(int)returnglobal('match'); $surveyid=returnglobal('sid'); if ($match==1) { $language=GetBaseLanguageFromSurveyID($surveyid); } else { $language=null; } $resultdata=getlabelsets($language); echo json_encode($resultdata); } if ($action == "ajaxquestionattributes") { $thissurvey=getSurveyInfo($surveyid); $type=returnglobal('question_type'); if (isset($qid)) { $attributesettings=getQuestionAttributes($qid); } $availableattributes=questionAttributes(); if (isset($availableattributes[$type])) { uasort($availableattributes[$type],'CategorySort'); $ajaxoutput = ''; $currentfieldset=''; foreach ($availableattributes[$type] as $qa) { if (isset($attributesettings[$qa['name']])) { $value=$attributesettings[$qa['name']]; } else { $value=$qa['default']; } if ($currentfieldset!=$qa['category']) { if ($currentfieldset!='') { $ajaxoutput.='
    '; } $ajaxoutput.="
    \n"; $ajaxoutput.="{$qa['category']}\n
      "; $currentfieldset=$qa['category']; } $ajaxoutput .= "
    • " .""; if (isset($qa['readonly']) && $qa['readonly']==true && $thissurvey['active']=='Y') { $ajaxoutput .= "$value"; } else { switch ($qa['inputtype']){ case 'singleselect': $ajaxoutput .="