function do_multiplenumeric($ia) { global $thissurvey; $extraclass = ""; $checkconditionFunction = "fixnum_checkconditions"; $aQuestionAttributes = QuestionAttribute::model()->getQuestionAttributes($ia[0]); $answer = ''; $sSeparator = getRadixPointData($thissurvey['surveyls_numberformat']); $sSeparator = $sSeparator['separator']; $extraclass .= " numberonly"; //Must turn on the "numbers only javascript" if (intval(trim($aQuestionAttributes['maximum_chars'])) > 0) { $maximum_chars = intval(trim($aQuestionAttributes['maximum_chars'])); // Only maxlength attribute, use textarea[maxlength] jquery selector for textarea $maxlength = "maxlength='{$maximum_chars}' "; $extraclass .= " maxchars maxchars-" . $maximum_chars; } else { $maxlength = " maxlength='25' "; } if (trim($aQuestionAttributes['prefix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '') { $prefix = $aQuestionAttributes['prefix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]; $extraclass .= " withprefix"; } else { $prefix = ''; } if (trim($aQuestionAttributes['suffix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '') { $suffix = $aQuestionAttributes['suffix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]; $extraclass .= " withsuffix"; } else { $suffix = ''; } $kpclass = testKeypad($thissurvey['nokeyboard']); // Virtual keyboard (probably obsolete today) $numbersonly_slider = ''; // DEPRECATED if (trim($aQuestionAttributes['text_input_width']) != '') { $tiwidth = $aQuestionAttributes['text_input_width']; $col = $aQuestionAttributes['text_input_width'] <= 12 ? $aQuestionAttributes['text_input_width'] : 12; //$extraclass .= " col-sm-".trim($col); } else { $tiwidth = 6; } $prefixclass = "numeric"; if ($aQuestionAttributes['slider_layout'] == 1) { $prefixclass = "slider"; $slider_layout = true; $extraclass .= " withslider"; $slider_step = trim(LimeExpressionManager::ProcessString("{{$aQuestionAttributes['slider_accuracy']}}", $ia[0], array(), false, 1, 1, false, false, true)); $slider_step = is_numeric($slider_step) ? $slider_step : 1; $slider_min = trim(LimeExpressionManager::ProcessString("{{$aQuestionAttributes['slider_min']}}", $ia[0], array(), false, 1, 1, false, false, true)); $slider_mintext = $slider_min = is_numeric($slider_min) ? $slider_min : 0; $slider_max = trim(LimeExpressionManager::ProcessString("{{$aQuestionAttributes['slider_max']}}", $ia[0], array(), false, 1, 1, false, false, true)); $slider_maxtext = $slider_max = is_numeric($slider_max) ? $slider_max : 100; $slider_default = trim(LimeExpressionManager::ProcessString("{{$aQuestionAttributes['slider_default']}}", $ia[0], array(), false, 1, 1, false, false, true)); $slider_default = is_numeric($slider_default) ? $slider_default : ""; $slider_orientation = trim($aQuestionAttributes['slider_orientation']) == 0 ? 'horizontal' : 'vertical'; $slider_custom_handle = trim($aQuestionAttributes['slider_custom_handle']); switch (trim($aQuestionAttributes['slider_handle'])) { case 0: $slider_handle = 'round'; break; case 1: $slider_handle = 'square'; break; case 2: $slider_handle = 'triangle'; break; case 3: $slider_handle = 'custom'; break; } if ($slider_default == '' && $aQuestionAttributes['slider_middlestart'] == 1) { $slider_middlestart = intval(($slider_max + $slider_min) / 2); } else { $slider_middlestart = ''; } $slider_separator = trim($aQuestionAttributes['slider_separator']) != '' ? $aQuestionAttributes['slider_separator'] : ""; $slider_reset = $aQuestionAttributes['slider_reset'] ? 1 : 0; // If the slider reset is ON, slider should be max 10 columns if ($slider_reset) { $tiwidth = $tiwidth < 10 ? $tiwidth : 10; } } else { $slider_layout = false; $slider_step = ''; $slider_min = ''; $slider_mintext = ''; $slider_max = ''; $slider_maxtext = ''; $slider_default = null; $slider_orientation = ''; $slider_handle = ''; $slider_custom_handle = ''; $slider_separator = ''; $slider_reset = 0; $slider_startvalue = ''; $slider_displaycallout = ''; } $hidetip = $aQuestionAttributes['hide_tip']; if ($aQuestionAttributes['random_order'] == 1) { $ansquery = "SELECT * FROM {{questions}} WHERE parent_qid={$ia['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 language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "' ORDER BY question_order"; } $ansresult = dbExecuteAssoc($ansquery); //Checked $aSubquestions = $ansresult->readAll(); $anscount = count($aSubquestions) * 2; $fn = 1; $sRows = ""; $answer_main = ''; $inputnames = array(); if ($anscount == 0) { $noanswer = true; $answer = doRender('/survey/questions/multiplenumeric/empty', array(), true); } else { foreach ($aSubquestions as $ansrow) { $labelText = $ansrow['question']; $myfname = $ia[1] . $ansrow['title']; if ($ansrow['question'] == "") { $ansrow['question'] = " "; } if ($slider_layout === false || $slider_separator == '') { $theanswer = $ansrow['question']; $sliders = false; } else { $aAnswer = explode($slider_separator, $ansrow['question']); $theanswer = isset($aAnswer[0]) ? $aAnswer[0] : ""; $labelText = $theanswer; $sliderleft = isset($aAnswer[1]) ? $aAnswer[1] : ""; $sliderright = isset($aAnswer[2]) ? $aAnswer[2] : ""; $sliders = true; } $aAnswer = isset($aAnswer) ? $aAnswer : ''; $sliderleft = isset($sliderleft) ? $sliderleft : ""; $sliderright = isset($sliderright) ? $sliderright : ""; // color code missing mandatory questions red $alert = ''; 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 ($ia[6] == 'Y' && $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname] === '') { $alert = true; } } //list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $aQuestionAttributes, $thissurvey, $ansrow, $myfname, '', $myfname, "div","form-group question-item answer-item text-item numeric-item".$extraclass); $sDisplayStyle = return_display_style($ia, $aQuestionAttributes, $thissurvey, $myfname); // TODO : check why it's done here a second time $sSeparator = getRadixPointData($thissurvey['surveyls_numberformat']); $sSeparator = $sSeparator['separator']; // The value of the slider depends on many possible different parameters, by order of priority : // 1. The value stored in the session // 2. Else the default Answer (set by EM and stored in session, so same case than 1) // 3. Else the init value // 4. Else the middle start // 5. If no value at all, or if middle start, the "user no action" is recorded as null in the database // For bootstrap slider, the value can't be NULL so we set it by default to the slider minimum value. // The old behaviour of "null" value (corresponding to user no action) is implemented via $slider_user_no_action // It could be used to show a temporary "No Answer" checkbox (hidden when user touch the slider) // Most of this javascript is here to handle the fact that bootstrapSlider need numerical value in the input // It can't accept "NULL" nor anyother thousand separator than "." (else it become a string) // See : https://github.com/LimeSurvey/LimeSurvey/blob/master/scripts/bootstrap-slider.js#l1453-l1461 // If the bootstrapSlider were updated, most of this javascript would not be necessary. $sValue = null; if (App()->request->getPost('slider_user_no_action_' . $myfname)) { $slider_user_no_action = App()->request->getPost('slider_user_no_action_' . $myfname); } else { $slider_user_no_action = 1; // value stored in _SESSION if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname])) { $sValue = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname]; $slider_user_no_action = 0; } elseif ($slider_default != "") { $sValue = $slider_default; $slider_user_no_action = 0; } elseif (isset($slider_middlestart) && $slider_middlestart != '') { $sValue = $slider_middlestart; } } $sUnformatedValue = $sValue; if (strpos($sValue, ".")) { $sValue = rtrim(rtrim($sValue, "0"), "."); $sValue = str_replace('.', $sSeparator, $sValue); } if (trim($aQuestionAttributes['num_value_int_only']) == 1) { $extraclass .= " integeronly"; $answertypeclass = " integeronly"; $integeronly = 1; } else { $answertypeclass = ""; $integeronly = 0; } if (!$sliders) { $sRows .= doRender('/survey/questions/multiplenumeric/rows/input/answer_row', array('qid' => $ia[0], 'extraclass' => $extraclass, 'answertypeclass' => $answertypeclass, 'sDisplayStyle' => $sDisplayStyle, 'kpclass' => $kpclass, 'alert' => $alert, 'theanswer' => $theanswer, 'labelname' => 'answer' . $myfname, 'prefixclass' => $prefixclass, 'prefix' => $prefix, 'suffix' => $suffix, 'tiwidth' => $tiwidth, 'myfname' => $myfname, 'dispVal' => $sValue, 'maxlength' => $maxlength, 'labelText' => $labelText, 'checkconditionFunction' => $checkconditionFunction . '(this.value, this.name, this.type, \'onchange\',' . $integeronly . ')', 'integeronly' => $integeronly), true); } else { $sRows .= doRender('/survey/questions/multiplenumeric/rows/sliders/answer_row', array('qid' => $ia[0], 'extraclass' => $extraclass, 'sDisplayStyle' => $sDisplayStyle, 'kpclass' => $kpclass, 'alert' => $alert, 'theanswer' => $theanswer, 'labelname' => 'answer' . $myfname, 'prefixclass' => $prefixclass, 'sliders' => $sliders, 'sliderleft' => $sliderleft, 'sliderright' => $sliderright, 'prefix' => $prefix, 'suffix' => $suffix, 'tiwidth' => $tiwidth, 'myfname' => $myfname, 'dispVal' => $sValue, 'maxlength' => $maxlength, 'labelText' => $labelText, 'checkconditionFunction' => $checkconditionFunction . '(this.value, this.name, this.type)', 'slider_orientation' => $slider_orientation, 'slider_step' => $slider_step, 'slider_min' => $slider_min, 'slider_mintext' => $slider_mintext, 'slider_max' => $slider_max, 'slider_maxtext' => $slider_maxtext, 'slider_default' => $slider_default, 'slider_handle' => isset($slider_handle) ? $slider_handle : '', 'slider_reset' => $slider_reset, 'slider_custom_handle' => $slider_custom_handle, 'slider_user_no_action' => $slider_user_no_action, 'slider_showminmax' => $aQuestionAttributes['slider_showminmax'], 'sSeparator' => $sSeparator, 'sUnformatedValue' => $sUnformatedValue), true); } $fn++; $inputnames[] = $myfname; } $displaytotal = false; $equals_num_value = false; if (trim($aQuestionAttributes['equals_num_value']) != '' || trim($aQuestionAttributes['min_num_value']) != '' || trim($aQuestionAttributes['max_num_value']) != '') { $qinfo = LimeExpressionManager::GetQuestionStatus($ia[0]); if (trim($aQuestionAttributes['equals_num_value']) != '') { $equals_num_value = true; } $displaytotal = true; } // TODO: Slider and multiple-numeric input should really be two different question types $templateFile = $sliders ? 'answer' : 'answer_input'; $answer = doRender('/survey/questions/multiplenumeric/' . $templateFile, array('sRows' => $sRows, 'prefixclass' => $prefixclass, 'equals_num_value' => $equals_num_value, 'id' => $ia[0], 'prefix' => $prefix, 'suffix' => $suffix, 'sumRemainingEqn' => isset($qinfo) ? $qinfo['sumRemainingEqn'] : '', 'displaytotal' => $displaytotal, 'sumEqn' => isset($qinfo) ? $qinfo['sumEqn'] : '', 'prefix' => $prefix), true); } if ($aQuestionAttributes['slider_layout'] == 1) { Yii::app()->getClientScript()->registerScriptFile(App()->baseUrl . "/third_party/bootstrap-slider/bootstrap-slider.js"); } $sSeparator = getRadixPointData($thissurvey['surveyls_numberformat']); $sSeparator = $sSeparator['separator']; return array($answer, $inputnames); }
function do_multiplechoice_withcomments($ia) { global $thissurvey; $inputnames = array(); $kpclass = testKeypad($thissurvey['nokeyboard']); // Virtual keyboard (probably obsolete today) $inputnames = array(); $attribute_ref = false; $qaquery = "SELECT qid,attribute FROM {{question_attributes}} WHERE value LIKE '" . strtolower($ia[2]) . "'"; $qaresult = Yii::app()->db->createCommand($qaquery)->query(); //Checked $attribute_ref = false; foreach ($qaresult->readAll() as $qarow) { $qquery = "SELECT qid FROM {{questions}} WHERE sid=" . $thissurvey['sid'] . " AND qid=" . $qarow['qid']; $qresult = Yii::app()->db->createCommand($qquery)->query(); //Checked if (count($qresult) > 0) { $attribute_ref = true; } } $checkconditionFunction = "checkconditions"; $aQuestionAttributes = QuestionAttribute::model()->getQuestionAttributes($ia[0]); if ($aQuestionAttributes['other_numbers_only'] == 1) { $sSeparator = getRadixPointData($thissurvey['surveyls_numberformat']); $sSeparator = $sSeparator['separator']; $oth_checkconditionFunction = "fixnum_checkconditions"; } else { $oth_checkconditionFunction = "checkconditions"; } 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 = gT('Other:'); } $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 language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "' ORDER BY " . dbRandom(); } else { $ansquery = "SELECT * FROM {{questions}} WHERE parent_qid={$ia['0']} AND language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "' ORDER BY question_order"; } $ansresult = Yii::app()->db->createCommand($ansquery)->query(); //Checked $anscount = count($ansresult) * 2; $answer = ""; $headerDatas = array('name' => 'MULTI' . $ia[1], 'value' => $anscount); $answer_main = Yii::app()->getController()->renderPartial('/survey/questions/multiplechoice_with_comments/header', $headerDatas, true); $fn = 1; if (!isset($other)) { $other = 'N'; } if ($other == 'Y') { $label_width = 25; } else { $label_width = 0; } // Size of elements depends on longest text item $toIterate = $ansresult->readAll(); $longest_question = 0; foreach ($toIterate as $ansrow) { $current_length = round(strlen($ansrow['question']) / 10 + 1); $longest_question = $longest_question > $current_length ? $longest_question : $current_length; } $nbCol = $longest_question; $nbColLabelLg = $nbCol > 11 ? 11 : $nbCol; $nbColInputLg = 11 - $nbColLabelLg; $nbColInputLg = $nbColInputLg < 1 ? 11 : $nbColInputLg; $nbColLabelXs = $nbColLabelLg + 5; $nbColLabelXs = $nbColLabelXs > 11 ? 11 : $nbColLabelXs; //$nbColInputXs = 11 - $nbColLabelXs; //$nbColInputXs = ($nbColInputXs < 1)?11:$nbColInputXs; $nbColInputXs = 12; foreach ($toIterate as $ansrow) { $myfname = $ia[1] . $ansrow['title']; $trbc = ''; /* Check for array_filter */ $sDisplayStyle = return_display_style($ia, $aQuestionAttributes, $thissurvey, $myfname); if ($label_width < strlen(trim(strip_tags($ansrow['question'])))) { $label_width = strlen(trim(strip_tags($ansrow['question']))); } $myfname2 = $myfname . "comment"; /* If the question has already been ticked, check the checkbox */ $checked = ''; if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname])) { if ($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname] == 'Y') { $checked = CHECKED; } } $javavalue = isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname]) ? $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname] : ''; $fn++; $fn++; $inputnames[] = $myfname; $inputnames[] = $myfname2; $inputCOmmentValue = htmlspecialchars($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname], ENT_QUOTES); $itemDatas = array('sDisplayStyle' => $sDisplayStyle, 'kpclass' => $kpclass, 'title' => '', 'liclasses' => 'responsive-content question-item answer-item checkbox-text-item', 'name' => $myfname, 'id' => 'answer' . $myfname, 'value' => 'Y', 'classes' => '', 'checkconditionFunction' => $checkconditionFunction . '(this.value, this.name, this.type)', 'checkconditionFunctionComment' => $checkconditionFunction . '(this.value, this.name, this.type)', 'labeltext' => $ansrow['question'], 'javainput' => true, 'javaname' => 'java' . $myfname, 'javavalue' => $javavalue, 'checked' => $checked, 'inputCommentId' => 'answer' . $myfname2, 'commentLabelText' => gT('Make a comment on your choice here:'), 'inputCommentName' => $myfname2, 'inputCOmmentValue' => $inputCOmmentValue); $answer_main .= Yii::app()->getController()->renderPartial('/survey/questions/multiplechoice_with_comments/item', $itemDatas, true); } if ($other == 'Y') { $myfname = $ia[1] . 'other'; $myfname2 = $myfname . 'comment'; $anscount = $anscount + 2; // SPAN LABEL OPTION ////////////////////////// if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname]) && $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname]) { $dispVal = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname]; if ($aQuestionAttributes['other_numbers_only'] == 1) { $dispVal = str_replace('.', $sSeparator, $dispVal); } $value = htmlspecialchars($dispVal, ENT_QUOTES); } $fn++; if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname2])) { $inputCOmmentValue = htmlspecialchars($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname2], ENT_QUOTES); } $itemDatas = array('liclasses' => 'other question-item answer-item checkbox-text-item other-item', 'liid' => 'javatbd' . $myfname, 'kpclass' => $kpclass, 'title' => gT('Other'), 'sDisplayStyle' => $sDisplayStyle, 'name' => $myfname, 'id' => 'answer' . $myfname, 'value' => $value, 'classes' => '', 'checkconditionFunction' => $oth_checkconditionFunction . '(this.value, this.name, this.type)', 'checkconditionFunctionComment' => $checkconditionFunction . '(this.value, this.name, this.type)', 'labeltext' => $othertext, 'inputCommentId' => 'answer' . $myfname2, 'commentLabelText' => gT('Make a comment on your choice here:'), 'inputCommentName' => $myfname2, 'inputCOmmentValue' => $inputCOmmentValue, 'checked' => $checked, 'javainput' => false, 'javaname' => '', 'javavalue' => ''); $answer_main .= Yii::app()->getController()->renderPartial('/survey/questions/multiplechoice_with_comments/item', $itemDatas, true); $inputnames[] = $myfname; $inputnames[] = $myfname2; } $answer_main .= Yii::app()->getController()->renderPartial('/survey/questions/multiplechoice_with_comments/footer', array(), true); $answer = $answer_main; if ($aQuestionAttributes['commented_checkbox'] != "allways" && $aQuestionAttributes['commented_checkbox_auto']) { Yii::app()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts') . "multiplechoice_withcomments.js"); $answer .= "<script type='text/javascript'>\n" . " /*<![CDATA[*/\n" . " doMultipleChoiceWithComments({$ia[0]},'{$aQuestionAttributes["commented_checkbox"]}');\n" . " /*]]>*/\n" . "</script>\n"; } return array($answer, $inputnames); }