/application/controllers/admin/printablesurvey.php
PHP | 1833 lines | 1445 code | 209 blank | 179 comment | 189 complexity | 2965d3075cfa139c9976cbc7df2c1b19 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, BSD-3-Clause, GPL-3.0, LGPL-3.0
Large files files are truncated, but you can click here to view the full file
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- /*
- * 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.
- *
- * $Id$
- */
- /**
- * Printable Survey Controller
- *
- * This controller shows a printable survey.
- *
- * @package LimeSurvey
- * @subpackage Backend
- */
- class printablesurvey extends Survey_Common_Action
- {
- /**
- * Show printable survey
- */
- function index($surveyid, $lang = null)
- {
- $surveyid = sanitize_int($surveyid);
- if(!hasSurveyPermission($surveyid,'surveycontent','read'))
- {
- $clang = $this->getController()->lang;
- $aData['surveyid'] = $surveyid;
- $this->getController()->_css_admin_includes(Yii::app()->getConfig('adminstyleurl')."superfish.css");
- $message['title']= $clang->gT('Access denied!');
- $message['message']= $clang->gT('You do not have sufficient rights to access this page.');
- $message['class']= "error";
- $this->_renderWrappedTemplate('survey', array("message"=>$message), $aData);
- }
- else
- {
- // PRESENT SURVEY DATAENTRY SCREEN
- // Set the language of the survey, either from GET parameter of session var
- if (isset($lang))
- {
- $lang = preg_replace("/[^a-zA-Z0-9-]/", "", $lang);
- if ($lang) $surveyprintlang = $lang;
- } else
- {
- $surveyprintlang=getBaseLanguageFromSurveyID((int) $surveyid);
- }
- $_POST['surveyprintlang']=$surveyprintlang;
- // Setting the selected language for printout
- $clang = new limesurvey_lang($surveyprintlang);
- $desrow = Survey::model()->with(array('languagesettings'=>array('condition'=>'surveyls_language=:language','params'=>array(':language'=>$surveyprintlang))))->findByAttributes(array('sid' => $surveyid));
- if (is_null($desrow))
- $this->getController()->error('Invalid survey ID');
- $desrow = array_merge($desrow->attributes, $desrow->languagesettings[0]->attributes);
- //echo '<pre>'.print_r($desrow,true).'</pre>';
- $template = $desrow['template'];
- $welcome = $desrow['surveyls_welcometext'];
- $end = $desrow['surveyls_endtext'];
- $surveyname = $desrow['surveyls_title'];
- $surveydesc = $desrow['surveyls_description'];
- $surveyactive = $desrow['active'];
- $surveytable = "{{survey_".$desrow['sid']."}}";
- $surveyexpirydate = $desrow['expires'];
- $surveyfaxto = $desrow['faxto'];
- $dateformattype = $desrow['surveyls_dateformat'];
- Yii::app()->loadHelper('surveytranslator');
-
- if (!is_null($surveyexpirydate))
- {
- $dformat=getDateFormatData($dateformattype);
- $dformat=$dformat['phpdate'];
- $expirytimestamp = strtotime($surveyexpirydate);
- $expirytimeofday_h = date('H',$expirytimestamp);
- $expirytimeofday_m = date('i',$expirytimestamp);
- $surveyexpirydate = date($dformat,$expirytimestamp);
- if(!empty($expirytimeofday_h) || !empty($expirytimeofday_m))
- {
- $surveyexpirydate .= ' – '.$expirytimeofday_h.':'.$expirytimeofday_m;
- };
- sprintf($clang->gT("Please submit by %s"), $surveyexpirydate);
- }
- else
- {
- $surveyexpirydate='';
- }
- if(is_file(Yii::app()->getConfig('usertemplaterootdir').DIRECTORY_SEPARATOR.$template.DIRECTORY_SEPARATOR.'print_survey.pstpl'))
- {
- define('PRINT_TEMPLATE_DIR' , Yii::app()->getConfig('usertemplaterootdir').DIRECTORY_SEPARATOR.$template.DIRECTORY_SEPARATOR , true);
- define('PRINT_TEMPLATE_URL' , Yii::app()->getConfig('usertemplaterooturl').'/'.$template.'/' , true);
- }
- elseif(is_file(Yii::app()->getConfig('usertemplaterootdir').'/'.$template.'/print_survey.pstpl'))
- {
- define('PRINT_TEMPLATE_DIR' , Yii::app()->getConfig('standardtemplaterootdir').DIRECTORY_SEPARATOR.$template.DIRECTORY_SEPARATOR , true);
- define('PRINT_TEMPLATE_URL' , Yii::app()->getConfig('standardtemplaterooturl').'/'.$template.'/' , true);
- }
- else
- {
- define('PRINT_TEMPLATE_DIR' , Yii::app()->getConfig('standardtemplaterootdir').DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR , true);
- define('PRINT_TEMPLATE_URL' , Yii::app()->getConfig('standardtemplaterooturl').'/default/' , true);
- }
- LimeExpressionManager::StartSurvey($surveyid, 'survey',NULL,false,LEM_PRETTY_PRINT_ALL_SYNTAX);
- $moveResult = LimeExpressionManager::NavigateForwards();
- $condition = "sid = '{$surveyid}' AND language = '{$surveyprintlang}'";
- $degresult = Groups::model()->getAllGroups($condition, array('group_order')); //xiao,
- if (!isset($surveyfaxto) || !$surveyfaxto and isset($surveyfaxnumber))
- {
- $surveyfaxto=$surveyfaxnumber; //Use system fax number if none is set in survey.
- }
- $headelements = getPrintableHeader();
- //if $showsgqacode is enabled at config.php show table name for reference
- $showsgqacode = Yii::app()->getConfig("showsgqacode");
- if(isset($showsgqacode) && $showsgqacode == true)
- {
- $surveyname = $surveyname."<br />[".$clang->gT('Database')." ".$clang->gT('table').": $surveytable]";
- }
- else
- {
- $surveyname = $surveyname;
- }
- $survey_output = array(
- 'SITENAME' => Yii::app()->getConfig("sitename")
- ,'SURVEYNAME' => $surveyname
- ,'SURVEYDESCRIPTION' => $surveydesc
- ,'WELCOME' => $welcome
- ,'END' => $end
- ,'THEREAREXQUESTIONS' => 0
- ,'SUBMIT_TEXT' => $clang->gT("Submit Your Survey.")
- ,'SUBMIT_BY' => $surveyexpirydate
- ,'THANKS' => $clang->gT("Thank you for completing this survey.")
- ,'HEADELEMENTS' => $headelements
- ,'TEMPLATEURL' => PRINT_TEMPLATE_URL
- ,'FAXTO' => $surveyfaxto
- ,'PRIVACY' => ''
- ,'GROUPS' => ''
- );
- $survey_output['FAX_TO'] ='';
- if(!empty($surveyfaxto) && $surveyfaxto != '000-00000000') //If no fax number exists, don't display faxing information!
- {
- $survey_output['FAX_TO'] = $clang->gT("Please fax your completed survey to:")." $surveyfaxto";
- }
- /**
- * Output arrays:
- * $survey_output = final vaiables for whole survey
- * $survey_output['SITENAME'] =
- * $survey_output['SURVEYNAME'] =
- * $survey_output['SURVEY_DESCRIPTION'] =
- * $survey_output['WELCOME'] =
- * $survey_output['THEREAREXQUESTIONS'] =
- * $survey_output['PDF_FORM'] =
- * $survey_output['HEADELEMENTS'] =
- * $survey_output['TEMPLATEURL'] =
- * $survey_output['SUBMIT_TEXT'] =
- * $survey_output['SUBMIT_BY'] =
- * $survey_output['THANKS'] =
- * $survey_output['FAX_TO'] =
- * $survey_output['SURVEY'] = contains an array of all the group arrays
- *
- * $groups[] = an array of all the groups output
- * $group['GROUPNAME'] =
- * $group['GROUPDESCRIPTION'] =
- * $group['QUESTIONS'] = templated formatted content if $question is appended to this at the end of processing each question.
- * $group['ODD_EVEN'] = class to differentiate alternate groups
- * $group['SCENARIO'] =
- *
- * $questions[] = contains an array of all the questions within a group
- * $question['QUESTION_CODE'] = content of the question code field
- * $question['QUESTION_TEXT'] = content of the question field
- * $question['QUESTION_SCENARIO'] = if there are conditions on a question, list the conditions.
- * $question['QUESTION_MANDATORY'] = translated 'mandatory' identifier
- * $question['QUESTION_CLASS'] = classes to be added to wrapping question div
- * $question['QUESTION_TYPE_HELP'] = instructions on how to complete the question
- * $question['QUESTION_MAN_MESSAGE'] = (not sure if this is used) mandatory error
- * $question['QUESTION_VALID_MESSAGE'] = (not sure if this is used) validation error
- * $question['ANSWER'] = contains formatted HTML answer
- * $question['QUESTIONHELP'] = content of the question help field.
- *
- */
- $total_questions = 0;
- $mapquestionsNumbers=Array();
- $answertext = ''; // otherwise can throw an error on line 1617
- // =========================================================
- // START doin the business:
- foreach ($degresult->readAll() as $degrow)
- {
- // ---------------------------------------------------
- // START doing groups
- $deqresult=Questions::model()->getQuestions($surveyid, $degrow['gid'], $surveyprintlang, 0, '"I"');
- $deqrows = array(); //Create an empty array in case FetchRow does not return any rows
- foreach ($deqresult->readAll() as $deqrow) {$deqrows[] = $deqrow;} // Get table output into array
- // Perform a case insensitive natural sort on group name then question title of a multidimensional array
- usort($deqrows, 'groupOrderThenQuestionOrder');
- if ($degrow['description'])
- {
- $group_desc = $degrow['description'];
- }
- else
- {
- $group_desc = '';
- }
- $group = array(
- 'GROUPNAME' => $degrow['group_name']
- ,'GROUPDESCRIPTION' => $group_desc
- ,'QUESTIONS' => '' // templated formatted content if $question is appended to this at the end of processing each question.
- );
- // A group can have only hidden questions. In that case you don't want to see the group's header/description either.
- $bGroupHasVisibleQuestions = false;
- $gid = $degrow['gid'];
- //Alternate bgcolor for different groups
- if (!isset($group['ODD_EVEN']) || $group['ODD_EVEN'] == ' g-row-even')
- {
- $group['ODD_EVEN'] = ' g-row-odd';}
- else
- {
- $group['ODD_EVEN'] = ' g-row-even';
- }
- //Loop through questions
- foreach ($deqrows as $deqrow)
- {
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- // START doing questions
- $qidattributes=getQuestionAttributeValues($deqrow['qid'],$deqrow['type']);
- if ($qidattributes['hidden'] == 1 && $deqrow['type'] != '*')
- {
- continue;
- }
- $bGroupHasVisibleQuestions = true;
- //GET ANY CONDITIONS THAT APPLY TO THIS QUESTION
- $printablesurveyoutput = '';
- $sExplanation = ''; //reset conditions explanation
- $s=0;
- // TMSW Conditions->Relevance: show relevance instead of this whole section to create $explanation
- $scenarioresult=Conditions::model()->getScenarios($deqrow['qid']);
- $scenarioresult = $scenarioresult->readAll();
- //Loop through distinct scenarios, thus grouping them together.
- foreach ($scenarioresult as $scenariorow)
- {
- if( $s == 0 && count($scenarioresult) > 1)
- {
- $sExplanation .= '<p class="scenario">'.self::_try_debug(__LINE__)." -------- Scenario {$scenariorow['scenario']} --------</p>\n\n";
- }
- if($s > 0)
- {
- $sExplanation .= '<p class="scenario">'.self::_try_debug(__LINE__).' -------- '.$clang->gT("or")." Scenario {$scenariorow['scenario']} --------</p>\n\n";
- }
- $x=0;
- $conditions1="qid={$deqrow['qid']} AND scenario={$scenariorow['scenario']}";
- $distinctresult=Conditions::model()->getSomeConditions(array('cqid','method', 'cfieldname', 'value'), $conditions1, array('cqid'),array('cqid', 'method'));
- //Loop through each condition for a particular scenario.
- foreach ($distinctresult->readAll() as $distinctrow)
- {
- $condition = "qid = '{$distinctrow['cqid']}' AND parent_qid = 0 AND language = '{$surveyprintlang}'";
- $subresult=Questions::model()->find($condition);
- if($x > 0)
- {
- $sExplanation .= ' <em class="scenario-and-seperator">'.$clang->gT('and').'</em> ';
- }
- if(trim($distinctrow['method'])=='') //If there is no method chosen assume "equals"
- {
- $distinctrow['method']='==';
- }
- if($distinctrow['cqid']){ // cqid != 0 ==> previous answer match
- if($distinctrow['method']=='==')
- {
- $sExplanation .= $clang->gT("Answer was")." ";
- }
- elseif($distinctrow['method']=='!=')
- {
- $sExplanation .= $clang->gT("Answer was NOT")." ";
- }
- elseif($distinctrow['method']=='<')
- {
- $sExplanation .= $clang->gT("Answer was less than")." ";
- }
- elseif($distinctrow['method']=='<=')
- {
- $sExplanation .= $clang->gT("Answer was less than or equal to")." ";
- }
- elseif($distinctrow['method']=='>=')
- {
- $sExplanation .= $clang->gT("Answer was greater than or equal to")." ";
- }
- elseif($distinctrow['method']=='>')
- {
- $sExplanation .= $clang->gT("Answer was greater than")." ";
- }
- elseif($distinctrow['method']=='RX')
- {
- $sExplanation .= $clang->gT("Answer matched (regexp)")." ";
- }
- else
- {
- $sExplanation .= $clang->gT("Answer was")." ";
- }
- if($distinctrow['value'] == '') {
- $sExplanation .= ' '.$clang->gT("Not selected").' ';
- }
- //If question type is numerical or multi-numerical, show the actual value - otherwise, don't.
- if($subresult['type'] == 'N' || $subresult['type'] == 'K') {
- $sExplanation .= ' '.$distinctrow['value']. ' ';
- }
- }
- if(!$distinctrow['cqid']) { // cqid == 0 ==> token attribute match
- $tokenData = getTokenFieldsAndNames($surveyid);
- preg_match('/^{TOKEN:([^}]*)}$/',$distinctrow['cfieldname'],$extractedTokenAttr);
- $sExplanation .= "Your ".$tokenData[strtolower($extractedTokenAttr[1])]." ";
- if($distinctrow['method']=='==')
- {
- $sExplanation .= $clang->gT("is")." ";
- }
- elseif($distinctrow['method']=='!=')
- {
- $sExplanation .= $clang->gT("is NOT")." ";
- }
- elseif($distinctrow['method']=='<')
- {
- $sExplanation .= $clang->gT("is less than")." ";
- }
- elseif($distinctrow['method']=='<=')
- {
- $sExplanation .= $clang->gT("is less than or equal to")." ";
- }
- elseif($distinctrow['method']=='>=')
- {
- $sExplanation .= $clang->gT("is greater than or equal to")." ";
- }
- elseif($distinctrow['method']=='>')
- {
- $sExplanation .= $clang->gT("is greater than")." ";
- }
- elseif($distinctrow['method']=='RX')
- {
- $sExplanation .= $clang->gT("is matched (regexp)")." ";
- }
- else
- {
- $sExplanation .= $clang->gT("is")." ";
- }
- $answer_section = ' '.$distinctrow['value'].' ';
- }
- $conresult=Conditions::model()->getConditionsQuestions($distinctrow['cqid'],$deqrow['qid'],$scenariorow['scenario'],$surveyprintlang);
- $conditions=array();
- foreach ($conresult->readAll() as $conrow)
- {
- $postans="";
- $value=$conrow['value'];
- switch($conrow['type'])
- {
- case "Y":
- switch ($conrow['value'])
- {
- case "Y": $conditions[]=$clang->gT("Yes"); break;
- case "N": $conditions[]=$clang->gT("No"); break;
- }
- break;
- case "G":
- switch($conrow['value'])
- {
- case "M": $conditions[]=$clang->gT("Male"); break;
- case "F": $conditions[]=$clang->gT("Female"); break;
- } // switch
- break;
- case "A":
- case "B":
- case ":":
- case ";":
- $conditions[]=$conrow['value'];
- break;
- case "C":
- switch($conrow['value'])
- {
- case "Y": $conditions[]=$clang->gT("Yes"); break;
- case "U": $conditions[]=$clang->gT("Uncertain"); break;
- case "N": $conditions[]=$clang->gT("No"); break;
- } // switch
- break;
- case "E":
- switch($conrow['value'])
- {
- case "I": $conditions[]=$clang->gT("Increase"); break;
- case "D": $conditions[]=$clang->gT("Decrease"); break;
- case "S": $conditions[]=$clang->gT("Same"); break;
- }
- case "1":
- $labelIndex=preg_match("/^[^#]+#([01]{1})$/",$conrow['cfieldname']);
- if ($labelIndex == 0)
- { // TIBO
- $condition="qid='{$conrow['cqid']}' AND code='{$conrow['value']}' AND scale_id=0 AND language='{$surveyprintlang}'";
- $fresult=Answers::model()->getAllRecords($condition);
- foreach($fresult->readAll() as $frow)
- {
- $postans=$frow['answer'];
- $conditions[]=$frow['answer'];
- } // while
- }
- elseif ($labelIndex == 1)
- {
- $condition="qid='{$conrow['cqid']}' AND code='{$conrow['value']}' AND scale_id=1 AND language='{$surveyprintlang}'";
- $fresult=Answers::model()->getAllRecords($condition);
- foreach($fresult->readAll() as $frow)
- {
- $postans=$frow['answer'];
- $conditions[]=$frow['answer'];
- } // while
- }
- break;
- case "L":
- case "!":
- case "O":
- case "R":
- $condition="qid='{$conrow['cqid']}' AND code='{$conrow['value']}' AND language='{$surveyprintlang}'";
- $ansresult=Answers::model()->findAll($condition);
- foreach ($ansresult as $ansrow)
- {
- $conditions[]=$ansrow['answer'];
- }
- if($conrow['value'] == "-oth-") {
- $conditions[]=$clang->gT("Other");
- }
- $conditions = array_unique($conditions);
- break;
- case "M":
- case "P":
- $condition=" parent_qid='{$conrow['cqid']}' AND title='{$conrow['value']}' AND language='{$surveyprintlang}'";
- $ansresult=Questions::model()->findAll($condition);
- foreach ($ansresult as $ansrow)
- {
- $conditions[]=$ansrow['question'];
- }
- $conditions = array_unique($conditions);
- break;
- case "N":
- $conditions[]=$value;
- break;
- case "F":
- case "H":
- default:
- $value=substr($conrow['cfieldname'], strpos($conrow['cfieldname'], "X".$conrow['cqid'])+strlen("X".$conrow['cqid']), strlen($conrow['cfieldname']));
- $condition=" qid='{$conrow['cqid']}' AND code='{$conrow['value']}' AND language='{$surveyprintlang}'";
- $fresult=Answers::model()->getAllRecords($condition);
- foreach ($fresult->readAll() as $frow)
- {
- $postans=$frow['answer'];
- $conditions[]=$frow['answer'];
- } // while
- break;
- } // switch
- // Now let's complete the answer text with the answer_section
- $answer_section="";
- switch($conrow['type'])
- {
- case "A":
- case "B":
- case "C":
- case "E":
- case "F":
- case "H":
- case "K":
- $thiscquestion=$fieldmap[$conrow['cfieldname']];
- $condition="parent_qid='{$conrow['cqid']}' AND title='{$thiscquestion['aid']}' AND language='{$surveyprintlang}'";
- $ansresult= Questions::model()->findAll($condition);
- foreach ($ansresult as $ansrow)
- {
- $answer_section=" (".$ansrow['question'].")";
- }
- break;
- case "1": // dual: (Label 1), (Label 2)
- $labelIndex=substr($conrow['cfieldname'],-1);
- $thiscquestion=$fieldmap[$conrow['cfieldname']];
- $condition="parent_qid='{$conrow['cqid']}' AND title='{$thiscquestion['aid']}' AND language='{$surveyprintlang}'";
- $ansresult= Questions::model()->findAll($condition);
- $cqidattributes = getQuestionAttributeValues($conrow['cqid'], $conrow['type']);
- if ($labelIndex == 0)
- {
- if (trim($cqidattributes['dualscale_headerA']) != '') {
- $header = $clang->gT($cqidattributes['dualscale_headerA']);
- } else {
- $header = '1';
- }
- }
- elseif ($labelIndex == 1)
- {
- if (trim($cqidattributes['dualscale_headerB']) != '') {
- $header = $clang->gT($cqidattributes['dualscale_headerB']);
- } else {
- $header = '2';
- }
- }
- foreach ($ansresult->readAll() as $ansrow)
- {
- $answer_section=" (".$ansrow['question']." ".sprintf($clang->gT("Label %s"),$header).")";
- }
- break;
- case ":":
- case ";": //multi flexi: ( answer [label] )
- $thiscquestion=$fieldmap[$conrow['cfieldname']];
- $condition="parent_qid='{$conrow['cqid']}' AND title='{$thiscquestion['aid']}' AND language='{$surveyprintlang}'";
- $ansresult= Questions::model()->findAll($condition);
- foreach ($ansresult as $ansrow)
- {
- $condition = "qid = '{$conrow['cqid']}' AND code = '{$conrow['value']}' AND language= '{$surveyprintlang}'";
- $fresult= Answers::model()->findAll($condition);
- foreach ($fresult as $frow)
- {
- //$conditions[]=$frow['title'];
- $answer_section=" (".$ansrow['question']."[".$frow['answer']."])";
- } // while
- }
- break;
- case "R": // (Rank 1), (Rank 2)... TIBO
- $thiscquestion=$fieldmap[$conrow['cfieldname']];
- $rankid=$thiscquestion['aid'];
- $answer_section=" (".$clang->gT("RANK")." $rankid)";
- break;
- default: // nothing to add
- break;
- }
- }
- if (count($conditions) > 1)
- {
- $sExplanation .= "'".implode("' <em class='scenario-or-seperator'>".$clang->gT("or")."</em> '", $conditions)."'";
- }
- elseif (count($conditions) == 1)
- {
- $sExplanation .= "'".$conditions[0]."'";
- }
- unset($conditions);
- // Following line commented out because answer_section was lost, but is required for some question types
- //$explanation .= " ".$clang->gT("to question")." '".$mapquestionsNumbers[$distinctrow['cqid']]."' $answer_section ";
- if($distinctrow['cqid']){
- $sExplanation .= " <span class='scenario-at-seperator'>".$clang->gT("at question")."</span> '".$mapquestionsNumbers[$distinctrow['cqid']]." [".$subresult['title']."]' (".strip_tags($subresult['question'])."$answer_section)" ;
- }
- else{
- $sExplanation .= " ".$distinctrow['value'] ;
- }
- //$distinctrow
- $x++;
- }
- $s++;
- }
- $qinfo = LimeExpressionManager::GetQuestionStatus($deqrow['qid']);
- $relevance = trim($qinfo['info']['relevance']);
- $sEquation = $qinfo['relEqn'];
- if (trim($relevance) != '' && trim($relevance) != '1')
- {
- if (isset($qidattributes['printable_help'][$surveyprintlang]) && $qidattributes['printable_help'][$surveyprintlang]!='')
- {
- $sExplanation=$qidattributes['printable_help'][$surveyprintlang];
- }
- elseif ($sExplanation=='') // There is only a relevance equation without conditions
- {
- $sExplanation=$sEquation;
- $sEquation=' '; // No need to show it twice
- }
- $sExplanation = "<b>".$clang->gT('Only answer this question if the following conditions are met:')."</b><br/> ".$sExplanation;
- if (Yii::app()->getConfig('showrelevance'))
- {
- $sExplanation.="<span class='printable_equation'><br>".$sEquation."</span>";
- }
- }
- else
- {
- $sExplanation = '';
- }
- ++$total_questions;
- //TIBO map question qid to their q number
- $mapquestionsNumbers[$deqrow['qid']]=$total_questions;
- //END OF GETTING CONDITIONS
- $qid = $deqrow['qid'];
- $fieldname = "$surveyid"."X"."$gid"."X"."$qid";
- if(isset($showsgqacode) && $showsgqacode == true)
- {
- $deqrow['question'] = $deqrow['question']."<br />".$clang->gT("ID:")." $fieldname <br />".
- $clang->gT("Question code:")." ".$deqrow['title'];
- }
- $question = array(
- 'QUESTION_NUMBER' => $total_questions // content of the question code field
- ,'QUESTION_CODE' => $deqrow['title']
- ,'QUESTION_TEXT' => preg_replace('/(?:<br ?\/?>|<\/(?:p|h[1-6])>)$/is' , '' , $deqrow['question']) // content of the question field
- ,'QUESTION_SCENARIO' => $sExplanation // if there are conditions on a question, list the conditions.
- ,'QUESTION_MANDATORY' => '' // translated 'mandatory' identifier
- ,'QUESTION_ID' => $deqrow['qid'] // id to be added to wrapping question div
- ,'QUESTION_CLASS' => getQuestionClass( $deqrow['type']) // classes to be added to wrapping question div
- ,'QUESTION_TYPE_HELP' => $qinfo['validTip'] // '' // instructions on how to complete the question // prettyValidTip is too verbose; assuming printable surveys will use static values
- ,'QUESTION_MAN_MESSAGE' => '' // (not sure if this is used) mandatory error
- ,'QUESTION_VALID_MESSAGE' => '' // (not sure if this is used) validation error
- ,'QUESTION_FILE_VALID_MESSAGE' => ''// (not sure if this is used) file validation error
- ,'QUESTIONHELP' => '' // content of the question help field.
- ,'ANSWER' => '' // contains formatted HTML answer
- );
- if($question['QUESTION_TYPE_HELP'] != "") {
- $question['QUESTION_TYPE_HELP'] .= "<br />\n";
- }
- if ($deqrow['mandatory'] == 'Y')
- {
- $question['QUESTION_MANDATORY'] = $clang->gT('*');
- $question['QUESTION_CLASS'] .= ' mandatory';
- }
- //DIFFERENT TYPES OF DATA FIELD HERE
- if ($deqrow['help'])
- {
- $question['QUESTIONHELP'] = $deqrow['help'];
- }
- if (!empty($qidattributes['page_break']))
- {
- $question['QUESTION_CLASS'] .=' breakbefore ';
- }
- if (isset($qidattributes['maximum_chars']) && $qidattributes['maximum_chars']!='') {
- $question['QUESTION_CLASS'] ="max-chars-{$qidattributes['maximum_chars']} ".$question['QUESTION_CLASS'];
- }
- switch($deqrow['type'])
- {
- // ==================================================================
- case "5": //5 POINT CHOICE
- $question['QUESTION_TYPE_HELP'] .= $clang->gT('Please choose *only one* of the following:');
- $question['ANSWER'] .= "\n\t<ul>\n";
- for ($i=1; $i<=5; $i++)
- {
- $question['ANSWER'] .="\t\t<li>\n\t\t\t".self::_input_type_image('radio',$i)."\n\t\t\t$i ".self::_addsgqacode("($i)")."\n\t\t</li>\n";
- }
- $question['ANSWER'] .="\t</ul>\n";
- break;
- // ==================================================================
- case "D": //DATE
- $question['QUESTION_TYPE_HELP'] .= $clang->gT('Please enter a date:');
- $question['ANSWER'] .= "\t".self::_input_type_image('text',$question['QUESTION_TYPE_HELP'],30,1);
- break;
- // ==================================================================
- case "G": //GENDER
- $question['QUESTION_TYPE_HELP'] .= $clang->gT("Please choose *only one* of the following:");
- $question['ANSWER'] .= "\n\t<ul>\n";
- $question['ANSWER'] .= "\t\t<li>\n\t\t\t".self::_input_type_image('radio',$clang->gT("Female"))."\n\t\t\t".$clang->gT("Female")." ".self::_addsgqacode("(F)")."\n\t\t</li>\n";
- $question['ANSWER'] .= "\t\t<li>\n\t\t\t".self::_input_type_image('radio',$clang->gT("Male"))."\n\t\t\t".$clang->gT("Male")." ".self::_addsgqacode("(M)")."\n\t\t</li>\n";
- $question['ANSWER'] .= "\t</ul>\n";
- break;
- // ==================================================================
- case "L": //LIST drop-down/radio-button list
- // ==================================================================
- case "!": //List - dropdown
- if (isset($qidattributes['display_columns']) && trim($qidattributes['display_columns'])!='')
- {
- $dcols=$qidattributes['display_columns'];
- }
- else
- {
- $dcols=0;
- }
- if (isset($qidattributes['category_separator']) && trim($qidattributes['category_separator'])!='') {
- $optCategorySeparator = $qidattributes['category_separator'];
- }
- else
- {
- unset($optCategorySeparator);
- }
- $question['QUESTION_TYPE_HELP'] .= $clang->gT("Please choose *only one* of the following:");
- $question['QUESTION_TYPE_HELP'] .= self::_array_filter_help($qidattributes, $surveyprintlang, $surveyid);
- $dearesult=Answers::model()->getAllRecords(" qid='{$deqrow['qid']}' AND language='{$surveyprintlang}' ", array('sortorder','answer'));
- $dearesult=$dearesult->readAll();
- $deacount=count($dearesult);
- if ($deqrow['other'] == "Y") {$deacount++;}
- $wrapper = setupColumns(0, $deacount);
- $question['ANSWER'] = $wrapper['whole-start'];
- $rowcounter = 0;
- $colcounter = 1;
- foreach ($dearesult as $dearow)
- {
- if (isset($optCategorySeparator))
- {
- list ($category, $answer) = explode($optCategorySeparator,$dearow['answer']);
- if ($category != '')
- {
- $dearow['answer'] = "($category) $answer ".self::_addsgqacode("(".$dearow['code'].")");
- }
- else
- {
- $dearow['answer'] = $answer.self::_addsgqacode(" (".$dearow['code'].")");
- }
- $question['ANSWER'] .= "\t".$wrapper['item-start']."\t\t".self::_input_type_image('radio' , $dearow['answer'])."\n\t\t\t".$dearow['answer']."\n".$wrapper['item-end'];
- }
- else
- {
- $question['ANSWER'] .= "\t".$wrapper['item-start']."\t\t".self::_input_type_image('radio' , $dearow['answer'])."\n\t\t\t".$dearow['answer'].self::_addsgqacode(" (".$dearow['code'].")")."\n".$wrapper['item-end'];
- }
- ++$rowcounter;
- if ($rowcounter == $wrapper['maxrows'] && $colcounter < $wrapper['cols'])
- {
- if($colcounter == $wrapper['cols'] - 1)
- {
- $question['ANSWER'] .= $wrapper['col-devide-last'];
- }
- else
- {
- $question['ANSWER'] .= $wrapper['col-devide'];
- }
- $rowcounter = 0;
- ++$colcounter;
- }
- }
- if ($deqrow['other'] == 'Y')
- {
- if(trim($qidattributes["other_replace_text"][$surveyprintlang])=='')
- {$qidattributes["other_replace_text"][$surveyprintlang]="Other";}
- // $printablesurveyoutput .="\t".$wrapper['item-start']."\t\t".self::_input_type_image('radio' , $clang->gT("Other"))."\n\t\t\t".$clang->gT("Other")."\n\t\t\t<input type='text' size='30' readonly='readonly' />\n".$wrapper['item-end'];
- $question['ANSWER'] .= $wrapper['item-start-other'].self::_input_type_image('radio',$clang->gT($qidattributes["other_replace_text"][$surveyprintlang])).' '.$clang->gT($qidattributes["other_replace_text"][$surveyprintlang]).self::_addsgqacode(" (-oth-)")."\n\t\t\t".self::_input_type_image('other').self::_addsgqacode(" (".$deqrow['sid']."X".$deqrow['gid']."X".$deqrow['qid']."other)")."\n".$wrapper['item-end'];
- }
- $question['ANSWER'] .= $wrapper['whole-end'];
- //Let's break the presentation into columns.
- break;
- // ==================================================================
- case "O": //LIST WITH COMMENT
- $question['QUESTION_TYPE_HELP'] .= $clang->gT("Please choose *only one* of the following:");
- $dearesult=Answers::model()->getAllRecords(" qid='{$deqrow['qid']}' AND language='{$surveyprintlang}'", array('sortorder', 'answer') );
- $question['ANSWER'] = "\t<ul>\n";
- foreach ($dearesult->readAll() as $dearow)
- {
- $question['ANSWER'] .= "\t\t<li>\n\t\t\t".self::_input_type_image('radio',$dearow['answer'])."\n\t\t\t".$dearow['answer'].self::_addsgqacode(" (".$dearow['code'].")")."\n\t\t</li>\n";
- }
- $question['ANSWER'] .= "\t</ul>\n";
- $question['ANSWER'] .= "\t<p class=\"comment\">\n\t\t".$clang->gT("Make a comment on your choice here:")."\n";
- $question['ANSWER'] .= "\t\t".self::_input_type_image('textarea',$clang->gT("Make a comment on your choice here:"),50,8).self::_addsgqacode(" (".$deqrow['sid']."X".$deqrow['gid']."X".$deqrow['qid']."comment)")."\n\t</p>\n";
- break;
- // ==================================================================
- case "R": //RANKING Type Question
- $rearesult=Answers::model()->getAllRecords(" qid='{$deqrow['qid']}' AND language='{$surveyprintlang}'", array('sortorder', 'answer'));
- $rearesult = $rearesult->readAll();
- $reacount = count($rearesult);
- $question['QUESTION_TYPE_HELP'] .= $clang->gT("Please number each box in order of preference from 1 to")." $reacount";
- $question['QUESTION_TYPE_HELP'] .= self::_min_max_answers_help($qidattributes, $surveyprintlang, $surveyid);
- $question['ANSWER'] = "\n<ul>\n";
- foreach ($rearesult as $rearow)
- {
- $question['ANSWER'] .="\t<li>\n\t".self::_input_type_image('rank','',4,1)."\n\t\t ".$rearow['answer'].self::_addsgqacode(" (".$fieldname.$rearow['code'].")")."\n\t</li>\n";
- }
- $question['ANSWER'] .= "\n</ul>\n";
- break;
- // ==================================================================
- case "M": //Multiple choice (Quite tricky really!)
- if (trim($qidattributes['display_columns'])!='')
- {
- $dcols=$qidattributes['display_columns'];
- }
- else
- {
- $dcols=0;
- }
- $question['QUESTION_TYPE_HELP'] .= $clang->gT("Please choose *all* that apply:");
- $question['QUESTION_TYPE_HELP'] .= self::_array_filter_help($qidattributes, $surveyprintlang, $surveyid);
- $mearesult = Questions::model()->getAllRecords(" parent_qid='{$deqrow['qid']}' AND language='{$surveyprintlang}' ", array('question_order'));
- $mearesult = $mearesult->readAll();
- $meacount = count($mearesult);
- if ($deqrow['other'] == 'Y') {$meacount++;}
- $wrapper = setupColumns($dcols, $meacount);
- $question['ANSWER'] = $wrapper['whole-start'];
- $rowcounter = 0;
- $colcounter = 1;
- foreach ($mearesult as $mearow)
- {
- $question['ANSWER'] .= $wrapper['item-star…
Large files files are truncated, but you can click here to view the full file