PageRenderTime 65ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 1ms

/application/controllers/admin/printablesurvey.php

https://bitbucket.org/sammousa/valuematchbv-ls2
PHP | 1827 lines | 1446 code | 204 blank | 177 comment | 189 complexity | eded729a03d39c1f741bc4307e2d22fb 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

  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /*
  3. * LimeSurvey
  4. * Copyright (C) 2007-2011 The LimeSurvey Project Team / Carsten Schmitz
  5. * All rights reserved.
  6. * License: GNU/GPL License v2 or later, see LICENSE.php
  7. * LimeSurvey is free software. This version may have been modified pursuant
  8. * to the GNU General Public License, and as distributed it includes or
  9. * is derivative of works licensed under the GNU General Public License or
  10. * other free or open source software licenses.
  11. * See COPYRIGHT.php for copyright notices and details.
  12. *
  13. * $Id$
  14. */
  15. /**
  16. * Printable Survey Controller
  17. *
  18. * This controller shows a printable survey.
  19. *
  20. * @package LimeSurvey
  21. * @subpackage Backend
  22. */
  23. class printablesurvey extends Survey_Common_Action
  24. {
  25. /**
  26. * Show printable survey
  27. */
  28. function index($surveyid, $lang = null)
  29. {
  30. $surveyid = sanitize_int($surveyid);
  31. if(!hasSurveyPermission($surveyid,'surveycontent','read'))
  32. {
  33. $clang = $this->getController()->lang;
  34. $aData['surveyid'] = $surveyid;
  35. $this->getController()->_css_admin_includes(Yii::app()->getConfig('adminstyleurl')."superfish.css");
  36. $message['title']= $clang->gT('Access denied!');
  37. $message['message']= $clang->gT('You do not have sufficient rights to access this page.');
  38. $message['class']= "error";
  39. $this->_renderWrappedTemplate('survey', array("message"=>$message), $aData);
  40. }
  41. else
  42. {
  43. // PRESENT SURVEY DATAENTRY SCREEN
  44. // Set the language of the survey, either from GET parameter of session var
  45. if (isset($lang))
  46. {
  47. $lang = preg_replace("/[^a-zA-Z0-9-]/", "", $lang);
  48. if ($lang) $surveyprintlang = $lang;
  49. } else
  50. {
  51. $surveyprintlang=getBaseLanguageFromSurveyID((int) $surveyid);
  52. }
  53. $_POST['surveyprintlang']=$surveyprintlang;
  54. // Setting the selected language for printout
  55. $clang = new limesurvey_lang($surveyprintlang);
  56. $desrow = Survey::model()->with(array('languagesettings'=>array('condition'=>'surveyls_language=:language','params'=>array(':language'=>$surveyprintlang))))->findByAttributes(array('sid' => $surveyid));
  57. if (is_null($desrow))
  58. $this->getController()->error('Invalid survey ID');
  59. $desrow = array_merge($desrow->attributes, $desrow->languagesettings[0]->attributes);
  60. //echo '<pre>'.print_r($desrow,true).'</pre>';
  61. $template = $desrow['template'];
  62. $welcome = $desrow['surveyls_welcometext'];
  63. $end = $desrow['surveyls_endtext'];
  64. $surveyname = $desrow['surveyls_title'];
  65. $surveydesc = $desrow['surveyls_description'];
  66. $surveyactive = $desrow['active'];
  67. $surveytable = "{{survey_".$desrow['sid']."}}";
  68. $surveyexpirydate = $desrow['expires'];
  69. $surveyfaxto = $desrow['faxto'];
  70. $dateformattype = $desrow['surveyls_dateformat'];
  71. Yii::app()->loadHelper('surveytranslator');
  72. if (!is_null($surveyexpirydate))
  73. {
  74. $dformat=getDateFormatData($dateformattype);
  75. $dformat=$dformat['phpdate'];
  76. $expirytimestamp = strtotime($surveyexpirydate);
  77. $expirytimeofday_h = date('H',$expirytimestamp);
  78. $expirytimeofday_m = date('i',$expirytimestamp);
  79. $surveyexpirydate = date($dformat,$expirytimestamp);
  80. if(!empty($expirytimeofday_h) || !empty($expirytimeofday_m))
  81. {
  82. $surveyexpirydate .= ' &ndash; '.$expirytimeofday_h.':'.$expirytimeofday_m;
  83. };
  84. sprintf($clang->gT("Please submit by %s"), $surveyexpirydate);
  85. }
  86. else
  87. {
  88. $surveyexpirydate='';
  89. }
  90. if(is_file(Yii::app()->getConfig('usertemplaterootdir').DIRECTORY_SEPARATOR.$template.DIRECTORY_SEPARATOR.'print_survey.pstpl'))
  91. {
  92. define('PRINT_TEMPLATE_DIR' , Yii::app()->getConfig('usertemplaterootdir').DIRECTORY_SEPARATOR.$template.DIRECTORY_SEPARATOR , true);
  93. define('PRINT_TEMPLATE_URL' , Yii::app()->getConfig('usertemplaterooturl').'/'.$template.'/' , true);
  94. }
  95. elseif(is_file(Yii::app()->getConfig('usertemplaterootdir').'/'.$template.'/print_survey.pstpl'))
  96. {
  97. define('PRINT_TEMPLATE_DIR' , Yii::app()->getConfig('standardtemplaterootdir').DIRECTORY_SEPARATOR.$template.DIRECTORY_SEPARATOR , true);
  98. define('PRINT_TEMPLATE_URL' , Yii::app()->getConfig('standardtemplaterooturl').'/'.$template.'/' , true);
  99. }
  100. else
  101. {
  102. define('PRINT_TEMPLATE_DIR' , Yii::app()->getConfig('standardtemplaterootdir').DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR , true);
  103. define('PRINT_TEMPLATE_URL' , Yii::app()->getConfig('standardtemplaterooturl').'/default/' , true);
  104. }
  105. LimeExpressionManager::StartSurvey($surveyid, 'survey',NULL,false,LEM_PRETTY_PRINT_ALL_SYNTAX);
  106. $moveResult = LimeExpressionManager::NavigateForwards();
  107. $condition = "sid = '{$surveyid}' AND language = '{$surveyprintlang}'";
  108. $degresult = Groups::model()->getAllGroups($condition, array('group_order')); //xiao,
  109. if (!isset($surveyfaxto) || !$surveyfaxto and isset($surveyfaxnumber))
  110. {
  111. $surveyfaxto=$surveyfaxnumber; //Use system fax number if none is set in survey.
  112. }
  113. $headelements = getPrintableHeader();
  114. //if $showsgqacode is enabled at config.php show table name for reference
  115. $showsgqacode = Yii::app()->getConfig("showsgqacode");
  116. if(isset($showsgqacode) && $showsgqacode == true)
  117. {
  118. $surveyname = $surveyname."<br />[".$clang->gT('Database')." ".$clang->gT('table').": $surveytable]";
  119. }
  120. else
  121. {
  122. $surveyname = $surveyname;
  123. }
  124. $survey_output = array(
  125. 'SITENAME' => Yii::app()->getConfig("sitename")
  126. ,'SURVEYNAME' => $surveyname
  127. ,'SURVEYDESCRIPTION' => $surveydesc
  128. ,'WELCOME' => $welcome
  129. ,'END' => $end
  130. ,'THEREAREXQUESTIONS' => 0
  131. ,'SUBMIT_TEXT' => $clang->gT("Submit Your Survey.")
  132. ,'SUBMIT_BY' => $surveyexpirydate
  133. ,'THANKS' => $clang->gT("Thank you for completing this survey.")
  134. ,'HEADELEMENTS' => $headelements
  135. ,'TEMPLATEURL' => PRINT_TEMPLATE_URL
  136. ,'FAXTO' => $surveyfaxto
  137. ,'PRIVACY' => ''
  138. ,'GROUPS' => ''
  139. );
  140. $survey_output['FAX_TO'] ='';
  141. if(!empty($surveyfaxto) && $surveyfaxto != '000-00000000') //If no fax number exists, don't display faxing information!
  142. {
  143. $survey_output['FAX_TO'] = $clang->gT("Please fax your completed survey to:")." $surveyfaxto";
  144. }
  145. /**
  146. * Output arrays:
  147. * $survey_output = final vaiables for whole survey
  148. * $survey_output['SITENAME'] =
  149. * $survey_output['SURVEYNAME'] =
  150. * $survey_output['SURVEY_DESCRIPTION'] =
  151. * $survey_output['WELCOME'] =
  152. * $survey_output['THEREAREXQUESTIONS'] =
  153. * $survey_output['PDF_FORM'] =
  154. * $survey_output['HEADELEMENTS'] =
  155. * $survey_output['TEMPLATEURL'] =
  156. * $survey_output['SUBMIT_TEXT'] =
  157. * $survey_output['SUBMIT_BY'] =
  158. * $survey_output['THANKS'] =
  159. * $survey_output['FAX_TO'] =
  160. * $survey_output['SURVEY'] = contains an array of all the group arrays
  161. *
  162. * $groups[] = an array of all the groups output
  163. * $group['GROUPNAME'] =
  164. * $group['GROUPDESCRIPTION'] =
  165. * $group['QUESTIONS'] = templated formatted content if $question is appended to this at the end of processing each question.
  166. * $group['ODD_EVEN'] = class to differentiate alternate groups
  167. * $group['SCENARIO'] =
  168. *
  169. * $questions[] = contains an array of all the questions within a group
  170. * $question['QUESTION_CODE'] = content of the question code field
  171. * $question['QUESTION_TEXT'] = content of the question field
  172. * $question['QUESTION_SCENARIO'] = if there are conditions on a question, list the conditions.
  173. * $question['QUESTION_MANDATORY'] = translated 'mandatory' identifier
  174. * $question['QUESTION_CLASS'] = classes to be added to wrapping question div
  175. * $question['QUESTION_TYPE_HELP'] = instructions on how to complete the question
  176. * $question['QUESTION_MAN_MESSAGE'] = (not sure if this is used) mandatory error
  177. * $question['QUESTION_VALID_MESSAGE'] = (not sure if this is used) validation error
  178. * $question['ANSWER'] = contains formatted HTML answer
  179. * $question['QUESTIONHELP'] = content of the question help field.
  180. *
  181. */
  182. $total_questions = 0;
  183. $mapquestionsNumbers=Array();
  184. $answertext = ''; // otherwise can throw an error on line 1617
  185. // =========================================================
  186. // START doin the business:
  187. foreach ($degresult->readAll() as $degrow)
  188. {
  189. // ---------------------------------------------------
  190. // START doing groups
  191. $deqresult=Questions::model()->getQuestions($surveyid, $degrow['gid'], $surveyprintlang, 0, '"I"');
  192. $deqrows = array(); //Create an empty array in case FetchRow does not return any rows
  193. foreach ($deqresult->readAll() as $deqrow) {$deqrows[] = $deqrow;} // Get table output into array
  194. // Perform a case insensitive natural sort on group name then question title of a multidimensional array
  195. usort($deqrows, 'groupOrderThenQuestionOrder');
  196. if ($degrow['description'])
  197. {
  198. $group_desc = $degrow['description'];
  199. }
  200. else
  201. {
  202. $group_desc = '';
  203. }
  204. $group = array(
  205. 'GROUPNAME' => $degrow['group_name']
  206. ,'GROUPDESCRIPTION' => $group_desc
  207. ,'QUESTIONS' => '' // templated formatted content if $question is appended to this at the end of processing each question.
  208. );
  209. // A group can have only hidden questions. In that case you don't want to see the group's header/description either.
  210. $bGroupHasVisibleQuestions = false;
  211. $gid = $degrow['gid'];
  212. //Alternate bgcolor for different groups
  213. if (!isset($group['ODD_EVEN']) || $group['ODD_EVEN'] == ' g-row-even')
  214. {
  215. $group['ODD_EVEN'] = ' g-row-odd';}
  216. else
  217. {
  218. $group['ODD_EVEN'] = ' g-row-even';
  219. }
  220. //Loop through questions
  221. foreach ($deqrows as $deqrow)
  222. {
  223. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  224. // START doing questions
  225. $qidattributes=getQuestionAttributeValues($deqrow['qid'],$deqrow['type']);
  226. if ($qidattributes['hidden'] == 1 && $deqrow['type'] != '*')
  227. {
  228. continue;
  229. }
  230. $bGroupHasVisibleQuestions = true;
  231. //GET ANY CONDITIONS THAT APPLY TO THIS QUESTION
  232. $printablesurveyoutput = '';
  233. $sExplanation = ''; //reset conditions explanation
  234. $s=0;
  235. // TMSW Conditions->Relevance: show relevance instead of this whole section to create $explanation
  236. $scenarioresult=Conditions::model()->getScenarios($deqrow['qid']);
  237. $scenarioresult = $scenarioresult->readAll();
  238. //Loop through distinct scenarios, thus grouping them together.
  239. foreach ($scenarioresult as $scenariorow)
  240. {
  241. if( $s == 0 && count($scenarioresult) > 1)
  242. {
  243. $sExplanation .= '<p class="scenario">'." -------- Scenario {$scenariorow['scenario']} --------</p>\n\n";
  244. }
  245. if($s > 0)
  246. {
  247. $sExplanation .= '<p class="scenario">'.' -------- '.$clang->gT("or")." Scenario {$scenariorow['scenario']} --------</p>\n\n";
  248. }
  249. $x=0;
  250. $conditions1="qid={$deqrow['qid']} AND scenario={$scenariorow['scenario']}";
  251. $distinctresult=Conditions::model()->getSomeConditions(array('cqid','method', 'cfieldname', 'value'), $conditions1, array('cqid'),array('cqid', 'method','cfieldname','value'));
  252. //Loop through each condition for a particular scenario.
  253. foreach ($distinctresult->readAll() as $distinctrow)
  254. {
  255. $condition = "qid = '{$distinctrow['cqid']}' AND parent_qid = 0 AND language = '{$surveyprintlang}'";
  256. $subresult=Questions::model()->find($condition);
  257. if($x > 0)
  258. {
  259. $sExplanation .= ' <em class="scenario-and-seperator">'.$clang->gT('and').'</em> ';
  260. }
  261. if(trim($distinctrow['method'])=='') //If there is no method chosen assume "equals"
  262. {
  263. $distinctrow['method']='==';
  264. }
  265. if($distinctrow['cqid']){ // cqid != 0 ==> previous answer match
  266. if($distinctrow['method']=='==')
  267. {
  268. $sExplanation .= $clang->gT("Answer was")." ";
  269. }
  270. elseif($distinctrow['method']=='!=')
  271. {
  272. $sExplanation .= $clang->gT("Answer was NOT")." ";
  273. }
  274. elseif($distinctrow['method']=='<')
  275. {
  276. $sExplanation .= $clang->gT("Answer was less than")." ";
  277. }
  278. elseif($distinctrow['method']=='<=')
  279. {
  280. $sExplanation .= $clang->gT("Answer was less than or equal to")." ";
  281. }
  282. elseif($distinctrow['method']=='>=')
  283. {
  284. $sExplanation .= $clang->gT("Answer was greater than or equal to")." ";
  285. }
  286. elseif($distinctrow['method']=='>')
  287. {
  288. $sExplanation .= $clang->gT("Answer was greater than")." ";
  289. }
  290. elseif($distinctrow['method']=='RX')
  291. {
  292. $sExplanation .= $clang->gT("Answer matched (regexp)")." ";
  293. }
  294. else
  295. {
  296. $sExplanation .= $clang->gT("Answer was")." ";
  297. }
  298. if($distinctrow['value'] == '') {
  299. $sExplanation .= ' '.$clang->gT("Not selected").' ';
  300. }
  301. //If question type is numerical or multi-numerical, show the actual value - otherwise, don't.
  302. if($subresult['type'] == 'N' || $subresult['type'] == 'K') {
  303. $sExplanation .= ' '.$distinctrow['value']. ' ';
  304. }
  305. }
  306. if(!$distinctrow['cqid']) { // cqid == 0 ==> token attribute match
  307. $tokenData = getTokenFieldsAndNames($surveyid);
  308. preg_match('/^{TOKEN:([^}]*)}$/',$distinctrow['cfieldname'],$extractedTokenAttr);
  309. $sExplanation .= "Your ".$tokenData[strtolower($extractedTokenAttr[1])]['description']." ";
  310. if($distinctrow['method']=='==')
  311. {
  312. $sExplanation .= $clang->gT("is")." ";
  313. }
  314. elseif($distinctrow['method']=='!=')
  315. {
  316. $sExplanation .= $clang->gT("is NOT")." ";
  317. }
  318. elseif($distinctrow['method']=='<')
  319. {
  320. $sExplanation .= $clang->gT("is less than")." ";
  321. }
  322. elseif($distinctrow['method']=='<=')
  323. {
  324. $sExplanation .= $clang->gT("is less than or equal to")." ";
  325. }
  326. elseif($distinctrow['method']=='>=')
  327. {
  328. $sExplanation .= $clang->gT("is greater than or equal to")." ";
  329. }
  330. elseif($distinctrow['method']=='>')
  331. {
  332. $sExplanation .= $clang->gT("is greater than")." ";
  333. }
  334. elseif($distinctrow['method']=='RX')
  335. {
  336. $sExplanation .= $clang->gT("is matched (regexp)")." ";
  337. }
  338. else
  339. {
  340. $sExplanation .= $clang->gT("is")." ";
  341. }
  342. $answer_section = ' '.$distinctrow['value'].' ';
  343. }
  344. $conresult=Conditions::model()->getConditionsQuestions($distinctrow['cqid'],$deqrow['qid'],$scenariorow['scenario'],$surveyprintlang);
  345. $conditions=array();
  346. foreach ($conresult->readAll() as $conrow)
  347. {
  348. $postans="";
  349. $value=$conrow['value'];
  350. switch($conrow['type'])
  351. {
  352. case "Y":
  353. switch ($conrow['value'])
  354. {
  355. case "Y": $conditions[]=$clang->gT("Yes"); break;
  356. case "N": $conditions[]=$clang->gT("No"); break;
  357. }
  358. break;
  359. case "G":
  360. switch($conrow['value'])
  361. {
  362. case "M": $conditions[]=$clang->gT("Male"); break;
  363. case "F": $conditions[]=$clang->gT("Female"); break;
  364. } // switch
  365. break;
  366. case "A":
  367. case "B":
  368. case ":":
  369. case ";":
  370. $conditions[]=$conrow['value'];
  371. break;
  372. case "C":
  373. switch($conrow['value'])
  374. {
  375. case "Y": $conditions[]=$clang->gT("Yes"); break;
  376. case "U": $conditions[]=$clang->gT("Uncertain"); break;
  377. case "N": $conditions[]=$clang->gT("No"); break;
  378. } // switch
  379. break;
  380. case "E":
  381. switch($conrow['value'])
  382. {
  383. case "I": $conditions[]=$clang->gT("Increase"); break;
  384. case "D": $conditions[]=$clang->gT("Decrease"); break;
  385. case "S": $conditions[]=$clang->gT("Same"); break;
  386. }
  387. case "1":
  388. $labelIndex=preg_match("/^[^#]+#([01]{1})$/",$conrow['cfieldname']);
  389. if ($labelIndex == 0)
  390. { // TIBO
  391. $condition="qid='{$conrow['cqid']}' AND code='{$conrow['value']}' AND scale_id=0 AND language='{$surveyprintlang}'";
  392. $fresult=Answers::model()->getAllRecords($condition);
  393. foreach($fresult->readAll() as $frow)
  394. {
  395. $postans=$frow['answer'];
  396. $conditions[]=$frow['answer'];
  397. } // while
  398. }
  399. elseif ($labelIndex == 1)
  400. {
  401. $condition="qid='{$conrow['cqid']}' AND code='{$conrow['value']}' AND scale_id=1 AND language='{$surveyprintlang}'";
  402. $fresult=Answers::model()->getAllRecords($condition);
  403. foreach($fresult->readAll() as $frow)
  404. {
  405. $postans=$frow['answer'];
  406. $conditions[]=$frow['answer'];
  407. } // while
  408. }
  409. break;
  410. case "L":
  411. case "!":
  412. case "O":
  413. case "R":
  414. $condition="qid='{$conrow['cqid']}' AND code='{$conrow['value']}' AND language='{$surveyprintlang}'";
  415. $ansresult=Answers::model()->findAll($condition);
  416. foreach ($ansresult as $ansrow)
  417. {
  418. $conditions[]=$ansrow['answer'];
  419. }
  420. if($conrow['value'] == "-oth-") {
  421. $conditions[]=$clang->gT("Other");
  422. }
  423. $conditions = array_unique($conditions);
  424. break;
  425. case "M":
  426. case "P":
  427. $condition=" parent_qid='{$conrow['cqid']}' AND title='{$conrow['value']}' AND language='{$surveyprintlang}'";
  428. $ansresult=Questions::model()->findAll($condition);
  429. foreach ($ansresult as $ansrow)
  430. {
  431. $conditions[]=$ansrow['question'];
  432. }
  433. $conditions = array_unique($conditions);
  434. break;
  435. case "N":
  436. $conditions[]=$value;
  437. break;
  438. case "F":
  439. case "H":
  440. default:
  441. $value=substr($conrow['cfieldname'], strpos($conrow['cfieldname'], "X".$conrow['cqid'])+strlen("X".$conrow['cqid']), strlen($conrow['cfieldname']));
  442. $condition=" qid='{$conrow['cqid']}' AND code='{$conrow['value']}' AND language='{$surveyprintlang}'";
  443. $fresult=Answers::model()->getAllRecords($condition);
  444. foreach ($fresult->readAll() as $frow)
  445. {
  446. $postans=$frow['answer'];
  447. $conditions[]=$frow['answer'];
  448. } // while
  449. break;
  450. } // switch
  451. // Now let's complete the answer text with the answer_section
  452. $answer_section="";
  453. switch($conrow['type'])
  454. {
  455. case "A":
  456. case "B":
  457. case "C":
  458. case "E":
  459. case "F":
  460. case "H":
  461. case "K":
  462. $thiscquestion=$fieldmap[$conrow['cfieldname']];
  463. $condition="parent_qid='{$conrow['cqid']}' AND title='{$thiscquestion['aid']}' AND language='{$surveyprintlang}'";
  464. $ansresult= Questions::model()->findAll($condition);
  465. foreach ($ansresult as $ansrow)
  466. {
  467. $answer_section=" (".$ansrow['question'].")";
  468. }
  469. break;
  470. case "1": // dual: (Label 1), (Label 2)
  471. $labelIndex=substr($conrow['cfieldname'],-1);
  472. $thiscquestion=$fieldmap[$conrow['cfieldname']];
  473. $condition="parent_qid='{$conrow['cqid']}' AND title='{$thiscquestion['aid']}' AND language='{$surveyprintlang}'";
  474. $ansresult= Questions::model()->findAll($condition);
  475. $cqidattributes = getQuestionAttributeValues($conrow['cqid'], $conrow['type']);
  476. if ($labelIndex == 0)
  477. {
  478. if (trim($cqidattributes['dualscale_headerA']) != '') {
  479. $header = $clang->gT($cqidattributes['dualscale_headerA']);
  480. } else {
  481. $header = '1';
  482. }
  483. }
  484. elseif ($labelIndex == 1)
  485. {
  486. if (trim($cqidattributes['dualscale_headerB']) != '') {
  487. $header = $clang->gT($cqidattributes['dualscale_headerB']);
  488. } else {
  489. $header = '2';
  490. }
  491. }
  492. foreach ($ansresult->readAll() as $ansrow)
  493. {
  494. $answer_section=" (".$ansrow['question']." ".sprintf($clang->gT("Label %s"),$header).")";
  495. }
  496. break;
  497. case ":":
  498. case ";": //multi flexi: ( answer [label] )
  499. $thiscquestion=$fieldmap[$conrow['cfieldname']];
  500. $condition="parent_qid='{$conrow['cqid']}' AND title='{$thiscquestion['aid']}' AND language='{$surveyprintlang}'";
  501. $ansresult= Questions::model()->findAll($condition);
  502. foreach ($ansresult as $ansrow)
  503. {
  504. $condition = "qid = '{$conrow['cqid']}' AND code = '{$conrow['value']}' AND language= '{$surveyprintlang}'";
  505. $fresult= Answers::model()->findAll($condition);
  506. foreach ($fresult as $frow)
  507. {
  508. //$conditions[]=$frow['title'];
  509. $answer_section=" (".$ansrow['question']."[".$frow['answer']."])";
  510. } // while
  511. }
  512. break;
  513. case "R": // (Rank 1), (Rank 2)... TIBO
  514. $thiscquestion=$fieldmap[$conrow['cfieldname']];
  515. $rankid=$thiscquestion['aid'];
  516. $answer_section=" (".$clang->gT("RANK")." $rankid)";
  517. break;
  518. default: // nothing to add
  519. break;
  520. }
  521. }
  522. if (count($conditions) > 1)
  523. {
  524. $sExplanation .= "'".implode("' <em class='scenario-or-seperator'>".$clang->gT("or")."</em> '", $conditions)."'";
  525. }
  526. elseif (count($conditions) == 1)
  527. {
  528. $sExplanation .= "'".$conditions[0]."'";
  529. }
  530. unset($conditions);
  531. // Following line commented out because answer_section was lost, but is required for some question types
  532. //$explanation .= " ".$clang->gT("to question")." '".$mapquestionsNumbers[$distinctrow['cqid']]."' $answer_section ";
  533. if($distinctrow['cqid']){
  534. $sExplanation .= " <span class='scenario-at-seperator'>".$clang->gT("at question")."</span> '".$mapquestionsNumbers[$distinctrow['cqid']]." [".$subresult['title']."]' (".strip_tags($subresult['question'])."$answer_section)" ;
  535. }
  536. else{
  537. $sExplanation .= " ".$distinctrow['value'] ;
  538. }
  539. //$distinctrow
  540. $x++;
  541. }
  542. $s++;
  543. }
  544. $qinfo = LimeExpressionManager::GetQuestionStatus($deqrow['qid']);
  545. $relevance = trim($qinfo['info']['relevance']);
  546. $sEquation = $qinfo['relEqn'];
  547. if (trim($relevance) != '' && trim($relevance) != '1')
  548. {
  549. if (isset($qidattributes['printable_help'][$surveyprintlang]) && $qidattributes['printable_help'][$surveyprintlang]!='')
  550. {
  551. $sExplanation=$qidattributes['printable_help'][$surveyprintlang];
  552. }
  553. elseif ($sExplanation=='') // There is only a relevance equation without conditions
  554. {
  555. $sExplanation=$sEquation;
  556. $sEquation='&nbsp;'; // No need to show it twice
  557. }
  558. $sExplanation = "<b>".$clang->gT('Only answer this question if the following conditions are met:')."</b><br/> ".$sExplanation;
  559. if (Yii::app()->getConfig('showrelevance'))
  560. {
  561. $sExplanation.="<span class='printable_equation'><br>".$sEquation."</span>";
  562. }
  563. }
  564. else
  565. {
  566. $sExplanation = '';
  567. }
  568. ++$total_questions;
  569. //TIBO map question qid to their q number
  570. $mapquestionsNumbers[$deqrow['qid']]=$total_questions;
  571. //END OF GETTING CONDITIONS
  572. $qid = $deqrow['qid'];
  573. $fieldname = "$surveyid"."X"."$gid"."X"."$qid";
  574. if(isset($showsgqacode) && $showsgqacode == true)
  575. {
  576. $deqrow['question'] = $deqrow['question']."<br />".$clang->gT("ID:")." $fieldname <br />".
  577. $clang->gT("Question code:")." ".$deqrow['title'];
  578. }
  579. $question = array(
  580. 'QUESTION_NUMBER' => $total_questions // content of the question code field
  581. ,'QUESTION_CODE' => $deqrow['title']
  582. ,'QUESTION_TEXT' => preg_replace('/(?:<br ?\/?>|<\/(?:p|h[1-6])>)$/is' , '' , $deqrow['question']) // content of the question field
  583. ,'QUESTION_SCENARIO' => $sExplanation // if there are conditions on a question, list the conditions.
  584. ,'QUESTION_MANDATORY' => '' // translated 'mandatory' identifier
  585. ,'QUESTION_ID' => $deqrow['qid'] // id to be added to wrapping question div
  586. ,'QUESTION_CLASS' => getQuestionClass( $deqrow['type']) // classes to be added to wrapping question div
  587. ,'QUESTION_TYPE_HELP' => $qinfo['validTip'] // '' // instructions on how to complete the question // prettyValidTip is too verbose; assuming printable surveys will use static values
  588. ,'QUESTION_MAN_MESSAGE' => '' // (not sure if this is used) mandatory error
  589. ,'QUESTION_VALID_MESSAGE' => '' // (not sure if this is used) validation error
  590. ,'QUESTION_FILE_VALID_MESSAGE' => ''// (not sure if this is used) file validation error
  591. ,'QUESTIONHELP' => '' // content of the question help field.
  592. ,'ANSWER' => '' // contains formatted HTML answer
  593. );
  594. if($question['QUESTION_TYPE_HELP'] != "") {
  595. $question['QUESTION_TYPE_HELP'] .= "<br />\n";
  596. }
  597. if ($deqrow['mandatory'] == 'Y')
  598. {
  599. $question['QUESTION_MANDATORY'] = $clang->gT('*');
  600. $question['QUESTION_CLASS'] .= ' mandatory';
  601. }
  602. //DIFFERENT TYPES OF DATA FIELD HERE
  603. if ($deqrow['help'])
  604. {
  605. $question['QUESTIONHELP'] = $deqrow['help'];
  606. }
  607. if (!empty($qidattributes['page_break']))
  608. {
  609. $question['QUESTION_CLASS'] .=' breakbefore ';
  610. }
  611. if (isset($qidattributes['maximum_chars']) && $qidattributes['maximum_chars']!='') {
  612. $question['QUESTION_CLASS'] ="max-chars-{$qidattributes['maximum_chars']} ".$question['QUESTION_CLASS'];
  613. }
  614. switch($deqrow['type'])
  615. {
  616. // ==================================================================
  617. case "5": //5 POINT CHOICE
  618. $question['QUESTION_TYPE_HELP'] .= $clang->gT('Please choose *only one* of the following:');
  619. $question['ANSWER'] .= "\n\t<ul>\n";
  620. for ($i=1; $i<=5; $i++)
  621. {
  622. $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";
  623. }
  624. $question['ANSWER'] .="\t</ul>\n";
  625. break;
  626. // ==================================================================
  627. case "D": //DATE
  628. $question['QUESTION_TYPE_HELP'] .= $clang->gT('Please enter a date:');
  629. $question['ANSWER'] .= "\t".self::_input_type_image('text',$question['QUESTION_TYPE_HELP'],30,1);
  630. break;
  631. // ==================================================================
  632. case "G": //GENDER
  633. $question['QUESTION_TYPE_HELP'] .= $clang->gT("Please choose *only one* of the following:");
  634. $question['ANSWER'] .= "\n\t<ul>\n";
  635. $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";
  636. $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";
  637. $question['ANSWER'] .= "\t</ul>\n";
  638. break;
  639. // ==================================================================
  640. case "L": //LIST drop-down/radio-button list
  641. // ==================================================================
  642. case "!": //List - dropdown
  643. if (isset($qidattributes['display_columns']) && trim($qidattributes['display_columns'])!='')
  644. {
  645. $dcols=$qidattributes['display_columns'];
  646. }
  647. else
  648. {
  649. $dcols=0;
  650. }
  651. if (isset($qidattributes['category_separator']) && trim($qidattributes['category_separator'])!='') {
  652. $optCategorySeparator = $qidattributes['category_separator'];
  653. }
  654. else
  655. {
  656. unset($optCategorySeparator);
  657. }
  658. $question['QUESTION_TYPE_HELP'] .= $clang->gT("Please choose *only one* of the following:");
  659. $question['QUESTION_TYPE_HELP'] .= self::_array_filter_help($qidattributes, $surveyprintlang, $surveyid);
  660. $dearesult=Answers::model()->getAllRecords(" qid='{$deqrow['qid']}' AND language='{$surveyprintlang}' ", array('sortorder','answer'));
  661. $dearesult=$dearesult->readAll();
  662. $deacount=count($dearesult);
  663. if ($deqrow['other'] == "Y") {$deacount++;}
  664. $wrapper = setupColumns(0, $deacount);
  665. $question['ANSWER'] = $wrapper['whole-start'];
  666. $rowcounter = 0;
  667. $colcounter = 1;
  668. foreach ($dearesult as $dearow)
  669. {
  670. if (isset($optCategorySeparator))
  671. {
  672. list ($category, $answer) = explode($optCategorySeparator,$dearow['answer']);
  673. if ($category != '')
  674. {
  675. $dearow['answer'] = "($category) $answer ".self::_addsgqacode("(".$dearow['code'].")");
  676. }
  677. else
  678. {
  679. $dearow['answer'] = $answer.self::_addsgqacode(" (".$dearow['code'].")");
  680. }
  681. $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'];
  682. }
  683. else
  684. {
  685. $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'];
  686. }
  687. ++$rowcounter;
  688. if ($rowcounter == $wrapper['maxrows'] && $colcounter < $wrapper['cols'])
  689. {
  690. if($colcounter == $wrapper['cols'] - 1)
  691. {
  692. $question['ANSWER'] .= $wrapper['col-devide-last'];
  693. }
  694. else
  695. {
  696. $question['ANSWER'] .= $wrapper['col-devide'];
  697. }
  698. $rowcounter = 0;
  699. ++$colcounter;
  700. }
  701. }
  702. if ($deqrow['other'] == 'Y')
  703. {
  704. if(trim($qidattributes["other_replace_text"][$surveyprintlang])=='')
  705. {$qidattributes["other_replace_text"][$surveyprintlang]="Other";}
  706. // $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'];
  707. $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'];
  708. }
  709. $question['ANSWER'] .= $wrapper['whole-end'];
  710. //Let's break the presentation into columns.
  711. break;
  712. // ==================================================================
  713. case "O": //LIST WITH COMMENT
  714. $question['QUESTION_TYPE_HELP'] .= $clang->gT("Please choose *only one* of the following:");
  715. $dearesult=Answers::model()->getAllRecords(" qid='{$deqrow['qid']}' AND language='{$surveyprintlang}'", array('sortorder', 'answer') );
  716. $question['ANSWER'] = "\t<ul>\n";
  717. foreach ($dearesult->readAll() as $dearow)
  718. {
  719. $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";
  720. }
  721. $question['ANSWER'] .= "\t</ul>\n";
  722. $question['ANSWER'] .= "\t<p class=\"comment\">\n\t\t".$clang->gT("Make a comment on your choice here:")."\n";
  723. $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";
  724. break;
  725. // ==================================================================
  726. case "R": //RANKING Type Question
  727. $rearesult=Answers::model()->getAllRecords(" qid='{$deqrow['qid']}' AND language='{$surveyprintlang}'", array('sortorder', 'answer'));
  728. $rearesult = $rearesult->readAll();
  729. $reacount = count($rearesult);
  730. $question['QUESTION_TYPE_HELP'] .= $clang->gT("Please number each box in order of preference from 1 to")." $reacount";
  731. $question['QUESTION_TYPE_HELP'] .= self::_min_max_answers_help($qidattributes, $surveyprintlang, $surveyid);
  732. $question['ANSWER'] = "\n<ul>\n";
  733. foreach ($rearesult as $rearow)
  734. {
  735. $question['ANSWER'] .="\t<li>\n\t".self::_input_type_image('rank','',4,1)."\n\t\t&nbsp;".$rearow['answer'].self::_addsgqacode(" (".$fieldname.$rearow['code'].")")."\n\t</li>\n";
  736. }
  737. $question['ANSWER'] .= "\n</ul>\n";
  738. break;
  739. // ==================================================================
  740. case "M": //Multiple choice (Quite tricky really!)
  741. if (trim($qidattributes['display_columns'])!='')
  742. {
  743. $dcols=$qidattributes['display_columns'];
  744. }
  745. else
  746. {
  747. $dcols=0;
  748. }
  749. $question['QUESTION_TYPE_HELP'] .= $clang->gT("Please choose *all* that apply:");
  750. $question['QUESTION_TYPE_HELP'] .= self::_array_filter_help($qidattributes, $surveyprintlang, $surveyid);
  751. $mearesult = Questions::model()->getAllRecords(" parent_qid='{$deqrow['qid']}' AND language='{$surveyprintlang}' ", array('question_order'));
  752. $mearesult = $mearesult->readAll();
  753. $meacount = count($mearesult);
  754. if ($deqrow['other'] == 'Y') {$meacount++;}
  755. $wrapper = setupColumns($dcols, $meacount);
  756. $question['ANSWER'] = $wrapper['whole-start'];
  757. $rowcounter = 0;
  758. $colcounter = 1;
  759. foreach ($mearesult as $mearow)
  760. {
  761. $question['ANSWER'] .= $wrapper['item-start'].self::_input_t

Large files files are truncated, but you can click here to view the full file