question id * $ia[1] => fieldname * $ia[2] => title * $ia[3] => question text * $ia[4] => type -- text, radio, select, array, etc * $ia[5] => group id * $ia[6] => mandatory Y || N * $ia[7] => conditions ?? * * $conditions element structure * $condition[n][0] => qid = question id * $condition[n][1] => cqid = question id of the target question, or 0 for TokenAttr leftOperand * $condition[n][2] => field name of element [1] (Except for type M or P) * $condition[n][3] => value to be evaluated on answers labeled. * $condition[n][4] => type of question * $condition[n][5] => SGQ code of element [1] (sub-part of [2]) * $condition[n][6] => method used to evaluate * $condition[n][7] => scenario *NEW BY R.L.J. van den Burg* */ function retrieveConditionInfo($ia) { //This function returns an array containing all related conditions //for a question - the array contains the fields from the conditions table global $dbprefix, $connect; if ($ia[7] == "Y") { //DEVELOP CONDITIONS ARRAY FOR THIS QUESTION $cquery = "SELECT {$dbprefix}conditions.qid, " ."{$dbprefix}conditions.scenario, " ."{$dbprefix}conditions.cqid, " ."{$dbprefix}conditions.cfieldname, " ."{$dbprefix}conditions.value, " ."{$dbprefix}questions.type, " ."{$dbprefix}questions.sid, " ."{$dbprefix}questions.gid, " ."{$dbprefix}conditions.method, " ."questionssrc.gid as srcgid " ."FROM {$dbprefix}conditions, " ."{$dbprefix}questions ," ."{$dbprefix}questions as questionssrc " ."WHERE {$dbprefix}conditions.cqid={$dbprefix}questions.qid " ."AND {$dbprefix}conditions.qid=questionssrc.qid " ."AND {$dbprefix}conditions.qid=$ia[0] " ."AND {$dbprefix}questions.language='".$_SESSION['s_lang']."' " ."AND {$dbprefix}conditions.cfieldname NOT LIKE '{%' " ."ORDER BY {$dbprefix}conditions.scenario, " ."{$dbprefix}conditions.cqid, " ."{$dbprefix}conditions.cfieldname"; $cresult = db_execute_assoc($cquery) or safe_die ("OOPS
$cquery
".$connect->ErrorMsg()); //Checked $cquerytoken = "SELECT {$dbprefix}conditions.qid, " ."{$dbprefix}conditions.scenario, " ."{$dbprefix}conditions.cqid, " ."{$dbprefix}conditions.cfieldname, " ."{$dbprefix}conditions.value, " ."'' as type, " ."0 as sid, " ."0 as gid, " ."{$dbprefix}conditions.method," ."questionssrc.gid as srcgid " ."FROM {$dbprefix}conditions, {$dbprefix}questions as questionssrc " ."WHERE {$dbprefix}conditions.qid=questionssrc.qid " ."AND {$dbprefix}conditions.qid=$ia[0] " ."AND {$dbprefix}conditions.cfieldname LIKE '{%' " ."ORDER BY {$dbprefix}conditions.scenario, " ."{$dbprefix}conditions.cqid, " ."{$dbprefix}conditions.cfieldname"; $cresulttoken = db_execute_assoc($cquerytoken) or safe_die ("OOPS
$cquerytoken
".$connect->ErrorMsg()); //Checked while ($tempcrow = $cresulttoken->FetchRow()) { $aAllConditions[] = $tempcrow; } while ($tempcrow = $cresult->FetchRow()) { $aAllConditions[] = $tempcrow; } // while ($crow = $cresult->FetchRow()) foreach ($aAllConditions as $crow) { if (preg_match("/^\+(.*)$/",$crow['cfieldname'],$cfieldnamematch)) { // this condition uses a single checkbox as source $crow['type'] = "+".$crow['type']; $crow['cfieldname'] = $cfieldnamematch[1]; } $conditions[] = array ($crow['qid'], $crow['cqid'], $crow['cfieldname'], $crow['value'], $crow['type'], $crow['sid']."X".$crow['gid']."X".$crow['cqid'], $crow['method'], $crow['scenario'], $crow['srcgid']); } return $conditions; } else { return null; } } // returns the Javascript IdName of a question used in conditions // $cd = Array ( // 0 => Unused // 1 => qid of the question // 2 => fieldname of the question // 3 => value used in comparison (only usd for type M and P egals 'Y', optionnal for other types) // 4 => type of the question // 5 => SGQ code corresponding to the fieldname // if $currentgid is not null (Group by group survey), the fieldname depends on the groupId function retrieveJSidname($cd,$currentgid=null) { global $dbprefix, $connect, $dropdownthreshold; preg_match("/^[0-9]+X([0-9]+)X([0-9]+)$/",$cd[5],$matchGID); $questiongid=$matchGID[1]; if ($cd[4] == "L") { $cccquery="SELECT code FROM {$dbprefix}answers WHERE qid={$cd[1]} AND language='".$_SESSION['s_lang']."'"; $cccresult=$connect->Execute($cccquery); // Checked $cccount=$cccresult->RecordCount(); } if ($cd[4] == "R") { if (!isset($currentgid) || $questiongid == $currentgid) { // if question is on same page then field is fvalue_XXXX $idname="fvalue_".$cd[1].substr($cd[2], strlen($cd[2])-1,1); } else { // If question is on another page then field if javaXXXX $idname="java$cd[2]"; } } elseif ($cd[4] == "5" || $cd[4] == "A" || $cd[4] == "B" || $cd[4] == "C" || $cd[4] == "E" || $cd[4] == "F" || $cd[4] == "H" || $cd[4] == "G" || $cd[4] == "Y" || $cd[4] == "1" || ($cd[4] == "L" && $cccount <= $dropdownthreshold)) { $idname="java$cd[2]"; } elseif ($cd[4] == "M" || $cd[4] == "P") { $idname="java$cd[5]$cd[3]"; } elseif ($cd[4] == "+M" || $cd[4] == "+P") { $idname="java$cd[2]"; } elseif ($cd[4] == "D" || $cd[4] == "N" || $cd[4] == "S" || $cd[4] == "T" || $cd[4] == "U" || $cd[4] == "Q" || $cd[4] == "K" ) { if (!isset($currentgid) || $questiongid == $currentgid) { // if question is on same page then field is answerXXXX $idname="answer$cd[2]"; } else { // If question is on another page then field if javaXXXX $idname="java$cd[2]"; } } else { $idname="java".$cd[2]; } return $idname; } function create_mandatorylist($ia) { //Checks current question and returns required mandatory arrays if required if ($ia[6] == 'Y') { switch($ia[4]) { case 'R': $thismandatory = setman_ranking($ia); break; case 'M': $thismandatory = setman_questionandcode($ia); break; case 'J': case 'P': case 'Q': case 'K': case 'A': case 'B': case 'C': case 'E': case 'F': case 'H': $thismandatory = setman_questionandcode($ia); break; case ':': case ';': $thismandatory = setman_multiflex($ia); break; case '1': $thismandatory = setman_questionandcode_multiscale($ia); break; case 'X': //Do nothing - boilerplate questions CANNOT be mandatory break; default: $thismandatory = setman_normal($ia); } if ($ia[7] != 'Y' && isset($thismandatory)) //Question is not conditional - addto mandatory arrays { $mandatory=$thismandatory; } if ($ia[7] == 'Y' && isset($thismandatory)) //Question IS conditional - add to conmandatory arrays { $conmandatory=$thismandatory; } } if (isset($mandatory)) { return array($mandatory, null); } elseif (isset($conmandatory)) { return array(null, $conmandatory); } else { return array(null, null); } } function setman_normal($ia) { $mandatorys[]=$ia[1]; $mandatoryfns[]=$ia[1]; return array($mandatorys, $mandatoryfns); } function setman_ranking($ia) { global $dbprefix, $connect; $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid={$ia[0]} AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, answer"; $ansresult = $connect->Execute($ansquery); //Checked $anscount = $ansresult->RecordCount(); $qidattributes=getQuestionAttributes($ia[0]); if ($ma=arraySearchByKey("max_answers", $qidattributes, "attribute", 1)) { $max_answers = $ma['value']; } else { $max_answers = $anscount; } for ($i=1; $i<=$max_answers; $i++) { $mandatorys[]=$ia[1].$i; $mandatoryfns[]=$ia[1]; } return array($mandatorys, $mandatoryfns); } function setman_questionandcode($ia) { global $dbprefix, $connect; $qquery = "SELECT other FROM {$dbprefix}questions WHERE qid=".$ia[0]." AND language='".$_SESSION['s_lang']."'"; $qresult = db_execute_assoc($qquery); //Checked while ($qrow = $qresult->FetchRow()) {$other = $qrow['other'];} $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid={$ia[0]} AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, answer"; $ansresult = db_execute_assoc($ansquery); //Checked while ($ansrow = $ansresult->FetchRow()) { $mandatorys[]=$ia[1].$ansrow['code']; $mandatoryfns[]=$ia[1]; } if ($other == "Y" and ($ia[4]=="!" or $ia[4]=="L" or $ia[4]=="M" or $ia[4]=="P")) { $mandatorys[]=$ia[1]."other"; $mandatoryfns[]=$ia[1]; } return array($mandatorys, $mandatoryfns); } function setman_multiflex($ia) { //The point of these functions (setman) is to return an array containing two arrays. // The first ($mandatorys) is an array containing question, so they can all be checked // The second ($mandatoryfns) is an arry containing the fieldnames of every question // What's the difference? The difference arises from multiple option questions, and came // about when trying to distinguish between answering just one option (which satisfies // the mandatory requirement, and answering them all). The "mandatorys" input contains the // actual specific response items that could be filled in.. ie: in a multiple option // question, there will be a unique one for every possible answer. The "mandatoryfns" array // contains the generic question fieldname for the question as a whole (it will be repeated // for multiple option qeustions, but won't contain unique items. global $dbprefix, $connect; $qq="SELECT lid FROM {$dbprefix}questions WHERE qid={$ia[0]}"; $qr=db_execute_assoc($qq); while($qd=$qr->FetchRow()) { $lid=$qd['lid']; } $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid={$ia[0]} AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, answer"; $ansresult = db_execute_assoc($ansquery); $ans2query = "SELECT * FROM {$dbprefix}labels WHERE lid={$lid} AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, title"; $ans2result = db_execute_assoc($ans2query); while ($ans2row=$ans2result->FetchRow()) { $lset[]=$ans2row; } $qidattributes=getQuestionAttributes($ia[0]); while ($ansrow = $ansresult->FetchRow()) { //Don't add to mandatory list if the row is filtered out with the array_filter option if ($htmltbody=arraySearchByKey("array_filter", $qidattributes, "attribute", 1)) { //This particular one may not be mandatory if it's hidden $selected = getArrayFiltersForQuestion($ia[0]); if (!in_array($ansrow['code'],$selected)) { //This one's hidden, so don't add it to the mandatory list } else { //This one's not hidden. so add it to the mandatory list foreach($lset as $ls) { $mandatorys[]=$ia[1].$ansrow['code']."_".$ls['code']; $mandatoryfns[]=$ia[1]; } } } else { //There is no array_filter option, so we should definitely add to the mandatory list here! foreach($lset as $ls) { $mandatorys[]=$ia[1].$ansrow['code']."_".$ls['code']; $mandatoryfns[]=$ia[1]; } } } return array($mandatorys, $mandatoryfns); } function setman_questionandcode_multiscale($ia) { global $dbprefix, $connect; $qquery = "SELECT other FROM {$dbprefix}questions WHERE qid=".$ia[0]." AND language='".$_SESSION['s_lang']."'"; $qresult = db_execute_assoc($qquery); //Checked while ($qrow = $qresult->FetchRow()) {$other = $qrow['other'];} $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid={$ia[0]} AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, answer"; $ansresult = db_execute_assoc($ansquery); //Checked $lquery = "SELECT q.qid FROM {$dbprefix}labels l, {$dbprefix}questions q WHERE l.lid = q.lid AND q.qid=".$ia[0]." AND l.language='".$_SESSION['s_lang']."' AND q.language='".$_SESSION['s_lang']."'"; $labelsresult = db_execute_assoc($lquery); //Checked $labelscount = $labelsresult->RowCount(); $lquery1 = "SELECT q.qid FROM {$dbprefix}labels l, {$dbprefix}questions q WHERE l.lid = q.lid1 AND q.qid=".$ia[0]." AND l.language='".$_SESSION['s_lang']."' AND q.language='".$_SESSION['s_lang']."'"; $labelsresult1 = db_execute_assoc($lquery1); //Checked $labelscount1 = $labelsresult1->RowCount(); while ($ansrow = $ansresult->FetchRow()) { if ($labelscount > 0) { $mandatorys[]=$ia[1].$ansrow['code']."#0"; $mandatoryfns[]=$ia[1]; } else { $mandatorys[]=$ia[1].$ansrow['code']; $mandatoryfns[]=$ia[1]; } // second label set if ($labelscount1 > 0) { $mandatorys[]=$ia[1].$ansrow['code']."#1"; $mandatoryfns[]=$ia[1]; } else { $mandatorys[]=$ia[1].$ansrow['code']; $mandatoryfns[]=$ia[1]; } } if ($other == "Y" and ($ia[4]=="!" or $ia[4]=="L" or $ia[4]=="M" or $ia[4]=="P" or $ia[4]=="1")) { $mandatorys[]=$ia[1]."other"; $mandatoryfns[]=$ia[1]; } return array($mandatorys, $mandatoryfns); } function getAge($day, $month, $year) { // define age $age = date('Y') - (int) $year; // month not yet passed if((int) $month > date('m')) $age--; // month == this month elseif(date('m') == (int) $month) { // day has yet to come if((int) $day > date('j')) $age--; } return $age; } function retrieveAnswers($ia, $notanswered=null, $notvalidated=null) { //This function returns an array containing the "question/answer" html display //and a list of the question/answer fieldnames associated. It is called from //question.php, group.php or survey.php //globalise required config variables global $dbprefix, $shownoanswer, $clang; //These are from the config-defaults.php file //----- global $thissurvey, $gl; //These are set by index.php global $connect; //DISPLAY $display = $ia[7]; //QUESTION NAME $name = $ia[0]; $qtitle=$ia[3]; //Replace INSERTANS statements with previously provided answers; while (strpos($qtitle, "{INSERTANS:") !== false) { $replace=substr($qtitle, strpos($qtitle, "{INSERTANS:"), strpos($qtitle, "}", strpos($qtitle, "{INSERTANS:"))-strpos($qtitle, "{INSERTANS:")+1); $replace2=substr($replace, 11, strpos($replace, "}", strpos($replace, "{INSERTANS:"))-11); $replace3=retrieve_Answer($replace2); $qtitle=str_replace($replace, $replace3, $qtitle); } //while while (strpos($qtitle, "{STRTOTIME:") !== false) { $replace=substr($qtitle, strpos($qtitle, "{STRTOTIME:"), strpos($qtitle, "}", strpos($qtitle, "{STRTOTIME:"))-strpos($qtitle, "{STRTOTIME:")+1); $replace2=substr($replace, 11, strpos($replace, "}", strpos($replace, "{STRTOTIME:"))-11); $replace3=date('l, j F',strtotime($replace2)); $qtitle=str_replace($replace, $replace3, $qtitle); } //while while (strpos($qtitle, "{CALCULAGE:") !== false) { $replace=substr($qtitle, strpos($qtitle, "{CALCULAGE:"), strpos($qtitle, "}", strpos($qtitle, "{CALCULAGE:"))-strpos($qtitle, "{CALCULAGE:")+1); $replace2=substr($replace, 11, strpos($replace, "}", strpos($replace, "{CALCULAGE:"))-11); $replace3=retrieve_Answer($replace2); $replace3=getAge(substr($replace3,0,2),substr($replace3,3,2),substr($replace3,6,4)); $qtitle=str_replace($replace, $replace3, $qtitle); } //while //GET HELP $hquery="SELECT help FROM {$dbprefix}questions WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."'"; $hresult=db_execute_num($hquery) or safe_die($connect->ErrorMsg()); //Checked $help=""; while ($hrow=$hresult->FetchRow()) {$help=$hrow[0];} //A bit of housekeeping to stop PHP Notices $answer = ""; if (!isset($_SESSION[$ia[1]])) {$_SESSION[$ia[1]] = "";} $qidattributes=getQuestionAttributes($ia[0]); //echo "
";print_r($qidattributes);echo "
"; //Create the question/answer html // Previously in limesurvey, it was virtually impossible to control how the start of questions were formatted. // this is an attempt to allow users (or rather system admins) some control over how the starting text is formatted. $question_text = array( 'text' => $qtitle ,'help' => '' ,'mandatory' => '' ,'man_message' => '' ,'valid_message' => '' ); switch ($ia[4]) { case 'X': //BOILERPLATE QUESTION $values = do_boilerplate($ia); break; case '5': //5 POINT CHOICE radio-buttons $values = do_5pointchoice($ia); break; case 'D': //DATE $values = do_date($ia); break; case 'Z': //LIST Flexible drop-down/radio-button list $values = do_list_flexible_radio($ia); if (!$displaycols=arraySearchByKey('hide_tip', $qidattributes, 'attribute', 1)) { $qtitle .= "
\n" . $clang->gT('Choose one of the following answers').''; $question_text['help'] = $clang->gT('Choose one of the following answers'); } break; case 'L': //LIST drop-down/radio-button list $values = do_list_radio($ia); if (!$displaycols=arraySearchByKey('hide_tip', $qidattributes, 'attribute', 1)) { $qtitle .= "
\n" . $clang->gT('Choose one of the following answers').''; $question_text['help'] = $clang->gT('Choose one of the following answers'); } break; case 'W': //List - dropdown $values=do_list_flexible_dropdown($ia); if (!$displaycols=arraySearchByKey('hide_tip', $qidattributes, 'attribute', 1)) { $qtitle .= "
\n" . $clang->gT('Choose one of the following answers').''; $question_text['help'] = $clang->gT('Choose one of the following answers'); } break; case '!': //List - dropdown $values=do_list_dropdown($ia); if (!$displaycols=arraySearchByKey('hide_tip', $qidattributes, 'attribute', 1)) { $qtitle .= "
\n" . $clang->gT('Choose one of the following answers').''; $question_text['help'] = $clang->gT('Choose one of the following answers'); } break; case 'O': //LIST WITH COMMENT drop-down/radio-button list + textarea $values=do_listwithcomment($ia); if (count($values[1]) > 1 && !$displaycols=arraySearchByKey('hide_tip', $qidattributes, 'attribute', 1)) { $qtitle .= "
\n" . $clang->gT('Choose one of the following answers').''; $question_text['help'] = $clang->gT('Choose one of the following answers'); } break; case 'R': //RANKING STYLE $values=do_ranking($ia); if (count($values[1]) > 1 && !$displaycols=arraySearchByKey('hide_tip', $qidattributes, 'attribute', 1)) { $question_text['help'] = $clang->gT("Click on an item in the list on the left, starting with your highest ranking item, moving through to your lowest ranking item."); if ($minansw=arraySearchByKey("min_answers", $qidattributes, "attribute", 1)) { $qtitle .= "
\n" . sprintf($clang->gT("Rank at least %d items"), $minansw['value']).""; $question_text['help'] .=' '.sprintf($clang->gT("Rank at least %d items"), $minansw['value']); } } break; case 'M': //MULTIPLE OPTIONS checkbox $values=do_multiplechoice($ia); if (count($values[1]) > 1 && !$displaycols=arraySearchByKey('hide_tip', $qidattributes, 'attribute', 1)) { $maxansw=arraySearchByKey("max_answers", $qidattributes, "attribute", 1); $minansw=arraySearchByKey("min_answers", $qidattributes, "attribute", 1); if (!($maxansw || $minansw)) { $qtitle .= "
\n" . $clang->gT('Check any that apply').''; $question_text['help'] = $clang->gT('Check any that apply'); } else { if ($maxansw && $minansw) { $qtitle .= "
\n" . sprintf($clang->gT("Check between %d and %d answers"), $minansw['value'], $maxansw['value']).""; $question_text['help'] = sprintf($clang->gT("Check between %d and %d answers"), $minansw['value'], $maxansw['value']); } elseif ($maxansw) { $qtitle .= "
\n" . sprintf($clang->gT("Check at most %d answers"), $maxansw['value']).""; $question_text['help'] = sprintf($clang->gT("Check at most %d answers"), $maxansw['value']); } else { $qtitle .= "
\n" . sprintf($clang->gT("Check at least %d answers"), $minansw['value']).""; $question_text['help'] = sprintf($clang->gT("Check at least %d answers"), $minansw['value']); } } } break; case 'I': //Language Question $values=do_language($ia); if (count($values[1]) > 1) { $qtitle .= "
\n" . $clang->gT('Choose your language').''; $question_text['help'] = $clang->gT('Choose your language'); } break; case 'P': //MULTIPLE OPTIONS WITH COMMENTS checkbox + text $values=do_multiplechoice_withcomments($ia); if (count($values[1]) > 1 && !$displaycols=arraySearchByKey('hide_tip', $qidattributes, 'attribute', 1)) { $maxansw=arraySearchByKey("max_answers", $qidattributes, "attribute", 1); $minansw=arraySearchByKey("min_answers", $qidattributes, "attribute", 1); if (!($maxansw || $minansw)) { $qtitle .= "
\n" . $clang->gT('Check any that apply').''; $question_text['help'] = $clang->gT('Check any that apply'); } else { if ($maxansw && $minansw) { $qtitle .= "
\n" . sprintf($clang->gT("Check between %d and %d answers"), $minansw['value'], $maxansw['value']).""; $question_text['help'] = sprintf($clang->gT("Check between %d and %d answers"), $minansw['value'], $maxansw['value']); } elseif ($maxansw) { $qtitle .= "
\n" . sprintf($clang->gT("Check at most %d answers"), $maxansw['value']).""; $question_text['help'] = sprintf($clang->gT("Check at most %d answers"), $maxansw['value']); } else { $qtitle .= "
\n" . sprintf($clang->gT("Check at least %d answers"), $minansw['value']).""; $question_text['help'] = sprintf($clang->gT("Check at least %d answers"), $minansw['value']); } } } break; case 'Q': //MULTIPLE SHORT TEXT $values=do_multipleshorttext($ia); break; case 'K': //MULTIPLE NUMERICAL QUESTION $values=do_multiplenumeric($ia); break; case 'N': //NUMERICAL QUESTION TYPE $values=do_numerical($ia); break; case 'S': //SHORT FREE TEXT $values=do_shortfreetext($ia); break; case 'T': //LONG FREE TEXT $values=do_longfreetext($ia); break; case 'U': //HUGE FREE TEXT $values=do_hugefreetext($ia); break; case 'Y': //YES/NO radio-buttons $values=do_yesno($ia); break; case 'G': //GENDER drop-down list $values=do_gender($ia); break; case 'A': //ARRAY (5 POINT CHOICE) radio-buttons $values=do_array_5point($ia); break; case 'B': //ARRAY (10 POINT CHOICE) radio-buttons $values=do_array_10point($ia); break; case 'C': //ARRAY (YES/UNCERTAIN/NO) radio-buttons $values=do_array_yesnouncertain($ia); break; case 'E': //ARRAY (Increase/Same/Decrease) radio-buttons $values=do_array_increasesamedecrease($ia); break; case 'F': //ARRAY (Flexible) - Row Format $values=do_array_flexible($ia); break; case 'H': //ARRAY (Flexible) - Column Format $values=do_array_flexiblecolumns($ia); break; // case '^': //SLIDER CONTROL // $values=do_slider($ia); // break; case ':': //ARRAY (Multi Flexi) 1 to 10 $values=do_array_multiflexi($ia); break; case ';': //ARRAY (Multi Flexi) Text $values=do_array_multitext($ia); //It's like the "5th element" movie, come to life break; case '1': //Array (Flexible Labels) dual scale $values=do_array_flexible_dual($ia); break; } //End Switch if (isset($values)) //Break apart $values array returned from switch { //$answer is the html code to be printed //$inputnames is an array containing the names of each input field list($answer, $inputnames)=$values; } $answer .= "\n\t\t\tgT('*').''.$qtitle; $question_text['mandatory'] = $clang->gT('*'); } //If this question is mandatory but wasn't answered in the last page //add a message HIGHLIGHTING the question $qtitle .= mandatory_message($ia); $question_text['man_message'] = mandatory_message($ia); $qtitle .= validation_message($ia); $question_text['valid_message'] = validation_message($ia); // ===================================================== // The following section adds to the templating system by allowing // templaters to control where the various parts of the question text // are put. $qtitle_custom = ''; $replace=array(); foreach($question_text as $key => $value) { $find[] = '{QUESTION_'.strtoupper($key).'}'; // Match key words from template $replace[] = $value; // substitue text }; if(!defined('QUESTION_START')) { define('QUESTION_START' , file_get_contents('templates/'.validate_templatedir($thissurvey['template']).'/question_start.pstpl' , true)); }; $qtitle_custom = str_replace( $find , $replace , QUESTION_START); $c = 1; // START: work-around step 1 $qtitle_custom = preg_replace( '/(]+>)(<\/embed>)/i' , '\1NOT_EMPTY\2' , $qtitle_custom ); // END work-around step 1 while($c > 0) // This recursively strips any empty tags to minimise rendering bugs. { $matches = 0; $oldtitle=$qtitle_custom; $qtitle_custom = preg_replace( '/<([^ >]+)[^>]*>[\r\n\t ]*<\/\1>[\r\n\t ]*/isU' , '' , $qtitle_custom , -1); // I removed the $count param because it is PHP 5.1 only. $c = ($qtitle_custom!=$oldtitle)?1:0; }; // START work-around step 2 $qtitle_custom = preg_replace( '/(]+>)NOT_EMPTY(<\/embed>)/i' , '\1\2' , $qtitle_custom ); // END work-around step 2 while($c > 0) // This recursively strips any empty tags to minimise rendering bugs. { $matches = 0; $oldtitle=$qtitle_custom; $qtitle_custom = preg_replace( '/((?: |\r\n|\n\r|\r|\n| )*)+$/i' , '' , $qtitle_custom , -1 ); // I removed the $count param because it is PHP 5.1 only. $c = ($qtitle_custom!=$oldtitle)?1:0; }; $qtitle = $qtitle_custom; // ===================================================== $qanda=array($qtitle, $answer, $help, $display, $name, $ia[2], $gl[0], $ia[1] ); //New Return return array($qanda, $inputnames); } function validation_message($ia) { //This function checks to see if this question requires validation and //that validation has not been met. global $notvalidated, $dbprefix, $connect, $clang; $qtitle=""; if (isset($notvalidated) && is_array($notvalidated)) //ADD WARNINGS TO QUESTIONS IF THEY ARE NOT VALID { global $validationpopup, $popup; if (in_array($ia[1], $notvalidated)) { $help=''; $helpselect="SELECT help\n" ."FROM {$dbprefix}questions\n" ."WHERE qid={$ia[0]} AND language='".$_SESSION['s_lang']."'"; $helpresult=db_execute_assoc($helpselect) or safe_die($helpselect.'
'.$connect->ErrorMsg()); //Checked while ($helprow=$helpresult->FetchRow()) { $help=' '.$helprow['help'].''; } $qtitle .= '
'.$clang->gT('This question must be answered correctly').'.'.$help.'
'; } } return $qtitle; } function mandatory_message($ia) { //This function checks to see if this question is mandatory and //is being re-displayed because it wasn't answered. It returns global $notanswered, $clang, $dbprefix; $qtitle=""; if (isset($notanswered) && is_array($notanswered)) //ADD WARNINGS TO QUESTIONS IF THEY WERE MANDATORY BUT NOT ANSWERED { global $mandatorypopup, $popup; if (in_array($ia[1], $notanswered)) { $qtitle .= "
".$clang->gT('This question is mandatory').'.'; switch($ia[4]) { case 'A': case 'B': case 'C': case 'Q': case 'K': case 'F': case 'J': case 'H': case ':': $qtitle .= "
\n".$clang->gT('Please complete all parts').'.'; break; case '1': $qtitle .= "
\n".$clang->gT('Please check the items').'.'; break; case 'R': $qtitle .= "
\n".$clang->gT('Please rank all items').'.'; break; case 'M': case 'P': $qtitle .= ' '.$clang->gT('Please check at least one item.').'.'; $qquery = "SELECT other FROM {$dbprefix}questions WHERE qid=".$ia[0]; $qresult = db_execute_assoc($qquery); //Checked $qrow = $qresult->FetchRow(); if ($qrow['other']=='Y') { $qidattributes=getQuestionAttributes($ia[0]); if ($othertexts=arraySearchByKey('other_replace_text', $qidattributes, 'attribute', 1)) { $othertext=$clang->gT($othertexts['value']); } else { $othertext=$clang->gT('Other:'); } $qtitle .= "
\n".sprintf($clang->gT("If you choose '%s' you must provide a description."), $othertext); } break; } // end switch $qtitle .= "

\n"; } } return $qtitle; } function mandatory_popup($ia, $notanswered=null) { global $showpopups; //This sets the mandatory popup message to show if required //Called from question.php, group.php or survey.php if ($notanswered === null) {unset($notanswered);} if (isset($notanswered) && is_array($notanswered) && isset($showpopups) && $showpopups == 1) //ADD WARNINGS TO QUESTIONS IF THEY WERE MANDATORY BUT NOT ANSWERED { global $mandatorypopup, $popup, $clang; //POPUP WARNING if (!isset($mandatorypopup) && ($ia[4] == 'T' || $ia[4] == 'S' || $ia[4] == 'U')) { $popup="\n"; $mandatorypopup="Y"; }else { $popup="\n"; $mandatorypopup="Y"; } return array($mandatorypopup, $popup); } else { return false; } } function validation_popup($ia, $notvalidated=null) { global $showpopups; //This sets the validation popup message to show if required //Called from question.php, group.php or survey.php if ($notvalidated === null) {unset($notvalidated);} $qtitle=""; if (isset($notvalidated) && is_array($notvalidated) && isset($showpopups) && $showpopups == 1) //ADD WARNINGS TO QUESTIONS IF THEY ARE NOT VALID { global $validationpopup, $vpopup, $clang; //POPUP WARNING if (!isset($validationpopup)) { $vpopup="\n"; $validationpopup="Y"; } return array($validationpopup, $vpopup); } else { return false; } } // ================================================================== // setting constants for 'checked' and 'selected' inputs define('CHECKED' , ' checked="checked"' , true); define('SELECTED' , ' selected="selected"' , true); // ================================================================== // QUESTION METHODS ================================================= //queXS addition function quexs_submit_on_click($do = true) { $r = ""; if ($do) { $r = "; document.limesurvey.move.value = '"; if (isset($_SESSION['step']) && $_SESSION['step'] && ($_SESSION['step'] == $_SESSION['totalsteps'])) $r .= "movesubmit"; else $r .= "movenext"; $r .= "'; document.limesurvey.submit(); "; } return $r; } function do_boilerplate($ia) { $answer = ' '; $inputnames[]=$ia[1]; return array($answer, $inputnames); } // --------------------------------------------------------------- function do_5pointchoice($ia) { global $shownoanswer, $clang; $answer = "\n
    \n"; for ($fp=1; $fp<=5; $fp++) { $answer .= "\t
  • \n\t\t\n\t\t\n\t
  • \n"; } if ($ia[6] != "Y" && $shownoanswer == 1) // Add "No Answer" option if question is not mandatory { $answer .= "\t
  • \n\t\t\n\t\t\n\t
  • \n"; } $answer .= "
\n\n"; $inputnames[]=$ia[1]; return array($answer, $inputnames); } // --------------------------------------------------------------- function do_date($ia) { global $clang, $js_header_includes, $css_header_includes, $thissurvey; $qidattributes=getQAttributes($ia[0]); $js_header_includes[] = '/scripts/jquery/jquery-ui.js'; $js_header_includes[] = '/scripts/jquery/lime-calendar.js'; $dateformatdetails=getDateFormatData($thissurvey['surveyls_dateformat']); if (isset($qidattributes['dropdown_dates'])) { if (!empty($_SESSION[$ia[1]])) { list($currentyear, $currentmonth, $currentdate) = explode('-', $_SESSION[$ia[1]]); } else { $currentdate=''; $currentmonth=''; $currentyear=''; } $dateorder = split('[/.-]', $dateformatdetails['phpdate']); $answer='

'; foreach($dateorder as $datepart) { switch($datepart) { // Show day select box case 'j': case 'd': $answer .= ' '; break; // Show month select box case 'n': case 'm': $answer .= ' '; break; // Show year select box case 'Y': $answer .= ' '; break; } } $answer .= '

'; $answer .= ' '; } else { $js_header_includes[] = '/scripts/jquery/locale/ui.datepicker-'.$clang->langcode.'.js'; $css_header_includes[]= '/scripts/jquery/css/start/jquery-ui-1.7.1.custom.css'; // Format the date for output if (trim($_SESSION[$ia[1]])!='') { $datetimeobj = new Date_Time_Converter($_SESSION[$ia[1]] , "Y-m-d"); $dateoutput=$datetimeobj->convert($dateformatdetails['phpdate']); } else { $dateoutput=''; } if (isset($qidattributes['dropdown_dates_year_min'])){ $minyear=$qidattributes['dropdown_dates_year_min']; } else { $minyear='1980'; } if (isset($qidattributes['dropdown_dates_year_max'])){ $maxyear=$qidattributes['dropdown_dates_year_max']; } else { $maxyear='2020'; } $answer ="

".sprintf($clang->gT('Format: %s'),$dateformatdetails['dateformat'])."

"; } $inputnames[]=$ia[1]; return array($answer, $inputnames); } // --------------------------------------------------------------- function do_language($ia) { global $dbprefix, $surveyid, $clang; $answerlangs = GetAdditionalLanguagesFromSurveyID($surveyid); $answerlangs [] = GetBaseLanguageFromSurveyID($surveyid); $answer = "\n\t\t\t

\n\t\t\t\t\n"; $answer .= "\t\t\t\t\n"; $inputnames[]=$ia[1]; $answer .= "\n\t\t\t\t\n\t\t\t

\n"; return array($answer, $inputnames); } // --------------------------------------------------------------- function do_list_dropdown($ia) { global $dbprefix, $dropdownthreshold, $lwcdropdowns, $connect; global $shownoanswer, $clang; $qidattributes=getQuestionAttributes($ia[0]); if ($othertexts=arraySearchByKey('other_replace_text', $qidattributes, 'attribute', 1)) { $othertext=$clang->gT($othertexts['value']); } else { $othertext=$clang->gT('Other:'); } if ($optCategorySeparator = arraySearchByKey('category_separator', $qidattributes, 'attribute', 1)) { $optCategorySeparator = $optCategorySeparator['value']; } else { unset($optCategorySeparator); } $answer=''; if (isset($defexists)) {unset ($defexists);} $query = "SELECT other FROM {$dbprefix}questions WHERE qid=".$ia[0]." AND language='".$_SESSION['s_lang']."' "; $result = db_execute_assoc($query); //Checked while($row = $result->FetchRow()) {$other = $row['other'];} //question attribute random order set? if (arraySearchByKey('random_order', $qidattributes, 'attribute', 1)) { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random(); } //question attribute alphasort set? elseif(arraySearchByKey('alphasort', $qidattributes, 'attribute', 1)) { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY answer"; } //no question attributes -> order by sortorder else { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, answer"; } $ansresult = db_execute_assoc($ansquery) or safe_die('Couldn\'t get answers
'.$ansquery.'
'.$connect->ErrorMsg()); //Checked if (!isset($optCategorySeparator)) { while ($ansrow = $ansresult->FetchRow()) { if ($_SESSION[$ia[1]] == $ansrow['code']) { $opt_select = SELECTED; } elseif ($ansrow['default_value'] == 'Y') { $opt_select = SELECTED; $defexists = 'Y'; } else { $opt_select = ''; } $answer .= ' '; } } else { $defaultopts = Array(); $optgroups = Array(); while ($ansrow = $ansresult->FetchRow()) { // Let's sort answers in an array indexed by subcategories list ($categorytext, $answertext) = explode($optCategorySeparator,$ansrow['answer']); // The blank category is left at the end outside optgroups if ($categorytext == '') { $defaultopts[] = array ( 'code' => $ansrow['code'], 'answer' => $answertext, 'default_value' => $ansrow['default_value']); } else { $optgroups[$categorytext][] = array ( 'code' => $ansrow['code'], 'answer' => $answertext, 'default_value' => $ansrow['default_value']); } } foreach ($optgroups as $categoryname => $optionlistarray) { $answer .= ' '; foreach ($optionlistarray as $optionarray) { if ($_SESSION[$ia[1]] == $optionarray['code']) { $opt_select = SELECTED; } elseif ($optionarray['default_value'] == 'Y') { $opt_select = SELECTED; $defexists = 'Y'; } else { $opt_select = ''; } $answer .= ' '; } $answer .= ' '; } $opt_select=''; foreach ($defaultopts as $optionarray) { if ($_SESSION[$ia[1]] == $optionarray['code']) { $opt_select = SELECTED; } elseif ($optionarray['default_value'] == 'Y') { $opt_select = SELECTED; $defexists = 'Y'; } else { $opt_select = ''; } $answer .= ' '; } } if (!$_SESSION[$ia[1]] && (!isset($defexists) || !$defexists)) { $answer = ' '.$answer; } if (isset($other) && $other=='Y') { if ($_SESSION[$ia[1]] == '-oth-') { $opt_select = SELECTED; } else { $opt_select = ''; } $answer .= ' \n"; } if ((isset($_SESSION[$ia[1]]) || $_SESSION[$ia[1]] != '') && (!isset($defexists) || !$defexists) && $ia[6] != 'Y' && $shownoanswer == 1) { $answer .= ' \n"; } $answer .= ' '; if (isset($other) && $other=='Y') { $sselect_show_hide = ' showhideother(this.name, this.value);'; } else { $sselect_show_hide = ''; } $sselect = '

END BUG FIX // --> START NEW FEATURE - SAVE $answer .= " onchange='checkconditions(this.value, this.name, this.type); document.limesurvey.move.value = '"; if (isset($_SESSION['step']) && $_SESSION['step'] && ($_SESSION['step'] == $_SESSION['totalsteps'])) $answer .= "movesubmit"; else $answer .= "movenext"; $answer .= "'; document.limesurvey.submit();\" "; $thisfieldname="$ia[1]other"; if (isset($_SESSION[$thisfieldname])) { $answer .= " value='".htmlspecialchars($_SESSION[$thisfieldname],ENT_QUOTES)."' ";} $answer .= ' />'; $answer .= "

"; // --> END NEW FEATURE - SAVE $inputnames[]=$ia[1]."other"; } else { $answer .= "

"; } $checkotherscript = ""; if (isset($other) && $other == 'Y' && $other_comment_mandatory=arraySearchByKey('other_comment_mandatory', $qidattributes, 'attribute', 1)) { $checkotherscript = "\n\n"; } $answer = $checkotherscript . $answer; $inputnames[]=$ia[1]; return array($answer, $inputnames); } // --------------------------------------------------------------- function do_list_flexible_dropdown($ia) { global $dbprefix, $dropdownthreshold, $lwcdropdowns, $connect; global $shownoanswer, $clang; $qidattributes=getQuestionAttributes($ia[0]); if ($othertexts=arraySearchByKey('other_replace_text', $qidattributes, 'attribute', 1)) { $othertext=$clang->gT($othertexts['value']); } else { $othertext=$clang->gT('Other'); } $answer=''; $qquery = "SELECT other, lid FROM {$dbprefix}questions WHERE qid=".$ia[0]." AND language='".$_SESSION['s_lang']."'"; $qresult = db_execute_assoc($qquery); //Checked while($row = $qresult->FetchRow()) {$other = $row['other']; $lid=$row['lid'];} $filter=''; if ($code_filter=arraySearchByKey('code_filter', $qidattributes, 'attribute', 1)) { $filter=$code_filter['value']; if(isset($_SESSION['insertarray']) && in_array($filter, $_SESSION['insertarray'])) { $filter=trim($_SESSION[$filter]); } } $filter .= '%'; //question attribute random order set? if (arraySearchByKey('random_order', $qidattributes, 'attribute', 1)) { $ansquery = "SELECT * FROM {$dbprefix}labels WHERE lid=$lid AND code LIKE '$filter' AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random(); } //question attribute alphasort set? elseif(arraySearchByKey('alphasort', $qidattributes, 'attribute', 1)) { $ansquery = "SELECT * FROM {$dbprefix}labels WHERE lid=$lid AND code LIKE '$filter' AND language='".$_SESSION['s_lang']."' ORDER BY title"; } //no question attributes -> order by sortorder else { $ansquery = "SELECT * FROM {$dbprefix}labels WHERE lid=$lid AND code LIKE '$filter' AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, code"; } $ansresult = db_execute_assoc($ansquery) or safe_die('Couldn\'t get answers
$ansquery
'.$connect->ErrorMsg());//Checked if (labelset_exists($lid,$_SESSION['s_lang'])) { $opt_select=''; while ($ansrow = $ansresult->FetchRow()) { if ($_SESSION[$ia[1]] == $ansrow['code']) { $opt_select = SELECTED; } else { $opt_select = ''; } $answer .= '\n"; } if (!$_SESSION[$ia[1]] && (!isset($defexists) || !$defexists)) { $answer = '\n".$answer; } if (isset($other) && $other=='Y') { if ($_SESSION[$ia[1]] == '-oth-') { $opt_select = SELECTED; } else { $opt_select = ''; } $answer .= ' \n"; } if ((isset($_SESSION[$ia[1]]) || $_SESSION[$ia[1]] != '') && (!isset($defexists) || !$defexists) && $ia[6] != 'Y' && $shownoanswer == 1) { $answer .= ' \n"; } $answer .= "\t\t\t\t\n"; } else { $answer .= ' '; } $answer .= ' \n"; if (isset($other) && $other=="Y") { $sselect_show_hide = ' showhideother(this.name, this.value)'; } else { $sselect_show_hide = ''; } $sselect = '

\n\t\t\t\n"; $inputnames[]=$ia[1]."other"; } $checkotherscript = ""; if (isset($other) && $other == 'Y' && $other_comment_mandatory=arraySearchByKey('other_comment_mandatory', $qidattributes, 'attribute', 1)) { $checkotherscript = "\n"; } $answer = $checkotherscript . $answer ."

"; $inputnames[]=$ia[1]; return array($answer, $inputnames); } // --------------------------------------------------------------- function do_list_radio($ia) { global $dbprefix, $dropdownthreshold, $lwcdropdowns, $connect, $clang; global $shownoanswer; $qidattributes=getQAttributes($ia[0]); unset ($defexists); $query = "SELECT other FROM {$dbprefix}questions WHERE qid=".$ia[0]." AND language='".$_SESSION['s_lang']."' "; $result = db_execute_assoc($query); //Checked while($row = $result->FetchRow()) { $other = $row['other']; } //question attribute random order set? if (isset($qidattributes['random_order'])) { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random(); } //question attribute alphasort set? elseif (isset($qidattributes['alphasort'])) { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY answer"; } //no question attributes -> order by sortorder else { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, answer"; } $ansresult = db_execute_assoc($ansquery) or safe_die('Couldn\'t get answers
$ansquery
'.$connect->ErrorMsg()); //Checked $anscount = $ansresult->RecordCount(); if (isset($qidattributes['display_columns'])) { $dcols = $qidattributes['display_columns']; } else { $dcols= 1; } if (isset($qidattributes['other_replace_text'])) { $othertext=$clang->gT($qidattributes['other_replace_text']); } else { $othertext=$clang->gT('Other:'); } if (isset($other) && $other=='Y') {$anscount++;} //Count up for the Other answer if ($ia[6] != 'Y' && $shownoanswer == 1) {$anscount++;} //Count up if "No answer" is showing $wrapper = setup_columns($dcols , $anscount); $answer = $wrapper['whole-start']; $rowcounter = 0; $colcounter = 1; while ($ansrow = $ansresult->FetchRow()) { if ($_SESSION[$ia[1]] == $ansrow['code']) { $check_ans = CHECKED; } elseif ($ansrow['default_value'] == 'Y') { $check_ans = CHECKED; $defexists = 'Y'; } else { $check_ans = ''; } // $answer .= $wrapper['item-start'].' // TIBO switch to the following line in order to reset the othercomment field when the other option is unselected $answer .= $wrapper['item-start'].' '.$wrapper['item-end']; ++$rowcounter; if ($rowcounter == $wrapper['maxrows'] && $colcounter < $wrapper['cols']) { if($colcounter == $wrapper['cols'] - 1) { $answer .= $wrapper['col-devide-last']; } else { $answer .= $wrapper['col-devide']; } $rowcounter = 0; ++$colcounter; } } if (isset($other) && $other=='Y') { if (isset($qidattributes['other_numbers_only'])) { $numbersonly = 'onkeypress="return goodchars(event,\'-0123456789.\')"'; } else { $numbersonly = ''; } if ($_SESSION[$ia[1]] == '-oth-') { $check_ans = CHECKED; } else { $check_ans = ''; } $thisfieldname=$ia[1].'other'; if (isset($_SESSION[$thisfieldname])) { $answer_other = ' value="'.htmlspecialchars($_SESSION[$thisfieldname],ENT_QUOTES).'"'; } else { $answer_other = ' value=""'; } $answer .= $wrapper['item-start-other'].' '.$wrapper['item-end']; $inputnames[]=$thisfieldname; ++$rowcounter; if ($rowcounter == $wrapper['maxrows'] && $colcounter < $wrapper['cols']) { if($colcounter == $wrapper['cols'] - 1) { $answer .= $wrapper['col-devide-last']; } else { $answer .= $wrapper['col-devide']; } $rowcounter = 0; ++$colcounter; } } if ($ia[6] != 'Y' && $shownoanswer == 1) { if (((!isset($_SESSION[$ia[1]]) || $_SESSION[$ia[1]] == '') && (!isset($defexists) || !$defexists)) || ($_SESSION[$ia[1]] == ' ' && (!isset($defexists) || !$defexists))) { $check_ans = CHECKED; //Check the "no answer" radio button if there is no default, and user hasn't answered this. } else { $check_ans = ''; } $answer .= $wrapper['item-start'].' '.$wrapper['item-end']; // --> END NEW FEATURE - SAVE ++$rowcounter; if ($rowcounter == $wrapper['maxrows'] && $colcounter < $wrapper['cols']) { if($colcounter == $wrapper['cols'] - 1) { $answer .= $wrapper['col-devide-last']; } else { $answer .= $wrapper['col-devide']; } $rowcounter = 0; ++$colcounter; } } $answer .= $wrapper['whole-end'].' \n"; $checkotherscript = ""; if (isset($other) && $other == 'Y' && isset($qidattributes['other_comment_mandatory'])) { $checkotherscript = "\n"; } $answer = $checkotherscript . $answer; $inputnames[]=$ia[1]; return array($answer, $inputnames); } // --------------------------------------------------------------- function do_list_flexible_radio($ia) { global $dbprefix, $dropdownthreshold, $lwcdropdowns, $connect; global $shownoanswer, $clang; $qidattributes=getQuestionAttributes($ia[0]); if ($othertexts=arraySearchByKey('other_replace_text', $qidattributes, 'attribute', 1)) { $othertext=$clang->gT($othertexts['value']); } else { $othertext=$clang->gT('Other:'); } if ($displaycols=arraySearchByKey('display_columns', $qidattributes, 'attribute', 1)) { $dcols=$displaycols['value']; } else { $dcols = 1; } if (isset($defexists)) {unset ($defexists);} $query = "SELECT other, lid FROM {$dbprefix}questions WHERE qid=".$ia[0]." AND language='".$_SESSION['s_lang']."'"; $result = db_execute_assoc($query); //Checked while($row = $result->FetchRow()) {$other = $row['other']; $lid = $row['lid'];} $filter=''; if ($code_filter=arraySearchByKey("code_filter", $qidattributes, "attribute", 1)) { $filter=$code_filter['value']; if(isset($_SESSION['insertarray']) && in_array($filter, $_SESSION['insertarray'])) { $filter=trim($_SESSION[$filter]); } } $filter .= '%'; //question attribute random order set? if (arraySearchByKey('random_order', $qidattributes, 'attribute', 1)) { $ansquery = "SELECT * FROM {$dbprefix}labels WHERE lid=$lid AND code LIKE '$filter' AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random(); } //question attribute alphasort set? elseif (arraySearchByKey('alphasort', $qidattributes, 'attribute', 1)) { $ansquery = "SELECT * FROM {$dbprefix}labels WHERE lid=$lid AND code LIKE '$filter' AND language='".$_SESSION['s_lang']."' ORDER BY title"; } //no question attributes -> order by sortorder else { $ansquery = "SELECT * FROM {$dbprefix}labels WHERE lid=$lid AND code LIKE '$filter' AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, code"; } $ansresult = db_execute_assoc($ansquery) or safe_die("Couldn't get answers
$ansquery
".$connect->ErrorMsg()); //Checked $anscount = $ansresult->RecordCount(); if ((isset($other) && $other=='Y') || ($ia[6] != 'Y' && $shownoanswer == 1)) {$anscount++;} //Count $wrapper = setup_columns($dcols , $anscount); $answer = $wrapper['whole-start']; $rowcounter = 0; $colcounter = 1; if (labelset_exists($lid,$_SESSION['s_lang'])) { while ($ansrow = $ansresult->FetchRow()) { if ($_SESSION[$ia[1]] == $ansrow['code']) { $check_ans = CHECKED; } else { $check_ans =''; }; $answer .= $wrapper['item-start'].' '.$wrapper['item-end']; ++$rowcounter; if ($rowcounter == $wrapper['maxrows'] && $colcounter < $wrapper['cols']) { if($colcounter == $wrapper['cols'] - 1) { $answer .= $wrapper['col-devide-last']; } else { $answer .= $wrapper['col-devide']; } $rowcounter = 0; ++$colcounter; } } } else { $answer .= $clang->gT('Error: The labelset used for this question is not available in this language.').'
'; } if (isset($other) && $other=='Y') { if ($_SESSION[$ia[1]] == '-oth-') { $check_ans = CHECKED; } else { $check_ans = ''; } $thisfieldname=$ia[1].'other'; if (isset($_SESSION[$thisfieldname])) { $answer_other = ' value="'.htmlspecialchars($_SESSION[$thisfieldname],ENT_QUOTES).'"'; } else { $answer_other = ' value=""'; } $answer .= $wrapper['item-start'].' '.$wrapper['item-end']; $inputnames[]=$thisfieldname; ++$rowcounter; if ($rowcounter == $wrapper['maxrows'] && $colcounter < $wrapper['cols']) { if($colcounter == $wrapper['cols'] - 1) { $answer .= $wrapper['col-devide-last']; } else { $answer .= $wrapper['col-devide']; } $rowcounter = 0; ++$colcounter; } } if ($ia[6] != 'Y' && $shownoanswer == 1) { if ((!isset($defexists) || $defexists != 'Y') && (!isset($_SESSION[$ia[1]]) || $_SESSION[$ia[1]] == '' || $_SESSION[$ia[1]] == ' ')) { $check_ans = CHECKED; //Check the "no answer" radio button if there is no default, and user hasn't answered this. } else { $check_ans = ''; } $answer .= $wrapper['item-start'].' '.$wrapper['item-end']; ++$rowcounter; if ($rowcounter == $wrapper['maxrows'] && $colcounter < $wrapper['cols']) { if($colcounter == $wrapper['cols'] - 1) { $answer .= $wrapper['col-devide-last']; } else { $answer .= $wrapper['col-devide']; } $rowcounter = 0; ++$colcounter; } } $answer .= $wrapper['whole-end'].' \n"; $checkotherscript = ""; if (isset($other) && $other == 'Y' && $other_comment_mandatory=arraySearchByKey('other_comment_mandatory', $qidattributes, 'attribute', 1)) { $checkotherscript = "\n"; } $answer = $checkotherscript . $answer; $inputnames[]=$ia[1]; return array($answer, $inputnames); } // --------------------------------------------------------------- function do_listwithcomment($ia) { global $maxoptionsize, $dbprefix, $dropdownthreshold, $lwcdropdowns; global $shownoanswer, $clang; $answer = ''; $qidattributes=getQuestionAttributes($ia[0]); if (!isset($maxoptionsize)) {$maxoptionsize=35;} //question attribute random order set? if (arraySearchByKey('random_order', $qidattributes, 'attribute', 1)) { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random(); } //question attribute alphasort set? elseif (arraySearchByKey('alphasort', $qidattributes, 'attribute', 1)) { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY answer"; } //no question attributes -> order by sortorder else { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, answer"; } $ansresult = db_execute_assoc($ansquery); //Checked $anscount = $ansresult->RecordCount(); $hint_list = $clang->gT('Please choose one of the following'); $hint_comment = $clang->gT('Please enter your comment here'); if ($lwcdropdowns == 'R' && $anscount <= $dropdownthreshold) { $answer .= '

'.$hint_list.':

    '; while ($ansrow=$ansresult->FetchRow()) { if ($_SESSION[$ia[1]] == $ansrow['code']) { $check_ans = CHECKED; } elseif ($ansrow['default_value'] == 'Y') { $check_ans = CHECKED; $defexists = 'Y'; } else { $check_ans = ''; } $answer .= '
  • '; } if ($ia[6] != 'Y' && $shownoanswer == 1) { if (((!isset($_SESSION[$ia[1]]) || $_SESSION[$ia[1]] == '') && (!isset($defexists) || !$defexists)) ||($_SESSION[$ia[1]] == ' ' && (!isset($defexists) || !$defexists))) { $check_ans = CHECKED; } elseif ((isset($_SESSION[$ia[1]]) || $_SESSION[$ia[1]] != '') && (!isset($defexists) || !$defexists)) { $check_ans = ''; } $answer .= '
  • '; } $fname2 = $ia[1].'comment'; if ($anscount > 8) {$tarows = $anscount/1.2;} else {$tarows = 4;} // --> START NEW FEATURE - SAVE // --> START ORIGINAL // $answer .= "\t\t\t\t\t\n" // . "\t\t\t\t\t\t

    "; $inputnames[]=$ia[1]; $inputnames[]=$ia[1].'comment'; } else //Dropdown list { // --> START NEW FEATURE - SAVE $answer .= '

    '; $fname2 = $ia[1].'comment'; if ($anscount > 8) {$tarows = $anscount/1.2;} else {$tarows = 4;} if ($tarows > 15) {$tarows=15;} $maxoptionsize=$maxoptionsize*0.72; if ($maxoptionsize < 33) {$maxoptionsize=33;} if ($maxoptionsize > 70) {$maxoptionsize=70;} $answer .= '

    '.$hint_comment.' \n

    \n"; $inputnames[]=$ia[1]; $inputnames[]=$ia[1].'comment'; } return array($answer, $inputnames); } // --------------------------------------------------------------- function do_ranking($ia) { global $dbprefix, $imagefiles, $clang, $thissurvey; $qidattributes=getQuestionAttributes($ia[0]); $answer=""; if (arraySearchByKey("random_order", $qidattributes, "attribute", 1)) { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random(); } else { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, answer"; } if ($ma=arraySearchByKey("max_answers", $qidattributes, "attribute", 1)) { $max_answers = $ma['value']; } else { $max_answers = false; } $ansresult = db_execute_assoc($ansquery); //Checked $anscount = $ansresult->RecordCount(); if(!$max_answers) { $max_answers=$anscount; } $finished=$anscount-$max_answers; $answer .= "\t\t\t\n"; unset($answers); //unset($inputnames); unset($chosen); $ranklist=""; while ($ansrow = $ansresult->FetchRow()) { $answers[] = array($ansrow['code'], $ansrow['answer']); } $existing=0; for ($i=1; $i<=$anscount; $i++) { $myfname=$ia[1].$i; if (isset($_SESSION[$myfname]) && $_SESSION[$myfname]) { $existing++; } } for ($i=1; $i<=$max_answers; $i++) { $myfname = $ia[1].$i; if (isset($_SESSION[$myfname]) && $_SESSION[$myfname]) { foreach ($answers as $ans) { if ($ans[0] == $_SESSION[$myfname]) { $thiscode=$ans[0]; $thistext=$ans[1]; } } } $ranklist .= "\t\t\t\t\t\t\t \n"; $ranklist .= "\t\t\t\t\t\t\n"; $ranklist .= "\t\t\t\t\t\t\"".$clang-gT("Remove this item")."\" title=\"".$clang->gT("Remove this item")."\" "; if ($i != $existing) { $ranklist .= "style=\"display:none\""; } $ranklist .= " id=\"cut_{$ia[0]}$i\" onclick=\"deletethis_{$ia[0]}(document.limesurvey.RANK_{$ia[0]}$i.value, document.limesurvey.fvalue_{$ia[0]}$i.value, document.limesurvey.RANK_{$ia[0]}$i.name, this.id)\" />
    \n"; $inputnames[]=$myfname; $ranklist .= "\n"; } $choicelist = "\t\t\t\t\t\t\n"; } $choicelist .= "\t\t\t\t\t\t\n"; $choicelist .= $hiddens; $answer .= "\t\t\t\n" . "\t\t\t\t\n" . "\t\t\t\t\t\n"; if (isset($maxselectlength) && $maxselectlength > 60) { $ranklist = str_replace("\n" . "\t\t\t\t\t\t\t
    \n" . "\t\t\t\t\t\t  
    \n" . " ".$choicelist . "\t\t\t\t\t 
    \n" . "\t\t\t\t\t\t\t\n"; } else { $answer .= "\t\t\t\t\t\n" . "\t\t\t\t\n" . "\t\t\t\t\n" . "\t\t\t\t\t\n" . "\t\t\t\t\n" . "\t\t\t
    ".$clang->gT("Your Ranking").":
    \n" . "\t\t\t\t\t\t\t\n" . "\t\t\t\t\t\t\t\n"; } $answer .= $ranklist . "\t\t\t\t\t\t\t
    ".$clang->gT("Your Ranking").":
    \n" . "\t\t\t\t\t
    \n" . "\t\t\t\t\t\t".$clang->gT("Click on the scissors next to each item on the right to remove the last entry in your ranked list") . "\t\t\t\t\t
    \n"; if ($minanswattr=arraySearchByKey("min_answers", $qidattributes, "attribute", 1)) { $minansw=$minanswattr['value']; $minanswscript = "\n"; $answer = $minanswscript . $answer; } return array($answer, $inputnames); } // --------------------------------------------------------------- function do_multiplechoice($ia) { global $dbprefix, $clang, $connect; $qidattributes=getQuestionAttributes($ia[0]); if ($othertexts=arraySearchByKey('other_replace_text', $qidattributes, 'attribute', 1)) { $othertext=$clang->gT($othertexts['value']); } else { $othertext=$clang->gT('Other:'); } if ($displaycols=arraySearchByKey('display_columns', $qidattributes, 'attribute', 1)) { $dcols = $displaycols['value']; } else { $dcols = 1; } if (arraySearchByKey('other_numbers_only', $qidattributes, 'attribute', 1)) { $numbersonly = 'return goodchars(event,"0123456789.")'; } else { $numbersonly = ''; } // Check if the max_answers attribute is set $maxansw = 0; $callmaxanswscriptcheckbox = ''; $callmaxanswscriptother = ''; $maxanswscript = ''; if ($excludeothers=arraySearchByKey('exclude_all_others', $qidattributes, 'attribute', '')) { foreach($excludeothers as $excludeother) { $excludeallothers[]=$excludeother['value']; } $excludeallotherscript = " \n"; } } } elseif ($ansrow['default_value'] == 'Y') { $answer .= CHECKED; } $answer .= " onclick='cancelBubbleThis(event);"; if(in_array($ansrow['code'], $excludeallothers)) { $answer .= "excludeAllOthers$ia[1](this.id, \"yes\");"; // was "this.id" $excludeallotherscripton .= "/* SKIPPING QUESTION {$ia[1]} */\n"; // $excludeallotherscripton .= "alert(value+'---'+'answer$ia[1]{$ansrow['code']}');\n"; $excludeallotherscripton .= "if( value != 'answer$ia[1]{$ansrow['code']}') {\n" . "\tthiselt=document.getElementById('answer$ia[1]{$ansrow['code']}');\n" . "\t\tthiselt.checked='';\n" . "\t\tthiselt.disabled='true';\n" . "\t\tif (doconditioncheck == 'yes') {\n" . "\t\t\tcheckconditions(thiselt.value, thiselt.name, thiselt.type);\n" . "\t\t}\n}\n"; $excludeallotherscriptoff .= "document.getElementById('answer$ia[1]{$ansrow['code']}').disabled='';\n"; } elseif (count($excludeallothers)>0) { $excludeallotherscripton .= "\tthiselt=document.getElementById('answer$ia[1]{$ansrow['code']}');\n" . "\t\tthiselt.checked='';\n" . "\t\tthiselt.disabled='true';\n" . "\t\tif (doconditioncheck == 'yes') {\n" . "\t\t\tcheckconditions(thiselt.value, thiselt.name, thiselt.type);\n" . "\t\t}\n"; $excludeallotherscriptoff.= "document.getElementById('answer$ia[1]{$ansrow['code']}').disabled='';\n"; } $answer .= $callmaxanswscriptcheckbox."checkconditions(this.value, this.name, this.type)' />\n\t\t\n"; // --> END NEW FEATURE - SAVE if ($maxansw > 0) {$maxanswscript .= "\t\t\t\t\tif (document.getElementById('answer".$myfname."').checked) { count += 1; }\n";} if ($minansw > 0) {$minanswscript .= "\t\t\t\t\tif (document.getElementById('answer".$myfname."').checked) { count += 1; }\n";} ++$fn; $answer .= ' \n{$wrapper['item-end']}"; $inputnames[]=$myfname; ++$rowcounter; if ($rowcounter == $wrapper['maxrows'] && $colcounter < $wrapper['cols']) { if($colcounter == $wrapper['cols'] - 1) { $answer .= $wrapper['col-devide-last']; } else { $answer .= $wrapper['col-devide']; } $rowcounter = 0; ++$colcounter; } } if ($other == 'Y') { $myfname = $ia[1].'other'; if(count($excludeallothers) > 0) { $excludeallotherscripton .= "thiselt=document.getElementById('answer{$ia[1]}othercbox');\n" . "\t\tthiselt.checked='';\n" . "\t\tthiselt.disabled='true';\n"; $excludeallotherscripton .= "thiselt=document.getElementById('answer$ia[1]other');\n" . "\t\tthiselt.value='';\n" . "\t\tthiselt.disabled='true';\n" . "\t\tif (doconditioncheck == 'yes') {\n" . "\t\t\tcheckconditions(thiselt.value, thiselt.name, thiselt.type);\n" . "\t\t}\n"; $excludeallotherscriptoff .="document.getElementById('answer$ia[1]other').disabled='';\n"; $excludeallotherscriptoff .="document.getElementById('answer{$ia[1]}othercbox').disabled='';\n"; } $answer .= $wrapper['item-start'].' 0) { // // For multiplechoice question there is no DB field for the other Checkbox // so in fact I need to assume that other_comment_mandatory is set to true // We only count the -other- as valid if both the cbox and the other text is filled // ==> hence the 1==1 if (1==1 || $other_comment_mandatory=arraySearchByKey('other_comment_mandatory', $qidattributes, 'attribute', 1)) { $minanswscript .= "\t\t\t\t\tif (document.getElementById('answer".$myfname."').value != '' && document.getElementById('answer".$myfname."cbox').checked ) { count += 1; }\n"; } else { $minanswscript .= "\t\t\t\t\tif (document.getElementById('answer".$myfname."').value != '' || document.getElementById('answer".$myfname."cbox').checked ) { count += 1; }\n"; } } if (isset($_SESSION[$myfname])) { $answer .= htmlspecialchars($_SESSION[$myfname],ENT_QUOTES); } $answer .= "\" />\n{$wrapper['item-end']}"; $inputnames[]=$myfname; ++$anscount; ++$rowcounter; if ($rowcounter == $wrapper['maxrows'] && $colcounter < $wrapper['cols']) { if($colcounter == $wrapper['cols'] - 1) { $answer .= $wrapper['col-devide-last']; } else { $answer .= $wrapper['col-devide']; } $rowcounter = 0; ++$colcounter; } } $answer .= $wrapper['whole-end']; if ( $maxansw > 0 ) { $maxanswscript .= "\t\t\t\t\tif (count > max)\n" . "\t\t\t\t\t\t{\n" . "\t\t\t\t\t\talert('".sprintf($clang->gT("Please choose at most %d answer(s) for question \"%s\"","js"), $maxansw, trim(javascript_escape(str_replace(array("\n", "\r"), "", $ia[3]),true,true)))."');\n" . "\t\t\t\t\t\tif (me.type == 'checkbox') {me.checked = false;}\n" . "\t\t\t\t\t\tif (me.type == 'text') {\n" . "\t\t\t\t\t\t\tme.value = '';\n" . "\t\t\t\t\t\t\tif (document.getElementById(me.name + 'cbox') ){\n" . "\t\t\t\t\t\t\t\t document.getElementById(me.name + 'cbox').checked = false;\n" . "\t\t\t\t\t\t\t}\n" . "\t\t\t\t\t\t}" . "\t\t\t\t\t\treturn max;\n" . "\t\t\t\t\t\t}\n" . "\t\t\t\t\t}\n" . "\t\t\t//-->\n" . "\t\t\t\n"; $answer = $maxanswscript . $answer; } if ( $minansw > 0 ) { $minanswscript .= "\t\t\t\t\tif (count < {$minansw} && document.getElementById('display{$ia[0]}').value == 'on'){\n" . "\t\t\t\t\t\talert('".sprintf($clang->gT("Please choose at least %d answer(s) for question \"%s\"","js"), $minansw, trim(javascript_escape(str_replace(array("\n", "\r"), "",$ia[3]),true,true)))."');\n" . "\t\t\t\t\t\treturn false;\n" . "\t\t\t\t\t} else {\n" . "\t\t\t\t\t\tif (oldonsubmit_{$ia[0]}){\n" . "\t\t\t\t\t\t\treturn oldonsubmit_{$ia[0]}();\n" . "\t\t\t\t\t\t}\n" . "\t\t\t\t\t\treturn true;\n" . "\t\t\t\t\t}\n" . "\t\t\t\t}\n" . "\t\t\t\tdocument.limesurvey.onsubmit = ensureminansw_{$ia[0]}\n" . "\t\t\t\t-->\n" . "\t\t\t\n"; //$answer = $minanswscript . $answer; } $checkotherscript = ""; if ($other == 'Y') { // Multiple options with 'other' is a specific case as the checkbox isn't recorded into DB // this means that if it is cehcked We must force the end-user to enter text in the input // box $checkotherscript = "\n"; } $answer = $minanswscript . $checkotherscript . $answer; if (count($excludeallothers)>0) { $excludeallotherscript .= " if (document.getElementById(value).checked) { $excludeallotherscripton } else { $excludeallotherscriptoff } } //--> "; $answer = $excludeallotherscript . $answer; } $answer .= $postrow; return array($answer, $inputnames); } // --------------------------------------------------------------- function do_multiplechoice_withcomments($ia) { global $dbprefix, $clang; $qidattributes=getQuestionAttributes($ia[0]); if (arraySearchByKey('other_numbers_only', $qidattributes, 'attribute', 1)) { $numbersonly = 'onkeypress="return goodchars(event,\'-0123456789.\')"'; } else { $numbersonly = ''; } if ($othertexts=arraySearchByKey('other_replace_text', $qidattributes, 'attribute', 1)) { $othertext=$clang->gT($othertexts['value']); } else { $othertext=$clang->gT('Other:'); } // Check if the max_answers attribute is set $maxansw=0; $callmaxanswscriptcheckbox = ''; $callmaxanswscriptcheckbox2 = ''; $callmaxanswscriptother = ''; $maxanswscript = ''; if ($maxanswattr=arraySearchByKey('max_answers', $qidattributes, 'attribute', 1)) { $maxansw=$maxanswattr['value']; $callmaxanswscriptcheckbox = "limitmaxansw_{$ia[0]}(this);"; $callmaxanswscriptcheckbox2= "limitmaxansw_{$ia[0]}"; $callmaxanswscriptother = "onkeyup=\"limitmaxansw_{$ia[0]}(this)\""; $maxanswscript = "\t\t\t\n"; $answer = $maxanswscript . $answer; } if ( $minansw > 0 ) { $minanswscript .= "\t\t\t\t\tif (count < {$minansw} && document.getElementById('display{$ia[0]}').value == 'on'){\n" . "\t\t\t\t\t\talert('".sprintf($clang->gT("Please choose at least %d answer(s) for question \"%s\"","js"), $minansw, trim(javascript_escape(str_replace(array("\n", "\r"), "",$ia[3]),true,true)))."');\n" . "\t\t\t\t\t\treturn false;\n" . "\t\t\t\t\t} else {\n" . "\t\t\t\t\t\tif (oldonsubmit_{$ia[0]}){\n" . "\t\t\t\t\t\t\treturn oldonsubmit_{$ia[0]}();\n" . "\t\t\t\t\t\t}\n" . "\t\t\t\t\t\treturn true;\n" . "\t\t\t\t\t}\n" . "\t\t\t\t}\n" . "\t\t\t\tdocument.limesurvey.onsubmit = ensureminansw_{$ia[0]}\n" . "\t\t\t\t-->\n" . "\t\t\t\n"; //$answer = $minanswscript . $answer; } $checkotherscript = ""; if ($other == 'Y' && $other_comment_mandatory=arraySearchByKey('other_comment_mandatory', $qidattributes, 'attribute', 1)) { // Multiple options with 'other' is a specific case as the checkbox isn't recorded into DB // this means that if it is cehcked We must force the end-user to enter text in the input // box $checkotherscript = "\n"; } $answer = $minanswscript . $checkotherscript . $answer; return array($answer, $inputnames); } // --------------------------------------------------------------- function do_multipleshorttext($ia) { global $dbprefix, $clang; $answer=''; $qidattributes=getQuestionAttributes($ia[0]); if (arraySearchByKey('numbers_only', $qidattributes, 'attribute', 1)) { $numbersonly = 'onkeypress="return goodchars(event,\'0123456789.\')"'; } else { $numbersonly = ''; } if ($maxchars=arraySearchByKey('maximum_chars', $qidattributes, 'attribute', 1)) { $maxsize=$maxchars['value']; } else { $maxsize=255; } if ($textinputwidth=arraySearchByKey('text_input_width', $qidattributes, 'attribute', 1)) { $tiwidth=$textinputwidth['value']; } else { $tiwidth=20; } if ($prefix=arraySearchByKey('prefix', $qidattributes, 'attribute', 1)) { $prefix = $prefix['value']; } else { $prefix = ''; } if ($suffix=arraySearchByKey('suffix', $qidattributes, 'attribute', 1)) { $suffix = $suffix['value']; } else { $suffix = ''; } if (arraySearchByKey('random_order', $qidattributes, 'attribute', 1)) { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random(); } else { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, answer"; } $ansresult = db_execute_assoc($ansquery); //Checked $anscount = $ansresult->RecordCount()*2; //$answer .= "\t\t\t\t\t\n"; $fn = 1; $answer_main = ''; $label_width = 0; if ($anscount==0) { $inputnames=array(); $answer_main .= '
  • '.$clang->gT('Error: This question has no answers.')."
  • \n"; } else { while ($ansrow = $ansresult->FetchRow()) { $myfname = $ia[1].$ansrow['code']; if ($ansrow['answer'] == "") {$ansrow['answer'] = " ";} $answer_main .= "\t
  • \n" . "\t\t\n" . "\t\t\t\n\t\t\t\t".$prefix."\n\t\t\t\t".''."\n\t\t\t\t".$suffix."\n\t\t\t\n" . "\t
  • \n"; // --> END NEW FEATURE - SAVE $fn++; $inputnames[]=$myfname; } } $answer .= "
      \n".$answer_main."
    \n"; return array($answer, $inputnames); } // --------------------------------------------------------------- function do_multiplenumeric($ia) { global $dbprefix, $clang, $js_header_includes, $css_header_includes; $qidattributes=getQuestionAttributes($ia[0]); $answer=''; //Must turn on the "numbers only javascript" $numbersonly = 'onkeypress="return goodchars(event,\'0123456789.\')"'; if ($maxchars=arraySearchByKey('maximum_chars', $qidattributes, 'attribute', 1)) { $maxsize=$maxchars['value']; } else { $maxsize = 255; } //EQUALS VALUE if ($equalvalue=arraySearchByKey('equals_num_value', $qidattributes, 'attribute', 1)) { $equals_num_value=$equalvalue['value']; $numbersonlyonblur[]='calculateValue'.$ia[1].'(3)'; $calculateValue[]=3; } elseif ($equalvalue=arraySearchByKey('num_value_equals_sgqa', $qidattributes, 'attribute', 1)) { $equals_num_value=$_SESSION[$equalvalue['value']]; $numbersonlyonblur[]='calculateValue'.$ia[1].'(3)'; $calculateValue[]=3; } else { $equals_num_value[]=0; } //MIN VALUE if ($minvalue=arraySearchByKey('min_num_value', $qidattributes, 'attribute', 1)) { $min_num_value=$minvalue['value']; $numbersonlyonblur[]='calculateValue'.$ia[1].'(2)'; $calculateValue[]=2; } elseif ($minvalue=arraySearchByKey('min_num_value_sgqa', $qidattributes, 'attribute', 1)) { $min_num_value=$_SESSION[$minvalue['value']]; $numbersonlyonblur[]='calculateValue'.$ia[1].'(2)'; $calculateValue[]=2; } else { $min_num_value=0; } //MAX VALUE if ($maxvalue=arraySearchByKey('max_num_value', $qidattributes, 'attribute', 1)) { $max_num_value = $maxvalue['value']; $numbersonlyonblur[]='calculateValue'.$ia[1].'(1)'; $calculateValue[]=1; } elseif ($maxvalue=arraySearchByKey('max_num_value_sgqa', $qidattributes, 'attribute', 1)) { $max_num_value = $_SESSION[$maxvalue['value']]; $numbersonlyonblur[]='calculateValue'.$ia[1].'(1)'; $calculateValue[]=1; } else { $max_num_value = 0; } if ($prefix=arraySearchByKey('prefix', $qidattributes, 'attribute', 1)) { $prefix = $prefix['value']; } else { $prefix = ''; } if ($suffix=arraySearchByKey('suffix', $qidattributes, 'attribute', 1)) { $suffix = $suffix['value']; } else { $suffix = ''; } if(!empty($numbersonlyonblur)) { $numbersonly .= ' onblur="'.implode(';', $numbersonlyonblur).'"'; $numbersonly_slider = implode(';', $numbersonlyonblur); } else { $numbersonly_slider = ''; } if ($maxchars=arraySearchByKey('text_input_width', $qidattributes, 'attribute', 1)) { $tiwidth=$maxchars['value']; } else { $tiwidth=10; } if (arraySearchByKey('slider_layout', $qidattributes, 'attribute', 1)) { $slider_layout=true; $css_header_includes[]= '/scripts/jquery/css/start/jquery-ui-1.7.1.custom.css'; $slider_accuracy=arraySearchByKey('slider_accuracy', $qidattributes, 'attribute', 1); if (isset($slider_accuracy['value'])) { //$slider_divisor = 1 / $slider_accuracy['value']; $decimnumber = strlen($slider_accuracy['value']) - strpos($slider_accuracy['value'],'.') -1; $slider_divisor = pow(10,$decimnumber); $slider_stepping = $slider_accuracy['value'] * $slider_divisor; // error_log('acc='.$slider_accuracy['value']." div=$slider_divisor stepping=$slider_stepping"); } else { $slider_divisor = 1; $slider_stepping = 1; } $slider_min=arraySearchByKey('slider_min', $qidattributes, 'attribute', 1); if (isset($slider_min['value'])) { $slider_min = $slider_min['value'] * $slider_divisor; } else { $slider_min = 0; } $slider_max=arraySearchByKey('slider_max', $qidattributes, 'attribute', 1); if (isset($slider_max['value'])) { $slider_max = $slider_max['value'] * $slider_divisor; } else { $slider_max = 100 * $slider_divisor; } $slider_default=arraySearchByKey('slider_default', $qidattributes, 'attribute', 1); if (isset($slider_default['value'])) { $slider_default = $slider_default['value']; } else { $slider_default = ''; } } else { $slider_layout = false; } if ($hidetip=arraySearchByKey('hide_tip', $qidattributes, 'attribute', 1)) { $hidetip=$hidetip['value']; } elseif ($slider_layout === true) // auto hide tip when using sliders { $hidetip=1; } else { $hidetip=0; } if (arraySearchByKey('random_order', $qidattributes, 'attribute', 1)) { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random(); } else { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, answer"; } $ansresult = db_execute_assoc($ansquery); //Checked $anscount = $ansresult->RecordCount()*2; //$answer .= "\t\t\t\t\t\n"; $fn = 1; $answer_main = ''; if ($anscount==0) { $inputnames=array(); $answer_main .= '
  • '.$clang->gT('Error: This question has no answers.')."
  • \n"; } else { $label_width = 0; while ($ansrow = $ansresult->FetchRow()) { $myfname = $ia[1].$ansrow['code']; if ($ansrow['answer'] == "") {$ansrow['answer'] = " ";} $answer_main .= "\t
  • \n\t\t\n"; if($label_width < strlen(trim(strip_tags($ansrow['answer'])))) { $label_width = strlen(trim(strip_tags($ansrow['answer']))); } if ($slider_layout === false) { $answer_main .= "\t\t\n\t\t\t".$prefix."\n\t\t\t\n\t\t\t".$suffix."\n\t\t\n\t
  • \n"; // --> END NEW FEATURE - SAVE } else { $js_header_includes[] = '/scripts/jquery/jquery-ui.js'; $js_header_includes[] = '/scripts/jquery/lime-slider.js'; if (isset($_SESSION[$myfname]) && $_SESSION[$myfname] != '') { $slider_startvalue = $_SESSION[$myfname] * $slider_divisor; } elseif ($slider_default != "") { $slider_startvalue = $slider_default * $slider_divisor; } else { $slider_startvalue = 'NULL'; } $answer_main .= "\t\t
    \n" . "\t\t\t\n" . "\t\t\t\n" . "\t\t\t\n" . "\t\t\t\n" . "\t\t\t\n" . "\t\t\t\n" . "\t\t\t\n" . "\t\t\t\n" . "\t\t\t
    \n" . "\t\t\t\t
    \n" . "\t\t\t\t
    \n" . "\t\t\t
    \n" . "\t\t
    \n" . "\t\t\n" . "\t\n"; } // $answer .= "\t\t\t\t\t\t\t\n"; $fn++; $inputnames[]=$myfname; } $question_tip = ''; if($hidetip == 0) { $question_tip .= '

    '.$clang->gT('Only numbers may be entered in these fields')."

    \n"; } if ($maxvalue) { $question_tip .= '

    '.sprintf($clang->gT('Total of all entries must not exceed %d'), $max_num_value)."

    \n"; } if ($equalvalue) { $question_tip .= '

    '.sprintf($clang->gT('Total of all entries must equal %d'),$equals_num_value)."

    \n"; } if ($minvalue) { $question_tip .= '

    '.sprintf($clang->gT('Total of all entries must be at least %s'),$min_num_value)."

    \n"; } if ($maxvalue || $equalvalue || $minvalue) { $answer_computed = ''; if ($equalvalue) { $answer_computed .= "\t
  • \n\t\t\n\t\t\n\t\t\t$prefix\n\t\t\t\n\t\t\t$suffix\n\t\t\n\t
  • \n"; } $answer_computed .= "\t
  • \n\t\t\n\t\t\n\t\t\t$prefix\n\t\t\t\n\t\t\t$suffix\n\t\t\n\t
  • \n"; $answer_main.=$answer_computed; } $answer .= $question_tip."
      \n".$answer_main."
    \n"; } //just added these here so its easy to change in one place $errorClass = 'tip problem'; $goodClass = 'tip good'; /* ================================== Style to be applied to all templates. .numeric-multi p.tip.error { color: #f00; } .numeric-multi p.tip.good { color: #0f0; } */ if ($maxvalue || $equalvalue || $minvalue) { //Do value validation $answer .= '\n"; $answer .= '\n"; $answer .= "\n"; } return array($answer, $inputnames); } // --------------------------------------------------------------- function do_numerical($ia) { global $clang; $qidattributes=getQuestionAttributes($ia[0]); if ($prefix=arraySearchByKey("prefix", $qidattributes, "attribute", 1)) { $prefix = $prefix['value']; } else { $prefix = ''; } if ($suffix=arraySearchByKey('suffix', $qidattributes, 'attribute', 1)) { $suffix = $suffix['value']; } else { $suffix = ''; } if ($maxchars=arraySearchByKey('maximum_chars', $qidattributes, 'attribute', 1)) { $maxsize=$maxchars['value']; if ($maxsize>20) { $maxsize=20; } } else { $maxsize=20; // The field length for numerical fields is 20 } if ($maxchars=arraySearchByKey('text_input_width', $qidattributes, 'attribute', 1)) { $tiwidth=$maxchars['value']; } else { $tiwidth=10; } // --> START NEW FEATURE - SAVE $answer = "

    \n\t$prefix\n\t\n\t$suffix\n

    \n" . "

    ".$clang->gT('Only numbers may be entered in this field')."

    \n"; // --> END NEW FEATURE - SAVE $inputnames[]=$ia[1]; $mandatory=null; return array($answer, $inputnames, $mandatory); } // --------------------------------------------------------------- function do_shortfreetext($ia) { $qidattributes=getQuestionAttributes($ia[0]); if ($maxchars=arraySearchByKey('maximum_chars', $qidattributes, 'attribute', 1)) { $maxsize=$maxchars['value']; } else { $maxsize=255; } if ($maxchars=arraySearchByKey('text_input_width', $qidattributes, 'attribute', 1)) { $tiwidth=$maxchars['value']; } else { $tiwidth=50; } if ($prefix=arraySearchByKey('prefix', $qidattributes, 'attribute', 1)) { $prefix = $prefix['value']; } else { $prefix = ''; } if ($suffix=arraySearchByKey('suffix', $qidattributes, 'attribute', 1)) { $suffix = $suffix['value']; } else { $suffix = ''; } // --> START NEW FEATURE - SAVE $answer = "

    \n\t$prefix\n\t\n\t$suffix\n

    \n"; // --> END NEW FEATURE - SAVE $inputnames[]=$ia[1]; return array($answer, $inputnames); } // --------------------------------------------------------------- function do_longfreetext($ia) { $qidattributes=getQuestionAttributes($ia[0]); if ($maxchars=arraySearchByKey('maximum_chars', $qidattributes, 'attribute', 1)) { $maxsize=$maxchars['value']; } else { $maxsize=65525; } // --> START ENHANCEMENT - DISPLAY ROWS if ($displayrows=arraySearchByKey('display_rows', $qidattributes, 'attribute', 1)) { $drows=$displayrows['value']; } else { $drows=5; } // <-- END ENHANCEMENT - DISPLAY ROWS // --> START ENHANCEMENT - TEXT INPUT WIDTH if ($maxchars=arraySearchByKey('text_input_width', $qidattributes, 'attribute', 1)) { $tiwidth=$maxchars['value']; } else { $tiwidth=40; } // <-- END ENHANCEMENT - TEXT INPUT WIDTH $answer = "\n"; // --> START ENHANCEMENT - DISPLAY ROWS // --> START ENHANCEMENT - TEXT INPUT WIDTH // --> START NEW FEATURE - SAVE $answer .= '\n"; $inputnames[]=$ia[1]; return array($answer, $inputnames); } // --------------------------------------------------------------- function do_hugefreetext($ia) { $qidattributes=getQuestionAttributes($ia[0]); if ($maxchars=arraySearchByKey('maximum_chars', $qidattributes, 'attribute', 1)) { $maxsize=$maxchars['value']; } else { $maxsize=65525; } // --> START ENHANCEMENT - DISPLAY ROWS if ($displayrows=arraySearchByKey('display_rows', $qidattributes, 'attribute', 1)) { $drows=$displayrows['value']; } else { $drows=30; } // <-- END ENHANCEMENT - DISPLAY ROWS // --> START ENHANCEMENT - TEXT INPUT WIDTH if ($maxchars=arraySearchByKey('text_input_width', $qidattributes, 'attribute', 1)) { $tiwidth=$maxchars['value']; } else { $tiwidth=70; } // <-- END ENHANCEMENT - TEXT INPUT WIDTH $answer = "\n"; // --> START ENHANCEMENT - DISPLAY ROWS // --> START ENHANCEMENT - TEXT INPUT WIDTH // --> START NEW FEATURE - SAVE $answer .= '\n"; $inputnames[]=$ia[1]; return array($answer, $inputnames); } // --------------------------------------------------------------- function do_yesno($ia) { global $shownoanswer, $clang; $answer = "
      \n" . "\t
    • \n\t\t START NEW FEATURE - SAVE $answer .= " onclick=\"checkconditions(this.value, this.name, this.type)" . quexs_submit_on_click() . "\" />\n\t\t\n\t
    • \n" . "\t
    • \n\t\t END NEW FEATURE - SAVE if ($_SESSION[$ia[1]] == 'N') { $answer .= CHECKED; } // --> START NEW FEATURE - SAVE $answer .= " onclick=\"checkconditions(this.value, this.name, this.type)" . quexs_submit_on_click() . "\" />\n\t\t\n\t
    • \n"; // --> END NEW FEATURE - SAVE if ($ia[6] != 'Y' && $shownoanswer == 1) { $answer .= "\t
    • \n\t\t START NEW FEATURE - SAVE $answer .= " onclick=\"checkconditions(this.value, this.name, this.type)" . quexs_submit_on_click() . "\" />\n\t\t\n\t
    • \n"; // --> END NEW FEATURE - SAVE } $answer .= "
    \n\n\n"; $inputnames[]=$ia[1]; return array($answer, $inputnames); } // --------------------------------------------------------------- function do_gender($ia) { global $shownoanswer, $clang; $qidattributes=getQuestionAttributes($ia[0]); /* This can (and should) now be done by CSS rather than using tables. if ($displaycols=arraySearchByKey('display_columns', $qidattributes, 'attribute', 1)) { $dcols=$displaycols['value']; } else { $dcols=0; } */ $answer = "
      \n" . "\t
    • \n" . ' START NEW FEATURE - SAVE $answer .= " onclick=\"checkconditions(this.value, this.name, this.type)" . quexs_submit_on_click() . "\" />\n" . ' \n\t
    • \n"; /* columns now done by CSS if ($dcols > 1 ) //Break into columns - don't need any detailed calculations becauase there's only ever 2 possible columns { $answer .= "\n\n"; } else { $answer .= "
      \n"; } */ $answer .= "\t
    • \n\t\t END NEW FEATURE - SAVE if ($_SESSION[$ia[1]] == 'M') { $answer .= CHECKED; } // --> START NEW FEATURE - SAVE $answer .= " onclick=\"checkconditions(this.value, this.name, this.type)" . quexs_submit_on_click() . "\" />\n\t\t\n\t
    • \n"; // --> END NEW FEATURE - SAVE if ($ia[6] != 'Y' && $shownoanswer == 1) { /* columns now done by CSS if ($dcols > 2) { $answer .= "\n\n"; } elseif ($dcols > 1) { $answer .= "\n\n"; } else { $answer .= "
      "; } */ $answer .= "\t
    • \n\t\t START NEW FEATURE - SAVE $answer .= " onclick=\"checkconditions(this.value, this.name, this.type)" . quexs_submit_on_click() . "\" />\n\t\t\n\t
    • \n"; // --> END NEW FEATURE - SAVE } $answer .= "
    \n\n\n"; $inputnames[]=$ia[1]; return array($answer, $inputnames); } // --------------------------------------------------------------- /** * DONE: well-formed valid HTML is appreciated * Enter description here... * @param $ia * @return unknown_type */ function do_array_5point($ia) { global $dbprefix, $shownoanswer, $notanswered, $thissurvey, $clang; $qidattributes=getQuestionAttributes($ia[0]); $qAttrib=getQAttributes($ia[0]); // if ($answerwidth=arraySearchByKey('answer_width', $qidattributes, 'attribute', 1)) // { // $answerwidth=$answerwidth['value']; // } // else // { // $answerwidth = 20; // } if (isset($qAttrib['answer_width'])) { $answerwidth=$qAttrib['answer_width']; } else { $answerwidth = 20; } $cellwidth = 5; // number of columns if ($ia[6] != 'Y' && $shownoanswer == 1) //Question is not mandatory { ++$cellwidth; // add another column } $cellwidth = round((( 100 - $answerwidth ) / $cellwidth) , 1); // convert number of columns to percentage of table width $ansquery = "SELECT answer FROM {$dbprefix}answers WHERE qid=".$ia[0]." AND answer like '%|%'"; $ansresult = db_execute_assoc($ansquery); //Checked if ($ansresult->RecordCount()>0) {$right_exists=true;$answerwidth=$answerwidth/2;} else {$right_exists=false;} // $right_exists is a flag to find out if there are any right hand answer parts. If there arent we can leave out the right td column //if (arraySearchByKey("random_order", $qidattributes, "attribute", 1)) if(isset($qAttrib['random_order'])) { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random(); } else { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, answer"; } $ansresult = db_execute_assoc($ansquery); //Checked $anscount = $ansresult->RecordCount(); $fn = 1; $answer = "\n\n\n" . "\t\n" . "\t\n"; $odd_even = ''; for ($xc=1; $xc<=5; $xc++) { $odd_even = alternation($odd_even); $answer .= "\t\t\n"; } if ($ia[6] != 'Y' && $shownoanswer == 1) //Question is not mandatory { $odd_even = alternation($odd_even); $answer .= "\t\t\n"; } $answer .= "\t\n\n" . "\t\n\t\t\n" . "\t\t\t\n"; for ($xc=1; $xc<=5; $xc++) { $answer .= "\t\t\t\n"; } if ($right_exists) {$answer .= "\t\t\t\n";} if ($ia[6] != 'Y' && $shownoanswer == 1) //Question is not mandatory { $answer .= "\t\t\t\n"; } $answer .= "\t\t\n"; $answer_t_content = ''; $trbc = ''; $n=0; //return array($answer, $inputnames); while ($ansrow = $ansresult->FetchRow()) { //echo $ansrow."--------------"; $myfname = $ia[1].$ansrow['code']; $answertext=answer_replace($ansrow['answer']); if (strpos($answertext,'|')) {$answertext=substr($answertext,0,strpos($answertext,'|'));} /* Check if this item has not been answered: the 'notanswered' variable must be an array, containing a list of unanswered questions, the current question must be in the array, and there must be no answer available for the item in this session. */ if ((is_array($notanswered)) && (array_search($ia[1], $notanswered) !== FALSE) && ($_SESSION[$myfname] == '') ) { $answertext = "{$answertext}"; } $trbc = alternation($trbc , 'row'); $htmltbody2 = ''; //if (($htmltbody=arraySearchByKey('array_filter', $qidattributes, 'attribute', 1) && $thissurvey['format'] == 'G' && getArrayFiltersOutGroup($ia[0]) == false) || ($htmltbody=arraySearchByKey('array_filter', $qidattributes, 'attribute', 1) && $thissurvey['format'] == 'A')) if((isset($qAttrib['array_filter']) && $thissurvey['format'] == 'G' && getArrayFiltersOutGroup($ia[0]) == false) || (isset($qAttrib['array_filter']) && $thissurvey['format'] == 'A')) { $htmltbody2 = "\t\n\n\t\n\t\t\t\n"; $hiddenfield = ""; } elseif ((isset($qAttrib['array_filter']) && $thissurvey['format'] == 'S') || (isset($qAttrib['array_filter']) && $thissurvey['format'] == 'G' && getArrayFiltersOutGroup($ia[0]) == true)) { $selected = getArrayFiltersForQuestion($ia[0]); if (!in_array($ansrow['code'],$selected)) { $htmltbody2 = "\t\n\n\t\n\t\t\t\n"; $hiddenfield = ""; $_SESSION[$myfname] = ''; } else { $htmltbody2 = "\t\n\n\t\n\t\t\t\n"; $hiddenfield = ""; } } else { $htmltbody2 = "\t\n\n\t\n\t\t\t\n"; $hiddenfield = ""; } $answer_t_content .= $htmltbody2; $answer_t_content .= "\t\t\n" . "\t\t\t\n"; for ($i=1; $i<=5; $i++) { $answer_t_content .= "\t\t\t\n"; } $answertext2=answer_replace($ansrow['answer']); if (strpos($answertext2,'|')) { $answertext2=substr($answertext2,strpos($answertext2,'|')+1); $answer_t_content .= "\t\t\t\n"; } elseif ($right_exists) { $answer_t_content .= "\t\t\t\n"; } if ($ia[6] != 'Y' && $shownoanswer == 1) { $answer_t_content .= "\t\t\t\n"; } $answer_t_content .= "\t\t\n\n\t"; $fn++; $inputnames[]=$myfname; } $answer .= $answer_t_content . "\t\t\t
     $xc ".$clang->gT('No answer')."
    \n\t\t\t\t$answertext\n" . $hiddenfield . "\t\t\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t$answertext2 \n\t\t\t\t\n\t\t\t
    \n"; return array($answer, $inputnames); } // --------------------------------------------------------------- /** * DONE: well-formed valid HTML is appreciated * Enter description here... * @param $ia * @return unknown_type */ function do_array_10point($ia) { global $dbprefix, $shownoanswer, $notanswered, $thissurvey, $clang; $qquery = "SELECT other FROM {$dbprefix}questions WHERE qid=".$ia[0]." AND language='".$_SESSION['s_lang']."'"; $qresult = db_execute_assoc($qquery); //Checked while($qrow = $qresult->FetchRow()) {$other = $qrow['other'];} $qidattributes=getQuestionAttributes($ia[0]); if ($answerwidth=arraySearchByKey("answer_width", $qidattributes, "attribute", 1)) { $answerwidth = $answerwidth['value']; } else { $answerwidth = 20; } $cellwidth = 10; // number of columns if ($ia[6] != 'Y' && $shownoanswer == 1) //Question is not mandatory { ++$cellwidth; // add another column } $cellwidth = round((( 100 - $answerwidth ) / $cellwidth) , 1); // convert number of columns to percentage of table width if (arraySearchByKey("random_order", $qidattributes, "attribute", 1)) { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random(); } else { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, answer"; } $ansresult = db_execute_assoc($ansquery); //Checked $anscount = $ansresult->RecordCount(); $fn = 1; $answer = "\n\n\n" . "\t\n" . "\t\n"; $odd_even = ''; for ($xc=1; $xc<=10; $xc++) { $odd_even = alternation($odd_even); $answer .= "\t\t\n"; } if ($ia[6] != 'Y' && $shownoanswer == 1) //Question is not mandatory { $odd_even = alternation($odd_even); $answer .= "\t\t\n"; } $answer .= "\t\n\n" . "\t\n\t\t\n" . "\t\t\t\n"; for ($xc=1; $xc<=10; $xc++) { $answer .= "\t\t\t\n"; } if ($ia[6] != 'Y' && $shownoanswer == 1) //Question is not mandatory { $answer .= "\t\t\t\t\t\n"; } $answer .= "\t\t\n"; $answer_t_content = ''; $trbc = ''; while ($ansrow = $ansresult->FetchRow()) { $myfname = $ia[1].$ansrow['code']; $answertext=answer_replace($ansrow['answer']); /* Check if this item has not been answered: the 'notanswered' variable must be an array, containing a list of unanswered questions, the current question must be in the array, and there must be no answer available for the item in this session. */ if ((is_array($notanswered)) && (array_search($ia[1], $notanswered) !== FALSE) && ($_SESSION[$myfname] == "") ) { $answertext = "{$answertext}"; } $trbc = alternation($trbc , 'row'); $htmltbody2 = ""; if ($htmltbody=arraySearchByKey("array_filter", $qidattributes, "attribute", 1) && $thissurvey['format'] == "G" && getArrayFiltersOutGroup($ia[0]) == false) { $htmltbody2 = "\t\n\n\t\n\t\t"; $hiddenfield = ""; } else if (($htmltbody=arraySearchByKey("array_filter", $qidattributes, "attribute", 1) && $thissurvey['format'] == "S") || ($htmltbody=arraySearchByKey("array_filter", $qidattributes, "attribute", 1) && $thissurvey['format'] == "G" && getArrayFiltersOutGroup($ia[0]) == true)) { $selected = getArrayFiltersForQuestion($ia[0]); if (!in_array($ansrow['code'],$selected)) { $htmltbody2 = "\t\n\n\t\n\t\t"; $hiddenfield = ""; $_SESSION[$myfname] = ""; } else { $htmltbody2 = "\t\n\n\t\n\t\t"; $hiddenfield = ""; } } else { $htmltbody2 = "\t\n\n\t\n\t\t"; $hiddenfield = ""; } $answer_t_content .= "".$htmltbody2; $answer_t_content .= "\t\t\n" . "\t\t\t\n"; for ($i=1; $i<=10; $i++) { $answer_t_content .= "\t\t\t\n"; // --> END NEW FEATURE - SAVE } if ($ia[6] != "Y" && $shownoanswer == 1) { $answer_t_content .= "\t\t\t\n"; } $answer_t_content .= "\t\t\n"; $inputnames[]=$myfname; $fn++; } $answer .= $answer_t_content . "\t\n
     $xc".$clang->gT('No answer')."
    \n\t\t\t\t$answertext\n" . $hiddenfield . "\t\t\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t
    \n"; return array($answer, $inputnames); } // --------------------------------------------------------------- function do_array_yesnouncertain($ia) { global $dbprefix, $shownoanswer, $notanswered, $thissurvey, $clang; $qquery = "SELECT other FROM {$dbprefix}questions WHERE qid=".$ia[0]." AND language='".$_SESSION['s_lang']."'"; $qresult = db_execute_assoc($qquery); //Checked while($qrow = $qresult->FetchRow()) {$other = $qrow['other'];} $qidattributes=getQuestionAttributes($ia[0]); if ($answerwidth=arraySearchByKey('answer_width', $qidattributes, 'attribute', 1)) { $answerwidth=$answerwidth['value']; } else { $answerwidth = 20; } $cellwidth = 3; // number of columns if ($ia[6] != 'Y' && $shownoanswer == 1) //Question is not mandatory { ++$cellwidth; // add another column } $cellwidth = round((( 100 - $answerwidth ) / $cellwidth) , 1); // convert number of columns to percentage of table width if (arraySearchByKey("random_order", $qidattributes, "attribute", 1)) { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random(); } else { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, answer"; } $ansresult = db_execute_assoc($ansquery); //Checked $anscount = $ansresult->RecordCount(); $fn = 1; $answer = "\n\n" . "\t\n" . "\n\t\n"; $odd_even = ''; for ($xc=1; $xc<=3; $xc++) { $odd_even = alternation($odd_even); $answer .= "\t\t\n"; } if ($ia[6] != 'Y' && $shownoanswer == 1) //Question is not mandatory { $odd_even = alternation($odd_even); $answer .= "\t\t\n"; } $answer .= "\t\n\n" . "\t\n\t\t\n" . "\t\t\t\n" . "\t\t\t\n" . "\t\t\t\n" . "\t\t\t\n"; if ($ia[6] != 'Y' && $shownoanswer == 1) //Question is not mandatory { $answer .= "\t\t\t\n"; } $answer .= "\t\t\n\t"; $answer_t_content = ''; $htmltbody2 = ''; if ($anscount==0) { $inputnames=array(); $answer.="\t\t\t\t\t\n\t\t\n"; } else { $trbc = ''; while ($ansrow = $ansresult->FetchRow()) { $myfname = $ia[1].$ansrow['code']; $answertext=answer_replace($ansrow['answer']); /* Check if this item has not been answered: the 'notanswered' variable must be an array, containing a list of unanswered questions, the current question must be in the array, and there must be no answer available for the item in this session. */ if ((is_array($notanswered)) && (array_search($ia[1], $notanswered) !== FALSE) && ($_SESSION[$myfname] == '') ) { $answertext = "{$answertext}"; } $trbc = alternation($trbc , 'row'); if ($htmltbody=arraySearchByKey('array_filter', $qidattributes, 'attribute', 1) && $thissurvey['format'] == 'G' && getArrayFiltersOutGroup($ia[0]) == false) { $htmltbody2 = "\t\n\n\t\n\t\t"; $hiddenfield = ""; } else if (($htmltbody=arraySearchByKey('array_filter', $qidattributes, 'attribute', 1) && $thissurvey['format'] == 'S') || ($htmltbody=arraySearchByKey('array_filter', $qidattributes, 'attribute', 1) && $thissurvey['format'] == 'G' && getArrayFiltersOutGroup($ia[0]) == true)) { $selected = getArrayFiltersForQuestion($ia[0]); if (!in_array($ansrow['code'],$selected)) { $htmltbody2 = "\t\n\n\t\n\t\t"; $hiddenfield = ""; $_SESSION[$myfname] = ''; } else { $htmltbody2 = "\t\n\n\t\n\t\t"; $hiddenfield = ""; } } else { $htmltbody2 = "\t\n\n\t\n\t\t"; $hiddenfield = ""; } $answer_t_content .= $htmltbody2; $answer_t_content .= "\t\t\n" . "\t\t\t\n" . "\t\t\t\n" . "\t\t\t\n" . "\t\t\t\n"; if ($ia[6] != 'Y' && $shownoanswer == 1) { $answer_t_content .= "\t\t\t\n"; // --> END NEW FEATURE - SAVE } $answer_t_content .= "\t\t\n"; $inputnames[]=$myfname; $fn++; } } $answer .= $answer_t_content . "\t\n
     ".$clang->gT('Yes')."".$clang->gT('Uncertain')."".$clang->gT('No')."".$clang->gT('No answer')."
    ".$clang->gT('Error: This question has no answers.')."
    $answertext\n\t\t\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t\t\t\n" . "\t\t\t\t END NEW FEATURE - SAVE if (isset($_SESSION[$myfname])) { $answer_t_content .= $_SESSION[$myfname]; } $answer_t_content .= "\" />\n\t\t\t\n\t\t\t\n\t\t\t
    \n"; return array($answer, $inputnames); } /* // --------------------------------------------------------------- function do_slider($ia) { global $shownoanswer; global $dbprefix; $qidattributes=getQuestionAttributes($ia[0]); if ($defaultvalue=arraySearchByKey("default_value", $qidattributes, "attribute", 1)) { $defaultvalue=$defaultvalue['value']; } else {$defaultvalue=0;} if ($minimumvalue=arraySearchByKey("minimum_value", $qidattributes, "attribute", 1)) { $minimumvalue=$minimumvalue['value']; } else { $minimumvalue=0; } if ($maximumvalue=arraySearchByKey("maximum_value", $qidattributes, "attribute", 1)) { $maximumvalue=$maximumvalue['value']; } else { $maximumvalue=50; } if ($answerwidth=arraySearchByKey("answer_width", $qidattributes, "attribute", 1)) { $answerwidth=$answerwidth['value']; } else { $answerwidth=20; } $sliderwidth=100-$answerwidth; //Get answers $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid={$ia[0]} AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, answer"; $ansresult = db_execute_assoc($ansquery); //Checked $anscount = $ansresult->RecordCount(); //Get labels $qquery = "SELECT lid FROM {$dbprefix}questions WHERE qid=".$ia[0]." AND language='".$_SESSION['s_lang']."'"; $qresult = db_execute_assoc($qquery); //Checked while($qrow = $qresult->FetchRow()) {$lid = $qrow['lid'];} $lquery = "SELECT * FROM {$dbprefix}labels WHERE lid=$lid AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, code"; $lresult = db_execute_assoc($lquery); //Checked $answer = "\t\t\t\n"; $answer .= "\t\t\t\t\n"; $lcolspan=$lresult->RecordCount(); $lcount=1; while($lrow=$lresult->FetchRow()) { $answer .= "\n"; $lcount++; } $answer .= "\t\t\t\t\n"; $answer .="\t\t\t\t\n" . "\t\t\t\t\t\n" . "\t\t\t\t\t\n"; $answer .= "\t\t\t\t\t"; $inputnames[]=$myfname; $fn++; } $answer .="\t\t\t\t\t\n" . "\t\t\t\t\n" . "\t\t\t
    ".$lrow['title']."
    \n" . "\t\t\t\t\t\t"; $fn=1; $trbc = ''; while ($ansrow = $ansresult->FetchRow()) { //A row for each slider control $myfname = $ia[1].$ansrow['code']; $answertext=answer_replace($ansrow['answer']); $trbc = alternation($trbc , 'row'); $answer .= "\t\t\t\t
    $answertext" . "
    " . "" . "
    "; $answer .= " \n" . "\n"; $answer .= "\t\t\t\t\n" . "\t\t\t\t\n
    \n"; $inputnames[]=$ia[1]; return array($answer, $inputnames); }*/ // --------------------------------------------------------------- function do_array_increasesamedecrease($ia) { global $dbprefix, $thissurvey, $clang; global $shownoanswer; global $notanswered; $qquery = "SELECT other FROM {$dbprefix}questions WHERE qid=".$ia[0]." AND language='".$_SESSION['s_lang']."'"; $qresult = db_execute_assoc($qquery); //Checked $qidattributes=getQuestionAttributes($ia[0]); if ($answerwidth=arraySearchByKey('answer_width', $qidattributes, 'attribute', 1)) { $answerwidth=$answerwidth['value']; } else { $answerwidth = 20; } $cellwidth = 3; // number of columns if ($ia[6] != 'Y' && $shownoanswer == 1) //Question is not mandatory { ++$cellwidth; // add another column } $cellwidth = round((( 100 - $answerwidth ) / $cellwidth) , 1); // convert number of columns to percentage of table width while($qrow = $qresult->FetchRow()) { $other = $qrow['other']; } if (arraySearchByKey('random_order', $qidattributes, 'attribute', 1)) { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random(); } else { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, answer"; } $ansresult = db_execute_assoc($ansquery); //Checked $anscount = $ansresult->RecordCount(); $fn = 1; $answer = "\n\n" . "\t\n" . "\t\n"; $odd_even = ''; for ($xc=1; $xc<=3; $xc++) { $odd_even = alternation($odd_even); $answer .= "\t\t\n"; } if ($ia[6] != 'Y' && $shownoanswer == 1) //Question is not mandatory { $odd_even = alternation($odd_even); $answer .= "\t\t\n"; } $answer .= "\t\n" . "\t\n" . "\t\t\n" . "\t\t\t\n" . "\t\t\t\n" . "\t\t\t\n" . "\t\t\t\n"; if ($ia[6] != 'Y' && $shownoanswer == 1) //Question is not mandatory { $answer .= "\t\t\t\n"; } $answer .= "\t\t\n" ."\t\n"; $answer_body = ''; $trbc = ''; while ($ansrow = $ansresult->FetchRow()) { $myfname = $ia[1].$ansrow['code']; $answertext=answer_replace($ansrow['answer']); /* Check if this item has not been answered: the 'notanswered' variable must be an array, containing a list of unanswered questions, the current question must be in the array, and there must be no answer available for the item in this session. */ if ((is_array($notanswered)) && (array_search($ia[1], $notanswered) !== FALSE) && ($_SESSION[$myfname] == "") ) { $answertext = "{$answertext}"; } $trbc = alternation($trbc , 'row'); $htmltbody2 = "\n\r"; if ($htmltbody=arraySearchByKey('array_filter', $qidattributes, 'attribute', 1) && $thissurvey['format'] == "G" && getArrayFiltersOutGroup($ia[0]) == false) { $htmltbody2 = "\n\t\t\n"; } elseif( ($htmltbody=arraySearchByKey('array_filter', $qidattributes, 'attribute', 1) && $thissurvey['format'] == 'S') || ($htmltbody=arraySearchByKey('array_filter', $qidattributes, 'attribute', 1) && $thissurvey['format'] == 'G' && getArrayFiltersOutGroup($ia[0]) == true)) { $selected = getArrayFiltersForQuestion($ia[0]); if (!in_array($ansrow['code'],$selected)) { $htmltbody2 = "\n\t\t\n"; $_SESSION[$myfname] = ''; } else { $htmltbody2 = "\n\t\t"; } } $answer_body .= "".$htmltbody2; $answer_body .= "\t\t\n" . "\t\t\t\n" . "\t\t\t\n" . "\t\t\t\n" . "\t\t\t\n"; if ($ia[6] != 'Y' && $shownoanswer == 1) { $answer_body .= "\t\t\t\n"; } $answer_body .= "\t\t\n\t"; $inputnames[]=$myfname; $fn++; } $answer .= $answer_body . "\t\n
     ".$clang->gT('Increase')."".$clang->gT('Same')."".$clang->gT('Decrease')."".$clang->gT('No answer')."
    $answertext\n" . "\t\t\t\t\n" . "\t\t\t\n" . "\t\t\t\t\n" . "\t\t\t\n" . "\t\t\t\t\n" . "\t\t\t\t\n\t\t\t\n" . "\t\t\t\t\n" . "\t\t\t
    \n"; return array($answer, $inputnames); } // --------------------------------------------------------------- function do_array_flexible($ia) { global $dbprefix, $connect, $thissurvey, $clang; global $shownoanswer; global $repeatheadings; global $notanswered; global $minrepeatheadings; $qquery = "SELECT other, lid FROM {$dbprefix}questions WHERE qid=".$ia[0]." AND language='".$_SESSION['s_lang']."'"; $qresult = db_execute_assoc($qquery); //Checked while($qrow = $qresult->FetchRow()) {$other = $qrow['other']; $lid = $qrow['lid'];} $lquery = "SELECT * FROM {$dbprefix}labels WHERE lid=$lid AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, code"; $qidattributes=getQuestionAttributes($ia[0]); if ($answerwidth=arraySearchByKey('answer_width', $qidattributes, 'attribute', 1)) { $answerwidth=$answerwidth['value']; } else { $answerwidth=20; } $columnswidth=100-$answerwidth; $lresult = db_execute_assoc($lquery); //Checked if ($lresult->RecordCount() > 0) { while ($lrow=$lresult->FetchRow()) { $labelans[]=$lrow['title']; $labelcode[]=$lrow['code']; } // $cellwidth=sprintf('%02d', $cellwidth); $ansquery = "SELECT answer FROM {$dbprefix}answers WHERE qid=".$ia[0]." AND answer like '%|%' "; $ansresult = db_execute_assoc($ansquery); //Checked if ($ansresult->RecordCount()>0) {$right_exists=true;$answerwidth=$answerwidth/2;} else {$right_exists=false;} // $right_exists is a flag to find out if there are any right hand answer parts. If there arent we can leave out the right td column if (arraySearchByKey('random_order', $qidattributes, 'attribute', 1)) { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random(); } else { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, answer"; } $ansresult = db_execute_assoc($ansquery); //Checked $anscount = $ansresult->RecordCount(); $fn=1; $numrows = count($labelans); if ($ia[6] != 'Y' && $shownoanswer == 1) { ++$numrows; } if ($right_exists) { ++$numrows; } $cellwidth = round( ($columnswidth / $numrows ) , 1 ); $answer_start = "\n\n"; $answer_head = "\t\n" . "\t\t\n" . "\t\t\t\n"; foreach ($labelans as $ld) { $answer_head .= "\t\t\t\n"; } if ($right_exists) {$answer_head .= "\t\t\t\n";} if ($ia[6] != 'Y' && $shownoanswer == 1) //Question is not mandatory and we can show "no answer" { $answer_head .= "\t\t\t\n"; } $answer_head .= "\t\t\n\t\n\n\t\n"; $answer = ''; $trbc = ''; while ($ansrow = $ansresult->FetchRow()) { if (isset($repeatheadings) && $repeatheadings > 0 && ($fn-1) > 0 && ($fn-1) % $repeatheadings == 0) { if ( ($anscount - $fn + 1) >= $minrepeatheadings ) { $answer .= "\t\t\n" . "\t\t\t\n"; foreach ($labelans as $ld) { $answer .= "\t\t\t\n"; } if ($ia[6] != 'Y' && $shownoanswer == 1) //Question is not mandatory and we can show "no answer" { $answer .= "\t\t\t\n\t\t\t\n"; } $answer .= "\t\t\n"; } } $myfname = $ia[1].$ansrow['code']; $trbc = alternation($trbc , 'row'); $answertext=answer_replace($ansrow['answer']); $answertextsave=$answertext; /* Check if this item has not been answered: the 'notanswered' variable must be an array, containing a list of unanswered questions, the current question must be in the array, and there must be no answer available for the item in this session. */ if (strpos($answertext,'|')) {$answerwidth=$answerwidth/2;} if ((is_array($notanswered)) && (array_search($ia[1], $notanswered) !== FALSE) && ($_SESSION[$myfname] == '') ) { $answertext = ''.$answertext.''; } $htmltbody2 = ''; if ($htmltbody=arraySearchByKey('array_filter', $qidattributes, 'attribute', 1) && $thissurvey['format'] == 'G' && getArrayFiltersOutGroup($ia[0]) == false) { $htmltbody2 = "\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n"; $thiskey=0; foreach ($labelcode as $ld) { $answer .= "\t\t\t\n"; // --> END NEW FEATURE - SAVE $thiskey++; } if (strpos($answertextsave,'|')) { $answertext=substr($answertextsave,strpos($answertextsave,'|')+1); $answer .= "\t\t\t\n"; } elseif ($right_exists) { $answer .= "\t\t\t\n"; } if ($ia[6] != 'Y' && $shownoanswer == 1) { $answer .= "\t\t\t\n"; // --> END NEW FEATURE - SAVE } $answer .= "\t\t\n"; $inputnames[]=$myfname; //IF a MULTIPLE of flexi-redisplay figure, repeat the headings $fn++; } $answer_cols = "\t\n" ."\t\n" ; $odd_even = ''; foreach ($labelans as $c) { $odd_even = alternation($odd_even); $answer_cols .= "\t\t\n"; } if ($right_exists) { $odd_even = alternation($odd_even); $answer_cols .= "\t\t\n"; } if ($ia[6] != 'Y' && $shownoanswer == 1) //Question is not mandatory { $odd_even = alternation($odd_even); $answer_cols .= "\t\t\n"; } $answer_cols .= "\t\n"; $answer = $answer_start . $answer_cols . $answer_head .$answer . "\t\n
     ".$ld." ".$clang->gT('No answer')."
     ".$ld." ".$clang->gT('No answer')."
    \n\t\t\t\t\n"; } else if (($htmltbody=arraySearchByKey('array_filter', $qidattributes, 'attribute', 1) && $thissurvey['format'] == 'S') || ($htmltbody=arraySearchByKey('array_filter', $qidattributes, 'attribute', 1) && $thissurvey['format'] == 'G' && getArrayFiltersOutGroup($ia[0]) == true)) { $selected = getArrayFiltersForQuestion($ia[0]); if (!in_array($ansrow['code'],$selected)) { $htmltbody2 = "\t\t
    \n\t\t\t\t\n"; $_SESSION[$myfname] = ""; } else { $htmltbody2 = "\t\t
    \n\t\t\t\t\n"; } } else { $htmltbody2 = "\t\t
    \n\t\t\t\t\n"; } if (strpos($answertext,'|')) { $answertext=substr($answertext,0, strpos($answertext,'|')); } $answer .= $htmltbody2 . "\t\t\t\t$answertext\n" . "\t\t\t\t\n" . "\t\t\t\n" . "\t\t\t\t\n" . "\t\t\t$answertext \n\t\t\t\t\n\t\t\t
    \n"; } else { $answer = "\n

    ".$clang->gT('Error: The labelset used for this question is not available in this language and/or does not exist.')."

    \n"; $inputnames=''; } return array($answer, $inputnames); } // --------------------------------------------------------------- function do_array_multitext($ia) { global $dbprefix, $connect, $thissurvey, $clang; global $shownoanswer; global $repeatheadings; global $notanswered; global $minrepeatheadings; //echo "
    "; print_r($_POST); echo "
    "; $defaultvaluescript = ""; $qquery = "SELECT other, lid FROM {$dbprefix}questions WHERE qid=".$ia[0]." AND language='".$_SESSION['s_lang']."'"; $qresult = db_execute_assoc($qquery); while($qrow = $qresult->FetchRow()) {$other = $qrow['other']; $lid = $qrow['lid'];} $lquery = "SELECT * FROM {$dbprefix}labels WHERE lid=$lid AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, code"; $qidattributes=getQuestionAttributes($ia[0]); if (arraySearchByKey('numbers_only', $qidattributes, 'attribute', 1)) { $numbersonly = 'onkeypress="return goodchars(event,\'-0123456789.\')"'; } else { $numbersonly = ''; } if ($answerwidth=arraySearchByKey("answer_width", $qidattributes, "attribute", 1)) { $answerwidth=$answerwidth['value']; } else { $answerwidth=20; } if ($inputwidth=arraySearchByKey('text_input_width', $qidattributes, 'attribute', 1)) { $inputwidth = $inputwidth['value']; } else { $inputwidth = 20; } $columnswidth=100-($answerwidth*2); $lresult = db_execute_assoc($lquery); if ($lresult->RecordCount() > 0) { while ($lrow=$lresult->FetchRow()) { $labelans[]=$lrow['title']; $labelcode[]=$lrow['code']; } $numrows=count($labelans); if ($ia[6] != 'Y' && $shownoanswer == 1) {$numrows++;} $cellwidth=$columnswidth/$numrows; $cellwidth=sprintf('%02d', $cellwidth); $ansquery = "SELECT answer FROM {$dbprefix}answers WHERE qid=".$ia[0]." AND answer like '%|%'"; $ansresult = db_execute_assoc($ansquery); if ($ansresult->RecordCount()>0) { $right_exists=true; $answerwidth=$answerwidth/2; } else { $right_exists=false; } // $right_exists is a flag to find out if there are any right hand answer parts. If there arent we can leave out the right td column if (arraySearchByKey('random_order', $qidattributes, 'attribute', 1)) { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random(); } else { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, answer"; } $ansresult = db_execute_assoc($ansquery); $anscount = $ansresult->RecordCount(); $fn=1; $answer_cols = "\t\n" ."\n\t\n" ; $answer_head = "\n\t\n" . "\t\t\n" . "\t\t\t \n"; $odd_even = ''; foreach ($labelans as $ld) { $answer_head .= "\t\t\t".$ld."\n"; $odd_even = alternation($odd_even); $answer_cols .= "\t\t\n"; } if ($right_exists) { $answer_head .= "\t\t\t \n";// class=\"answertextright\" $odd_even = alternation($odd_even); $answer_cols .= "\t\t\n"; } $answer_cols .= "\n\t\n"; $answer_head .= "\t\t\n" . "\t\n" . "\n\t\n"; $answer = "\n\n" . $answer_cols . $answer_head; $trbc = ''; while ($ansrow = $ansresult->FetchRow()) { if (isset($repeatheadings) && $repeatheadings > 0 && ($fn-1) > 0 && ($fn-1) % $repeatheadings == 0) { if ( ($anscount - $fn + 1) >= $minrepeatheadings ) { $trbc = alternation($trbc , 'row'); $answer .= "\t\t\n" . "\t\t\t\n"; foreach ($labelans as $ld) { $answer .= "\t\t\t\n"; } } $myfname = $ia[1].$ansrow['code']; $answertext=answer_replace($ansrow['answer']); $answertextsave=$answertext; /* Check if this item has not been answered: the 'notanswered' variable must be an array, containing a list of unanswered questions, the current question must be in the array, and there must be no answer available for the item in this session. */ if ((is_array($notanswered)) && (array_search($ia[1], $notanswered) !== FALSE)) { //Go through each labelcode and check for a missing answer! If any are found, highlight this line $emptyresult=0; foreach($labelcode as $ld) { $myfname2=$myfname.'_'.$ld; if($_SESSION[$myfname2] == '') { $emptyresult=1; } } if ($emptyresult == 1) { $answertext = "{$answertext}"; } } $htmltbody2 = ''; if ($htmltbody=arraySearchByKey('array_filter', $qidattributes, 'attribute', 1) && $thissurvey['format'] == 'G' && getArrayFiltersOutGroup($ia[0]) == false) { $htmltbody2 = "\n\t\n\t\t\n"; } else if (($htmltbody=arraySearchByKey('array_filter', $qidattributes, 'attribute', 1) && $thissurvey['format'] == 'S') || ($htmltbody=arraySearchByKey('array_filter', $qidattributes, 'attribute', 1) && $thissurvey['format'] == 'G' && getArrayFiltersOutGroup($ia[0]) == true)) { $selected = getArrayFiltersForQuestion($ia[0]); if (!in_array($ansrow['code'],$selected)) { $htmltbody2 = "\n\t\n\t\t\n"; $_SESSION[$myfname] = ''; } else { $htmltbody2 = "\n\t\n"; } } if (strpos($answertext,'|')) {$answertext=substr($answertext,0, strpos($answertext,'|'));} $trbc = alternation($trbc , 'row'); $answer .= $htmltbody2."\t\t\n" . "\t\t\t\n"; $thiskey=0; foreach ($labelcode as $ld) { $myfname2=$myfname."_$ld"; $myfname2value = isset($_SESSION[$myfname2]) ? $_SESSION[$myfname2] : ""; $answer .= "\t\t\t\n"; $thiskey += 1; } if (strpos($answertextsave,'|')) { $answertext=substr($answertextsave,strpos($answertextsave,'|')+1); $answer .= "\t\t\t\n"; } elseif ($right_exists) { $answer .= "\t\t\t\n"; } $answer .= "\t\t\n"; //IF a MULTIPLE of flexi-redisplay figure, repeat the headings $fn++; } $answer .= "\t\n
     ".$ld."\n"; } $answer .= "\t\t
    \n" . "\t\t\t\t$answertext\n" . "\t\t\t\t\n\t\t\t\n" . "\t\t\t\t\n\t\t\t$answertext 
    \n"; } else { $answer = "\n

    ".$clang->gT('Error: The labelset used for this question is not available in this language and/or does not exist.')."

    "; $inputnames=''; } return array($answer, $inputnames); } // --------------------------------------------------------------- function do_array_multiflexi($ia) { global $dbprefix, $connect, $thissurvey, $clang; global $shownoanswer; global $repeatheadings; global $notanswered; global $minrepeatheadings; //echo '
    '; print_r($_POST); echo '
    '; $defaultvaluescript = ''; $qquery = "SELECT other, lid FROM {$dbprefix}questions WHERE qid=".$ia[0]." AND language='".$_SESSION['s_lang']."'"; $qresult = db_execute_assoc($qquery); while($qrow = $qresult->FetchRow()) {$other = $qrow['other']; $lid = $qrow['lid'];} $lquery = "SELECT * FROM {$dbprefix}labels WHERE lid=$lid AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, code"; $qidattributes=getQuestionAttributes($ia[0]); if ($maxvalue=arraySearchByKey('multiflexible_max', $qidattributes, 'attribute', 1)) { $maxvalue=$maxvalue['value']; } else { $maxvalue=10; } if ($minvalue=arraySearchByKey('multiflexible_min', $qidattributes, 'attribute', 1)) { $minvalue=$minvalue['value']; } else { if(isset($minvalue['value']) && $minvalue['value'] == 0) {$minvalue = 0;} else {$minvalue=1;} } if ($stepvalue=arraySearchByKey('multiflexible_step', $qidattributes, 'attribute', 1)) { $stepvalue=$stepvalue['value']; } else { $stepvalue=1; } $checkboxlayout=false; if (arraySearchByKey('multiflexible_checkbox', $qidattributes, 'attribute', 1)) { $minvalue=0; $maxvalue=1; $checkboxlayout=true; } if ($answerwidth=arraySearchByKey('answer_width', $qidattributes, 'attribute', 1)) { $answerwidth=$answerwidth['value']; } else { $answerwidth=20; } $columnswidth=100-($answerwidth*2); $lresult = db_execute_assoc($lquery); if ($lresult->RecordCount() > 0) { while ($lrow=$lresult->FetchRow()) { $labelans[]=$lrow['title']; $labelcode[]=$lrow['code']; } $numrows=count($labelans); if ($ia[6] != 'Y' && $shownoanswer == 1) {$numrows++;} $cellwidth=$columnswidth/$numrows; $cellwidth=sprintf('%02d', $cellwidth); $ansquery = "SELECT answer FROM {$dbprefix}answers WHERE qid=".$ia[0]." AND answer like '%|%'"; $ansresult = db_execute_assoc($ansquery); if ($ansresult->RecordCount()>0) {$right_exists=true;$answerwidth=$answerwidth/2;} else {$right_exists=false;} // $right_exists is a flag to find out if there are any right hand answer parts. If there arent we can leave out the right td column if (arraySearchByKey('random_order', $qidattributes, 'attribute', 1)) { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random(); } else { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, answer"; } $ansresult = db_execute_assoc($ansquery); $anscount = $ansresult->RecordCount(); $fn=1; $mycols = "\t\n" . "\n\t\n"; $myheader = "\n\t\n" . "\t\t\n" . "\t\t\t \n"; $odd_even = ''; foreach ($labelans as $ld) { $myheader .= "\t\t\t".$ld."\n"; $odd_even = alternation($odd_even); $mycols .= "\t\t\n"; } if ($right_exists) { $myheader .= "\t\t\t "; $odd_even = alternation($odd_even); $mycols .= "\t\t\n"; } $myheader .= "\t\t\n" . "\t\n"; $mycols .= "\t\n"; $trbc = ''; $answer = "\n\n" . $mycols . $myheader . "\n\t\n"; while ($ansrow = $ansresult->FetchRow()) { if (isset($repeatheadings) && $repeatheadings > 0 && ($fn-1) > 0 && ($fn-1) % $repeatheadings == 0) { if ( ($anscount - $fn + 1) >= $minrepeatheadings ) { $trbc = alternation($trbc , 'row'); $answer .= "\t\t\n" . "\t\t\t\n"; foreach ($labelans as $ld) { $answer .= "\t\t\t\n"; } $answer .= "\t\t\n"; } } $myfname = $ia[1].$ansrow['code']; $answertext=answer_replace($ansrow['answer']); $answertextsave=$answertext; /* Check if this item has not been answered: the 'notanswered' variable must be an array, containing a list of unanswered questions, the current question must be in the array, and there must be no answer available for the item in this session. */ if ((is_array($notanswered)) && (array_search($ia[1], $notanswered) !== FALSE)) { //Go through each labelcode and check for a missing answer! If any are found, highlight this line $emptyresult=0; foreach($labelcode as $ld) { $myfname2=$myfname.'_'.$ld; if($_SESSION[$myfname2] == "") { $emptyresult=1; } } if ($emptyresult == 1) { $answertext = ''.$answertext.''; } } $htmltbody2 = ''; $first_hidden_field = ''; if ($htmltbody=arraySearchByKey('array_filter', $qidattributes, 'attribute', 1) && $thissurvey['format'] == 'G' && getArrayFiltersOutGroup($ia[0]) == false) { $htmltbody2 = "\n\t\n"; $first_hidden_field = '\n"; // $htmltbody2 .= "\t\t" . $first_hidden_field; // This is how it used to be. I have moved $first_hidden_field into the first cell of the table so it validates. // $first_hidden_field = ''; // These two lines have been commented because they replace badly validating code. } else if (($htmltbody=arraySearchByKey('array_filter', $qidattributes, 'attribute', 1) && $thissurvey['format'] == 'S') || ($htmltbody=arraySearchByKey('array_filter', $qidattributes, 'attribute', 1) && $thissurvey['format'] == 'G' && getArrayFiltersOutGroup($ia[0]) == true)) { $selected = getArrayFiltersForQuestion($ia[0]); if (!in_array($ansrow['code'],$selected)) { $htmltbody2 = "\n\t\n"; $first_hidden_field = '\n"; // $htmltbody2 .= "\t\t" . $first_hidden_field; // This is how it used to be. I have moved $first_hidden_field into the first cell of the table so it validates. // $first_hidden_field = ''; // These two lines have been commented because they replace badly validating code. $_SESSION[$myfname] = ''; } else { $htmltbody2 = "\n\t\n"; $first_hidden_field = '\n"; // $htmltbody2 .= "\t\t" . $first_hidden_field; // This is how it used to be. I have moved $first_hidden_field into the first cell of the table so it validates. // $first_hidden_field = ''; // These two lines have been commented because they replace badly validating code. } } if (strpos($answertext,'|')) {$answertext=substr($answertext,0, strpos($answertext,'|'));} $trbc = alternation($trbc , 'row'); $answer .= $htmltbody2 . "\t\t\n" . "\t\t\t\n"; $first_hidden_field = ''; $thiskey=0; foreach ($labelcode as $ld) { if ($checkboxlayout == false) { $myfname2=$myfname."_$ld"; $answer .= "\t\t\t\n"; $thiskey++; } else { $myfname2=$myfname."_$ld"; if(isset($_SESSION[$myfname2]) && $_SESSION[$myfname2] == '1') { $myvalue = '1'; $setmyvalue = CHECKED; } else { $myvalue = '0'; $setmyvalue = ''; } $answer .= "\t\t\t\n"; $thiskey++; } } if (strpos($answertextsave,'|')) { $answertext=substr($answertextsave,strpos($answertextsave,'|')+1); $answer .= "\t\t\t\n"; } elseif ($right_exists) { $answer .= "\t\t\t\n"; } $answer .= "\t\t\n"; //IF a MULTIPLE of flexi-redisplay figure, repeat the headings $fn++; } $answer .= "\t\n
     ".$ld."
    \n" . "\t\t\t\t$answertext\n" . "\t\t\t\t" . $first_hidden_field . "\t\t\t\t\n\t\t\t\n" . "\t\t\t\t\n" // . "\t\t\t\t\n" $answer .= "" . "\t\t\t$answertext 
    \n"; } else { $answer = "\n

    ".$clang->gT('Error: The labelset used for this question is not available in this language and/or does not exist.')."

    \n"; $inputnames = ''; } return array($answer, $inputnames); } // --------------------------------------------------------------- function do_array_flexiblecolumns($ia) { global $dbprefix; global $shownoanswer; global $notanswered, $clang; $qidattributes=getQuestionAttributes($ia[0]); $qquery = "SELECT other, lid FROM {$dbprefix}questions WHERE qid=".$ia[0]." AND language='".$_SESSION['s_lang']."'"; $qresult = db_execute_assoc($qquery); //Checked while($qrow = $qresult->FetchRow()) {$other = $qrow['other']; $lid = $qrow['lid'];} $lquery = "SELECT * FROM {$dbprefix}labels WHERE lid=$lid AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, code"; $lresult = db_execute_assoc($lquery); //Checked if ($lresult->RecordCount() > 0) { while ($lrow=$lresult->FetchRow()) { $labelans[]=$lrow['title']; $labelcode[]=$lrow['code']; $labels[]=array("answer"=>$lrow['title'], "code"=>$lrow['code']); } if ($ia[6] != 'Y' && $shownoanswer == 1) { $labelcode[]=''; $labelans[]=$clang->gT('No answer'); $labels[]=array('answer'=>$clang->gT('No answer'), 'code'=>''); } if (arraySearchByKey('random_order', $qidattributes, 'attribute', 1)) { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random(); } else { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, answer"; } $ansresult = db_execute_assoc($ansquery); //Checked $anscount = $ansresult->RecordCount(); if ($anscount>0) { $fn=1; $cellwidth=$anscount; $cellwidth=round(( 50 / $cellwidth ) , 1); $answer = "\n\n\n" . "\t\n" . "\t\n"; $odd_even = ''; for( $c = 0 ; $c < $anscount ; ++$c ) { $odd_even = alternation($odd_even); $answer .= "\t\t\n"; } $answer .= "\t\n\n" . "\t\n" . "\t\t\n" . "\t\t\t\n"; while ($ansrow = $ansresult->FetchRow()) { $anscode[]=$ansrow['code']; $answers[]=answer_replace($ansrow['answer']); } $trbc = ''; $odd_even = ''; foreach ($answers as $ld) { $myfname = $ia[1].$ansrow['code']; $trbc = alternation($trbc , 'row'); /* Check if this item has not been answered: the 'notanswered' variable must be an array, containing a list of unanswered questions, the current question must be in the array, and there must be no answer available for the item in this session. */ if ((is_array($notanswered)) && (array_search($ia[1], $notanswered) !== FALSE) && ($_SESSION[$myfname] == "") ) { $ld = "{$ld}"; } $odd_even = alternation($odd_even); $answer .= "\t\t\t\n"; } unset($trbc); $answer .= "\t\t\n\t\n\n\t\n"; $ansrowcount=0; $ansrowtotallength=0; while ($ansrow = $ansresult->FetchRow()) { $ansrowcount++; $ansrowtotallength=$ansrowtotallength+strlen($ansrow['answer']); } $percwidth=100 - ($cellwidth*$anscount); foreach($labels as $ansrow) { $answer .= "\t\t\n" . "\t\t\t\n"; foreach ($anscode as $ld) { //if (!isset($trbc) || $trbc == 'array1') {$trbc = 'array2';} else {$trbc = 'array1';} $myfname=$ia[1].$ld; $answer .= "\t\t\t\n"; } unset($trbc); $answer .= "\t\t\n"; $fn++; } $answer .= "\t\n
     $ld
    {$ansrow['answer']}\n" . "\t\t\t\t\n\t\t\t
    \n"; foreach($anscode as $ld) { $myfname=$ia[1].$ld; $answer .= '\n"; $inputnames[]=$myfname; } } else { $answer = '

    '.$clang->gT('Error: There are no answers defined for this question.')."

    "; $inputnames=""; } } else { $answer = '

    '.$clang->gT('Error: The labelset used for this question is not available in this language and/or does not exist.')."

    "; $inputnames = ''; } return array($answer, $inputnames); } // --------------------------------------------------------------- function do_array_flexible_dual($ia) { global $dbprefix, $connect, $thissurvey, $clang; global $shownoanswer; global $repeatheadings; global $notanswered; global $minrepeatheadings; $inputnames=array(); $qquery = "SELECT other, lid, lid1 FROM {$dbprefix}questions WHERE qid=".$ia[0]." AND language='".$_SESSION['s_lang']."'"; $qresult = db_execute_assoc($qquery); //Checked while($qrow = $qresult->FetchRow()) {$other = $qrow['other']; $lid = $qrow['lid']; $lid1 = $qrow['lid1'];} $lquery = "SELECT * FROM {$dbprefix}labels WHERE lid=$lid AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, code"; $lquery1 = "SELECT * FROM {$dbprefix}labels WHERE lid=$lid1 AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, code"; $qidattributes=getQuestionAttributes($ia[0]); if ($useDropdownLayout=arraySearchByKey('use_dropdown', $qidattributes, 'attribute', 1)) { $useDropdownLayout = true; } else { $useDropdownLayout = false; } if ($dsheaderA=arraySearchByKey('dualscale_headerA', $qidattributes, 'attribute', 1)) { $leftheader= $dsheaderA['value']; } else { $leftheader =''; } if ($dsheaderB=arraySearchByKey('dualscale_headerB', $qidattributes, 'attribute', 1)) { $rightheader= $dsheaderB['value']; } else { $rightheader =''; } $lresult = db_execute_assoc($lquery); //Checked if ($useDropdownLayout === false && $lresult->RecordCount() > 0) { if ($answerwidth=arraySearchByKey('answer_width', $qidattributes, 'attribute', 1)) { $answerwidth=$answerwidth['value']; } else { $answerwidth=20; } $columnswidth = 100 - $answerwidth; while ($lrow=$lresult->FetchRow()) { $labelans[]=$lrow['title']; $labelcode[]=$lrow['code']; } $lresult1 = db_execute_assoc($lquery1); //Checked if ($lresult1->RecordCount() > 0) { while ($lrow1=$lresult1->FetchRow()) { $labelans1[]=$lrow1['title']; $labelcode1[]=$lrow1['code']; } } $numrows=count($labelans) + count($labelans1); if ($ia[6] != "Y" && $shownoanswer == 1) {$numrows++;} $cellwidth=$columnswidth/$numrows; $cellwidth=sprintf("%02d", $cellwidth); $ansquery = "SELECT answer FROM {$dbprefix}answers WHERE qid=".$ia[0]." AND answer like '%|%'"; $ansresult = db_execute_assoc($ansquery); //Checked if ($ansresult->RecordCount()>0) { $right_exists=true; } else { $right_exists=false; } // $right_exists is a flag to find out if there are any right hand answer parts. If there arent we can leave out the right td column if (arraySearchByKey('random_order', $qidattributes, 'attribute', 1)) { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random(); } else { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, answer"; } $ansresult = db_execute_assoc($ansquery); //Checked $anscount = $ansresult->RecordCount(); $fn=1; // unselect second scale when using "no answer" $answer = "\n"; $mycolumns = "\t\n" ."\t\n"; $myheader2 = "\n\t\t\n" . "\t\t\t \n\n"; $odd_even = ''; foreach ($labelans as $ld) { $myheader2 .= "\t\t\t".$ld."\n"; $odd_even = alternation($odd_even); $mycolumns .= "\t\t\n"; } $mycolumns .= "\t\n"; if (count($labelans1)>0) // if second label set is used { $mycolumns .= "\t\n" . "\t\n"; $myheader2 .= "\n\t\t\t \n\n"; foreach ($labelans1 as $ld) { $myheader2 .= "\t\t\t".$ld."\n"; $odd_even = alternation($odd_even); $mycolumns .= "\t\t\n"; } } $myheader2 .= "\t\t\t \n"; if ($right_exists) { $mycolumns .= "\n\t\n\n"; } else { $mycolumns .= "\n\t\n\n"; } if ($ia[6] != 'Y' && $shownoanswer == 1) //Question is not mandatory and we can show "no answer" { $myheader2 .= "\t\t\t".$clang->gT('No answer')."\n"; $odd_even = alternation($odd_even); $mycolumns .= "\t\n"; } $mycolumns .= "\t\n"; $myheader2 .= "\t\t\n"; // build first row of header if needed if ($leftheader != '' || $rightheader !='') { $myheader1 = "\t\t\n" . "\t\t\t \n" . "\t\t\t$leftheader\n"; if (count($labelans1)>0) { $myheader1 .= "\t\t\t \n" ."\t\t\t$rightheader\n"; } $myheader1 .= "\t\t\t \n"; if ($ia[6] != 'Y' && $shownoanswer == 1) { $myheader1 .= "\t\t\t \n"; } $myheader1 .= "\t\t\n"; } else { $myheader1 = ''; } $answer .= "\n\n" . $mycolumns . "\n\t\n" . $myheader1 . $myheader2 . "\n\t\n" . "\n\t\n"; $trbc = ''; while ($ansrow = $ansresult->FetchRow()) { if (isset($repeatheadings) && $repeatheadings > 0 && ($fn-1) > 0 && ($fn-1) % $repeatheadings == 0) { if ( ($anscount - $fn + 1) >= $minrepeatheadings ) { $answer .= "\t\t\t\t\n" . "\t\t\t\n"; foreach ($labelans as $ld) { $answer .= "\t\t\t\n"; // separator foreach ($labelans1 as $ld) { $answer .= "\t\t\t\n"; } } if ($ia[6] != 'Y' && $shownoanswer == 1) //Question is not mandatory and we can show "no answer" { $answer .= "\t\t\t\n"; // separator $answer .= "\t\t\t\n"; } $answer .= "\t\t\n"; } } $trbc = alternation($trbc , 'row'); $answertext=answer_replace($ansrow['answer']); $answertextsave=$answertext; $dualgroup=0; $myfname = $ia[1].$ansrow['code'].'#0'; $myfname1 = $ia[1].$ansrow['code'].'#1'; // new multi-scale-answer /* Check if this item has not been answered: the 'notanswered' variable must be an array, containing a list of unanswered questions, the current question must be in the array, and there must be no answer available for the item in this session. */ if ((is_array($notanswered)) && (array_search($ia[1], $notanswered) !== FALSE) && (($_SESSION[$myfname] == '') || ($_SESSION[$myfname1] == '')) ) { $answertext = "{$answertext}"; } $htmltbody2 = ''; $hiddenanswers=''; if ($htmltbody=arraySearchByKey('array_filter', $qidattributes, 'attribute', 1) && $thissurvey['format'] == 'G' && getArrayFiltersOutGroup($ia[0]) == false) { $htmltbody2 = "\n\t\n"; $hiddenanswers .="\t\t\n"; } else if (($htmltbody=arraySearchByKey('array_filter', $qidattributes, 'attribute', 1) && $thissurvey['format'] == 'S') || ($htmltbody=arraySearchByKey('array_filter', $qidattributes, 'attribute', 1) && $thissurvey['format'] == 'G' && getArrayFiltersOutGroup($ia[0]) == true)) { $selected = getArrayFiltersForQuestion($ia[0]); if (!in_array($ansrow['code'],$selected)) { $htmltbody2 = "\t"; $hiddenanswers .=""; $_SESSION[$myfname] = ""; } else { $htmltbody2 = "\t"; $hiddenanswers .=""; } } if (strpos($answertext,'|')) {$answertext=substr($answertext,0, strpos($answertext,'|'));} array_push($inputnames,$myfname); $answer .= $htmltbody2 . "\t\t\n" . "\t\t\t\n"; $hiddenanswers=''; $thiskey=0; foreach ($labelcode as $ld) { $answer .= "\t\t\t\n"; $thiskey++; } if (count($labelans1)>0) // if second label set is used { $dualgroup++; $hiddenanswers=''; $answer .= "\t\t\t\n"; // separator array_push($inputnames,$myfname1); $hiddenanswers .= "\t\t\t\t\n"; $thiskey=0; foreach ($labelcode1 as $ld) // second label set { $answer .= "\t\t\t\n"; $thiskey++; } } if (strpos($answertextsave,'|')) { $answertext=substr($answertextsave,strpos($answertextsave,'|')+1); $answer .= "\t\t\t\n"; $hiddenanswers = ''; } elseif ($right_exists) { $answer .= "\t\t\t\n"; } else { $answer .= "\t\t\t\n"; // separator } if ($ia[6] != "Y" && $shownoanswer == 1) { $answer .= "\t\t\t\n"; // --> END NEW FEATURE - SAVE } $answer .= "\t\t\n"; // $inputnames[]=$myfname; //IF a MULTIPLE of flexi-redisplay figure, repeat the headings $fn++; } $answer .= "\t\n
     ".$ld."\n"; } if (count($labelans1)>0) // if second label set is used { $answer .= " ".$ld." ".$clang->gT('No answer')."
    \n\t\t\t\t$answertext\n" . "\t\t\t\t\n\t\t\t\t$hiddenanswers\n\t\t\t\n" . "\t\t\t\t\n"; // --> END NEW FEATURE - SAVE $answer .= "\n\t\t\t \n"; if ($hiddenanswers!='') { $answer .=$hiddenanswers; $hiddenanswers=''; } $answer .= "\t\t\t\t\n"; // --> END NEW FEATURE - SAVE $answer .= "\t\t\t$answertext  \n" . "\t\t\t\t\n" . "\t\t\t
    \n"; } elseif ($useDropdownLayout === true && $lresult->RecordCount() > 0) { if ($answerwidth=arraySearchByKey('answer_width', $qidattributes, 'attribute', 1)) { $answerwidth=$answerwidth['value']; } else { $answerwidth=20; } $separatorwidth=(100-$answerwidth)/10; $columnswidth=100-$answerwidth-($separatorwidth*2); $answer = "\n"; // Get Answers //question atribute random_order set? if (arraySearchByKey('random_order', $qidattributes, 'attribute', 1)) { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random(); } //no question attributes -> order by sortorder else { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, answer"; } $ansresult = db_execute_assoc($ansquery); //Checked $anscount = $ansresult->RecordCount(); if ($anscount==0) { $inputnames = array(); $answer .="\n

    ".$clang->gT('Error: This question has no answers.')."

    \n"; } else { //already done $lresult = db_execute_assoc($lquery); while ($lrow=$lresult->FetchRow()) { $labels0[]=Array('code' => $lrow['code'], 'title' => $lrow['title']); } $lresult1 = db_execute_assoc($lquery1); //Checked while ($lrow1=$lresult1->FetchRow()) { $labels1[]=Array('code' => $lrow1['code'], 'title' => $lrow1['title']); } // Get attributes for Headers and Prefix/Suffix if ($ddprepostfix=arraySearchByKey("dropdown_prepostfix", $qidattributes, "attribute", 1)) { list ($ddprefix, $ddsuffix) =explode("|",$ddprepostfix['value']); $ddprefix = $ddprefix; $ddsuffix = $ddsuffix; } else { $ddprefix =''; $ddsuffix=''; } if ($ddseparators=arraySearchByKey('dropdown_separators', $qidattributes, 'attribute', 1)) { list ($postanswSep, $interddSep) =explode('|',$ddseparators['value']); $postanswSep = $postanswSep; $interddSep = $interddSep; } else { $postanswSep = ''; $interddSep = ''; } $colspan_1 = ''; $colspan_2 = ''; $suffix_cell = ''; $answer .= "\n\n\n" . "\t\n"; if($ddprefix != '') { $answer .= "\t\n"; $colspan_1 = ' colspan="2"'; } $answer .= "\t\n"; if($ddsuffix != '') { $answer .= "\t\n"; if(!empty($colspan_1)) { $colspan_2 = ' colspan="3"'; } $suffix_cell = "\t\t\t\n"; // suffix } $answer .= "\t\n"; if($ddprefix != '') { $answer .= "\t\n"; } $answer .= "\t\n"; if($ddsuffix != '') { $answer .= "\t\n"; }; // headers $answer .= "\n\t\n" . "\t\t\n" . "\t\t\t \n" // prefix . "\n" // . "\t\t\t\n" . "\t\t\t\n" . "\n" . "\t\t\t \n" // suffix // Inter DD separator // prefix // . "\t\t\t\n" . "\t\t\t\n" . $suffix_cell."\t\t\n" . "\t\n\n" . "\t\n"; $trbc = ''; while ($ansrow = $ansresult->FetchRow()) { $rowname = $ia[1].$ansrow['code']; $dualgroup=0; $myfname = $ia[1].$ansrow['code']."#".$dualgroup; $dualgroup1=1; $myfname1 = $ia[1].$ansrow['code']."#".$dualgroup1; if ((is_array($notanswered)) && (array_search($ia[1], $notanswered) !== FALSE) && ($_SESSION[$myfname] == "" || $_SESSION[$myfname1] == "") ) { $answertext="".answer_replace($ansrow['answer']).""; } else { $answertext=answer_replace($ansrow['answer']); } $trbc = alternation($trbc , 'row'); $htmltbody2 = ''; if (($htmltbody=arraySearchByKey('array_filter', $qidattributes, 'attribute', 1) && $thissurvey['format'] == 'G' && getArrayFiltersOutGroup($ia[0]) == false) || ($htmltbody=arraySearchByKey('array_filter', $qidattributes, 'attribute', 1) && $thissurvey['format'] == 'A')) { $htmltbody2 = "\n\t\n"; $hiddenanswers = "\t\t\n\t\t\n"; } else if (($htmltbody=arraySearchByKey('array_filter', $qidattributes, 'attribute', 1) && $thissurvey['format'] == 'S') || ($htmltbody=arraySearchByKey('array_filter', $qidattributes, 'attribute', 1) && $thissurvey['format'] == 'G' && getArrayFiltersOutGroup($ia[0]) == true)) { $selected = getArrayFiltersForQuestion($ia[0]); if (!in_array($ansrow['code'],$selected)) { $htmltbody2 = "\n\t\n"; $hiddenanswers="\t\t\n\t\t\n"; $_SESSION[$myfname] = ''; } else { $htmltbody2 = "\n\t"; $hiddenanswers="\n\t\t\n\t\t"; } } else { // $htmltbody2 = "\n\t\n"; $hiddenanswers=""; } $answer .= $htmltbody2."\t\t\n" . "\t\t\t\n"; // Label0 // prefix if($ddprefix != '') { $answer .= "\t\t\t\n"; } $answer .= "\t\t\t\n"; } $answer .= "\t\t\t\t\n" . "\t\t\t\n"; $inputnames[]=$myfname; $answer .= "\t\t\t\n"; //Separator // Label1 // prefix if($ddprefix != '') { $answer .= "\t\t\t\n"; } // $answer .= "\t\t\t\n"; } $answer .= "\t\t\t\t\n" . "\t\t\t\n"; $inputnames[]=$myfname1; $answer .= "\t\t\n"; } } // End there are answers $answer .= "\t\n
     
    $leftheader$leftheader$rightheader$rightheader
    \n" . "\t\t\t\t\n" . "\t\t\t$ddprefix\n" . "\t\t\t\t\n"; // suffix if($ddsuffix != '') { $answer .= "\t\t\t$ddsuffix$interddSep$ddprefix\n" $answer .= "\t\t\t\n" . "\t\t\t\t\n"; // suffix if($ddsuffix != '') { $answer .= "\t\t\t$ddsuffix
    \n\n$hiddenanswers\n"; $hiddenanswers=''; } else { $answer = ''.$clang->gT('Error: The labelset used for this question is not available in this language and/or does not exist.').""; $inputnames=""; } return array($answer, $inputnames); } // --------------------------------------------------------------- function answer_replace($text) { while (strpos($text, "{INSERTANS:") !== false) { $replace=substr($text, strpos($text, "{INSERTANS:"), strpos($text, "}", strpos($text, "{INSERTANS:"))-strpos($text, "{INSERTANS:")+1); $replace2=substr($replace, 11, strpos($replace, "}", strpos($replace, "{INSERTANS:"))-11); $replace3=retrieve_Answer($replace2); $text=str_replace($replace, $replace3, $text); } //while return $text; } // --------------------------------------------------------------- function labelset_exists($labelid,$language) { $qulabel = "SELECT * FROM ".db_table_name('labels')." WHERE lid=$labelid AND language='$language'"; $tablabel = db_execute_assoc($qulabel) or safe_die("Couldn't check for labelset
    $ansquery
    ".$connect->ErrorMsg()); //Checked if ($tablabel->RecordCount()>0) {return true;} else {return false;} } ?>