Skip to content
Permalink
 
 
Cannot retrieve contributors at this time
<?php
/*
* LimeSurvey
* Copyright (C) 2007-2011 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
// Security Checked: POST, GET, SESSION, REQUEST, returnGlobal, DB
//if (!isset($homedir) || isset($_REQUEST['$homedir'])) {die("Cannot run this script directly");}
/*
* Let's explain what this strange $ia var means
*
* The $ia string comes from the $_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['insertarray'] variable which is built at the commencement of the survey.
* See index.php, function "buildsurveysession()"
* One $ia array zexists for every question in the survey. The $_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['insertarray']
* string is an array of $ia arrays.
*
* $ia[0] => question id
* $ia[1] => fieldname
* $ia[2] => title
* $ia[3] => question text
* $ia[4] => type -- text, radio, select, array, etc
* $ia[5] => group id
* $ia[6] => mandatory Y || S || N
* $ia[7] => conditions exist for this question
* $ia[8] => other questions have conditions which rely on this question (including array_filter and array_filter_exclude attributes)
* $ia[9] => incremental question count (used by {QUESTION_NUMBER})
*
* $conditions element structure
* $condition[n][0] => qid = question id
* $condition[n][1] => cqid = question id of the target question, or 0 for TokenAttr leftOperand
* $condition[n][2] => field name of element [1] (Except for type M or P)
* $condition[n][3] => value to be evaluated on answers labeled.
* $condition[n][4] => type of question
* $condition[n][5] => SGQ code of element [1] (sub-part of [2])
* $condition[n][6] => method used to evaluate
* $condition[n][7] => scenario *NEW BY R.L.J. van den Burg*
*/
// ==================================================================
// setting constants for 'checked' and 'selected' inputs
define('CHECKED', ' checked="checked"');
define('SELECTED', ' selected="selected"');
/**
* setNoAnswerMode
*/
function setNoAnswerMode($thissurvey)
{
if (App()->getConfig('shownoanswer') == 2) {
if ($thissurvey['shownoanswer'] == 'N') {
define('SHOW_NO_ANSWER', 0);
} else {
define('SHOW_NO_ANSWER', 1);
}
} elseif (App()->getConfig('shownoanswer') == 1) {
define('SHOW_NO_ANSWER', 1);
} elseif (App()->getConfig('shownoanswer') == 0) {
define('SHOW_NO_ANSWER', 0);
} else {
define('SHOW_NO_ANSWER', 1);
}
}
/**
* This function returns an array containing the "question/answer" html display
* and a list of the question/answer fieldnames associated. It is called from
* question.php, group.php, survey.php or preview.php
*
* @param array $ia Details of $ia can be found at top of this file
* @return array Array like [array $qanda, array $inputnames] where
* $qanda has elements [
* $qtitle (question_text) : array [
* all : string; complete HTML?; all has been added for backwards compatibility with templates that use question_start.pstpl (now redundant)
* 'text' => $qtitle, question?? $ia[3]?
* 'code' => $ia[2] or title??
* 'number' => $number
* 'help' => ''
* 'mandatory' => ''
* man_message : string; message when mandatory is not answered
* 'valid_message' => ''
* file_valid_message : string; only relevant for file upload
* 'class' => ''
* 'man_class' => ''
* 'input_error_class' => '' // provides a class.
* 'essentials' => ''
* ]
* $answer ?
* 'help' : string
* $display : ?
* $qid : integer
* $ia[2] = title;
* $ia[5] = group id : int
* $ia[1] = fieldname : string
* ]
* and $inputnames is ? used for hiddenfieldnames and upload file?
*
*/
function retrieveAnswers($ia)
{
//globalise required config variables
global $thissurvey; //These are set by index.php
// TODO: This can be cached in some special cases.
// 1. If move back is disabled
// 2. No tokens
// 3. Always first time it's shown to one user (and no tokens).
// 4. No expressions with tokens or time or other dynamic features.
if (EmCacheHelper::cacheQanda($ia, $_SESSION['survey_' . $thissurvey['sid']])) {
$cacheKey = 'retrieveAnswers_' . sha1(implode('_', $ia));
$value = EmCacheHelper::get($cacheKey);
if ($value !== false) {
return $value;
}
}
$display = $ia[7]; //DISPLAY
$qid = $ia[0]; // Question ID
$qtitle = $ia[3];
$inputnames = [];
$answer = ""; //Create the question/answer html
$number = isset($ia[9]) ? $ia[9] : ''; // Previously in limesurvey, it was virtually impossible to control how the start of questions were formatted. // this is an attempt to allow users (or rather system admins) some control over how the starting text is formatted.
$aQuestionAttributes = QuestionAttribute::model()->getQuestionAttributes($ia[0]);
$question_text = array(
'all' => '' // All has been added for backwards compatibility with templates that use question_start.pstpl (now redundant)
,'text' => $qtitle
,'code' => $ia[2]
,'number' => $number
,'help' => ''
,'mandatory' => ''
,'man_message' => ''
,'valid_message' => ''
,'file_valid_message' => ''
,'class' => ''
,'man_class' => ''
,'input_error_class' => '' // provides a class.
,'essentials' => ''
);
$oQuestion = Question::model()->findByPk($ia[0]);
$oQuestionTemplate = QuestionTemplate::getNewInstance($oQuestion);
$oQuestionTemplate->registerAssets(); // Register the custom assets of the question template, if needed
$oRenderer = $oQuestion->getRenderererObject($ia);
$values = $oRenderer->render();
if (isset($values)) {
//Break apart $values array returned from switch
//$answer is the html code to be printed
//$inputnames is an array containing the names of each input field
list($answer, $inputnames) = $values;
}
$question_text['mandatory'] = $ia[6];
//If this question is mandatory but wasn't answered in the last page
//add a message HIGHLIGHTING the question
$mandatory_msg = (($_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['step'] != $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['maxstep']) || ($_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['step'] == $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['prevstep'])) ? mandatory_message($ia) : '';
$qtitle .= $mandatory_msg;
$question_text['man_message'] = $mandatory_msg;
//show or hide tip
$_vshow = false;
if(isset($aQuestionAttributes['hide_tip'])){
$_vshow = $aQuestionAttributes['hide_tip'] == 0; //hide_tip=0 means: show the tip
}
list($validation_msg, $isValid) = validation_message($ia, $_vshow);
$qtitle .= $validation_msg;
$question_text['valid_message'] = $validation_msg;
if (($_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['step'] != $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['maxstep']) || ($_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['step'] == $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['prevstep'])) {
$file_validation_msg = file_validation_message($ia);
} else {
$file_validation_msg = '';
$isValid = true; // don't want to show any validation messages.
}
$qtitle .= $ia[4] == "|" ? $file_validation_msg : "";
$question_text['file_valid_message'] = $ia[4] == "|" ? $file_validation_msg : "";
if (!empty($question_text['man_message']) || !$isValid || !empty($question_text['file_valid_message'])) {
$question_text['input_error_class'] = ' input-error'; // provides a class to style question wrapper differently if there is some kind of user input error;
}
// =====================================================
// START: legacy question_start.pstpl code
// The following section adds to the templating system by allowing
// templaters to control where the various parts of the question text
// are put.
$sTemplate = isset($thissurvey['template']) ? $thissurvey['template'] : null;
if (is_file('templates/' . $sTemplate . '/question_start.pstpl')) {
$replace = [];
$find = [];
foreach ($question_text as $key => $value) {
$find[] = '{QUESTION_' . strtoupper($key) . '}'; // Match key words from template
$replace[] = $value; // substitue text
};
if (!defined('QUESTION_START')) {
define('QUESTION_START', file_get_contents(getTemplatePath($thissurvey['template']) . '/question_start.pstpl'));
};
$qtitle_custom = str_replace($find, $replace, QUESTION_START);
$c = 1;
// START: <EMBED> work-around step 1
$qtitle_custom = preg_replace('/(<embed[^>]+>)(<\/embed>)/i', '\1NOT_EMPTY\2', $qtitle_custom);
// END <EMBED> work-around step 1
while ($c > 0) {
// This recursively strips any empty tags to minimise rendering bugs.
$oldtitle = $qtitle_custom;
$qtitle_custom = preg_replace('/<([^ >]+)[^>]*>[\r\n\t ]*<\/\1>[\r\n\t ]*/isU', '', $qtitle_custom, -1); // I removed the $count param because it is PHP 5.1 only.
$c = ($qtitle_custom != $oldtitle) ? 1 : 0;
};
// START <EMBED> work-around step 2
$qtitle_custom = preg_replace('/(<embed[^>]+>)NOT_EMPTY(<\/embed>)/i', '\1\2', $qtitle_custom);
// END <EMBED> work-around step 2
while ($c > 0) {
// This recursively strips any empty tags to minimise rendering bugs.
$oldtitle = $qtitle_custom;
$qtitle_custom = preg_replace('/(<br(?: ?\/)?>(?:&nbsp;|\r\n|\n\r|\r|\n| )*)+$/i', '', $qtitle_custom, -1); // I removed the $count param because it is PHP 5.1 only.
$c = ($qtitle_custom != $oldtitle) ? 1 : 0;
};
$question_text['all'] = $qtitle_custom;
} else {
$question_text['all'] = $qtitle;
};
// END: legacy question_start.pstpl code
//===================================================================
$qtitle = $question_text;
// =====================================================
$qanda = array($qtitle, $answer, 'help', $display, $qid, $ia[2], $ia[5], $ia[1]);
if (EmCacheHelper::cacheQanda($ia, $_SESSION['survey_' . $thissurvey['sid']])) {
EmCacheHelper::set($cacheKey, [$qanda, $inputnames]);
}
//New Return
return array($qanda, $inputnames);
}
function mandatory_message($ia)
{
$qinfo = LimeExpressionManager::GetQuestionStatus($ia[0]);
$qinfoValue = ($qinfo['mandViolation']) ? $qinfo['mandTip'] : "";
return $qinfoValue;
}
/**
*
* @param array $ia
* @param boolean $show - true if should initially be visible
* @return array
*/
function validation_message($ia, $show)
{
$qinfo = LimeExpressionManager::GetQuestionStatus($ia[0]);
$class = (!$show) ? ' hide-tip' : '';
$id = "vmsg_" . $ia[0];
$message = $qinfo['validTip'];
if ($message != "") {
$tip = doRender('/survey/questions/question_help/help', array('message' => $message, 'classes' => $class, 'id' => $id), true);
} else {
$tip = "";
}
$isValid = $qinfo['valid'];
return array($tip, $isValid);
}
// TMSW Validation -> EM
function file_validation_message($ia)
{
global $filenotvalidated;
$qtitle = "";
if (isset($filenotvalidated) && is_array($filenotvalidated) && $ia[4] == "|") {
foreach ($filenotvalidated as $k => $v) {
if ($ia[1] == $k || strpos($k, "_") && $ia[1] == substr(0, strpos($k, "_") - 1)) {
$message = gT($filenotvalidated[$k]);
$qtitle .= doRender('/survey/questions/question_help/error', array('message' => $message, 'classes' => ''), true);
}
}
}
return $qtitle;
}
// TMSW Validation -> EM
function mandatory_popup($ia, $notanswered = null)
{
//This sets the mandatory popup message to show if required
//Called from question.php, group.php or survey.php
if ($notanswered === null) {
unset($notanswered);
}
if (isset($notanswered) && is_array($notanswered)) {
//ADD WARNINGS TO QUESTIONS IF THEY WERE MANDATORY BUT NOT ANSWERED
global $mandatorypopup, $popup;
//POPUP WARNING
if (!isset($mandatorypopup) && ($ia[4] == 'T' || $ia[4] == 'S' || $ia[4] == 'U')) {
$popup = gT("You cannot proceed until you enter some text for one or more questions.");
$mandatorypopup = "Y";
} else {
$popup = gT("One or more mandatory questions have not been answered. You cannot proceed until these have been completed.");
$mandatorypopup = "Y";
}
return array($mandatorypopup, $popup);
} else {
return false;
}
}
// TMSW Validation -> EM
function validation_popup($ia, $notvalidated = null)
{
//This sets the validation popup message to show if required
//Called from question.php, group.php or survey.php
if ($notvalidated === null) {
unset($notvalidated);
}
if (isset($notvalidated) && is_array($notvalidated)) {
//ADD WARNINGS TO QUESTIONS IF THEY ARE NOT VALID
global $validationpopup, $vpopup;
//POPUP WARNING
if (!isset($validationpopup)) {
$vpopup = gT("One or more questions have not been answered in a valid manner. You cannot proceed until these answers are valid.");
$validationpopup = "Y";
}
return array($validationpopup, $vpopup);
} else {
return false;
}
}
// TMSW Validation -> EM
/**
* @param boolean $filenotvalidated
*/
function file_validation_popup($ia, $filenotvalidated = null)
{
if ($filenotvalidated === null) {
unset($filenotvalidated);
}
if (isset($filenotvalidated) && is_array($filenotvalidated)) {
global $filevalidationpopup, $fpopup;
if (!isset($filevalidationpopup)) {
$fpopup = gT("One or more file have either exceeded the filesize/are not in the right format or the minimum number of required files have not been uploaded. You cannot proceed until these have been completed");
$filevalidationpopup = "Y";
}
return array($filevalidationpopup, $fpopup);
} else {
return false;
}
}
/**
* @param string $disable
* @return string
*/
function return_timer_script($aQuestionAttributes, $ia, $disable = null)
{
global $thissurvey;
Yii::app()->getClientScript()->registerScriptFile(Yii::app()->getConfig("generalscripts") . 'coookies.js', CClientScript::POS_BEGIN);
Yii::app()->getClientScript()->registerPackage('timer-addition');
$langTimer = array(
'hours' => gT("hours"),
'mins' => gT("mins"),
'seconds' => gT("seconds"),
);
/* Registering script : don't go to EM : no need usage of ls_json_encode */
App()->getClientScript()->registerScript("LSVarLangTimer", "LSvar.lang.timer=" . json_encode($langTimer) . ";", CClientScript::POS_BEGIN);
/**
* The following lines cover for previewing questions, because no $_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['fieldarray'] exists.
* This just stops error messages occuring
*/
if (!isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['fieldarray'])) {
$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['fieldarray'] = [];
}
/* End */
//Used to count how many timer questions in a page, and ensure scripts only load once
$thissurvey['timercount'] = (isset($thissurvey['timercount'])) ? $thissurvey['timercount']++ : 1;
$time_limit = $aQuestionAttributes['time_limit'];
$disable_next = trim($aQuestionAttributes['time_limit_disable_next']) != '' ? $aQuestionAttributes['time_limit_disable_next'] : 0;
$disable_prev = trim($aQuestionAttributes['time_limit_disable_prev']) != '' ? $aQuestionAttributes['time_limit_disable_prev'] : 0;
$time_limit_action = trim($aQuestionAttributes['time_limit_action']) != '' ? $aQuestionAttributes['time_limit_action'] : 1;
$time_limit_message = trim($aQuestionAttributes['time_limit_message'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '' ? htmlspecialchars($aQuestionAttributes['time_limit_message'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']], ENT_QUOTES) : gT("Your time to answer this question has expired");
$time_limit_warning = trim($aQuestionAttributes['time_limit_warning']) != '' ? $aQuestionAttributes['time_limit_warning'] : 0;
$time_limit_warning_2 = trim($aQuestionAttributes['time_limit_warning_2']) != '' ? $aQuestionAttributes['time_limit_warning_2'] : 0;
$time_limit_countdown_message = trim($aQuestionAttributes['time_limit_countdown_message'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '' ? htmlspecialchars($aQuestionAttributes['time_limit_countdown_message'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']], ENT_QUOTES) : gT("Time remaining");
$time_limit_warning_message = trim($aQuestionAttributes['time_limit_warning_message'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '' ? htmlspecialchars($aQuestionAttributes['time_limit_warning_message'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']], ENT_QUOTES) : gT("Your time to answer this question has nearly expired. You have {TIME} remaining.");
//Render timer
$timer_html = doRender('/survey/questions/question_timer/timer', array('iQid' => $ia[0], 'sWarnId' => ''), true);
$time_limit_warning_message = str_replace("{TIME}", $timer_html, $time_limit_warning_message);
$time_limit_warning_display_time = trim($aQuestionAttributes['time_limit_warning_display_time']) != '' ? $aQuestionAttributes['time_limit_warning_display_time'] + 1 : 0;
$time_limit_warning_2_message = trim($aQuestionAttributes['time_limit_warning_2_message'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '' ? htmlspecialchars($aQuestionAttributes['time_limit_warning_2_message'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']], ENT_QUOTES) : gT("Your time to answer this question has nearly expired. You have {TIME} remaining.");
//Render timer 2
$timer_html = doRender('/survey/questions/question_timer/timer', array('iQid' => $ia[0], 'sWarnId' => '_Warning_2'), true);
$time_limit_message_delay = trim($aQuestionAttributes['time_limit_message_delay']) != '' ? $aQuestionAttributes['time_limit_message_delay'] * 1000 : 1000;
$time_limit_warning_2_message = str_replace("{TIME}", $timer_html, $time_limit_warning_2_message);
$time_limit_warning_2_display_time = trim($aQuestionAttributes['time_limit_warning_2_display_time']) != '' ? $aQuestionAttributes['time_limit_warning_2_display_time'] + 1 : 0;
$time_limit_message_style = trim($aQuestionAttributes['time_limit_message_style']) != '' ? $aQuestionAttributes['time_limit_message_style'] : "";
$time_limit_message_class = "hidden ls-timer-content ls-timer-message ls-no-js-hidden";
$time_limit_warning_style = trim($aQuestionAttributes['time_limit_warning_style']) != '' ? $aQuestionAttributes['time_limit_warning_style'] : "";
$time_limit_warning_class = "hidden ls-timer-content ls-timer-warning ls-no-js-hidden";
$time_limit_warning_2_style = trim($aQuestionAttributes['time_limit_warning_2_style']) != '' ? $aQuestionAttributes['time_limit_warning_2_style'] : "";
$time_limit_warning_2_class = "hidden ls-timer-content ls-timer-warning2 ls-no-js-hidden";
$time_limit_timer_style = trim($aQuestionAttributes['time_limit_timer_style']) != '' ? $aQuestionAttributes['time_limit_timer_style'] : "position: relative;";
$time_limit_timer_class = "ls-timer-content ls-timer-countdown ls-no-js-hidden";
$timersessionname = "timer_question_" . $ia[0];
if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$timersessionname])) {
$time_limit = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$timersessionname];
}
$output = doRender('/survey/questions/question_timer/timer_header', array('timersessionname' => $timersessionname, 'time_limit' => $time_limit), true);
if ($thissurvey['timercount'] < 2) {
$iAction = '';
if (isset($thissurvey['format']) && $thissurvey['format'] == "G") {
global $gid;
$qcount = 0;
foreach ($_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['fieldarray'] as $ib) {
if ($ib[5] == $gid) {
$qcount++;
}
}
// Override all other options and just allow freezing, survey is presented in group by group mode
// Why don't allow submit in Group by group mode, this surely broke 'mandatory' question, but this remove a great system for user (Denis 140224)
if ($qcount > 1) {
$iAction = '3';
}
}
/* If this is a preview, don't allow the page to submit/reload */
$thisaction = returnglobal('action');
if ($thisaction == "previewquestion" || $thisaction == "previewgroup") {
$iAction = '3';
}
$output .= doRender('/survey/questions/question_timer/timer_javascript', array(
'timersessionname' => $timersessionname,
'time_limit' => $time_limit,
'iAction' => $iAction,
'disable_next' => $disable_next,
'disable_prev' => $disable_prev,
'time_limit_countdown_message' => $time_limit_countdown_message,
'time_limit_message_delay' => $time_limit_message_delay
), true);
}
$output .= doRender(
'/survey/questions/question_timer/timer_content',
array(
'iQid' => $ia[0],
'time_limit_message_style' => $time_limit_message_style,
'time_limit_message_class' => $time_limit_message_class,
'time_limit_message' => $time_limit_message,
'time_limit_warning_style' => $time_limit_warning_style,
'time_limit_warning_class' => $time_limit_warning_class,
'time_limit_warning_message' => $time_limit_warning_message,
'time_limit_warning_2_style' => $time_limit_warning_2_style,
'time_limit_warning_2_class' => $time_limit_warning_2_class,
'time_limit_warning_2_message' => $time_limit_warning_2_message,
'time_limit_timer_style' => $time_limit_timer_style,
'time_limit_timer_class' => $time_limit_timer_class,
),
true
);
$output .= doRender(
'/survey/questions/question_timer/timer_footer',
array(
'iQid' => $ia[0],
'iSid' => Yii::app()->getConfig('surveyID'),
'time_limit' => $time_limit,
'time_limit_action' => $time_limit_action,
'time_limit_warning' => $time_limit_warning,
'time_limit_warning_2' => $time_limit_warning_2,
'time_limit_warning_display_time' => $time_limit_warning_display_time,
'time_limit_warning_2_display_time' => $time_limit_warning_2_display_time,
'disable' => $disable,
),
true
);
return $output;
}
/**
* Return class of a specific row (hidden by relevance)
* @param int $surveyId actual survey id
* @param string $baseName the base name of the question
* @param string $name The name of the question/row to test
* @param array $aQuestionAttributes the question attributes
* @return string
*/
function currentRelevecanceClass($surveyId, $baseName, $name, $aQuestionAttributes)
{
$relevanceStatus = !isset($_SESSION["survey_{$surveyId}"]['relevanceStatus'][$name]) || $_SESSION["survey_{$surveyId}"]['relevanceStatus'][$name];
if ($relevanceStatus) {
return "";
}
$sExcludeAllOther = isset($aQuestionAttributes['exclude_all_others']) ? trim($aQuestionAttributes['exclude_all_others']) : '';
/* EM don't set difference between relevance in session, if exclude_all_others is set , just ls-disabled */
if ($sExcludeAllOther) {
foreach (explode(';', $sExcludeAllOther) as $sExclude) {
$sExclude = $baseName . $sExclude;
if (
(!isset($_SESSION["survey_{$surveyId}"]['relevanceStatus'][$sExclude]) || $_SESSION["survey_{$surveyId}"]['relevanceStatus'][$sExclude])
&& (isset($_SESSION["survey_{$surveyId}"][$sExclude]) && $_SESSION["survey_{$surveyId}"][$sExclude] == "Y")
) {
return "ls-irrelevant ls-disabled";
}
}
}
$filterStyle = !empty($aQuestionAttributes['array_filter_style']); // Currently null/0/false=> hidden , 1 : disabled
if ($filterStyle) {
return "ls-irrelevant ls-disabled";
}
return "ls-irrelevant ls-hidden";
}
/**
* @param string $rowname
*/
function return_display_style($ia, $aQuestionAttributes, $thissurvey, $rowname)
{
/* Disabled actually : no inline style */
return "";
}
/**
* @param string $rowname
* @param string $valuename
*/
function return_array_filter_strings($ia, $aQuestionAttributes, $thissurvey, $ansrow, $rowname, $trbc, $valuename, $method = "tbody", $class = null)
{
$htmltbody2 = "\n\n\t<$method id='javatbd$rowname'";
$htmltbody2 .= ($class !== null) ? " class='$class'" : "";
$surveyid = $thissurvey['sid'];
if (isset($_SESSION["survey_{$surveyid}"]['relevanceStatus'][$rowname]) && !$_SESSION["survey_{$surveyid}"]['relevanceStatus'][$rowname]) {
// If using exclude_all_others, then need to know whether irrelevant rows should be hidden or disabled
if (isset($aQuestionAttributes['exclude_all_others'])) {
$disableit = false;
foreach (explode(';', trim($aQuestionAttributes['exclude_all_others'])) as $eo) {
$eorow = $ia[1] . $eo;
if (
(!isset($_SESSION["survey_{$surveyid}"]['relevanceStatus'][$eorow]) || $_SESSION["survey_{$surveyid}"]['relevanceStatus'][$eorow])
&& (isset($_SESSION[$eorow]) && $_SESSION[$eorow] == "Y")
) {
$disableit = true;
}
}
if ($disableit) {
$htmltbody2 .= " disabled='disabled'";
} else {
if (!isset($aQuestionAttributes['array_filter_style']) || $aQuestionAttributes['array_filter_style'] == '0') {
$htmltbody2 .= " style='display: none'";
} else {
$htmltbody2 .= " disabled='disabled'";
}
}
} else {
if (!isset($aQuestionAttributes['array_filter_style']) || $aQuestionAttributes['array_filter_style'] == '0') {
$htmltbody2 .= " style='display: none'";
} else {
$htmltbody2 .= " disabled='disabled'";
}
}
}
$htmltbody2 .= ">\n";
return array($htmltbody2, "");
}
/**
* @param string $sUseKeyPad
* @return string
*/
function testKeypad($sUseKeyPad)
{
if ($sUseKeyPad == 'Y') {
includeKeypad();
$kpclass = "text-keypad";
} else {
$kpclass = "";
}
return $kpclass;
}
// ==================================================================
// QUESTION METHODS =================================================
// ---------------------------------------------------------------
function do_language($ia)
{
$checkconditionFunction = "checkconditions";
$answerlangs = Survey::model()->findByPk(Yii::app()->getConfig('surveyID'))->additionalLanguages;
$answerlangs[] = Survey::model()->findByPk(Yii::app()->getConfig('surveyID'))->language;
$sLang = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'];
$coreClass = "ls-answers answer-item dropdow-item langage-item";
$inputnames = [];
if (!in_array($sLang, $answerlangs)) {
$sLang = Survey::model()->findByPk(Yii::app()->getConfig('surveyID'))->language;
}
$inputnames[] = $ia[1];
$languageData = array(
'name' => $ia[1],
'basename' => $ia[1],
'checkconditionFunction' => $checkconditionFunction . '(this.value, this.name, this.type)',
'answerlangs' => $answerlangs,
'sLang' => $sLang,
'coreClass' => $coreClass,
);
$answer = doRender('/survey/questions/answer/language/answer', $languageData, true);
return array($answer, $inputnames);
}
// ---------------------------------------------------------------
// TMSW TODO - Can remove DB query by passing in answer list from EM
function do_list_dropdown($ia)
{
//// Init variables
$inputnames = [];
// General variables
$checkconditionFunction = "checkconditions";
// Question attribute variables
$aQuestionAttributes = QuestionAttribute::model()->getQuestionAttributes($ia[0]);
$iSurveyId = Yii::app()->getConfig('surveyID'); // survey id
$sSurveyLang = $_SESSION['survey_' . $iSurveyId]['s_lang']; // survey language
$othertext = (trim($aQuestionAttributes['other_replace_text'][$sSurveyLang]) != '') ? $aQuestionAttributes['other_replace_text'][$sSurveyLang] : gT('Other:'); // text for 'other'
$optCategorySeparator = (trim($aQuestionAttributes['category_separator']) != '') ? $aQuestionAttributes['category_separator'] : '';
$coreClass = "ls-answers answer-item dropdown-item";
if ($optCategorySeparator == '') {
unset($optCategorySeparator);
}
//// Retrieving datas
// Getting question
$oQuestion = Question::model()->findByPk(array('qid' => $ia[0], 'language' => $sSurveyLang));
$other = $oQuestion->other;
// Getting answers
$ansresult = $oQuestion->getOrderedAnswers($aQuestionAttributes['random_order'], $aQuestionAttributes['alphasort']);
$dropdownSize = null;
if (isset($aQuestionAttributes['dropdown_size']) && $aQuestionAttributes['dropdown_size'] > 0) {
$_height = sanitize_int($aQuestionAttributes['dropdown_size']);
$_maxHeight = count($ansresult);
if ((!is_null($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]]) || $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]] === '') && ($ia[6] != 'Y' && $ia[6] != 'S') && SHOW_NO_ANSWER == 1) {
++$_maxHeight; // for No Answer
}
if (isset($other) && $other == 'Y') {
++$_maxHeight; // for Other
}
if (is_null($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]])) {
++$_maxHeight; // for 'Please choose:'
}
if ($_height > $_maxHeight) {
$_height = $_maxHeight;
}
$dropdownSize = $_height;
}
$prefixStyle = 0;
if (isset($aQuestionAttributes['dropdown_prefix'])) {
$prefixStyle = sanitize_int($aQuestionAttributes['dropdown_prefix']);
}
$_rowNum = 0;
$_prefix = '';
$value = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]];
$sOptions = '';
// If no answer previously selected
if (is_null($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]]) || $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]] === '') {
$sOptions .= doRender('/survey/questions/answer/list_dropdown/rows/option', array(
'name' => $ia[1],
'value' => '',
'opt_select' => ($dropdownSize) ? SELECTED : "", /* needed width size, not for single first one */
'answer' => gT('Please choose...')
), true);
}
if (!isset($optCategorySeparator)) {
foreach ($ansresult as $ansrow) {
$opt_select = '';
if ($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]] == $ansrow['code']) {
$opt_select = SELECTED;
}
if ($prefixStyle == 1) {
$_prefix = ++$_rowNum . ') ';
}
// ==> rows
$sOptions .= doRender('/survey/questions/answer/list_dropdown/rows/option', array(
'name' => $ia[1],
'value' => $ansrow['code'],
'opt_select' => $opt_select,
'answer' => $_prefix . $ansrow->answerl10ns[$sSurveyLang]->answer,
), true);
}
} else {
$defaultopts = [];
$optgroups = [];
foreach ($ansresult as $ansrow) {
// Let's sort answers in an array indexed by subcategories
@list($categorytext, $answertext) = explode($optCategorySeparator, $ansrow->answerl10ns[$sSurveyLang]->answer);
// The blank category is left at the end outside optgroups
if ($categorytext == '') {
$defaultopts[] = array('code' => $ansrow['code'], 'answer' => $answertext);
} else {
$optgroups[$categorytext][] = array('code' => $ansrow['code'], 'answer' => $answertext);
}
}
foreach ($optgroups as $categoryname => $optionlistarray) {
$sOptGroupOptions = '';
foreach ($optionlistarray as $optionarray) {
if ($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]] == $optionarray['code']) {
$opt_select = SELECTED;
} else {
$opt_select = '';
}
// ==> rows
$sOptGroupOptions .= doRender('/survey/questions/answer/list_dropdown/rows/option', array(
'name' => $ia[1],
'value' => $optionarray['code'],
'opt_select' => $opt_select,
'answer' => flattenText($optionarray['answer'])
), true);
}
$sOptions .= doRender('/survey/questions/answer/list_dropdown/rows/optgroup', array(
'categoryname' => flattenText($categoryname),
'sOptGroupOptions' => $sOptGroupOptions,
), true);
}
foreach ($defaultopts as $optionarray) {
if ($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]] == $optionarray['code']) {
$opt_select = SELECTED;
} else {
$opt_select = '';
}
// ==> rows
$sOptions .= doRender('/survey/questions/answer/list_dropdown/rows/option', array(
'name' => $ia[1],
'value' => $optionarray['code'],
'opt_select' => $opt_select,
'answer' => flattenText($optionarray['answer'])
), true);
}
}
if (isset($other) && $other == 'Y') {
if ($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]] == '-oth-') {
$opt_select = SELECTED;
} else {
$opt_select = '';
}
if ($prefixStyle == 1) {
$_prefix = ++$_rowNum . ') ';
}
$sOptions .= doRender('/survey/questions/answer/list_dropdown/rows/option', array(
'name' => $ia[1],
'classes' => 'other-item',
'value' => '-oth-',
'opt_select' => $opt_select,
'answer' => flattenText($_prefix . $othertext)
), true);
}
if (!(is_null($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]]) || $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]] === "") && ($ia[6] != 'Y' && $ia[6] != 'S') && SHOW_NO_ANSWER == 1) {
if ($prefixStyle == 1) {
$_prefix = ++$_rowNum . ') ';
}
$optionData = array(
'name' => $ia[1],
'classes' => 'noanswer-item',
'value' => '',
'opt_select' => '', // Never selected
'answer' => $_prefix . gT('No answer')
);
// ==> rows
$sOptions .= doRender('/survey/questions/answer/list_dropdown/rows/option', $optionData, true);
}
$sOther = '';
if (isset($other) && $other == 'Y') {
$aData = [];
$aData['name'] = $ia[1];
$aData['checkconditionFunction'] = $checkconditionFunction;
$aData['display'] = ($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]] != '-oth-') ? 'display: none;' : '';
$aData['label'] = $othertext;
$thisfieldname = "$ia[1]other";
$aData['value'] = (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$thisfieldname])) ? htmlspecialchars($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$thisfieldname], ENT_QUOTES) : '';
// ==> other
$sOther .= doRender('/survey/questions/answer/list_dropdown/rows/othertext', $aData, true);
$inputnames[] = $ia[1] . 'other';
}
// ==> answer
$answer = doRender('/survey/questions/answer/list_dropdown/answer', array(
'sOptions' => $sOptions,
'sOther' => $sOther,
'name' => $ia[1],
'basename' => $ia[1],
'dropdownSize' => $dropdownSize,
'checkconditionFunction' => $checkconditionFunction,
'value' => $value,
'coreClass' => $coreClass
), true);
$inputnames[] = $ia[1];
//Time Limit Code
if (trim($aQuestionAttributes['time_limit']) != '') {
$answer .= return_timer_script($aQuestionAttributes, $ia);
}
//End Time Limit Code
return array($answer, $inputnames);
}
// ---------------------------------------------------------------
// TMSW TODO - Can remove DB query by passing in answer list from EM
function do_list_radio($ia)
{
//// Init variables
// General variables
global $thissurvey;
$kpclass = testKeypad($thissurvey['nokeyboard']); // Virtual keyboard (probably obsolete today)
$checkconditionFunction = "checkconditions"; // name of the function to check condition TODO : check is used more than once
$iSurveyId = Yii::app()->getConfig('surveyID'); // survey id
$sSurveyLang = $_SESSION['survey_' . $iSurveyId]['s_lang']; // survey language
$inputnames = [];
$coreClass = "ls-answers answers-list radio-list";
// Question attribute variables
$aQuestionAttributes = QuestionAttribute::model()->getQuestionAttributes($ia[0]);
$othertext = (trim($aQuestionAttributes['other_replace_text'][$sSurveyLang]) != '') ? $aQuestionAttributes['other_replace_text'][$sSurveyLang] : gT('Other:'); // text for 'other'
$iNbCols = $aQuestionAttributes['display_columns']; // number of columns
$sTimer = (trim($aQuestionAttributes['time_limit']) != '') ? return_timer_script($aQuestionAttributes, $ia) : ''; //Time Limit
//// Retrieving datas
// Getting question
$oQuestion = Question::model()->findByPk(array('qid' => $ia[0], 'language' => $sSurveyLang));
$other = $oQuestion->other;
// Getting answers
$ansresult = $oQuestion->getOrderedAnswers($aQuestionAttributes['random_order'], $aQuestionAttributes['alphasort']);
$anscount = count($ansresult);
$anscount = ($other == 'Y') ? $anscount + 1 : $anscount; //COUNT OTHER AS AN ANSWER FOR MANDATORY CHECKING!
$anscount = (($ia[6] != 'Y' && $ia[6] != 'S') && SHOW_NO_ANSWER == 1) ? $anscount + 1 : $anscount; //Count up if "No answer" is showing
//// Columns containing answer rows, set by user in question attribute
/// TODO : move to a dedicated function
// setting variables
$iRowCount = 0;
$isOpen = false; // Is a column opened
if ($iNbCols > 1) {
// Add a class on the wrapper
$coreClass .= " multiple-list nbcol-{$iNbCols}";
// First we calculate the width of each column
// Max number of column is 12 http://getbootstrap.com/css/#grid
$iColumnWidth = round(12 / $iNbCols);
$iColumnWidth = ($iColumnWidth >= 1) ? $iColumnWidth : 1;
$iColumnWidth = ($iColumnWidth <= 12) ? $iColumnWidth : 12;
// Then, we calculate how many answer rows in each column
$iMaxRowsByColumn = ceil($anscount / $iNbCols);
} else {
$iColumnWidth = 12;
$iMaxRowsByColumn = $anscount + 3; // No max : anscount + no answer + other + 1 by security
}
// Get array_filter stuff
$i = 0;
$sRows = '';
foreach ($ansresult as $key => $ansrow) {
$i++; // general count of loop, to check if the item is the last one for column process. Never reset.
$iRowCount++; // counter of number of row by column. Is reset to zero each time a column is full.
$myfname = $ia[1] . $ansrow['code'];
$checkedState = '';
if ($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]] == $ansrow['code']) {
$checkedState = 'CHECKED';
}
//list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $aQuestionAttributes, $thissurvey, $ansrow, $myfname, '', $myfname, "div","form-group answer-item radio-item");
/* Check for array_filter */
$sDisplayStyle = return_display_style($ia, $aQuestionAttributes, $thissurvey, $myfname);
////
// Open Column
// The column is opened if user set more than one column in question attribute
// and if this is the first answer row, or if the column has been closed and the row count reset before.
if ($iRowCount == 1) {
$sRows .= doRender('/survey/questions/answer/listradio/columns/column_header', array('iColumnWidth' => $iColumnWidth), true);
$isOpen = true; // If a column is not closed, it will be closed at the end of the process
}
////
// Insert row
// Display the answer row
$sRows .= doRender('/survey/questions/answer/listradio/rows/answer_row', array(
'sDisplayStyle' => $sDisplayStyle,
'name' => $ia[1],
'code' => $ansrow['code'],
'answer' => $ansrow->answerl10ns[$sSurveyLang]->answer,
'checkedState' => $checkedState,
'myfname' => $myfname,
'i' => $i
), true);
////
// Close column
// The column is closed if the user set more than one column in question attribute
// and if the max answer rows by column is reached.
// If max answer rows by column is not reached while there is no more answer,
// the column will remain opened, and it will be closed by 'other' answer row if set or at the end of the process
if ($iRowCount == $iMaxRowsByColumn) {
$last = ($i == $anscount) ? true : false; // If this loop count equal to the number of answers, then this answer is the last one.
$sRows .= doRender('/survey/questions/answer/listradio/columns/column_footer', array('last' => $last), true);
$iRowCount = 0;
$isOpen = false;
}
}
if (isset($other) && $other == 'Y') {
$iRowCount++;
$i++;
$sSeparator = getRadixPointData($thissurvey['surveyls_numberformat']);
$sSeparator = $sSeparator['separator'];
if ($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]] == '-oth-') {
$checkedState = CHECKED;
} else {
$checkedState = '';
}
$myfname = $thisfieldname = $ia[1] . 'other';
if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$thisfieldname])) {
$dispVal = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$thisfieldname];
if ($aQuestionAttributes['other_numbers_only'] == 1) {
$dispVal = str_replace('.', $sSeparator, $dispVal);
}
$answer_other = ' value="' . htmlspecialchars($dispVal, ENT_QUOTES) . '"';
} else {
$answer_other = ' value=""';
}
////
// Open Column
// The column is opened if user set more than one column in question attribute
// and if this is the first answer row (should never happen for 'other'),
// or if the column has been closed and the row count reset before.
if ($iRowCount == 1) {
$sRows .= doRender('/survey/questions/answer/listradio/columns/column_header', array('iColumnWidth' => $iColumnWidth, 'first' => false), true);
}
$sDisplayStyle = return_display_style($ia, $aQuestionAttributes, $thissurvey, $myfname);
////
// Insert row
// Display the answer row
$sRows .= doRender('/survey/questions/answer/listradio/rows/answer_row_other', array(
'name' => $ia[1],
'answer_other' => $answer_other,
'myfname' => $myfname,
'sDisplayStyle' => $sDisplayStyle,
'othertext' => $othertext,
'checkedState' => $checkedState,
'kpclass' => $kpclass,
'checkconditionFunction' => $checkconditionFunction,
'numbers_only' => ($aQuestionAttributes['other_numbers_only'] == 1),
), true);
$inputnames[] = $thisfieldname;
////
// Close column
// The column is closed if the user set more than one column in question attribute
// We can't be sure it's the last one because of 'no answer' item
if ($iRowCount == $iMaxRowsByColumn) {
$sRows .= doRender('/survey/questions/answer/listradio/columns/column_footer', [], true);
$iRowCount = 0;
$isOpen = false;
}
}
if (($ia[6] != 'Y' && $ia[6] != 'S') && SHOW_NO_ANSWER == 1) {
$iRowCount++;
if ((!isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]]) || $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]] == '') || ($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]] == ' ')) {
$check_ans = CHECKED; //Check the "no answer" radio button if there is no answer in session.
} else {
$check_ans = '';
}
if ($iRowCount == 1) {
$sRows .= doRender('/survey/questions/answer/listradio/columns/column_header', array('iColumnWidth' => $iColumnWidth), true);
}
$sRows .= doRender('/survey/questions/answer/listradio/rows/answer_row_noanswer', array(
'name' => $ia[1],
'check_ans' => $check_ans,
'checkconditionFunction' => $checkconditionFunction,
), true);
////
// Close column
// 'No answer' is always the last answer, so it's always closing the col and the bootstrap row containing the columns
$sRows .= doRender('/survey/questions/answer/listradio/columns/column_footer', array('last' => true), true);
$isOpen = false;
}
////
// Close column
// if on column has been opened and not closed
// That can happen only when no 'other' option is set, and the maximum answer rows has not been reached in the last question
if ($isOpen) {
$sRows .= doRender('/survey/questions/answer/listradio/columns/column_footer', array('last' => true), true);
}
//END OF ITEMS
// ==> answer
$answer = doRender('/survey/questions/answer/listradio/answer', array(
'sTimer' => $sTimer,
'sRows' => $sRows,
'name' => $ia[1],
'basename' => $ia[1],
'value' => $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]],
'coreClass' => $coreClass,
), true);
$inputnames[] = $ia[1];
return array($answer, $inputnames);
}
// ---------------------------------------------------------------
// TMSW TODO - Can remove DB query by passing in answer list from EM
function do_listwithcomment($ia)
{
//// Init variables
// General variables
global $thissurvey;
$kpclass = testKeypad($thissurvey['nokeyboard']); // Virtual keyboard (probably obsolete today)
$checkconditionFunction = "checkconditions";
$iSurveyId = Yii::app()->getConfig('surveyID'); // survey id
$sSurveyLang = $_SESSION['survey_' . $iSurveyId]['s_lang']; // survey language
$maxoptionsize = 35;
$coreClass = "ls-answers";
$inputnames = [];
$aQuestionAttributes = QuestionAttribute::model()->getQuestionAttributes($ia[0]); // Question attribute variables
$oQuestion = Question::model()->findByPk(array('qid' => $ia[0], 'language' => $sSurveyLang)); // Getting question
// Getting answers
$ansresult = $oQuestion->getOrderedAnswers($aQuestionAttributes['random_order'], $aQuestionAttributes['alphasort']);
$anscount = count($ansresult);
$hint_comment = gT('Please enter your comment here');
if ($aQuestionAttributes['use_dropdown'] != 1) {
$sRows = '';
$li_classes = 'answer-item radio-item';
foreach ($ansresult as $ansrow) {
$check_ans = '';
if ($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]] == $ansrow['code']) {
$check_ans = CHECKED;
}
$itemData = array(
'li_classes' => $li_classes,
'name' => $ia[1],
'id' => 'answer' . $ia[1] . $ansrow['code'],
'value' => $ansrow['code'],
'check_ans' => $check_ans,
'checkconditionFunction' => $checkconditionFunction . '(this.value, this.name, this.type);',
'labeltext' => $ansrow->answerl10ns[$sSurveyLang]->answer,
);
$sRows .= doRender('/survey/questions/answer/list_with_comment/list/rows/answer_row', $itemData, true);
}
// ==> rows
$check_ans = '';
if (($ia[6] != 'Y' && $ia[6] != 'S') && SHOW_NO_ANSWER == 1) {
if ((!isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]]) || $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]] == '') || ($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]] == ' ')) {
$check_ans = CHECKED;
} elseif (($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]] || $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]] != '')) {
$check_ans = '';
}
$itemData = array(
'li_classes' => $li_classes . ' noanswer-item',
'name' => $ia[1],
'id' => 'answer' . $ia[1],
'value' => '',
'check_ans' => $check_ans,
'checkconditionFunction' => $checkconditionFunction . '(this.value, this.name, this.type)',
'labeltext' => gT('No answer'),
);
$sRows .= doRender('/survey/questions/answer/list_with_comment/list/rows/answer_row', $itemData, true);
}
$fname2 = $ia[1] . 'comment';
$tarows = ($anscount > 8) ? $anscount / 1.2 : 4;
$answer = doRender('/survey/questions/answer/list_with_comment/list/answer', array(
'sRows' => $sRows,
'id' => 'answer' . $ia[1] . 'comment',
'basename' => $ia[1],
'coreClass' => $coreClass,
'hint_comment' => $hint_comment,
'kpclass' => $kpclass,
'name' => $ia[1] . 'comment',
'tarows' => floor($tarows),
'has_comment_saved' => isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$fname2]) && $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$fname2],
'comment_saved' => htmlspecialchars($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$fname2]),
'java_name' => 'java' . $ia[1],
'java_id' => 'java' . $ia[1],
'java_value' => $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]]
), true);
$inputnames[] = $ia[1];
$inputnames[] = $ia[1] . 'comment';
} else {
//Dropdown list
$sOptions = '';
foreach ($ansresult as $ansrow) {
$check_ans = '';
if ($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]] == $ansrow['code']) {
$check_ans = SELECTED;
}
$itemData = array(
'value' => $ansrow['code'],
'check_ans' => $check_ans,
'option_text' => $ansrow['answer'],
);
$sOptions .= doRender('/survey/questions/answer/list_with_comment/dropdown/rows/option', $itemData, true);
if (strlen($ansrow['answer']) > $maxoptionsize) {
$maxoptionsize = strlen($ansrow['answer']);
}
}
if (($ia[6] != 'Y' && $ia[6] != 'S') && SHOW_NO_ANSWER == 1 && !is_null($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]])) {
$check_ans = "";
if (trim($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]]) == '') {
$check_ans = SELECTED;
}
$itemData = array(
'classes' => ' noanswer-item ',
'value' => '',
'check_ans' => $check_ans,
'option_text' => gT('No answer'),
);
$sOptions .= doRender('/survey/questions/answer/list_with_comment/dropdown/rows/option', $itemData, true);
}
$fname2 = $ia[1] . 'comment';
if ($anscount > 8) {
$tarows = $anscount / 1.2;
} else {
$tarows = 4;
}
if ($tarows > 15) {
$tarows = 15;
}
$maxoptionsize = $maxoptionsize * 0.72;
if ($maxoptionsize < 33) {
$maxoptionsize = 33;
}
if ($maxoptionsize > 70) {
$maxoptionsize = 70;
}
$answer = doRender('/survey/questions/answer/list_with_comment/dropdown/answer', array(
'sOptions' => $sOptions,
'name' => $ia[1],
'coreClass' => $coreClass,
'id' => 'answer' . $ia[1],
'basename' => $ia[1],
'show_noanswer' => is_null($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]]),
'label_text' => $hint_comment,
'kpclass' => $kpclass,
'tarows' => $tarows,
'maxoptionsize' => $maxoptionsize,
'comment_saved' => htmlspecialchars($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$fname2]), /* htmlspecialchars(null)=="" right ? */
'value' => $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]],
), true);
$inputnames[] = $ia[1];
$inputnames[] = $ia[1] . 'comment';
}
return array($answer, $inputnames);
}
/**
* @deprecated 4.0 Replaced by core\QuestionTypes\RankingStyle
*/
function do_ranking($ia)
{
$aQuestionAttributes = QuestionAttribute::model()->getQuestionAttributes($ia[0]);
$coreClass = "ls-answers answers-lists select-sortable-lists";
// Get answers by defined order
if ($aQuestionAttributes['random_order'] == 1) {
$sOrder = dbRandom();
} else {
$sOrder = 'sortorder';
}
$aAnswers = Answer::model()->findAll(array('order' => $sOrder, 'condition' => 'qid=:parent_qid AND scale_id=0', 'params' => array(':parent_qid' => $ia[0])));
$anscount = count($aAnswers);
$max_subquestions = intval($aQuestionAttributes['max_subquestions']) > 0 ? intval($aQuestionAttributes['max_subquestions']) : $anscount;
$max_subquestions = min($max_subquestions, $anscount); // Can not be upper than current answers #14899
if (trim($aQuestionAttributes["max_answers"]) != '') {
$max_answers = "min(" . trim($aQuestionAttributes["max_answers"]) . "," . $max_subquestions . ")";
} else {
$max_answers = $max_subquestions;
}
// Get the max number of line needed
if (ctype_digit($max_answers) && intval($max_answers) < $max_subquestions) {
$iMaxLine = $max_answers;
} else {
$iMaxLine = $max_subquestions;
}
if (trim($aQuestionAttributes["min_answers"]) != '') {
$min_answers = trim($aQuestionAttributes["min_answers"]);
} else {
$min_answers = 0;
}
$inputnames = [];
$sSelects = '';
$myfname = '';
$sSurveyLanguage = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'];
$thisvalue = "";
for ($i = 1; $i <= $iMaxLine; $i++) {
$myfname = $ia[1] . $i;
$labeltext = ($i == 1) ? gT('First choice') : sprintf(gT('Choice of rank %s'), $i);
$aItemData = [];
if (!$_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname]) {
$aItemData[] = array(
'value' => '',
'selected' => 'SELECTED',
'classes' => '',
'id' => '',
'optiontext' => gT('Please choose...'),
);
}
foreach ($aAnswers as $aAnswer) {
if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname]) && $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname] == $aAnswer['code']) {
$selected = SELECTED;
$thisvalue = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname];
} else {
$selected = '';
}
$aItemData[] = array(
'value' => $aAnswer['code'],
'selected' => $selected,
'classes' => '',
'optiontext' => $aAnswer->answerl10ns[$sSurveyLanguage]->answer
);
}
$sSelects .= doRender(
'/survey/questions/answer/ranking/rows/answer_row',
array(
'myfname' => $myfname,
'labeltext' => $labeltext,
'options' => $aItemData,
'thisvalue' => $thisvalue
),
true
);
$inputnames[] = $myfname;
}
$rankingTranslation = 'LSvar.lang.rankhelp="' . gT("Double-click or drag-and-drop items in the left list to move them to the right - your highest ranking item should be on the top right, moving through to your lowest ranking item.", 'js') . '";';
App()->getClientScript()->registerScript("rankingTranslation", $rankingTranslation, CClientScript::POS_BEGIN);
if (trim($aQuestionAttributes['choice_title'][App()->language]) != '') {
$choice_title = htmlspecialchars(trim($aQuestionAttributes['choice_title'][App()->language]), ENT_QUOTES);
} else {
$choice_title = gT("Your Choices", 'html');
}
if (trim($aQuestionAttributes['rank_title'][App()->language]) != '') {
$rank_title = htmlspecialchars(trim($aQuestionAttributes['rank_title'][App()->language]), ENT_QUOTES);
} else {
$rank_title = gT("Your Ranking", 'html');
}
$aDisplayAnswers = [];
foreach ($aAnswers as $aAnswer) {
$aDisplayAnswers[] = array_merge($aAnswer->attributes, $aAnswer->answerl10ns[$sSurveyLanguage]->attributes);
}
$answer = doRender('/survey/questions/answer/ranking/answer', array(
'coreClass' => $coreClass,
'sSelects' => $sSelects,
'thisvalue' => $thisvalue,
'answers' => $aDisplayAnswers,
'myfname' => $myfname,
'labeltext' => (isset($labeltext)) ? $labeltext : '',
'qId' => $ia[0],
'rankingName' => $ia[1],
'basename' => $ia[1],
'max_answers' => $max_answers,
'min_answers' => $min_answers,
'choice_title' => $choice_title,
'rank_title' => $rank_title,
'showpopups' => $aQuestionAttributes["showpopups"],
'samechoiceheight' => $aQuestionAttributes["samechoiceheight"],
'samelistheight' => $aQuestionAttributes["samelistheight"],
), true);
return array($answer, $inputnames);
}
// ---------------------------------------------------------------
function do_multiplechoice($ia)
{
//// Init variables
// General variables
global $thissurvey;
$kpclass = testKeypad($thissurvey['nokeyboard']); // Virtual keyboard (probably obsolete today)
$inputnames = array(); // It is used!
$checkconditionFunction = "checkconditions"; // name of the function to check condition TODO : check is used more than once
$iSurveyId = Yii::app()->getConfig('surveyID'); // survey id
$sSurveyLang = $_SESSION['survey_' . $iSurveyId]['s_lang']; // survey language
$coreClass = "ls-answers checkbox-list answers-list";
// Question attribute variables
$aQuestionAttributes = (array) QuestionAttribute::model()->getQuestionAttributes($ia[0]); // Question attributes
$othertext = (trim($aQuestionAttributes['other_replace_text'][$sSurveyLang]) != '') ? $aQuestionAttributes['other_replace_text'][$sSurveyLang] : gT('Other:'); // text for 'other'
$iNbCols = (trim($aQuestionAttributes['display_columns']) != '') ? $aQuestionAttributes['display_columns'] : 1; // number of columns
$aSeparator = getRadixPointData($thissurvey['surveyls_numberformat']);
$sSeparator = $aSeparator['separator'];
$oth_checkconditionFunction = ($aQuestionAttributes['other_numbers_only'] == 1) ? "fixnum_checkconditions" : "checkconditions";
//// Retrieving datas
// Getting question
$oQuestion = Question::model()->findByPk(array('qid' => $ia[0], 'language' => $sSurveyLang));
$other = $oQuestion->other;
// Getting answers
$aQuestions = $oQuestion->getOrderedSubQuestions($aQuestionAttributes['random_order'], $aQuestionAttributes['exclude_all_others']);
$anscount = count($aQuestions);
$anscount = ($other == 'Y') ? $anscount + 1 : $anscount; //COUNT OTHER AS AN ANSWER FOR MANDATORY CHECKING!
// First we calculate the width of each column
// Max number of column is 12 http://getbootstrap.com/css/#grid
$iColumnWidth = round(12 / $iNbCols);
$iColumnWidth = ($iColumnWidth >= 1) ? $iColumnWidth : 1;
$iColumnWidth = ($iColumnWidth <= 12) ? $iColumnWidth : 12;
$iMaxRowsByColumn = ceil($anscount / $iNbCols);
if ($iNbCols > 1) {
$coreClass .= " multiple-list nbcol-{$iNbCols}";
}
/// Generate answer rows
foreach ($aQuestions as $aQuestion) {
$myfname = $ia[1] . $aQuestion['title'];
$relevanceClass = currentRelevecanceClass($iSurveyId, $ia[1], $myfname, $aQuestionAttributes);
$checkedState = '';
/* If the question has already been ticked, check the checkbox */
if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname])) {
if ($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname] == 'Y') {
$checkedState = 'CHECKED';
}
}
$sCheckconditionFunction = $checkconditionFunction . '(this.value, this.name, this.type)';
$sValue = (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname])) ? $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname] : '';
$inputnames[] = $myfname;
////
// Insert row
// Display the answer row
$aRows[] = array(
'name' => $ia[1], // field name
'title' => $aQuestion['title'],
'question' => $aQuestion->questionl10ns[$sSurveyLang]->question,
'ansrow' => $aQuestion,
'checkedState' => $checkedState,
'sCheckconditionFunction' => $sCheckconditionFunction,
'myfname' => $myfname,
'sValue' => $sValue,
'relevanceClass' => $relevanceClass,
);
}
//==> rows
if ($other == 'Y') {
$myfname = $ia[1] . 'other';
$relevanceClass = currentRelevecanceClass($iSurveyId, $ia[1], $myfname, $aQuestionAttributes);
$checkedState = '';
// othercbox can be not display, because only input text goes to database
if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname]) && trim($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname]) != '') {
$checkedState = 'CHECKED';
}
$sValue = '';
if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname])) {
$dispVal = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname];
if ($aQuestionAttributes['other_numbers_only'] == 1) {
$dispVal = str_replace('.', $sSeparator, $dispVal);
}
$sValue .= htmlspecialchars($dispVal, ENT_QUOTES);
}
// TODO : check if $sValueHidden === $sValue
$sValueHidden = '';
if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname])) {
$dispVal = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname];
if ($aQuestionAttributes['other_numbers_only'] == 1) {
$dispVal = str_replace('.', $sSeparator, $dispVal);
}
$sValueHidden = htmlspecialchars($dispVal, ENT_QUOTES);
;
}
$inputnames[] = $myfname;
++$anscount;
////
// Insert row
// Display the answer row
$aRows[] = array(
'myfname' => $myfname,
'othertext' => $othertext,
'checkedState' => $checkedState,
'kpclass' => $kpclass,
'sValue' => $sValue,
'oth_checkconditionFunction' => $oth_checkconditionFunction,
'checkconditionFunction' => $checkconditionFunction,
'sValueHidden' => $sValueHidden,
'relevanceClass' => $relevanceClass,
'other' => true
);
}
// ==> answer
$answer = doRender('/survey/questions/answer/multiplechoice/answer', array(
'aRows' => $aRows,
'name' => $ia[1],
'basename' => $ia[1],
'anscount' => $anscount,
'iColumnWidth' => $iColumnWidth,
'iMaxRowsByColumn' => $iMaxRowsByColumn,
'iNbCols' => $iNbCols,
'coreClass' => $coreClass,
), true);
return array($answer, $inputnames);
}
function do_multiplechoice_withcomments($ia)
{
global $thissurvey;
$kpclass = testKeypad($thissurvey['nokeyboard']); // Virtual keyboard (probably obsolete today)
$inputnames = [];
$coreClass = "ls-answers answers-list checkbox-text-list";
$aQuestionAttributes = QuestionAttribute::model()->getQuestionAttributes($ia[0]);
if ($aQuestionAttributes['other_numbers_only'] == 1) {
$sSeparator = getRadixPointData($thissurvey['surveyls_numberformat']);
$sSeparator = $sSeparator['separator'];
$otherNumber = 1;
} else {
$otherNumber = 0;
$sSeparator = '.';
}
if (trim($aQuestionAttributes['other_replace_text'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '') {
$othertext = $aQuestionAttributes['other_replace_text'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']];
} else {
$othertext = gT('Other:');
}
$aQuestion = Question::model()->findByPk($ia[0]);
$sSurveyLanguage = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'];
// Get questions and answers by defined order
if ($aQuestionAttributes['random_order'] == 1) {
$sOrder = dbRandom();
} else {
$sOrder = 'question_order';
}
$aSubquestions = Question::model()->findAll(array('order' => $sOrder, 'condition' => 'parent_qid=:parent_qid', 'params' => array(':parent_qid' => $ia[0])));
$anscount = count($aSubquestions) * 2;
$fn = 1;
if ($aQuestion->other == 'Y') {
$label_width = 25;
} else {
$label_width = 0;
}
/* Find the col-sm width : if none is set : default, if one is set, set another one to be 12, if two is set : no change*/
$attributeInputContainerWidth = intval(trim($aQuestionAttributes['text_input_columns']));
if ($attributeInputContainerWidth < 1 || $attributeInputContainerWidth > 12) {
$attributeInputContainerWidth = null;
}
$attributeLabelWidth = intval(trim($aQuestionAttributes['choice_input_columns']));
if ($attributeLabelWidth < 1 || $attributeLabelWidth > 12) {
/* old system or imported */
$attributeLabelWidth = null;
}
if ($attributeInputContainerWidth === null && $attributeLabelWidth === null) {
$sInputContainerWidth = 8;
$sLabelWidth = 4;
} else {
if ($attributeInputContainerWidth !== null) {
$sInputContainerWidth = $attributeInputContainerWidth;
} elseif ($attributeLabelWidth == 12) {
$sInputContainerWidth = 12;
} else {
$sInputContainerWidth = 12 - $attributeLabelWidth;
}
if ($attributeLabelWidth !== null) {
$sLabelWidth = $attributeLabelWidth;
} elseif ($attributeInputContainerWidth == 12) {
$sLabelWidth = 12;
} else {
$sLabelWidth = 12 - $attributeInputContainerWidth;
}
}
// Size of elements depends on longest text item
$longest_question = 0;
foreach ($aSubquestions as $ansrow) {
$current_length = round((strlen($ansrow->questionl10ns[$sSurveyLanguage]->question) / 10) + 1);
$longest_question = ($longest_question > $current_length) ? $longest_question : $current_length;
}
$sRows = "";
$inputCOmmentValue = '';
$checked = '';
foreach ($aSubquestions as $ansrow) {
$myfname = $ia[1] . $ansrow['title'];
if ($label_width < strlen(trim(strip_tags($ansrow->questionl10ns[$sSurveyLanguage]->question)))) {
$label_width = strlen(trim(strip_tags($ansrow->questionl10ns[$sSurveyLanguage]->question)));
}
$myfname2 = $myfname . "comment";
/* If the question has already been ticked, check the checkbox */
$checked = '';
if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname])) {
if ($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname] == 'Y') {
$checked = CHECKED;
}
}
$javavalue = (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname])) ? $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname] : '';
$fn++;
$fn++;
$inputnames[] = $myfname;
$inputnames[] = $myfname2;
$inputCOmmentValue = htmlspecialchars($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname2], ENT_QUOTES);
$sRows .= doRender('/survey/questions/answer/multiplechoice_with_comments/rows/answer_row', array(
'kpclass' => $kpclass,
'title' => '',
'liclasses' => 'responsive-content question-item answer-item checkbox-text-item',
'name' => $myfname,
'id' => 'answer' . $myfname,
'value' => 'Y', // TODO : check if it should be the same than javavalue
'classes' => '',
'otherNumber' => $otherNumber,
'labeltext' => $ansrow->questionl10ns[$sSurveyLanguage]->question,
'javainput' => true,
'javaname' => 'java' . $myfname,
'javavalue' => $javavalue,
'checked' => $checked,
'inputCommentId' => 'answer' . $myfname2,
'commentLabelText' => gT('Make a comment on your choice here:'),
'inputCommentName' => $myfname2,
'inputCOmmentValue' => (isset($inputCOmmentValue)) ? $inputCOmmentValue : '',
'sInputContainerWidth' => $sInputContainerWidth,
'sLabelWidth' => $sLabelWidth,
), true);
}
if ($aQuestion->other == 'Y') {
$myfname = $ia[1] . 'other';
$myfname2 = $myfname . 'comment';
$anscount = $anscount + 2;
// SPAN LABEL OPTION //////////////////////////
if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname]) && $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname]) {
$dispVal = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname];
if ($aQuestionAttributes['other_numbers_only'] == 1) {
$dispVal = str_replace('.', $sSeparator, $dispVal);
}
$value = htmlspecialchars($dispVal, ENT_QUOTES);
}
if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname2])) {
$inputCOmmentValue = htmlspecialchars($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname2], ENT_QUOTES);
}
// TODO: $value is not defined for some execution paths.
if (!isset($value)) {
$value = '';
}
$sRows .= doRender('/survey/questions/answer/multiplechoice_with_comments/rows/answer_row_other', array(
'liclasses' => 'other question-item answer-item checkbox-text-item other-item',
'liid' => 'javatbd' . $myfname,
'kpclass' => $kpclass,
'title' => gT('Other'),
'name' => $myfname,
'id' => 'answer' . $myfname,
'value' => $value, // TODO : check if it should be the same than javavalue
'classes' => '',
'otherNumber' => $otherNumber,
'labeltext' => $othertext,
'inputCommentId' => 'answer' . $myfname2,
'commentLabelText' => gT('Make a comment on your choice here:'),
'inputCommentName' => $myfname2,
'inputCOmmentValue' => $inputCOmmentValue,
'checked' => $checked,
'javainput' => false,
'javaname' => '',
'javavalue' => '',
'sInputContainerWidth' => $sInputContainerWidth,
'sLabelWidth' => $sLabelWidth
), true);
$inputnames[] = $myfname;
$inputnames[] = $myfname2;
}
$answer = doRender('/survey/questions/answer/multiplechoice_with_comments/answer', array(
'sRows' => $sRows,
'coreClass' => $coreClass,
'name' => 'MULTI' . $ia[1], /* ? name is not $ia[1] */
'basename' => $ia[1],
'value' => $anscount
), true);
if ($aQuestionAttributes['commented_checkbox'] != "allways" && $aQuestionAttributes['commented_checkbox_auto']) {
Yii::app()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts') . "multiplechoice_withcomments.js", LSYii_ClientScript::POS_BEGIN);
Yii::app()->getClientScript()->registerScript(
'doMultipleChoiceWithComments' . $ia[0],
"doMultipleChoiceWithComments({$ia[0]},'{$aQuestionAttributes["commented_checkbox"]}');",
LSYii_ClientScript::POS_POSTSCRIPT
);
}
return array($answer, $inputnames);
}
// ---------------------------------------------------------------
function do_file_upload($ia)
{
global $thissurvey;
$aQuestionAttributes = QuestionAttribute::model()->getQuestionAttributes($ia[0]);
$coreClass = "ls-answers upload-item";
// Fetch question attributes
$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['fieldname'] = $ia[1];
$bPreview = Yii::app()->request->getParam('action') == "previewgroup" || Yii::app()->request->getParam('action') == "previewquestion" || $thissurvey['active'] != "Y";
if ($bPreview) {
$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['preview'] = 1;
$questgrppreview = 1; // Preview is launched from Question or group level
} elseif ($thissurvey['active'] != "Y") {
$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['preview'] = 1;
$questgrppreview = 0;
} else {
$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['preview'] = 0;
$questgrppreview = 0;
}
$scriptloc = Yii::app()->getController()->createUrl(
'uploader/index',
[
"sid" => Yii::app()->getConfig('surveyID'),
"fieldname" => $ia[1],
"qid" => $ia[0],
"preview" => $questgrppreview,
"show_title" => $aQuestionAttributes['show_title'],
"show_comment" => $aQuestionAttributes['show_comment'],
"minfiles" => $aQuestionAttributes['min_num_of_files'],
"maxfiles" => $aQuestionAttributes['max_num_of_files'],
]
);
Yii::app()->getClientScript()->registerPackage('question-file-upload');
// Modal dialog
$filecountvalue = '0';
if (array_key_exists($ia[1] . "_filecount", $_SESSION['survey_' . Yii::app()->getConfig('surveyID')])) {
$tempval = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1] . "_filecount"];
if (is_numeric($tempval)) {
$filecountvalue = $tempval;
}
}
$uploadurl = $scriptloc . "?sid=" . Yii::app()->getConfig('surveyID') . "&fieldname=" . $ia[1] . "&qid=" . $ia[0];
$uploadurl .= "&preview=" . $questgrppreview . "&show_title=" . $aQuestionAttributes['show_title'];
$uploadurl .= "&show_comment=" . $aQuestionAttributes['show_comment'];
$uploadurl .= "&minfiles=" . $aQuestionAttributes['min_num_of_files']; // TODO: Regression here? Should use LEMval(minfiles) like above
$uploadurl .= "&maxfiles=" . $aQuestionAttributes['max_num_of_files']; // Same here.
$fileuploadData = array(
'fileid' => $ia[1],
'value' => $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]],
'filecountvalue' => $filecountvalue,
'coreClass' => $coreClass,
'basename' => $ia[1],
'uploadurl' => $uploadurl,
'show_title' => $aQuestionAttributes['show_title'],
'show_comment' => $aQuestionAttributes['show_comment'],
'uploadButtonLabel' => ngT("Upload file|Upload files", $aQuestionAttributes['max_num_of_files'])
);
$answer = doRender('/survey/questions/answer/file_upload/answer', $fileuploadData, true);
$inputnames = array();
$inputnames[] = $ia[1];
$inputnames[] = $ia[1] . "_filecount";
return array($answer, $inputnames);
}
// ---------------------------------------------------------------
// TMSW TODO - Can remove DB query by passing in answer list from EM
function do_multipleshorttext($ia)
{
global $thissurvey;
$extraclass = "";
$aQuestionAttributes = QuestionAttribute::model()->getQuestionAttributes($ia[0]);
$coreClass = "ls-answers subquestion-list questions-list text-list";
if ($aQuestionAttributes['numbers_only'] == 1) {
$sSeparator = getRadixPointData($thissurvey['surveyls_numberformat']);
$sSeparator = $sSeparator['separator'];
$extraclass .= " numberonly";
$coreClass .= " number-list";
} else {
$sSeparator = '';
}
if (intval(trim($aQuestionAttributes['maximum_chars'])) > 0) {
// Only maxlength attribute, use textarea[maxlength] jquery selector for textarea
$maxlength = intval(trim($aQuestionAttributes['maximum_chars']));
$extraclass .= " ls-input-maxchars";
} else {
$maxlength = "";
}
if (ctype_digit(trim($aQuestionAttributes['input_size']))) {
$inputsize = trim($aQuestionAttributes['input_size']);
$extraclass .= " ls-input-sized";
} else {
$inputsize = null;
}
/* Find the col-sm width : if non is set : default, if one is set, set another one to be 12, if two is set : no change*/
/* Find the col-sm width : if none is set : default, if one is set, set another one to be 12, if two is set : no change*/
list($sLabelWidth, $sInputContainerWidth, $defaultWidth) = getLabelInputWidth($aQuestionAttributes['label_input_columns'], $aQuestionAttributes['text_input_columns']);
if (trim($aQuestionAttributes['prefix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '') {
$prefix = $aQuestionAttributes['prefix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']];
$extraclass .= " withprefix";
} else {
$prefix = '';
}
if (trim($aQuestionAttributes['suffix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '') {
$suffix = $aQuestionAttributes['suffix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']];
$extraclass .= " withsuffix";
} else {
$suffix = '';
}
if (trim($aQuestionAttributes['placeholder'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '') {
$placeholder = $aQuestionAttributes['placeholder'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']];
} else {
$placeholder = '';
}
$kpclass = testKeypad($thissurvey['nokeyboard']); // Virtual keyboard (probably obsolete today)
$sSurveyLanguage = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'];
// Get questions and answers by defined order
if ($aQuestionAttributes['random_order'] == 1) {
$sOrder = dbRandom();
} else {
$sOrder = 'question_order';
}
$aSubquestions = Question::model()->findAll(array('order' => $sOrder, 'condition' => 'parent_qid=:parent_qid', 'params' => array(':parent_qid' => $ia[0])));
$anscount = count($aSubquestions) * 2;
$fn = 1;
$sRows = '';
$inputnames = [];
if ($anscount != 0) {
$alert = false;
foreach ($aSubquestions as $aSubquestion) {
$myfname = $ia[1] . $aSubquestion['title'];
$sSubquestionText = ($aSubquestion->questionl10ns[$sSurveyLanguage]->question == "") ? "&nbsp;" : $aSubquestion->questionl10ns[$sSurveyLanguage]->question;
// color code missing mandatory questions red
if (($_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['step'] != $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['maxstep']) || ($_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['step'] == $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['prevstep'])) {
if (($ia[6] == 'Y' || $ia[6] == 'S') && $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname] === '') {
$alert = true;
}
}
$sDisplayStyle = return_display_style($ia, $aQuestionAttributes, $thissurvey, $myfname);
$dispVal = '';
if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname])) {
$dispVal = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname];
if ($aQuestionAttributes['numbers_only'] == 1) {
$dispVal = str_replace('.', $sSeparator, $dispVal);
}
$dispVal = htmlspecialchars($dispVal, ENT_QUOTES, 'UTF-8');
}
$numbersonly = ($aQuestionAttributes['numbers_only'] == 1);
if (trim($aQuestionAttributes['display_rows']) != '') {
$sRows .= doRender('/survey/questions/answer/multipleshorttext/rows/answer_row_textarea', array(
'alert' => $alert,
'labelname' => 'answer' . $myfname,
'maxlength' => $maxlength,
'rows' => $aQuestionAttributes['display_rows'],
'numbersonly' => $numbersonly,
'sInputContainerWidth' => $sInputContainerWidth,
'sLabelWidth' => $sLabelWidth,
'inputsize' => $inputsize,
'extraclass' => $extraclass,
'sDisplayStyle' => $sDisplayStyle,
'prefix' => $prefix,
'placeholder' => $placeholder,
'myfname' => $myfname,
'question' => $sSubquestionText,
'kpclass' => $kpclass,
'dispVal' => $dispVal,
'suffix' => $suffix,
), true);
} else {
$sRows .= doRender('/survey/questions/answer/multipleshorttext/rows/answer_row_inputtext', array(
'alert' => $alert,
'labelname' => 'answer' . $myfname,
'maxlength' => $maxlength,
'numbersonly' => $numbersonly,
'sInputContainerWidth' => $sInputContainerWidth,
'sLabelWidth' => $sLabelWidth,
'inputsize' => $inputsize,
'extraclass' => $extraclass,
'sDisplayStyle' => $sDisplayStyle,
'prefix' => $prefix,
'placeholder' => $placeholder,
'myfname' => $myfname,
'question' => $sSubquestionText,
'kpclass' => $kpclass,
'dispVal' => $dispVal,
'suffix' => $suffix,
), true);
}
$fn++;
$inputnames[] = $myfname;
}
$answer = doRender('/survey/questions/answer/multipleshorttext/answer', array(
'sRows' => $sRows,
'coreClass' => $coreClass,
'basename' => $ia[1],
), true);
} else {
$inputnames = [];
$answer = doRender('/survey/questions/answer/multipleshorttext/empty', [], true);
}
return array($answer, $inputnames);
}
/**
* @deprecated 4.?.?
* @see RenderMultipleNumerical
* @see DataSetMultipleNumerical
*/
function do_multiplenumeric($ia)
{
global $thissurvey;
$extraclass = "";
$aQuestionAttributes = QuestionAttribute::model()->getQuestionAttributes($ia[0]);
$sSeparator = getRadixPointData($thissurvey['surveyls_numberformat']);
$sSeparator = $sSeparator['separator'];
$extraclass .= " numberonly"; //Must turn on the "numbers only javascript"
$coreClass = "ls-answers subquestion-list questions-list ";
if (intval(trim($aQuestionAttributes['maximum_chars'])) > 0) {
$maxlength = intval(trim($aQuestionAttributes['maximum_chars'])); /* must be limited to 32 : -(10 number)dot(20 numbers) ! DECIMAL sql */
$extraclass .= " ls-input-maxchars";
} else {
$maxlength = 20;
}
if (ctype_digit(trim($aQuestionAttributes['input_size']))) {
$inputsize = trim($aQuestionAttributes['input_size']);
$extraclass .= " ls-input-sized";
} else {
$inputsize = null;
}
if ($aQuestionAttributes['prefix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']] != '') {
$prefix = $aQuestionAttributes['prefix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']];
$extraclass .= " withprefix";
} else {
$prefix = ''; /* slider js need it */
}
if ($aQuestionAttributes['suffix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']] != '') {
$suffix = $aQuestionAttributes['suffix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']];
$extraclass .= " withsuffix";
} else {
$suffix = ''; /* slider js need it */
}
$kpclass = testKeypad($thissurvey['nokeyboard']); // Virtual keyboard (probably obsolete today)
/* Find the col-sm width : if none is set : default, if one is set, set another one to be 12, if two is set : no change*/
list($sLabelWidth, $sInputContainerWidth, $defaultWidth) = getLabelInputWidth($aQuestionAttributes['label_input_columns'], $aQuestionAttributes['text_input_width']);
$prefixclass = "numeric";
$sliders = 0;
$slider_position = '';
$slider_default_set = false;
if ($aQuestionAttributes['slider_layout'] == 1) {
$coreClass .= " slider-list";
$slider_layout = true;
$extraclass .= " withslider";
$slider_step = trim(LimeExpressionManager::ProcessString("{{$aQuestionAttributes['slider_accuracy']}}", $ia[0], [], 1, 1, false, false, true));
$slider_step = (is_numeric($slider_step)) ? $slider_step : 1;
$slider_min = trim(LimeExpressionManager::ProcessString("{{$aQuestionAttributes['slider_min']}}", $ia[0], [], 1, 1, false, false, true));
$slider_mintext = $slider_min = (is_numeric($slider_min)) ? $slider_min : 0;
$slider_max = trim(LimeExpressionManager::ProcessString("{{$aQuestionAttributes['slider_max']}}", $ia[0], [], 1, 1, false, false, true));
$slider_maxtext = $slider_max = (is_numeric($slider_max)) ? $slider_max : 100;
$slider_default = trim(LimeExpressionManager::ProcessString("{{$aQuestionAttributes['slider_default']}}", $ia[0], [], 1, 1, false, false, true));
$slider_default = (is_numeric($slider_default)) ? $slider_default : "";
$slider_default_set = (bool) ($aQuestionAttributes['slider_default_set'] && $slider_default !== '');
$slider_orientation = (trim($aQuestionAttributes['slider_orientation']) == 0) ? 'horizontal' : 'vertical';
$slider_custom_handle = (trim($aQuestionAttributes['slider_custom_handle']));
switch (trim($aQuestionAttributes['slider_handle'])) {
case 0:
$slider_handle = 'round';
break;
case 1:
$slider_handle = 'square';
break;
case 2:
$slider_handle = 'triangle';
break;
case 3:
$slider_handle = 'custom';
break;
}
/* Put the slider init to initial state (when no click is set or when 'reset') */
if ($slider_default !== '') {
/* can be 0 */
$slider_position = $slider_default;
} elseif ($aQuestionAttributes['slider_middlestart'] == 1) {
$slider_position = intval(($slider_max + $slider_min) / 2);
}
$slider_separator = (trim($aQuestionAttributes['slider_separator']) != '') ? $aQuestionAttributes['slider_separator'] : "";
$slider_reset = ($aQuestionAttributes['slider_reset']) ? 1 : 0;
/* Slider reversed value */
if ($aQuestionAttributes['slider_reversed'] == 1) {
$slider_reversed = 'true';
} else {
$slider_reversed = 'false';
}
} else {
$coreClass .= " text-list number-list";
$slider_layout = false;
$slider_step = '';
$slider_min = '';
$slider_mintext = '';
$slider_max = '';
$slider_maxtext = '';
$slider_default = null;
$slider_orientation = '';
$slider_handle = '';
$slider_custom_handle = '';
$slider_separator = '';
$slider_reset = 0;
$slider_reversed = 'false';
}
if ($aQuestionAttributes['random_order'] == 1) {
$sOrder = dbRandom();
} else {
$sOrder = 'question_order';
}
$aSubquestions = Question::model()->findAll(array('order' => $sOrder, 'condition' => 'parent_qid=:parent_qid', 'params' => array(':parent_qid' => $ia[0])));
$sSurveyLanguage = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'];
$anscount = count($aSubquestions) * 2;
$fn = 1;
$sRows = "";
$inputnames = [];
if ($anscount == 0) {
$answer = doRender('/survey/questions/answer/multiplenumeric/empty', [], true);
} else {
foreach ($aSubquestions as $aSubquestion) {
$labelText = $sQuestionText = $aSubquestion->questionl10ns[$sSurveyLanguage]->question;
$myfname = $ia[1] . $aSubquestion['title'];
if ($sQuestionText == "") {
$sQuestionText = "&nbsp;";
}
if ($slider_layout) {
$sliderWidth = 12;
if ($slider_separator != '') {
$aAnswer = explode($slider_separator, $sQuestionText);
$theanswer = (isset($aAnswer[0])) ? $aAnswer[0] : "";
$labelText = $theanswer;
$sliderleft = (isset($aAnswer[1])) ? $aAnswer[1] : null;
$sliderright = (isset($aAnswer[2])) ? $aAnswer[2] : null;
/* sliderleft and sliderright is in input, but is part of answers then take label width */
if (!empty($sliderleft)) {
$sliderWidth = 10;
}
if (!empty($sliderright)) {
$sliderWidth = $sliderWidth == 10 ? 8 : 10 ;
}
$sliders = true; // What is the usage ?
} else {
$theanswer = $sQuestionText;
$sliders = false;
}
} else {
$theanswer = $sQuestionText;
$sliders = false;
}
$aAnswer = (isset($aAnswer)) ? $aAnswer : '';
$sliderleft = (isset($sliderleft)) ? $sliderleft : null;
$sliderright = (isset($sliderright)) ? $sliderright : null;
// color code missing mandatory questions red
$alert = '';
if (($_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['step'] != $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['maxstep']) || ($_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['step'] == $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['prevstep'])) {
if (($ia[6] == 'Y' || $ia[6] == 'S') && $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname] === '') {
$alert = true;
}
}
$sDisplayStyle = return_display_style($ia, $aQuestionAttributes, $thissurvey, $myfname);
// The value of the slider depends on many possible different parameters, by order of priority :
// 1. The value stored in the session
// 2. Else the default Answer (set by EM and stored in session, so same case than 1)
// 3. Else the slider_default value : if slider_default_set set the value here
// 4. Else the middle start or slider_default or nothing : leave the value to "" for the input, show slider pos at this position
if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname])) {
$sValue = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname];
} elseif ($slider_layout && $slider_default !== "" && $slider_default_set) {
$sValue = $slider_default;
} else {
$sValue = null;
}
// Fix the display value : Value is stored as decimal in SQL. Issue when reloading survey
if ($sValue[0] == ".") {
// issue #15684 mssql SAVE 0.01 AS .0100000000, set it at 0.0100000000
$sValue = "0" . $sValue;
}
if (strpos($sValue, ".")) {
$sValue = rtrim(rtrim($sValue, "0"), ".");
}
// End of DECIMAL fix : get the nulber value
$sUnformatedValue = $sValue ? $sValue : '';
if (strpos($sValue, ".")) {
$sValue = str_replace('.', $sSeparator, $sValue);
}
if (trim($aQuestionAttributes['num_value_int_only']) == 1) {
$extraclass .= " integeronly";
$answertypeclass = " integeronly";
$integeronly = 1;
} else {
$answertypeclass = "";
$integeronly = 0;
}
if (!$slider_layout) {
$sRows .= doRender('/survey/questions/answer/multiplenumeric/rows/input/answer_row', array(
'qid' => $ia[0],
'extraclass' => $extraclass,
'answertypeclass' => $answertypeclass,
'sDisplayStyle' => $sDisplayStyle,
'kpclass' => $kpclass,
'alert' => $alert,
'theanswer' => $theanswer,
'labelname' => 'answer' . $myfname,
'prefixclass' => $prefixclass,
'prefix' => $prefix,
'suffix' => $suffix,
'sInputContainerWidth' => $sInputContainerWidth,
'sLabelWidth' => $sLabelWidth,
'inputsize' => $inputsize,
'myfname' => $myfname,
'dispVal' => $sValue,
'maxlength' => $maxlength,
'labelText' => $labelText,
'integeronly' => $integeronly,
), true);
} else {
$sRows .= doRender('/survey/questions/answer/multiplenumeric/rows/sliders/answer_row', array(
'qid' => $ia[0],
'basename' => $ia[1],
'extraclass' => $extraclass,
'sDisplayStyle' => $sDisplayStyle,
'kpclass' => $kpclass,
'alert' => $alert,
'theanswer' => $theanswer,
'labelname' => 'answer' . $myfname,
'prefixclass' => $prefixclass,
'sliders' => $sliders,
'sliderleft' => $sliderleft,
'sliderright' => $sliderright,
'prefix' => $prefix,
'suffix' => $suffix,
'sInputContainerWidth' => $sInputContainerWidth,
'sLabelWidth' => $sLabelWidth,
'sliderWidth' => $sliderWidth,
'inputsize' => $inputsize,
'myfname' => $myfname,
'dispVal' => $sValue,
'maxlength' => $maxlength,
'labelText' => $labelText,
'slider_orientation' => $slider_orientation,
'slider_value' => $slider_position !== '' ? $slider_position : $sUnformatedValue,
'slider_step' => $slider_step,
'slider_min' => $slider_min,
'slider_mintext' => $slider_mintext,
'slider_max' => $slider_max,
'slider_maxtext' => $slider_maxtext,
'slider_position' => $slider_position,
'slider_reset_set' => $slider_default_set,
'slider_handle' => (isset($slider_handle)) ? $slider_handle : '',
'slider_reset' => $slider_reset,
'slider_reversed' => $slider_reversed,
'slider_custom_handle' => $slider_custom_handle,
'slider_showminmax' => $aQuestionAttributes['slider_showminmax'],
'sSeparator' => $sSeparator,
'sUnformatedValue' => $sUnformatedValue,
'integeronly' => $integeronly,
), true);
}
$fn++;
$inputnames[] = $myfname;
}
$displaytotal = false;
$equals_num_value = false;
if (
trim($aQuestionAttributes['equals_num_value']) != ''
|| trim($aQuestionAttributes['min_num_value']) != ''
|| trim($aQuestionAttributes['max_num_value']) != ''
) {
$qinfo = LimeExpressionManager::GetQuestionStatus($ia[0]);
if (trim($aQuestionAttributes['equals_num_value']) != '') {
$equals_num_value = true;
}
$displaytotal = true;
}
// TODO: Slider and multiple-numeric input should really be two different question types
$templateFile = $sliders ? 'answer' : 'answer_input';
$answer = doRender('/survey/questions/answer/multiplenumeric/' . $templateFile, array(
'sRows' => $sRows,
'coreClass' => $coreClass,
'prefixclass' => $prefixclass,
'equals_num_value' => $equals_num_value,
'id' => $ia[0],
'basename' => $ia[1],
'suffix' => $suffix,
'sumRemainingEqn' => (isset($qinfo)) ? $qinfo['sumRemainingEqn'] : '',
'displaytotal' => $displaytotal,
'sumEqn' => (isset($qinfo)) ? $qinfo['sumEqn'] : '',
'prefix' => $prefix, // Need to know this to place sum/remaining correctly
'sInputContainerWidth' => $sInputContainerWidth,
'sLabelWidth' => $sLabelWidth,
), true);
}
if ($aQuestionAttributes['slider_layout'] == 1) {
/* Add some data for javascript */
$sliderTranslation = array(
'help' => gT('Please click and drag the slider handles to enter your answer.')
);
App()->getClientScript()->registerScript("sliderTranslation", "var sliderTranslation=" . json_encode($sliderTranslation) . ";\n", CClientScript::POS_BEGIN);
App()->getClientScript()->registerPackage("question-numeric-slider");
}
return array($answer, $inputnames);
}
// ---------------------------------------------------------------
function do_numerical($ia)
{
global $thissurvey;
$extraclass = "";
$answertypeclass = "numeric";
$checkconditionFunction = "fixnum_checkconditions";
$aQuestionAttributes = QuestionAttribute::model()->getQuestionAttributes($ia[0]);
$coreClass = "ls-answers answer-item text-item numeric-item";
if (trim($aQuestionAttributes['prefix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '') {
$prefix = $aQuestionAttributes['prefix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']];
$extraclass .= " withprefix";
} else {
$prefix = '';
}
if (trim($aQuestionAttributes['suffix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '') {
$suffix = $aQuestionAttributes['suffix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']];
$extraclass .= " withsuffix";
} else {
$suffix = '';
}
if (intval(trim($aQuestionAttributes['maximum_chars'])) > 0 && intval(trim($aQuestionAttributes['maximum_chars'])) < 20) {
// Only maxlength attribute, use textarea[maxlength] jquery selector for textarea
$maxlength = intval(trim($aQuestionAttributes['maximum_chars']));
$extraclass .= " ls-input-maxchars";
} else {
$maxlength = 20;
}
if (trim($aQuestionAttributes['text_input_width']) != '') {
$col = ($aQuestionAttributes['text_input_width'] <= 12) ? $aQuestionAttributes['text_input_width'] : 12;
$extraclass .= " col-sm-" . trim($col);
$withColumn = true;
} else {
$withColumn = false;
}
if (ctype_digit(trim($aQuestionAttributes['input_size']))) {
$inputsize = trim($aQuestionAttributes['input_size']);
$extraclass .= " ls-input-sized";
} else {
$inputsize = null;
}
if (trim($aQuestionAttributes['num_value_int_only']) == 1) {
$extraclass .= " integeronly";
$answertypeclass .= " integeronly";
$integeronly = 1;
} else {
$integeronly = 0;
}
if (trim($aQuestionAttributes['placeholder'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '') {
$placeholder = $aQuestionAttributes['placeholder'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']];
} else {
$placeholder = '';
}
$fValue = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]];
$sSeparator = getRadixPointData($thissurvey['surveyls_numberformat']);
$sSeparator = $sSeparator['separator'];
if ($fValue && is_string($fValue)) {
// Fix reloaded DECIMAL value
if ($fValue[0] == ".") {
// issue #15684 mssql SAVE 0.01 AS .0100000000, set it at 0.0100000000
$fValue = "0" . $fValue;
}
if (strpos($fValue, ".")) {
$fValue = rtrim(rtrim($fValue, "0"), ".");
}
}
$fValue = str_replace('.', $sSeparator, $fValue);
if ($thissurvey['nokeyboard'] == 'Y') {
includeKeypad();
$extraclass .= " inputkeypad";
$answertypeclass .= " num-keypad";
}
$answer = doRender('/survey/questions/answer/numerical/answer', array(
'extraclass' => $extraclass,
'coreClass' => $coreClass,
'withColumn' => $withColumn,
'id' => $ia[1],
'basename' => $ia[1],
'prefix' => $prefix,
'answertypeclass' => $answertypeclass,
'inputsize' => $inputsize,
'fValue' => $fValue,
'checkconditionFunction' => $checkconditionFunction,
'integeronly' => $integeronly,
'maxlength' => $maxlength,
'suffix' => $suffix,
'placeholder' => $placeholder,
), true);
$inputnames = [];
$inputnames[] = $ia[1];
$mandatory = null;
return array($answer, $inputnames, $mandatory);
}
// ---------------------------------------------------------------
function do_shortfreetext($ia)
{
global $thissurvey;
$coreClass = "ls-answers answer-item text-item";
$extraclass = "";
$aQuestionAttributes = QuestionAttribute::model()->getQuestionAttributes($ia[0]);
if ($aQuestionAttributes['numbers_only'] == 1) {
$sSeparator = getRadixPointData($thissurvey['surveyls_numberformat']);
$sSeparator = $sSeparator['separator'];
$extraclass .= " numberonly";
$coreClass .= " numeric-item";
$checkconditionFunction = "fixnum_checkconditions";
} else {
$sSeparator = '';
$checkconditionFunction = "checkconditions";
}
if (intval(trim($aQuestionAttributes['maximum_chars'])) > 0) {
// Only maxlength attribute, use textarea[maxlength] jquery selector for textarea
$maxlength = intval(trim($aQuestionAttributes['maximum_chars']));
$extraclass .= " ls-input-maxchars";
} else {
$maxlength = "";
}
if (trim($aQuestionAttributes['text_input_width']) != '' && intval(trim($aQuestionAttributes['location_mapservice'])) == 0) {
$col = ($aQuestionAttributes['text_input_width'] <= 12) ? $aQuestionAttributes['text_input_width'] : 12;
$extraclass .= " col-sm-" . trim($col);
$withColumn = true;
} else {
$withColumn = false;
}
if (ctype_digit(trim($aQuestionAttributes['input_size']))) {
$inputsize = trim($aQuestionAttributes['input_size']);
$extraclass .= " ls-input-sized";
} else {
$inputsize = null;
}
if (trim($aQuestionAttributes['prefix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '') {
$prefix = $aQuestionAttributes['prefix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']];
$extraclass .= " withprefix";
} else {
$prefix = '';
}
if (trim($aQuestionAttributes['suffix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '') {
$suffix = $aQuestionAttributes['suffix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']];
$extraclass .= " withsuffix";
} else {
$suffix = '';
}
if (trim($aQuestionAttributes['placeholder'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '') {
$placeholder = $aQuestionAttributes['placeholder'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']];
} else {
$placeholder = '';
}
if ($thissurvey['nokeyboard'] == 'Y') {
includeKeypad();
$kpclass = "text-keypad";
$extraclass .= " inputkeypad";
} else {
$kpclass = "";
}
$answer = "";
$sQuestionHelpText = '';
if (trim($aQuestionAttributes['display_rows']) != '') {
//question attribute "display_rows" is set -> we need a textarea to be able to show several rows
$drows = $aQuestionAttributes['display_rows'];
$dispVal = "";
if ($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]]) {
$dispVal = str_replace("\\", "", $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]]);
if ($aQuestionAttributes['numbers_only'] == 1) {
$dispVal = str_replace('.', $sSeparator, $dispVal);
}
$dispVal = htmlspecialchars($dispVal);
}
$answer .= doRender('/survey/questions/answer/shortfreetext/textarea/item', array(
'extraclass' => $extraclass,
'coreClass' => $coreClass,
'freeTextId' => 'answer' . $ia[1],
'name' => $ia[1],
'basename' => $ia[1],
'drows' => $drows,
'checkconditionFunction' => $checkconditionFunction . '(this.value, this.name, this.type)',
'dispVal' => $dispVal,
'maxlength' => $maxlength,
'kpclass' => $kpclass,
'prefix' => $prefix,
'suffix' => $suffix,
'inputsize' => $inputsize,
'placeholder' => $placeholder,
'withColumn' => $withColumn
), true);
} elseif ((int) ($aQuestionAttributes['location_mapservice']) == 1) {
$coreClass = "ls-answers map-item geoloc-item";
$currentLocation = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]];
$currentLatLong = null;
// Get the latitude/longtitude for the point that needs to be displayed by default
if (strlen($currentLocation) > 2 && strpos($currentLocation, ";")) { // Quick check if current location is OK
$currentLatLong = explode(';', $currentLocation);
$currentLatLong = array($currentLatLong[0], $currentLatLong[1]);
} else {
if ((int) ($aQuestionAttributes['location_nodefaultfromip']) == 0) {
$currentLatLong = getLatLongFromIp(getIPAddress());
}
if (empty($currentLatLong)) {
$floatLat = "";
$floatLng = "";
$sDefaultcoordinates = trim(LimeExpressionManager::ProcessString($aQuestionAttributes['location_defaultcoordinates'], $ia[0], array(), 3, 1, false, false, true));/* static var is the last one */
if (strlen($sDefaultcoordinates) > 2 && strpos($sDefaultcoordinates, " ")) {
$LatLong = explode(" ", $sDefaultcoordinates);
if (isset($LatLong[0]) && isset($LatLong[1])) {
$floatLat = $LatLong[0];
$floatLng = $LatLong[1];
}
}
$currentLatLong = array($floatLat, $floatLng);
}
}
// 2 - city; 3 - state; 4 - country; 5 - postal
$strBuild = "";
if ($aQuestionAttributes['location_city']) {
$strBuild .= "2";
}
if ($aQuestionAttributes['location_state']) {
$strBuild .= "3";
}
if ($aQuestionAttributes['location_country']) {
$strBuild .= "4";
}
if ($aQuestionAttributes['location_postal']) {
$strBuild .= "5";
}
$currentLocation = $currentLatLong[0] . " " . $currentLatLong[1];
Yii::app()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts') . "map.js", LSYii_ClientScript::POS_END);
$sGoogleMapsAPIKey = trim(Yii::app()->getConfig("googleMapsAPIKey"));
if ($aQuestionAttributes['location_mapservice'] == 1 && !empty($sGoogleMapsAPIKey)) {
Yii::app()->getClientScript()->registerScriptFile("//maps.googleapis.com/maps/api/js?sensor=false&key={$sGoogleMapsAPIKey}", LSYii_ClientScript::POS_BEGIN);
} elseif ($aQuestionAttributes['location_mapservice'] == 2) {
/* 2019-04-01 : openlayers auto redirect to https (on firefox) , but always good to use automatic protocol */
Yii::app()->getClientScript()->registerScriptFile("//www.openlayers.org/api/OpenLayers.js", LSYii_ClientScript::POS_BEGIN);
}
$questionHelp = false;
if (isset($aQuestionAttributes['hide_tip']) && $aQuestionAttributes['hide_tip'] == 0) {
$questionHelp = true;
$sQuestionHelpText = gT('Drag and drop the pin to the desired location. You may also right click on the map to move the pin.');
}
$answer = doRender('/survey/questions/answer/shortfreetext/location_mapservice/item', array(
'extraclass' => $extraclass,
'coreClass' => $coreClass,
'freeTextId' => 'answer' . $ia[1],
'name' => $ia[1],
'qid' => $ia[0],
'basename' => $ia[1],
'checkconditionFunction' => $checkconditionFunction . '(this.value, this.name, this.type)',
'value' => $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]],
'kpclass' => $kpclass,
'currentLocation' => $currentLocation,
'strBuild' => $strBuild,
'location_mapservice' => $aQuestionAttributes['location_mapservice'],
'location_mapzoom' => $aQuestionAttributes['location_mapzoom'],
'location_mapheight' => $aQuestionAttributes['location_mapheight'],
'questionHelp' => $questionHelp,
'question_text_help' => $sQuestionHelpText,
'inputsize' => $inputsize,
'placeholder' => $placeholder,
'withColumn' => $withColumn
), true);
} elseif ((int) ($aQuestionAttributes['location_mapservice']) == 100) {
$coreClass = "ls-answers map-item geoloc-item";
$currentLocation = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]];
$currentCenter = $currentLatLong = null;
// Get the latitude/longtitude for the point that needs to be displayed by default
if (strlen($currentLocation) > 2 && strpos($currentLocation, ";")) {
$currentLatLong = explode(';', $currentLocation);
$currentCenter = $currentLatLong = array($currentLatLong[0], $currentLatLong[1]);
} elseif ((int) ($aQuestionAttributes['location_nodefaultfromip']) == 0) {
$currentCenter = $currentLatLong = getLatLongFromIp(getIPAddress());
}
// If it's not set : set the center to the default position, but don't set the marker
if (!$currentLatLong) {
$currentLatLong = array("", "");
$sDefaultcoordinates = trim(LimeExpressionManager::ProcessString($aQuestionAttributes['location_defaultcoordinates'], $ia[0], array(), 3, 1, false, false, true));/* static var is the last one */
$currentCenter = explode(" ", $sDefaultcoordinates);
if (count($currentCenter) != 2) {
$currentCenter = array("", "");
}
}
$strBuild = "";
$aGlobalMapScriptVar = array(
'geonameUser' => getGlobalSetting('GeoNamesUsername'), // Did we need to urlencode ?
'geonameLang' => Yii::app()->language,
);
$aThisMapScriptVar = array(
'zoomLevel' => $aQuestionAttributes['location_mapzoom'],
'latitude' => $currentCenter[0],
'longitude' => $currentCenter[1],
);
App()->getClientScript()->registerPackage('leaflet');
App()->getClientScript()->registerPackage('devbridge-autocomplete'); /* for autocomplete */
Yii::app()->getClientScript()->registerScript('sGlobalMapScriptVar', "LSmap=" . ls_json_encode($aGlobalMapScriptVar) . ";\nLSmaps=[];", CClientScript::POS_BEGIN);
Yii::app()->getClientScript()->registerScript('sThisMapScriptVar' . $ia[1], "LSmaps['{$ia[1]}']=" . ls_json_encode($aThisMapScriptVar) . ";", CClientScript::POS_BEGIN);
Yii::app()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts') . "map.js", CClientScript::POS_END);
Yii::app()->getClientScript()->registerCssFile(Yii::app()->getConfig('publicstyleurl') . 'map.css');
if (isset($aQuestionAttributes['hide_tip']) && $aQuestionAttributes['hide_tip'] == 0) {
$questionHelp = true;
$sQuestionHelpText = gT('Click to set the location or drag and drop the pin. You may may also enter coordinates');
}
$itemDatas = array(
'extraclass' => $extraclass,
'coreClass' => $coreClass,
'name' => $ia[1],
'qid' => $ia[0],
'basename' => $ia[1],
'checkconditionFunction' => $checkconditionFunction . '(this.value, this.name, this.type)',
'value' => $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]],
'strBuild' => $strBuild,
'location_mapservice' => $aQuestionAttributes['location_mapservice'],
'location_mapzoom' => $aQuestionAttributes['location_mapzoom'],
'location_mapheight' => $aQuestionAttributes['location_mapheight'],
'questionHelp' => (isset($questionHelp)) ? $questionHelp : '',
'question_text_help' => $sQuestionHelpText,
'location_value' => $currentLatLong[0] . ' ' . $currentLatLong[1],
'currentLat' => $currentLatLong[0],
'currentLong' => $currentLatLong[1],
'inputsize' => $inputsize,
'placeholder' => $placeholder,
'withColumn' => $withColumn
);
$answer = doRender('/survey/questions/answer/shortfreetext/location_mapservice/item_100', $itemDatas, true);
} else {
//no question attribute set, use common input text field
$dispVal = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]];
if ($aQuestionAttributes['numbers_only'] == 1) {
$dispVal = str_replace('.', $sSeparator, $dispVal);
}
$dispVal = htmlspecialchars($dispVal, ENT_QUOTES, 'UTF-8');
$itemDatas = array(
'extraclass' => $extraclass,
'coreClass' => $coreClass,
'name' => $ia[1],
'basename' => $ia[1],
'prefix' => $prefix,
'suffix' => $suffix,
'kpclass' => $kpclass,
'dispVal' => $dispVal,
'maxlength' => $maxlength,
'inputsize' => $inputsize,
'placeholder' => $placeholder,
'withColumn' => $withColumn
);
$answer = doRender('/survey/questions/answer/shortfreetext/text/item', $itemDatas, true);
}
if (trim($aQuestionAttributes['time_limit']) != '') {
$answer .= return_timer_script($aQuestionAttributes, $ia, "answer" . $ia[1]);
}
$inputnames = [];
$inputnames[] = $ia[1];
return array($answer, $inputnames);
}
function getLatLongFromIp($sIPAddress)
{
$ipInfoDbAPIKey = Yii::app()->getConfig("ipInfoDbAPIKey");
if ($ipInfoDbAPIKey) {
// ipinfodb.com needs a key
$oXML = simplexml_load_file("http://api.ipinfodb.com/v3/ip-city/?key=$ipInfoDbAPIKey&ip=$sIPAddress&format=xml");
if ($oXML->{'statusCode'} == "OK") {
$lat = (float) $oXML->{'latitude'};
$lng = (float) $oXML->{'longitude'};
return(array($lat, $lng));
} else {
return false;
}
}