function do_array_dual($ia) { global $thissurvey; $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 = ""; // Maybe not $caption = ""; // Just leave empty, are replaced after $inputnames = array(); $labelans1 = array(); $labelans = array(); $aQuestionAttributes = getQuestionAttributeValues($ia[0]); if ($aQuestionAttributes['random_order'] == 1) { $ansquery = "SELECT * FROM {{questions}} WHERE parent_qid={$ia['0']} AND language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "' and scale_id=0 ORDER BY " . dbRandom(); } else { $ansquery = "SELECT * FROM {{questions}} WHERE parent_qid={$ia['0']} AND language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "' and scale_id=0 ORDER BY question_order"; } $ansresult = dbExecuteAssoc($ansquery); //Checked $aSubQuestions = $ansresult->readAll(); $anscount = count($aSubQuestions); $lquery = "SELECT * FROM {{answers}} WHERE scale_id=0 AND qid={$ia[0]} AND language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "' ORDER BY sortorder, code"; $lresult = dbExecuteAssoc($lquery); //Checked $aAnswersScale0 = $lresult->readAll(); $lquery1 = "SELECT * FROM {{answers}} WHERE scale_id=1 AND qid={$ia[0]} AND language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "' ORDER BY sortorder, code"; $lresult1 = dbExecuteAssoc($lquery1); //Checked $aAnswersScale1 = $lresult1->readAll(); if ($aQuestionAttributes['use_dropdown'] == 1) { $useDropdownLayout = true; $extraclass .= " dropdown-list"; $answertypeclass .= " dropdown"; $doDualScaleFunction = "doDualScaleDropDown"; // javascript funtion to lauch at end of answers $caption = gT("An array with sub-question on each line, with 2 answers to provide on each line. You have to select the answer."); } else { $useDropdownLayout = false; $extraclass .= " radio-list"; $answertypeclass .= " radio"; $doDualScaleFunction = "doDualScaleRadio"; $caption = gT("An array with sub-question on each line, with 2 answers to provide on each line. The answers are contained in the table header. "); } if (ctype_digit(trim($aQuestionAttributes['repeat_headings'])) && trim($aQuestionAttributes['repeat_headings'] != "")) { $repeatheadings = intval($aQuestionAttributes['repeat_headings']); $minrepeatheadings = 0; } if (trim($aQuestionAttributes['dualscale_headerA'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '') { $leftheader = $aQuestionAttributes['dualscale_headerA'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]; } else { $leftheader = ''; } if (trim($aQuestionAttributes['dualscale_headerB'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '') { $rightheader = $aQuestionAttributes['dualscale_headerB'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]; } else { $rightheader = ''; } if (trim($aQuestionAttributes['answer_width']) != '') { $answerwidth = $aQuestionAttributes['answer_width']; } else { $answerwidth = 20; } // Find if we have rigth and center text // TODO move "|" to attribute $sQuery = "SELECT count(question) FROM {{questions}} WHERE parent_qid=" . $ia[0] . " and scale_id=0 AND question like '%|%'"; $rigthCount = Yii::app()->db->createCommand($sQuery)->queryScalar(); $rightexists = $rigthCount > 0; // $right_exists: flag to find out if there are any right hand answer parts. leaving right column but don't force with $sQuery = "SELECT count(question) FROM {{questions}} WHERE parent_qid=" . $ia[0] . " and scale_id=0 AND question like '%|%|%'"; $centerCount = Yii::app()->db->createCommand($sQuery)->queryScalar(); $centerexists = $centerCount > 0; // $center_exists: flag to find out if there are any center hand answer parts. leaving center column but don't force with // Label and code for input foreach ($aAnswersScale0 as $lrow) { $labels0[] = array('code' => $lrow['code'], 'title' => $lrow['answer']); } foreach ($aAnswersScale1 as $lrow) { $labels1[] = array('code' => $lrow['code'], 'title' => $lrow['answer']); } if (count($aAnswersScale0) > 0 && $anscount) { $answer = ""; $fn = 1; // Used by repeat_heading if ($useDropdownLayout === false) { $columnswidth = 100 - $answerwidth; foreach ($aAnswersScale0 as $lrow) { $labelans0[] = $lrow['answer']; $labelcode0[] = $lrow['code']; } foreach ($aAnswersScale1 as $lrow) { $labelans1[] = $lrow['answer']; $labelcode1[] = $lrow['code']; } $numrows = count($labelans0) + count($labelans1); // Add needed row and fill some boolean: shownoanswer, rightexists, centerexists $shownoanswer = $ia[6] != "Y" && SHOW_NO_ANSWER == 1; if ($shownoanswer) { $numrows++; $caption .= gT("The last cell are for no answer. "); } if ($rightexists) { $numrows++; } if ($centerexists) { $numrows++; } $cellwidth = $columnswidth / $numrows; //$cellwidth=sprintf("%02d", $cellwidth); // No reason to do this, except to leave place for separator ? But then table can not be the same in all browser // Header row and colgroups $mycolumns = "\t<col class=\"col-answers\" width=\"{$answerwidth}%\" />\n"; $answer_head_line = "\t<th class=\"header_answer_text\"> </th>\n\n"; $mycolumns .= "\t<colgroup class=\"col-responses group-1\">\n"; $odd_even = ''; foreach ($labelans0 as $ld) { $answer_head_line .= "\t<th>" . $ld . "</th>\n"; $odd_even = alternation($odd_even); $mycolumns .= "<col class=\"{$odd_even}\" width=\"{$cellwidth}%\" />\n"; } $mycolumns .= "\t</colgroup>\n"; if (count($labelans1) > 0) { $separatorwidth = $centerexists ? "width=\"{$cellwidth}%\" " : ""; $mycolumns .= "\t<col class=\"separator\" {$separatorwidth}/>\n"; $mycolumns .= "\t<colgroup class=\"col-responses group-2\">\n"; $answer_head_line .= "\n\t<td class=\"header_separator\"> </td>\n\n"; // Separator : and No answer for accessibility for first colgroup foreach ($labelans1 as $ld) { $answer_head_line .= "\t<th>" . $ld . "</th>\n"; $odd_even = alternation($odd_even); $mycolumns .= "<col class=\"{$odd_even}\" width=\"{$cellwidth}%\" />\n"; } $mycolumns .= "\t</colgroup>\n"; } if ($shownoanswer || $rightexists) { $rigthwidth = $rightexists ? "width=\"{$cellwidth}%\" " : ""; $mycolumns .= "\t<col class=\"separator rigth_separator\" {$rigthwidth}/>\n"; $answer_head_line .= "\n\t<td class=\"header_separator rigth_separator\"> </td>\n"; } if ($shownoanswer) { $mycolumns .= "\t<col class=\"col-no-answer\" width=\"{$cellwidth}%\" />\n"; $answer_head_line .= "\n\t<th class=\"header_no_answer\">" . gT('No answer') . "</th>\n"; } $answer_head2 = "\n<tr class=\"array1 header_row dontread\">\n" . $answer_head_line . "</tr>\n"; // build first row of header if needed if ($leftheader != '' || $rightheader != '') { $answer_head1 = "<tr class=\"array1 groups header_row\">\n" . "\t<th class=\"header_answer_text\"> </th>\n" . "\t<th colspan=\"" . count($labelans0) . "\" class=\"dsheader\">{$leftheader}</th>\n"; if (count($labelans1) > 0) { $answer_head1 .= "\t<td class=\"header_separator\"> </td>\n" . "\t<th colspan=\"" . count($labelans1) . "\" class=\"dsheader\">{$rightheader}</th>\n"; } if ($shownoanswer || $rightexists) { $rigthclass = $rightexists ? " header_answer_text_right" : ""; $answer_head1 .= "\t<td class=\"header_separator {$rigthclass}\"> </td>\n"; if ($shownoanswer) { $answer_head1 .= "\t<th class=\"header_no_answer\"> </th>\n"; } } $answer_head1 .= "</tr>\n"; } else { $answer_head1 = ""; } $answer .= "\n<table class=\"question subquestions-list questions-list\" summary=\"{$caption}\">\n" . $mycolumns . "\n\t<thead>\n" . $answer_head1 . $answer_head2 . "\n\t</thead>\n" . "<tbody>\n"; // And no each line of body $trbc = ''; foreach ($aSubQuestions as $ansrow) { // Build repeat headings if needed if (isset($repeatheadings) && $repeatheadings > 0 && $fn - 1 > 0 && ($fn - 1) % $repeatheadings == 0) { if ($anscount - $fn + 1 >= $minrepeatheadings) { $answer .= "</tbody>\n<tbody>"; // Close actual body and open another one //$answer .= $answer_head1; $answer .= "\n<tr class=\"repeat headings\">\n" . $answer_head_line . "</tr>\n"; } } $trbc = alternation($trbc, 'row'); $answertext = $ansrow['question']; // rigth and center answertext: not explode for ? Why not if (strpos($answertext, '|')) { $answertextrigth = substr($answertext, strpos($answertext, '|') + 1); $answertext = substr($answertext, 0, strpos($answertext, '|')); } else { $answertextrigth = ""; } if ($centerexists) { $answertextcenter = substr($answertextrigth, 0, strpos($answertextrigth, '|')); $answertextrigth = substr($answertextrigth, strpos($answertextrigth, '|') + 1); } else { $answertextcenter = ""; } $myfname = $ia[1] . $ansrow['title']; $myfname0 = $ia[1] . $ansrow['title'] . '#0'; $myfid0 = $ia[1] . $ansrow['title'] . '_0'; $myfname1 = $ia[1] . $ansrow['title'] . '#1'; // new multi-scale-answer $myfid1 = $ia[1] . $ansrow['title'] . '_1'; /* Check the Sub Q mandatory violation */ if ($ia[6] == 'Y' && (in_array($myfname0, $aMandatoryViolationSubQ) || in_array($myfname1, $aMandatoryViolationSubQ))) { $answertext = "<span class='errormandatory'>{$answertext}</span>"; } // Get array_filter stuff list($htmltbody2, $hiddenfield) = return_array_filter_strings($ia, $aQuestionAttributes, $thissurvey, $ansrow, $myfname, $trbc, $myfname, "tr", "{$trbc} answers-list radio-list"); $answer .= $htmltbody2; array_push($inputnames, $myfname0); $answer .= "\t<th class=\"answertext\">\n" . $hiddenfield . "{$answertext}\n"; // Hidden answers used by EM: sure can be added in javascript $answer .= "<input type=\"hidden\" disabled=\"disabled\" name=\"java{$myfid0}\" id=\"java{$myfid0}\" value=\""; if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0])) { $answer .= $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0]; } $answer .= "\" />\n"; if (count($labelans1) > 0) { $answer .= "<input type=\"hidden\" disabled=\"disabled\" name=\"java{$myfid1}\" id=\"java{$myfid1}\" value=\""; if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1])) { $answer .= $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1]; } $answer .= "\" />\n"; } $answer .= "\t</th>\n"; $hiddenanswers = ''; $thiskey = 0; foreach ($labelcode0 as $ld) { $answer .= "\t<td class=\"answer_cell_1_00{$ld} answer-item {$answertypeclass}-item\">\n" . "\t<input class=\"radio\" type=\"radio\" name=\"{$myfname0}\" value=\"{$ld}\" id=\"answer{$myfid0}-{$ld}\" "; if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0]) && $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0] == $ld) { $answer .= CHECKED; } $answer .= " />\n" . "<label class=\"hide read\" for=\"answer{$myfid0}-{$ld}\">{$labelans0[$thiskey]}</label>\n" . "\n\t</td>\n"; $thiskey++; } if (count($labelans1) > 0) { $answer .= "\t<td class=\"dual_scale_separator information-item\">"; if ($shownoanswer) { $answer .= "\t<input class='radio jshide read' type='radio' name='{$myfname0}' value='' id='answer{$myfid0}-' "; if (!isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0]) || $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0] == "") { $answer .= CHECKED; } $answer .= " />\n"; } $answer .= "<label for='answer{$myfid0}-' class= \"hide read\">" . gT("No answer") . "</label>"; $answer .= "\t{$answertextcenter}</td>\n"; // separator array_push($inputnames, $myfname1); $thiskey = 0; foreach ($labelcode1 as $ld) { $answer .= "\t<td class=\"answer_cell_2_00{$ld} answer-item radio-item\">\n" . "\t<input class=\"radio\" type=\"radio\" name=\"{$myfname1}\" value=\"{$ld}\" id=\"answer{$myfid1}-{$ld}\" "; if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1]) && $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1] == $ld) { $answer .= CHECKED; } $answer .= " />\n" . "<label class=\"hide read\" for=\"answer{$myfid1}-{$ld}\">{$labelans1[$thiskey]}</label>\n" . "\t</td>\n"; $thiskey++; } } if ($shownoanswer || $rightexists) { $answer .= "\t<td class=\"answertextright dual_scale_separator information-item\">{$answertextrigth}</td>\n"; } if ($shownoanswer) { $answer .= "\t<td class=\"dual_scale_no_answer answer-item radio-item noanswer-item\">\n"; if (count($labelans1) > 0) { $answer .= "\t<input class='radio' type='radio' name='{$myfname1}' value='' id='answer{$myfid1}-' "; if (!isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1]) || $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1] == "") { $answer .= CHECKED; } // --> START NEW FEATURE - SAVE $answer .= " />\n"; $answer .= "<label class='hide read' for='answer{$myfid1}-'>" . gT("No answer") . "</label>"; } else { $answer .= "\t<input class='radio' type='radio' name='{$myfname0}' value='' id='answer{$myfid0}-' "; if (!isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0]) || $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0] == "") { $answer .= CHECKED; } $answer .= "<label class='hide read' for='answer{$myfid0}-'>" . gT("No answer") . "<label>\n"; $answer .= " />\n"; } $answer .= "\t</td>\n"; } $answer .= "</tr>\n"; $fn++; } $answer .= "</tbody>\n"; $answer .= "</table>"; } elseif ($useDropdownLayout === true) { $separatorwidth = (100 - $answerwidth) / 10; $cellwidth = (100 - $answerwidth - $separatorwidth) / 2; $answer = ""; // Get attributes for Headers and Prefix/Suffix if (trim($aQuestionAttributes['dropdown_prepostfix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '') { list($ddprefix, $ddsuffix) = explode("|", $aQuestionAttributes['dropdown_prepostfix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]); $ddprefix = $ddprefix; $ddsuffix = $ddsuffix; } else { $ddprefix = ''; $ddsuffix = ''; } if (trim($aQuestionAttributes['dropdown_separators']) != '') { $aSeparator = explode('|', $aQuestionAttributes['dropdown_separators']); if (isset($aSeparator[1])) { $interddSep = $aSeparator[1]; } else { $interddSep = $aSeparator[0]; } } else { $interddSep = ''; } $colspan_1 = ''; $colspan_2 = ''; $suffix_cell = ''; $answer .= "\n<table class=\"question subquestion-list questions-list dropdown-list\" summary=\"{$caption}\">\n" . "\t<col class=\"answertext\" width=\"{$answerwidth}%\" />\n"; if ($ddprefix != '' || $ddsuffix != '') { $answer .= "\t<colgroup width=\"{$cellwidth}%\">\n"; } if ($ddprefix != '') { $answer .= "\t\t<col class=\"ddprefix\" />\n"; $colspan_1 = ' colspan="2"'; } $headcolwidth = $ddprefix != '' || $ddsuffix != '' ? "" : " width=\"{$cellwidth}%\""; $answer .= "\t<col class=\"dsheader\"{$headcolwidth} />\n"; if ($ddsuffix != '') { $answer .= "\t<col class=\"ddsuffix\" />\n"; } if ($ddprefix != '' || $ddsuffix != '') { $answer .= "\t</colgroup>\n"; } $answer .= "\t<col class=\"ddarrayseparator\" width=\"{$separatorwidth}%\" />\n"; if ($ddprefix != '' || $ddsuffix != '') { $answer .= "\t<colgroup width=\"{$cellwidth}%\">\n"; } if ($ddprefix != '') { $answer .= "\t\t<col class=\"ddprefix\" />\n"; } $answer .= "\t<col class=\"dsheader\"{$headcolwidth} />\n"; if ($ddsuffix != '') { $answer .= "\t<col class=\"ddsuffix\" />\n"; } if ($ddprefix != '' || $ddsuffix != '') { $answer .= "\t</colgroup>\n"; } // colspan : for header only if ($ddprefix != '' && $ddsuffix != '') { $colspan = ' colspan="3"'; } elseif ($ddprefix != '' || $ddsuffix != '') { $colspan = ' colspan="2"'; } else { $colspan = ""; } // headers $answer .= "\n\t<thead>\n" . "<tr>\n" . "\t<td> </td>\n" . "\t<th{$colspan}>{$leftheader}</th>\n" . "\t<td> </td>\n" . "\t<th{$colspan}>{$rightheader}</th>\n"; $answer .= "\t</tr>\n" . "\t</thead>\n"; $answer .= "\n<tbody>\n"; $trbc = ''; foreach ($aSubQuestions as $ansrow) { $myfname = $ia[1] . $ansrow['title']; $myfname0 = $ia[1] . $ansrow['title'] . "#0"; $myfid0 = $ia[1] . $ansrow['title'] . "_0"; $myfname1 = $ia[1] . $ansrow['title'] . "#1"; $myfid1 = $ia[1] . $ansrow['title'] . "_1"; $sActualAnswer0 = isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0]) ? $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0] : ""; $sActualAnswer1 = isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1]) ? $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1] : ""; if ($ia[6] == 'Y' && (in_array($myfname0, $aMandatoryViolationSubQ) || in_array($myfname1, $aMandatoryViolationSubQ))) { $answertext = "<span class='errormandatory'>" . $ansrow['question'] . "</span>"; } else { $answertext = $ansrow['question']; } list($htmltbody2, $hiddenfield) = return_array_filter_strings($ia, $aQuestionAttributes, $thissurvey, $ansrow, $myfname, $trbc, $myfname, "tr", "{$trbc} subquestion-list questions-list dropdown-list"); $answer .= $htmltbody2; $answer .= "\t<th class=\"answertext\">\n" . "<label for=\"answer{$myfid0}\">{$answertext}</label>\n"; // Hidden answers used by EM: sure can be added in javascript $answer .= "<input type=\"hidden\" disabled=\"disabled\" name=\"java{$myfid0}\" id=\"java{$myfid0}\" value=\"{$sActualAnswer0}\" />\n"; $answer .= "<input type=\"hidden\" disabled=\"disabled\" name=\"java{$myfid1}\" id=\"java{$myfid1}\" value=\"{$sActualAnswer1}\" />\n"; $answer . "\t</th>\n"; // Selector 0 if ($ddprefix != '') { $answer .= "\t<td class=\"ddprefix information-item\">{$ddprefix}</td>\n"; } $answer .= "\t<td class=\"answer-item dropdown-item\">\n" . "<select name=\"{$myfname0}\" id=\"answer{$myfid0}\">\n"; // Show the 'Please choose' if there are no answer actually if ($sActualAnswer0 == '') { $answer .= "\t<option value=\"\" " . SELECTED . ">" . gT('Please choose...') . "</option>\n"; } foreach ($labels0 as $lrow) { $answer .= "\t<option value=\"" . $lrow['code'] . '" '; if ($sActualAnswer0 == $lrow['code']) { $answer .= SELECTED; } $answer .= '>' . flattenText($lrow['title']) . "</option>\n"; } if ($sActualAnswer0 != '' && $ia[6] != 'Y' && SHOW_NO_ANSWER) { $answer .= "\t<option value=\"\">" . gT('No answer') . "</option>\n"; } $answer .= "</select>\n"; $answer .= "</td>\n"; if ($ddsuffix != '') { $answer .= "\t<td class=\"ddsuffix information-item\">{$ddsuffix}</td>\n"; } $inputnames[] = $myfname0; $answer .= "\t<td class=\"ddarrayseparator information-item\">{$interddSep}</td>\n"; //Separator // Selector 1 if ($ddprefix != '') { $answer .= "\t<td class='ddprefix information-item'>{$ddprefix}</td>\n"; } $answer .= "\t<td class=\"answer-item dropdown-item\">\n" . "<label class=\"hide read\" for=\"answer{$myfid1}\">{$answertext}</label>" . "<select name=\"{$myfname1}\" id=\"answer{$myfid1}\">\n"; // Show the 'Please choose' if there are no answer actually if ($sActualAnswer1 == '') { $answer .= "\t<option value=\"\" " . SELECTED . ">" . gT('Please choose...') . "</option>\n"; } foreach ($labels1 as $lrow1) { $answer .= "\t<option value=\"" . $lrow1['code'] . '" '; if ($sActualAnswer1 == $lrow1['code']) { $answer .= SELECTED; } $answer .= '>' . flattenText($lrow1['title']) . "</option>\n"; } if ($sActualAnswer1 != '' && $ia[6] != 'Y' && SHOW_NO_ANSWER) { $answer .= "\t<option value=\"\">" . gT('No answer') . "</option>\n"; } $answer .= "</select>\n"; $answer .= "</td>\n"; if ($ddsuffix != '') { $answer .= "\t<td class=\"ddsuffix information-item\">{$ddsuffix}</td>\n"; } $inputnames[] = $myfname1; $answer .= "</tr>\n"; } $answer .= "\t</tbody>\n"; $answer .= "</table>\n"; } } else { $answer = "<p class='error'>" . gT("Error: There are no answer options for this question and/or they don't exist in this language.") . "</p>\n"; $inputnames = ""; } Yii::app()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts') . "dualscale.js"); $answer .= "<script type='text/javascript'>\n" . " <!--\n" . " {$doDualScaleFunction}({$ia[0]});\n" . " -->\n" . "</script>\n"; return array($answer, $inputnames); }
$fcount = $fresult->RecordCount(); $fwidth = "120"; $i = 0; $pdfoutput = array(); $pdfoutput[0][0] = ''; while ($frow = $fresult->FetchRow()) { $question['ANSWER'] .= "\t\t\t<th>{$frow['question']}" . addsgqacode(" (" . $fieldname . $frow['title'] . ")") . "</th>\n"; $i++; $pdfoutput[0][$i] = $frow['question']; } $question['ANSWER'] .= "\t\t</tr>\n\t</thead>\n\n\t<tbody>\n"; $a = 1; $rowclass = 'array1'; while ($mearow = $mearesult->FetchRow()) { $question['ANSWER'] .= "\t\t<tr class=\"{$rowclass}\">\n"; $rowclass = alternation($rowclass, 'row'); $question['ANSWER'] .= "\t\t\t<th class=\"answertext\">{$mearow['answer']}" . addsgqacode(" (" . $mearow['code'] . ")") . "</th>\n"; //$printablesurveyoutput .="\t\t\t\t\t<td>"; $pdfoutput[$a][0] = $mearow['answer']; for ($i = 1; $i <= $fcount; $i++) { $question['ANSWER'] .= "\t\t\t<td>" . input_type_image('radio') . "</td>\n"; $pdfoutput[$a][$i] = "o"; } //$printablesurveyoutput .="\t\t\t\t\t</tr></table></td>\n"; $question['ANSWER'] .= "\t\t</tr>\n"; $a++; } $question['ANSWER'] .= "\t</tbody>\n</table>\n"; if (isset($_POST['printableexport'])) { $pdf->tableintopdf($pdfoutput); }
/** * Show printable survey */ function index($surveyid, $lang = null) { $surveyid = sanitize_int($surveyid); if (!Permission::model()->hasSurveyPermission($surveyid, 'surveycontent', 'read')) { $aData['surveyid'] = $surveyid; App()->getClientScript()->registerPackage('jquery-superfish'); $message['title'] = gT('Access denied!'); $message['message'] = gT('You do not have sufficient rights to access this page.'); $message['class'] = "error"; $this->_renderWrappedTemplate('survey', array("message" => $message), $aData); } else { $aSurveyInfo = getSurveyInfo($surveyid, $lang); if (!$aSurveyInfo) { $this->getController()->error('Invalid survey ID'); } SetSurveyLanguage($surveyid, $lang); $sLanguageCode = App()->language; $templatename = $aSurveyInfo['template']; $welcome = $aSurveyInfo['surveyls_welcometext']; $end = $aSurveyInfo['surveyls_endtext']; $surveyname = $aSurveyInfo['surveyls_title']; $surveydesc = $aSurveyInfo['surveyls_description']; $surveyactive = $aSurveyInfo['active']; $surveytable = "{{survey_" . $aSurveyInfo['sid'] . "}}"; $surveyexpirydate = $aSurveyInfo['expires']; $surveyfaxto = $aSurveyInfo['faxto']; $dateformattype = $aSurveyInfo['surveyls_dateformat']; Yii::app()->loadHelper('surveytranslator'); if (!is_null($surveyexpirydate)) { $dformat = getDateFormatData($dateformattype); $dformat = $dformat['phpdate']; $expirytimestamp = strtotime($surveyexpirydate); $expirytimeofday_h = date('H', $expirytimestamp); $expirytimeofday_m = date('i', $expirytimestamp); $surveyexpirydate = date($dformat, $expirytimestamp); if (!empty($expirytimeofday_h) || !empty($expirytimeofday_m)) { $surveyexpirydate .= ' – ' . $expirytimeofday_h . ':' . $expirytimeofday_m; } sprintf(gT("Please submit by %s"), $surveyexpirydate); } else { $surveyexpirydate = ''; } //Fix $templatename : control if print_survey.pstpl exist if (is_file(getTemplatePath($templatename) . DIRECTORY_SEPARATOR . 'print_survey.pstpl')) { $templatename = $templatename; // Change nothing } elseif (is_file(getTemplatePath(Yii::app()->getConfig("defaulttemplate")) . DIRECTORY_SEPARATOR . 'print_survey.pstpl')) { $templatename = Yii::app()->getConfig("defaulttemplate"); } else { $templatename = "default"; } $sFullTemplatePath = getTemplatePath($templatename) . DIRECTORY_SEPARATOR; $sFullTemplateUrl = getTemplateURL($templatename) . "/"; define('PRINT_TEMPLATE_DIR', $sFullTemplatePath, true); define('PRINT_TEMPLATE_URL', $sFullTemplateUrl, true); LimeExpressionManager::StartSurvey($surveyid, 'survey', NULL, false, LEM_PRETTY_PRINT_ALL_SYNTAX); $moveResult = LimeExpressionManager::NavigateForwards(); $condition = "sid = '{$surveyid}' AND language = '{$sLanguageCode}'"; $degresult = QuestionGroup::model()->getAllGroups($condition, array('group_order')); //xiao, if (!isset($surveyfaxto) || !$surveyfaxto and isset($surveyfaxnumber)) { $surveyfaxto = $surveyfaxnumber; //Use system fax number if none is set in survey. } $headelements = getPrintableHeader(); //if $showsgqacode is enabled at config.php show table name for reference $showsgqacode = Yii::app()->getConfig("showsgqacode"); if (isset($showsgqacode) && $showsgqacode == true) { $surveyname = $surveyname . "<br />[" . gT('Database') . " " . gT('table') . ": {$surveytable}]"; } else { $surveyname = $surveyname; } $survey_output = array('SITENAME' => Yii::app()->getConfig("sitename"), 'SURVEYNAME' => $surveyname, 'SURVEYDESCRIPTION' => $surveydesc, 'WELCOME' => $welcome, 'END' => $end, 'THEREAREXQUESTIONS' => 0, 'SUBMIT_TEXT' => gT("Submit Your Survey."), 'SUBMIT_BY' => $surveyexpirydate, 'THANKS' => gT("Thank you for completing this survey."), 'HEADELEMENTS' => $headelements, 'TEMPLATEURL' => PRINT_TEMPLATE_URL, 'FAXTO' => $surveyfaxto, 'PRIVACY' => '', 'GROUPS' => ''); $survey_output['FAX_TO'] = ''; if (!empty($surveyfaxto) && $surveyfaxto != '000-00000000') { $survey_output['FAX_TO'] = gT("Please fax your completed survey to:") . " {$surveyfaxto}"; } $total_questions = 0; $mapquestionsNumbers = array(); $answertext = ''; // otherwise can throw an error on line 1617 $fieldmap = createFieldMap($surveyid, 'full', false, false, $sLanguageCode); // ========================================================= // START doin the business: foreach ($degresult->readAll() as $degrow) { // --------------------------------------------------- // START doing groups $deqresult = Question::model()->getQuestions($surveyid, $degrow['gid'], $sLanguageCode, 0, '"I"'); $deqrows = array(); //Create an empty array in case FetchRow does not return any rows foreach ($deqresult->readAll() as $deqrow) { $deqrows[] = $deqrow; } // Get table output into array // Perform a case insensitive natural sort on group name then question title of a multidimensional array usort($deqrows, 'groupOrderThenQuestionOrder'); if ($degrow['description']) { $group_desc = $degrow['description']; } else { $group_desc = ''; } $group = array('GROUPNAME' => $degrow['group_name'], 'GROUPDESCRIPTION' => $group_desc, 'QUESTIONS' => ''); // A group can have only hidden questions. In that case you don't want to see the group's header/description either. $bGroupHasVisibleQuestions = false; $gid = $degrow['gid']; //Alternate bgcolor for different groups if (!isset($group['ODD_EVEN']) || $group['ODD_EVEN'] == ' g-row-even') { $group['ODD_EVEN'] = ' g-row-odd'; } else { $group['ODD_EVEN'] = ' g-row-even'; } //Loop through questions foreach ($deqrows as $deqrow) { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // START doing questions $qidattributes = getQuestionAttributeValues($deqrow['qid'], $deqrow['type']); if ($qidattributes['hidden'] == 1 && $deqrow['type'] != '*') { continue; } $bGroupHasVisibleQuestions = true; //GET ANY CONDITIONS THAT APPLY TO THIS QUESTION $printablesurveyoutput = ''; $sExplanation = ''; //reset conditions explanation $s = 0; // TMSW Condition->Relevance: show relevance instead of this whole section to create $explanation $scenarioresult = Condition::model()->getScenarios($deqrow['qid']); $scenarioresult = $scenarioresult->readAll(); //Loop through distinct scenarios, thus grouping them together. foreach ($scenarioresult as $scenariorow) { if ($s == 0 && count($scenarioresult) > 1) { $sExplanation .= '<p class="scenario">' . " -------- Scenario {$scenariorow['scenario']} --------</p>\n\n"; } if ($s > 0) { $sExplanation .= '<p class="scenario">' . ' -------- ' . gT("or") . " Scenario {$scenariorow['scenario']} --------</p>\n\n"; } $x = 0; $conditions1 = "qid={$deqrow['qid']} AND scenario={$scenariorow['scenario']}"; $distinctresult = Condition::model()->getSomeConditions(array('cqid', 'method', 'cfieldname'), $conditions1, array('cqid'), array('cqid', 'method', 'cfieldname')); //Loop through each condition for a particular scenario. foreach ($distinctresult->readAll() as $distinctrow) { $condition = "qid = '{$distinctrow['cqid']}' AND parent_qid = 0 AND language = '{$sLanguageCode}'"; $subresult = Question::model()->find($condition); if ($x > 0) { $sExplanation .= ' <em class="scenario-and-separator">' . gT('and') . '</em> '; } if (trim($distinctrow['method']) == '') { $distinctrow['method'] = '=='; } if ($distinctrow['cqid']) { // cqid != 0 ==> previous answer match if ($distinctrow['method'] == '==') { $sExplanation .= gT("Answer was") . " "; } elseif ($distinctrow['method'] == '!=') { $sExplanation .= gT("Answer was NOT") . " "; } elseif ($distinctrow['method'] == '<') { $sExplanation .= gT("Answer was less than") . " "; } elseif ($distinctrow['method'] == '<=') { $sExplanation .= gT("Answer was less than or equal to") . " "; } elseif ($distinctrow['method'] == '>=') { $sExplanation .= gT("Answer was greater than or equal to") . " "; } elseif ($distinctrow['method'] == '>') { $sExplanation .= gT("Answer was greater than") . " "; } elseif ($distinctrow['method'] == 'RX') { $sExplanation .= gT("Answer matched (regexp)") . " "; } else { $sExplanation .= gT("Answer was") . " "; } } if (!$distinctrow['cqid']) { // cqid == 0 ==> token attribute match $tokenData = getTokenFieldsAndNames($surveyid); preg_match('/^{TOKEN:([^}]*)}$/', $distinctrow['cfieldname'], $extractedTokenAttr); $sExplanation .= "Your " . $tokenData[strtolower($extractedTokenAttr[1])]['description'] . " "; if ($distinctrow['method'] == '==') { $sExplanation .= gT("is") . " "; } elseif ($distinctrow['method'] == '!=') { $sExplanation .= gT("is NOT") . " "; } elseif ($distinctrow['method'] == '<') { $sExplanation .= gT("is less than") . " "; } elseif ($distinctrow['method'] == '<=') { $sExplanation .= gT("is less than or equal to") . " "; } elseif ($distinctrow['method'] == '>=') { $sExplanation .= gT("is greater than or equal to") . " "; } elseif ($distinctrow['method'] == '>') { $sExplanation .= gT("is greater than") . " "; } elseif ($distinctrow['method'] == 'RX') { $sExplanation .= gT("is matched (regexp)") . " "; } else { $sExplanation .= gT("is") . " "; } $answer_section = ' ' . $distinctrow['value'] . ' '; } $conresult = Condition::model()->getConditionsQuestions($distinctrow['cqid'], $deqrow['qid'], $scenariorow['scenario'], $sLanguageCode); $conditions = array(); foreach ($conresult->readAll() as $conrow) { $postans = ""; $value = $conrow['value']; switch ($conrow['type']) { case "Y": switch ($conrow['value']) { case "Y": $conditions[] = gT("Yes"); break; case "N": $conditions[] = gT("No"); break; } break; case "G": switch ($conrow['value']) { case "M": $conditions[] = gT("Male"); break; case "F": $conditions[] = gT("Female"); break; } // switch break; case "A": case "B": case ":": case ";": case "5": $conditions[] = $conrow['value']; break; case "C": switch ($conrow['value']) { case "Y": $conditions[] = gT("Yes"); break; case "U": $conditions[] = gT("Uncertain"); break; case "N": $conditions[] = gT("No"); break; } // switch break; case "E": switch ($conrow['value']) { case "I": $conditions[] = gT("Increase"); break; case "D": $conditions[] = gT("Decrease"); break; case "S": $conditions[] = gT("Same"); break; } case "1": $labelIndex = preg_match("/^[^#]+#([01]{1})\$/", $conrow['cfieldname']); if ($labelIndex == 0) { // TIBO $condition = "qid='{$conrow['cqid']}' AND code='{$conrow['value']}' AND scale_id=0 AND language='{$sLanguageCode}'"; $fresult = Answer::model()->getAllRecords($condition); foreach ($fresult->readAll() as $frow) { $postans = $frow['answer']; $conditions[] = $frow['answer']; } // while } elseif ($labelIndex == 1) { $condition = "qid='{$conrow['cqid']}' AND code='{$conrow['value']}' AND scale_id=1 AND language='{$sLanguageCode}'"; $fresult = Answer::model()->getAllRecords($condition); foreach ($fresult->readAll() as $frow) { $postans = $frow['answer']; $conditions[] = $frow['answer']; } // while } break; case "L": case "!": case "O": case "R": $condition = "qid='{$conrow['cqid']}' AND code='{$conrow['value']}' AND language='{$sLanguageCode}'"; $ansresult = Answer::model()->findAll($condition); foreach ($ansresult as $ansrow) { $conditions[] = $ansrow['answer']; } if ($conrow['value'] == "-oth-") { $conditions[] = gT("Other"); } $conditions = array_unique($conditions); break; case "M": case "P": $condition = " parent_qid='{$conrow['cqid']}' AND title='{$conrow['value']}' AND language='{$sLanguageCode}'"; $ansresult = Question::model()->findAll($condition); foreach ($ansresult as $ansrow) { $conditions[] = $ansrow['question']; } $conditions = array_unique($conditions); break; case "N": case "K": $conditions[] = $value; break; case "F": case "H": default: $value = substr($conrow['cfieldname'], strpos($conrow['cfieldname'], "X" . $conrow['cqid']) + strlen("X" . $conrow['cqid']), strlen($conrow['cfieldname'])); $condition = " qid='{$conrow['cqid']}' AND code='{$conrow['value']}' AND language='{$sLanguageCode}'"; $fresult = Answer::model()->getAllRecords($condition); foreach ($fresult->readAll() as $frow) { $postans = $frow['answer']; $conditions[] = $frow['answer']; } // while break; } // switch // Now let's complete the answer text with the answer_section $answer_section = ""; switch ($conrow['type']) { case "A": case "B": case "C": case "E": case "F": case "H": case "K": $thiscquestion = $fieldmap[$conrow['cfieldname']]; $condition = "parent_qid='{$conrow['cqid']}' AND title='{$thiscquestion['aid']}' AND language='{$sLanguageCode}'"; $ansresult = Question::model()->findAll($condition); foreach ($ansresult as $ansrow) { $answer_section = " (" . $ansrow['question'] . ")"; } break; case "1": // dual: (Label 1), (Label 2) $labelIndex = substr($conrow['cfieldname'], -1); $thiscquestion = $fieldmap[$conrow['cfieldname']]; $condition = "parent_qid='{$conrow['cqid']}' AND title='{$thiscquestion['aid']}' AND language='{$sLanguageCode}'"; $ansresult = Question::model()->findAll($condition); $cqidattributes = getQuestionAttributeValues($conrow['cqid']); if ($labelIndex == 0) { if (trim($cqidattributes['dualscale_headerA'][$sLanguageCode]) != '') { $header = gT($cqidattributes['dualscale_headerA'][$sLanguageCode]); } else { $header = '1'; } } elseif ($labelIndex == 1) { if (trim($cqidattributes['dualscale_headerB'][$sLanguageCode]) != '') { $header = gT($cqidattributes['dualscale_headerB'][$sLanguageCode]); } else { $header = '2'; } } foreach ($ansresult as $ansrow) { $answer_section = " (" . $ansrow->question . " " . sprintf(gT("Label %s"), $header) . ")"; } break; case ":": case ";": //multi flexi: ( answer [label] ) $thiscquestion = $fieldmap[$conrow['cfieldname']]; $condition = "parent_qid='{$conrow['cqid']}' AND title='{$thiscquestion['aid']}' AND language='{$sLanguageCode}'"; $ansresult = Question::model()->findAll($condition); foreach ($ansresult as $ansrow) { $condition = "qid = '{$conrow['cqid']}' AND code = '{$conrow['value']}' AND language= '{$sLanguageCode}'"; $fresult = Answer::model()->findAll($condition); foreach ($fresult as $frow) { //$conditions[]=$frow['title']; $answer_section = " (" . $ansrow->question . "[" . $frow['answer'] . "])"; } // while } break; case "R": // (Rank 1), (Rank 2)... TIBO $thiscquestion = $fieldmap[$conrow['cfieldname']]; $rankid = $thiscquestion['aid']; $answer_section = " (" . gT("RANK") . " {$rankid})"; break; default: // nothing to add break; } } if (count($conditions) > 1) { $sExplanation .= "'" . implode("' <em class='scenario-or-separator'>" . gT("or") . "</em> '", $conditions) . "'"; } elseif (count($conditions) == 1) { $sExplanation .= "'" . $conditions[0] . "'"; } unset($conditions); // Following line commented out because answer_section was lost, but is required for some question types //$explanation .= " ".gT("to question")." '".$mapquestionsNumbers[$distinctrow['cqid']]."' $answer_section "; if ($distinctrow['cqid']) { $sExplanation .= " <span class='scenario-at-separator'>" . gT("at question") . "</span> '" . $mapquestionsNumbers[$distinctrow['cqid']] . " [" . $subresult['title'] . "]' (" . strip_tags($subresult['question']) . "{$answer_section})"; } else { $sExplanation .= " " . $distinctrow['value']; } //$distinctrow $x++; } $s++; } $qinfo = LimeExpressionManager::GetQuestionStatus($deqrow['qid']); $relevance = trim($qinfo['info']['relevance']); $sEquation = $qinfo['relEqn']; if (trim($relevance) != '' && trim($relevance) != '1') { if (isset($qidattributes['printable_help'][$sLanguageCode]) && $qidattributes['printable_help'][$sLanguageCode] != '') { $sExplanation = $qidattributes['printable_help'][$sLanguageCode]; } elseif ($sExplanation == '') { $sExplanation = $sEquation; $sEquation = ' '; // No need to show it twice } $sExplanation = "<b>" . gT('Only answer this question if the following conditions are met:') . "</b><br/> " . $sExplanation; if (Yii::app()->getConfig('showrelevance')) { $sExplanation .= "<span class='printable_equation'><br>" . $sEquation . "</span>"; } } else { $sExplanation = ''; } ++$total_questions; //TIBO map question qid to their q number $mapquestionsNumbers[$deqrow['qid']] = $total_questions; //END OF GETTING CONDITIONS $qid = $deqrow['qid']; $fieldname = "{$surveyid}" . "X" . "{$gid}" . "X" . "{$qid}"; if (isset($showsgqacode) && $showsgqacode == true) { $deqrow['question'] = $deqrow['question'] . "<br />" . gT("ID:") . " {$fieldname} <br />" . gT("Question code:") . " " . $deqrow['title']; } $question = array('QUESTION_NUMBER' => $total_questions, 'QUESTION_CODE' => $deqrow['title'], 'QUESTION_TEXT' => preg_replace('/(?:<br ?\\/?>|<\\/(?:p|h[1-6])>)$/is', '', $deqrow['question']), 'QUESTION_SCENARIO' => $sExplanation, 'QUESTION_MANDATORY' => '', 'QUESTION_ID' => $deqrow['qid'], 'QUESTION_CLASS' => getQuestionClass($deqrow['type']), 'QUESTION_TYPE_HELP' => $qinfo['validTip'], 'QUESTION_MAN_MESSAGE' => '', 'QUESTION_VALID_MESSAGE' => '', 'QUESTION_FILE_VALID_MESSAGE' => '', 'QUESTIONHELP' => '', 'ANSWER' => ''); $showqnumcode = Yii::app()->getConfig('showqnumcode'); if ($showqnumcode == 'choose' && ($aSurveyInfo['showqnumcode'] == 'N' || $aSurveyInfo['showqnumcode'] == 'X') || $showqnumcode == 'number' || $showqnumcode == 'none') { $question['QUESTION_CODE'] = ''; } if ($showqnumcode == 'choose' && ($aSurveyInfo['showqnumcode'] == 'C' || $aSurveyInfo['showqnumcode'] == 'X') || $showqnumcode == 'code' || $showqnumcode == 'none') { $question['QUESTION_NUMBER'] = ''; } if ($question['QUESTION_TYPE_HELP'] != "") { $question['QUESTION_TYPE_HELP'] .= "<br />\n"; } if ($deqrow['mandatory'] == 'Y') { $question['QUESTION_MANDATORY'] = gT('*'); $question['QUESTION_CLASS'] .= ' mandatory'; } //DIFFERENT TYPES OF DATA FIELD HERE if ($deqrow['help']) { $question['QUESTIONHELP'] = $deqrow['help']; } if (!empty($qidattributes['page_break'])) { $question['QUESTION_CLASS'] .= ' breakbefore '; } if (isset($qidattributes['maximum_chars']) && $qidattributes['maximum_chars'] != '') { $question['QUESTION_CLASS'] = "max-chars-{$qidattributes['maximum_chars']} " . $question['QUESTION_CLASS']; } switch ($deqrow['type']) { // ================================================================== case "5": //5 POINT CHOICE $question['QUESTION_TYPE_HELP'] .= gT('Please choose *only one* of the following:'); $question['ANSWER'] .= "\n\t<ul>\n"; for ($i = 1; $i <= 5; $i++) { $question['ANSWER'] .= "\t\t<li>\n\t\t\t" . self::_input_type_image('radio', $i) . "\n\t\t\t{$i} " . self::_addsgqacode("({$i})") . "\n\t\t</li>\n"; } $question['ANSWER'] .= "\t</ul>\n"; break; // ================================================================== // ================================================================== case "D": //DATE $question['QUESTION_TYPE_HELP'] .= gT('Please enter a date:'); $question['ANSWER'] .= "\t" . self::_input_type_image('text', $question['QUESTION_TYPE_HELP'], 30, 1); break; // ================================================================== // ================================================================== case "G": //GENDER $question['QUESTION_TYPE_HELP'] .= gT("Please choose *only one* of the following:"); $question['ANSWER'] .= "\n\t<ul>\n"; $question['ANSWER'] .= "\t\t<li>\n\t\t\t" . self::_input_type_image('radio', gT("Female")) . "\n\t\t\t" . gT("Female") . " " . self::_addsgqacode("(F)") . "\n\t\t</li>\n"; $question['ANSWER'] .= "\t\t<li>\n\t\t\t" . self::_input_type_image('radio', gT("Male")) . "\n\t\t\t" . gT("Male") . " " . self::_addsgqacode("(M)") . "\n\t\t</li>\n"; $question['ANSWER'] .= "\t</ul>\n"; break; // ================================================================== // ================================================================== case "L": //LIST drop-down/radio-button list // ================================================================== //LIST drop-down/radio-button list // ================================================================== case "!": //List - dropdown if (isset($qidattributes['display_columns']) && trim($qidattributes['display_columns']) != '') { $dcols = $qidattributes['display_columns']; } else { $dcols = 0; } if (isset($qidattributes['category_separator']) && trim($qidattributes['category_separator']) != '') { $optCategorySeparator = $qidattributes['category_separator']; } else { unset($optCategorySeparator); } $question['QUESTION_TYPE_HELP'] .= gT("Please choose *only one* of the following:"); $question['QUESTION_TYPE_HELP'] .= self::_array_filter_help($qidattributes, $sLanguageCode, $surveyid); $dearesult = Answer::model()->getAllRecords(" qid='{$deqrow['qid']}' AND language='{$sLanguageCode}' ", array('sortorder', 'answer')); $dearesult = $dearesult->readAll(); $deacount = count($dearesult); if ($deqrow['other'] == "Y") { $deacount++; } $wrapper = setupColumns(0, $deacount); $question['ANSWER'] = $wrapper['whole-start']; $rowcounter = 0; $colcounter = 1; foreach ($dearesult as $dearow) { if (isset($optCategorySeparator)) { list($category, $answer) = explode($optCategorySeparator, $dearow['answer']); if ($category != '') { $dearow['answer'] = "({$category}) {$answer} " . self::_addsgqacode("(" . $dearow['code'] . ")"); } else { $dearow['answer'] = $answer . self::_addsgqacode(" (" . $dearow['code'] . ")"); } $question['ANSWER'] .= "\t" . $wrapper['item-start'] . "\t\t" . self::_input_type_image('radio', $dearow['answer']) . "\n\t\t\t" . $dearow['answer'] . "\n" . $wrapper['item-end']; } else { $question['ANSWER'] .= "\t" . $wrapper['item-start'] . "\t\t" . self::_input_type_image('radio', $dearow['answer']) . "\n\t\t\t" . $dearow['answer'] . self::_addsgqacode(" (" . $dearow['code'] . ")") . "\n" . $wrapper['item-end']; } ++$rowcounter; if ($rowcounter == $wrapper['maxrows'] && $colcounter < $wrapper['cols']) { if ($colcounter == $wrapper['cols'] - 1) { $question['ANSWER'] .= $wrapper['col-devide-last']; } else { $question['ANSWER'] .= $wrapper['col-devide']; } $rowcounter = 0; ++$colcounter; } } if ($deqrow['other'] == 'Y') { if (trim($qidattributes["other_replace_text"][$sLanguageCode]) == '') { $qidattributes["other_replace_text"][$sLanguageCode] = gT("Other"); } // $printablesurveyoutput .="\t".$wrapper['item-start']."\t\t".self::_input_type_image('radio' , gT("Other"))."\n\t\t\t".gT("Other")."\n\t\t\t<input type='text' size='30' readonly='readonly' />\n".$wrapper['item-end']; $question['ANSWER'] .= $wrapper['item-start-other'] . self::_input_type_image('radio', gT($qidattributes["other_replace_text"][$sLanguageCode])) . ' ' . gT($qidattributes["other_replace_text"][$sLanguageCode]) . self::_addsgqacode(" (-oth-)") . "\n\t\t\t" . self::_input_type_image('other') . self::_addsgqacode(" (" . $deqrow['sid'] . "X" . $deqrow['gid'] . "X" . $deqrow['qid'] . "other)") . "\n" . $wrapper['item-end']; } $question['ANSWER'] .= $wrapper['whole-end']; //Let's break the presentation into columns. break; // ================================================================== // ================================================================== case "O": //LIST WITH COMMENT $question['QUESTION_TYPE_HELP'] .= gT("Please choose *only one* of the following:"); $dearesult = Answer::model()->getAllRecords(" qid='{$deqrow['qid']}' AND language='{$sLanguageCode}'", array('sortorder', 'answer')); $question['ANSWER'] = "\t<ul>\n"; foreach ($dearesult->readAll() as $dearow) { $question['ANSWER'] .= "\t\t<li>\n\t\t\t" . self::_input_type_image('radio', $dearow['answer']) . "\n\t\t\t" . $dearow['answer'] . self::_addsgqacode(" (" . $dearow['code'] . ")") . "\n\t\t</li>\n"; } $question['ANSWER'] .= "\t</ul>\n"; $question['ANSWER'] .= "\t<p class=\"comment\">\n\t\t" . gT("Make a comment on your choice here:") . "\n"; $question['ANSWER'] .= "\t\t" . self::_input_type_image('textarea', gT("Make a comment on your choice here:"), 50, 8) . self::_addsgqacode(" (" . $deqrow['sid'] . "X" . $deqrow['gid'] . "X" . $deqrow['qid'] . "comment)") . "\n\t</p>\n"; break; // ================================================================== // ================================================================== case "R": //RANKING Type Question $rearesult = Answer::model()->getAllRecords(" qid='{$deqrow['qid']}' AND language='{$sLanguageCode}'", array('sortorder', 'answer')); $rearesult = $rearesult->readAll(); $reacount = count($rearesult); $question['QUESTION_TYPE_HELP'] .= gT("Please number each box in order of preference from 1 to") . " {$reacount}"; $question['QUESTION_TYPE_HELP'] .= self::_min_max_answers_help($qidattributes, $sLanguageCode, $surveyid); $question['ANSWER'] = "\n<ul>\n"; foreach ($rearesult as $rearow) { $question['ANSWER'] .= "\t<li>\n\t" . self::_input_type_image('rank', '', 4, 1) . "\n\t\t " . $rearow['answer'] . self::_addsgqacode(" (" . $fieldname . $rearow['code'] . ")") . "\n\t</li>\n"; } $question['ANSWER'] .= "\n</ul>\n"; break; // ================================================================== // ================================================================== case "M": //Multiple choice (Quite tricky really!) if (trim($qidattributes['display_columns']) != '') { $dcols = $qidattributes['display_columns']; } else { $dcols = 0; } $question['QUESTION_TYPE_HELP'] .= gT("Please choose *all* that apply:"); $question['QUESTION_TYPE_HELP'] .= self::_array_filter_help($qidattributes, $sLanguageCode, $surveyid); $mearesult = Question::model()->getAllRecords(" parent_qid='{$deqrow['qid']}' AND language='{$sLanguageCode}' ", array('question_order')); $mearesult = $mearesult->readAll(); $meacount = count($mearesult); if ($deqrow['other'] == 'Y') { $meacount++; } $wrapper = setupColumns($dcols, $meacount); $question['ANSWER'] = $wrapper['whole-start']; $rowcounter = 0; $colcounter = 1; foreach ($mearesult as $mearow) { $question['ANSWER'] .= $wrapper['item-start'] . self::_input_type_image('checkbox', $mearow['question']) . "\n\t\t" . $mearow['question'] . self::_addsgqacode(" (" . $fieldname . $mearow['title'] . ") ") . $wrapper['item-end']; ++$rowcounter; if ($rowcounter == $wrapper['maxrows'] && $colcounter < $wrapper['cols']) { if ($colcounter == $wrapper['cols'] - 1) { $question['ANSWER'] .= $wrapper['col-devide-last']; } else { $question['ANSWER'] .= $wrapper['col-devide']; } $rowcounter = 0; ++$colcounter; } } if ($deqrow['other'] == "Y") { if (trim($qidattributes['other_replace_text'][$sLanguageCode]) == '') { $qidattributes["other_replace_text"][$sLanguageCode] = "Other"; } if (!isset($mearow['answer'])) { $mearow['answer'] = ""; } $question['ANSWER'] .= $wrapper['item-start-other'] . self::_input_type_image('checkbox', $mearow['answer']) . gT($qidattributes["other_replace_text"][$sLanguageCode]) . ":\n\t\t" . self::_input_type_image('other') . self::_addsgqacode(" (" . $fieldname . "other) ") . $wrapper['item-end']; } $question['ANSWER'] .= $wrapper['whole-end']; // } break; // ================================================================== // ================================================================== case "P": //Multiple choice with comments $question['QUESTION_TYPE_HELP'] .= gT("Please choose all that apply and provide a comment:"); $question['QUESTION_TYPE_HELP'] .= self::_array_filter_help($qidattributes, $sLanguageCode, $surveyid); $mearesult = Question::model()->getAllRecords("parent_qid='{$deqrow['qid']}' AND language='{$sLanguageCode}'", array('question_order')); // $printablesurveyoutput .="\t\t\t<u>".gT("Please choose all that apply and provide a comment:")."</u><br />\n"; $j = 0; $longest_string = 0; foreach ($mearesult->readAll() as $mearow) { $longest_string = longestString($mearow['question'], $longest_string); $question['ANSWER'] .= "\t<li><span>\n\t\t" . self::_input_type_image('checkbox', $mearow['question']) . $mearow['question'] . self::_addsgqacode(" (" . $fieldname . $mearow['title'] . ") ") . "</span>\n\t\t" . self::_input_type_image('text', 'comment box', 60) . self::_addsgqacode(" (" . $fieldname . $mearow['title'] . "comment) ") . "\n\t</li>\n"; $j++; } if ($deqrow['other'] == "Y") { $question['ANSWER'] .= "\t<li class=\"other\">\n\t\t<div class=\"other-replacetext\">" . gT('Other:') . self::_input_type_image('other', '', 1) . "</div>" . self::_input_type_image('othercomment', 'comment box', 50) . self::_addsgqacode(" (" . $fieldname . "other) ") . "\n\t</li>\n"; $j++; } $question['ANSWER'] = "\n<ul>\n" . $question['ANSWER'] . "</ul>\n"; break; // ================================================================== // ================================================================== case "Q": //MULTIPLE SHORT TEXT $width = 60; // ================================================================== // ================================================================== case "K": //MULTIPLE NUMERICAL $question['QUESTION_TYPE_HELP'] = ""; $width = isset($width) ? $width : 16; // if (!empty($qidattributes['equals_num_value'])) // { // $question['QUESTION_TYPE_HELP'] .= "* ".sprintf(gT('Total of all entries must equal %d'),$qidattributes['equals_num_value'])."<br />\n"; // } // if (!empty($qidattributes['max_num_value'])) // { // $question['QUESTION_TYPE_HELP'] .= sprintf(gT('Total of all entries must not exceed %d'), $qidattributes['max_num_value'])."<br />\n"; // } // if (!empty($qidattributes['min_num_value'])) // { // $question['QUESTION_TYPE_HELP'] .= sprintf(gT('Total of all entries must be at least %s'),$qidattributes['min_num_value'])."<br />\n"; // } $question['QUESTION_TYPE_HELP'] .= gT("Please write your answer(s) here:"); $longest_string = 0; $mearesult = Question::model()->getAllRecords("parent_qid='{$deqrow['qid']}' AND language='{$sLanguageCode}'", array('question_order')); foreach ($mearesult->readAll() as $mearow) { $longest_string = longestString($mearow['question'], $longest_string); if (isset($qidattributes['slider_layout']) && $qidattributes['slider_layout'] == 1) { $mearow['question'] = explode(':', $mearow['question']); $mearow['question'] = $mearow['question'][0]; } $question['ANSWER'] .= "\t<li>\n\t\t<span>" . $mearow['question'] . "</span>\n\t\t" . self::_input_type_image('text', $mearow['question'], $width) . self::_addsgqacode(" (" . $fieldname . $mearow['title'] . ") ") . "\n\t</li>\n"; } $question['ANSWER'] = "\n<ul>\n" . $question['ANSWER'] . "</ul>\n"; break; // ================================================================== // ================================================================== case "S": //SHORT TEXT $question['QUESTION_TYPE_HELP'] .= gT("Please write your answer here:"); $question['ANSWER'] = self::_input_type_image('text', $question['QUESTION_TYPE_HELP'], 50); break; // ================================================================== // ================================================================== case "T": //LONG TEXT $question['QUESTION_TYPE_HELP'] .= gT("Please write your answer here:"); $question['ANSWER'] = self::_input_type_image('textarea', $question['QUESTION_TYPE_HELP'], '100%', 8); break; // ================================================================== // ================================================================== case "U": //HUGE TEXT $question['QUESTION_TYPE_HELP'] .= gT("Please write your answer here:"); $question['ANSWER'] = self::_input_type_image('textarea', $question['QUESTION_TYPE_HELP'], '100%', 30); break; // ================================================================== // ================================================================== case "N": //NUMERICAL $prefix = ""; $suffix = ""; if ($qidattributes['prefix'][$sLanguageCode] != "") { $prefix = $qidattributes['prefix'][$sLanguageCode]; } if ($qidattributes['suffix'][$sLanguageCode] != "") { $suffix = $qidattributes['suffix'][$sLanguageCode]; } $question['QUESTION_TYPE_HELP'] .= gT("Please write your answer here:"); $question['ANSWER'] = "<ul>\n\t<li>\n\t\t<span>{$prefix}</span>\n\t\t" . self::_input_type_image('text', $question['QUESTION_TYPE_HELP'], 20) . "\n\t\t<span>{$suffix}</span>\n\t\t</li>\n\t</ul>"; break; // ================================================================== // ================================================================== case "Y": //YES/NO $question['QUESTION_TYPE_HELP'] .= gT("Please choose *only one* of the following:"); $question['ANSWER'] = "\n<ul>\n\t<li>\n\t\t" . self::_input_type_image('radio', gT('Yes')) . "\n\t\t" . gT('Yes') . self::_addsgqacode(" (Y)") . "\n\t</li>\n"; $question['ANSWER'] .= "\n\t<li>\n\t\t" . self::_input_type_image('radio', gT('No')) . "\n\t\t" . gT('No') . self::_addsgqacode(" (N)") . "\n\t</li>\n</ul>\n"; break; // ================================================================== // ================================================================== case "A": //ARRAY (5 POINT CHOICE) $condition = "parent_qid = '{$deqrow['qid']}' AND language= '{$sLanguageCode}'"; $question['QUESTION_TYPE_HELP'] .= gT("Please choose the appropriate response for each item:"); $question['QUESTION_TYPE_HELP'] .= self::_array_filter_help($qidattributes, $sLanguageCode, $surveyid); $question['ANSWER'] = "\n <table>\n <thead>\n <tr>\n <td> </td>\n <th style='font-family:Arial,helvetica,sans-serif;font-weight:normal;'>1 " . self::_addsgqacode(" (1)") . "</th>\n <th style='font-family:Arial,helvetica,sans-serif;font-weight:normal;'>2 " . self::_addsgqacode(" (2)") . "</th>\n <th style='font-family:Arial,helvetica,sans-serif;font-weight:normal;'>3 " . self::_addsgqacode(" (3)") . "</th>\n <th style='font-family:Arial,helvetica,sans-serif;font-weight:normal;'>4 " . self::_addsgqacode(" (4)") . "</th>\n <th style='font-family:Arial,helvetica,sans-serif;font-weight:normal;'>5" . self::_addsgqacode(" (5)") . "</th>\n </tr>\n </thead>\n <tbody>"; $j = 0; $rowclass = 'array1'; $mearesult = Question::model()->getAllRecords($condition, array('question_order')); foreach ($mearesult->readAll() as $mearow) { $question['ANSWER'] .= "\t\t<tr class=\"{$rowclass}\">\n"; $rowclass = alternation($rowclass, 'row'); //semantic differential question type? if (strpos($mearow['question'], '|')) { $answertext = substr($mearow['question'], 0, strpos($mearow['question'], '|')) . self::_addsgqacode(" (" . $fieldname . $mearow['title'] . ")") . " "; } else { $answertext = $mearow['question'] . self::_addsgqacode(" (" . $fieldname . $mearow['title'] . ")"); } $question['ANSWER'] .= "\t\t\t<th class=\"answertext\">{$answertext}</th>\n"; for ($i = 1; $i <= 5; $i++) { $question['ANSWER'] .= "\t\t\t<td>" . self::_input_type_image('radio', $i) . "</td>\n"; } $answertext .= $mearow['question']; //semantic differential question type? if (strpos($mearow['question'], '|')) { $answertext2 = substr($mearow['question'], strpos($mearow['question'], '|') + 1); $question['ANSWER'] .= "\t\t\t<th class=\"answertextright\">{$answertext2}</td>\n"; } $question['ANSWER'] .= "\t\t</tr>\n"; $j++; } $question['ANSWER'] .= "\t</tbody>\n</table>\n"; break; // ================================================================== // ================================================================== case "B": //ARRAY (10 POINT CHOICE) $question['QUESTION_TYPE_HELP'] .= gT("Please choose the appropriate response for each item:"); $question['QUESTION_TYPE_HELP'] .= self::_array_filter_help($qidattributes, $sLanguageCode, $surveyid); $question['ANSWER'] .= "\n<table>\n\t<thead>\n\t\t<tr>\n\t\t\t<td> </td>\n"; for ($i = 1; $i <= 10; $i++) { $question['ANSWER'] .= "\t\t\t<th>{$i}" . self::_addsgqacode(" ({$i})") . "</th>\n"; } $question['ANSWER'] .= "\t</thead>\n\n\t<tbody>\n"; $j = 0; $rowclass = 'array1'; $mearesult = Question::model()->getAllRecords(" parent_qid='{$deqrow['qid']}' AND language='{$sLanguageCode}' ", array('question_order')); foreach ($mearesult->readAll() as $mearow) { $question['ANSWER'] .= "\t\t<tr class=\"{$rowclass}\">\n\t\t\t<th class=\"answertext\">{$mearow['question']}" . self::_addsgqacode(" (" . $fieldname . $mearow['title'] . ")") . "</th>\n"; $rowclass = alternation($rowclass, 'row'); for ($i = 1; $i <= 10; $i++) { $question['ANSWER'] .= "\t\t\t<td>" . self::_input_type_image('radio', $i) . "</td>\n"; } $question['ANSWER'] .= "\t\t</tr>\n"; $j++; } $question['ANSWER'] .= "\t</tbody>\n</table>\n"; break; // ================================================================== // ================================================================== case "C": //ARRAY (YES/UNCERTAIN/NO) $question['QUESTION_TYPE_HELP'] .= gT("Please choose the appropriate response for each item:"); $question['QUESTION_TYPE_HELP'] .= self::_array_filter_help($qidattributes, $sLanguageCode, $surveyid); $question['ANSWER'] = ' <table> <thead> <tr> <td> </td> <th>' . gT("Yes") . self::_addsgqacode(" (Y)") . '</th> <th>' . gT("Uncertain") . self::_addsgqacode(" (U)") . '</th> <th>' . gT("No") . self::_addsgqacode(" (N)") . '</th> </tr> </thead> <tbody> '; $j = 0; $rowclass = 'array1'; $mearesult = Question::model()->getAllRecords(" parent_qid='{$deqrow['qid']}' AND language='{$sLanguageCode}' ", array('question_order')); foreach ($mearesult->readAll() as $mearow) { $question['ANSWER'] .= "\t\t<tr class=\"{$rowclass}\">\n"; $question['ANSWER'] .= "\t\t\t<th class=\"answertext\">{$mearow['question']}" . self::_addsgqacode(" (" . $fieldname . $mearow['title'] . ")") . "</th>\n"; $question['ANSWER'] .= "\t\t\t<td>" . self::_input_type_image('radio', gT("Yes")) . "</td>\n"; $question['ANSWER'] .= "\t\t\t<td>" . self::_input_type_image('radio', gT("Uncertain")) . "</td>\n"; $question['ANSWER'] .= "\t\t\t<td>" . self::_input_type_image('radio', gT("No")) . "</td>\n"; $question['ANSWER'] .= "\t\t</tr>\n"; $j++; $rowclass = alternation($rowclass, 'row'); } $question['ANSWER'] .= "\t</tbody>\n</table>\n"; break; case "E": //ARRAY (Increase/Same/Decrease) $question['QUESTION_TYPE_HELP'] .= gT("Please choose the appropriate response for each item:"); $question['QUESTION_TYPE_HELP'] .= self::_array_filter_help($qidattributes, $sLanguageCode, $surveyid); $question['ANSWER'] = ' <table> <thead> <tr> <td> </td> <th>' . gT("Increase") . self::_addsgqacode(" (I)") . '</th> <th>' . gT("Same") . self::_addsgqacode(" (S)") . '</th> <th>' . gT("Decrease") . self::_addsgqacode(" (D)") . '</th> </tr> </thead> <tbody> '; $j = 0; $rowclass = 'array1'; $mearesult = Question::model()->getAllRecords(" parent_qid='{$deqrow['qid']}' AND language='{$sLanguageCode}' ", array('question_order')); foreach ($mearesult->readAll() as $mearow) { $question['ANSWER'] .= "\t\t<tr class=\"{$rowclass}\">\n"; $question['ANSWER'] .= "\t\t\t<th class=\"answertext\">{$mearow['question']}" . self::_addsgqacode(" (" . $fieldname . $mearow['title'] . ")") . "</th>\n"; $question['ANSWER'] .= "\t\t\t<td>" . self::_input_type_image('radio', gT("Increase")) . "</td>\n"; $question['ANSWER'] .= "\t\t\t<td>" . self::_input_type_image('radio', gT("Same")) . "</td>\n"; $question['ANSWER'] .= "\t\t\t<td>" . self::_input_type_image('radio', gT("Decrease")) . "</td>\n"; $question['ANSWER'] .= "\t\t</tr>\n"; $j++; $rowclass = alternation($rowclass, 'row'); } $question['ANSWER'] .= "\t</tbody>\n</table>\n"; break; // ================================================================== // ================================================================== case ":": //ARRAY (Multi Flexible) (Numbers) $headstyle = "style='padding-left: 20px; padding-right: 7px'"; if (trim($qidattributes['multiflexible_max']) != '' && trim($qidattributes['multiflexible_min']) == '') { $maxvalue = $qidattributes['multiflexible_max']; $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']) == '') { $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']) != '') { $stepvalue = $qidattributes['multiflexible_step']; } else { $stepvalue = 1; } if ($qidattributes['multiflexible_checkbox'] != 0) { $checkboxlayout = true; } else { $checkboxlayout = false; } $question['QUESTION_TYPE_HELP'] .= self::_array_filter_help($qidattributes, $sLanguageCode, $surveyid); $question['ANSWER'] .= "\n<table>\n\t<thead>\n\t\t<tr>\n\t\t\t<td> </td>\n"; $fresult = Question::model()->getAllRecords(" parent_qid='{$deqrow['qid']}' and scale_id=1 AND language='{$sLanguageCode}' ", array('question_order')); $fresult = $fresult->readAll(); $fcount = count($fresult); $fwidth = "120"; $i = 0; //array to temporary store X axis question codes $xaxisarray = array(); foreach ($fresult as $frow) { $question['ANSWER'] .= "\t\t\t<th>{$frow['question']}</th>\n"; $i++; //add current question code $xaxisarray[$i] = $frow['title']; } $question['ANSWER'] .= "\t\t</tr>\n\t</thead>\n\n\t<tbody>\n"; $a = 1; //Counter for pdfoutput $rowclass = 'array1'; $mearesult = Question::model()->getAllRecords(" parent_qid='{$deqrow['qid']}' and scale_id=0 AND language='{$sLanguageCode}' ", array('question_order')); $result = $mearesult->readAll(); foreach ($result as $frow) { $question['ANSWER'] .= "\t<tr class=\"{$rowclass}\">\n"; $rowclass = alternation($rowclass, 'row'); $answertext = $frow['question']; if (strpos($answertext, '|')) { $answertext = substr($answertext, 0, strpos($answertext, '|')); } $question['ANSWER'] .= "\t\t\t\t\t<th class=\"answertext\">{$answertext}</th>\n"; //$printablesurveyoutput .="\t\t\t\t\t<td>"; for ($i = 1; $i <= $fcount; $i++) { $question['ANSWER'] .= "\t\t\t<td>\n"; if ($checkboxlayout === false) { $question['ANSWER'] .= "\t\t\t\t" . self::_input_type_image('text', '', 4) . self::_addsgqacode(" (" . $fieldname . $frow['title'] . "_" . $xaxisarray[$i] . ") ") . "\n"; } else { $question['ANSWER'] .= "\t\t\t\t" . self::_input_type_image('checkbox') . self::_addsgqacode(" (" . $fieldname . $frow['title'] . "_" . $xaxisarray[$i] . ") ") . "\n"; } $question['ANSWER'] .= "\t\t\t</td>\n"; } $answertext = $frow['question']; if (strpos($answertext, '|')) { $answertext = substr($answertext, strpos($answertext, '|') + 1); $question['ANSWER'] .= "\t\t\t<th class=\"answertextright\">{$answertext}</th>\n"; } $question['ANSWER'] .= "\t\t</tr>\n"; $a++; } $question['ANSWER'] .= "\t</tbody>\n</table>\n"; break; // ================================================================== // ================================================================== case ";": //ARRAY (Multi Flexible) (text) $headstyle = "style='padding-left: 20px; padding-right: 7px'"; $mearesult = Question::model()->getAllRecords(" parent_qid='{$deqrow['qid']}' AND scale_id=0 AND language='{$sLanguageCode}' ", array('question_order')); $mearesult = $mearesult->readAll(); $question['QUESTION_TYPE_HELP'] .= self::_array_filter_help($qidattributes, $sLanguageCode, $surveyid); $question['ANSWER'] .= "\n<table>\n\t<thead>\n\t\t<tr>\n\t\t\t<td> </td>\n"; $fresult = Question::model()->getAllRecords(" parent_qid='{$deqrow['qid']}' AND scale_id=1 AND language='{$sLanguageCode}' ", array('question_order')); $fresult = $fresult->readAll(); $fcount = count($fresult); $fwidth = "120"; $i = 0; //array to temporary store X axis question codes $xaxisarray = array(); foreach ($fresult as $frow) { $question['ANSWER'] .= "\t\t\t<th>{$frow['question']}</th>\n"; $i++; //add current question code $xaxisarray[$i] = $frow['title']; } $question['ANSWER'] .= "\t\t</tr>\n\t</thead>\n\n<tbody>\n"; $a = 1; $rowclass = 'array1'; foreach ($mearesult as $mearow) { $question['ANSWER'] .= "\t\t<tr class=\"{$rowclass}\">\n"; $rowclass = alternation($rowclass, 'row'); $answertext = $mearow['question']; if (strpos($answertext, '|')) { $answertext = substr($answertext, 0, strpos($answertext, '|')); } $question['ANSWER'] .= "\t\t\t<th class=\"answertext\">{$answertext}</th>\n"; for ($i = 1; $i <= $fcount; $i++) { $question['ANSWER'] .= "\t\t\t<td>\n"; $question['ANSWER'] .= "\t\t\t\t" . self::_input_type_image('text', '', 23) . self::_addsgqacode(" (" . $fieldname . $mearow['title'] . "_" . $xaxisarray[$i] . ") ") . "\n"; $question['ANSWER'] .= "\t\t\t</td>\n"; } $answertext = $mearow['question']; if (strpos($answertext, '|')) { $answertext = substr($answertext, strpos($answertext, '|') + 1); $question['ANSWER'] .= "\t\t\t\t<th class=\"answertextright\">{$answertext}</th>\n"; } $question['ANSWER'] .= "\t\t</tr>\n"; $a++; } $question['ANSWER'] .= "\t</tbody>\n</table>\n"; break; // ================================================================== // ================================================================== case "F": //ARRAY (Flexible Labels) $question['QUESTION_TYPE_HELP'] .= gT("Please choose the appropriate response for each item:"); $question['QUESTION_TYPE_HELP'] .= self::_array_filter_help($qidattributes, $sLanguageCode, $surveyid); $fresult = Answer::model()->getAllRecords(" scale_id=0 AND qid='{$deqrow['qid']}' AND language='{$sLanguageCode}'", array('sortorder', 'code')); $fresult = $fresult->readAll(); $fcount = count($fresult); $fwidth = "120"; $i = 1; $column_headings = array(); foreach ($fresult as $frow) { $column_headings[] = $frow['answer'] . self::_addsgqacode(" (" . $frow['code'] . ")"); } if (trim($qidattributes['answer_width']) != '') { $iAnswerWidth = 100 - $qidattributes['answer_width']; } else { $iAnswerWidth = 80; } if (count($column_headings) > 0) { $col_width = round($iAnswerWidth / count($column_headings)); } else { $heading = ''; } $question['ANSWER'] .= "\n<table>\n\t<thead>\n\t\t<tr>\n"; $question['ANSWER'] .= "\t\t\t<td> </td>\n"; foreach ($column_headings as $heading) { $question['ANSWER'] .= "\t\t\t<th style=\"width:{$col_width}%;\">{$heading}</th>\n"; } $i++; $question['ANSWER'] .= "\t\t</tr>\n\t</thead>\n\n\t<tbody>\n"; $counter = 1; $rowclass = 'array1'; $mearesult = Question::model()->getAllRecords(" parent_qid='{$deqrow['qid']}' AND language='{$sLanguageCode}' ", array('question_order')); foreach ($mearesult->readAll() as $mearow) { $question['ANSWER'] .= "\t\t<tr class=\"{$rowclass}\">\n"; $rowclass = alternation($rowclass, 'row'); if (trim($answertext) == '') { $answertext = ' '; } //semantic differential question type? if (strpos($mearow['question'], '|')) { $answertext = substr($mearow['question'], 0, strpos($mearow['question'], '|')) . self::_addsgqacode(" (" . $fieldname . $mearow['title'] . ")") . " "; } else { $answertext = $mearow['question'] . self::_addsgqacode(" (" . $fieldname . $mearow['title'] . ")"); } if (trim($qidattributes['answer_width']) != '') { $sInsertStyle = ' style="width:' . $qidattributes['answer_width'] . '%" '; } else { $sInsertStyle = ''; } $question['ANSWER'] .= "\t\t\t<th {$sInsertStyle} class=\"answertext\">{$answertext}</th>\n"; for ($i = 1; $i <= $fcount; $i++) { $question['ANSWER'] .= "\t\t\t<td>" . self::_input_type_image('radio') . "</td>\n"; } $counter++; $answertext = $mearow['question']; //semantic differential question type? if (strpos($mearow['question'], '|')) { $answertext2 = substr($mearow['question'], strpos($mearow['question'], '|') + 1); $question['ANSWER'] .= "\t\t\t<th class=\"answertextright\">{$answertext2}</th>\n"; } $question['ANSWER'] .= "\t\t</tr>\n"; } $question['ANSWER'] .= "\t</tbody>\n</table>\n"; break; // ================================================================== // ================================================================== case "1": //ARRAY (Flexible Labels) multi scale $leftheader = $qidattributes['dualscale_headerA'][$sLanguageCode]; $rightheader = $qidattributes['dualscale_headerB'][$sLanguageCode]; $headstyle = 'style="padding-left: 20px; padding-right: 7px"'; $question['QUESTION_TYPE_HELP'] .= gT("Please choose the appropriate response for each item:"); $question['QUESTION_TYPE_HELP'] .= self::_array_filter_help($qidattributes, $sLanguageCode, $surveyid); $question['ANSWER'] .= "\n<table>\n\t<thead>\n"; $condition = "qid= '{$deqrow['qid']}' AND language= '{$sLanguageCode}' AND scale_id=0"; $fresult = Answer::model()->getAllRecords($condition, array('sortorder', 'code')); $fresult = $fresult->readAll(); $fcount = count($fresult); $fwidth = "120"; $l1 = 0; $printablesurveyoutput2 = "\t\t\t<td> </td>\n"; $myheader2 = ''; foreach ($fresult as $frow) { $printablesurveyoutput2 .= "\t\t\t<th>{$frow['answer']}" . self::_addsgqacode(" (" . $frow['code'] . ")") . "</th>\n"; $myheader2 .= "<td></td>"; $l1++; } // second scale $printablesurveyoutput2 .= "\t\t\t<td> </td>\n"; //$fquery1 = "SELECT * FROM {{answers}} WHERE qid='{$deqrow['qid']}' AND language='{$sLanguageCode}' AND scale_id=1 ORDER BY sortorder, code"; // $fresult1 = Yii::app()->db->createCommand($fquery1)->query(); $fresult1 = Answer::model()->getAllRecords(" qid='{$deqrow['qid']}' AND language='{$sLanguageCode}' AND scale_id=1 ", array('sortorder', 'code')); $fresult1 = $fresult1->readAll(); $fcount1 = count($fresult1); $fwidth = "120"; $l2 = 0; //array to temporary store second scale question codes $scale2array = array(); foreach ($fresult1 as $frow1) { $printablesurveyoutput2 .= "\t\t\t<th>{$frow1['answer']}" . self::_addsgqacode(" (" . $frow1['code'] . ")") . "</th>\n"; //add current question code $scale2array[$l2] = $frow1['code']; $l2++; } // build header if needed if ($leftheader != '' || $rightheader != '') { $myheader = "\t\t\t<td> </td>"; $myheader .= "\t\t\t<th colspan=\"" . $l1 . "\">{$leftheader}</th>\n"; if ($rightheader != '') { // $myheader .= "\t\t\t\t\t" .$myheader2; $myheader .= "\t\t\t<td> </td>"; $myheader .= "\t\t\t<th colspan=\"" . $l2 . "\">{$rightheader}</td>\n"; } $myheader .= "\t\t\t\t</tr>\n"; } else { $myheader = ''; } $question['ANSWER'] .= $myheader . "\t\t</tr>\n\n\t\t<tr>\n"; $question['ANSWER'] .= $printablesurveyoutput2; $question['ANSWER'] .= "\t\t</tr>\n\t</thead>\n\n\t<tbody>\n"; $rowclass = 'array1'; //counter for each subquestion $sqcounter = 0; $mearesult = Question::model()->getAllRecords(" parent_qid={$deqrow['qid']} AND language='{$sLanguageCode}' ", array('question_order')); foreach ($mearesult->readAll() as $mearow) { $question['ANSWER'] .= "\t\t<tr class=\"{$rowclass}\">\n"; $rowclass = alternation($rowclass, 'row'); $answertext = $mearow['question'] . self::_addsgqacode(" (" . $fieldname . $mearow['title'] . "#0) / (" . $fieldname . $mearow['title'] . "#1)"); if (strpos($answertext, '|')) { $answertext = substr($answertext, 0, strpos($answertext, '|')); } $question['ANSWER'] .= "\t\t\t<th class=\"answertext\">{$answertext}</th>\n"; for ($i = 1; $i <= $fcount; $i++) { $question['ANSWER'] .= "\t\t\t<td>" . self::_input_type_image('radio') . "</td>\n"; } $question['ANSWER'] .= "\t\t\t<td> </td>\n"; for ($i = 1; $i <= $fcount1; $i++) { $question['ANSWER'] .= "\t\t\t<td>" . self::_input_type_image('radio') . "</td>\n"; } $answertext = $mearow['question']; if (strpos($answertext, '|')) { $answertext = substr($answertext, strpos($answertext, '|') + 1); $question['ANSWER'] .= "\t\t\t<th class=\"answertextright\">{$answertext}</th>\n"; } $question['ANSWER'] .= "\t\t</tr>\n"; //increase subquestion counter $sqcounter++; } $question['ANSWER'] .= "\t</tbody>\n</table>\n"; break; // ================================================================== // ================================================================== case "H": //ARRAY (Flexible Labels) by Column //$headstyle="style='border-left-style: solid; border-left-width: 1px; border-left-color: #AAAAAA'"; $headstyle = "style='padding-left: 20px; padding-right: 7px'"; $condition = "parent_qid= '{$deqrow['qid']}' AND language= '{$sLanguageCode}'"; $fresult = Question::model()->getAllRecords($condition, array('question_order', 'title')); $fresult = $fresult->readAll(); $question['QUESTION_TYPE_HELP'] .= gT("Please choose the appropriate response for each item:"); $question['ANSWER'] .= "\n<table>\n\t<thead>\n\t\t<tr>\n\t\t\t<td> </td>\n"; $fcount = count($fresult); $fwidth = "120"; $i = 0; foreach ($fresult as $frow) { $question['ANSWER'] .= "\t\t\t<th>{$frow['question']}" . self::_addsgqacode(" (" . $fieldname . $frow['title'] . ")") . "</th>\n"; $i++; } $question['ANSWER'] .= "\t\t</tr>\n\t</thead>\n\n\t<tbody>\n"; $a = 1; $rowclass = 'array1'; $mearesult = Answer::model()->getAllRecords(" qid='{$deqrow['qid']}' AND scale_id=0 AND language='{$sLanguageCode}' ", array('sortorder', 'code')); foreach ($mearesult->readAll() as $mearow) { //$_POST['type']=$type; $question['ANSWER'] .= "\t\t<tr class=\"{$rowclass}\">\n"; $rowclass = alternation($rowclass, 'row'); $question['ANSWER'] .= "\t\t\t<th class=\"answertext\">{$mearow['answer']}" . self::_addsgqacode(" (" . $mearow['code'] . ")") . "</th>\n"; //$printablesurveyoutput .="\t\t\t\t\t<td>"; for ($i = 1; $i <= $fcount; $i++) { $question['ANSWER'] .= "\t\t\t<td>" . self::_input_type_image('radio') . "</td>\n"; } //$printablesurveyoutput .="\t\t\t\t\t</tr></table></td>\n"; $question['ANSWER'] .= "\t\t</tr>\n"; $a++; } $question['ANSWER'] .= "\t</tbody>\n</table>\n"; break; case "|": // File Upload $question['QUESTION_TYPE_HELP'] .= "Kindly attach the aforementioned documents along with the survey"; break; // === END SWITCH =================================================== } $question['QUESTION_TYPE_HELP'] = self::_star_replace($question['QUESTION_TYPE_HELP']); $group['QUESTIONS'] .= self::_populate_template('question', $question); } if ($bGroupHasVisibleQuestions) { $survey_output['GROUPS'] .= self::_populate_template('group', $group); } } $survey_output['THEREAREXQUESTIONS'] = str_replace('{NUMBEROFQUESTIONS}', $total_questions, gT('There are {NUMBEROFQUESTIONS} questions in this survey')); // START recursive tag stripping. // PHP 5.1.0 introduced the count parameter for preg_replace() and thus allows this procedure to run with only one regular expression. // Previous version of PHP needs two regular expressions to do the same thing and thus will run a bit slower. $server_is_newer = version_compare(PHP_VERSION, '5.1.0', '>'); $rounds = 0; while ($rounds < 1) { $replace_count = 0; if ($server_is_newer) { $survey_output['GROUPS'] = preg_replace(array('/<td>(?: | | )?<\\/td>/isU', '/<th[^>]*>(?: | | )?<\\/th>/isU', '/<([^ >]+)[^>]*>(?: | |\\r\\n|\\n\\r|\\n|\\r|\\t| )*<\\/\\1>/isU'), array('[[EMPTY-TABLE-CELL]]', '[[EMPTY-TABLE-CELL-HEADER]]', ''), $survey_output['GROUPS'], -1, $replace_count); } else { $survey_output['GROUPS'] = preg_replace(array('/<td>(?: | | )?<\\/td>/isU', '/<th[^>]*>(?: | | )?<\\/th>/isU', '/<([^ >]+)[^>]*>(?: | |\\r\\n|\\n\\r|\\n|\\r|\\t| )*<\\/\\1>/isU'), array('[[EMPTY-TABLE-CELL]]', '[[EMPTY-TABLE-CELL-HEADER]]', ''), $survey_output['GROUPS']); $replace_count = preg_match('/<([^ >]+)[^>]*>(?: | |\\r\\n|\\n\\r|\\n|\\r|\\t| )*<\\/\\1>/isU', $survey_output['GROUPS']); } if ($replace_count == 0) { ++$rounds; $survey_output['GROUPS'] = preg_replace(array('/\\[\\[EMPTY-TABLE-CELL\\]\\]/', '/\\[\\[EMPTY-TABLE-CELL-HEADER\\]\\]/', '/\\n(?:\\t*\\n)+/'), array('<td> </td>', '<th> </th>', "\n"), $survey_output['GROUPS']); } } $survey_output['GROUPS'] = preg_replace('/(<div[^>]*>){NOTEMPTY}(<\\/div>)/', '\\1 \\2', $survey_output['GROUPS']); // END recursive empty tag stripping. echo self::_populate_template('survey', $survey_output); } // End print }
function do_array_dual($ia) { global $thissurvey; $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 = ""; // Maybe not $caption = ""; // Just leave empty, are replaced after $inputnames = array(); $labelans1 = array(); $labelans = array(); /* * Get Question Attributes */ $aQuestionAttributes = QuestionAttribute::model()->getQuestionAttributes($ia[0]); // Get questions and answers by defined order if ($aQuestionAttributes['random_order'] == 1) { $ansquery = "SELECT * FROM {{questions}} WHERE parent_qid={$ia['0']} AND language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "' and scale_id=0 ORDER BY " . dbRandom(); } else { $ansquery = "SELECT * FROM {{questions}} WHERE parent_qid={$ia['0']} AND language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "' and scale_id=0 ORDER BY question_order"; } $ansresult = dbExecuteAssoc($ansquery); //Checked $aSubQuestions = $ansresult->readAll(); $anscount = count($aSubQuestions); $lquery = "SELECT * FROM {{answers}} WHERE scale_id=0 AND qid={$ia[0]} AND language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "' ORDER BY sortorder, code"; $lresult = dbExecuteAssoc($lquery); //Checked $aAnswersScale0 = $lresult->readAll(); $lquery1 = "SELECT * FROM {{answers}} WHERE scale_id=1 AND qid={$ia[0]} AND language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "' ORDER BY sortorder, code"; $lresult1 = dbExecuteAssoc($lquery1); //Checked $aAnswersScale1 = $lresult1->readAll(); // Set attributes if ($aQuestionAttributes['use_dropdown'] == 1) { $useDropdownLayout = true; $extraclass .= " dropdown-list"; $answertypeclass .= " dropdown"; $doDualScaleFunction = "doDualScaleDropDown"; // javascript funtion to lauch at end of answers $caption = gT("A table with a subquestion on each row, with two answers to provide on each line. Please select the answers."); } else { $useDropdownLayout = false; $extraclass .= " radio-list"; $answertypeclass .= " radio"; $doDualScaleFunction = "doDualScaleRadio"; $caption = gT("A table with one subquestion on each row and two answers to provide on each row. The related answer options are in the top table header row."); } if (ctype_digit(trim($aQuestionAttributes['repeat_headings'])) && trim($aQuestionAttributes['repeat_headings'] != "")) { $repeatheadings = intval($aQuestionAttributes['repeat_headings']); $minrepeatheadings = 0; } $leftheader = trim($aQuestionAttributes['dualscale_headerA'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '' ? $leftheader = $aQuestionAttributes['dualscale_headerA'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']] : ''; $rightheader = trim($aQuestionAttributes['dualscale_headerB'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '' ? $aQuestionAttributes['dualscale_headerB'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']] : ''; $answerwidth = trim($aQuestionAttributes['answer_width']) != '' ? $aQuestionAttributes['answer_width'] : 20; // Find if we have rigth and center text $sQuery = "SELECT count(question) FROM {{questions}} WHERE parent_qid=" . $ia[0] . " and scale_id=0 AND question like '%|%'"; $rigthCount = Yii::app()->db->createCommand($sQuery)->queryScalar(); $rightexists = $rigthCount > 0; // $right_exists: flag to find out if there are any right hand answer parts. leaving right column but don't force with $sQuery = "SELECT count(question) FROM {{questions}} WHERE parent_qid=" . $ia[0] . " and scale_id=0 AND question like '%|%|%'"; $centerCount = Yii::app()->db->createCommand($sQuery)->queryScalar(); $centerexists = $centerCount > 0; // $center_exists: flag to find out if there are any center hand answer parts. leaving center column but don't force with // Label and code for input foreach ($aAnswersScale0 as $lrow) { $labels0[] = array('code' => $lrow['code'], 'title' => $lrow['answer']); } foreach ($aAnswersScale1 as $lrow) { $labels1[] = array('code' => $lrow['code'], 'title' => $lrow['answer']); } if (count($aAnswersScale0) > 0 && $anscount) { $answer = ""; $fn = 1; // Used by repeat_heading // No drop-down if ($useDropdownLayout === false) { $aData = array(); $aData['answertypeclass'] = $answertypeclass; $columnswidth = 100 - $answerwidth; $labelans0 = array(); $labelans1 = array(); $labelcode0 = array(); $labelcode1 = array(); foreach ($aAnswersScale0 as $lrow) { $labelans0[] = $lrow['answer']; $labelcode0[] = $lrow['code']; } foreach ($aAnswersScale1 as $lrow) { $labelans1[] = $lrow['answer']; $labelcode1[] = $lrow['code']; } $numrows = count($labelans0) + count($labelans1); // Add needed row and fill some boolean: shownoanswer, rightexists, centerexists $shownoanswer = $ia[6] != "Y" && SHOW_NO_ANSWER == 1; if ($shownoanswer) { $numrows++; $caption .= gT("The last cell is for 'No answer'."); } if ($rightexists) { $numrows++; } if ($centerexists) { $numrows++; } $cellwidth = $columnswidth / $numrows; $cellwidth = sprintf("%02d", $cellwidth); // No reason to do this, except to leave place for separator ? But then table can not be the same in all browser // Header row and colgroups $aData['answerwidth'] = $answerwidth; $aData['cellwidth'] = $cellwidth; $aData['labelans0'] = $labelans0; $aData['labelcode0'] = $labelcode0; $aData['labelans1'] = $labelans1; $aData['labelcode1'] = $labelcode1; $aData['separatorwidth'] = $centerexists ? "style='width: {$cellwidth}%;' " : ""; $aData['shownoanswer'] = $shownoanswer; $aData['rightexists'] = $rightexists; $aData['rigthwidth'] = $rightexists ? "style='width: {$cellwidth}%;' " : ""; // build first row of header if needed $aData['leftheader'] = $leftheader; $aData['rightheader'] = $rightheader; $aData['rigthclass'] = $rightexists ? " header_answer_text_right" : ""; // And no each line of body $trbc = ''; $aData['aSubQuestions'] = $aSubQuestions; foreach ($aSubQuestions as $i => $ansrow) { // Build repeat headings if needed if (isset($repeatheadings) && $repeatheadings > 0 && $fn - 1 > 0 && ($fn - 1) % $repeatheadings == 0) { if ($anscount - $fn + 1 >= $minrepeatheadings) { $aData['aSubQuestions'][$i]['repeatheadings'] = true; } } else { $aData['aSubQuestions'][$i]['repeatheadings'] = false; } $trbc = alternation($trbc, 'row'); $answertext = $ansrow['question']; // rigth and center answertext: not explode for ? Why not if (strpos($answertext, '|')) { $answertextright = substr($answertext, strpos($answertext, '|') + 1); $answertext = substr($answertext, 0, strpos($answertext, '|')); } else { $answertextright = ""; } if ($centerexists) { $answertextcenter = substr($answertextright, 0, strpos($answertextright, '|')); $answertextright = substr($answertextright, strpos($answertextright, '|') + 1); } else { $answertextcenter = ""; } $myfname = $ia[1] . $ansrow['title']; $myfname0 = $ia[1] . $ansrow['title'] . '#0'; $myfid0 = $ia[1] . $ansrow['title'] . '_0'; $myfname1 = $ia[1] . $ansrow['title'] . '#1'; // new multi-scale-answer $myfid1 = $ia[1] . $ansrow['title'] . '_1'; $aData['aSubQuestions'][$i]['myfname'] = $myfname; $aData['aSubQuestions'][$i]['myfname0'] = $myfname0; $aData['aSubQuestions'][$i]['myfid0'] = $myfid0; $aData['aSubQuestions'][$i]['myfname1'] = $myfname1; $aData['aSubQuestions'][$i]['myfid1'] = $myfid1; $aData['aSubQuestions'][$i]['answertext'] = $ansrow['question']; /* Check the Sub Q mandatory violation */ if ($ia[6] == 'Y' && (in_array($myfname0, $aMandatoryViolationSubQ) || in_array($myfname1, $aMandatoryViolationSubQ))) { $aData['aSubQuestions'][$i]['showmandatoryviolation'] = true; } else { $aData['aSubQuestions'][$i]['showmandatoryviolation'] = false; } // Get array_filter stuff list($htmltbody2, $hiddenfield) = return_array_filter_strings($ia, $aQuestionAttributes, $thissurvey, $ansrow, $myfname, $trbc, $myfname, "tr", "{$trbc} answers-list radio-list"); $aData['aSubQuestions'][$i]['htmltbody2'] = $htmltbody2; $aData['aSubQuestions'][$i]['hiddenfield'] = $hiddenfield; array_push($inputnames, $myfname0); if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0])) { $aData['aSubQuestions'][$i]['sessionfname0'] = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0]; } else { $aData['aSubQuestions'][$i]['sessionfname0'] = ''; } if (count($labelans1) > 0) { if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1])) { //$answer .= $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname1]; $aData['aSubQuestions'][$i]['sessionfname1'] = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1]; } else { $aData['aSubQuestions'][$i]['sessionfname1'] = ''; } } foreach ($labelcode0 as $j => $ld) { if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0]) && $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0] == $ld) { $aData['labelcode0_checked'][$ansrow['title']][$ld] = CHECKED; } else { $aData['labelcode0_checked'][$ansrow['title']][$ld] = ""; } } if (count($labelans1) > 0) { if ($shownoanswer) { if (!isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0]) || $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0] == "") { $answer .= CHECKED; $aData['myfname0_notset'] = CHECKED; } else { $aData['myfname0_notset'] = ""; } } array_push($inputnames, $myfname1); foreach ($labelcode1 as $j => $ld) { if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1]) && $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1] == $ld) { $aData['labelcode1_checked'][$ansrow['title']][$ld] = CHECKED; } else { $aData['labelcode1_checked'][$ansrow['title']][$ld] = ""; } } } $aData['answertextright'] = $answertextright; if ($shownoanswer) { if (count($labelans1) > 0) { if (!isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1]) || $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1] == "") { $answer .= CHECKED; $aData['myfname1_notset'] = CHECKED; } else { $aData['myfname1_notset'] = ""; } } else { if (!isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0]) || $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0] == "") { $answer .= CHECKED; $aData['myfname0_notset'] = CHECKED; } else { $aData['myfname0_notset'] = ''; } } } $fn++; } $answer = doRender('/survey/questions/arrays/dualscale/answer', $aData, true); } elseif ($useDropdownLayout === true) { $aData = array(); $separatorwidth = (100 - $answerwidth) / 10; $cellwidth = (100 - $answerwidth - $separatorwidth) / 2; $answer = ""; // Get attributes for Headers and Prefix/Suffix if (trim($aQuestionAttributes['dropdown_prepostfix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '') { list($ddprefix, $ddsuffix) = explode("|", $aQuestionAttributes['dropdown_prepostfix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]); $ddprefix = $ddprefix; $ddsuffix = $ddsuffix; } else { $ddprefix = ''; $ddsuffix = ''; } if (trim($aQuestionAttributes['dropdown_separators']) != '') { $aSeparator = explode('|', $aQuestionAttributes['dropdown_separators']); if (isset($aSeparator[1])) { $interddSep = $aSeparator[1]; } else { $interddSep = $aSeparator[0]; } } else { $interddSep = ''; } $aData['answerwidth'] = $answerwidth; $aData['ddprefix'] = $ddprefix; $aData['ddsuffix'] = $ddsuffix; $aData['cellwidth'] = $cellwidth; ////// TODO: check in prev headcolwidth if style='width:$cellwidth' and not style='width:\"$cellwidth\"' $headcolwidth = $ddprefix != '' || $ddsuffix != '' ? "" : " style='width: {$cellwidth}%';"; $aData['headcolwidth'] = $headcolwidth; $aData['separatorwidth'] = $separatorwidth; // colspan : for header only if ($ddprefix != '' && $ddsuffix != '') { $colspan = ' colspan="3"'; } elseif ($ddprefix != '' || $ddsuffix != '') { $colspan = ' colspan="2"'; } else { $colspan = ""; } $aData['colspan'] = $colspan; $aData['leftheader'] = $leftheader; $aData['rightheader'] = $rightheader; $trbc = ''; $aData['aSubQuestions'] = $aSubQuestions; foreach ($aSubQuestions as $i => $ansrow) { $myfname = $ia[1] . $ansrow['title']; $myfname0 = $ia[1] . $ansrow['title'] . "#0"; $myfid0 = $ia[1] . $ansrow['title'] . "_0"; $myfname1 = $ia[1] . $ansrow['title'] . "#1"; $myfid1 = $ia[1] . $ansrow['title'] . "_1"; $sActualAnswer0 = isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0]) ? $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname0] : ""; $sActualAnswer1 = isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1]) ? $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1] : ""; $aData['aSubQuestions'][$i]['myfname'] = $myfname; $aData['aSubQuestions'][$i]['myfname0'] = $myfname0; $aData['aSubQuestions'][$i]['myfid0'] = $myfid0; $aData['aSubQuestions'][$i]['myfname1'] = $myfname1; $aData['aSubQuestions'][$i]['myfid1'] = $myfid1; $aData['aSubQuestions'][$i]['sActualAnswer0'] = $sActualAnswer0; $aData['aSubQuestions'][$i]['sActualAnswer1'] = $sActualAnswer1; // Set mandatory alert $aData['aSubQuestions'][$i]['alert'] = $ia[6] == 'Y' && (in_array($myfname0, $aMandatoryViolationSubQ) || in_array($myfname1, $aMandatoryViolationSubQ)); list($htmltbody2, $hiddenfield) = return_array_filter_strings($ia, $aQuestionAttributes, $thissurvey, $ansrow, $myfname, $trbc, $myfname, "tr", "{$trbc} subquestion-list questions-list dropdown-list"); $aData['aSubQuestions'][$i]['htmltbody2'] = $htmltbody2; $aData['aSubQuestions'][$i]['hiddenfield'] = $hiddenfield; $aData['labels0'] = $labels0; $aData['labels1'] = $labels1; $aData['aSubQuestions'][$i]['showNoAnswer0'] = $sActualAnswer0 != '' && $ia[6] != 'Y' && SHOW_NO_ANSWER; $aData['aSubQuestions'][$i]['showNoAnswer1'] = $sActualAnswer1 != '' && $ia[6] != 'Y' && SHOW_NO_ANSWER; $aData['interddSep'] = $interddSep; $inputnames[] = $myfname0; $inputnames[] = $myfname1; } $answer = doRender('/survey/questions/arrays/dualscale/answer_dropdown', $aData, true); } } else { $answer = "<p class='error'>" . gT("Error: There are no answer options for this question and/or they don't exist in this language.") . "</p>\n"; $inputnames = ""; } Yii::app()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts') . "dualscale.js"); $answer .= "<script type='text/javascript'>\n" . " <!--\n" . " {$doDualScaleFunction}({$ia[0]});\n" . " -->\n" . "</script>\n"; return array($answer, $inputnames); }
function do_array_dual($ia) { global $dbprefix, $connect, $thissurvey, $clang; global $repeatheadings; global $notanswered; global $minrepeatheadings; if ($ia[8] == 'Y') { $checkconditionFunction = "checkconditions"; } else { $checkconditionFunction = "noop_checkconditions"; } $inputnames=array(); $labelans1=array(); $labelans=array(); $qquery = "SELECT other FROM {$dbprefix}questions WHERE qid=".$ia[0]." AND language='".$_SESSION['s_lang']."'"; $other = $connect->GetOne($qquery); //Checked $lquery = "SELECT * FROM {$dbprefix}answers WHERE scale_id=0 AND qid={$ia[0]} AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, code"; $lquery1 = "SELECT * FROM {$dbprefix}answers WHERE scale_id=1 AND qid={$ia[0]} AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, code"; $qidattributes=getQuestionAttributes($ia[0],$ia[4]); if ($qidattributes['use_dropdown']==1) { $useDropdownLayout = true; } else { $useDropdownLayout = false; } if (trim($qidattributes['dualscale_headerA'])!='') { $leftheader= $clang->gT($qidattributes['dualscale_headerA']); } else { $leftheader =''; } if (trim($qidattributes['dualscale_headerB'])!='') { $rightheader= $clang->gT($qidattributes['dualscale_headerB']); } else { $rightheader =''; } $lresult = db_execute_assoc($lquery); //Checked if ($useDropdownLayout === false && $lresult->RecordCount() > 0) { if (trim($qidattributes['answer_width'])!='') { $answerwidth=$qidattributes['answer_width']; } else { $answerwidth=20; } $columnswidth = 100 - $answerwidth; while ($lrow=$lresult->FetchRow()) { $labelans[]=$lrow['answer']; $labelcode[]=$lrow['code']; } $lresult1 = db_execute_assoc($lquery1); //Checked if ($lresult1->RecordCount() > 0) { while ($lrow1=$lresult1->FetchRow()) { $labelans1[]=$lrow1['answer']; $labelcode1[]=$lrow1['code']; } } $numrows=count($labelans) + count($labelans1); if ($ia[6] != "Y" && SHOW_NO_ANSWER == 1) {$numrows++;} $cellwidth=$columnswidth/$numrows; $cellwidth=sprintf("%02d", $cellwidth); $ansquery = "SELECT question FROM {$dbprefix}questions WHERE parent_qid=".$ia[0]." and scale_id=0 AND question like '%|%'"; $ansresult = db_execute_assoc($ansquery); //Checked if ($ansresult->RecordCount()>0) { $right_exists=true; } else { $right_exists=false; } // $right_exists is a flag to find out if there are any right hand answer parts. If there arent we can leave out the right td column if ($qidattributes['random_order']==1) { $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' and scale_id=0 ORDER BY ".db_random(); } else { $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' and scale_id=0 ORDER BY question_order"; } $ansresult = db_execute_assoc($ansquery); //Checked $anscount = $ansresult->RecordCount(); $fn=1; // unselect second scale when using "no answer" $answer = "<script type='text/javascript'>\n" . "<!--\n" . "\tfunction noanswer_checkconditions(value, name, type)\n" . "{\n" . "\tvar vname;\n" . "\tvname = name.replace(/#0/g,\"#1\");\n" . "\tfor(var i=0, n=document.getElementsByName(vname).length; i<n; ++i)\n" . "\t{\n" . "document.getElementsByName(vname)[i].checked=false;\n" . "\t}\n" . "\t$checkconditionFunction(value, name, type);\n" . "}\n" . "\tfunction secondlabel_checkconditions(value, name, type)\n" . "{\n" . "\tvar vname;\n" . "\tvname = \"answer\"+name.replace(/#1/g,\"#0-\");\n" . "\tif(document.getElementById(vname))\n" . "\t{\n" . "document.getElementById(vname).checked=false;\n" . "\t}\n" . "\t$checkconditionFunction(value, name, type);\n" . "}\n" . " //-->\n" . " </script>\n"; // Header row and colgroups $mycolumns = "\t<colgroup class=\"col-responses group-1\">\n" ."\t<col class=\"col-answers\" width=\"$answerwidth%\" />\n"; $myheader2 = "\n<tr class=\"array1 header_row\">\n" . "\t<th class=\"header_answer_text\"> </th>\n\n"; $odd_even = ''; foreach ($labelans as $ld) { $myheader2 .= "\t<th>".$ld."</th>\n"; $odd_even = alternation($odd_even); $mycolumns .= "<col class=\"$odd_even\" width=\"$cellwidth%\" />\n"; } $mycolumns .= "\t</colgroup>\n"; if (count($labelans1)>0) // if second label set is used { $mycolumns .= "\t<colgroup class=\"col-responses group-2\">\n" . "\t<col class=\"seperator\" />\n"; $myheader2 .= "\n\t<td class=\"header_separator\"> </td>\n\n"; // Separator foreach ($labelans1 as $ld) { $myheader2 .= "\t<th>".$ld."</th>\n"; $odd_even = alternation($odd_even); $mycolumns .= "<col class=\"$odd_even\" width=\"$cellwidth%\" />\n"; } } if ($right_exists) { $myheader2 .= "\t<td class=\"header_answer_text_right\"> </td>\n"; $mycolumns .= "\n\t<col class=\"answertextright\" />\n\n"; } if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) //Question is not mandatory and we can show "no answer" { $myheader2 .= "\t<td class=\"header_separator\"> </td>\n"; // Separator $myheader2 .= "\t<th class=\"header_no_answer\">".$clang->gT('No answer')."</th>\n"; $odd_even = alternation($odd_even); $mycolumns .= "\n\t<col class=\"seperator\" />\n\n"; $mycolumns .= "\t<col class=\"col-no-answer $odd_even\" width=\"$cellwidth%\" />\n"; } $mycolumns .= "\t</colgroup>\n"; $myheader2 .= "</tr>\n"; // build first row of header if needed if ($leftheader != '' || $rightheader !='') { $myheader1 = "<tr class=\"array1 groups header_row\">\n" . "\t<th class=\"header_answer_text\"> </th>\n" . "\t<th colspan=\"".count($labelans)."\" class=\"dsheader\">$leftheader</th>\n"; if (count($labelans1)>0) { $myheader1 .= "\t<td class=\"header_separator\"> </td>\n" // Separator ."\t<th colspan=\"".count($labelans1)."\" class=\"dsheader\">$rightheader</th>\n"; } if ($right_exists) { $myheader1 .= "\t<td class=\"header_answer_text_right\"> </td>\n"; } if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { $myheader1 .= "\t<td class=\"header_separator\"> </td>\n"; // Separator $myheader1 .= "\t<th class=\"header_no_answer\"> </th>\n"; } $myheader1 .= "</tr>\n"; } else { $myheader1 = ''; } $answer .= "\n<table class=\"question\" summary=\"".str_replace('"','' ,strip_tags($ia[3]))." - a dual array type question\">\n" . $mycolumns . "\n\t<thead>\n" . $myheader1 . $myheader2 . "\n\t</thead>\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 .= "<tbody>\n<tr class=\"repeat\">\n" . "\t<th class=\"header_answer_text\"> </th>\n"; foreach ($labelans as $ld) { $answer .= "\t<th>".$ld."</th>\n"; } if (count($labelans1)>0) // if second label set is used { $answer .= "<th class=\"header_separator\"> </th>\n"; // Separator foreach ($labelans1 as $ld) { $answer .= "\t<th>".$ld."</th>\n"; } } if ($right_exists) { $answer .= "\t<td class=\"header_answer_text_right\"> </td>\n"; } if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) //Question is not mandatory and we can show "no answer" { $answer .= "\t<td class=\"header_separator\"> </td>\n"; // Separator $answer .= "\t<th class=\"header_no_answer\">".$clang->gT('No answer')."</th>\n"; } $answer .= "</tr>\n</tbody>\n"; } } $trbc = alternation($trbc , 'row'); $answertext=dTexts::run($ansrow['question']); $answertextsave=$answertext; $dualgroup=0; $myfname0= $ia[1].$ansrow['title']; $myfname = $ia[1].$ansrow['title'].'#0'; $myfname1 = $ia[1].$ansrow['title'].'#1'; // new multi-scale-answer /* Check if this item has not been answered: the 'notanswered' variable must be an array, containing a list of unanswered questions, the current question must be in the array, and there must be no answer available for the item in this session. */ if ((is_array($notanswered)) && (array_search($ia[1], $notanswered) !== FALSE) && (($_SESSION[$myfname] == '') || ($_SESSION[$myfname1] == '')) ) { $answertext = "<span class='errormandatory'>{$answertext}</span>"; } // 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 .= "<tr class=\"$trbc\">\n" . "\t<th class=\"answertext\">\n" . $hiddenfield . "$answertext\n" . "<input type=\"hidden\" name=\"java$myfname\" id=\"java$myfname\" value=\""; if (isset($_SESSION[$myfname])) {$answer .= $_SESSION[$myfname];} $answer .= "\" />\n\t</th>\n"; $hiddenanswers=''; $thiskey=0; foreach ($labelcode as $ld) { $answer .= "\t<td class=\"answer_cell_1_00$ld\">\n" . "<label for=\"answer$myfname-$ld\">\n" . "\t<input class=\"radio\" type=\"radio\" name=\"$myfname\" value=\"$ld\" id=\"answer$myfname-$ld\" title=\"" . html_escape(strip_tags($labelans[$thiskey])).'"'; if (isset($_SESSION[$myfname]) && $_SESSION[$myfname] == $ld) { $answer .= CHECKED; } // --> START NEW FEATURE - SAVE $answer .= " onclick=\"$checkconditionFunction(this.value, this.name, this.type)\" />\n</label>\n"; // --> END NEW FEATURE - SAVE $answer .= "\n\t</td>\n"; $thiskey++; } if (count($labelans1)>0) // if second label set is used { $dualgroup++; $hiddenanswers=''; $answer .= "\t<td class=\"dual_scale_separator\"> </td>\n"; // separator array_push($inputnames,$myfname1); $hiddenanswers .= "<input type=\"hidden\" name=\"java$myfname1\" id=\"java$myfname1\" value=\""; if (isset($_SESSION[$myfname1])) {$hiddenanswers .= $_SESSION[$myfname1];} $hiddenanswers .= "\" />\n"; $thiskey=0; foreach ($labelcode1 as $ld) // second label set { $answer .= "\t<td class=\"answer_cell_2_00$ld\">\n"; if ($hiddenanswers!='') { $answer .=$hiddenanswers; $hiddenanswers=''; } $answer .= "<label for=\"answer$myfname1-$ld\">\n" . "\t<input class=\"radio\" type=\"radio\" name=\"$myfname1\" value=\"$ld\" id=\"answer$myfname1-$ld\" title=\"" . html_escape(strip_tags($labelans1[$thiskey])).'"'; if (isset($_SESSION[$myfname1]) && $_SESSION[$myfname1] == $ld) { $answer .= CHECKED; } // --> START NEW FEATURE - SAVE $answer .= " onclick=\"secondlabel_checkconditions(this.value, this.name, this.type)\" />\n</label>\n"; // --> END NEW FEATURE - SAVE $answer .= "\t</td>\n"; $thiskey++; } } if (strpos($answertextsave,'|')) { $answertext=substr($answertextsave,strpos($answertextsave,'|')+1); $answer .= "\t<td class=\"answertextright\">$answertext</td>\n"; $hiddenanswers = ''; } elseif ($right_exists) { $answer .= "\t<td class=\"answertextright\"> </td>\n"; } if ($ia[6] != "Y" && SHOW_NO_ANSWER == 1) { $answer .= "\t<td class=\"dual_scale_separator\"> </td>\n"; // separator $answer .= "\t<td class=\"dual_scale_no_answer\">\n" . "<label for='answer$myfname-'>\n" . "\t<input class='radio' type='radio' name='$myfname' value='' id='answer$myfname-' title='".$clang->gT("No answer")."'"; if (!isset($_SESSION[$myfname]) || $_SESSION[$myfname] == "") { $answer .= CHECKED; } // --> START NEW FEATURE - SAVE $answer .= " onclick=\"noanswer_checkconditions(this.value, this.name, this.type)\" />\n" . "</label>\n" . "\t</td>\n"; // --> END NEW FEATURE - SAVE } $answer .= "</tr>\n"; $answer .= "\t</tbody>\n"; // $inputnames[]=$myfname; //IF a MULTIPLE of flexi-redisplay figure, repeat the headings $fn++; } $answer .= "</table>\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<p class=\"error\">".$clang->gT('Error: This question has no answers.')."</p>\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<table class=\"question\" summary=\"".str_replace('"','' ,strip_tags($ia[3]))." - an dual array type question\">\n\n" . "\t<col class=\"answertext\" width=\"$answerwidth%\" />\n"; if($ddprefix != '') { $answer .= "\t<col class=\"ddprefix\" />\n"; $colspan_1 = ' colspan="2"'; } $answer .= "\t<col class=\"dsheader\" />\n"; if($ddsuffix != '') { $answer .= "\t<col class=\"ddsuffix\" />\n"; if(!empty($colspan_1)) { $colspan_2 = ' colspan="3"'; } $suffix_cell = "\t<td> </td>\n"; // suffix } $answer .= "\t<col class=\"ddarrayseparator\" width=\"$separatorwidth%\" />\n"; if($ddprefix != '') { $answer .= "\t<col class=\"ddprefix\" />\n"; } $answer .= "\t<col class=\"dsheader\" />\n"; if($ddsuffix != '') { $answer .= "\t<col class=\"ddsuffix\" />\n"; }; // headers $answer .= "\n\t<thead>\n" . "<tr>\n" . "\t<td$colspan_1> </td>\n" // prefix . "\n" // . "\t<td align='center' width='$columnswidth%'><span class='dsheader'>$leftheader</span></td>\n" . "\t<th>$leftheader</th>\n" . "\n" . "\t<td$colspan_2> </td>\n" // suffix // Inter DD separator // prefix // . "\t<td align='center' width='$columnswidth%'><span class='dsheader'>$rightheader</span></td>\n" . "\t<th>$rightheader</th>\n" . $suffix_cell."</tr>\n" . "\t</thead>\n\n"; $trbc = ''; while ($ansrow = $ansresult->FetchRow()) { $rowname = $ia[1].$ansrow['title']; $dualgroup=0; $myfname = $ia[1].$ansrow['title']."#".$dualgroup; $dualgroup1=1; $myfname1 = $ia[1].$ansrow['title']."#".$dualgroup1; if ((is_array($notanswered)) && (array_search($ia[1], $notanswered) !== FALSE) && ($_SESSION[$myfname] == "" || $_SESSION[$myfname1] == "") ) { $answertext="<span class='errormandatory'>".dTexts::run($ansrow['question'])."</span>"; } 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 .= "<tr class=\"$trbc\">\n" . "\t<th class=\"answertext\">\n" . "<label for=\"answer$rowname\">\n" . $hiddenfield . "$answertext\n" . "</label>\n" . "\t</th>\n"; // Label0 // prefix if($ddprefix != '') { $answer .= "\t<td class=\"ddprefix\">$ddprefix</td>\n"; } $answer .= "\t<td >\n" . "<select name=\"$myfname\" id=\"answer$myfname\" onchange=\"array_dual_dd_checkconditions(this.value, this.name, this.type,$dualgroup,$checkconditionFunction);\">\n"; if (!isset($_SESSION[$myfname]) || $_SESSION[$myfname] =='') { $answer .= "\t<option value=\"\" ".SELECTED.'>'.$clang->gT('Please choose...')."</option>\n"; } foreach ($labels0 as $lrow) { $answer .= "\t<option value=\"".$lrow['code'].'" '; if (isset($_SESSION[$myfname]) && $_SESSION[$myfname] == $lrow['code']) { $answer .= SELECTED; } $answer .= '>'.$lrow['title']."</option>\n"; } // If not mandatory and showanswer, show no ans if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { $answer .= "\t<option value=\"\" "; if (!isset($_SESSION[$myfname]) || $_SESSION[$myfname] == '') { $answer .= SELECTED; } $answer .= '>'.$clang->gT('No answer')."</option>\n"; } $answer .= "</select>\n"; // suffix if($ddsuffix != '') { $answer .= "\t<td class=\"ddsuffix\">$ddsuffix</td>\n"; } $answer .= "<input type=\"hidden\" name=\"java$myfname\" id=\"java$myfname\" value=\""; if (isset($_SESSION[$myfname])) { $answer .= $_SESSION[$myfname]; } $answer .= "\" />\n" . "\t</td>\n"; $inputnames[]=$myfname; $answer .= "\t<td class=\"ddarrayseparator\">$interddSep</td>\n"; //Separator // Label1 // prefix if($ddprefix != '') { $answer .= "\t<td class='ddprefix'>$ddprefix</td>\n"; } // $answer .= "\t<td align='left' width='$columnswidth%'>\n" $answer .= "\t<td>\n" . "<select name=\"$myfname1\" id=\"answer$myfname1\" onchange=\"array_dual_dd_checkconditions(this.value, this.name, this.type,$dualgroup1,$checkconditionFunction);\">\n"; if (!isset($_SESSION[$myfname1]) || $_SESSION[$myfname1] =='') { $answer .= "\t<option value=\"\"".SELECTED.'>'.$clang->gT('Please choose...')."</option>\n"; } foreach ($labels1 as $lrow1) { $answer .= "\t<option value=\"".$lrow1['code'].'" '; if (isset($_SESSION[$myfname1]) && $_SESSION[$myfname1] == $lrow1['code']) { $answer .= SELECTED; } $answer .= '>'.$lrow1['title']."</option>\n"; } // If not mandatory and showanswer, show no ans if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { $answer .= "\t<option value='' "; if (!isset($_SESSION[$myfname1]) || $_SESSION[$myfname1] == '') { $answer .= SELECTED; } $answer .= ">".$clang->gT('No answer')."</option>\n"; } $answer .= "</select>\n"; // suffix if($ddsuffix != '') { $answer .= "\t<td class=\"ddsuffix\">$ddsuffix</td>\n"; } $answer .= "<input type=\"hidden\" name=\"java$myfname1\" id=\"java$myfname1\" value=\""; if (isset($_SESSION[$myfname1])) { $answer .= $_SESSION[$myfname1]; } $answer .= "\" />\n" . "\t</td>\n"; $inputnames[]=$myfname1; $answer .= "</tr>\n"; $answer .= "\t</tbody>\n"; } } // End there are answers $answer .= "</table>\n"; } else { $answer = "<p class='error'>".$clang->gT("Error: There are no answer options for this question and/or they don't exist in this language.")."</p>\n"; $inputnames=""; } return array($answer, $inputnames); }
function do_array_dual($ia) { global $thissurvey; global $notanswered; $repeatheadings = Yii::app()->getConfig("repeatheadings"); $minrepeatheadings = Yii::app()->getConfig("minrepeatheadings"); $extraclass = ""; $answertypeclass = ""; // Maybe not $clang = Yii::app()->lang; $checkconditionFunction = "checkconditions"; $inputnames = array(); $labelans1 = array(); $labelans = array(); $qquery = "SELECT other FROM {{questions}} WHERE qid=" . $ia[0] . " AND language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "'"; $other = dbExecuteAssoc($qquery)->read(); $other = reset($other); //Checked $lquery = "SELECT * FROM {{answers}} WHERE scale_id=0 AND qid={$ia[0]} AND language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "' ORDER BY sortorder, code"; $lquery1 = "SELECT * FROM {{answers}} WHERE scale_id=1 AND qid={$ia[0]} AND language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "' ORDER BY sortorder, code"; $aQuestionAttributes = getQuestionAttributeValues($ia[0], $ia[4]); if ($aQuestionAttributes['use_dropdown'] == 1) { $useDropdownLayout = true; $extraclass .= " dropdown-list"; $answertypeclass .= " dropdown"; } else { $useDropdownLayout = false; $extraclass .= " radio-list"; $answertypeclass .= " radio"; } if (ctype_digit(trim($aQuestionAttributes['repeat_headings'])) && trim($aQuestionAttributes['repeat_headings'] != "")) { $repeatheadings = intval($aQuestionAttributes['repeat_headings']); $minrepeatheadings = 0; } if (trim($aQuestionAttributes['dualscale_headerA'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '') { $leftheader = $clang->gT($aQuestionAttributes['dualscale_headerA'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]); } else { $leftheader = ''; } if (trim($aQuestionAttributes['dualscale_headerB'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '') { $rightheader = $clang->gT($aQuestionAttributes['dualscale_headerB'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]); } else { $rightheader = ''; } $lresult = dbExecuteAssoc($lquery); //Checked $aAnswersScale1 = $lresult->readAll(); if ($useDropdownLayout === false && count($aAnswersScale1) > 0) { if (trim($aQuestionAttributes['answer_width']) != '') { $answerwidth = $aQuestionAttributes['answer_width']; } else { $answerwidth = 20; } $columnswidth = 100 - $answerwidth; foreach ($aAnswersScale1 as $lrow) { $labelans[] = $lrow['answer']; $labelcode[] = $lrow['code']; } $lresult1 = dbExecuteAssoc($lquery1); //Checked foreach ($lresult1->readAll() as $lrow1) { $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); $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(); $right_exists = $iCount > 0; // $right_exists is a flag to find out if there are any right hand answer parts. If there aren't we can leave out the right td column if ($aQuestionAttributes['random_order'] == 1) { $ansquery = "SELECT * FROM {{questions}} WHERE parent_qid={$ia['0']} AND language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "' and scale_id=0 ORDER BY " . dbRandom(); } else { $ansquery = "SELECT * FROM {{questions}} WHERE parent_qid={$ia['0']} AND language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "' and scale_id=0 ORDER BY question_order"; } $ansresult = dbExecuteAssoc($ansquery); //Checked $aQuestionsRight = $ansresult->readAll(); $anscount = count($aQuestionsRight); $fn = 1; // unselect second scale when using "no answer" $answer = "<script type='text/javascript'>\n" . "<!--\n" . "function noanswer_checkconditions(value, name, type)\n" . "{\n" . "\tvar vname;\n" . "\tvname = name.replace(/#.*\$/,\"\");\n" . "\t\$('input[name^=\"' + vname + '\"]').attr('checked',false);\n" . "\t\$('input[id=\"answer' + vname + '#0-\"]').attr('checked',true);\n" . "\t\$('input[name^=\"java' + vname + '\"]').val('');\n" . "\t{$checkconditionFunction}(value, name, type);\n" . "}\n" . "function secondlabel_checkconditions(value, name, type)\n" . "{\n" . "\tvar vname;\n" . "\tvname = \"answer\"+name.replace(/#1/g,\"#0-\");\n" . "\tif(document.getElementById(vname))\n" . "\t{\n" . "\tdocument.getElementById(vname).checked=false;\n" . "\t}\n" . "\t{$checkconditionFunction}(value, name, type);\n" . "}\n" . " //-->\n" . " </script>\n"; // Header row and colgroups $mycolumns = "\t<colgroup class=\"col-responses group-1\">\n" . "\t<col class=\"col-answers\" width=\"{$answerwidth}%\" />\n"; $answer_head_line = "\t<th class=\"header_answer_text\"> </th>\n\n"; $odd_even = ''; foreach ($labelans as $ld) { $answer_head_line .= "\t<th>" . $ld . "</th>\n"; $odd_even = alternation($odd_even); $mycolumns .= "<col class=\"{$odd_even}\" width=\"{$cellwidth}%\" />\n"; } $mycolumns .= "\t</colgroup>\n"; if (count($labelans1) > 0) { $mycolumns .= "\t<colgroup class=\"col-responses group-2\">\n" . "\t<col class=\"seperator\" />\n"; $answer_head_line .= "\n\t<td class=\"header_separator\"> </td>\n\n"; // Separator foreach ($labelans1 as $ld) { $answer_head_line .= "\t<th>" . $ld . "</th>\n"; $odd_even = alternation($odd_even); $mycolumns .= "<col class=\"{$odd_even}\" width=\"{$cellwidth}%\" />\n"; } } if ($right_exists) { $answer_head_line .= "\t<td class=\"header_answer_text_right\"> </td>\n"; $mycolumns .= "\n\t<col class=\"answertextright\" />\n\n"; } if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { $answer_head_line .= "\t<td class=\"header_separator\"> </td>\n"; // Separator $answer_head_line .= "\t<th class=\"header_no_answer\">" . $clang->gT('No answer') . "</th>\n"; $odd_even = alternation($odd_even); $mycolumns .= "\n\t<col class=\"seperator\" />\n\n"; $mycolumns .= "\t<col class=\"col-no-answer {$odd_even}\" width=\"{$cellwidth}%\" />\n"; } $mycolumns .= "\t</colgroup>\n"; $answer_head2 = "\n<tr class=\"array1 header_row\">\n" . $answer_head_line . "</tr>\n"; // build first row of header if needed if ($leftheader != '' || $rightheader != '') { $answer_head1 = "<tr class=\"array1 groups header_row\">\n" . "\t<th class=\"header_answer_text\"> </th>\n" . "\t<th colspan=\"" . count($labelans) . "\" class=\"dsheader\">{$leftheader}</th>\n"; if (count($labelans1) > 0) { $answer_head1 .= "\t<td class=\"header_separator\"> </td>\n" . "\t<th colspan=\"" . count($labelans1) . "\" class=\"dsheader\">{$rightheader}</th>\n"; } if ($right_exists) { $answer_head1 .= "\t<td class=\"header_answer_text_right\"> </td>\n"; } if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { $answer_head1 .= "\t<td class=\"header_separator\"> </td>\n"; // Separator $answer_head1 .= "\t<th class=\"header_no_answer\"> </th>\n"; } $answer_head1 .= "</tr>\n"; } else { $answer_head1 = ''; } $answer .= "\n<table class=\"question subquestions-list questions-list\" summary=\"" . str_replace('"', '', strip_tags($ia[3])) . " - a dual array type question\">\n" . $mycolumns . "\n\t<thead>\n" . $answer_head1 . $answer_head2 . "\n\t</thead>\n" . "<tbody>\n"; $trbc = ''; foreach ($aQuestionsRight as $ansrow) { // Build repeat headings if needed if (isset($repeatheadings) && $repeatheadings > 0 && $fn - 1 > 0 && ($fn - 1) % $repeatheadings == 0) { if ($anscount - $fn + 1 >= $minrepeatheadings) { $answer .= "</tbody>\n<tbody>"; // Close actual body and open another one //$answer .= $answer_head1; $answer .= "\n<tr class=\"repeat headings\">\n" . $answer_head_line . "</tr>\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['survey_' . Yii::app()->getConfig('surveyID')][$myfname] == '' || $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1] == '')) { $answertext = "<span class='errormandatory'>{$answertext}</span>"; } // Get array_filter stuff list($htmltbody2, $hiddenfield) = return_array_filter_strings($ia, $aQuestionAttributes, $thissurvey, $ansrow, $myfname0, $trbc, $myfname, "tr", "{$trbc} answers-list radio-list"); $answer .= $htmltbody2; if (strpos($answertext, '|')) { $answertext = substr($answertext, 0, strpos($answertext, '|')); } array_push($inputnames, $myfname); $answer .= "\t<th class=\"answertext\">\n" . $hiddenfield . "{$answertext}\n" . "<input type=\"hidden\" name=\"java{$myfname}\" id=\"java{$myfname}\" value=\""; if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname])) { $answer .= $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname]; } $answer .= "\" />\n\t</th>\n"; $hiddenanswers = ''; $thiskey = 0; foreach ($labelcode as $ld) { $answer .= "\t<td class=\"answer_cell_1_00{$ld} answer-item {$answertypeclass}-item\">\n" . "<label for=\"answer{$myfname}-{$ld}\">\n" . "\t<input class=\"radio\" type=\"radio\" name=\"{$myfname}\" value=\"{$ld}\" id=\"answer{$myfname}-{$ld}\" title=\"" . HTMLEscape(strip_tags($labelans[$thiskey])) . '"'; if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname]) && $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname] == $ld) { $answer .= CHECKED; } // --> START NEW FEATURE - SAVE $answer .= " onclick=\"{$checkconditionFunction}(this.value, this.name, this.type)\" />\n</label>\n"; // --> END NEW FEATURE - SAVE $answer .= "\n\t</td>\n"; $thiskey++; } if (count($labelans1) > 0) { $dualgroup++; $hiddenanswers = ''; $answer .= "\t<td class=\"dual_scale_separator information-item\"> </td>\n"; // separator array_push($inputnames, $myfname1); $hiddenanswers .= "<input type=\"hidden\" name=\"java{$myfname1}\" id=\"java{$myfname1}\" value=\""; if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1])) { $hiddenanswers .= $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1]; } $hiddenanswers .= "\" />\n"; $thiskey = 0; foreach ($labelcode1 as $ld) { $answer .= "\t<td class=\"answer_cell_2_00{$ld} answer-item radio-item\">\n"; if ($hiddenanswers != '') { $answer .= $hiddenanswers; $hiddenanswers = ''; } $answer .= "<label for=\"answer{$myfname1}-{$ld}\">\n" . "\t<input class=\"radio\" type=\"radio\" name=\"{$myfname1}\" value=\"{$ld}\" id=\"answer{$myfname1}-{$ld}\" title=\"" . HTMLEscape(strip_tags($labelans1[$thiskey])) . '"'; if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1]) && $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1] == $ld) { $answer .= CHECKED; } // --> START NEW FEATURE - SAVE $answer .= " onclick=\"secondlabel_checkconditions(this.value, this.name, this.type)\" />\n</label>\n"; // --> END NEW FEATURE - SAVE $answer .= "\t</td>\n"; $thiskey++; } } if (strpos($answertextsave, '|')) { $answertext = substr($answertextsave, strpos($answertextsave, '|') + 1); $answer .= "\t<td class=\"answertextright\">{$answertext}</td>\n"; $hiddenanswers = ''; } elseif ($right_exists) { $answer .= "\t<td class=\"answertextright\"> </td>\n"; } if ($ia[6] != "Y" && SHOW_NO_ANSWER == 1) { $answer .= "\t<td class=\"dual_scale_separator information-item\"> </td>\n"; // separator $answer .= "\t<td class=\"dual_scale_no_answer answer-item radio-item noanswer-item\">\n" . "<label for='answer{$myfname}-'>\n" . "\t<input class='radio' type='radio' name='{$myfname}' value='' id='answer{$myfname}-' title='" . $clang->gT("No answer") . "'"; if (!isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname]) || $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname] == "") { $answer .= CHECKED; } // --> START NEW FEATURE - SAVE $answer .= " onclick=\"noanswer_checkconditions(this.value, this.name, this.type)\" />\n" . "</label>\n" . "\t</td>\n"; // --> END NEW FEATURE - SAVE } $answer .= "</tr>\n"; // $inputnames[]=$myfname; //IF a MULTIPLE of flexi-redisplay figure, repeat the headings $fn++; } $answer .= "\t</tbody>\n"; $answer .= "</table>\n"; } elseif ($useDropdownLayout === true && count($aAnswersScale1) > 0) { if (trim($aQuestionAttributes['answer_width']) != '') { $answerwidth = $aQuestionAttributes['answer_width']; } else { $answerwidth = 20; } $separatorwidth = (100 - $answerwidth) / 10; $columnswidth = 100 - $answerwidth - $separatorwidth * 2; $answer = ""; // Get Answers //question atribute random_order set? 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); $aSubquestions = $ansresult->readAll(); //Checked $anscount = count($aSubquestions); if ($anscount == 0) { $inputnames = array(); $answer .= "\n<p class=\"error\">" . $clang->gT('Error: This question has no answers.') . "</p>\n"; } else { //already done $lresult = dbExecuteAssoc($lquery); foreach ($aAnswersScale1 as $lrow) { $labels0[] = array('code' => $lrow['code'], 'title' => $lrow['answer']); } $lresult1 = dbExecuteAssoc($lquery1); //Checked foreach ($lresult1->readAll() as $lrow1) { $labels1[] = array('code' => $lrow1['code'], 'title' => $lrow1['answer']); } // Get attributes for Headers and Prefix/Suffix if (trim($aQuestionAttributes['dropdown_prepostfix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '') { list($ddprefix, $ddsuffix) = explode("|", $aQuestionAttributes['dropdown_prepostfix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]); $ddprefix = $ddprefix; $ddsuffix = $ddsuffix; } else { $ddprefix = ''; $ddsuffix = ''; } if (trim($aQuestionAttributes['dropdown_separators']) != '') { list($postanswSep, $interddSep) = explode('|', $aQuestionAttributes['dropdown_separators']); $postanswSep = $postanswSep; $interddSep = $interddSep; } else { $postanswSep = ''; $interddSep = ''; } $colspan_1 = ''; $colspan_2 = ''; $suffix_cell = ''; $answer .= "\n<table class=\"question subquestion-list questions-list dropdown-list\" summary=\"" . str_replace('"', '', strip_tags($ia[3])) . " - an dual array type question\">\n\n" . "\t<col class=\"answertext\" width=\"{$answerwidth}%\" />\n"; if ($ddprefix != '') { $answer .= "\t<col class=\"ddprefix\" />\n"; $colspan_1 = ' colspan="2"'; } $answer .= "\t<col class=\"dsheader\" />\n"; if ($ddsuffix != '') { $answer .= "\t<col class=\"ddsuffix\" />\n"; if (!empty($colspan_1)) { $colspan_2 = ' colspan="3"'; } $suffix_cell = "\t<td> </td>\n"; // suffix } $answer .= "\t<col class=\"ddarrayseparator\" width=\"{$separatorwidth}%\" />\n"; if ($ddprefix != '') { $answer .= "\t<col class=\"ddprefix\" />\n"; } $answer .= "\t<col class=\"dsheader\" />\n"; if ($ddsuffix != '') { $answer .= "\t<col class=\"ddsuffix\" />\n"; } // headers $answer .= "\n\t<thead>\n" . "<tr>\n" . "\t<td{$colspan_1}> </td>\n" . "\n" . "\t<th>{$leftheader}</th>\n" . "\n" . "\t<td{$colspan_2}> </td>\n" . "\t<th>{$rightheader}</th>\n" . $suffix_cell . "</tr>\n" . "\t</thead>\n\n"; $answer .= "\n<tbody>\n"; $trbc = ''; foreach ($aSubquestions as $ansrow) { $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['survey_' . Yii::app()->getConfig('surveyID')][$myfname] == '' || $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1] == '')) { $answertext = "<span class='errormandatory'>" . dTexts__run($ansrow['question']) . "</span>"; } else { $answertext = dTexts__run($ansrow['question']); } $trbc = alternation($trbc, 'row'); // Get array_filter stuff list($htmltbody2, $hiddenfield) = return_array_filter_strings($ia, $aQuestionAttributes, $thissurvey, $ansrow, $rowname, $trbc, $myfname, "tr", "{$trbc} subquestion-list questions-list dropdown-list"); $answer .= $htmltbody2; $answer .= "\t<th class=\"answertext\">\n" . "<label for=\"answer{$rowname}\">\n" . $hiddenfield . "{$answertext}\n" . "</label>\n" . "\t</th>\n"; // Label0 // prefix if ($ddprefix != '') { $answer .= "\t<td class=\"ddprefix information-item\">{$ddprefix}</td>\n"; } $answer .= "\t<td class=\"answer-item dropdown-item\">\n" . "<select name=\"{$myfname}\" id=\"answer{$myfname}\" onchange=\"array_dual_dd_checkconditions(this.value, this.name, this.type,{$dualgroup},{$checkconditionFunction});\">\n"; if (!isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname]) || $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname] == '') { $answer .= "\t<option value=\"\" " . SELECTED . '>' . $clang->gT('Please choose...') . "</option>\n"; } foreach ($labels0 as $lrow) { $answer .= "\t<option value=\"" . $lrow['code'] . '" '; if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname]) && $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname] == $lrow['code']) { $answer .= SELECTED; } $answer .= '>' . flattenText($lrow['title']) . "</option>\n"; } // If not mandatory and showanswer, show no ans if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { $answer .= "\t<option class=\"noanswer-item\" value=\"\" "; if (!isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname]) || $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname] == '') { $answer .= SELECTED; } $answer .= '>' . $clang->gT('No answer') . "</option>\n"; } $answer .= "</select>\n"; // suffix if ($ddsuffix != '') { $answer .= "\t<td class=\"ddsuffix information-item\">{$ddsuffix}</td>\n"; } $answer .= "<input type=\"hidden\" name=\"java{$myfname}\" id=\"java{$myfname}\" value=\""; if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname])) { $answer .= $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname]; } $answer .= "\" />\n" . "\t</td>\n"; $inputnames[] = $myfname; $answer .= "\t<td class=\"ddarrayseparator information-item\">{$interddSep}</td>\n"; //Separator // Label1 // prefix if ($ddprefix != '') { $answer .= "\t<td class='ddprefix information-item'>{$ddprefix}</td>\n"; } // $answer .= "\t<td align='left' width='$columnswidth%'>\n" $answer .= "\t<td class=\"answer-item dropdown-item\">\n" . "<select name=\"{$myfname1}\" id=\"answer{$myfname1}\" onchange=\"array_dual_dd_checkconditions(this.value, this.name, this.type,{$dualgroup1},{$checkconditionFunction});\">\n"; if (empty($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname])) { $answer .= "\t<option value=\"\"" . SELECTED . '>' . $clang->gT('Please choose...') . "</option>\n"; } foreach ($labels1 as $lrow1) { $answer .= "\t<option value=\"" . $lrow1['code'] . '" '; if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1]) && $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1] == $lrow1['code']) { $answer .= SELECTED; } $answer .= '>' . flattenText($lrow1['title']) . "</option>\n"; } // If not mandatory and showanswer, show no ans if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { $answer .= "\t<option class=\"noanswer-item\" value='' "; if (empty($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname])) { $answer .= SELECTED; } $answer .= ">" . $clang->gT('No answer') . "</option>\n"; } $answer .= "</select>\n"; // suffix if ($ddsuffix != '') { $answer .= "\t<td class=\"ddsuffix information-item\">{$ddsuffix}</td>\n"; } $answer .= "<input type=\"hidden\" name=\"java{$myfname1}\" id=\"java{$myfname1}\" value=\""; if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1])) { $answer .= $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname1]; } $answer .= "\" />\n" . "\t</td>\n"; $inputnames[] = $myfname1; $answer .= "</tr>\n"; } } // End there are answers $answer .= "\t</tbody>\n"; $answer .= "</table>\n"; } else { $answer = "<p class='error'>" . $clang->gT("Error: There are no answer options for this question and/or they don't exist in this language.") . "</p>\n"; $inputnames = ""; } return array($answer, $inputnames); }