getConfig('surveyID')]['insertarray'] variable which is built at the commencement of the survey. * See index.php, function "buildsurveysession()" * One $ia array exists for every question in the survey. The $_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['insertarray'] * string is an array of $ia arrays. * * $ia[0] => 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* */ /** * setNoAnswerMode */ function setNoAnswerMode($thissurvey) { if (getGlobalSetting('shownoanswer') > 0 && $thissurvey['shownoanswer'] != 'N') { define('SHOW_NO_ANSWER', 1); } else { define('SHOW_NO_ANSWER', 0); } } /** * 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, survey.php or preview.php * * @param mixed $ia * @return mixed */ function retrieveAnswers($ia) { //globalise required config variables global $thissurvey; //These are set by index.php //$clang = Yii::app()->lang; $clang = Yii::app()->lang; //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['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]])) {$_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]] = "";} $aQuestionAttributes = getQuestionAttributeValues($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 ($aQuestionAttributes['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 ($aQuestionAttributes['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 && $aQuestionAttributes['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 && $aQuestionAttributes['hide_tip']==0) { $question_text['help'] = $clang->gT("Double-click or drag-and-drop items in the left list to move them to the right - your highest ranking item should be on the top right, moving through to your lowest ranking item."); } break; case 'M': //Multiple choice checkbox $values=do_multiplechoice($ia); if (count($values[1]) > 1 && $aQuestionAttributes['hide_tip']==0) { $maxansw=trim($aQuestionAttributes['max_answers']); $minansw=trim($aQuestionAttributes['min_answers']); if (!($maxansw || $minansw)) { $qtitle .= "
\n" . $clang->gT('Check any that apply').''; $question_text['help'] = $clang->gT('Check any that apply'); } // else // { // if ($maxansw && $minansw) // { // $qtitle .= "
\n" // . sprintf($clang->gT("Check between %d and %d answers"), $minansw, $maxansw).""; // $question_text['help'] = sprintf($clang->gT("Check between %d and %d answers"), $minansw, $maxansw); // } elseif ($maxansw) // { // $qtitle .= "
\n" // . sprintf($clang->gT("Check at most %d answers"), $maxansw).""; // $question_text['help'] = sprintf($clang->gT("Check at most %d answers"), $maxansw); // } else // { // $qtitle .= "
\n" // . sprintf($clang->ngT("Check at least %d answer","Check at least %d answers",$minansw),$minansw).""; // $question_text['help'] = sprintf($clang->ngT("Check at least %d answer","Check at least %d answers",$minansw),$minansw); // } // } } break; case 'I': //Language Question $values=do_language($ia); if (count($values[1]) > 1) { $qtitle .= "
\n" . $clang->gT('Choose your language').''; $question_text['help'] = $clang->gT('Choose your language'); } break; case 'P': //Multiple choice with comments checkbox + text $values=do_multiplechoice_withcomments($ia); if (count($values[1]) > 1 && $aQuestionAttributes['hide_tip']==0) { $maxansw=trim($aQuestionAttributes["max_answers"]); $minansw=trim($aQuestionAttributes["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['survey_'.Yii::app()->getConfig('surveyID')]['step'] != $_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['maxstep']) || ($_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['step'] == $_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['prevstep'])) { $mandatory_msg = mandatory_message($ia); } else { $mandatory_msg = ''; } $qtitle .= $mandatory_msg; $question_text['man_message'] = $mandatory_msg; // if (($_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['step'] != $_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['maxstep']) || ($_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['step'] == $_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['prevstep'])) { if (!isset($aQuestionAttributes['hide_tip']) || $aQuestionAttributes['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['survey_'.Yii::app()->getConfig('surveyID')]['step'] != $_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['maxstep']) || ($_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['step'] == $_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['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. $sTemplate = isset($thissurvey['template']) ? $thissurvey['template'] : NULL; if(is_file('templates/'.validateTemplateDir($sTemplate).'/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(getTemplatePath($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], $ia[5], $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); // if (!$qinfo['valid']) { // if (strlen($tip) == 0) { // $help = $clang->gT('This question must be answered correctly'); // } // else { // $tip =' '.$tip.''; // } // return '
'.$tip.'
'; // } // else { // return $tip; // } } // TMSW Validation -> EM function file_validation_message($ia) { global $filenotvalidated; $clang = Yii::app()->lang; $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 Validation -> EM function mandatory_popup($ia, $notanswered=null) { $showpopups=Yii::app()->getConfig('showpopups'); $clang = Yii::app()->lang; //This sets the mandatory popup message to show if required //Called from question.php, group.php or survey.php if ($notanswered === null) {unset($notanswered);} if (isset($notanswered) && is_array($notanswered) && $showpopups) //ADD WARNINGS TO QUESTIONS IF THEY WERE MANDATORY BUT NOT ANSWERED { global $mandatorypopup, $popup; //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) { $showpopups=Yii::app()->getConfig('showpopups'); $clang = Yii::app()->lang; //This sets the validation popup message to show if required //Called from question.php, group.php or survey.php if ($notvalidated === null) {unset($notvalidated);} $qtitle=""; if (isset($notvalidated) && is_array($notvalidated) && $showpopups) //ADD WARNINGS TO QUESTIONS IF THEY ARE NOT VALID { global $validationpopup, $vpopup; //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) { $showpopups=Yii::app()->getConfig('showpopups'); $clang = Yii::app()->lang; if ($filenotvalidated === null) { unset($filenotvalidated); } if (isset($filenotvalidated) && is_array($filenotvalidated) && $showpopups) { global $filevalidationpopup, $fpopup; if (!isset($filevalidationpopup)) { $fpopup="\n"; $filevalidationpopup = "Y"; } return array($filevalidationpopup, $fpopup); } else return false; } function return_timer_script($aQuestionAttributes, $ia, $disable=null) { global $thissurvey; $clang = Yii::app()->lang; header_includes(Yii::app()->getConfig("generalscripts").'coookies.js', 'js'); /* The following lines cover for previewing questions, because no $_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['fieldarray'] exists. This just stops error messages occuring */ if(!isset($_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['fieldarray'])) { $_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['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=$aQuestionAttributes['time_limit']; $disable_next=trim($aQuestionAttributes['time_limit_disable_next']) != '' ? $aQuestionAttributes['time_limit_disable_next'] : 0; $disable_prev=trim($aQuestionAttributes['time_limit_disable_prev']) != '' ? $aQuestionAttributes['time_limit_disable_prev'] : 0; $time_limit_action=trim($aQuestionAttributes['time_limit_action']) != '' ? $aQuestionAttributes['time_limit_action'] : 1; $time_limit_message_delay=trim($aQuestionAttributes['time_limit_message_delay']) != '' ? $aQuestionAttributes['time_limit_message_delay']*1000 : 1000; $time_limit_message=trim($aQuestionAttributes['time_limit_message'][$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']]) != '' ? htmlspecialchars($aQuestionAttributes['time_limit_message'][$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']], ENT_QUOTES) : $clang->gT("Your time to answer this question has expired"); $time_limit_warning=trim($aQuestionAttributes['time_limit_warning']) != '' ? $aQuestionAttributes['time_limit_warning'] : 0; $time_limit_warning_2=trim($aQuestionAttributes['time_limit_warning_2']) != '' ? $aQuestionAttributes['time_limit_warning_2'] : 0; $time_limit_countdown_message=trim($aQuestionAttributes['time_limit_countdown_message'][$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']]) != '' ? htmlspecialchars($aQuestionAttributes['time_limit_countdown_message'][$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']], ENT_QUOTES) : $clang->gT("Time remaining"); $time_limit_warning_message=trim($aQuestionAttributes['time_limit_warning_message'][$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']]) != '' ? htmlspecialchars($aQuestionAttributes['time_limit_warning_message'][$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']], 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($aQuestionAttributes['time_limit_warning_display_time']) != '' ? $aQuestionAttributes['time_limit_warning_display_time']+1 : 0; $time_limit_warning_2_message=trim($aQuestionAttributes['time_limit_warning_2_message'][$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']]) != '' ? htmlspecialchars($aQuestionAttributes['time_limit_warning_2_message'][$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']], 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($aQuestionAttributes['time_limit_warning_2_display_time']) != '' ? $aQuestionAttributes['time_limit_warning_2_display_time']+1 : 0; $time_limit_message_style=trim($aQuestionAttributes['time_limit_message_style']) != '' ? $aQuestionAttributes['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($aQuestionAttributes['time_limit_warning_style']) != '' ? $aQuestionAttributes['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($aQuestionAttributes['time_limit_warning_2_style']) != '' ? $aQuestionAttributes['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($aQuestionAttributes['time_limit_timer_style']) != '' ? $aQuestionAttributes['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['survey_'.Yii::app()->getConfig('surveyID')][$timersessionname])) { $time_limit=$_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$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, $aQuestionAttributes, $thissurvey, $ansrow, $rowname, $trbc='', $valuename, $method="tbody", $class=null) { $htmltbody2 = "\n\n\t<$method id='javatbd$rowname'"; $htmltbody2 .= ($class !== null) ? " class='$class'": ""; $surveyid=$thissurvey['sid']; if (isset($_SESSION["survey_{$surveyid}"]['relevanceStatus'][$rowname]) && !$_SESSION["survey_{$surveyid}"]['relevanceStatus'][$rowname]) { // If using exclude_all_others, then need to know whether irrelevant rows should be hidden or disabled if (isset($aQuestionAttributes['exclude_all_others'])) { $disableit=false; foreach(explode(';',trim($aQuestionAttributes['exclude_all_others'])) as $eo) { $eorow = $ia[1] . $eo; if ((!isset($_SESSION["survey_{$surveyid}"]['relevanceStatus'][$eorow]) || $_SESSION["survey_{$surveyid}"]['relevanceStatus'][$eorow]) && (isset($_SESSION[$eorow]) && $_SESSION[$eorow] == "Y")) { $disableit = true; } } if ($disableit) { $htmltbody2 .= " disabled='disabled'"; } else { if (!isset($aQuestionAttributes['array_filter_style']) || $aQuestionAttributes['array_filter_style'] == '0') { $htmltbody2 .= " style='display: none'"; } else { $htmltbody2 .= " disabled='disabled'"; } } } else { if (!isset($aQuestionAttributes['array_filter_style']) || $aQuestionAttributes['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) { $aQuestionAttributes = getQuestionAttributeValues($ia[0], $ia[4]); $answer=''; if (trim($aQuestionAttributes['time_limit'])!='') { $answer .= return_timer_script($aQuestionAttributes, $ia); } $answer .= ''; $inputnames[]=$ia[1]; return array($answer, $inputnames); } function do_equation($ia) { $answer=''; $inputnames[]=$ia[1]; $mandatory=null; return array($answer, $inputnames, $mandatory); } // --------------------------------------------------------------- function do_5pointchoice($ia) { $clang=Yii::app()->lang; $imageurl = Yii::app()->getConfig("imageurl"); $checkconditionFunction = "checkconditions"; $aQuestionAttributes= getQuestionAttributeValues($ia[0], $ia[4]); $id = 'slider'.time().rand(0,100); $answer = "\n
    \n"; for ($fp=1; $fp<=5; $fp++) { $answer .= "\t
  • \ngetConfig('surveyID')][$ia[1]] == $fp) { $answer .= CHECKED; } $answer .= " onclick=\"$checkconditionFunction(this.value, this.name, this.type)\" />\n\n\t
  • \n"; } if ($ia[6] != "Y" && SHOW_NO_ANSWER == 1) // Add "No Answer" option if question is not mandatory { $answer .= "\t
  • \ngetConfig('surveyID')][$ia[1]])) { $answer .= CHECKED; } $answer .= " onclick=\"$checkconditionFunction(this.value, this.name, this.type)\" />\n\n\t
  • \n"; } $answer .= "
\ngetConfig('surveyID')][$ia[1]]."\" />\n"; $inputnames[]=$ia[1]; if($aQuestionAttributes['slider_rating']==1){ header_includes('jquery.rating.css','css'); header_includes('jquery.rating.js','js'); $answer.=" "; $answer.=" "; } if($aQuestionAttributes['slider_rating']==2){ if(!isset($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]]) OR $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]]==''){ $value=1; }else{ $value=$_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]]; } $answer.=" "; $answer.=" "; } return array($answer, $inputnames); } // --------------------------------------------------------------- function do_date($ia) { global $thissurvey; header_includes(Yii::app()->getConfig("generalscripts").'date.js', 'js'); $clang=Yii::app()->lang; $aQuestionAttributes=getQuestionAttributeValues($ia[0],$ia[4]); $checkconditionFunction = "checkconditions"; $dateformatdetails = getDateFormatDataForQID($aQuestionAttributes,$thissurvey); $numberformatdatat = getRadixPointData($thissurvey['surveyls_numberformat']); if (trim($aQuestionAttributes['dropdown_dates'])==1) { if (!empty($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]])) { $datetimeobj = new Date_Time_Converter($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]], "Y-m-d H:i:s"); $currentyear = $datetimeobj->years; $currentmonth = $datetimeobj->months; $currentdate = $datetimeobj->days; $currenthour = $datetimeobj->hours; $currentminute = $datetimeobj->minutes; } else { $currentdate=''; $currentmonth=''; $currentyear=''; $currenthour = ''; $currentminute = ''; } $dateorder = preg_split('/([-\.\/ :])/', $dateformatdetails['phpdate'],-1,PREG_SPLIT_DELIM_CAPTURE ); $answer=''; $answer .= ' '; } else { if ($clang->langcode !== 'en') { header_includes(Yii::app()->getConfig("generalscripts").'jquery/locale/jquery.ui.datepicker-'.$clang->langcode.'.js'); } // Format the date for output if (trim($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]])!='') { $datetimeobj = new Date_Time_Converter($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]] , "Y-m-d H:i"); $dateoutput = $datetimeobj->convert($dateformatdetails['phpdate']); } else { $dateoutput=''; } if (trim($aQuestionAttributes['dropdown_dates_year_min'])!='') { $minyear=$aQuestionAttributes['dropdown_dates_year_min']; } else { $minyear='1900'; } if (trim($aQuestionAttributes['dropdown_dates_year_max'])!='') { $maxyear=$aQuestionAttributes['dropdown_dates_year_max']; } else { $maxyear='2020'; } $goodchars = str_replace( array("m","d","y"), "", $dateformatdetails['jsdate']); $goodchars = "0123456789".substr($goodchars,0,1); $iLength=strlen($dateformatdetails['dateformat']); $answer ="

"; if (trim($aQuestionAttributes['hide_tip'])==1) { $answer.="

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

"; } } $inputnames[]=$ia[1]; return array($answer, $inputnames); } // --------------------------------------------------------------- function do_language($ia) { $clang = Yii::app()->lang; $checkconditionFunction = "checkconditions"; $answerlangs = Survey::model()->findByPk(Yii::app()->getConfig('surveyID'))->additionalLanguages; $answerlangs [] = Survey::model()->findByPk(Yii::app()->getConfig('surveyID'))->language; $answer = "\n\t

\n" ."" ."\n"; $answer .= "getConfig('surveyID')][$ia[1]]."\" />\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 $dropdownthreshold; $clang=Yii::app()->lang; $checkconditionFunction = "checkconditions"; $aQuestionAttributes = getQuestionAttributeValues($ia[0], $ia[4]); if (trim($aQuestionAttributes['other_replace_text'][$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']])!='') { $othertext=$aQuestionAttributes['other_replace_text'][$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']]; } else { $othertext=$clang->gT('Other:'); } if (trim($aQuestionAttributes['category_separator'])!='') { $optCategorySeparator = $aQuestionAttributes['category_separator']; } $answer=''; //Time Limit Code if (trim($aQuestionAttributes['time_limit'])!='') { $answer .= return_timer_script($aQuestionAttributes, $ia); } //End Time Limit Code $query = "SELECT other FROM {{questions}} WHERE qid=".$ia[0]." AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' "; $other = Yii::app()->db->createCommand($query)->queryScalar(); //Checked //question attribute random order set? if ($aQuestionAttributes['random_order']==1) { $ansquery = "SELECT * FROM {{answers}} WHERE qid=$ia[0] AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' and scale_id=0 ORDER BY ".dbRandom(); } //question attribute alphasort set? elseif ($aQuestionAttributes['alphasort']==1) { $ansquery = "SELECT * FROM {{answers}} WHERE qid=$ia[0] AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' and scale_id=0 ORDER BY answer"; } //no question attributes -> order by sortorder else { $ansquery = "SELECT * FROM {{answers}} WHERE qid=$ia[0] AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' and scale_id=0 ORDER BY sortorder, answer"; } $ansresult = Yii::app()->db->createCommand($ansquery)->query() or safeDie('Couldn\'t get answers
'.$ansquery.'
'); //Checked $ansresult= $ansresult->readAll(); $dropdownSize = ''; if (isset($aQuestionAttributes['dropdown_size']) && $aQuestionAttributes['dropdown_size'] > 0) { $_height = sanitize_int($aQuestionAttributes['dropdown_size']) ; $_maxHeight = count($ansresult); if ((!empty($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$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['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]]) { ++$_maxHeight; // for 'Please choose:' } if ($_height > $_maxHeight) { $_height = $_maxHeight; } $dropdownSize = ' size="'.$_height.'"'; } $prefixStyle = 0; if (isset($aQuestionAttributes['dropdown_prefix'])) { $prefixStyle = sanitize_int($aQuestionAttributes['dropdown_prefix']) ; } $_rowNum=0; $_prefix=''; if (!isset($optCategorySeparator)) { foreach ($ansresult as $ansrow) { $opt_select = ''; if ($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]] == $ansrow['code']) { $opt_select = SELECTED; } if ($prefixStyle == 1) { $_prefix = ++$_rowNum . ') '; } $answer .= "\n"; } } else { $defaultopts = Array(); $optgroups = Array(); foreach ($ansresult as $ansrow) { // 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['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]] == $optionarray['code']) { $opt_select = SELECTED; } else { $opt_select = ''; } $answer .= ' '; } $answer .= ' '; } $opt_select=''; foreach ($defaultopts as $optionarray) { if ($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]] == $optionarray['code']) { $opt_select = SELECTED; } else { $opt_select = ''; } $answer .= ' '; } } if (!$_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]]) { $answer = ' '."\n".$answer; } if (isset($other) && $other=='Y') { if ($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]] == '-oth-') { $opt_select = SELECTED; } else { $opt_select = ''; } if ($prefixStyle == 1) { $_prefix = ++$_rowNum . ') '; } $answer .= ' \n"; } if (($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]] || $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$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 = ' "; // --> END NEW FEATURE - SAVE $inputnames[]=$ia[1]."other"; } else { $answer .= "

"; } // $checkotherscript = ""; // if (isset($other) && $other == 'Y' && $aQuestionAttributes['other_comment_mandatory']==1) // { // $checkotherscript = "\n\n"; // } // $answer = $checkotherscript . $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 $dropdownthreshold; global $thissurvey; $clang=Yii::app()->lang; if ($thissurvey['nokeyboard']=='Y') { includeKeypad(); $kpclass = "text-keypad"; } else { $kpclass = ""; } $checkconditionFunction = "checkconditions"; $aQuestionAttributes = getQuestionAttributeValues($ia[0], $ia[4]); $query = "SELECT other FROM {{questions}} WHERE qid=".$ia[0]." AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' "; $result = Yii::app()->db->createCommand($query)->query(); foreach ($result->readAll() as $row) { $other = $row['other']; } //question attribute random order set? if ($aQuestionAttributes['random_order']==1) { $ansquery = "SELECT * FROM {{answers}} WHERE qid=$ia[0] AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' and scale_id=0 ORDER BY ".dbRandom(); } //question attribute alphasort set? elseif ($aQuestionAttributes['alphasort']==1) { $ansquery = "SELECT * FROM {{answers}} WHERE qid=$ia[0] AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' and scale_id=0 ORDER BY answer"; } //no question attributes -> order by sortorder else { $ansquery = "SELECT * FROM {{answers}} WHERE qid=$ia[0] AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' and scale_id=0 ORDER BY sortorder, answer"; } $ansresult = dbExecuteAssoc($ansquery)->readAll(); //Checked $anscount = count($ansresult); if (trim($aQuestionAttributes['display_columns'])!='') { $dcols = $aQuestionAttributes['display_columns']; } else { $dcols= 1; } if (trim($aQuestionAttributes['other_replace_text'][$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']])!='') { $othertext=$aQuestionAttributes['other_replace_text'][$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']]; } 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 = setupColumns($dcols , $anscount,"answers-list radio-list","answer-item radio-item"); $answer = $wrapper['whole-start']; //Time Limit Code if (trim($aQuestionAttributes['time_limit'])!='') { $answer .= return_timer_script($aQuestionAttributes, $ia); } //End Time Limit Code // Get array_filter stuff $rowcounter = 0; $colcounter = 1; $trbc=''; foreach ($ansresult as $key=>$ansrow) { $myfname = $ia[1].$ansrow['code']; $check_ans = ''; if ($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]] == $ansrow['code']) { $check_ans = CHECKED; } list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $aQuestionAttributes, $thissurvey, $ansrow, $myfname, $trbc, $myfname, "li","answer-item radio-item"); if(substr($wrapper['item-start'],0,4) == "\t '.$wrapper['item-end']; ++$rowcounter; if ($rowcounter == $wrapper['maxrows'] && $colcounter < $wrapper['cols'] || (count($ansresult)-$key)==$wrapper['cols']-$colcounter) { 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 ($aQuestionAttributes['other_numbers_only']==1) { $oth_checkconditionFunction = 'fixnum_checkconditions'; } else { $oth_checkconditionFunction = 'checkconditions'; } if ($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]] == '-oth-') { $check_ans = CHECKED; } else { $check_ans = ''; } $thisfieldname=$ia[1].'other'; if (isset($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$thisfieldname])) { $dispVal = $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$thisfieldname]; if ($aQuestionAttributes['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, $aQuestionAttributes, $thissurvey, array("code"=>"other"), $thisfieldname, $trbc, $myfname, "li", "answer-item radio-item other-item other"); if(substr($wrapper['item-start-other'],0,4) == "\t '.$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 ((!$_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]] || $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]] == '') || ($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$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-noanswer'].' '.$wrapper['item-end']; // --> END NEW FEATURE - SAVE ++$rowcounter; if ($rowcounter == $wrapper['maxrows'] && $colcounter < $wrapper['cols']) { if($colcounter == $wrapper['cols'] - 1) { $answer .= $wrapper['col-devide-last']; } else { $answer .= $wrapper['col-devide']; } $rowcounter = 0; ++$colcounter; } } //END OF ITEMS $answer .= $wrapper['whole-end'].' getConfig('surveyID')][$ia[1]]."\" />\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, $thissurvey; $clang=Yii::app()->lang; $dropdownthreshold = Yii::app()->getConfig("dropdownthreshold"); if ($thissurvey['nokeyboard']=='Y') { includeKeypad(); $kpclass = "text-keypad"; } else { $kpclass = ""; } $checkconditionFunction = "checkconditions"; $answer = ''; $aQuestionAttributes = getQuestionAttributeValues($ia[0], $ia[4]); if (!isset($maxoptionsize)) {$maxoptionsize=35;} //question attribute random order set? if ($aQuestionAttributes['random_order']==1) { $ansquery = "SELECT * FROM {{answers}} WHERE qid=$ia[0] AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' and scale_id=0 ORDER BY ".dbRandom(); } //question attribute alphasort set? elseif ($aQuestionAttributes['alphasort']==1) { $ansquery = "SELECT * FROM {{answers}} WHERE qid=$ia[0] AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' and scale_id=0 ORDER BY answer"; } //no question attributes -> order by sortorder else { $ansquery = "SELECT * FROM {{answers}} WHERE qid=$ia[0] AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' and scale_id=0 ORDER BY sortorder, answer"; } $ansresult=Yii::app()->db->createCommand($ansquery)->query()->readAll(); $anscount = count($ansresult); $hint_comment = $clang->gT('Please enter your comment here'); if ($aQuestionAttributes['use_dropdown']!=1 && $anscount <= $dropdownthreshold) { $answer .= '
    '; foreach ($ansresult as $ansrow) { $check_ans = ''; if ($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]] == $ansrow['code']) { $check_ans = CHECKED; } $answer .= '
  • '; } if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { if ((!$_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]] || $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]] == '') ||($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]] == ' ' )) { $check_ans = CHECKED; } elseif (($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]] || $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]] != '')) { $check_ans = ''; } $answer .= '
  • '; } $fname2 = $ia[1].'comment'; if ($anscount > 8) {$tarows = $anscount/1.2;} else {$tarows = 4;} // --> START NEW FEATURE - SAVE // --> START ORIGINAL // $answer .= "\t\n" // . "

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

    '; $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) { // note to self: this function needs to define: // inputnames, answer, among others global $thissurvey; $clang=Yii::app()->lang; $imageurl = Yii::app()->getConfig("imageurl"); $checkconditionFunction = "checkconditions"; $aQuestionAttributes = getQuestionAttributeValues($ia[0], $ia[4]); if ($aQuestionAttributes['random_order']==1) { $ansquery = "SELECT * FROM {{answers}} WHERE qid=$ia[0] AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' and scale_id=0 ORDER BY ".dbRandom(); } else { $ansquery = "SELECT * FROM {{answers}} WHERE qid=$ia[0] AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' and scale_id=0 ORDER BY sortorder, answer"; } $ansresult = Yii::app()->db->createCommand($ansquery)->query()->readAll(); //Checked $anscount= count($ansresult); if (trim($aQuestionAttributes["max_answers"])!='') { $max_answers=trim($aQuestionAttributes["max_answers"]); } else { $max_answers=$anscount; } if (trim($aQuestionAttributes["min_answers"])!='') { $min_answers=trim($aQuestionAttributes["min_answers"]); } else { $min_answers=0; } $answer = ''; // First start by a ranking without javascript : just a list of select box // construction select box $answers= array(); foreach ($ansresult as $ansrow) { $answers[] = $ansrow; } $answer .= '
      '; for ($i=1; $i<=$anscount; $i++) { $myfname=$ia[1].$i; $answer .= "\n
    • "; $answer .=""; $answer .= ""; // Hidden form: maybe can be replaced with ranking.js $answer .=""; $answer .="
    • "; $inputnames[]=$myfname; } $answer .="
    " . "" . "" . "" . "
    "; // The list with HTML answres $answer .="
    "; foreach ($answers as $ansrow) { $answer.="
    {$ansrow['answer']}
    "; } $answer .="
    "; header_includes("jquery/jquery.actual/jquery.actual.min.js"); // For jquery 1.5, can be removed with jquery 1.7, then had to rework on ranking.js header_includes("ranking.js"); header_includes("ranking.css","css"); if(trim($aQuestionAttributes['choice_title'][$clang->langcode]) != '') { $choice_title=htmlspecialchars(trim($aQuestionAttributes['choice_title'][$clang->langcode]), ENT_QUOTES); } else { $choice_title=$clang->gT("Your Choices",'js'); } if(trim($aQuestionAttributes['rank_title'][$clang->langcode]) != '') { $rank_title=htmlspecialchars(trim($aQuestionAttributes['rank_title'][$clang->langcode]), ENT_QUOTES); } else { $rank_title=$clang->gT("Your Ranking",'js'); } $answer .= "\n"; return array($answer, $inputnames); } // --------------------------------------------------------------- // TMSW TODO - Can remove DB query by passing in answer list from EM function do_multiplechoice($ia) { global $thissurvey; $clang = Yii::app()->lang; if ($thissurvey['nokeyboard']=='Y') { includeKeypad(); $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 {{question_attributes}} WHERE value LIKE '".strtolower($ia[2])."' and (attribute='array_filter' or attribute='array_filter_exclude')"; $qaresult = Yii::app()->db->createCommand($qaquery)->query(); //Checked foreach ($qaresult->readAll() as $qarow) { $qquery = "SELECT count(qid) FROM {{questions}} WHERE sid=".$thissurvey['sid']." AND scale_id=0 AND qid=".$qarow['qid']; $qresult = Yii::app()->db->createCommand($qquery)->queryScalar(); //Checked if ($qresult > 0) { $attribute_ref = true; } } $checkconditionFunction = "checkconditions"; $aQuestionAttributes = getQuestionAttributeValues($ia[0], $ia[4]); if (trim($aQuestionAttributes['other_replace_text'][$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']])!='') { $othertext=$aQuestionAttributes['other_replace_text'][$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']]; } else { $othertext=$clang->gT('Other:'); } if (trim($aQuestionAttributes['display_columns'])!='') { $dcols = $aQuestionAttributes['display_columns']; } else { $dcols = 1; } if ($aQuestionAttributes['other_numbers_only']==1) { $sSeperator = getRadixPointData($thissurvey['surveyls_numberformat']); $sSeperator= $sSeperator['seperator']; $oth_checkconditionFunction = "fixnum_checkconditions"; } else { $oth_checkconditionFunction = "checkconditions"; } $qquery = "SELECT other FROM {{questions}} WHERE qid=".$ia[0]." AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' and parent_qid=0"; $other = Yii::app()->db->createCommand($qquery)->queryScalar(); //Checked if ($aQuestionAttributes['random_order']==1) { $ansquery = "SELECT * FROM {{questions}} WHERE parent_qid=$ia[0] AND scale_id=0 AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' ORDER BY ".dbRandom(); } else { $ansquery = "SELECT * FROM {{questions}} WHERE parent_qid=$ia[0] AND scale_id=0 AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' ORDER BY question_order"; } $ansresult = dbExecuteAssoc($ansquery)->readAll(); //Checked $anscount = count($ansresult); if (trim($aQuestionAttributes['exclude_all_others'])!='' && $aQuestionAttributes['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($aQuestionAttributes['exclude_all_others']) != '') && ($answer['title']==trim($aQuestionAttributes['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 = setupColumns($dcols, $anscount,"subquestions-list questions-list checkbox-list","question-item answer-item checkbox-item"); $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']; $extra_class=""; $trbc=''; /* Check for array_filter */ list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $aQuestionAttributes, $thissurvey, $ansrow, $myfname, $trbc, $myfname, "li","question-item answer-item checkbox-item".$extra_class); if(substr($wrapper['item-start'],0,4) == "\tgetConfig('surveyID')][$myfname])) { if ($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname] == 'Y') { $answer .= CHECKED; } } $answer .= " onclick='cancelBubbleThis(event);"; $answer .= '' . "$checkconditionFunction(this.value, this.name, this.type)' />\n" . "\n"; // if ($maxansw > 0) {$maxanswscript .= "\tif (document.getElementById('answer".$myfname."').checked) { count += 1; }\n";} // if ($minansw > 0) {$minanswscript .= "\tif (document.getElementById('answer".$myfname."').checked) { count += 1; }\n";} ++$fn; /* Now add the hidden field to contain information about this answer */ $answer .= ' \n{$wrapper['item-end']}"; $inputnames[]=$myfname; ++$rowcounter; if ($rowcounter == $wrapper['maxrows'] && $colcounter < $wrapper['cols']) { if($colcounter == $wrapper['cols'] - 1) { $answer .= $wrapper['col-devide-last']; } else { $answer .= $wrapper['col-devide']; } $rowcounter = 0; ++$colcounter; } } if ($other == 'Y') { $myfname = $ia[1].'other'; list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $aQuestionAttributes, $thissurvey, array("code"=>"other"), $myfname, $trbc, $myfname, "li","question-item answer-item checkbox-item other-item"); if(substr($wrapper['item-start-other'],0,4) == "\t