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', ''); "; $interviewer=returnglobal('interviewer'); if (!empty($interviewer) || (isset($_SESSION['interviewer']) && $_SESSION['interviewer'] == true)) { $interviewer = true; } else { $interviewer = false; } if (LIME_AUTO_ADVANCE && $do && $interviewer) { $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; } /** * 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) { //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]; $inputnames=array(); // TMSW - eliminate this - get from LEM //A bit of housekeeping to stop PHP Notices $answer = ""; if (!isset($_SESSION[$ia[1]])) {$_SESSION[$ia[1]] = "";} $qidattributes=getQuestionAttributes($ia[0],$ia[4]); //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] : ''; // TMSW - populate this directly from LEM? - this this is global $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."); } 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'); } } 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'); } } break; case '|': //File Upload $values=do_file_upload($ia); 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; case '*': // Equation $values=do_equation($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; } if ($ia[6] == 'Y') { $qtitle = ''.$clang->gT('*').''.$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 if (($_SESSION['step'] != $_SESSION['maxstep']) || ($_SESSION['step'] == $_SESSION['prevstep']) && returnglobal('action')!='previewquestion' && returnglobal('action')!='previewgroup') { $mandatory_msg = mandatory_message($ia); } else { $mandatory_msg = ''; } $qtitle .= $mandatory_msg; $question_text['man_message'] = $mandatory_msg; if (!isset($qidattributes['hide_tip']) || $qidattributes['hide_tip']==0) { $_vshow = true; // whether should initially be visible - TODO should also depend upon 'hidetip'? } else { $_vshow = false; } list($validation_msg,$isValid) = validation_message($ia,$_vshow); $qtitle .= $validation_msg; $question_text['valid_message'] = $validation_msg; if (($_SESSION['step'] != $_SESSION['maxstep']) || ($_SESSION['step'] == $_SESSION['prevstep'])) { $file_validation_msg = file_validation_message($ia); } else { $file_validation_msg = ''; $isValid = true; // don't want to show any validation messages. } $qtitle .= $ia[4] == "|" ? $file_validation_msg : ""; $question_text['file_valid_message'] = $ia[4] == "|" ? $file_validation_msg : ""; if(!empty($question_text['man_message']) || !$isValid || !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; }; $question_text['all'] = $qtitle_custom; } else { $question_text['all'] = $qtitle; }; // END: legacy question_start.pstpl code //=================================================================== $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) { $qinfo = LimeExpressionManager::GetQuestionStatus($ia[0]); if ($qinfo['mandViolation']) { return $qinfo['mandTip']; } else { return ""; } } /** * * @param $ia * @param $show - true if should initially be visible * @return */ function validation_message($ia,$show) { $qinfo = LimeExpressionManager::GetQuestionStatus($ia[0]); $class = "questionhelp"; if (!$show) { $class .= ' hide-tip'; } $tip = '' . $qinfo['validTip'] . ""; $isValid = $qinfo['valid']; return array($tip,$isValid); } // TMSW Validation -> EM 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; } // TMSW Mandatory -> EM function mandatory_popup($ia, $notanswered=null) { global $showpopups; //This sets the mandatory popup message to show if required if ($notanswered === null) {unset($notanswered);} if (isset($notanswered) && $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; } } // TMSW Validation -> EM function validation_popup($ia, $notvalidated=null) { global $showpopups; //This sets the validation popup message to show if required if ($notvalidated === null) {unset($notvalidated);} $qtitle=""; if (isset($notvalidated) && $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; } } // TMSW Validation -> EM 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_strings($ia, $qidattributes, $thissurvey, $ansrow, $rowname, $trbc='', $valuename, $method="tbody", $class=null) { $htmltbody2 = "\n\n\t<$method id='javatbd$rowname'"; $htmltbody2 .= ($class !== null) ? " class='$class'": ""; if (isset($_SESSION['relevanceStatus'][$rowname]) && !$_SESSION['relevanceStatus'][$rowname]) { // If using exclude_all_others, then need to know whether irrelevant rows should be hidden or disabled if (isset($qidattributes['exclude_all_others'])) { $disableit=false; foreach(explode(';',trim($qidattributes['exclude_all_others'])) as $eo) { $eorow = $ia[1] . $eo; if ((!isset($_SESSION['relevanceStatus'][$eorow]) || $_SESSION['relevanceStatus'][$eorow]) && (isset($_SESSION[$eorow]) && $_SESSION[$eorow] == "Y")) { $disableit = true; } } if ($disableit) { $htmltbody2 .= " disabled='disabled'"; } else { if (!isset($qidattributes['array_filter_style']) || $qidattributes['array_filter_style'] == '0') { $htmltbody2 .= " style='display: none'"; } else { $htmltbody2 .= " disabled='disabled'"; } } } else { if (!isset($qidattributes['array_filter_style']) || $qidattributes['array_filter_style'] == '0') { $htmltbody2 .= " style='display: none'"; } else { $htmltbody2 .= " disabled='disabled'"; } } } $htmltbody2 .= ">\n"; return array($htmltbody2, ""); } // ================================================================== // 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_equation($ia) { $answer=''; $inputnames[]=$ia[1]; $mandatory=null; return array($answer, $inputnames); } // --------------------------------------------------------------- function do_5pointchoice($ia) { global $clang, $imageurl; global $js_header_includes, $css_header_includes; $checkconditionFunction = "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'; // write the alternative HTML only for activated javascript $answer.=" "; $answer.=" "; } if($qidattributes['slider_rating']==2){ if(!IsSet($_SESSION[$ia[1]]) OR $_SESSION[$ia[1]]==''){ $value=1; }else{ $value=$_SESSION[$ia[1]]; } // write the alternative HTML only for activated javascript $answer.=" "; $answer.=" "; } 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'; $checkconditionFunction = "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('Format: %s'),$dateformatdetails['dateformat'])."\" 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; $checkconditionFunction = "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); } // --------------------------------------------------------------- // TMSW TODO - Can remove DB query by passing in answer list from EM function do_list_dropdown($ia) { global $dbprefix, $dropdownthreshold, $lwcdropdowns, $connect; global $clang; $checkconditionFunction = "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 $dropdownSize = ''; if (isset($qidattributes['dropdown_size']) && $qidattributes['dropdown_size'] > 0) { $_height = sanitize_int($qidattributes['dropdown_size']) ; $_maxHeight = $ansresult->RowCount(); if ((isset($_SESSION[$ia[1]]) || $_SESSION[$ia[1]] != '') && $ia[6] != 'Y' && $ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { ++$_maxHeight; // for No Answer } if (isset($other) && $other=='Y') { ++$_maxHeight; // for Other } if (!$_SESSION[$ia[1]]) { ++$_maxHeight; // for 'Please choose:' } if ($_height > $_maxHeight) { $_height = $_maxHeight; } $dropdownSize = ' size="'.$_height.'"'; } $prefixStyle = 0; if (isset($qidattributes['dropdown_prefix'])) { $prefixStyle = sanitize_int($qidattributes['dropdown_prefix']) ; } $_rowNum=0; $_prefix=''; if (!isset($optCategorySeparator)) { while ($ansrow = $ansresult->FetchRow()) { $opt_select = ''; if ($_SESSION[$ia[1]] == $ansrow['code']) { $opt_select = SELECTED; } if ($prefixStyle == 1) { $_prefix = ++$_rowNum . ') '; } $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 = ''; } if ($prefixStyle == 1) { $_prefix = ++$_rowNum . ') '; } $answer .= '\n"; } if ((isset($_SESSION[$ia[1]]) || $_SESSION[$ia[1]] != '') && $ia[6] != 'Y' && $ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { if ($prefixStyle == 1) { $_prefix = ++$_rowNum . ') '; } $answer .= '\n"; } $answer .= ''; if (isset($other) && $other=='Y') { $sselect_show_hide = ' showhideother(this.name, this.value);'; } else { $sselect_show_hide = ''; } $sselect = '

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 .= "

"; $inputnames[]=$ia[1]."other"; } else { $answer .= "

"; } $inputnames[]=$ia[1]; return array($answer, $inputnames); } // --------------------------------------------------------------- // TMSW TODO - Can remove DB query by passing in answer list from EM function do_list_radio($ia) { global $dbprefix, $dropdownthreshold, $lwcdropdowns, $connect, $clang; global $thissurvey; if ($thissurvey['nokeyboard']=='Y') { vIncludeKeypad(); $kpclass = "text-keypad"; } else { $kpclass = ""; } $checkconditionFunction = "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) { include_once(dirname(__FILE__) . '/quexs.php'); $ansrow['answer'] = T_("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) { $oth_checkconditionFunction = 'fixnum_checkconditions'; } else { $oth_checkconditionFunction = 'checkconditions'; } if ($_SESSION[$ia[1]] == '-oth-') { $check_ans = CHECKED; } else { $check_ans = ''; } $thisfieldname=$ia[1].'other'; if (isset($_SESSION[$thisfieldname])) { $dispVal = $_SESSION[$thisfieldname]; if ($qidattributes['other_numbers_only']==1) { $dispVal = str_replace('.',$sSeperator,$dispVal); } $answer_other = ' value="'.htmlspecialchars($dispVal,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']; ++$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"; $inputnames[]=$ia[1]; return array($answer, $inputnames); } // --------------------------------------------------------------- // TMSW TODO - Can remove DB query by passing in answer list from EM function do_listwithcomment($ia) { global $maxoptionsize, $dbprefix, $dropdownthreshold, $lwcdropdowns, $thissurvey; global $clang; if ($thissurvey['nokeyboard']=='Y') { vIncludeKeypad(); $kpclass = "text-keypad"; } else { $kpclass = ""; } $checkconditionFunction = "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; } //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) { include_once(dirname(__FILE__) . '/quexs.php'); $ansrow['answer'] = T_("Schedule Appointment"); $quexs_appointment = true; } $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;} $answer .= '

    "; $inputnames[]=$ia[1]; $inputnames[]=$ia[1].'comment'; } else //Dropdown list { $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); } // --------------------------------------------------------------- // TMSW TODO - Can remove DB query by passing in answer list from EM function do_ranking($ia) { global $dbprefix, $imageurl, $clang, $thissurvey, $showpopups; $checkconditionFunction = "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"]); $max_ans_val = LimeExpressionManager::ProcessString('{'.$max_answers.'}',$ia[0]); if (!is_numeric($max_ans_val)) // this happens when try to do dynamic max ranking values and the starting value is blank { $max_ans_val = $anscount; } } else { $max_answers=$anscount; $max_ans_val = $anscount; } if (trim($qidattributes["min_answers"])!='') { $min_answers = trim($qidattributes["min_answers"]); } else { $min_answers = 0; } $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<=floor($max_ans_val); $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"; return array($answer, $inputnames); } // --------------------------------------------------------------- // TMSW TODO - Can remove DB query by passing in answer list from EM 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; } } $checkconditionFunction = "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']; $oth_checkconditionFunction = "fixnum_checkconditions"; } else { $oth_checkconditionFunction = "checkconditions"; } $qquery = "SELECT other FROM ".db_table_name('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'];} if ($qidattributes['random_order']==1) { $ansquery = "SELECT * FROM ".db_table_name('questions')." WHERE parent_qid=$ia[0] AND scale_id=0 AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random(); } else { $ansquery = "SELECT * FROM ".db_table_name('questions')." WHERE parent_qid=$ia[0] AND scale_id=0 AND language='".$_SESSION['s_lang']."' ORDER BY question_order"; } $ansresult = $connect->GetAll($ansquery); //Checked $anscount = count($ansresult); if (trim($qidattributes['exclude_all_others'])!='' && $qidattributes['random_order']==1) { //if exclude_all_others is set then the related answer should keep its position at all times //thats why we have to re-position it if it has been randomized $position=0; foreach ($ansresult as $answer) { if ((trim($qidattributes['exclude_all_others']) != '') && ($answer['title']==trim($qidattributes['exclude_all_others']))) { if ($position==$answer['question_order']-1) break; //already in the right position $tmp = array_splice($ansresult, $position, 1); array_splice($ansresult, $answer['question_order']-1, 0, $tmp); break; } $position++; } } if ($other == 'Y') { $anscount++; //COUNT OTHER AS AN ANSWER FOR MANDATORY CHECKING! } $wrapper = setup_columns($dcols, $anscount); $answer = '\n\n".$wrapper['whole-start']; $fn = 1; if (!isset($multifields)) { $multifields = ''; } $rowcounter = 0; $colcounter = 1; $startitem=''; $postrow = ''; $trbc=''; foreach ($ansresult as $ansrow) { $myfname = $ia[1].$ansrow['title']; $trbc=''; /* Check for array_filter */ 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']; } /* Print out the checkbox */ $answer .= $startitem; $answer .= "\t$hiddenfield\n"; $answer .= ' \n" . "\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 ($other == 'Y') { $myfname = $ia[1].'other'; list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $qidattributes, $thissurvey, array("code"=>"other"), $myfname, $trbc, $myfname, "li","other"); if($wrapper['item-start'] == "\t
  • \n") { $startitem = "\t$htmltbody2\n"; } else { $startitem = $wrapper['item-start']; } $answer .= $startitem; $answer .= $hiddenfield.' ".$othertext." "; $answer .=" />"; $answer .="\n"; $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']; # No need $checkotherscript : already done by check mandatory # $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 = $checkotherscript . $answer; $answer .= $postrow; return array($answer, $inputnames); } // --------------------------------------------------------------- // TMSW TODO - Can remove DB query by passing in answer list from EM function do_multiplechoice_withcomments($ia) { global $dbprefix, $clang, $thissurvey; if ($thissurvey['nokeyboard']=='Y') { vIncludeKeypad(); $kpclass = "text-keypad"; } else { $kpclass = ""; } $inputnames = array(); $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; } } $checkconditionFunction = "checkconditions"; $qidattributes=getQuestionAttributes($ia[0],$ia[4]); if ($qidattributes['other_numbers_only']==1) { $sSeperator = getRadixPointData($thissurvey['surveyls_numberformat']); $sSeperator = $sSeperator['seperator']; $oth_checkconditionFunction = "fixnum_checkconditions"; } else { $oth_checkconditionFunction = "checkconditions"; } if (trim($qidattributes['other_replace_text'])!='') { $othertext=$qidattributes['other_replace_text']; } else { $othertext=$clang->gT('Other:'); } // Check if the max_answers attribute is set $callmaxanswscriptother = ''; $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'];} 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 = "\n"; $answer_main = ''; $fn = 1; if (!isset($other)){ $other = 'N'; } if($other == 'Y') { $label_width = 25; } else { $label_width = 0; } while ($ansrow = $ansresult->FetchRow()) { $myfname = $ia[1].$ansrow['title']; $trbc=''; /* Check for array_filter */ list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $qidattributes, $thissurvey, $ansrow, $myfname, $trbc, $myfname, "li"); if($label_width < strlen(trim(strip_tags($ansrow['question'])))) { $label_width = strlen(trim(strip_tags($ansrow['question']))); } $myfname2 = $myfname."comment"; $startitem = "\t$htmltbody2\n"; /* Print out the checkbox */ $answer_main .= $startitem; $answer_main .= "\t$hiddenfield\n"; $answer_main .= "\n" . "\t\n" . "\t\n"; $answer_main .= "\n"; $fn++; $answer_main .= "\n\n\t\n" ."\n\n" . "\t
  • \n"; $fn++; $inputnames[]=$myfname; $inputnames[]=$myfname2; } if ($other == 'Y') { $myfname = $ia[1].'other'; $myfname2 = $myfname.'comment'; $anscount = $anscount + 2; $answer_main .= "\t
  • \n\n" . "\t\n\n" . "\n\t\n\n\t
  • \n"; $inputnames[]=$myfname; $inputnames[]=$myfname2; } $answer .= "
      \n".$answer_main."
    \n"; return array($answer, $inputnames); } // --------------------------------------------------------------- function do_file_upload($ia) { global $rooturl,$clang, $js_header_includes, $thissurvey, $surveyid; $checkconditionFunction = "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(); $bIsPreview = (substr($currentdir,strlen(dirname($currentdir))+1)=="admin"); $scriptloc = $rooturl.'/uploader.php'; if ($bIsPreview) { $_SESSION['preview'] = 1; $questgrppreview = 1; // Preview is launched from Question or group level } else if ($thissurvey['active'] != "Y") { $_SESSION['preview'] = 1; $questgrppreview = 0; } else { $_SESSION['preview'] = 0; $questgrppreview = 0; } $uploadbutton = "

    gT('Upload files'). "



    "; $answer = "\n"; /*if ($pos) $answer .= ""; else $answer .= "";*/ $js_header_includes[]= '/scripts/modaldialog.js'; // 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); } // --------------------------------------------------------------- // TMSW TODO - Can remove DB query by passing in answer list from EM function do_multipleshorttext($ia) { global $dbprefix, $clang, $thissurvey; $answer=''; $qidattributes=getQuestionAttributes($ia[0],$ia[4]); if ($qidattributes['numbers_only']==1) { $sSeperator = getRadixPointData($thissurvey['surveyls_numberformat']); $sSeperator = $sSeperator['seperator']; $checkconditionFunction = "fixnum_checkconditions"; } else { $checkconditionFunction = "checkconditions"; } if (intval(trim($qidattributes['maximum_chars']))>0) { // Only maxlength attribute, use textarea[maxlength] jquery selector for textarea $maximum_chars= intval(trim($qidattributes['maximum_chars'])); $maxlength= "maxlength='{$maximum_chars}' "; } else { $maxlength= ""; } 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']; 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; } } list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $qidattributes, $thissurvey, $ansrow, $myfname, '', $myfname, "li"); $answer_main .= "\t$htmltbody2\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; } } list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $qidattributes, $thissurvey, $ansrow, $myfname, '', $myfname, "li"); // color code missing mandatory questions red if ($ia[6]=='Y' && (($_SESSION['step'] == $_SESSION['prevstep']) || ($_SESSION['maxstep'] > $_SESSION['step'])) && $_SESSION[$myfname] == '') { $ansrow['question'] = "{$ansrow['question']}"; } $answer_main .= "\t$htmltbody2\n" . "\n" . "\t\n".$prefix."\n".''."\n".$suffix."\n\t\n" . "\t\n"; $fn++; $inputnames[]=$myfname; } } } $answer = "
      \n".$answer_main."
    \n"; return array($answer, $inputnames); } // --------------------------------------------------------------- // TMSW TODO - Can remove DB query by passing in answer list from EM function do_multiplenumeric($ia) { global $dbprefix, $clang, $js_header_includes, $css_header_includes, $thissurvey; $checkconditionFunction = "fixnum_checkconditions"; $qidattributes=getQuestionAttributes($ia[0],$ia[4]); $answer=''; $sSeperator = getRadixPointData($thissurvey['surveyls_numberformat']); $sSeperator = $sSeperator['seperator']; $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 (intval(trim($qidattributes['maximum_chars']))>0) { // Only maxlength attribute, use textarea[maxlength] jquery selector for textarea $maximum_chars= intval(trim($qidattributes['maximum_chars'])); $maxlength= "maxlength='{$maximum_chars}' "; } else { $maxlength= "maxlength='25'"; } 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
    "; } // color code missing mandatory questions red if ($ia[6]=='Y' && (($_SESSION['step'] == $_SESSION['prevstep']) || ($_SESSION['maxstep'] > $_SESSION['step'])) && $_SESSION[$myfname] == '') { $theanswer = "{$theanswer}"; } list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $qidattributes, $thissurvey, $ansrow, $myfname, '', $myfname, "li"); $answer_main .= "\t$htmltbody2\n"; if ($slider_layout === false) { $answer_main .= "\n"; } else { $answer_main .= "\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 (trim($qidattributes['equals_num_value'])!='' || trim($qidattributes['min_num_value'])!='' || trim($qidattributes['max_num_value'])!='' ) { $qinfo = LimeExpressionManager::GetQuestionStatus($ia[0]); if (trim($qidattributes['equals_num_value'])!='') { $answer_main .= "\t
  • \n" . "\n" . "$prefix\n" . "{" . $qinfo['sumRemainingEqn'] . "}\n" . "$suffix\n" . "\t
  • \n"; } $answer_main .= "\t
  • \n" . "\n" . "$prefix\n" . "{" . $qinfo['sumEqn'] . "}\n" . "$suffix\n" . "\t
  • \n"; } $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']; return array($answer, $inputnames); } // --------------------------------------------------------------- function do_numerical($ia) { global $clang, $thissurvey; $checkconditionFunction = "fixnum_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 (intval(trim($qidattributes['maximum_chars']))>0 && intval(trim($qidattributes['maximum_chars']))<20) // Limt to 20 chars for numeric { // Only maxlength attribute, use textarea[maxlength] jquery selector for textarea $maximum_chars= intval(trim($qidattributes['maximum_chars'])); $maxlength= "maxlength='{$maximum_chars}' "; } else { $maxlength= "maxlength='20' "; } if (trim($qidattributes['text_input_width'])!='') { $tiwidth=$qidattributes['text_input_width']; } else { $tiwidth=10; } if (trim($qidattributes['num_value_int_only'])==1) { $acomma=""; $intonly=1; } else { $acomma=getRadixPointData($thissurvey['surveyls_numberformat']); $acomma = $acomma['seperator']; $intonly=0; } $sSeperator = getRadixPointData($thissurvey['surveyls_numberformat']); $sSeperator = $sSeperator['seperator']; $dispVal = str_replace('.',$sSeperator,$_SESSION[$ia[1]]); if ($thissurvey['nokeyboard']=='Y') { vIncludeKeypad(); $kpclass = "num-keypad"; } else { $kpclass = ""; } $answer = "

    \n$prefix\tgT('Only numbers may be entered in this field')."\" onkeyup='$checkconditionFunction(this.value, this.name, this.type,null, $intonly)' " . " {$maxlength} />\n\t{$suffix}\n

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

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

    \n"; } $inputnames[]=$ia[1]; $mandatory=null; return array($answer, $inputnames, $mandatory); } // --------------------------------------------------------------- function do_shortfreetext($ia) { global $clang, $js_header_includes, $thissurvey,$googleMapsAPIKey; $qidattributes=getQuestionAttributes($ia[0],$ia[4]); if ($qidattributes['numbers_only']==1) { $sSeperator = getRadixPointData($thissurvey['surveyls_numberformat']); $sSeperator = $sSeperator['seperator']; $checkconditionFunction = "fixnum_checkconditions"; } else { $checkconditionFunction = "checkconditions"; } if (intval(trim($qidattributes['maximum_chars']))>0) { // Only maxlength attribute, use textarea[maxlength] jquery selector for textarea $maximum_chars= intval(trim($qidattributes['maximum_chars'])); $maxlength= "maxlength='{$maximum_chars}' "; } else { $maxlength= ""; } 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']; //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; } $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(getIPAddress()); 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 = ""; } $checkconditionFunction = "checkconditions"; $qidattributes=getQuestionAttributes($ia[0],$ia[4]); if (intval(trim($qidattributes['maximum_chars']))>0) { // Only maxlength attribute, use textarea[maxlength] jquery selector for textarea $maximum_chars= intval(trim($qidattributes['maximum_chars'])); $maxlength= "maxlength='{$maximum_chars}' "; } else { $maxlength= ""; } if (trim($qidattributes['display_rows'])!='') { $drows=$qidattributes['display_rows']; } else { $drows=5; } if (trim($qidattributes['text_input_width'])!='') { $tiwidth=$qidattributes['text_input_width']; } else { $tiwidth=40; } $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 = ""; } $checkconditionFunction = "checkconditions"; $qidattributes=getQuestionAttributes($ia[0],$ia[4]); if (intval(trim($qidattributes['maximum_chars']))>0) { // Only maxlength attribute, use textarea[maxlength] jquery selector for textarea $maximum_chars= intval(trim($qidattributes['maximum_chars'])); $maxlength= "maxlength='{$maximum_chars}' "; } else { $maxlength= ""; } if (trim($qidattributes['display_rows'])!='') { $drows=$qidattributes['display_rows']; } else { $drows=30; } if (trim($qidattributes['text_input_width'])!='') { $tiwidth=$qidattributes['text_input_width']; } else { $tiwidth=70; } $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; $checkconditionFunction = "checkconditions"; $answer = "
      \n" . "\t
    • \n\n\n\t
    • \n" . "\t
    • \n\n\n\t
    • \n"; if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { $answer .= "\t
    • \n\n\n\t
    • \n"; } $answer .= "
    \n\n\n"; $inputnames[]=$ia[1]; return array($answer, $inputnames); } // --------------------------------------------------------------- function do_gender($ia) { global $clang; $checkconditionFunction = "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) { $answer .= "\t
    • \n\n\n\t
    • \n"; } $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 */ // TMSW TODO - Can remove DB query by passing in answer list from EM function do_array_5point($ia) { global $dbprefix, $notanswered, $thissurvey, $clang; $inputnames=array(); $checkconditionFunction = "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 ($ia[6]=='Y' && (is_array($notanswered)) && (array_search($myfname, $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 */ // TMSW TODO - Can remove DB query by passing in answer list from EM function do_array_10point($ia) { global $dbprefix, $notanswered, $thissurvey, $clang; $checkconditionFunction = "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 ($ia[6]=='Y' && (is_array($notanswered)) && (array_search($myfname, $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"; } 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); } // --------------------------------------------------------------- // TMSW TODO - Can remove DB query by passing in answer list from EM function do_array_yesnouncertain($ia) { global $dbprefix, $notanswered, $thissurvey, $clang; $checkconditionFunction = "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 ($ia[6]=='Y' && (is_array($notanswered)) && (array_search($myfname, $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"; } $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" . "\n\t\n\t\n\t
    \n"; return array($answer, $inputnames); } // TMSW TODO - Can remove DB query by passing in answer list from EM function do_array_increasesamedecrease($ia) { global $dbprefix, $thissurvey, $clang; global $notanswered; $checkconditionFunction = "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 ($ia[6]=='Y' && (is_array($notanswered)) && (array_search($myfname, $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); } // --------------------------------------------------------------- // TMSW TODO - Can remove DB query by passing in answer list from EM function do_array($ia) { global $dbprefix, $connect, $thissurvey, $clang; global $repeatheadings; global $notanswered; global $minrepeatheadings; $checkconditionFunction = "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 ($ia[6]=='Y' && (is_array($notanswered)) && (array_search($myfname, $notanswered) !== FALSE) && ($_SESSION[$myfname] == '') ) { $answertext = ''.$answertext.''; } // Get array_filter stuff // list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $qidattributes, $thissurvey, $ansrow, $myfname, $trbc, $myfname); $trbc = alternation($trbc , 'row'); $fn++; $answer .= $htmltbody2; $answer .= "\n" . "\t\n"; $thiskey=0; foreach ($labelcode as $ld) { $answer .= "\t\t\t\n"; $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"; } $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=$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 ($ia[6]=='Y' && (is_array($notanswered)) && (array_search($myfname, $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); } // --------------------------------------------------------------- // TMSW TODO - Can remove DB query by passing in answer list from EM 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 = ""; } $checkconditionFunction = "checkconditions"; $sSeperator = getRadixPointData($thissurvey['surveyls_numberformat']); $sSeperator = $sSeperator['seperator']; //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]); if (intval(trim($qidattributes['maximum_chars']))>0) { // Only maxlength attribute, use textarea[maxlength] jquery selector for textarea $maximum_chars= intval(trim($qidattributes['maximum_chars'])); $maxlength= "maxlength='{$maximum_chars}' "; } else { $maxlength= ""; } $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 = ''; if ($qidattributes['numbers_only']==1) { $checkconditionFunction = "fixnum_checkconditions"; $q_table_id = 'totals_'.$ia[0]; $q_table_id_HTML = ' id="'.$q_table_id.'"'; $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 ($ia[6]=='Y' && is_array($notanswered)) { //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((array_search($myfname2, $notanswered) !== FALSE) && $_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)) { if ($qidattributes['numbers_only']==1) { $radix = $sSeperator; } else { $radix = 'X'; // to indicate that should not try to change entered values } $answer .= "\n\n"; } else { $addcheckcond = <<< EOD EOD; $answer .= $addcheckcond; } } 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); } // --------------------------------------------------------------- // TMSW TODO - Can remove DB query by passing in answer list from EM function do_array_multiflexi($ia) { global $dbprefix, $connect, $thissurvey, $clang; global $repeatheadings; global $notanswered; global $minrepeatheadings; $checkconditionFunction = "fixnum_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 (intval(trim($qidattributes['maximum_chars']))>0) { // Only maxlength attribute, use textarea[maxlength] jquery selector for textarea $maximum_chars= intval(trim($qidattributes['maximum_chars'])); $maxlength= "maxlength='{$maximum_chars}' "; } else { $maxlength= ""; } 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 ($ia[6]=='Y' && is_array($notanswered)) { //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((array_search($myfname2, $notanswered) !== FALSE) && $_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 = ''; $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); } // --------------------------------------------------------------- // TMSW TODO - Can remove DB query by passing in answer list from EM function do_arraycolumns($ia) { global $dbprefix; global $notanswered, $clang; $checkconditionFunction = "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 = ''; for ($_i=0;$_i{$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); } // --------------------------------------------------------------- // TMSW TODO - Can remove DB query by passing in answer list from EM function do_array_dual($ia) { global $dbprefix, $connect, $thissurvey, $clang; global $repeatheadings; global $notanswered; global $minrepeatheadings; $checkconditionFunction = "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 ($ia[6]=='Y' && (is_array($notanswered)) && ((array_search($myfname, $notanswered) !== FALSE) || (array_search($myfname1, $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"; } $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"; $answer .= "\n\t \n"; if ($hiddenanswers!='') { $answer .=$hiddenanswers; $hiddenanswers=''; } $answer .= "\n"; $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 ($ia[6]=='Y' && (is_array($notanswered)) && ((array_search($myfname, $notanswered) !== FALSE) || (array_search($myfname1, $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); } // Closing PHP tag intentionally left out - yes, it is okay