/** * 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 // //DISPLAY $display = $ia[7]; //QUESTION NAME $name = $ia[0]; $qtitle = $ia[3]; $inputnames = array(); $aQuestionAttributes = getQuestionAttributeValues($ia[0]); //Create the question/answer html $answer = ""; // 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' => '', 'text' => $qtitle, 'code' => $ia[2], 'number' => $number, 'help' => '', 'mandatory' => '', 'man_message' => '', 'valid_message' => '', 'file_valid_message' => '', 'class' => '', 'man_class' => '', 'input_error_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'] = '<span class="error">' . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['qattribute_answer' . $ia[1]] . '</span>'; } } break; case 'L': //LIST drop-down/radio-button list $values = do_list_radio($ia); if ($aQuestionAttributes['hide_tip'] == 0) { $qtitle .= "<br />\n<span class=\"questionhelp\">" . gT('Choose one of the following answers') . '</span>'; $question_text['help'] = gT('Choose one of the following answers'); } break; case '!': //List - dropdown $values = do_list_dropdown($ia); if ($aQuestionAttributes['hide_tip'] == 0) { $qtitle .= "<br />\n<span class=\"questionhelp\">" . gT('Choose one of the following answers') . '</span>'; $question_text['help'] = 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 .= "<br />\n<span class=\"questionhelp\">" . gT('Choose one of the following answers') . '</span>'; $question_text['help'] = gT('Choose one of the following answers'); } break; case 'R': //RANKING STYLE $values = do_ranking($ia); 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 .= "<br />\n<span class=\"questionhelp\">" . gT('Check any that apply') . '</span>'; $question_text['help'] = gT('Check any that apply'); } } break; case 'I': //Language Question $values = do_language($ia); if (count($values[1]) > 1) { $qtitle .= "<br />\n<span class=\"questionhelp\">" . gT('Choose your language') . '</span>'; $question_text['help'] = 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 .= "<br />\n<span class=\"questionhelp\">" . gT('Check any that apply') . '</span>'; $question_text['help'] = 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)) { //$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 = '<span class="asterisk">' . gT('*') . '</span>' . $qtitle; $question_text['mandatory'] = 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/' . $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: <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) { $matches = 0; $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) { $matches = 0; $oldtitle = $qtitle_custom; $qtitle_custom = preg_replace('/(<br(?: ?\\/)?>(?: |\\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, $name, $ia[2], $ia[5], $ia[1]); //New Return return array($qanda, $inputnames); }
/** * 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 or survey.php * * @param mixed $ia * @param mixed $notanswered * @param mixed $notvalidated * @param mixed $filenotvalidated * @return mixed */ function retrieveAnswers($ia, $notanswered=null, $notvalidated=null, $filenotvalidated=null) { //globalise required config variables global $dbprefix, $clang; //These are from the config-defaults.php file global $thissurvey, $gl; //These are set by index.php global $connect; //DISPLAY $display = $ia[7]; //QUESTION NAME $name = $ia[0]; $qtitle=$ia[3]; //Replace INSERTANS statements with previously provided answers; $qtitle=dTexts::run($qtitle); //GET HELP $hquery="SELECT help FROM {$dbprefix}questions WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."'"; $hresult=db_execute_num($hquery) or safe_die($connect->ErrorMsg()); //Checked $help=""; while ($hrow=$hresult->FetchRow()) {$help=$hrow[0];} //A bit of housekeeping to stop PHP Notices $answer = ""; if (!isset($_SESSION[$ia[1]])) {$_SESSION[$ia[1]] = "";} $qidattributes=getQuestionAttributes($ia[0],$ia[4]); //echo "<pre>";print_r($qidattributes);echo "</pre>"; //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] : ''; $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); break; case 'L': //LIST drop-down/radio-button list $values = do_list_radio($ia); if ($qidattributes['hide_tip']==0) { $qtitle .= "<br />\n<span class=\"questionhelp\">" . $clang->gT('Choose one of the following answers').'</span>'; $question_text['help'] = $clang->gT('Choose one of the following answers'); } break; case '!': //List - dropdown $values=do_list_dropdown($ia); if ($qidattributes['hide_tip']==0) { $qtitle .= "<br />\n<span class=\"questionhelp\">" . $clang->gT('Choose one of the following answers').'</span>'; $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 && $qidattributes['hide_tip']==0) { $qtitle .= "<br />\n<span class=\"questionhelp\">" . $clang->gT('Choose one of the following answers').'</span>'; $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 && $qidattributes['hide_tip']==0) { $question_text['help'] = $clang->gT("Click on an item in the list on the left, starting with your highest ranking item, moving through to your lowest ranking item."); if (trim($qidattributes['min_answers'])!='') { $qtitle .= "<br />\n<span class=\"questionhelp\">" . sprintf($clang->ngT("Check at least %d item","Check at least %d items",$qidattributes['min_answers']),$qidattributes['min_answers'])."</span>"; $question_text['help'] .=' '.sprintf($clang->ngT("Check at least %d item","Check at least %d items",$qidattributes['min_answers']),$qidattributes['min_answers']); } } break; case 'M': //Multiple choice checkbox $values=do_multiplechoice($ia); if (count($values[1]) > 1 && $qidattributes['hide_tip']==0) { $maxansw=trim($qidattributes['max_answers']); $minansw=trim($qidattributes['min_answers']); if (!($maxansw || $minansw)) { $qtitle .= "<br />\n<span class=\"questionhelp\">" . $clang->gT('Check any that apply').'</span>'; $question_text['help'] = $clang->gT('Check any that apply'); } else { if ($maxansw && $minansw) { $qtitle .= "<br />\n<span class=\"questionhelp\">" . sprintf($clang->gT("Check between %d and %d answers"), $minansw, $maxansw)."</span>"; $question_text['help'] = sprintf($clang->gT("Check between %d and %d answers"), $minansw, $maxansw); } elseif ($maxansw) { $qtitle .= "<br />\n<span class=\"questionhelp\">" . sprintf($clang->gT("Check at most %d answers"), $maxansw)."</span>"; $question_text['help'] = sprintf($clang->gT("Check at most %d answers"), $maxansw); } else { $qtitle .= "<br />\n<span class=\"questionhelp\">" . sprintf($clang->ngT("Check at least %d answer","Check at least %d answers",$minansw),$minansw)."</span>"; $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 .= "<br />\n<span class=\"questionhelp\">" . $clang->gT('Choose your language').'</span>'; $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 && $qidattributes['hide_tip']==0) { $maxansw=trim($qidattributes["max_answers"]); $minansw=trim($qidattributes["min_answers"]); if (!($maxansw || $minansw)) { $qtitle .= "<br />\n<span class=\"questionhelp\">" . $clang->gT('Check any that apply').'</span>'; $question_text['help'] = $clang->gT('Check any that apply'); } else { if ($maxansw && $minansw) { $qtitle .= "<br />\n<span class=\"questionhelp\">" . sprintf($clang->gT("Check between %d and %d answers"), $minansw, $maxansw)."</span>"; $question_text['help'] = sprintf($clang->gT("Check between %d and %d answers"), $minansw, $maxansw); } elseif ($maxansw) { $qtitle .= "<br />\n<span class=\"questionhelp\">" . sprintf($clang->gT("Check at most %d answers"), $maxansw)."</span>"; $question_text['help'] = sprintf($clang->gT("Check at most %d answers"), $maxansw); } else { $qtitle .= "<br />\n<span class=\"questionhelp\">" . sprintf($clang->gT("Check at least %d answers"), $minansw)."</span>"; $question_text['help'] = sprintf($clang->gT("Check at least %d answers"), $minansw); } } } break; case '|': //File Upload $values=do_file_upload($ia); if ($qidattributes['min_num_of_files'] != 0) { if (trim($qidattributes['min_num_of_files']) != 0) { $qtitle .= "<br />\n<span class = \"questionhelp\">" .sprintf($clang->gT("At least %d files must be uploaded for this question"), $qidattributes['min_num_of_files'])."<span>"; $question_text['help'] .= ' '.sprintf($clang->gT("At least %d files must be uploaded for this question"), $qidattributes['min_num_of_files']); } } 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; } //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; } $answer .= "\n\t<input type='hidden' name='display$ia[1]' id='display$ia[0]' value='"; $answer .= 'on'; //If this is single format, then it must be showing. Needed for checking conditional mandatories $answer .= "' />\n"; //for conditional mandatory questions if ($ia[6] == 'Y') { $qtitle = '<span class="asterisk">'.$clang->gT('*').'</span>'.$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 $qtitle .= mandatory_message($ia); $question_text['man_message'] = mandatory_message($ia); $qtitle .= validation_message($ia); $question_text['valid_message'] = validation_message($ia); $qtitle .= $ia[4] == "|" ? file_validation_message($ia) : ""; $question_text['file_valid_message'] = $ia[4] == "|" ? file_validation_message($ia) : ""; if(!empty($question_text['man_message']) || !empty($question_text['valid_message']) || !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. if(is_file('templates/'.validate_templatedir($thissurvey['template']).'/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(sGetTemplatePath($thissurvey['template']).'/question_start.pstpl' , true)); }; $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. { $matches = 0; $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. { $matches = 0; $oldtitle=$qtitle_custom; $qtitle_custom = preg_replace( '/(<br(?: ?\/)?>(?: |\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; }; // $qtitle = $qtitle_custom; $question_text['all'] = $qtitle_custom; } else { $question_text['all'] = $qtitle; }; // END: legacy question_start.pstpl code //=================================================================== // echo '<pre>[qanda.php] line '.__LINE__.": $question_text =\n".htmlspecialchars(print_r($question_text,true)).'</pre>'; $qtitle = $question_text; // ===================================================== $qanda=array($qtitle, $answer, $help, $display, $name, $ia[2], $gl[0], $ia[1] ); //New Return return array($qanda, $inputnames); }