getConfig('surveyID')]['insertarray'] variable which is built at the commencement of the survey.
* See index.php, function "buildsurveysession()"
* One $ia array exists for every question in the survey. The $_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['insertarray']
* string is an array of $ia arrays.
*
* $ia[0] => question id
* $ia[1] => fieldname
* $ia[2] => title
* $ia[3] => question text
* $ia[4] => type -- text, radio, select, array, etc
* $ia[5] => group id
* $ia[6] => mandatory Y || N
* $ia[7] => conditions exist for this question
* $ia[8] => other questions have conditions which rely on this question (including array_filter and array_filter_exclude attributes)
* $ia[9] => incremental question count (used by {QUESTION_NUMBER})
*
* $conditions element structure
* $condition[n][0] => qid = question id
* $condition[n][1] => cqid = question id of the target question, or 0 for TokenAttr leftOperand
* $condition[n][2] => field name of element [1] (Except for type M or P)
* $condition[n][3] => value to be evaluated on answers labeled.
* $condition[n][4] => type of question
* $condition[n][5] => SGQ code of element [1] (sub-part of [2])
* $condition[n][6] => method used to evaluate
* $condition[n][7] => scenario *NEW BY R.L.J. van den Burg*
*/
/**
* setNoAnswerMode
*/
function setNoAnswerMode($thissurvey)
{
if (getGlobalSetting('shownoanswer') == 1)
{
define('SHOW_NO_ANSWER', 1);
}
elseif (getGlobalSetting('shownoanswer') == 0)
{
define('SHOW_NO_ANSWER', 0);
}
elseif ($thissurvey['shownoanswer'] == 'N')
{
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 mixed $ia
* @return mixed
*/
function retrieveAnswers($ia)
{
//globalise required config variables
global $thissurvey; //These are set by index.php
//$clang = Yii::app()->lang;
$clang = Yii::app()->lang;
//DISPLAY
$display = $ia[7];
//QUESTION NAME
$name = $ia[0];
$qtitle=$ia[3];
$inputnames=array();
// TMSW - eliminate this - get from LEM
//A bit of housekeeping to stop PHP Notices
$answer = "";
if (!isset($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]])) {$_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]] = "";}
$aQuestionAttributes = getQuestionAttributeValues($ia[0], $ia[4]);
//Create the question/answer html
// Previously in limesurvey, it was virtually impossible to control how the start of questions were formatted.
// this is an attempt to allow users (or rather system admins) some control over how the starting text is formatted.
$number = isset($ia[9]) ? $ia[9] : '';
// TMSW - populate this directly from LEM? - this this is global
$question_text = array(
'all' => '' // All has been added for backwards compatibility with templates that use question_start.pstpl (now redundant)
,'text' => $qtitle
,'code' => $ia[2]
,'number' => $number
,'help' => ''
,'mandatory' => ''
,'man_message' => ''
,'valid_message' => ''
,'file_valid_message' => ''
,'class' => ''
,'man_class' => ''
,'input_error_class' => ''// provides a class.
,'essentials' => ''
);
switch ($ia[4])
{
case 'X': //BOILERPLATE QUESTION
$values = do_boilerplate($ia);
break;
case '5': //5 POINT CHOICE radio-buttons
$values = do_5pointchoice($ia);
break;
case 'D': //DATE
$values = do_date($ia);
// if a drop box style date was answered incompletely (dropbox), print an error/help message
if (($_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['step'] != $_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['maxstep']) ||
($_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['step'] == $_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['prevstep']))
{
if (isset($_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['qattribute_answer'.$ia[1]]))
$question_text['help'] = ''.$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['qattribute_answer'.$ia[1]].'';
}
break;
case 'L': //LIST drop-down/radio-button list
$values = do_list_radio($ia);
if ($aQuestionAttributes['hide_tip']==0)
{
$qtitle .= " \n"
. $clang->gT('Choose one of the following answers').'';
$question_text['help'] = $clang->gT('Choose one of the following answers');
}
break;
case '!': //List - dropdown
$values=do_list_dropdown($ia);
if ($aQuestionAttributes['hide_tip']==0)
{
$qtitle .= " \n"
. $clang->gT('Choose one of the following answers').'';
$question_text['help'] = $clang->gT('Choose one of the following answers');
}
break;
case 'O': //LIST WITH COMMENT drop-down/radio-button list + textarea
$values=do_listwithcomment($ia);
if (count($values[1]) > 1 && $aQuestionAttributes['hide_tip']==0)
{
$qtitle .= " \n"
. $clang->gT('Choose one of the following answers').'';
$question_text['help'] = $clang->gT('Choose one of the following answers');
}
break;
case 'R': //RANKING STYLE
$values=do_ranking($ia);
if (count($values[1]) > 1 && $aQuestionAttributes['hide_tip']==0)
{
$question_text['help'] = $clang->gT("Double-click or drag-and-drop items in the left list to move them to the right - your highest ranking item should be on the top right, moving through to your lowest ranking item.");
}
break;
case 'M': //Multiple choice checkbox
$values=do_multiplechoice($ia);
if (count($values[1]) > 1 && $aQuestionAttributes['hide_tip']==0)
{
$maxansw=trim($aQuestionAttributes['max_answers']);
$minansw=trim($aQuestionAttributes['min_answers']);
if (!($maxansw || $minansw))
{
$qtitle .= " \n"
. $clang->gT('Check any that apply').'';
$question_text['help'] = $clang->gT('Check any that apply');
}
// else
// {
// if ($maxansw && $minansw)
// {
// $qtitle .= " \n"
// . sprintf($clang->gT("Check between %d and %d answers"), $minansw, $maxansw)."";
// $question_text['help'] = sprintf($clang->gT("Check between %d and %d answers"), $minansw, $maxansw);
// } elseif ($maxansw)
// {
// $qtitle .= " \n"
// . sprintf($clang->gT("Check at most %d answers"), $maxansw)."";
// $question_text['help'] = sprintf($clang->gT("Check at most %d answers"), $maxansw);
// } else
// {
// $qtitle .= " \n"
// . sprintf($clang->ngT("Check at least %d answer","Check at least %d answers",$minansw),$minansw)."";
// $question_text['help'] = sprintf($clang->ngT("Check at least %d answer","Check at least %d answers",$minansw),$minansw);
// }
// }
}
break;
case 'I': //Language Question
$values=do_language($ia);
if (count($values[1]) > 1)
{
$qtitle .= " \n"
. $clang->gT('Choose your language').'';
$question_text['help'] = $clang->gT('Choose your language');
}
break;
case 'P': //Multiple choice with comments checkbox + text
$values=do_multiplechoice_withcomments($ia);
if (count($values[1]) > 1 && $aQuestionAttributes['hide_tip']==0)
{
$maxansw=trim($aQuestionAttributes["max_answers"]);
$minansw=trim($aQuestionAttributes["min_answers"]);
if (!($maxansw || $minansw))
{
$qtitle .= " \n"
. $clang->gT('Check any that apply').'';
$question_text['help'] = $clang->gT('Check any that apply');
}
}
break;
case '|': //File Upload
$values=do_file_upload($ia);
break;
case 'Q': //MULTIPLE SHORT TEXT
$values=do_multipleshorttext($ia);
break;
case 'K': //MULTIPLE NUMERICAL QUESTION
$values=do_multiplenumeric($ia);
break;
case 'N': //NUMERICAL QUESTION TYPE
$values=do_numerical($ia);
break;
case 'S': //SHORT FREE TEXT
$values=do_shortfreetext($ia);
break;
case 'T': //LONG FREE TEXT
$values=do_longfreetext($ia);
break;
case 'U': //HUGE FREE TEXT
$values=do_hugefreetext($ia);
break;
case 'Y': //YES/NO radio-buttons
$values=do_yesno($ia);
break;
case 'G': //GENDER drop-down list
$values=do_gender($ia);
break;
case 'A': //ARRAY (5 POINT CHOICE) radio-buttons
$values=do_array_5point($ia);
break;
case 'B': //ARRAY (10 POINT CHOICE) radio-buttons
$values=do_array_10point($ia);
break;
case 'C': //ARRAY (YES/UNCERTAIN/NO) radio-buttons
$values=do_array_yesnouncertain($ia);
break;
case 'E': //ARRAY (Increase/Same/Decrease) radio-buttons
$values=do_array_increasesamedecrease($ia);
break;
case 'F': //ARRAY (Flexible) - Row Format
$values=do_array($ia);
break;
case 'H': //ARRAY (Flexible) - Column Format
$values=do_arraycolumns($ia);
break;
case ':': //ARRAY (Multi Flexi) 1 to 10
$values=do_array_multiflexi($ia);
break;
case ';': //ARRAY (Multi Flexi) Text
$values=do_array_multitext($ia); //It's like the "5th element" movie, come to life
break;
case '1': //Array (Flexible Labels) dual scale
$values=do_array_dual($ia);
break;
case '*': // Equation
$values=do_equation($ia);
break;
} //End Switch
if (isset($values)) //Break apart $values array returned from switch
{
//$answer is the html code to be printed
//$inputnames is an array containing the names of each input field
list($answer, $inputnames)=$values;
}
if ($ia[6] == 'Y')
{
$qtitle = ''.$clang->gT('*').''.$qtitle;
$question_text['mandatory'] = $clang->gT('*');
}
//If this question is mandatory but wasn't answered in the last page
//add a message HIGHLIGHTING the question
if (($_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['step'] != $_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['maxstep']) || ($_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['step'] == $_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['prevstep'])) {
$mandatory_msg = mandatory_message($ia);
}
else {
$mandatory_msg = '';
}
$qtitle .= $mandatory_msg;
$question_text['man_message'] = $mandatory_msg;
// if (($_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['step'] != $_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['maxstep']) || ($_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['step'] == $_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['prevstep'])) {
if (!isset($aQuestionAttributes['hide_tip']) || $aQuestionAttributes['hide_tip']==0) {
$_vshow = true; // whether should initially be visible - TODO should also depend upon 'hidetip'?
}
else {
$_vshow = false;
}
list($validation_msg,$isValid) = validation_message($ia,$_vshow);
$qtitle .= $validation_msg;
$question_text['valid_message'] = $validation_msg;
if (($_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['step'] != $_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['maxstep']) || ($_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['step'] == $_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['prevstep'])) {
$file_validation_msg = file_validation_message($ia);
}
else {
$file_validation_msg = '';
$isValid = true; // don't want to show any validation messages.
}
$qtitle .= $ia[4] == "|" ? $file_validation_msg : "";
$question_text['file_valid_message'] = $ia[4] == "|" ? $file_validation_msg : "";
if(!empty($question_text['man_message']) || !$isValid || !empty($question_text['file_valid_message']))
{
$question_text['input_error_class'] = ' input-error';// provides a class to style question wrapper differently if there is some kind of user input error;
}
// =====================================================
// START: legacy question_start.pstpl code
// The following section adds to the templating system by allowing
// templaters to control where the various parts of the question text
// are put.
$sTemplate = isset($thissurvey['template']) ? $thissurvey['template'] : NULL;
if(is_file('templates/'.validateTemplateDir($sTemplate).'/question_start.pstpl'))
{
$qtitle_custom = '';
$replace=array();
foreach($question_text as $key => $value)
{
$find[] = '{QUESTION_'.strtoupper($key).'}'; // Match key words from template
$replace[] = $value; // substitue text
};
if(!defined('QUESTION_START'))
{
define('QUESTION_START' , file_get_contents(getTemplatePath($thissurvey['template']).'/question_start.pstpl' , true));
};
$qtitle_custom = str_replace( $find , $replace , QUESTION_START);
$c = 1;
// START:
";
}
// $checkotherscript = "";
// if (isset($other) && $other == 'Y' && $aQuestionAttributes['other_comment_mandatory']==1)
// {
// $checkotherscript = "\n\n";
// }
// $answer = $checkotherscript . $answer;
$inputnames[]=$ia[1];
return array($answer, $inputnames);
}
// ---------------------------------------------------------------
// TMSW TODO - Can remove DB query by passing in answer list from EM
function do_list_radio($ia)
{
global $dropdownthreshold;
global $thissurvey;
$clang=Yii::app()->lang;
if ($thissurvey['nokeyboard']=='Y')
{
includeKeypad();
$kpclass = "text-keypad";
}
else
{
$kpclass = "";
}
$checkconditionFunction = "checkconditions";
$aQuestionAttributes = getQuestionAttributeValues($ia[0], $ia[4]);
$query = "SELECT other FROM {{questions}} WHERE qid=".$ia[0]." AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' ";
$result = Yii::app()->db->createCommand($query)->query();
foreach ($result->readAll() as $row)
{
$other = $row['other'];
}
//question attribute random order set?
if ($aQuestionAttributes['random_order']==1) {
$ansquery = "SELECT * FROM {{answers}} WHERE qid=$ia[0] AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' and scale_id=0 ORDER BY ".dbRandom();
}
//question attribute alphasort set?
elseif ($aQuestionAttributes['alphasort']==1)
{
$ansquery = "SELECT * FROM {{answers}} WHERE qid=$ia[0] AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' and scale_id=0 ORDER BY answer";
}
//no question attributes -> order by sortorder
else
{
$ansquery = "SELECT * FROM {{answers}} WHERE qid=$ia[0] AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' and scale_id=0 ORDER BY sortorder, answer";
}
$ansresult = dbExecuteAssoc($ansquery)->readAll(); //Checked
$anscount = count($ansresult);
if (trim($aQuestionAttributes['display_columns'])!='') {
$dcols = $aQuestionAttributes['display_columns'];
}
else
{
$dcols= 1;
}
if (trim($aQuestionAttributes['other_replace_text'][$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']])!='')
{
$othertext=$aQuestionAttributes['other_replace_text'][$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']];
}
else
{
$othertext=$clang->gT('Other:');
}
if (isset($other) && $other=='Y') {$anscount++;} //Count up for the Other answer
if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) {$anscount++;} //Count up if "No answer" is showing
$wrapper = setupColumns($dcols , $anscount,"answers-list radio-list","answer-item radio-item");
$answer = $wrapper['whole-start'];
//Time Limit Code
if (trim($aQuestionAttributes['time_limit'])!='')
{
$answer .= return_timer_script($aQuestionAttributes, $ia);
}
//End Time Limit Code
// Get array_filter stuff
$rowcounter = 0;
$colcounter = 1;
$trbc='';
foreach ($ansresult as $key=>$ansrow)
{
$myfname = $ia[1].$ansrow['code'];
$check_ans = '';
if ($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]] == $ansrow['code'])
{
$check_ans = CHECKED;
}
list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $aQuestionAttributes, $thissurvey, $ansrow, $myfname, $trbc, $myfname, "li","answer-item radio-item");
if(substr($wrapper['item-start'],0,4) == "\t
'.$wrapper['item-end'];
++$rowcounter;
if ($rowcounter == $wrapper['maxrows'] && $colcounter < $wrapper['cols'] || (count($ansresult)-$key)==$wrapper['cols']-$colcounter)
{
if($colcounter == $wrapper['cols'] - 1 )
{
$answer .= $wrapper['col-devide-last'];
}
else
{
$answer .= $wrapper['col-devide'];
}
$rowcounter = 0;
++$colcounter;
}
}
if (isset($other) && $other=='Y')
{
$sSeparator = getRadixPointData($thissurvey['surveyls_numberformat']);
$sSeparator = $sSeparator['separator'];
if ($aQuestionAttributes['other_numbers_only']==1)
{
$oth_checkconditionFunction = 'fixnum_checkconditions';
}
else
{
$oth_checkconditionFunction = 'checkconditions';
}
if ($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]] == '-oth-')
{
$check_ans = CHECKED;
}
else
{
$check_ans = '';
}
$thisfieldname=$ia[1].'other';
if (isset($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$thisfieldname]))
{
$dispVal = $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$thisfieldname];
if ($aQuestionAttributes['other_numbers_only']==1)
{
$dispVal = str_replace('.',$sSeparator,$dispVal);
}
$answer_other = ' value="'.htmlspecialchars($dispVal,ENT_QUOTES).'"';
}
else
{
$answer_other = ' value=""';
}
list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $aQuestionAttributes, $thissurvey, array("code"=>"other"), $thisfieldname, $trbc, $myfname, "li", "answer-item radio-item other-item other");
if(substr($wrapper['item-start-other'],0,4) == "\t
'.$wrapper['item-end'];
$inputnames[]=$thisfieldname;
++$rowcounter;
if ($rowcounter == $wrapper['maxrows'] && $colcounter < $wrapper['cols'])
{
if($colcounter == $wrapper['cols'] - 1)
{
$answer .= $wrapper['col-devide-last'];
}
else
{
$answer .= $wrapper['col-devide'];
}
$rowcounter = 0;
++$colcounter;
}
}
if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1)
{
if ((!$_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]] || $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]] == '') || ($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]] == ' ' ))
{
$check_ans = CHECKED; //Check the "no answer" radio button if there is no answer in session.
}
else
{
$check_ans = '';
}
$answer .= $wrapper['item-start-noanswer'].'
'.$wrapper['item-end'];
// --> END NEW FEATURE - SAVE
++$rowcounter;
if ($rowcounter == $wrapper['maxrows'] && $colcounter < $wrapper['cols'])
{
if($colcounter == $wrapper['cols'] - 1)
{
$answer .= $wrapper['col-devide-last'];
}
else
{
$answer .= $wrapper['col-devide'];
}
$rowcounter = 0;
++$colcounter;
}
}
//END OF ITEMS
$answer .= $wrapper['whole-end'].'
getConfig('surveyID')][$ia[1]]."\" />\n";
$inputnames[]=$ia[1];
return array($answer, $inputnames);
}
// ---------------------------------------------------------------
// TMSW TODO - Can remove DB query by passing in answer list from EM
function do_listwithcomment($ia)
{
global $maxoptionsize, $thissurvey;
$clang=Yii::app()->lang;
$dropdownthreshold = Yii::app()->getConfig("dropdownthreshold");
if ($thissurvey['nokeyboard']=='Y')
{
includeKeypad();
$kpclass = "text-keypad";
}
else
{
$kpclass = "";
}
$checkconditionFunction = "checkconditions";
$answer = '';
$aQuestionAttributes = getQuestionAttributeValues($ia[0], $ia[4]);
if (!isset($maxoptionsize)) {$maxoptionsize=35;}
//question attribute random order set?
if ($aQuestionAttributes['random_order']==1) {
$ansquery = "SELECT * FROM {{answers}} WHERE qid=$ia[0] AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' and scale_id=0 ORDER BY ".dbRandom();
}
//question attribute alphasort set?
elseif ($aQuestionAttributes['alphasort']==1)
{
$ansquery = "SELECT * FROM {{answers}} WHERE qid=$ia[0] AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' and scale_id=0 ORDER BY answer";
}
//no question attributes -> order by sortorder
else
{
$ansquery = "SELECT * FROM {{answers}} WHERE qid=$ia[0] AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' and scale_id=0 ORDER BY sortorder, answer";
}
$ansresult=Yii::app()->db->createCommand($ansquery)->query()->readAll();
$anscount = count($ansresult);
$hint_comment = $clang->gT('Please enter your comment here');
if ($aQuestionAttributes['use_dropdown']!=1 && $anscount <= $dropdownthreshold)
{
$answer .= '