\n" ."\t" .$clang->gT("Condition Designer")."\n" ."\n"; if (!isset($surveyid)) { $conditionsoutput .= "
" .$clang->gT("You have not selected a Survey.")." ".$clang->gT("You cannot run this script directly.") ."
\n" ."\n"; return; } if (!isset($_GET['qid']) && !isset($_POST['qid'])) { $conditionsoutput .= "
" .$clang->gT("You have not selected a Question.")." ".$clang->gT("You cannot run this script directly.") ."
\n" ."\n"; return; } $markcidarray=Array(); if (isset($_GET['markcid'])) { $markcidarray=explode("-",$_GET['markcid']); } //ADD NEW ENTRY IF THIS IS AN ADD if (isset($_POST['subaction']) && $_POST['subaction'] == "insertcondition") { if ((!isset($_POST['canswers']) && !isset($_POST['ValOrRegEx'])) || !isset($_POST['cquestions'])) { $conditionsoutput .= "\n"; } else { if (isset($_POST['canswers'])) { foreach ($_POST['canswers'] as $ca) { // There I must add the indicated field for condition method // Original // $query = "INSERT INTO {$dbprefix}conditions (qid, cqid, cfieldname, value) VALUES " // . "('{$_POST['qid']}', '{$_POST['cqid']}', '{$_POST['cquestions']}', '$ca')"; // Modified $query = "INSERT INTO {$dbprefix}conditions (qid, cqid, cfieldname, method, value) VALUES " . "('{$_POST['qid']}', '{$_POST['cqid']}', '{$_POST['cquestions']}', '{$_POST['method']}', '$ca')"; $result = $connect->Execute($query) or safe_die ("Couldn't insert new condition
$query
".$connect->ErrorMsg()); } } if (isset($_POST['ValOrRegEx']) && $_POST['ValOrRegEx']) //Remmember: '', ' ', 0 are evaluated as FALSE { //here is saved the textarea for constants or regex $query = "INSERT INTO {$dbprefix}conditions (qid, cqid, cfieldname, method, value) VALUES " . "('{$_POST['qid']}', '{$_POST['cqid']}', '{$_POST['cquestions']}', '{$_POST['method']}', '{$_POST['ValOrRegEx']}')"; $result = $connect->Execute($query) or safe_die ("Couldn't insert new condition
$query
".$connect->ErrorMsg()); } } } //DELETE ENTRY IF THIS IS DELETE if (isset($_POST['subaction']) && $_POST['subaction'] == "delete") { $query = "DELETE FROM {$dbprefix}conditions WHERE cid={$_POST['cid']}"; $result = $connect->Execute($query) or safe_die ("Couldn't delete condition
$query
".$connect->ErrorMsg()); } //COPY CONDITIONS IF THIS IS COPY if (isset($_POST['subaction']) && $_POST['subaction'] == "copyconditions") { $qid=returnglobal('qid'); $copyconditionsfrom=returnglobal('copyconditionsfrom'); $copyconditionsto=returnglobal('copyconditionsto'); if (isset($copyconditionsto) && is_array($copyconditionsto) && isset($copyconditionsfrom) && is_array($copyconditionsfrom)) { //Get the conditions we are going to copy $query = "SELECT * FROM {$dbprefix}conditions\n" ."WHERE cid in ('"; $query .= implode("', '", $copyconditionsfrom); $query .= "')"; $result = db_execute_assoc($query) or safe_die("Couldn't get conditions for copy
$query
".$connect->ErrorMsg()); while($row=$result->FetchRow()) { $proformaconditions[]=array("cqid"=>$row['cqid'], "cfieldname"=>$row['cfieldname'], "method"=>$row['method'], "value"=>$row['value']); } // while foreach ($copyconditionsto as $copyc) { list($newsid, $newgid, $newqid)=explode("X", $copyc); foreach ($proformaconditions as $pfc) { //First lets make sure there isn't already an exact replica of this condition $query = "SELECT * FROM {$dbprefix}conditions\n" ."WHERE qid='$newqid'\n" ."AND cqid='".$pfc['cqid']."'\n" ."AND cfieldname='".$pfc['cfieldname']."'\n" ."AND method='".$pfc['method']."'\n" ."AND value='".$pfc['value']."'"; $result = $connect->Execute($query) or safe_die("Couldn't check for existing condition
$query
".$connect->ErrorMsg()); $count = $result->RecordCount(); if ($count == 0) //If there is no match, add the condition. { $query = "INSERT INTO {$dbprefix}conditions ( qid,cqid,cfieldname,method,value) \n" ."VALUES ( '$newqid', '".$pfc['cqid']."'," ."'".$pfc['cfieldname']."', '".$pfc['method']."'," ."'".$pfc['value']."')"; $result=$connect->Execute($query) or safe_die ("Couldn't insert query
$query
".$connect->ErrorMsg()); } } } } else { $message = $clang->gT("Did not copy questions","js").": "; if (!isset($copyconditionsfrom)) { $message .= $clang->gT("No condition selected to copy from","js").". "; } if (!isset($copyconditionsto)) { $message .= $clang->gT("No question selected to copy condition to","js")."."; } $conditionsoutput .= "\n"; } } unset($cquestions); unset($canswers); // ******************************************************************* // ** ADD FORM // ******************************************************************* //1: Get information for this question if (!isset($qid)) {$qid=returnglobal('qid');} if (!isset($surveyid)) {$surveyid=returnglobal('sid');} $query = "SELECT * " ."FROM {$dbprefix}questions, " ."{$dbprefix}groups " ."WHERE {$dbprefix}questions.gid={$dbprefix}groups.gid " ."AND qid=$qid " ."AND {$dbprefix}questions.language='".GetBaseLanguageFromSurveyID($surveyid)."'" ; $result = db_execute_assoc($query) or safe_die ("Couldn't get information for question $qid
$query
".$connect->ErrorMsg()); while ($rows=$result->FetchRow()) { $questiongroupname=$rows['group_name']; $questiontitle=$rows['title']; $questiontext=$rows['question']; $questiontype=$rows['type']; } //2: Get all other questions that occur before this question that are pre-determined answer types //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 $qquery = "SELECT * " ."FROM {$dbprefix}questions, " ."{$dbprefix}groups " ."WHERE {$dbprefix}questions.gid={$dbprefix}groups.gid " ."AND {$dbprefix}questions.sid=$surveyid " ."AND {$dbprefix}questions.language='".GetBaseLanguageFromSurveyID($surveyid)."' " ."AND {$dbprefix}groups.language='".GetBaseLanguageFromSurveyID($surveyid)."' " ; $qresult = db_execute_assoc($qquery) or safe_die ("$qquery
".$connect->ErrorMsg()); $qrows = $qresult->GetRows(); // Perform a case insensitive natural sort on group name then question title (known as "code" in the form) of a multidimensional array usort($qrows, 'CompareGroupThenTitle'); $position="before"; //Go through each question until we reach the current one foreach ($qrows as $qrow) { if ($qrow["qid"] != $qid && $position=="before") { if ($qrow['type'] != "UNSUPPORTEDTYPE") { // There is currently no unsupported question // type for use in conditions // So remember the questions of this type $questionlist[]=$qrow["qid"]; } } elseif ($qrow["qid"] == $qid) { break; } } //Now, using the same array which is now properly sorted by group then question //Create an array of all the questions that appear AFTER the current one $position = "before"; foreach ($qrows as $qrow) //Go through each question until we reach the current one { if ($qrow["qid"] == $qid) { $position="after"; //break; } elseif ($qrow["qid"] != $qid && $position=="after") { $postquestionlist[]=$qrow['qid']; } } $theserows=array(); if (isset($questionlist) && is_array($questionlist)) { foreach ($questionlist as $ql) { $query = "SELECT {$dbprefix}questions.qid, " ."{$dbprefix}questions.sid, " ."{$dbprefix}questions.gid, " ."{$dbprefix}questions.question, " ."{$dbprefix}questions.type, " ."{$dbprefix}questions.lid, " ."{$dbprefix}questions.lid1, " ."{$dbprefix}questions.title, " ."{$dbprefix}questions.other, " ."{$dbprefix}questions.mandatory " ."FROM {$dbprefix}questions, " ."{$dbprefix}groups " ."WHERE {$dbprefix}questions.gid={$dbprefix}groups.gid " ."AND {$dbprefix}questions.qid=$ql " ."AND {$dbprefix}questions.language='".GetBaseLanguageFromSurveyID($surveyid)."' " ."AND {$dbprefix}groups.language='".GetBaseLanguageFromSurveyID($surveyid)."'" ; $result=db_execute_assoc($query) or die("Couldn't get question $qid"); $thiscount=$result->RecordCount(); // And store again these questions in this array... while ($myrows=$result->FetchRow()) { //key => value $theserows[]=array("qid"=>$myrows['qid'], "sid"=>$myrows['sid'], "gid"=>$myrows['gid'], "question"=>$myrows['question'], "type"=>$myrows['type'], "lid"=>$myrows['lid'], "lid1"=>$myrows['lid1'], "mandatory"=>$myrows['mandatory'], "other"=>$myrows['other'], "title"=>$myrows['title']); } } } if (isset($postquestionlist) && is_array($postquestionlist)) { foreach ($postquestionlist as $pq) { $query = "SELECT {$dbprefix}questions.qid, " ."{$dbprefix}questions.sid, " ."{$dbprefix}questions.gid, " ."{$dbprefix}questions.question, " ."{$dbprefix}questions.type, " ."{$dbprefix}questions.lid, " ."{$dbprefix}questions.lid1, " ."{$dbprefix}questions.title, " ."{$dbprefix}questions.other, " ."{$dbprefix}questions.mandatory " ."FROM {$dbprefix}questions, " ."{$dbprefix}groups " ."WHERE {$dbprefix}questions.gid={$dbprefix}groups.gid AND " ."{$dbprefix}questions.qid=$pq AND " ."{$dbprefix}questions.language='".GetBaseLanguageFromSurveyID($surveyid)."'" ; $result = db_execute_assoc($query) or safe_die("Couldn't get postquestions $qid
$query
".$connect->ErrorMsg()); $postcount=$result->RecordCount(); while($myrows=$result->FetchRow()) { $postrows[]=array("qid"=>$myrows['qid'], "sid"=>$myrows['sid'], "gid"=>$myrows['gid'], "question"=>$myrows['question'], "type"=>$myrows['type'], "lid"=>$myrows['lid'], "lid1"=>$myrows['lid1'], "mandatory"=>$myrows['mandatory'], "other"=>$myrows['other'], "title"=>$myrows['title']); } // while } $postquestionscount=count($postrows); } $questionscount=count($theserows); if (isset($postquestionscount) && $postquestionscount > 0) //Build the select box for questions after this one { foreach ($postrows as $pr) { $pquestions[]=array("text"=>$pr['title'].": ".substr($pr['question'], 0, 30), "fieldname"=>$pr['sid']."X".$pr['gid']."X".$pr['qid']); } } if ($questionscount > 0) { $X="X"; // Will detect if the questions are type D to use latter $dquestions=array(); foreach($theserows as $rows) { $shortquestion=$rows['title'].": ".strip_tags($rows['question']); if ($rows['type'] == "A" || $rows['type'] == "B" || $rows['type'] == "C" || $rows['type'] == "E" || $rows['type'] == "F" || $rows['type'] == "H") { $aquery="SELECT * " ."FROM {$dbprefix}answers " ."WHERE qid={$rows['qid']} " ."AND {$dbprefix}answers.language='".GetBaseLanguageFromSurveyID($surveyid)."' " ."ORDER BY sortorder, " ."answer"; $aresult=db_execute_assoc($aquery) or safe_die ("Couldn't get answers to Array questions
$aquery
".$connect->ErrorMsg()); while ($arows = $aresult->FetchRow()) { $shortanswer = strip_tags($arows['answer']); $shortanswer .= " [{$arows['code']}]"; $cquestions[]=array("$shortquestion [$shortanswer]", $rows['qid'], $rows['type'], $rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['code']); switch ($rows['type']) { case "A": //Array 5 buttons for ($i=1; $i<=5; $i++) { $canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['code'], $i, $i); } break; case "B": //Array 10 buttons for ($i=1; $i<=10; $i++) { $canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['code'], $i, $i); } break; case "C": //Array Y/N/NA $canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['code'], "Y", $clang->gT("Yes")); $canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['code'], "U", $clang->gT("Uncertain")); $canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['code'], "N", $clang->gT("No")); break; case "E": //Array >/=/< $canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['code'], "I", $clang->gT("Increase")); $canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['code'], "S", $clang->gT("Same")); $canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['code'], "D", $clang->gT("Decrease")); break; case "F": //Array Flexible Row case "H": //Array Flexible Column $fquery = "SELECT * " ."FROM {$dbprefix}labels " ."WHERE lid={$rows['lid']} " ."AND language='".GetBaseLanguageFromSurveyID($surveyid)."' " ."ORDER BY sortorder, code "; $fresult = db_execute_assoc($fquery); while ($frow=$fresult->FetchRow()) { $canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['code'], $frow['code'], $frow['title']); } break; } // Only Show No-Answer if question is not mandatory if ($rows['mandatory'] != 'Y') { $canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['code'], "", $clang->gT("No answer")); } } //while } //if A,B,C,E,F,H elseif ($rows['type'] == "1") //Multi Scale { $aquery="SELECT * " ."FROM {$dbprefix}answers " ."WHERE qid={$rows['qid']} " ."AND {$dbprefix}answers.language='".GetBaseLanguageFromSurveyID($surveyid)."' " ."ORDER BY sortorder, " ."answer"; $aresult=db_execute_assoc($aquery) or safe_die ("Couldn't get answers to Array questions
$aquery
".$connect->ErrorMsg()); while ($arows = $aresult->FetchRow()) { $shortanswer = strip_tags($arows['answer']); $shortanswer .= "[[Label 1]{$arows['code']}]"; $cquestions[]=array("$shortquestion [$shortanswer]", $rows['qid'], $rows['type'], $rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['code']."#0"); $shortanswer = strip_tags($arows['answer']); $shortanswer .= "[[Label 2]{$arows['code']}]"; $cquestions[]=array("$shortquestion [$shortanswer]", $rows['qid'], $rows['type'], $rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['code']."#1"); // first label $lquery="SELECT * " ."FROM {$dbprefix}labels " ."WHERE lid={$rows['lid']} " ."AND {$dbprefix}labels.language='".GetBaseLanguageFromSurveyID($surveyid)."' " ."ORDER BY sortorder, " ."lid"; $lresult=db_execute_assoc($lquery) or safe_die ("Couldn't get labels to Array
$lquery
".$connect->ErrorMsg()); while ($lrows = $lresult->FetchRow()) { $canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['code']."#0", "{$lrows['code']}", "{$lrows['code']}"); } // second label $lquery="SELECT * " ."FROM {$dbprefix}labels " ."WHERE lid={$rows['lid1']} " ."AND {$dbprefix}labels.language='".GetBaseLanguageFromSurveyID($surveyid)."' " ."ORDER BY sortorder, " ."lid"; $lresult=db_execute_assoc($lquery) or safe_die ("Couldn't get labels to Array
$lquery
".$connect->ErrorMsg()); while ($lrows = $lresult->FetchRow()) { $canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['code']."#1", "{$lrows['code']}", "{$lrows['code']}"); } // Only Show No-Answer if question is not mandatory if ($rows['mandatory'] != 'Y') { $canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['code']."#0", "", $clang->gT("No answer")); $canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['code']."#1", "", $clang->gT("No answer")); } } //while } elseif ($rows['type'] == "K" ||$rows['type'] == "Q") //Multi shorttext/numerical { $aquery="SELECT * " ."FROM {$dbprefix}answers " ."WHERE qid={$rows['qid']} " ."AND {$dbprefix}answers.language='".GetBaseLanguageFromSurveyID($surveyid)."' " ."ORDER BY sortorder, " ."answer"; $aresult=db_execute_assoc($aquery) or safe_die ("Couldn't get answers to Array questions
$aquery
".$connect->ErrorMsg()); while ($arows = $aresult->FetchRow()) { $shortanswer = strip_tags($arows['answer']); $shortanswer .= "[{$arows['code']}]"; $cquestions[]=array("$shortquestion [$shortanswer]", $rows['qid'], $rows['type'], $rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['code']); // Only Show No-Answer if question is not mandatory if ($rows['mandatory'] != 'Y') { $canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['code'], "", $clang->gT("No answer")); } } //while } elseif ($rows['type'] == "R") //Answer Ranking { $aquery="SELECT * " ."FROM {$dbprefix}answers " ."WHERE qid={$rows['qid']} " ."AND ".db_table_name('answers').".language='".GetBaseLanguageFromSurveyID($surveyid)."' " ."ORDER BY sortorder, answer"; $aresult=db_execute_assoc($aquery) or safe_die ("Couldn't get answers to Ranking question
$aquery
".$connect->ErrorMsg()); $acount=$aresult->RecordCount(); while ($arow=$aresult->FetchRow()) { $theanswer = addcslashes($arow['answer'], "'"); $quicky[]=array($arow['code'], $theanswer); } for ($i=1; $i<=$acount; $i++) { $cquestions[]=array("$shortquestion [RANK $i]", $rows['qid'], $rows['type'], $rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$i); foreach ($quicky as $qck) { $canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$i, $qck[0], $qck[1]); } // Only Show No-Answer if question is not mandatory if ($rows['mandatory'] != 'Y') { $canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$i, " ", $clang->gT("No answer")); } } unset($quicky); } // End if type R else { $cquestions[]=array($shortquestion, $rows['qid'], $rows['type'], $rows['sid'].$X.$rows['gid'].$X.$rows['qid']); switch ($rows['type']) { case "Y": // Y/N/NA $canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'], "Y", $clang->gT("Yes")); $canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'], "N", $clang->gT("No")); // Only Show No-Answer if question is not mandatory if ($rows['mandatory'] != 'Y') { $canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'], " ", $clang->gT("No answer")); } break; case "G": //Gender $canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'], "F", $clang->gT("Female")); $canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'], "M", $clang->gT("Male")); // Only Show No-Answer if question is not mandatory if ($rows['mandatory'] != 'Y') { $canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'], " ", $clang->gT("No answer")); } break; case "5": // 5 choice for ($i=1; $i<=5; $i++) { $canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'], $i, $i); } // Only Show No-Answer if question is not mandatory if ($rows['mandatory'] != 'Y') { $canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'], " ", $clang->gT("No answer")); } break; case "W": // List Flexibel Label Dropdown case "Z": // List Flexible Radio Button $fquery = "SELECT * FROM {$dbprefix}labels\n" . "WHERE lid={$rows['lid']} AND language='".GetBaseLanguageFromSurveyID($surveyid)."' " . "ORDER BY sortorder, code"; $fresult = db_execute_assoc($fquery); if (!isset($arows['code'])) {$arows['code']='';} // for some questions types there is no code while ($frow=$fresult->FetchRow()) { $canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['code'], $frow['code'], $frow['title']); } // Only Show No-Answer if question is not mandatory if ($rows['mandatory'] != 'Y') { $canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'], " ", $clang->gT("No answer")); } break; default: $aquery="SELECT * " ."FROM {$dbprefix}answers " ."WHERE qid={$rows['qid']} " ."AND language='".GetBaseLanguageFromSurveyID($surveyid)."' " ."ORDER BY sortorder, " ."answer"; // Ranking question? Replacing "Ranking" by "this" $aresult=db_execute_assoc($aquery) or safe_die ("Couldn't get answers to this question
$aquery
".$connect->ErrorMsg()); while ($arows=$aresult->FetchRow()) { $theanswer = addcslashes($arows['answer'], "'"); $canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'], $arows['code'], $theanswer); } if ($rows['type'] == "D") { // Only Show No-Answer if question is not mandatory if ($rows['mandatory'] != 'Y') { $canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'], " ", $clang->gT("No answer")); } // Now, save the questions type D only, then // it donīt need pass by all the array elements... $dquestions[]=$rows; // offer previous date questions to compare foreach ($dquestions as $dq) { if ($rows['qid'] != $dq['qid'] && $dq['type'] == "D") { // Canīt compare with the same question, and only if are D // The question tittle is enclossed by @ to be identified latter // and be processed accordingly $canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'], "@".$dq['title']."@", $dq['title'].": ".$dq['question']); } } } elseif ($rows['type'] != "M" && $rows['type'] != "P" && $rows['type'] != "J" && $rows['type'] != "I" ) { // For dropdown questions // optinnaly add the 'Other' answer if ( ($rows['type'] == "L" || $rows['type'] == "!") && $rows['other'] == "Y") { $canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'], "-oth-", $clang->gT("Other")); } // Only Show No-Answer if question is not mandatory if ($rows['mandatory'] != 'Y') { $canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'], " ", $clang->gT("No answer")); } } break; // types X,D,!,0,Q,N,S,T,U,^ just have an option as "No Answer" originally // but now if type is D could have a list of questions D after it. }//switch row type } //else } //foreach theserows } //if questionscount > 0 // Now Iīll add a hack to add the questions before as option // if they are date type //JAVASCRIPT TO SHOW MATCHING ANSWERS TO SELECTED QUESTION $conditionsoutput .= "\n"; //SHOW FORM TO CREATE IT! $conditionsoutput .= "\n" ."\t\n" ."\t\t\n" ."\t\n"; //3: Get other conditions currently set for this question $query = "SELECT {$dbprefix}conditions.cid, " ."{$dbprefix}conditions.cqid, " ."{$dbprefix}conditions.cfieldname, " ."{$dbprefix}conditions.method, " ."{$dbprefix}conditions.value, " ."{$dbprefix}questions.type " ."FROM {$dbprefix}conditions, " ."{$dbprefix}questions " ."WHERE {$dbprefix}conditions.cqid={$dbprefix}questions.qid " ."AND {$dbprefix}questions.language='".GetBaseLanguageFromSurveyID($surveyid)."' " ."AND {$dbprefix}conditions.qid=$qid\n" ."ORDER BY {$dbprefix}conditions.cfieldname"; $result = db_execute_assoc($query) or safe_die ("Couldn't get other conditions for question $qid
$query
".$connect->ErrorMsg()); $conditionscount=$result->RecordCount(); // this array will be used soon, // to explain wich conditions is used to evaluate the question $method = array( "<" => $clang->gT("Less than"), "<=" => $clang->gT("Less than or Equal to"), "==" => $clang->gT("Equals"), "!=" => $clang->gT("Not Equal to"), ">=" => $clang->gT("Greater than or Equal to"), ">" => $clang->gT("Greater than"), "RX" => $clang->gT("Regular Expression") ); if ($conditionscount > 0) { while ($rows=$result->FetchRow()) { if($rows['method'] == "") {$rows['method'] = "==";} //Fill in the empty method from previous versions if (is_null(array_search($rows['cid'], $markcidarray)) || // PHP4 array_search($rows['cid'], $markcidarray) === FALSE) // PHP5 // === required cause key 0 would otherwise be interpreted as FALSE { $markcidstyle=""; } else { $markcidstyle="background-color: #5670A1;"; } if (isset($currentfield) && $currentfield != $rows['cfieldname']) { $conditionsoutput .= "\t\t\t\t\n" ."\t\t\t\t\t\n" ."\t\t\t\t\t\n" ."\t\n"; $currentfield=$rows['cfieldname']; } $conditionsoutput .= "\t\n" ."\t\t\n" ."\t\n"; } else { $conditionsoutput .= "\t\n" ."\t\t\n" ."\t\n"; } $conditionsoutput .= "\t\n"; if ($conditionscount > 0 && isset($postquestionscount) && $postquestionscount > 0) { $conditionsoutput .= "\n" ."\t\n"; } $conditionsoutput .= "
\n"; $showreplace="$questiontitle". showSpeaker($questiontext); $onlyshow=str_replace("{QID}", $showreplace, $clang->gT("Only show question {QID} IF")); $conditionsoutput .= "\t\t\t$onlyshow\n" ."\t\t
\n" ."" .$clang->gT("and").""; } elseif (isset($currentfield)) { $conditionsoutput .= "\t\t\t\t
\n" ."" .$clang->gT("OR").""; } $conditionsoutput .= "\t
\n" ."\t\t\n" ."\t\t\t\n" ."\t\t\t\t\n" ."\t\t\t\t\t" .$method[$rows['method']] ."\t\t\t\t\t\t\n" ."\t\t\t\t\t\n" ."\n" ."\t\t\t\t\t\n" ."\t\t\t\t\t\n" ."\t
\n" ."\t\t\t\t\t\n"; //BUILD FIELDNAME? foreach ($cquestions as $cqn) { if ($cqn[3] == $rows['cfieldname']) { $conditionsoutput .= "\t\t\t$cqn[0] (qid{$rows['cqid']})\n"; $conditionsList[]=array("cid"=>$rows['cid'], "text"=>$cqn[0]." ({$rows['value']})"); } else { //$conditionsoutput .= "\t\t\tERROR: Delete this condition. It is out of order.\n"; } } $conditionsoutput .= "\t\t\t\t\t\n" ."\t\t\t\t\t\t\n" // .$clang->gT("Equals")."\n" ."\t\t\t\t\t\t\n"; // Here will be searched the conditional answer for this question // this conditional part is the labeled one // But there is another kind of condition // the specified in ValOrRegEx and is in $rows['value'] $bHasAnswer = false; foreach ($canswers as $can) { //$conditionsoutput .= $rows['cfieldname'] . "- $can[0]
"; //$conditionsoutput .= $can[1]; if ($can[0] == $rows['cfieldname'] && $can[1] == $rows['value']) { $conditionsoutput .= "\t\t\t\t\t\t$can[2] ($can[1])\n"; $bHasAnswer = true; } } if (!$bHasAnswer) { if ($rows['value'] == ' ' || $rows['value'] == '') { $conditionsoutput .= "\t\t\t\t\t\t".$clang->gT("No Answer")."\n"; } else { $conditionsoutput .= "\t\t\t\t\t\t".$rows['value']."\n"; } } $conditionsoutput .= "\t\t\t\t\t
\n" ."\t\t\t\t\t\t\n" ."\t\t\t\t\t\n" ."\t\t\t\t\t\n" ."\t\t\t\t\t\n" ."\t\t\t\t\t\n" ."\t\t\t\t\t
\n" ."\t
\n" ."\t\t
\n" ."\t\t
\n"; $conditionsoutput .= "\t\n" ."\t\t\n" ."\t\n"; $conditionsoutput .= "\t\n" ."\t\t\n" ."\t\n"; $conditionsoutput .= "\t\n" ."\t\t\n" ."\t\t\n" ."\t\t\n" ."\t\n"; $conditionsoutput .= "\t
\n" ."\t\t" .$clang->gT("Copy Conditions")."\n" ."\t\t
".$clang->gT("Condition")."".$clang->gT("Question")."
\n" ."\t\t\n" ."\t\t\n" ."\t\t".$clang->gT("copy to")."\n" ."\t\t\n" ."\t\t\n"; $conditionsoutput .= "\t\t
\n" ."gT("Are you sure you want to copy these condition(s) to the questions you have selected?","js")."')\" />" ."\t\t\n"; $conditionsoutput .= "\n" ."\n" ."\n" ."
\n"; $conditionsoutput .= "\t
\n"; $qcount=isset($cquestions) ? count($cquestions) : 0; $conditionsoutput .= "
\n"; $conditionsoutput .= "\n"; $conditionsoutput .= "\t\n" ."\t\t\n" ."\t\n" ."\t\n" ."\t\t\n" ."\t\t\n" ."\t\t\n" ."\t\n" ."\t\n" ."\t\t\n" ."\t\t" ."\t\n" ."\t\n" ."\t\t\n" ."\t\n" ."
\n" ."\t\t\t".$clang->gT("Add Condition")."\n" ."\t\t
\n" ."\t\t\t".$clang->gT("Question")."\n" ."\t\t\n" ."\t\t\n" ."\t\t\t".$clang->gT("Answer")."\n" ."\t\t
\n" ."\t\t\t\n"; // Originally was planned to do that: //$conditionsoutput .= "\t\t\t\n"; // ---------------------------------------- // Perhaps was leaved for this time with //$conditionsoutput .= "\t\t\t".$clang->gT("Equals")."\n" // Here I go $conditionsoutput .= "\t\t\t
\n"; $conditionsoutput .= "\t\t\t
".$clang->gT("NOTE: If you use a pre-defined answer as your condition, only the equals or not-equal-to conditions apply.")."
\n"; $conditionsoutput .= "\t\t
\n" ."\t\t\t
\n\t\t\t\n"; // Some one request to hidde this if it is not necesary // It will be showed when answers array is empty // on HTMLīs JS code. I fixed that enclosing it in a div called // CONST_RGX and it will be showed or not. $conditionsoutput .= "" ."\t\t
\n" ."\t\t\t\n" ."\t\t\t\n" ."\n" ."\n" ."\n" ."\n" ."\t\t
\n" ."
\n" ."\n"; $conditionsoutput .= "\t\n" ."\t\n" ."\t\t\n"; $conditionsoutput .= "\t\n" ."\t\t\n" ."\t\n"; $conditionsoutput .= "\t\n" ."
\n" ."\t\t
\n" ."\t\t\t\n" ."\t\t

 \n"; function showSpeaker($hinttext) { global $imagefiles, $clang; $reshtml= "\"".strip_tags($hinttext)."\"gT("Question","js").": ".javascript_escape($hinttext,true,true)."')\" />"; return $reshtml; } ?>