function do_array_multiflexi($ia) { global $thissurvey; $answer = ''; $aLastMoveResult = LimeExpressionManager::GetLastMoveResult(); $aMandatoryViolationSubQ = $aLastMoveResult['mandViolation'] && $ia[6] == 'Y' ? explode("|", $aLastMoveResult['unansweredSQs']) : array(); $repeatheadings = Yii::app()->getConfig("repeatheadings"); $minrepeatheadings = Yii::app()->getConfig("minrepeatheadings"); $extraclass = ""; $answertypeclass = ""; $caption = gT("A table of subquestions on each cell. The subquestion texts are in the colum header and concern the row header."); $checkconditionFunction = "fixnum_checkconditions"; $defaultvaluescript = ''; $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 /* * Question Attributes */ $aQuestionAttributes = QuestionAttribute::model()->getQuestionAttributes($ia[0]); // Define min and max value if (trim($aQuestionAttributes['multiflexible_max']) != '' && trim($aQuestionAttributes['multiflexible_min']) == '') { $maxvalue = $aQuestionAttributes['multiflexible_max']; $minvalue = 1; $extraclass .= " maxvalue maxvalue-" . trim($aQuestionAttributes['multiflexible_max']); } if (trim($aQuestionAttributes['multiflexible_min']) != '' && trim($aQuestionAttributes['multiflexible_max']) == '') { $minvalue = $aQuestionAttributes['multiflexible_min']; $maxvalue = $aQuestionAttributes['multiflexible_min'] + 10; $extraclass .= " minvalue minvalue-" . trim($aQuestionAttributes['multiflexible_max']); } if (trim($aQuestionAttributes['multiflexible_min']) == '' && trim($aQuestionAttributes['multiflexible_max']) == '') { $maxvalue = 10; $minvalue = isset($minvalue['value']) && $minvalue['value'] == 0 ? 0 : 1; } if (trim($aQuestionAttributes['multiflexible_min']) != '' && trim($aQuestionAttributes['multiflexible_max']) != '') { if ($aQuestionAttributes['multiflexible_min'] < $aQuestionAttributes['multiflexible_max']) { $minvalue = $aQuestionAttributes['multiflexible_min']; $maxvalue = $aQuestionAttributes['multiflexible_max']; } } $stepvalue = trim($aQuestionAttributes['multiflexible_step']) != '' && $aQuestionAttributes['multiflexible_step'] > 0 ? $aQuestionAttributes['multiflexible_step'] : 1; if ($aQuestionAttributes['reverse'] == 1) { $tmp = $minvalue; $minvalue = $maxvalue; $maxvalue = $tmp; $reverse = true; $stepvalue = -$stepvalue; } else { $reverse = false; } $checkboxlayout = false; $inputboxlayout = false; $textAlignment = 'right'; if ($aQuestionAttributes['multiflexible_checkbox'] != 0) { $minvalue = 0; $maxvalue = 1; $checkboxlayout = true; $answertypeclass = " checkbox"; $caption .= gT("Please check the matching combinations."); $textAlignment = 'center'; } elseif ($aQuestionAttributes['input_boxes'] != 0) { $inputboxlayout = true; $answertypeclass .= " numeric-item text"; $extraclass .= " numberonly"; $caption .= gT("Please enter only numbers."); $textAlignment = 'right'; } else { $answertypeclass = " dropdown"; $caption .= gT("Please select an answer for each combination."); } if (ctype_digit(trim($aQuestionAttributes['repeat_headings'])) && trim($aQuestionAttributes['repeat_headings'] != "")) { $repeatheadings = intval($aQuestionAttributes['repeat_headings']); $minrepeatheadings = 0; } if (intval(trim($aQuestionAttributes['maximum_chars'])) > 0) { // Only maxlength attribute, use textarea[maxlength] jquery selector for textarea $maximum_chars = intval(trim($aQuestionAttributes['maximum_chars'])); $maxlength = "maxlength='{$maximum_chars}' "; $extraclass .= " maxchars maxchars-" . $maximum_chars; } else { $maxlength = ""; } if ($thissurvey['nokeyboard'] == 'Y') { includeKeypad(); $kpclass = " num-keypad"; $extraclass .= " inputkeypad"; } else { $kpclass = ""; } if (trim($aQuestionAttributes['answer_width']) != '') { $answerwidth = $aQuestionAttributes['answer_width']; $useAnswerWidth = true; } else { $answerwidth = 20; // If answerwidth is not given, we want to default to Bootstrap column. // Otherwise bug on phone screen. $useAnswerWidth = false; } $columnswidth = 100 - $answerwidth * 2; $lquery = "SELECT * FROM {{questions}} WHERE parent_qid={$ia[0]} AND language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "' and scale_id=1 ORDER BY question_order"; $lresult = dbExecuteAssoc($lquery); $aQuestions = $lresult->readAll(); $labelans = array(); $labelcode = array(); foreach ($aQuestions as $lrow) { $labelans[] = $lrow['question']; $labelcode[] = $lrow['title']; } if ($numrows = count($labelans)) { if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { $numrows++; } $cellwidth = $columnswidth / $numrows; $cellwidth = sprintf('%02d', $cellwidth); $sQuery = "SELECT count(question) FROM {{questions}} WHERE parent_qid=" . $ia[0] . " AND scale_id=0 AND question like '%|%'"; $iCount = Yii::app()->db->createCommand($sQuery)->queryScalar(); if ($iCount > 0) { $right_exists = true; $answerwidth = $answerwidth / 2; $caption .= gT("The last cell gives some information."); } 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 ($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 if (trim($aQuestionAttributes['parent_order'] != '')) { $iParentQID = (int) $aQuestionAttributes['parent_order']; $aResult = array(); $sessionao = isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['answer_order']) ? $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['answer_order'] : array(); if (isset($sessionao[$iParentQID])) { foreach ($sessionao[$iParentQID] as $aOrigRow) { $sCode = $aOrigRow['title']; foreach ($ansresult as $aRow) { if ($sCode == $aRow['title']) { $aResult[] = $aRow; } } } $ansresult = $aResult; } } $anscount = count($ansresult); $fn = 1; $sAnswerRows = ''; foreach ($ansresult as $j => $ansrow) { if (isset($repeatheadings) && $repeatheadings > 0 && $fn - 1 > 0 && ($fn - 1) % $repeatheadings == 0) { if ($anscount - $fn + 1 >= $minrepeatheadings) { $sAnswerRows .= doRender('/survey/questions/arrays/multiflexi/rows/repeat_header', array('labelans' => $labelans, 'right_exists' => $right_exists, 'cellwidth' => $cellwidth, 'answerwidth' => $answerwidth, 'textAlignment' => $textAlignment), true); } } $myfname = $ia[1] . $ansrow['title']; $answertext = $ansrow['question']; $answertextsave = $answertext; /* Check the sub Q mandatory violation */ $error = false; if ($ia[6] == 'Y' && !empty($aMandatoryViolationSubQ)) { //Go through each labelcode and check for a missing answer! Default :If any are found, highlight this line, checkbox : if one is not found : don't highlight // PS : we really need a better system : event for EM ! $emptyresult = $aQuestionAttributes['multiflexible_checkbox'] != 0 ? 1 : 0; foreach ($labelcode as $ld) { $myfname2 = $myfname . '_' . $ld; if ($aQuestionAttributes['multiflexible_checkbox'] != 0) { if (!in_array($myfname2, $aMandatoryViolationSubQ)) { $emptyresult = 0; } } else { if (in_array($myfname2, $aMandatoryViolationSubQ)) { $emptyresult = 1; } } } $error = $emptyresult == 1 ? true : false; } $sSeparator = getRadixPointData($thissurvey['surveyls_numberformat']); $sSeparator = $sSeparator['separator']; // Get array_filter stuff $sDisplayStyle = return_display_style($ia, $aQuestionAttributes, $thissurvey, $myfname); if (strpos($answertext, '|')) { $answertext = substr($answertext, 0, strpos($answertext, '|')); } $row_value = isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname]) ? $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname] : ''; $first_hidden_field = ''; $thiskey = 0; $answer_tds = ''; foreach ($labelcode as $i => $ld) { $myfname2 = $myfname . "_{$ld}"; $value = isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname2]) ? $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname2] : ''; // Possibly replace '.' with ',' $surveyId = Yii::app()->getConfig('surveyID'); $surveyLabel = 'survey_' . $surveyId; $fieldnameIsNumeric = isset($_SESSION[$surveyLabel][$myfname2]) && is_numeric($_SESSION[$surveyLabel][$myfname2]); if ($fieldnameIsNumeric) { $value = str_replace('.', $sSeparator, $_SESSION[$surveyLabel][$myfname2]); } if ($checkboxlayout == false) { $answer_tds .= doRender('/survey/questions/arrays/multiflexi/rows/cells/answer_td', array('dataTitle' => $labelans[$i], 'ld' => $ld, 'answertypeclass' => $answertypeclass, 'answertext' => $answertext, 'stepvalue' => $stepvalue, 'extraclass' => $extraclass, 'myfname2' => $myfname2, 'error' => $error, 'inputboxlayout' => $inputboxlayout, 'checkconditionFunction' => $checkconditionFunction, 'minvalue' => $minvalue, 'maxvalue' => $maxvalue, 'reverse' => $reverse, 'value' => $value, 'sSeparator' => $sSeparator, 'kpclass' => $kpclass, 'maxlength' => $maxlength), true); $inputnames[] = $myfname2; $thiskey++; } else { if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname2]) && $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname2] == '1') { $myvalue = '1'; $setmyvalue = CHECKED; } else { $myvalue = ''; $setmyvalue = ''; } $answer_tds .= doRender('/survey/questions/arrays/multiflexi/rows/cells/answer_td_checkboxes', array('dataTitle' => $labelans[$i], 'ld' => $ld, 'answertypeclass' => $answertypeclass, 'value' => $myvalue, 'setmyvalue' => $setmyvalue, 'myfname2' => $myfname2, 'checkconditionFunction' => $checkconditionFunction, 'extraclass' => $extraclass), true); $inputnames[] = $myfname2; $thiskey++; } } $rightTd = false; $answertextright = ''; if (strpos($answertextsave, '|')) { $answertextright = substr($answertextsave, strpos($answertextsave, '|') + 1); $rightTd = true; } elseif ($right_exists) { $rightTd = true; } $sAnswerRows .= doRender('/survey/questions/arrays/multiflexi/rows/answer_row', array('sDisplayStyle' => $sDisplayStyle, 'useAnswerWidth' => $useAnswerWidth, 'answerwidth' => $answerwidth, 'myfname' => $myfname, 'error' => $error, 'row_value' => $row_value, 'answertext' => $answertext, 'answertextright' => $answertextright, 'answer_tds' => $answer_tds, 'rightTd' => $rightTd, 'zebra' => 2 - $j % 2), true); $fn++; } $answer = doRender('/survey/questions/arrays/multiflexi/answer', array('answertypeclass' => $answertypeclass, 'extraclass' => $extraclass, 'answerwidth' => $answerwidth, 'labelans' => $labelans, 'cellwidth' => $cellwidth, 'right_exists' => $right_exists, 'sAnswerRows' => $sAnswerRows, 'textAlignment' => $textAlignment), true); } else { $answer = doRender('/survey/questions/arrays/multiflexi/empty_error', array(), true); $inputnames = ''; } return array($answer, $inputnames); }
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']; //Must turn on the "numbers only javascript" $extraclass .= " numberonly"; if ($aQuestionAttributes['thousands_separator'] == 1) { App()->clientScript->registerPackage('jquery-price-format'); App()->clientScript->registerScriptFile(Yii::app()->getConfig('generalscripts') . 'numerical_input.js'); $extraclass .= " thousandsseparator"; } if (intval(trim($aQuestionAttributes['maximum_chars'])) > 0) { // Only maxlength attribute, use textarea[maxlength] jquery selector for textarea $maximum_chars = intval(trim($aQuestionAttributes['maximum_chars'])); $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 = ''; } if ($thissurvey['nokeyboard'] == 'Y') { includeKeypad(); $kpclass = "num-keypad"; $extraclass .= " keypad"; } else { $kpclass = ""; } $numbersonly_slider = ''; // DEPRECATED if (trim($aQuestionAttributes['text_input_width']) != '') { $tiwidth = $aQuestionAttributes['text_input_width']; //$extraclass .=" inputwidth".trim($aQuestionAttributes['text_input_width']); $col = $aQuestionAttributes['text_input_width'] <= 12 ? $aQuestionAttributes['text_input_width'] : 12; $extraclass .= " col-sm-" . trim($col); } else { $tiwidth = 10; } $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; } else { $slider_layout = false; $slider_step = ''; $slider_step = ''; $slider_min = ''; $slider_mintext = ''; $slider_max = ''; $slider_maxtext = ''; $slider_default = ''; $slider_default = ''; $slider_orientation = ''; $slider_handle = ''; $slider_custom_handle = ''; $slider_separator = ''; } $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; $answer = Yii::app()->getController()->renderPartial('/survey/questions/multiplenumeric/header', array('prefixclass' => $prefixclass), true); $answer_main = ''; if ($anscount == 0) { $inputnames = array(); $noanswer = true; $answer .= ' <p class="text-danger">' . gT('Error: This question has no answers.') . "</p>\n"; } else { foreach ($aSubquestions as $ansrow) { $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] : ""; $sliderleft = isset($aAnswer[1]) ? $aAnswer[1] : ""; $sliderright = isset($aAnswer[2]) ? $aAnswer[2] : ""; $sliders = true; $sliderright = "<div class=\"slider_righttext\">{$sliderright}</div>"; } $aAnswer = isset($aAnswer) ? $aAnswer : ''; $sliderleft = isset($sliderleft) ? $sliderleft : ""; $sliderright = isset($sliderright) ? $sliderright : ""; // color code missing mandatory questions red $alert = ''; 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); $sSeparator = getRadixPointData($thissurvey['surveyls_numberformat']); $sSeparator = $sSeparator['separator']; $dispVal = ''; if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname])) { $dispVal = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname]; if (strpos($dispVal, ".")) { $dispVal = rtrim(rtrim($dispVal, "0"), "."); } $dispVal = str_replace('.', $sSeparator, $dispVal); } $itemDatas = array('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' => $dispVal, 'maxlength' => $maxlength, 'labelText' => $ansrow['question'], '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' => $slider_handle, 'slider_custom_handle' => $slider_custom_handle); $answer .= Yii::app()->getController()->renderPartial('/survey/questions/multiplenumeric/item', $itemDatas, 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; } $footerDatas = array('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'] : ''); $answer .= Yii::app()->getController()->renderPartial('/survey/questions/multiplenumeric/footer', $footerDatas, true); } if ($aQuestionAttributes['slider_layout'] == 1) { Yii::app()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts') . "bootstrap-slider.js"); Yii::app()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts') . "numeric-slider.js"); Yii::app()->getClientScript()->registerCssFile(Yii::app()->getConfig('publicstyleurl') . "numeric-slider.css"); if ($slider_default != "") { $slider_startvalue = $slider_default; $slider_displaycallout = 1; } elseif ($slider_middlestart != '') { $slider_startvalue = $slider_middlestart; $slider_displaycallout = 0; } else { $slider_startvalue = 'NULL'; $slider_displaycallout = 0; } $slider_showminmax = $aQuestionAttributes['slider_showminmax'] == 1 ? 1 : 0; //some var for slider $aJsLang = array('reset' => gT('Reset'), 'tip' => gT('Please click and drag the slider handles to enter your answer.')); $aJsVar = array('slider_showminmax' => $slider_showminmax, 'slider_min' => $slider_min, 'slider_mintext' => $slider_mintext, 'slider_max' => $slider_max, 'slider_maxtext' => $slider_maxtext, 'slider_step' => $slider_step, 'slider_startvalue' => $slider_startvalue, 'slider_displaycallout' => $slider_displaycallout, 'slider_prefix' => $prefix, 'slider_suffix' => $suffix, 'slider_reset' => $slider_reset, 'lang' => $aJsLang); /* $answer .= "<script type='text/javascript'><!--\n" . " doNumericSlider({$ia[0]},".ls_json_encode($aJsVar).");\n" . " //--></script>"; */ } $sSeparator = getRadixPointData($thissurvey['surveyls_numberformat']); $sSeparator = $sSeparator['separator']; return array($answer, $inputnames); }