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 exist for this question * $ia[8] => other questions have conditions which rely on this question (including array_filter and array_filter_exclude attributes) * $ia[9] => incremental question count (used by {QUESTION_NUMBER}) * * $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* */ if($shownoanswer > 0 && $thissurvey['shownoanswer'] != 'N') { define('SHOW_NO_ANSWER',1); } else { define('SHOW_NO_ANSWER',0); }; //queXS addition function quexs_submit_on_click($do = true) { include_once(dirname(__FILE__) . '/quexs.php'); $r = "; $('.submit').css('display', ''); "; if (LIME_AUTO_ADVANCE && $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 quexs_appointment($do) { include_once(dirname(__FILE__) . '/quexs.php'); $r = ""; if ($do) { $r = "; $('.submit').css('display', 'none'); parent.poptastic('" . QUEXS_URL . "appointment.php'); "; } return $r; } function quexs_outcome($outcome) { include_once(dirname(__FILE__) . '/quexs.php'); $r = ""; if (is_numeric($outcome) && $outcome != 0) { $r = "; $('.submit').css('display', 'none'); parent.poptastic('" . QUEXS_URL . "call.php?defaultoutcome=$outcome'); "; } return $r; } 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 c.qid, c.scenario, c.cqid, c.cfieldname, c.value, '' as type, 0 as sid, 0 as gid, c.method, q.gid as srcgid " ."FROM {$dbprefix}conditions c, {$dbprefix}questions q " ."WHERE c.qid=q.qid " ."AND c.qid=$ia[0] " ."AND c.cfieldname LIKE '{%' " ."ORDER BY c.scenario, c.cqid, c.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']); } foreach ($conditions as $condkey => $condarr) { // We need to sort the merged array by Ascending scenario, cqid, then cfieldname // otherwise condition evaluations of Tokens in Scenarii won't work in "live" Javascript eval $scenariolist[$condkey] = $condarr[7]; $cqidlist[$condkey] = $condarr[1]; $cfieldnamelist[$condkey] = $condarr[2]; } array_multisort($scenariolist,SORT_ASC,$cqidlist,SORT_ASC,$cfieldnamelist,SORT_ASC,$conditions); 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; if (preg_match("/^\+{0,1}[0-9]+X([0-9]+)X(.*)$/",$cd[2]) == 0) { // This is not a true fieldname (for instance a {TOKEN:ATTR..} // placeholder return "NoJSidname"; } //preg_match("/^[0-9]+X([0-9]+)X([0-9]+)$/",$cd[2],$matchFields); //^^^^^does not seem to work, explode below should $matchFields = explode('X', $cd[2], 3); $questiongid=$matchFields[1]; $questionFieldpart=$matchFields[2]; 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); // broken when ranking more than 9 items $idname="fvalue_".$questionFieldpart; } 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],$ia[4]); if (trim($qidattributes['max_answers'])!='') { $max_answers = $qidattributes['max_answers']; } 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']."' and parent_qid=0"; $qresult = db_execute_assoc($qquery); //Checked while ($qrow = $qresult->FetchRow()) {$other = $qrow['other'];} $subquestionquery = "SELECT title FROM {$dbprefix}questions WHERE parent_qid={$ia[0]} AND language='".$_SESSION['s_lang']."' ORDER BY question_order"; $sqresult = db_execute_assoc($subquestionquery); //Checked while ($subquestionrow = $sqresult->FetchRow()) { $mandatorys[]=$ia[1].$subquestionrow['title']; $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); } /** * 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. * * @param mixed $ia * @return array See explanation above */ function setman_multiflex($ia) { global $dbprefix, $connect; $mandatorys=array(); $mandatoryfns=array(); $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid={$ia[0]} AND language='".$_SESSION['s_lang']."' and scale_id=0 ORDER BY question_order, title"; $ansresult = db_execute_assoc($ansquery); $ans2query = "SELECT * FROM {$dbprefix}questions WHERE parent_qid={$ia[0]} AND language='".$_SESSION['s_lang']."' and scale_id=1 ORDER BY question_order, title"; $ans2result = db_execute_assoc($ans2query); while ($ans2row=$ans2result->FetchRow()) { $lset[]=$ans2row; } $qidattributes=getQuestionAttributes($ia[0],$ia[4]); while ($ansrow = $ansresult->FetchRow()) { //Don't add to mandatory list if the row is filtered out with the array_filter option if (trim($qidattributes['array_filter'])!='') { //This particular one may not be mandatory if it's hidden $selected = getArrayFiltersForQuestion($ia[0]); if (!in_array($ansrow['title'],$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['title']."_".$ls['title']; $mandatoryfns[]=$ia[1]; } } } elseif (trim($qidattributes['array_filter_exclude'])!='') { //This particular one may not be mandatory if it's hidden $selected = getArrayFilterExcludesForQuestion($ia[0]); if ($selected!=false && in_array($ansrow['title'],$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['title']."_".$ls['title']; $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['title']."_".$ls['title']; $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']; } // Get Subquestions $subquery="SELECT * " ."FROM {$dbprefix}questions " ."WHERE parent_qid={$ia[0]} " ."AND language='".$_SESSION['s_lang']."' " ."ORDER BY question_order"; $subresult = db_execute_assoc($subquery); //Checked // Get Answer Scale 1 $ans1query="SELECT qid " ."FROM {$dbprefix}answers " ."WHERE qid={$ia[0]} " ."AND scale_id=0 " ."AND language='".$_SESSION['s_lang']."' " ."ORDER BY sortorder"; $ans1result = db_execute_assoc($ans1query); //Checked $ans1count = $ans1result->RowCount(); // Get Answer Scale 2 $ans2query="SELECT qid " ."FROM {$dbprefix}answers " ."WHERE qid={$ia[0]} " ."AND scale_id=1 " ."AND language='".$_SESSION['s_lang']."' " ."ORDER BY sortorder"; $ans2result = db_execute_assoc($ans2query); //Checked $ans2count = $ans2result->RowCount(); while ($subrow = $subresult->FetchRow()) { // first answer set if ($ans1count > 0) { $mandatorys[]=$ia[1].$subrow['title']."#0"; $mandatoryfns[]=$ia[1]; } else { $mandatorys[]=$ia[1].$subrow['title']; $mandatoryfns[]=$ia[1]; } // second answer set if ($ans2count > 0) { $mandatorys[]=$ia[1].$subrow['title']."#1"; $mandatoryfns[]=$ia[1]; } else { $mandatorys[]=$ia[1].$subrow['title']; $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); } /** * 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 * * @param mixed $ia * @param mixed $notanswered * @param mixed $notvalidated * @param mixed $filenotvalidated * @return mixed */ function retrieveAnswers($ia, $notanswered=null, $notvalidated=null, $filenotvalidated=null) { //globalise required config variables global $dbprefix, $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; $qtitle=dTexts::run($qtitle); //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],$ia[4]); //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. $number = isset($ia[9]) ? $ia[9] : ''; $question_text = array( 'all' => '' // All has been added for backwards compatibility with templates that use question_start.pstpl (now redundant) ,'text' => $qtitle ,'code' => $ia[2] ,'number' => $number ,'help' => '' ,'mandatory' => '' ,'man_message' => '' ,'valid_message' => '' ,'file_valid_message' => '' ,'class' => '' ,'man_class' => '' ,'input_error_class' => ''// provides a class. ,'essentials' => '' ); 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 'L': //LIST drop-down/radio-button list $values = do_list_radio($ia); if ($qidattributes['hide_tip']==0) { $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 ($qidattributes['hide_tip']==0) { $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 && $qidattributes['hide_tip']==0) { $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 && $qidattributes['hide_tip']==0) { $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 (trim($qidattributes['min_answers'])!='') { $qtitle .= "
\n" . sprintf($clang->ngT("Check at least %d item","Check at least %d items",$qidattributes['min_answers']),$qidattributes['min_answers']).""; $question_text['help'] .=' '.sprintf($clang->ngT("Check at least %d item","Check at least %d items",$qidattributes['min_answers']),$qidattributes['min_answers']); } } break; case 'M': //Multiple choice checkbox $values=do_multiplechoice($ia); if (count($values[1]) > 1 && $qidattributes['hide_tip']==0) { $maxansw=trim($qidattributes['max_answers']); $minansw=trim($qidattributes['min_answers']); 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, $maxansw).""; $question_text['help'] = sprintf($clang->gT("Check between %d and %d answers"), $minansw, $maxansw); } elseif ($maxansw) { $qtitle .= "
\n" . sprintf($clang->gT("Check at most %d answers"), $maxansw).""; $question_text['help'] = sprintf($clang->gT("Check at most %d answers"), $maxansw); } else { $qtitle .= "
\n" . sprintf($clang->ngT("Check at least %d answer","Check at least %d answers",$minansw),$minansw).""; $question_text['help'] = sprintf($clang->ngT("Check at least %d answer","Check at least %d answers",$minansw),$minansw); } } } 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 choice with comments checkbox + text $values=do_multiplechoice_withcomments($ia); if (count($values[1]) > 1 && $qidattributes['hide_tip']==0) { $maxansw=trim($qidattributes["max_answers"]); $minansw=trim($qidattributes["min_answers"]); 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, $maxansw).""; $question_text['help'] = sprintf($clang->gT("Check between %d and %d answers"), $minansw, $maxansw); } elseif ($maxansw) { $qtitle .= "
\n" . sprintf($clang->gT("Check at most %d answers"), $maxansw).""; $question_text['help'] = sprintf($clang->gT("Check at most %d answers"), $maxansw); } else { $qtitle .= "
\n" . sprintf($clang->gT("Check at least %d answers"), $minansw).""; $question_text['help'] = sprintf($clang->gT("Check at least %d answers"), $minansw); } } } break; case '|': //File Upload $values=do_file_upload($ia); if ($qidattributes['min_num_of_files'] != 0) { if (trim($qidattributes['min_num_of_files']) != 0) { $qtitle .= "
\n" .sprintf($clang->gT("At least %d files must be uploaded for this question"), $qidattributes['min_num_of_files']).""; $question_text['help'] .= ' '.sprintf($clang->gT("At least %d files must be uploaded for this question"), $qidattributes['min_num_of_files']); } } 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($ia); break; case 'H': //ARRAY (Flexible) - Column Format $values=do_arraycolumns($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_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\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); $qtitle .= $ia[4] == "|" ? file_validation_message($ia) : ""; $question_text['file_valid_message'] = $ia[4] == "|" ? file_validation_message($ia) : ""; if(!empty($question_text['man_message']) || !empty($question_text['valid_message']) || !empty($question_text['file_valid_message'])) { $question_text['input_error_class'] = ' input-error';// provides a class to style question wrapper differently if there is some kind of user input error; } // ===================================================== // START: legacy question_start.pstpl code // The following section adds to the templating system by allowing // templaters to control where the various parts of the question text // are put. if(is_file('templates/'.validate_templatedir($thissurvey['template']).'/question_start.pstpl')) { $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(sGetTemplatePath($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; $question_text['all'] = $qtitle_custom; } else { $question_text['all'] = $qtitle; }; // END: legacy question_start.pstpl code //=================================================================== // echo '
[qanda.php] line '.__LINE__.": $question_text =\n".htmlspecialchars(print_r($question_text,true)).'
'; $qtitle = $question_text; // ===================================================== $qanda=array($qtitle, $answer, $help, $display, $name, $ia[2], $gl[0], $ia[1] ); //New Return return array($qanda, $inputnames); } 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],$ia[4]); if (trim($qidattributes['other_replace_text'])!='') { $othertext=$qidattributes['other_replace_text']; } 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 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 file_validation_message($ia) { global $filenotvalidated, $clang; $qtitle = ""; if (isset($filenotvalidated) && is_array($filenotvalidated) && $ia[4] == "|") { global $filevalidationpopup, $popup; foreach ($filenotvalidated as $k => $v) { if ($ia[1] == $k || strpos($k, "_") && $ia[1] == substr(0, strpos($k, "_") - 1)); $qtitle .= '
'.$clang->gT($filenotvalidated[$k]).'
'; } } 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; } } function file_validation_popup($ia, $filenotvalidated = null) { global $showpopups; if ($filenotvalidated === null) { unset($filenotvalidated); } if (isset($filenotvalidated) && is_array($filenotvalidated) && isset($showpopups) && $showpopups == 1) { global $filevalidationpopup, $fpopup, $clang; if (!isset($filevalidationpopup)) { $fpopup="\n"; $filevalidationpopup = "Y"; } return array($filevalidationpopup, $fpopup); } else return false; } function return_timer_script($qidattributes, $ia, $disable=null) { global $thissurvey, $clang; /* The following lines cover for previewing questions, because no $_SESSION['fieldarray'] exists. This just stops error messages occuring */ if(!isset($_SESSION['fieldarray'])) { $_SESSION['fieldarray'] = array(); } /* End */ if(isset($thissurvey['timercount'])) { $thissurvey['timercount']++; //Used to count how many timer questions in a page, and ensure scripts only load once } else { $thissurvey['timercount']=1; } if($thissurvey['format'] != "S") { if($thissurvey['format'] != "G") { return "\n\n\n\n"; //We don't do the timer in any format other than question-by-question } } $time_limit=$qidattributes['time_limit']; $disable_next=trim($qidattributes['time_limit_disable_next']) != '' ? $qidattributes['time_limit_disable_next'] : 0; $disable_prev=trim($qidattributes['time_limit_disable_prev']) != '' ? $qidattributes['time_limit_disable_prev'] : 0; $time_limit_action=trim($qidattributes['time_limit_action']) != '' ? $qidattributes['time_limit_action'] : 1; $time_limit_message_delay=trim($qidattributes['time_limit_message_delay']) != '' ? $qidattributes['time_limit_message_delay']*1000 : 1000; $time_limit_message=trim($qidattributes['time_limit_message']) != '' ? htmlspecialchars($qidattributes['time_limit_message'], ENT_QUOTES) : $clang->gT("Your time to answer this question has expired"); $time_limit_warning=trim($qidattributes['time_limit_warning']) != '' ? $qidattributes['time_limit_warning'] : 0; $time_limit_warning_2=trim($qidattributes['time_limit_warning_2']) != '' ? $qidattributes['time_limit_warning_2'] : 0; $time_limit_countdown_message=trim($qidattributes['time_limit_countdown_message']) != '' ? htmlspecialchars($qidattributes['time_limit_countdown_message'], ENT_QUOTES) : $clang->gT("Time remaining"); $time_limit_warning_message=trim($qidattributes['time_limit_warning_message']) != '' ? htmlspecialchars($qidattributes['time_limit_warning_message'], ENT_QUOTES) : $clang->gT("Your time to answer this question has nearly expired. You have {TIME} remaining."); $time_limit_warning_message=str_replace("{TIME}", "
", $time_limit_warning_message); $time_limit_warning_display_time=trim($qidattributes['time_limit_warning_display_time']) != '' ? $qidattributes['time_limit_warning_display_time']+1 : 0; $time_limit_warning_2_message=trim($qidattributes['time_limit_warning_2_message']) != '' ? htmlspecialchars($qidattributes['time_limit_warning_2_message'], ENT_QUOTES) : $clang->gT("Your time to answer this question has nearly expired. You have {TIME} remaining."); $time_limit_warning_2_message=str_replace("{TIME}", "
", $time_limit_warning_2_message); $time_limit_warning_2_display_time=trim($qidattributes['time_limit_warning_2_display_time']) != '' ? $qidattributes['time_limit_warning_2_display_time']+1 : 0; $time_limit_message_style=trim($qidattributes['time_limit_message_style']) != '' ? $qidattributes['time_limit_message_style'] : "position: absolute; top: 10px; left: 35%; width: 30%; height: 60px; padding: 16px; border: 8px solid #555; background-color: white; z-index:1002; text-align: center; overflow: auto;"; $time_limit_message_style.="\n display: none;"; //Important to hide time limit message at start $time_limit_warning_style=trim($qidattributes['time_limit_warning_style']) != '' ? $qidattributes['time_limit_warning_style'] : "position: absolute; top: 10px; left: 35%; width: 30%; height: 60px; padding: 16px; border: 8px solid #555; background-color: white; z-index:1001; text-align: center; overflow: auto;"; $time_limit_warning_style.="\n display: none;"; //Important to hide time limit warning at the start $time_limit_warning_2_style=trim($qidattributes['time_limit_warning_2_style']) != '' ? $qidattributes['time_limit_warning_2_style'] : "position: absolute; top: 10px; left: 35%; width: 30%; height: 60px; padding: 16px; border: 8px solid #555; background-color: white; z-index:1001; text-align: center; overflow: auto;"; $time_limit_warning_2_style.="\n display: none;"; //Important to hide time limit warning at the start $time_limit_timer_style=trim($qidattributes['time_limit_timer_style']) != '' ? $qidattributes['time_limit_timer_style'] : "position: relative; width: 150px; margin-left: auto; margin-right: auto; border: 1px solid #111; text-align: center; background-color: #EEE; margin-bottom: 5px; font-size: 8pt;"; $timersessionname="timer_question_".$ia[0]; if(isset($_SESSION[$timersessionname])) { $time_limit=$_SESSION[$timersessionname]; } $output = " \n"; if($thissurvey['timercount'] < 2) { $output .=" "; $output .= " "; } $output .= "
".$time_limit_message."
\n\n"; $output .= "
".$time_limit_warning_message."
\n\n"; $output .= "
".$time_limit_warning_2_message."
\n\n"; $output .= "
\n\n"; //Call the countdown script $output .= "\n\n"; return $output; } function return_array_filter_selected($ia, $qidattributes, $thissurvey, $ansrow, $rowname, $trbc='', $valuename, $method="tbody", $class=null) // function which returns TRUE if the given $ansrow contains a row which is selected, ie, not filtered out in previous answer { $filter_select = TRUE; if ( (trim($qidattributes['array_filter'])!='' && // The array filter attribute is set $thissurvey['format'] == 'S' // and the survey is being presented in question-by-question mode ) || // OR (trim($qidattributes['array_filter'])!='' && // The array filter attribute is set $thissurvey['format'] == 'G' && // and the survey is being presented in group-by-group mode getArrayFiltersOutGroup($ia[0]) == true // and the source question for the array filter is in a different group than this question ) ) { $selected = getArrayFiltersForQuestion($ia[0]); if (isset($ansrow['code'])) $ansrow['title'] = $ansrow['code']; if (!empty($selected) && !in_array($ansrow['title'],$selected)) { $filter_select = FALSE; } else { $filter_select = TRUE; } } if (isset($qidattributes['array_filter_exclude']) && ( (trim($qidattributes['array_filter_exclude'])!='' && $thissurvey['format'] == 'S' ) || (trim($qidattributes['array_filter_exclude'])!='' && $thissurvey['format'] == 'G' && getArrayFiltersExcludesOutGroup($ia[0]) == true ) ) ) { $selected = getArrayFilterExcludesForQuestion($ia[0]); if (isset($ansrow['code'])) $ansrow['title'] = $ansrow['code']; if (!empty($selected) && !in_array($ansrow['title'],$selected)) { $filter_select = TRUE; } else { $filter_select = FALSE; } } return $filter_select; } function return_array_filter_strings($ia, $qidattributes, $thissurvey, $ansrow, $rowname, $trbc='', $valuename, $method="tbody", $class=null) { /* We're just going to work out whether to do the include or exclude version of the function at this point */ if(isset($qidattributes['array_filter_exclude']) && trim($qidattributes['array_filter_exclude']) != '') { list($html2body, $hiddenfield) = return_array_filter_exclude_strings($ia, $qidattributes, $thissurvey, $ansrow, $rowname, $trbc, $valuename, $method, $class); } else { list($html2body, $hiddenfield) = return_array_filter_include_strings($ia, $qidattributes, $thissurvey, $ansrow, $rowname, $trbc, $valuename, $method, $class); } return array($html2body, $hiddenfield); } function return_array_filter_include_strings($ia, $qidattributes, $thissurvey, $ansrow, $rowname, $trbc='', $valuename, $method="tbody", $class=null) { /* DO ARRAY_FILTER ATTRIBUTE We set the $hiddenfield for each answer, and the value of this is available to java to let javascripts know whether each answer is currently being displayed. $htmltbody2 determines whether the answer row should be displayed initially. If no answers for the source question have been selected then the whole answer row should start in the display-off position for array_filter or the display-on position for array_filter_exclude. */ //Are we doing array_filter, or array_filter_exclude. Where a conflict occurs, do array_filter $htmltbody2 = ''; $hiddenfield= ''; if ( (trim($qidattributes['array_filter'])!='' && // the array_filter attribute is set $thissurvey['format'] == 'G' && // and the survey is being presented group by group getArrayFiltersOutGroup($ia[0]) == false // and the source question is in the same group (ie displayed on same page) ) || // OR (trim($qidattributes['array_filter'])!='' && // the array_filter attribute is set $thissurvey['format'] == 'A' // and the survey is being presented all on one page ) ) { $htmltbody2 = "\n\n\t<$method id='javatbd$rowname' style='display: none'"; $htmltbody2 .= ($class !== null) ? " class='$class'": ""; $htmltbody2 .= ">\n"; if($ia[4]=="1") { //This is an array dual scale question and we have to massage the tbidpslay rowname $hiddenfield = "\n"; $hiddenfield .= "\n"; } else { $hiddenfield = "\n"; } } else if ( (trim($qidattributes['array_filter'])!='' && // The array filter attribute is set $thissurvey['format'] == 'S' // and the survey is being presented in question-by-question mode ) || // OR (trim($qidattributes['array_filter'])!='' && // The array filter attribute is set $thissurvey['format'] == 'G' && // and the survey is being presented in group-by-group mode getArrayFiltersOutGroup($ia[0]) == true // and the source question for the array filter is in a different group than this question ) ) { $selected = getArrayFiltersForQuestion($ia[0]); if (isset($ansrow['code'])) $ansrow['title'] = $ansrow['code']; if (!empty($selected) && !in_array($ansrow['title'],$selected)) { $htmltbody2 = "\n\n\t<$method id='javatbd$rowname' style='display: none'"; $htmltbody2 .= ($class !== null) ? " class='$class'": ""; $htmltbody2 .= ">\n"; if($ia[4]=="1") { //This is an array dual scale question and we have to massage the tbidpslay rowname $hiddenfield = "\n"; $hiddenfield .= "\n"; } else { $hiddenfield = "\n"; } $_SESSION[$valuename] = ''; //Remove any saved results for this since it is no longer being displayed } else { $htmltbody2 = "\n\n\t<$method id='javatbd$rowname'"; $htmltbody2 .= ($class !== null) ? " class='$class'": ""; $htmltbody2 .= ">"; if($ia[4]=="1") { //This is an array dual scale question and we have to massage the tbidpslay rowname $hiddenfield = "\n"; $hiddenfield .= "\n"; } else { $hiddenfield = "\n"; } } } else { $htmltbody2 = "\n\n\t<$method id='javatbd$rowname'"; $htmltbody2 .= ($class !== null) ? " class='$class'": ""; $htmltbody2 .= ">\n"; if($ia[4]=="1") { //This is an array dual scale question and we have to massage the tbidpslay rowname $hiddenfield = "\n"; $hiddenfield .= "\n"; } else { $hiddenfield = "\n"; } } //End of array_filter attribute return array($htmltbody2, $hiddenfield); } function return_array_filter_exclude_strings($ia, $qidattributes, $thissurvey, $ansrow, $rowname, $trbc='', $valuename, $method="tbody", $class=null) { /* DO ARRAY_FILTER_EXCLUDE ATTRIBUTE We set the $hiddenfield for each answer, and the value of this is available to java to let javascripts know whether each answer is currently being displayed. $htmltbody2 determines whether the answer row should be displayed initially. If no answers for the source question have been selected then the whole answer row should start in the display-on position. */ $htmltbody2 = ''; $hiddenfield= ''; if ( (trim($qidattributes['array_filter_exclude'])!='' && // the array_filter attribute is set $thissurvey['format'] == 'G' && // and the survey is being presented group by group getArrayFiltersExcludesOutGroup($ia[0]) == false // and this question _is_ in the current group for the array filter (ie it's on the same page) ) || // OR (trim($qidattributes['array_filter_exclude'])!='' && // the array_filter attribute is set $thissurvey['format'] == 'A' // and the survey is being presented all on one page ) ) { $htmltbody2 = "\n\n\t<$method id='javatbd$rowname'>\n"; if($ia[4]=="1") { //This is an array dual scale question and we have to massage the tbidpslay rowname $hiddenfield = "\n"; $hiddenfield .= "\n"; } else { $hiddenfield = "\n"; } } else if ( (trim($qidattributes['array_filter_exclude'])!='' && $thissurvey['format'] == 'S' ) || (trim($qidattributes['array_filter_exclude'])!='' && $thissurvey['format'] == 'G' && getArrayFiltersExcludesOutGroup($ia[0]) == true ) ) { $selected = getArrayFilterExcludesForQuestion($ia[0]); if (isset($ansrow['code'])) $ansrow['title'] = $ansrow['code']; if (!empty($selected) && !in_array($ansrow['title'],$selected)) { $htmltbody2 = "\n\n\t<$method id='javatbd$rowname'>\n"; if($ia[4]=="1") { //This is an array dual scale question and we have to massage the tbidpslay rowname $hiddenfield = "\n"; $hiddenfield .= "\n"; } else { $hiddenfield=""; } } else { $htmltbody2 = "\n\n\t<$method id='javatbd$rowname' style='display: none'>"; if($ia[4]=="1") { //This is an array dual scale question and we have to massage the tbidpslay rowname $hiddenfield = "\n"; $hiddenfield .= "\n"; } else { $hiddenfield="\n"; } $_SESSION[$valuename]=''; //Remove any saved results for this since it is no longer being displayed } } else { $htmltbody2 = "\n\n\t<$method id='javatbd$rowname' style='display: none'>\n"; if($ia[4]=="1") { //This is an array dual scale question and we have to massage the tbidpslay rowname $hiddenfield = "\n"; $hiddenfield .= "\n"; } else { $hiddenfield = ""; } } //End of array_filter attribute return array($htmltbody2, $hiddenfield); } // ================================================================== // setting constants for 'checked' and 'selected' inputs define('CHECKED' , ' checked="checked"' , true); define('SELECTED' , ' selected="selected"' , true); // ================================================================== // QUESTION METHODS ================================================= function do_boilerplate($ia) { global $js_header_includes; $qidattributes=getQuestionAttributes($ia[0],$ia[4]); $answer=''; if (trim($qidattributes['time_limit'])!='') { $js_header_includes[] = '/scripts/coookies.js'; $answer .= return_timer_script($qidattributes, $ia); } $answer .= ''; $inputnames[]=$ia[1]; return array($answer, $inputnames); } // --------------------------------------------------------------- function do_5pointchoice($ia) { global $clang, $imageurl; global $js_header_includes, $css_header_includes; if ($ia[8] == 'Y') { $checkconditionFunction = "checkconditions"; } else { $checkconditionFunction = "noop_checkconditions"; } $qidattributes=getQuestionAttributes($ia[0],$ia[4]); //print_r($qidattributes); $id = 'slider'.time().rand(0,100); $answer = "\n
    \n"; for ($fp=1; $fp<=5; $fp++) { $answer .= "\t
  • \n\n\n\t
  • \n"; } if ($ia[6] != "Y" && SHOW_NO_ANSWER == 1) // Add "No Answer" option if question is not mandatory { $answer .= "\t
  • \n\n\n\t
  • \n"; } $answer .= "
\n\n"; $inputnames[]=$ia[1]; if($qidattributes['slider_rating']==1){ $css_header_includes[]= '/admin/scripts/rating/jquery.rating.css'; $js_header_includes[]='/admin/scripts/rating/jquery.rating.js'; $answer.='

'; $answer.=" "; } if($qidattributes['slider_rating']==2){ if(!IsSet($_SESSION[$ia[1]]) OR $_SESSION[$ia[1]]==''){ $value=1; }else{ $value=$_SESSION[$ia[1]]; } $answer.="
1
2
3
4
5

"; } return array($answer, $inputnames); } // --------------------------------------------------------------- function do_date($ia) { global $clang, $js_header_includes, $css_header_includes, $thissurvey; $qidattributes=getQuestionAttributes($ia[0],$ia[4]); $js_header_includes[] = '/scripts/jquery/lime-calendar.js'; if ($ia[8] == 'Y') { $checkconditionFunction = "checkconditions"; } else { $checkconditionFunction = "noop_checkconditions"; } $dateformatdetails=getDateFormatData($thissurvey['surveyls_dateformat']); $numberformatdatat = getRadixPointData($thissurvey['surveyls_numberformat']); if (trim($qidattributes['dropdown_dates'])!=0) { if (!empty($_SESSION[$ia[1]])) { list($currentyear, $currentmonth, $currentdate) = explode('-', $_SESSION[$ia[1]]); } else { $currentdate=''; $currentmonth=''; $currentyear=''; } $dateorder = preg_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 { if ($clang->langcode !== 'en') { $js_header_includes[] = '/scripts/jquery/locale/jquery.ui.datepicker-'.$clang->langcode.'.js'; } $css_header_includes[]= '/scripts/jquery/css/start/jquery-ui.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 (trim($qidattributes['dropdown_dates_year_min'])!='') { $minyear=$qidattributes['dropdown_dates_year_min']; } else { $minyear='1980'; } if (trim($qidattributes['dropdown_dates_year_max'])!='') { $maxyear=$qidattributes['dropdown_dates_year_max']; } else { $maxyear='2020'; } $goodchars = str_replace( array("m","d","y"), "", $dateformatdetails['jsdate']); $goodchars = "0123456789".$goodchars[0]; $answer ="

gT('Date picker')."\" size=\"10\" name=\"{$ia[1]}\" id=\"answer{$ia[1]}\" value=\"$dateoutput\" maxlength=\"10\" onkeypress=\"return goodchars(event,'".$goodchars."')\" onchange=\"$checkconditionFunction(this.value, this.name, this.type)\" />

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

"; } $inputnames[]=$ia[1]; return array($answer, $inputnames); } // --------------------------------------------------------------- function do_language($ia) { global $dbprefix, $surveyid, $clang; if ($ia[8] == 'Y') { $checkconditionFunction = "checkconditions"; } else { $checkconditionFunction = "noop_checkconditions"; } $answerlangs = GetAdditionalLanguagesFromSurveyID($surveyid); $answerlangs [] = GetBaseLanguageFromSurveyID($surveyid); $answer = "\n\t

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

\n"; return array($answer, $inputnames); } // --------------------------------------------------------------- function do_list_dropdown($ia) { global $dbprefix, $dropdownthreshold, $lwcdropdowns, $connect; global $clang; if ($ia[8] == 'Y') { $checkconditionFunction = "checkconditions"; } else { $checkconditionFunction = "noop_checkconditions"; } $qidattributes=getQuestionAttributes($ia[0],$ia[4]); if (trim($qidattributes['other_replace_text'])!='') { $othertext=$qidattributes['other_replace_text']; } else { $othertext=$clang->gT('Other:'); } if (trim($qidattributes['category_separator'])!='') { $optCategorySeparator = $qidattributes['category_separator']; } $answer=''; $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 ($qidattributes['random_order']==1) { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' and scale_id=0 ORDER BY ".db_random(); } //question attribute alphasort set? elseif ($qidattributes['alphasort']==1) { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' and scale_id=0 ORDER BY answer"; } //no question attributes -> order by sortorder else { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' and scale_id=0 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()) { $opt_select = ''; if ($_SESSION[$ia[1]] == $ansrow['code']) { $opt_select = SELECTED; } $answer .= "\n"; } } 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); } else { $optgroups[$categorytext][] = array ( 'code' => $ansrow['code'], 'answer' => $answertext); } } foreach ($optgroups as $categoryname => $optionlistarray) { $answer .= ' '; foreach ($optionlistarray as $optionarray) { if ($_SESSION[$ia[1]] == $optionarray['code']) { $opt_select = SELECTED; } else { $opt_select = ''; } $answer .= ' '; } $answer .= ' '; } $opt_select=''; foreach ($defaultopts as $optionarray) { if ($_SESSION[$ia[1]] == $optionarray['code']) { $opt_select = SELECTED; } else { $opt_select = ''; } $answer .= ' '; } } if (!$_SESSION[$ia[1]]) { $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]] != '') && $ia[6] != 'Y' && $ia[6] != 'Y' && SHOW_NO_ANSWER == 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 .= " alt='".$clang->gT('Other answer')."' onchange='$checkconditionFunction(this.value, this.name, this.type);'"; $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' && $qidattributes['other_comment_mandatory']==1) { $checkotherscript = "\n\n"; } $answer = $checkotherscript . $answer; $inputnames[]=$ia[1]; return array($answer, $inputnames); } // --------------------------------------------------------------- function do_list_radio($ia) { global $dbprefix, $dropdownthreshold, $lwcdropdowns, $connect, $clang; global $thissurvey; if ($thissurvey['nokeyboard']=='Y') { vIncludeKeypad(); $kpclass = "text-keypad"; } else { $kpclass = ""; } if ($ia[8] == 'Y') { $checkconditionFunction = "checkconditions"; } else { $checkconditionFunction = "noop_checkconditions"; } $qidattributes=getQuestionAttributes($ia[0],$ia[4]); $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 ($qidattributes['random_order']==1) { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' and scale_id=0 ORDER BY ".db_random(); } //question attribute alphasort set? elseif ($qidattributes['alphasort']==1) { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' and scale_id=0 ORDER BY answer"; } //no question attributes -> order by sortorder else { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' and scale_id=0 ORDER BY sortorder, answer"; } $ansresult = db_execute_assoc($ansquery) or safe_die('Couldn\'t get answers
$ansquery
'.$connect->ErrorMsg()); //Checked $anscount = $ansresult->RecordCount(); if (trim($qidattributes['display_columns'])!='') { $dcols = $qidattributes['display_columns']; } else { $dcols= 1; } if (trim($qidattributes['other_replace_text'])!='') { $othertext=$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' && SHOW_NO_ANSWER == 1) {$anscount++;} //Count up if "No answer" is showing $wrapper = setup_columns($dcols , $anscount); $answer = $wrapper['whole-start']; // Get array_filter stuff $rowcounter = 0; $colcounter = 1; $trbc=''; while ($ansrow = $ansresult->FetchRow()) { $myfname = $ia[1].$ansrow['code']; $check_ans = ''; if ($_SESSION[$ia[1]] == $ansrow['code']) { $check_ans = CHECKED; } list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $qidattributes, $thissurvey, $ansrow, $myfname, $trbc, $myfname, "li"); if($wrapper['item-start'] == "\t
  • \n") { $startitem = "\t$htmltbody2\n"; } else { $startitem = $wrapper['item-start']; } //queXS check if this is designed to set an outcome: $quexs_outcome = false; $quexs_outcome_code = 0; if (strncasecmp($ansrow['answer'],"{OUTCOME:",9) == 0) { $quexs_pos = strrpos($ansrow['answer'],"}",8); if ($quexs_pos != false) { $quexs_outcome_code = substr($ansrow['answer'],9,$quexs_pos - 9); $quexs_outcome = true; include_once(dirname(__FILE__) . '/quexs.php'); $ansrow['answer'] = quexs_template_replace($ansrow['answer']); } } //queXS check if this is designed to schedule an appointment: $quexs_appointment = false; if (strncasecmp($ansrow['answer'],"{SCHEDULEAPPOINTMENT}",21) == 0) { $ansrow['answer'] = $clang->gT("Schedule Appointment"); $quexs_appointment = true; } $answer .= $startitem; $answer .= "\t$hiddenfield\n"; $answer .=' '.$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') { $sSeperator = getRadixPointData($thissurvey['surveyls_numberformat']); $sSeperator = $sSeperator['seperator']; if ($qidattributes['other_numbers_only']==1) { $numbersonly = 'onkeypress="return goodchars(event,\'-0123456789'.$sSeperator.'\')"'; } 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=""'; } list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $qidattributes, $thissurvey, array("code"=>"other"), $thisfieldname, $trbc, $myfname, "li", "other"); if($wrapper['item-start-other'] == "\t
  • \n") { $startitem = "\t$htmltbody2\n"; } else { $startitem = $wrapper['item-start-other']; } $answer .= $startitem; $answer .= "\t$hiddenfield\n"; $answer .= ' '.$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' && SHOW_NO_ANSWER == 1) { if ((!isset($_SESSION[$ia[1]]) || $_SESSION[$ia[1]] == '') || ($_SESSION[$ia[1]] == ' ' )) { $check_ans = CHECKED; //Check the "no answer" radio button if there is no answer in session. } 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; } } //END OF ITEMS $answer .= $wrapper['whole-end'].' \n"; $checkotherscript = ""; if (isset($other) && $other == 'Y' && $qidattributes['other_comment_mandatory']==1) { $checkotherscript = "\n"; } $answer = $checkotherscript . $answer; $inputnames[]=$ia[1]; return array($answer, $inputnames); } // --------------------------------------------------------------- function do_listwithcomment($ia) { global $maxoptionsize, $dbprefix, $dropdownthreshold, $lwcdropdowns, $thissurvey; global $clang; if ($thissurvey['nokeyboard']=='Y') { vIncludeKeypad(); $kpclass = "text-keypad"; } else { $kpclass = ""; } if ($ia[8] == 'Y') { $checkconditionFunction = "checkconditions"; } else { $checkconditionFunction = "noop_checkconditions"; } $answer = ''; $qidattributes=getQuestionAttributes($ia[0],$ia[4]); if (!isset($maxoptionsize)) {$maxoptionsize=35;} //question attribute random order set? if ($qidattributes['random_order']==1) { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' and scale_id=0 ORDER BY ".db_random(); } //question attribute alphasort set? elseif ($qidattributes['alphasort']==1) { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' and scale_id=0 ORDER BY answer"; } //no question attributes -> order by sortorder else { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' and scale_id=0 ORDER BY sortorder, answer"; } $ansresult = db_execute_assoc($ansquery); //Checked $anscount = $ansresult->RecordCount(); $hint_comment = $clang->gT('Please enter your comment here'); if ($lwcdropdowns == 'R' && $anscount <= $dropdownthreshold) { $answer .= '
      '; while ($ansrow=$ansresult->FetchRow()) { $check_ans = ''; if ($_SESSION[$ia[1]] == $ansrow['code']) { $check_ans = CHECKED; } $answer .= '
    • '; } if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { if ((!isset($_SESSION[$ia[1]]) || $_SESSION[$ia[1]] == '') ||($_SESSION[$ia[1]] == ' ' )) { $check_ans = CHECKED; } elseif ((isset($_SESSION[$ia[1]]) || $_SESSION[$ia[1]] != '')) { $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\n" // . "

      "; $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, $imageurl, $clang, $thissurvey, $showpopups; if ($ia[8] == 'Y') { $checkconditionFunction = "checkconditions"; } else { $checkconditionFunction = "noop_checkconditions"; } $qidattributes=getQuestionAttributes($ia[0],$ia[4]); $answer=""; if ($qidattributes['random_order']==1) { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' and scale_id=0 ORDER BY ".db_random(); } else { $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."' and scale_id=0 ORDER BY sortorder, answer"; } $ansresult = db_execute_assoc($ansquery); //Checked $anscount= $ansresult->RecordCount(); if (trim($qidattributes["max_answers"])!='') { $max_answers=trim($qidattributes["max_answers"]); } else { $max_answers=$anscount; } $finished=$anscount-$max_answers; $answer .= "\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 \n"; $ranklist .= "\n"; $ranklist .= "\"".$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.getElementById('RANK_{$ia[0]}$i').value, document.getElementById('fvalue_{$ia[0]}$i').value, document.getElementById('RANK_{$ia[0]}$i').name, this.id)\" />
      \n"; $inputnames[]=$myfname; $ranklist .= "\n"; } $maxselectlength=0; $choicelist = "\n"; $answer .= "\t\n" . "\n" . "\t\n"; $maxselectlength=$maxselectlength+2; if ($maxselectlength > 60) { $maxselectlength=60; } $ranklist = str_replace("\n" . "\t
      \n" . "  
      \n" . " ".$choicelist . "\t 
      \n" . "\t\n"; $answer .= $ranklist . "\t
      ".$clang->gT("Your Ranking").":
      \n" . "\t\n" . "\n" . "\n" . "\t\n" . "".$clang->gT("Click on the scissors next to each item on the right to remove the last entry in your ranked list") . "\t\n" . "\n" . "\t\n"; if (trim($qidattributes["min_answers"])!='') { $minansw=trim($qidattributes["min_answers"]); if(!isset($showpopups) || $showpopups == 0) { $answer .= ""; } $minanswscript = "\n"; $answer = $minanswscript . $answer; } return array($answer, $inputnames); } // --------------------------------------------------------------- function do_multiplechoice($ia) { global $dbprefix, $clang, $connect, $thissurvey; if ($thissurvey['nokeyboard']=='Y') { vIncludeKeypad(); $kpclass = "text-keypad"; } else { $kpclass = ""; } // Find out if any questions have attributes which reference this questions // based on value of attribute. This could be array_filter and array_filter_exclude $attribute_ref=false; $inputnames=array(); $qaquery = "SELECT qid,attribute FROM ".db_table_name('question_attributes')." WHERE value LIKE '".strtolower($ia[2])."' and (attribute='array_filter' or attribute='array_filter_exclude')"; $qaresult = db_execute_assoc($qaquery); //Checked while($qarow = $qaresult->FetchRow()) { $qquery = "SELECT qid FROM ".db_table_name('questions')." WHERE sid=".$thissurvey['sid']." AND scale_id=0 AND qid=".$qarow['qid']; $qresult = db_execute_assoc($qquery); //Checked if ($qresult->RecordCount() > 0) { $attribute_ref = true; } } if ($ia[8] == 'Y' || $attribute_ref === true) { $checkconditionFunction = "checkconditions"; } else { $checkconditionFunction = "noop_checkconditions"; } $qidattributes=getQuestionAttributes($ia[0],$ia[4]); if (trim($qidattributes['other_replace_text'])!='') { $othertext=$qidattributes['other_replace_text']; } else { $othertext=$clang->gT('Other:'); } if (trim($qidattributes['display_columns'])!='') { $dcols = $qidattributes['display_columns']; } else { $dcols = 1; } if ($qidattributes['other_numbers_only']==1) { $sSeperator = getRadixPointData($thissurvey['surveyls_numberformat']); $sSeperator= $sSeperator['seperator']; $numbersonly = 'return goodchars(event,"0123456789'.$sSeperator.'")'; } else { $numbersonly = ''; } // Check if the max_answers attribute is set $maxansw = 0; $callmaxanswscriptcheckbox = ''; $callmaxanswscriptother = ''; $maxanswscript = ''; $exclude_all_others_auto = trim($qidattributes["exclude_all_others_auto"]); if ($exclude_all_others_auto=='1'){ $autoArray['list'][]=$ia[1]; $autoArray[$ia[1]]['parent'] = $ia[1]; } if (trim($qidattributes['exclude_all_others'])!='') { $excludeallothers=explode(';',trim($qidattributes['exclude_all_others'])); $excludeallotherscript = " \n"; } } } $answer .= " onclick='cancelBubbleThis(event);"; /* Exclude all others coding */ if(in_array($ansrow['title'], $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['title']}') {\n" . "\tthiselt=document.getElementById('answer$ia[1]{$ansrow['title']}');\n" . "thiselt.checked='';\n" . "thiselt.disabled='true';\n" . "if (doconditioncheck == 'yes') {\n" . "\t$checkconditionFunction(thiselt.value, thiselt.name, thiselt.type);\n" . "}\n}\n"; $excludeallotherscriptoff .= "document.getElementById('answer$ia[1]{$ansrow['title']}').disabled='';\n"; } elseif (count($excludeallothers)>0) { $excludeallotherscripton .= "\tthiselt=document.getElementById('answer$ia[1]{$ansrow['title']}');\n" . "thiselt.checked='';\n" . "thiselt.disabled='true';\n" . "if (doconditioncheck == 'yes') {\n" . "\t$checkconditionFunction(thiselt.value, thiselt.name, thiselt.type);\n" . "}\n"; $excludeallotherscriptoff.= "document.getElementById('answer$ia[1]{$ansrow['title']}').disabled='';\n"; } /* End of exclude all others coding */ $answer .= $callmaxanswscriptcheckbox /* Include checkbox for script for maxanswers if that attribute is selected */ . "$checkconditionFunction(this.value, this.name, this.type)' />\n" . "\n"; if ($maxansw > 0) {$maxanswscript .= "\tif (document.getElementById('answer".$myfname."').checked) { count += 1; }\n";} if ($minansw > 0) {$minanswscript .= "\tif (document.getElementById('answer".$myfname."').checked) { count += 1; }\n";} ++$fn; /* Now add the hidden field to contain information about this answer */ $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 ($exclude_all_others_auto==1){ $answer .= ""; } if ($other == 'Y') { $myfname = $ia[1].'other'; list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $qidattributes, $thissurvey, array("code"=>"other"), $myfname, $trbc, $myfname, "li"); if(count($excludeallothers) > 0) { $excludeallotherscripton .= "thiselt=document.getElementById('answer{$ia[1]}othercbox');\n" . "thiselt.checked='';\n" . "thiselt.disabled='true';\n"; $excludeallotherscripton .= "thiselt=document.getElementById('answer$ia[1]other');\n" . "thiselt.value='';\n" . "thiselt.disabled='true';\n" . "if (doconditioncheck == 'yes') {\n" . "\t$checkconditionFunction(thiselt.value, thiselt.name, thiselt.type);\n" . "}\n"; $excludeallotherscriptoff .="document.getElementById('answer$ia[1]other').disabled='';\n"; $excludeallotherscriptoff .="document.getElementById('answer{$ia[1]}othercbox').disabled='';\n"; } if($wrapper['item-start'] == "\t
    • \n") { $startitem = "\t$htmltbody2\n"; } else { $startitem = $wrapper['item-start']; } $answer .= $startitem; $answer .= $hiddenfield.' ".$othertext." "; $answer .= ' 0) { // // For multiplechoice question there is no DB field for the other Checkbox // We only count the -other- as valid if both the cbox and the other text is filled $minanswscript .= "\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 .= " if (count > max) { alert('".sprintf($clang->gT("Please choose at most %d answers for question \"%s\"","js"), $maxansw, trim(javascript_escape(str_replace(array("\n", "\r"), "", $ia[3]),true,true)))."'); if (me.type == 'checkbox') {me.checked = false;} if (me.type == 'text') { me.value = ''; if (document.getElementById('answer'+me.name + 'cbox') ){ document.getElementById('answer'+me.name + 'cbox').checked = false; } } return max; } } //--> \n"; $answer = $maxanswscript . $answer; } if ( $minansw > 0 ) { $minanswscript .= "\tif (count < {$minansw} && document.getElementById('display{$ia[0]}').value == 'on'){\n" . "alert('".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" . "return false;\n" . "\t} else {\n" . "if (oldonsubmit_{$ia[0]}){\n" . "\treturn oldonsubmit_{$ia[0]}();\n" . "}\n" . "return true;\n" . "\t}\n" . "}\n" . "document.limesurvey.onsubmit = ensureminansw_{$ia[0]}\n" . "-->\n" . "\t\n"; //$answer = $minanswscript . $answer; } $checkotherscript = ""; if ($other == 'Y') { // Multiple choice 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, $thissurvey; if ($thissurvey['nokeyboard']=='Y') { vIncludeKeypad(); $kpclass = "text-keypad"; } else { $kpclass = ""; } $attribute_ref=false; $qaquery = "SELECT qid,attribute FROM ".db_table_name('question_attributes')." WHERE value LIKE '".strtolower($ia[2])."'"; $qaresult = db_execute_assoc($qaquery); //Checked $attribute_ref=false; while($qarow = $qaresult->FetchRow()) { $qquery = "SELECT qid FROM ".db_table_name('questions')." WHERE sid=".$thissurvey['sid']." AND qid=".$qarow['qid']; $qresult = db_execute_assoc($qquery); //Checked if ($qresult->RecordCount() > 0) { $attribute_ref = true; } } if ($ia[8] == 'Y' || $attribute_ref == true) { $checkconditionFunction = "checkconditions"; } else { $checkconditionFunction = "noop_checkconditions"; } $qidattributes=getQuestionAttributes($ia[0],$ia[4]); if ($qidattributes['other_numbers_only']==1) { $sSeperator = getRadixPointData($thissurvey['surveyls_numberformat']); $sSeperator = $sSeperator['seperator']; $numbersonly = 'onkeypress="return goodchars(event,\'-0123456789'.$sSeperator.'\')"'; } else { $numbersonly = ''; } if (trim($qidattributes['other_replace_text'])!='') { $othertext=$qidattributes['other_replace_text']; } else { $othertext=$clang->gT('Other:'); } // Check if the max_answers attribute is set $maxansw=0; $callmaxanswscriptcheckbox = ''; $callmaxanswscriptcheckbox2 = ''; $callmaxanswscriptother = ''; $maxanswscript = ''; if (trim($qidattributes['max_answers'])!='') { $maxansw=$qidattributes['max_answers']; $callmaxanswscriptcheckbox = "limitmaxansw_{$ia[0]}(this);"; $callmaxanswscriptcheckbox2= "limitmaxansw_{$ia[0]}"; $callmaxanswscriptother = "onkeyup=\"limitmaxansw_{$ia[0]}(this)\""; $maxanswscript = "\t\n"; $answer = $maxanswscript . $answer; } if ( $minansw > 0 ) { $minanswscript .= "\tif (count < {$minansw} && document.getElementById('display{$ia[0]}').value == 'on'){\n" . "alert('".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" . "return false;\n" . "\t} else {\n" . "if (oldonsubmit_{$ia[0]}){\n" . "\treturn oldonsubmit_{$ia[0]}();\n" . "}\n" . "return true;\n" . "\t}\n" . "}\n" . "document.limesurvey.onsubmit = ensureminansw_{$ia[0]}\n" . "-->\n" . "\t\n"; //$answer = $minanswscript . $answer; } $checkotherscript = ""; //if ($other == 'Y' && $qidattributes['other_comment_mandatory']==1) //TIBO if ($other == 'Y' && $qidattributes['other_comment_mandatory']==1) //TIBO { // Multiple choice 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_file_upload($ia) { global $clang, $js_header_includes, $thissurvey, $surveyid; if ($ia[8] == 'Y') $checkconditionFunction = "checkconditions"; else $checkconditionFunction = "noop_checkconditions"; $qidattributes=getQuestionAttributes($ia[0]); // Fetch question attributes $_SESSION['fieldname'] = $ia[1]; // Basic uploader /* $basic = '

      ' .''; if ($_SESSION['show_title']) { $basic .= ''; } if ($_SESSION['show_comment']) { $basic .= ''; } $basic .= '' .'' .'' .''; for ($i = 1; $i <= $_SESSION['maxfiles']; $i++) { $basic .= '' .'' .''; if ($_SESSION['show_comment']) $basic .= '' .''; $basic .= '' .'' .''; } $basic .= '
      Title  Comment  Select file
         
      '; if ($_SESSION['show_title']) $basic .= '' .'  ' .'' .'  ' .'
         
      '; $basic .= '

      Hide Simple Uploader'; */ $currentdir = getcwd(); $pos = stripos($currentdir, "admin"); if ($pos) { $_SESSION['preview'] = 1; $questgrppreview = 1; // Preview is launched from Question or group level $scriptloc = '../uploader.php'; } else if ($thissurvey['active'] != "Y") { $_SESSION['preview'] = 1; $questgrppreview = 0; $scriptloc = 'uploader.php'; } else { $_SESSION['preview'] = 0; $questgrppreview = 0; $scriptloc = 'uploader.php'; } $uploadbutton = "

      " .$clang->gT('Upload files'). "



      "; $answer = "\n"; if ($pos) $answer .= ""; else $answer .= ""; // Modal dialog $answer .= $uploadbutton; $answer .= ""; $answer .= ""; } else { $answer .= "0 />"; } } else { $answer .= "0 />"; } $answer .= "
      "; $answer .= ''; $answer .= ''; $inputnames[] = $ia[1]; $inputnames[] = $ia[1]."_filecount"; return array($answer, $inputnames); } // --------------------------------------------------------------- function do_multipleshorttext($ia) { global $dbprefix, $clang, $thissurvey; if ($ia[8] == 'Y') { $checkconditionFunction = "checkconditions"; } else { $checkconditionFunction = "noop_checkconditions"; } $answer=''; $qidattributes=getQuestionAttributes($ia[0],$ia[4]); if ($qidattributes['numbers_only']==1) { $sSeperator = getRadixPointData($thissurvey['surveyls_numberformat']); $sSeperator = $sSeperator['seperator']; $numbersonly = 'onkeypress="return goodchars(event,\'-0123456789'.$sSeperator.'\')"'; } else { $numbersonly = ''; } if (trim($qidattributes['maximum_chars'])!='') { $maxsize=$qidattributes['maximum_chars']; } else { $maxsize=255; } if (trim($qidattributes['text_input_width'])!='') { $tiwidth=$qidattributes['text_input_width']; } else { $tiwidth=20; } if (trim($qidattributes['prefix'])!='') { $prefix=$qidattributes['prefix']; } else { $prefix = ''; } if (trim($qidattributes['suffix'])!='') { $suffix=$qidattributes['suffix']; } else { $suffix = ''; } if ($thissurvey['nokeyboard']=='Y') { vIncludeKeypad(); $kpclass = "text-keypad"; } else { $kpclass = ""; } if ($qidattributes['random_order']==1) { $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random(); } else { $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY question_order"; } $ansresult = db_execute_assoc($ansquery); //Checked $anscount = $ansresult->RecordCount()*2; //$answer .= "\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 { if (trim($qidattributes['display_rows'])!='') { //question attribute "display_rows" is set -> we need a textarea to be able to show several rows $drows=$qidattributes['display_rows']; //extend maximum chars if this is set to short text default of 255 if($maxsize == 255) { $maxsize=65525; } while ($ansrow = $ansresult->FetchRow()) { $myfname = $ia[1].$ansrow['title']; if ($ansrow['question'] == "") { $ansrow['question'] = " "; } $quexs_answer = false; if (strncasecmp($ansrow['question'],"{SAMPLEUPDATE:",14) == 0) //queXS Addition { $ansrow['question'] = substr($ansrow['question'],14,-1); //remove token text include_once('quexs.php'); $quexs_operator_id = get_operator_id(); $quexs_case_id = get_case_id($quexs_operator_id); if ($quexs_case_id) { $quexs_answer = get_sample_variable($ansrow['question'],$quexs_case_id); $tiwidth = strlen($quexs_answer) + 5; $maxsize = $tiwidth + 255; } } //NEW: textarea instead of input=text field $answer_main .= "\t
    • \n" . "\n" . "\t\n".$prefix."\n".' \n".$suffix."\n\t\n" . "\t
    • \n"; $fn++; $inputnames[]=$myfname; } } else { while ($ansrow = $ansresult->FetchRow()) { $myfname = $ia[1].$ansrow['title']; if ($ansrow['question'] == "") {$ansrow['question'] = " ";} $quexs_answer = false; if (strncasecmp($ansrow['question'],"{SAMPLEUPDATE:",14) == 0) //queXS Addition { $ansrow['question'] = substr($ansrow['question'],14,-1); //remove token text include_once('quexs.php'); $quexs_operator_id = get_operator_id(); $quexs_case_id = get_case_id($quexs_operator_id); if ($quexs_case_id) { $quexs_answer = get_sample_variable($ansrow['question'],$quexs_case_id); $tiwidth = strlen($quexs_answer) + 5; $maxsize = $tiwidth + 255; } } $answer_main .= "\t
    • \n" . "\n" . "\t\n".$prefix."\n".''."\n".$suffix."\n\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, $thissurvey; if ($ia[8] == 'Y') { $checkconditionFunction = "checkconditions"; } else { $checkconditionFunction = "noop_checkconditions"; } $qidattributes=getQuestionAttributes($ia[0],$ia[4]); $answer=''; $sSeperator = getRadixPointData($thissurvey['surveyls_numberformat']); $sSeperator = $sSeperator['seperator']; //Must turn on the "numbers only javascript" $numbersonly = 'onkeypress="inputField = event.srcElement ? event.srcElement : event.target || event.currentTarget; if (inputField.value.indexOf(\''.$sSeperator.'\')>0 && String.fromCharCode(getkey(event))==\''.$sSeperator.'\') return false; return goodchars(event,\'0123456789'.$sSeperator.'\')"'; if (trim($qidattributes['maximum_chars'])!='') { $maxsize=$qidattributes['maximum_chars']; } else { $maxsize = 25; } //EQUALS VALUE if (trim($qidattributes['equals_num_value'])!=''){ $equals_num_value=$qidattributes['equals_num_value']; $numbersonlyonblur[]='calculateValue'.$ia[1].'(3)'; $calculateValue[]=3; } elseif (trim($qidattributes['num_value_equals_sgqa'])!='' && isset($_SESSION[$qidattributes['num_value_equals_sgqa']])) { $equals_num_value=$_SESSION[$qidattributes['num_value_equals_sgqa']]; $numbersonlyonblur[]='calculateValue'.$ia[1].'(3)'; $calculateValue[]=3; } else { $equals_num_value=0; } //MIN VALUE if (trim($qidattributes['min_num_value'])!=''){ $min_num_value=$qidattributes['min_num_value']; $numbersonlyonblur[]='calculateValue'.$ia[1].'(2)'; $calculateValue[]=2; } elseif (trim($qidattributes['min_num_value_sgqa'])!='' && isset($_SESSION[$qidattributes['min_num_value_sgqa']])){ $min_num_value=$_SESSION[$qidattributes['min_num_value_sgqa']]; $numbersonlyonblur[]='calculateValue'.$ia[1].'(2)'; $calculateValue[]=2; } else { $min_num_value=0; } //MAX VALUE if (trim($qidattributes['max_num_value'])!=''){ $max_num_value = $qidattributes['max_num_value']; $numbersonlyonblur[]='calculateValue'.$ia[1].'(1)'; $calculateValue[]=1; } elseif (trim($qidattributes['max_num_value_sgqa'])!='' && isset($_SESSION[$qidattributes['max_num_value_sgqa']])){ $max_num_value = $_SESSION[$qidattributes['max_num_value_sgqa']]; $numbersonlyonblur[]='calculateValue'.$ia[1].'(1)'; $calculateValue[]=1; } else { $max_num_value = 0; } if (trim($qidattributes['prefix'])!='') { $prefix=$qidattributes['prefix']; } else { $prefix = ''; } if (trim($qidattributes['suffix'])!='') { $suffix=$qidattributes['suffix']; } else { $suffix = ''; } if ($thissurvey['nokeyboard']=='Y') { vIncludeKeypad(); $kpclass = "num-keypad"; } else { $kpclass = ""; } if(!empty($numbersonlyonblur)) { $numbersonly .= ' onblur="'.implode(';', $numbersonlyonblur).'"'; $numbersonly_slider = implode(';', $numbersonlyonblur); } else { $numbersonly_slider = ''; } if (trim($qidattributes['text_input_width'])!='') { $tiwidth=$qidattributes['text_input_width']; } else { $tiwidth=10; } if ($qidattributes['slider_layout']==1) { $slider_layout=true; $css_header_includes[]= '/scripts/jquery/css/start/jquery-ui.css'; if (trim($qidattributes['slider_accuracy'])!='') { //$slider_divisor = 1 / $slider_accuracy['value']; $decimnumber = strlen($qidattributes['slider_accuracy']) - strpos($qidattributes['slider_accuracy'],'.') -1; $slider_divisor = pow(10,$decimnumber); $slider_stepping = $qidattributes['slider_accuracy'] * $slider_divisor; // error_log('acc='.$slider_accuracy['value']." div=$slider_divisor stepping=$slider_stepping"); } else { $slider_divisor = 1; $slider_stepping = 1; } if (trim($qidattributes['slider_min'])!='') { $slider_mintext = $qidattributes['slider_min']; $slider_min = $qidattributes['slider_min'] * $slider_divisor; } else { $slider_mintext = 0; $slider_min = 0; } if (trim($qidattributes['slider_max'])!='') { $slider_maxtext = $qidattributes['slider_max']; $slider_max = $qidattributes['slider_max'] * $slider_divisor; } else { $slider_maxtext = "100"; $slider_max = 100 * $slider_divisor; } if (trim($qidattributes['slider_default'])!='') { $slider_default = $qidattributes['slider_default']; } else { $slider_default = ''; } if ($slider_default == '' && $qidattributes['slider_middlestart']==1) { $slider_middlestart = intval(($slider_max + $slider_min)/2); } else { $slider_middlestart = ''; } if (trim($qidattributes['slider_separator'])!='') { $slider_separator = $qidattributes['slider_separator']; } else { $slider_separator = ''; } } else { $slider_layout = false; } $hidetip=$qidattributes['hide_tip']; if ($slider_layout === true) // auto hide tip when using sliders { $hidetip=1; } if ($qidattributes['random_order']==1) { $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random(); } else { $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY question_order"; } $ansresult = db_execute_assoc($ansquery); //Checked $anscount = $ansresult->RecordCount()*2; //$answer .= "\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['title']; if ($ansrow['question'] == "") {$ansrow['question'] = " ";} if ($slider_layout === false || $slider_separator == '') { $theanswer = $ansrow['question']; $sliderleft=''; $sliderright=''; } else { $answer_and_slider_array=explode($slider_separator,$ansrow['question']); if (isset($answer_and_slider_array[0])) $theanswer=$answer_and_slider_array[0]; else $theanswer=""; if (isset($answer_and_slider_array[1])) $sliderleft=$answer_and_slider_array[1]; else $sliderleft=""; if (isset($answer_and_slider_array[2])) $sliderright=$answer_and_slider_array[2]; else $sliderright=""; $sliderleft="
      $sliderleft
      "; $sliderright="
      $sliderright
      "; } if ($slider_layout === false) { $answer_main .= "\t
    • \n\n"; } else { $answer_main .= "\t
    • \n\n"; } if($label_width < strlen(trim(strip_tags($ansrow['question'])))) { $label_width = strlen(trim(strip_tags($ansrow['question']))); } if ($slider_layout === false) { $sSeperator = getRadixPointData($thissurvey['surveyls_numberformat']); $sSeperator = $sSeperator['seperator']; $answer_main .= "\n\t".$prefix."\n\t\n\t".$suffix."\n\n\t
    • \n"; } else { if ($qidattributes['slider_showminmax']==1) { //$slider_showmin=$slider_min; $slider_showmin= "\t
      $slider_mintext
      \n"; $slider_showmax= "\t
      $slider_maxtext
      \n"; } else { $slider_showmin=''; $slider_showmax=''; } $js_header_includes[] = '/scripts/jquery/lime-slider.js'; if (isset($_SESSION[$myfname]) && $_SESSION[$myfname] != '') { $slider_startvalue = $_SESSION[$myfname] * $slider_divisor; $displaycallout_atstart=1; } elseif ($slider_default != "") { $slider_startvalue = $slider_default * $slider_divisor; $displaycallout_atstart=1; } elseif ($slider_middlestart != '') { $slider_startvalue = $slider_middlestart; $displaycallout_atstart=0; } else { $slider_startvalue = 'NULL'; $displaycallout_atstart=0; } $answer_main .= "$sliderleft
      \n" . "\t\n" . "\t\n" . "\t\n" . "\t\n" . "\t\n" . "\t\n" . "\t\n" . "\t\n" . "\t\n" . "
      \n" . $slider_showmin . "
      \n" . "
      \n"; $answer_main .= "\n"; $answer_main .= $slider_showmax . "\t
      " . "
      $sliderright\n"; $answer_main .= "\t\n"; } // $answer .= "\t\n"; $fn++; $inputnames[]=$myfname; } $question_tip = ''; if($hidetip == 0) { $question_tip .= '

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

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

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

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

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

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

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

      \n"; } if ($max_num_value || $equals_num_value || $min_num_value) { $answer_computed = ''; if ($equals_num_value) { $answer_computed .= "\t
    • \n\n\n\t$prefix\n\t\n\t$suffix\n\n\t
    • \n"; } $answer_computed .= "\t
    • \n\n\n\t$prefix\n\t\n\t$suffix\n\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; } */ $sSeperator = getRadixPointData($thissurvey['surveyls_numberformat']); $sSeperator = $sSeperator['seperator']; if ($max_num_value || $equals_num_value || $min_num_value) { //Do value validation $answer .= '\n"; $answer .= '\n"; $answer .= "\n"; } return array($answer, $inputnames); } // --------------------------------------------------------------- function do_numerical($ia) { global $clang, $thissurvey; if ($ia[8] == 'Y') { $checkconditionFunction = "checkconditions"; } else { $checkconditionFunction = "noop_checkconditions"; } $qidattributes=getQuestionAttributes($ia[0],$ia[4]); if (trim($qidattributes['prefix'])!='') { $prefix=$qidattributes['prefix']; } else { $prefix = ''; } if (trim($qidattributes['suffix'])!='') { $suffix=$qidattributes['suffix']; } else { $suffix = ''; } if (trim($qidattributes['maximum_chars'])!='') { $maxsize=$qidattributes['maximum_chars']; if ($maxsize>20) { $maxsize=20; } } else { $maxsize=20; // The field length for numerical fields is 20 } if (trim($qidattributes['text_input_width'])!='') { $tiwidth=$qidattributes['text_input_width']; } else { $tiwidth=10; } if (trim($qidattributes['num_value_int_only'])==1) { $acomma=""; } else { $acomma=getRadixPointData($thissurvey['surveyls_numberformat']); $acomma = $acomma['seperator']; } $sSeperator = getRadixPointData($thissurvey['surveyls_numberformat']); $sSeperator = $sSeperator['seperator']; $_SESSION[$ia[1]] = str_replace('.',$sSeperator,$_SESSION[$ia[1]]); if ($thissurvey['nokeyboard']=='Y') { vIncludeKeypad(); $kpclass = "num-keypad"; } else { $kpclass = ""; } // --> START NEW FEATURE - SAVE $answer = "

      \n\t$prefix\n\tgT('Answer')."\" onkeypress=\"return goodchars(event,'-0123456789{$acomma}')\" onchange='$checkconditionFunction(this.value, this.name, this.type)'" . "maxlength=\"{$maxsize}\" />\n\t{$suffix}\n

      \n"; if ($qidattributes['hide_tip']==0) { $answer .= "

      ".$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) { global $clang, $js_header_includes, $thissurvey,$googleMapsAPIKey; if ($ia[8] == 'Y') { $checkconditionFunction = "checkconditions"; } else { $checkconditionFunction = "noop_checkconditions"; } $qidattributes=getQuestionAttributes($ia[0],$ia[4]); if ($qidattributes['numbers_only']==1) { $sSeperator = getRadixPointData($thissurvey['surveyls_numberformat']); $sSeperator = $sSeperator['seperator']; $numbersonly = 'onkeypress="return goodchars(event,\'0123456789'.$sSeperator.'\')"'; } else { $numbersonly = ''; } if (trim($qidattributes['maximum_chars'])!='') { $maxsize=$qidattributes['maximum_chars']; } else { $maxsize=255; } if (trim($qidattributes['text_input_width'])!='') { $tiwidth=$qidattributes['text_input_width']; } else { $tiwidth=50; } if (trim($qidattributes['prefix'])!='') { $prefix=$qidattributes['prefix']; } else { $prefix = ''; } if (trim($qidattributes['suffix'])!='') { $suffix=$qidattributes['suffix']; } else { $suffix = ''; } if ($thissurvey['nokeyboard']=='Y') { vIncludeKeypad(); $kpclass = "text-keypad"; } else { $kpclass = ""; } if (trim($qidattributes['display_rows'])!='') { //question attribute "display_rows" is set -> we need a textarea to be able to show several rows $drows=$qidattributes['display_rows']; //extend maximum chars if this is set to short text default of 255 if($maxsize == 255) { $maxsize=65525; } //if a textarea should be displayed we make it equal width to the long text question //this looks nicer and more continuous if($tiwidth == 50) { $tiwidth=40; } //NEW: textarea instead of input=text field // --> START NEW FEATURE - SAVE $answer = '\n"; } elseif((int)($qidattributes['location_mapservice'])!=0){ $mapservice = $qidattributes['location_mapservice']; $currentLocation = $_SESSION[$ia[1]]; $currentLatLong = null; $floatLat = 0; $floatLng = 0; // Get the latitude/longtitude for the point that needs to be displayed by default if (strlen($currentLocation) > 2){ $currentLatLong = explode(';',$currentLocation); $currentLatLong = array($currentLatLong[0],$currentLatLong[1]); } else{ if ((int)($qidattributes['location_nodefaultfromip'])==0) $currentLatLong = getLatLongFromIp($_SERVER['REMOTE_ADDR']); if (!isset($currentLatLong) || $currentLatLong==false){ $floatLat = 0; $floatLng = 0; $LatLong = explode(" ",trim($qidattributes['location_defaultcoordinates'])); if (isset($LatLong[0]) && isset($LatLong[1])){ $floatLat = $LatLong[0]; $floatLng = $LatLong[1]; } $currentLatLong = array($floatLat,$floatLng); } } // 2 - city; 3 - state; 4 - country; 5 - postal $strBuild = ""; if ($qidattributes['location_city']) $strBuild .= "2"; if ($qidattributes['location_state']) $strBuild .= "3"; if ($qidattributes['location_country']) $strBuild .= "4"; if ($qidattributes['location_postal']) $strBuild .= "5"; $currentLocation = $currentLatLong[0] . " " . $currentLatLong[1]; $answer = "

      "; if ($qidattributes['location_mapservice']==1 && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != "off") $js_header_includes[] = "https://maps.googleapis.com/maps/api/js?sensor=false"; else if ($qidattributes['location_mapservice']==1) $js_header_includes[] = "http://maps.googleapis.com/maps/api/js?sensor=false"; elseif ($qidattributes['location_mapservice']==2) $js_header_includes[] = "http://www.openlayers.org/api/OpenLayers.js"; if (isset($qidattributes['hide_tip']) && $qidattributes['hide_tip']==0) { $answer .= "
      \n" . $clang->gT('Drag and drop the pin to the desired location. You may also right click on the map to move the pin.').''; $question_text['help'] = $clang->gT('Drag and drop the pin to the desired location. You may also right click on the map to move the pin.'); } } else { //no question attribute set, use common input text field $answer = "

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

      \n"; } if (trim($qidattributes['time_limit'])!='') { $js_header_includes[] = '/scripts/coookies.js'; $answer .= return_timer_script($qidattributes, $ia, "answer".$ia[1]); } $inputnames[]=$ia[1]; return array($answer, $inputnames); } function getLatLongFromIp($ip){ global $ipInfoDbAPIKey; $xml = simplexml_load_file("http://api.ipinfodb.com/v2/ip_query.php?key=$ipInfoDbAPIKey&ip=$ip&timezone=false"); if ($xml->{'Status'} == "OK"){ $lat = (float)$xml->{'Latitude'}; $lng = (float)$xml->{'Longitude'}; return(array($lat,$lng)); } else return false; } // --------------------------------------------------------------- function do_longfreetext($ia) { global $clang, $js_header_includes, $thissurvey; if ($thissurvey['nokeyboard']=='Y') { vIncludeKeypad(); $kpclass = "text-keypad"; } else { $kpclass = ""; } if ($ia[8] == 'Y') { $checkconditionFunction = "checkconditions"; } else { $checkconditionFunction = "noop_checkconditions"; } $qidattributes=getQuestionAttributes($ia[0],$ia[4]); if (trim($qidattributes['maximum_chars'])!='') { $maxsize=$qidattributes['maximum_chars']; } else { $maxsize=65525; } // --> START ENHANCEMENT - DISPLAY ROWS if (trim($qidattributes['display_rows'])!='') { $drows=$qidattributes['display_rows']; } else { $drows=5; } // <-- END ENHANCEMENT - DISPLAY ROWS // --> START ENHANCEMENT - TEXT INPUT WIDTH if (trim($qidattributes['text_input_width'])!='') { $tiwidth=$qidattributes['text_input_width']; } else { $tiwidth=40; } // <-- END ENHANCEMENT - TEXT INPUT WIDTH // --> START NEW FEATURE - SAVE $answer = '\n"; if (trim($qidattributes['time_limit'])!='') { $js_header_includes[] = '/scripts/coookies.js'; $answer .= return_timer_script($qidattributes, $ia, "answer".$ia[1]); } $inputnames[]=$ia[1]; return array($answer, $inputnames); } // --------------------------------------------------------------- function do_hugefreetext($ia) { global $clang, $js_header_includes, $thissurvey; if ($thissurvey['nokeyboard']=='Y') { vIncludeKeypad(); $kpclass = "text-keypad"; } else { $kpclass = ""; } if ($ia[8] == 'Y') { $checkconditionFunction = "checkconditions"; } else { $checkconditionFunction = "noop_checkconditions"; } $qidattributes=getQuestionAttributes($ia[0],$ia[4]); if (trim($qidattributes['maximum_chars'])!='') { $maxsize=$qidattributes['maximum_chars']; } else { $maxsize=65525; } // --> START ENHANCEMENT - DISPLAY ROWS if (trim($qidattributes['display_rows'])!='') { $drows=$qidattributes['display_rows']; } else { $drows=30; } // <-- END ENHANCEMENT - DISPLAY ROWS // --> START ENHANCEMENT - TEXT INPUT WIDTH if (trim($qidattributes['text_input_width'])!='') { $tiwidth=$qidattributes['text_input_width']; } else { $tiwidth=70; } // <-- END ENHANCEMENT - TEXT INPUT WIDTH // --> START NEW FEATURE - SAVE $answer = '\n"; if (trim($qidattributes['time_limit']) != '') { $js_header_includes[] = '/scripts/coookies.js'; $answer .= return_timer_script($qidattributes, $ia, "answer".$ia[1]); } $inputnames[]=$ia[1]; return array($answer, $inputnames); } // --------------------------------------------------------------- function do_yesno($ia) { global $clang; if ($ia[8] == 'Y') { $checkconditionFunction = "checkconditions"; } else { $checkconditionFunction = "noop_checkconditions"; } $answer = "
        \n" . "\t
      • \n START NEW FEATURE - SAVE $answer .= " onclick=\"$checkconditionFunction(this.value, this.name, this.type)" . quexs_submit_on_click() . "\" />\n\n\t
      • \n" . "\t
      • \n END NEW FEATURE - SAVE if ($_SESSION[$ia[1]] == 'N') { $answer .= CHECKED; } // --> START NEW FEATURE - SAVE $answer .= " onclick=\"$checkconditionFunction(this.value, this.name, this.type)" . quexs_submit_on_click() . "\" />\n\n\t
      • \n"; // --> END NEW FEATURE - SAVE if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { $answer .= "\t
      • \n START NEW FEATURE - SAVE $answer .= " onclick=\"$checkconditionFunction(this.value, this.name, this.type)" . quexs_submit_on_click() . "\" />\n\n\t
      • \n"; // --> END NEW FEATURE - SAVE } $answer .= "
      \n\n\n"; $inputnames[]=$ia[1]; return array($answer, $inputnames); } // --------------------------------------------------------------- function do_gender($ia) { global $clang; if ($ia[8] == 'Y') { $checkconditionFunction = "checkconditions"; } else { $checkconditionFunction = "noop_checkconditions"; } $qidattributes=getQuestionAttributes($ia[0],$ia[4]); $answer = "
        \n" . "\t
      • \n" . ' \n" . ' \n\t
      • \n"; $answer .= "\t
      • \n\n\n\t
      • \n"; if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { /* columns now done by CSS if ($dcols > 2) { $answer .= "\n\n"; } elseif ($dcols > 1) { $answer .= "\n\n"; } else { $answer .= "
        "; } */ $answer .= "\t
      • \n START NEW FEATURE - SAVE $answer .= " onclick=\"$checkconditionFunction(this.value, this.name, this.type)" . quexs_submit_on_click() . "\" />\n\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, $notanswered, $thissurvey, $clang; $inputnames=array(); if ($ia[8] == 'Y') { $checkconditionFunction = "checkconditions"; } else { $checkconditionFunction = "noop_checkconditions"; } $qidattributes=getQuestionAttributes($ia[0],$ia[4]); if (trim($qidattributes['answer_width'])!='') { $answerwidth=$qidattributes['answer_width']; } else { $answerwidth = 20; } $cellwidth = 5; // number of columns if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 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 question FROM {$dbprefix}questions WHERE parent_qid=".$ia[0]." AND question 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 ($qidattributes['random_order']==1) { $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random(); } else { $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY question_order"; } $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 .= "\n"; } if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) //Question is not mandatory { $odd_even = alternation($odd_even); $answer .= "\n"; } $answer .= "\t\n\n" . "\t\n\n" . "\t\n"; for ($xc=1; $xc<=5; $xc++) { $answer .= "\t\n"; } if ($right_exists) {$answer .= "\t\n";} if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) //Question is not mandatory { $answer .= "\t\n"; } $answer .= "\n"; $answer_t_content = ''; $trbc = ''; $n=0; //return array($answer, $inputnames); while ($ansrow = $ansresult->FetchRow()) { $myfname = $ia[1].$ansrow['title']; $answertext=dTexts::run($ansrow['question']); 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'); // Get array_filter stuff list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $qidattributes, $thissurvey, $ansrow, $myfname, $trbc, $myfname); $answer_t_content .= $htmltbody2; $answer_t_content .= "\n" . "\t\n"; for ($i=1; $i<=5; $i++) { $answer_t_content .= "\t\n"; } $answertext2=dTexts::run($ansrow['question']); if (strpos($answertext2,'|')) { $answertext2=substr($answertext2,strpos($answertext2,'|')+1); $answer_t_content .= "\t\n"; } elseif ($right_exists) { $answer_t_content .= "\t\n"; } if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { $answer_t_content .= "\t\n"; } $answer_t_content .= "\n\n\t"; $fn++; $inputnames[]=$myfname; } $answer .= $answer_t_content . "\t
       $xc ".$clang->gT('No answer')."
      \n$answertext\n" . $hiddenfield . "\n\t\n\n\t$answertext2 \n\n\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, $notanswered, $thissurvey, $clang; if ($ia[8] == 'Y') { $checkconditionFunction = "checkconditions"; } else { $checkconditionFunction = "noop_checkconditions"; } $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],$ia[4]); if (trim($qidattributes['answer_width'])!='') { $answerwidth=$qidattributes['answer_width']; } else { $answerwidth = 20; } $cellwidth = 10; // number of columns if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 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 ($qidattributes['random_order']==1) { $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random(); } else { $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY question_order"; } $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 .= "\n"; } if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) //Question is not mandatory { $odd_even = alternation($odd_even); $answer .= "\n"; } $answer .= "\t\n\n" . "\t\n\n" . "\t\n"; for ($xc=1; $xc<=10; $xc++) { $answer .= "\t\n"; } if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) //Question is not mandatory { $answer .= "\t\n"; } $answer .= "\n"; $answer_t_content = ''; $trbc = ''; while ($ansrow = $ansresult->FetchRow()) { $myfname = $ia[1].$ansrow['title']; $answertext=dTexts::run($ansrow['question']); /* 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'); //Get array filter stuff list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $qidattributes, $thissurvey, $ansrow, $myfname, $trbc, $myfname); $answer_t_content .= $htmltbody2; $answer_t_content .= "\n" . "\t\n"; for ($i=1; $i<=10; $i++) { $answer_t_content .= "\t\n"; // --> END NEW FEATURE - SAVE } if ($ia[6] != "Y" && SHOW_NO_ANSWER == 1) { $answer_t_content .= "\t\n"; } $answer_t_content .= "\n"; $inputnames[]=$myfname; $fn++; } $answer .= $answer_t_content . "\t\n
       $xc".$clang->gT('No answer')."
      \n$answertext\n" . $hiddenfield . "\n\t\n\n\t\n\n\t
      \n"; return array($answer, $inputnames); } // --------------------------------------------------------------- function do_array_yesnouncertain($ia) { global $dbprefix, $notanswered, $thissurvey, $clang; if ($ia[8] == 'Y') { $checkconditionFunction = "checkconditions"; } else { $checkconditionFunction = "noop_checkconditions"; } $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],$ia[4]); if (trim($qidattributes['answer_width'])!='') { $answerwidth=$qidattributes['answer_width']; } else { $answerwidth = 20; } $cellwidth = 3; // number of columns if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 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 ($qidattributes['random_order']==1) { $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random(); } else { $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY question_order"; } $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 .= "\n"; } if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) //Question is not mandatory { $odd_even = alternation($odd_even); $answer .= "\n"; } $answer .= "\t\n\n" . "\t\n\n" . "\t\n" . "\t\n" . "\t\n" . "\t\n"; if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) //Question is not mandatory { $answer .= "\t\n"; } $answer .= "\n\t"; $answer_t_content = ''; if ($anscount==0) { $inputnames=array(); $answer.="\t\n\n"; } else { $trbc = ''; while ($ansrow = $ansresult->FetchRow()) { $myfname = $ia[1].$ansrow['title']; $answertext=dTexts::run($ansrow['question']); /* 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'); // Get array_filter stuff list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $qidattributes, $thissurvey, $ansrow, $myfname, $trbc, $myfname); $answer_t_content .= $htmltbody2; $answer_t_content .= "\n" . "\t\n" . "\t\n" . "\t\n" . "\t\n"; if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { $answer_t_content .= "\t\n"; // --> END NEW FEATURE - SAVE } $answer_t_content .= "\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.')."
      \n" . $hiddenfield . "\t\t\t\t$answertext\n\n\t\n\n\t\n\n" . " END NEW FEATURE - SAVE if (isset($_SESSION[$myfname])) { $answer_t_content .= $_SESSION[$myfname]; } $answer_t_content .= "\" />\n\t\n\t\n\t
      \n"; return array($answer, $inputnames); } function do_array_increasesamedecrease($ia) { global $dbprefix, $thissurvey, $clang; global $notanswered; if ($ia[8] == 'Y') { $checkconditionFunction = "checkconditions"; } else { $checkconditionFunction = "noop_checkconditions"; } $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],$ia[4]); if (trim($qidattributes['answer_width'])!='') { $answerwidth=$qidattributes['answer_width']; } else { $answerwidth = 20; } $cellwidth = 3; // number of columns if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 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 ($qidattributes['random_order']==1) { $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random(); } else { $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY question_order"; } $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 .= "\n"; } if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) //Question is not mandatory { $odd_even = alternation($odd_even); $answer .= "\n"; } $answer .= "\t\n" . "\t\n" . "\n" . "\t\n" . "\t\n" . "\t\n" . "\t\n"; if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) //Question is not mandatory { $answer .= "\t\n"; } $answer .= "\n" ."\t\n"; $answer_body = ''; $trbc = ''; while ($ansrow = $ansresult->FetchRow()) { $myfname = $ia[1].$ansrow['title']; $answertext=dTexts::run($ansrow['question']); /* 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'); // Get array_filter stuff list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $qidattributes, $thissurvey, $ansrow, $myfname, $trbc, $myfname); $answer_body .= $htmltbody2; $answer_body .= "\n" . "\t\n"; $answer_body .= "\t\n" . "\t\n" . "\t\n"; if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { $answer_body .= "\t\n"; } $answer_body .= "\n\t"; $inputnames[]=$myfname; $fn++; } $answer .= $answer_body . "\t\n
       ".$clang->gT('Increase')."".$clang->gT('Same')."".$clang->gT('Decrease')."".$clang->gT('No answer')."
      \n" . "$answertext\n" . $hiddenfield . "\n\t\n" . "\n" . "\t\n" . "\n" . "\t\n" . "\n" . "\n\t\n" . "\n" . "\t
      \n"; return array($answer, $inputnames); } // --------------------------------------------------------------- function do_array($ia) { global $dbprefix, $connect, $thissurvey, $clang; global $repeatheadings; global $notanswered; global $minrepeatheadings; if (isset($ia[8]) && $ia[8] == 'Y') { $checkconditionFunction = "checkconditions"; } else { $checkconditionFunction = "noop_checkconditions"; } $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'];} $lquery = "SELECT * FROM {$dbprefix}answers WHERE qid={$ia[0]} AND language='".$_SESSION['s_lang']."' and scale_id=0 ORDER BY sortorder, code"; $qidattributes=getQuestionAttributes($ia[0],$ia[4]); if (trim($qidattributes['answer_width'])!='') { $answerwidth=$qidattributes['answer_width']; } else { $answerwidth=20; } $columnswidth=100-$answerwidth; if ($qidattributes['use_dropdown'] == 1) { $useDropdownLayout = true; } else { $useDropdownLayout = false; } $lresult = db_execute_assoc($lquery); //Checked if ($useDropdownLayout === false && $lresult->RecordCount() > 0) { while ($lrow=$lresult->FetchRow()) { $labelans[]=$lrow['answer']; $labelcode[]=$lrow['code']; } // $cellwidth=sprintf('%02d', $cellwidth); $ansquery = "SELECT question FROM {$dbprefix}questions WHERE parent_qid={$ia[0]} AND question 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 ($qidattributes['random_order']==1) { $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid={$ia[0]} AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random(); } else { $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid={$ia[0]} AND language='".$_SESSION['s_lang']."' ORDER BY question_order"; } $ansresult = db_execute_assoc($ansquery); //Checked $anscount = $ansresult->RecordCount(); $fn=1; $numrows = count($labelans); if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { ++$numrows; } if ($right_exists) { ++$numrows; } $cellwidth = round( ($columnswidth / $numrows ) , 1 ); $answer_start = "\n\n"; $answer_head = "\t\n" . "\n" . "\t\n"; foreach ($labelans as $ld) { $answer_head .= "\t\n"; } if ($right_exists) {$answer_head .= "\t\n";} if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) //Question is not mandatory and we can show "no answer" { $answer_head .= "\t\n"; } $answer_head .= "\n\t\n\n\t\n"; $answer = ''; $trbc = ''; $inputnames=array(); while ($ansrow = $ansresult->FetchRow()) { if (isset($repeatheadings) && $repeatheadings > 0 && ($fn-1) > 0 && ($fn-1) % $repeatheadings == 0) { if ( ($anscount - $fn + 1) >= $minrepeatheadings ) { $answer .= "\n" . "\t\n"; foreach ($labelans as $ld) { $answer .= "\t\n"; } if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) //Question is not mandatory and we can show "no answer" { $answer .= "\t\n"; } $answer .= "\n"; } } $myfname = $ia[1].$ansrow['title']; $answertext=dTexts::run($ansrow['question']); $answertextsave=$answertext; 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 (strpos($answertext,'|')) {$answerwidth=$answerwidth/2;} if ((is_array($notanswered)) && (array_search($ia[1], $notanswered) !== FALSE) && ($_SESSION[$myfname] == '') ) { $answertext = ''.$answertext.''; } // Get array_filter stuff list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $qidattributes, $thissurvey, $ansrow, $myfname, $trbc, $myfname); $row_selected = return_array_filter_selected($ia, $qidattributes, $thissurvey, $ansrow, $myfname, $trbc, $myfname); if($row_selected) { $trbc = alternation($trbc , 'row'); $fn++; } $answer .= $htmltbody2; $answer .= "\n" . "\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\n"; } elseif ($right_exists) { $answer .= "\t\n"; } if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { $answer .= "\t\n"; // --> END NEW FEATURE - SAVE } $answer .= "\n"; $inputnames[]=$myfname; //IF a MULTIPLE of flexi-redisplay figure, repeat the headings } $answer_cols = "\t\n" ."\t\n" ; $odd_even = ''; foreach ($labelans as $c) { $odd_even = alternation($odd_even); $answer_cols .= "\n"; } if ($right_exists) { $odd_even = alternation($odd_even); $answer_cols .= "\n"; } if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) //Question is not mandatory { $odd_even = alternation($odd_even); $answer_cols .= "\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$answertext" . $hiddenfield . "\n\t\n" . "\n" . "\t$answertext \n\n\t
      \n"; } elseif ($useDropdownLayout === true && $lresult->RecordCount() > 0) { while ($lrow=$lresult->FetchRow()) $labels[]=Array('code' => $lrow['code'], 'answer' => $lrow['answer']); $ansquery = "SELECT question FROM {$dbprefix}questions WHERE parent_qid={$ia[0]} AND question 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 ($qidattributes['random_order']==1) { $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid={$ia[0]} AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random(); } else { $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid={$ia[0]} AND language='".$_SESSION['s_lang']."' ORDER BY question_order"; } $ansresult = db_execute_assoc($ansquery); //Checked $anscount = $ansresult->RecordCount(); $fn=1; $numrows = count($labels); if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { ++$numrows; } if ($right_exists) { ++$numrows; } $cellwidth = round( ($columnswidth / $numrows ) , 1 ); $answer_start = "\n\n"; $answer = "\t\n"; $trbc = ''; $inputnames=array(); while ($ansrow = $ansresult->FetchRow()) { $myfname = $ia[1].$ansrow['title']; $trbc = alternation($trbc , 'row'); $answertext=answer_replace($ansrow['question']); $answertextsave=$answertext; 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 (strpos($answertext,'|')) {$answerwidth=$answerwidth/2;} if ((is_array($notanswered)) && (array_search($ia[1], $notanswered) !== FALSE) && ($_SESSION[$myfname] == '') ) { $answertext = ''.$answertext.''; } // Get array_filter stuff list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $qidattributes, $thissurvey, $ansrow, $myfname, $trbc, $myfname); $answer .= $htmltbody2; $answer .= "\n" . "\t\n"; $answer .= "\t\n"; } elseif ($right_exists) { $answer .= "\t\n"; } $answer .= "\n"; $inputnames[]=$myfname; //IF a MULTIPLE of flexi-redisplay figure, repeat the headings $fn++; } $answer = $answer_start . $answer . "\t\n
      \n$answertext" . $hiddenfield . "\n\t\n" . "\n"; if (strpos($answertextsave,'|')) { $answertext=substr($answertextsave,strpos($answertextsave,'|')+1); $answer .= "\t$answertext 
      \n"; } else { $answer = "\n

      ".$clang->gT("Error: There are no answer options for this question and/or they don't exist in this language.")."

      \n"; $inputnames=''; } return array($answer, $inputnames); } // --------------------------------------------------------------- function do_array_multitext($ia) { global $dbprefix, $connect, $thissurvey, $clang; global $repeatheadings; global $notanswered; global $minrepeatheadings; if ($thissurvey['nokeyboard']=='Y') { vIncludeKeypad(); $kpclass = "text-keypad"; } else { $kpclass = ""; } if ($ia[8] == 'Y') { $checkconditionFunction = "checkconditions"; } else { $checkconditionFunction = "noop_checkconditions"; } //echo "
      "; print_r($_POST); echo "
      "; $defaultvaluescript = ""; $qquery = "SELECT other FROM {$dbprefix}questions WHERE qid={$ia[0]} AND language='".$_SESSION['s_lang']."'"; $qresult = db_execute_assoc($qquery); while($qrow = $qresult->FetchRow()) {$other = $qrow['other'];} $qidattributes=getQuestionAttributes($ia[0],$ia[4]); $show_grand = $qidattributes['show_grand_total']; $totals_class = ''; $num_class = ''; $show_totals = ''; $col_total = ''; $row_total = ''; $total_col = ''; $col_head = ''; $row_head = ''; $grand_total = ''; $q_table_id = ''; $q_table_id_HTML = ''; $numbersonly = ''; if ($qidattributes['numbers_only']==1) { $q_table_id = 'totals_'.$ia[0]; $q_table_id_HTML = ' id="'.$q_table_id.'"'; // $numbersonly = 'onkeypress="return goodchars(event,\'-0123456789.\')"'; $num_class = ' numbers-only'; switch ($qidattributes['show_totals']) { case 'R': $totals_class = $show_totals = 'row'; $row_total = ' '; $col_head = ' Total'; if($show_grand == true) { $row_head = ' Grand total'; $col_total = '  '; $grand_total = ' '; }; break; case 'C': $totals_class = $show_totals = 'col'; $col_total = ' '; $row_head = ' Total'; if($show_grand == true) { $row_total = '  '; $col_head = ' Grand Total'; $grand_total = ' '; }; break; case 'B': $totals_class = $show_totals = 'both'; $row_total = ' '; $col_total = ' '; $col_head = ' Total'; $row_head = ' Total'; if($show_grand == true) { $grand_total = ' '; } else { $grand_total = '  '; }; break; }; if(!empty($totals_class)) { $totals_class = ' show-totals '.$totals_class; if($qidattributes['show_grand_total']) { $totals_class .= ' grand'; $show_grand = true; }; }; } else { $numbersonly = ''; }; if (trim($qidattributes['answer_width'])!='') { $answerwidth=$qidattributes['answer_width']; } else { $answerwidth=20; }; if (trim($qidattributes['text_input_width'])!='') { $inputwidth=$qidattributes['text_input_width']; } else { $inputwidth = 20; } $columnswidth=100-($answerwidth*2); $lquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid={$ia[0]} AND language='".$_SESSION['s_lang']."' and scale_id=1 ORDER BY question_order"; $lresult = db_execute_assoc($lquery); if ($lresult->RecordCount() > 0) { while ($lrow=$lresult->FetchRow()) { $labelans[]=$lrow['question']; $labelcode[]=$lrow['title']; } $numrows=count($labelans); if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) {$numrows++;} if( ($show_grand == true && $show_totals == 'col' ) || $show_totals == 'row' || $show_totals == 'both' ) { ++$numrows; }; $cellwidth=$columnswidth/$numrows; $cellwidth=sprintf('%02d', $cellwidth); $ansquery = "SELECT count(question) FROM {$dbprefix}questions WHERE parent_qid={$ia[0]} and scale_id=0 AND question like '%|%'"; $ansresult = $connect->GetOne($ansquery); if ($ansresult>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 ($qidattributes['random_order']==1) { $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] and scale_id=0 AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random(); } else { $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] and scale_id=0 AND language='".$_SESSION['s_lang']."' ORDER BY question_order"; } $ansresult = db_execute_assoc($ansquery); $anscount = $ansresult->RecordCount(); $fn=1; $answer_cols = "\t\n" ."\n\t\t\n"; $answer_head = "\n\t\n" . "\t\t\n" . "\t\t\t \n"; $odd_even = ''; foreach ($labelans as $ld) { $answer_head .= "\t".$ld."\n"; $odd_even = alternation($odd_even); $answer_cols .= "\n"; } if ($right_exists) { $answer_head .= "\t \n";// class=\"answertextright\" $odd_even = alternation($odd_even); $answer_cols .= "\n"; } if( ($show_grand == true && $show_totals == 'col' ) || $show_totals == 'row' || $show_totals == 'both' ) { $answer_head .= $col_head; $odd_even = alternation($odd_even); $answer_cols .= "\t\t\n"; }; $answer_cols .= "\t\n"; $answer_head .= "\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 .= "\n\n" . "\t \n"; foreach ($labelans as $ld) { $answer .= "\t".$ld."\n"; } $answer .= "\n\n"; } } $myfname = $ia[1].$ansrow['title']; $answertext=dTexts::run($ansrow['question']); $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}"; } } // Get array_filter stuff list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $qidattributes, $thissurvey, $ansrow, $myfname, $trbc, $myfname); $answer .= $htmltbody2; if (strpos($answertext,'|')) {$answertext=substr($answertext,0, strpos($answertext,'|'));} $trbc = alternation($trbc , 'row'); $answer .= "\t\t\n" . "\t\t\t\n" . "\t\t\t\t".$hiddenfield . "$answertext\n" . "\t\t\t\t\n\t\t\t\n"; $thiskey=0; foreach ($labelcode as $ld) { $myfname2=$myfname."_$ld"; $myfname2value = isset($_SESSION[$myfname2]) ? $_SESSION[$myfname2] : ""; $answer .= "\t\n" . "\t\t\t\t\n\t\t\t\n"; $thiskey += 1; } if (strpos($answertextsave,'|')) { $answertext=substr($answertextsave,strpos($answertextsave,'|')+1); $answer .= "\t\t\t$answertext\n"; } elseif ($right_exists) { $answer .= "\t\t\t \n"; } $answer .= str_replace(array('[[ROW_NAME]]','[[INPUT_WIDTH]]') , array(strip_tags($answertext),$inputwidth) , $row_total); $answer .= "\n\t\t\n"; $answer .= "\n"; //IF a MULTIPLE of flexi-redisplay figure, repeat the headings $fn++; } if($show_totals == 'col' || $show_totals = 'both' || $grand_total == true) { $answer .= "\t\t$row_head"; for( $a = 0; $a < count($labelcode) ; ++$a ) { $answer .= str_replace(array('[[ROW_NAME]]','[[INPUT_WIDTH]]') , array(strip_tags($answertext),$inputwidth) , $col_total); }; $answer .= str_replace(array('[[ROW_NAME]]','[[INPUT_WIDTH]]') , array(strip_tags($answertext),$inputwidth) , $grand_total)."\n\t\t\n"; }; $answer .= "\t\n\n"; if(!empty($q_table_id)) { $answer .= "\n\n"; }; } else { $answer = "\n

      ".$clang->gT("Error: There are no answer options for this question and/or they don't exist in this language.")."

      \n"; $inputnames=''; } return array($answer, $inputnames); } // --------------------------------------------------------------- function do_array_multiflexi($ia) { global $dbprefix, $connect, $thissurvey, $clang; global $repeatheadings; global $notanswered; global $minrepeatheadings; if ($ia[8] == 'Y') { $checkconditionFunction = "checkconditions"; } else { $checkconditionFunction = "noop_checkconditions"; } //echo '
      '; print_r($_POST); echo '
      '; $defaultvaluescript = ''; $qquery = "SELECT other FROM {$dbprefix}questions WHERE qid=".$ia[0]." AND language='".$_SESSION['s_lang']."' and parent_qid=0"; $qresult = db_execute_assoc($qquery); while($qrow = $qresult->FetchRow()) {$other = $qrow['other'];} $qidattributes=getQuestionAttributes($ia[0],$ia[4]); if (trim($qidattributes['multiflexible_max'])!='' && trim($qidattributes['multiflexible_min']) ==''){ $maxvalue=$qidattributes['multiflexible_max']; if(isset($minvalue['value']) && $minvalue['value'] == 0) {$minvalue = 0;} else {$minvalue=1;} } if (trim($qidattributes['multiflexible_min'])!='' && trim($qidattributes['multiflexible_max']) ==''){ $minvalue=$qidattributes['multiflexible_min']; $maxvalue=$qidattributes['multiflexible_min'] + 10; } if (trim($qidattributes['multiflexible_min'])=='' && trim($qidattributes['multiflexible_max']) ==''){ if(isset($minvalue['value']) && $minvalue['value'] == 0) {$minvalue = 0;} else {$minvalue=1;} $maxvalue=10; } if (trim($qidattributes['multiflexible_min']) !='' && trim($qidattributes['multiflexible_max']) !=''){ if($qidattributes['multiflexible_min'] < $qidattributes['multiflexible_max']){ $minvalue=$qidattributes['multiflexible_min']; $maxvalue=$qidattributes['multiflexible_max']; } } if (trim($qidattributes['multiflexible_step'])!='' && $qidattributes['multiflexible_step'] > 0) { $stepvalue=$qidattributes['multiflexible_step']; } else { $stepvalue=1; } if($qidattributes['reverse']==1) { $tmp = $minvalue; $minvalue = $maxvalue; $maxvalue = $tmp; $reverse=true; $stepvalue=-$stepvalue; } else { $reverse=false; } $checkboxlayout=false; if ($qidattributes['multiflexible_checkbox']!=0) { $minvalue=0; $maxvalue=1; $checkboxlayout=true; } $inputboxlayout=false; if ($qidattributes['input_boxes']!=0) { $inputboxlayout=true; } if (trim($qidattributes['maximum_chars'])!='') { $maxsize=$qidattributes['maximum_chars']; } else { $maxsize=255; } if ($thissurvey['nokeyboard']=='Y') { vIncludeKeypad(); $kpclass = "num-keypad"; } else { $kpclass = ""; } if (trim($qidattributes['answer_width'])!='') { $answerwidth=$qidattributes['answer_width']; } else { $answerwidth=20; } $columnswidth=100-($answerwidth*2); $lquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid={$ia[0]} AND language='".$_SESSION['s_lang']."' and scale_id=1 ORDER BY question_order"; $lresult = db_execute_assoc($lquery); if ($lresult->RecordCount() > 0) { while ($lrow=$lresult->FetchRow()) { $labelans[]=$lrow['question']; $labelcode[]=$lrow['title']; } $numrows=count($labelans); if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) {$numrows++;} $cellwidth=$columnswidth/$numrows; $cellwidth=sprintf('%02d', $cellwidth); $ansquery = "SELECT question FROM {$dbprefix}questions WHERE parent_qid=".$ia[0]." AND scale_id=0 AND question 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 ($qidattributes['random_order']==1) { $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND scale_id=0 AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random(); } else { $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND scale_id=0 AND language='".$_SESSION['s_lang']."' ORDER BY question_order"; } $ansresult = db_execute_assoc($ansquery); $anscount = $ansresult->RecordCount(); $fn=1; $mycols = "\t\n" . "\n\t\n"; $myheader = "\n\t\n" . "\n" . "\t \n"; $odd_even = ''; foreach ($labelans as $ld) { $myheader .= "\t".$ld."\n"; $odd_even = alternation($odd_even); $mycols .= "\n"; } if ($right_exists) { $myheader .= "\t "; $odd_even = alternation($odd_even); $mycols .= "\n"; } $myheader .= "\n" . "\t\n"; $mycols .= "\t\n"; $trbc = ''; $answer = "\n\n" . $mycols . $myheader . "\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 .= "\n\n" . "\t\n"; foreach ($labelans as $ld) { $answer .= "\t\n"; } $answer .= "\n\n"; } } $myfname = $ia[1].$ansrow['title']; $answertext=dTexts::run($ansrow['question']); $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.''; } } // Get array_filter stuff list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $qidattributes, $thissurvey, $ansrow, $myfname, $trbc, $myfname); $answer .= $htmltbody2; if (strpos($answertext,'|')) {$answertext=substr($answertext,0, strpos($answertext,'|'));} $trbc = alternation($trbc , 'row'); $answer .= "\n" . "\t\n"; $first_hidden_field = ''; $thiskey=0; foreach ($labelcode as $ld) { if ($checkboxlayout == false) { $myfname2=$myfname."_$ld"; if(isset($_SESSION[$myfname2])) { $myfname2_java_value = " value=\"$_SESSION[$myfname2]\" "; } else { $myfname2_java_value = ""; } $answer .= "\t\n"; $inputnames[]=$myfname2; $thiskey++; } else { $myfname2=$myfname."_$ld"; if(isset($_SESSION[$myfname2]) && $_SESSION[$myfname2] == '1') { $myvalue = '1'; $setmyvalue = CHECKED; } else { $myvalue = '0'; $setmyvalue = ''; } $answer .= "\t\n"; $thiskey++; } } if (strpos($answertextsave,'|')) { $answertext=substr($answertextsave,strpos($answertextsave,'|')+1); $answer .= "\t\n"; } elseif ($right_exists) { $answer .= "\t\n"; } $answer .= "\n\t"; //IF a MULTIPLE of flexi-redisplay figure, repeat the headings $fn++; } $answer .= "\n
       ".$ld."
      \n" . "$answertext\n" . $hiddenfield . "\n\t\n" . "\n" // . "\n" $answer .= "" . "\t$answertext 
      \n"; } else { $answer = "\n

      ".$clang->gT("Error: There are no answer options for this question and/or they don't exist in this language.")."

      \n"; $inputnames = ''; } return array($answer, $inputnames); } // --------------------------------------------------------------- function do_arraycolumns($ia) { global $dbprefix; global $notanswered, $clang; if ($ia[8] == 'Y') { $checkconditionFunction = "checkconditions"; } else { $checkconditionFunction = "noop_checkconditions"; } $qidattributes=getQuestionAttributes($ia[0],$ia[4]); $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'];} $lquery = "SELECT * FROM {$dbprefix}answers WHERE qid=".$ia[0]." AND language='".$_SESSION['s_lang']."' and scale_id=0 ORDER BY sortorder, code"; $lresult = db_execute_assoc($lquery); //Checked if ($lresult->RecordCount() > 0) { while ($lrow=$lresult->FetchRow()) { $labelans[]=$lrow['answer']; $labelcode[]=$lrow['code']; $labels[]=array("answer"=>$lrow['answer'], "code"=>$lrow['code']); } if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { $labelcode[]=''; $labelans[]=$clang->gT('No answer'); $labels[]=array('answer'=>$clang->gT('No answer'), 'code'=>''); } if ($qidattributes['random_order']==1) { $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random(); } else { $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY question_order"; } $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 .= "\n"; } $answer .= "\t\n\n" . "\t\n" . "\n" . "\t\n"; while ($ansrow = $ansresult->FetchRow()) { $anscode[]=$ansrow['title']; $answers[]=dTexts::run($ansrow['question']); } $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\n"; } unset($trbc); $answer .= "\n\t\n\n\t\n"; $ansrowcount=0; $ansrowtotallength=0; while ($ansrow = $ansresult->FetchRow()) { $ansrowcount++; $ansrowtotallength=$ansrowtotallength+strlen($ansrow['question']); } $percwidth=100 - ($cellwidth*$anscount); foreach($labels as $ansrow) { $answer .= "\n" . "\t\n"; foreach ($anscode as $ld) { //if (!isset($trbc) || $trbc == 'array1') {$trbc = 'array2';} else {$trbc = 'array1';} $myfname=$ia[1].$ld; $answer .= "\t\n"; } unset($trbc); $answer .= "\n"; $fn++; } $answer .= "\t\n
       $ld
      {$ansrow['answer']}\n" . "\n\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: There are no answer options for this question and/or they don't exist in this language.")."

      \n"; $inputnames = ''; } return array($answer, $inputnames); } // --------------------------------------------------------------- function do_array_dual($ia) { global $dbprefix, $connect, $thissurvey, $clang; global $repeatheadings; global $notanswered; global $minrepeatheadings; if ($ia[8] == 'Y') { $checkconditionFunction = "checkconditions"; } else { $checkconditionFunction = "noop_checkconditions"; } $inputnames=array(); $labelans1=array(); $labelans=array(); $qquery = "SELECT other FROM {$dbprefix}questions WHERE qid=".$ia[0]." AND language='".$_SESSION['s_lang']."'"; $other = $connect->GetOne($qquery); //Checked $lquery = "SELECT * FROM {$dbprefix}answers WHERE scale_id=0 AND qid={$ia[0]} AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, code"; $lquery1 = "SELECT * FROM {$dbprefix}answers WHERE scale_id=1 AND qid={$ia[0]} AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, code"; $qidattributes=getQuestionAttributes($ia[0],$ia[4]); if ($qidattributes['use_dropdown']==1) { $useDropdownLayout = true; } else { $useDropdownLayout = false; } if (trim($qidattributes['dualscale_headerA'])!='') { $leftheader= $clang->gT($qidattributes['dualscale_headerA']); } else { $leftheader =''; } if (trim($qidattributes['dualscale_headerB'])!='') { $rightheader= $clang->gT($qidattributes['dualscale_headerB']); } else { $rightheader =''; } $lresult = db_execute_assoc($lquery); //Checked if ($useDropdownLayout === false && $lresult->RecordCount() > 0) { if (trim($qidattributes['answer_width'])!='') { $answerwidth=$qidattributes['answer_width']; } else { $answerwidth=20; } $columnswidth = 100 - $answerwidth; while ($lrow=$lresult->FetchRow()) { $labelans[]=$lrow['answer']; $labelcode[]=$lrow['code']; } $lresult1 = db_execute_assoc($lquery1); //Checked if ($lresult1->RecordCount() > 0) { while ($lrow1=$lresult1->FetchRow()) { $labelans1[]=$lrow1['answer']; $labelcode1[]=$lrow1['code']; } } $numrows=count($labelans) + count($labelans1); if ($ia[6] != "Y" && SHOW_NO_ANSWER == 1) {$numrows++;} $cellwidth=$columnswidth/$numrows; $cellwidth=sprintf("%02d", $cellwidth); $ansquery = "SELECT question FROM {$dbprefix}questions WHERE parent_qid=".$ia[0]." and scale_id=0 AND question 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 ($qidattributes['random_order']==1) { $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' and scale_id=0 ORDER BY ".db_random(); } else { $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' and scale_id=0 ORDER BY question_order"; } $ansresult = db_execute_assoc($ansquery); //Checked $anscount = $ansresult->RecordCount(); $fn=1; // unselect second scale when using "no answer" $answer = "\n"; // Header row and colgroups $mycolumns = "\t\n" ."\t\n"; $myheader2 = "\n\n" . "\t \n\n"; $odd_even = ''; foreach ($labelans as $ld) { $myheader2 .= "\t".$ld."\n"; $odd_even = alternation($odd_even); $mycolumns .= "\n"; } $mycolumns .= "\t\n"; if (count($labelans1)>0) // if second label set is used { $mycolumns .= "\t\n" . "\t\n"; $myheader2 .= "\n\t \n\n"; // Separator foreach ($labelans1 as $ld) { $myheader2 .= "\t".$ld."\n"; $odd_even = alternation($odd_even); $mycolumns .= "\n"; } } if ($right_exists) { $myheader2 .= "\t \n"; $mycolumns .= "\n\t\n\n"; } if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) //Question is not mandatory and we can show "no answer" { $myheader2 .= "\t \n"; // Separator $myheader2 .= "\t".$clang->gT('No answer')."\n"; $odd_even = alternation($odd_even); $mycolumns .= "\n\t\n\n"; $mycolumns .= "\t\n"; } $mycolumns .= "\t\n"; $myheader2 .= "\n"; // build first row of header if needed if ($leftheader != '' || $rightheader !='') { $myheader1 = "\n" . "\t \n" . "\t$leftheader\n"; if (count($labelans1)>0) { $myheader1 .= "\t \n" // Separator ."\t$rightheader\n"; } if ($right_exists) { $myheader1 .= "\t \n"; } if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { $myheader1 .= "\t \n"; // Separator $myheader1 .= "\t \n"; } $myheader1 .= "\n"; } else { $myheader1 = ''; } $answer .= "\n\n" . $mycolumns . "\n\t\n" . $myheader1 . $myheader2 . "\n\t\n"; $trbc = ''; while ($ansrow = $ansresult->FetchRow()) { // Build repeat headings if needed if (isset($repeatheadings) && $repeatheadings > 0 && ($fn-1) > 0 && ($fn-1) % $repeatheadings == 0) { if ( ($anscount - $fn + 1) >= $minrepeatheadings ) { $answer .= "\n\n" . "\t\n"; foreach ($labelans as $ld) { $answer .= "\t\n"; } if (count($labelans1)>0) // if second label set is used { $answer .= "\n"; // Separator foreach ($labelans1 as $ld) { $answer .= "\t\n"; } } if ($right_exists) { $answer .= "\t\n"; } if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) //Question is not mandatory and we can show "no answer" { $answer .= "\t\n"; // Separator $answer .= "\t\n"; } $answer .= "\n\n"; } } $trbc = alternation($trbc , 'row'); $answertext=dTexts::run($ansrow['question']); $answertextsave=$answertext; $dualgroup=0; $myfname0= $ia[1].$ansrow['title']; $myfname = $ia[1].$ansrow['title'].'#0'; $myfname1 = $ia[1].$ansrow['title'].'#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}"; } // Get array_filter stuff list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $qidattributes, $thissurvey, $ansrow, $myfname0, $trbc, $myfname); $answer .= $htmltbody2; if (strpos($answertext,'|')) {$answertext=substr($answertext,0, strpos($answertext,'|'));} array_push($inputnames,$myfname); $answer .= "\n" . "\t\n"; $hiddenanswers=''; $thiskey=0; foreach ($labelcode as $ld) { $answer .= "\t\n"; $thiskey++; } if (count($labelans1)>0) // if second label set is used { $dualgroup++; $hiddenanswers=''; $answer .= "\t\n"; // separator array_push($inputnames,$myfname1); $hiddenanswers .= "\n"; $thiskey=0; foreach ($labelcode1 as $ld) // second label set { $answer .= "\t\n"; $thiskey++; } } if (strpos($answertextsave,'|')) { $answertext=substr($answertextsave,strpos($answertextsave,'|')+1); $answer .= "\t\n"; $hiddenanswers = ''; } elseif ($right_exists) { $answer .= "\t\n"; } if ($ia[6] != "Y" && SHOW_NO_ANSWER == 1) { $answer .= "\t\n"; // separator $answer .= "\t\n"; // --> END NEW FEATURE - SAVE } $answer .= "\n"; $answer .= "\t\n"; // $inputnames[]=$myfname; //IF a MULTIPLE of flexi-redisplay figure, repeat the headings $fn++; } $answer .= "
       ".$ld." ".$ld."  ".$clang->gT('No answer')."
      \n" . $hiddenfield . "$answertext\n" . "\n\t\n" . "\n"; // --> END NEW FEATURE - SAVE $answer .= "\n\t \n"; if ($hiddenanswers!='') { $answer .=$hiddenanswers; $hiddenanswers=''; } $answer .= "\n"; // --> END NEW FEATURE - SAVE $answer .= "\t$answertext  \n" . "\n" . "\t
      \n"; } elseif ($useDropdownLayout === true && $lresult->RecordCount() > 0) { if (trim($qidattributes['answer_width'])!='') { $answerwidth=$qidattributes['answer_width']; } else { $answerwidth=20; } $separatorwidth=(100-$answerwidth)/10; $columnswidth=100-$answerwidth-($separatorwidth*2); $answer = ""; // Get Answers //question atribute random_order set? if ($qidattributes['random_order']==1) { $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] and scale_id=0 AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random(); } //no question attributes -> order by sortorder else { $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] and scale_id=0 AND language='".$_SESSION['s_lang']."' ORDER BY question_order"; } $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['answer']); } $lresult1 = db_execute_assoc($lquery1); //Checked while ($lrow1=$lresult1->FetchRow()) { $labels1[]=Array('code' => $lrow1['code'], 'title' => $lrow1['answer']); } // Get attributes for Headers and Prefix/Suffix if (trim($qidattributes['dropdown_prepostfix'])!='') { list ($ddprefix, $ddsuffix) =explode("|",$qidattributes['dropdown_prepostfix']); $ddprefix = $ddprefix; $ddsuffix = $ddsuffix; } else { $ddprefix =''; $ddsuffix=''; } if (trim($qidattributes['dropdown_separators'])!='') { list ($postanswSep, $interddSep) =explode('|',$qidattributes['dropdown_separators']); $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\n"; // suffix } $answer .= "\t\n"; if($ddprefix != '') { $answer .= "\t\n"; } $answer .= "\t\n"; if($ddsuffix != '') { $answer .= "\t\n"; }; // headers $answer .= "\n\t\n" . "\n" . "\t \n" // prefix . "\n" // . "\t\n" . "\t\n" . "\n" . "\t \n" // suffix // Inter DD separator // prefix // . "\t\n" . "\t\n" . $suffix_cell."\n" . "\t\n\n"; $trbc = ''; while ($ansrow = $ansresult->FetchRow()) { $rowname = $ia[1].$ansrow['title']; $dualgroup=0; $myfname = $ia[1].$ansrow['title']."#".$dualgroup; $dualgroup1=1; $myfname1 = $ia[1].$ansrow['title']."#".$dualgroup1; if ((is_array($notanswered)) && (array_search($ia[1], $notanswered) !== FALSE) && ($_SESSION[$myfname] == "" || $_SESSION[$myfname1] == "") ) { $answertext="".dTexts::run($ansrow['question']).""; } else { $answertext=dTexts::run($ansrow['question']); } $trbc = alternation($trbc , 'row'); // Get array_filter stuff list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $qidattributes, $thissurvey, $ansrow, $rowname, $trbc, $myfname); $answer .= $htmltbody2; $answer .= "\n" . "\t\n"; // Label0 // prefix if($ddprefix != '') { $answer .= "\t\n"; } $answer .= "\t\n"; } $answer .= "\n" . "\t\n"; $inputnames[]=$myfname; $answer .= "\t\n"; //Separator // Label1 // prefix if($ddprefix != '') { $answer .= "\t\n"; } // $answer .= "\t\n"; } $answer .= "\n" . "\t\n"; $inputnames[]=$myfname1; $answer .= "\n"; $answer .= "\t\n"; } } // End there are answers $answer .= "
       
      $leftheader$leftheader$rightheader$rightheader
      \n" . "\n" . "\t$ddprefix\n" . "\n"; // suffix if($ddsuffix != '') { $answer .= "\t$ddsuffix$interddSep$ddprefix\n" $answer .= "\t\n" . "\n"; // suffix if($ddsuffix != '') { $answer .= "\t$ddsuffix
      \n"; } else { $answer = "

      ".$clang->gT("Error: There are no answer options for this question and/or they don't exist in this language.")."

      \n"; $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, $_SESSION['dateformats']['phpdate']); $text=str_replace($replace, $replace3, $text); } //while return $text; } // Closing PHP tag intentionally left out - yes, it is okay