PageRenderTime 31ms CodeModel.GetById 18ms 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
  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_type_image('checkbox',$mearow['question'])."\n\t\t".$mearow['question'].self::_addsgqacode(" (".$fieldname.$mearow['title'].") ").$wrapper['item-end'];
  762. ++$rowcounter;
  763. if ($rowcounter == $wrapper['maxrows'] && $colcounter < $wrapper['cols'])
  764. {
  765. if($colcounter == $wrapper['cols'] - 1)
  766. {
  767. $question['ANSWER'] .= $wrapper['col-devide-last'];
  768. }
  769. else
  770. {
  771. $question['ANSWER'] .= $wrapper['col-devide'];
  772. }
  773. $rowcounter = 0;
  774. ++$colcounter;
  775. }
  776. }
  777. if ($deqrow['other'] == "Y")
  778. {
  779. if (trim($qidattributes['other_replace_text'][$surveyprintlang])=='')
  780. {
  781. $qidattributes["other_replace_text"][$surveyprintlang]="Other";
  782. }
  783. if(!isset($mearow['answer'])) $mearow['answer']="";
  784. $question['ANSWER'] .= $wrapper['item-start-other'].self::_input_type_image('checkbox',$mearow['answer']).$clang->gT($qidattributes["other_replace_text"][$surveyprintlang]).":\n\t\t".self::_input_type_image('other').self::_addsgqacode(" (".$fieldname."other) ").$wrapper['item-end'];
  785. }
  786. $question['ANSWER'] .= $wrapper['whole-end'];
  787. // }
  788. break;
  789. // ==================================================================
  790. case "P": //Multiple choice with comments
  791. $question['QUESTION_TYPE_HELP'] .= $clang->gT("Please choose all that apply and provide a comment:");
  792. $question['QUESTION_TYPE_HELP'] .= self::_array_filter_help($qidattributes, $surveyprintlang, $surveyid);
  793. $mearesult=Questions::model()->getAllRecords("parent_qid='{$deqrow['qid']}' AND language='{$surveyprintlang}'", array('question_order'));
  794. // $printablesurveyoutput .="\t\t\t<u>".$clang->gT("Please choose all that apply and provide a comment:")."</u><br />\n";
  795. $j=0;
  796. $longest_string = 0;
  797. foreach ($mearesult->readAll() as $mearow)
  798. {
  799. $longest_string = longestString($mearow['question'] , $longest_string );
  800. $question['ANSWER'] .= "\t<li><span>\n\t\t".self::_input_type_image('checkbox',$mearow['question']).$mearow['question'].self::_addsgqacode(" (".$fieldname.$mearow['title'].") ")."</span>\n\t\t".self::_input_type_image('text','comment box',60).self::_addsgqacode(" (".$fieldname.$mearow['title']."comment) ")."\n\t</li>\n";
  801. $j++;
  802. }
  803. if ($deqrow['other'] == "Y")
  804. {
  805. $question['ANSWER'] .= "\t<li class=\"other\">\n\t\t<div class=\"other-replacetext\">".$clang->gT('Other:').self::_input_type_image('other','',1)."</div>".self::_input_type_image('othercomment','comment box',50).self::_addsgqacode(" (".$fieldname."other) ")."\n\t</li>\n";
  806. $j++;
  807. }
  808. $question['ANSWER'] = "\n<ul>\n".$question['ANSWER']."</ul>\n";
  809. break;
  810. // ==================================================================
  811. case "Q": //MULTIPLE SHORT TEXT
  812. $width=60;
  813. // ==================================================================
  814. case "K": //MULTIPLE NUMERICAL
  815. $question['QUESTION_TYPE_HELP'] = "";
  816. $width=(isset($width))?$width:16;
  817. // if (!empty($qidattributes['equals_num_value']))
  818. // {
  819. // $question['QUESTION_TYPE_HELP'] .= "* ".sprintf($clang->gT('Total of all entries must equal %d'),$qidattributes['equals_num_value'])."<br />\n";
  820. // }
  821. // if (!empty($qidattributes['max_num_value']))
  822. // {
  823. // $question['QUESTION_TYPE_HELP'] .= sprintf($clang->gT('Total of all entries must not exceed %d'), $qidattributes['max_num_value'])."<br />\n";
  824. // }
  825. // if (!empty($qidattributes['min_num_value']))
  826. // {
  827. // $question['QUESTION_TYPE_HELP'] .= sprintf($clang->gT('Total of all entries must be at least %s'),$qidattributes['min_num_value'])."<br />\n";
  828. // }
  829. $question['QUESTION_TYPE_HELP'] .= $clang->gT("Please write your answer(s) here:");
  830. $longest_string = 0;
  831. $mearesult=Questions::model()->getAllRecords("parent_qid='{$deqrow['qid']}' AND language='{$surveyprintlang}'", array('question_order'));
  832. foreach ($mearesult->readAll() as $mearow)
  833. {
  834. $longest_string = longestString($mearow['question'] , $longest_string );
  835. if (isset($qidattributes['slider_layout']) && $qidattributes['slider_layout']==1)
  836. {
  837. $mearow['question']=explode(':',$mearow['question']);
  838. $mearow['question']=$mearow['question'][0];
  839. }
  840. $question['ANSWER'] .= "\t<li>\n\t\t<span>".$mearow['question']."</span>\n\t\t".self::_input_type_image('text',$mearow['question'],$width).self::_addsgqacode(" (".$fieldname.$mearow['title'].") ")."\n\t</li>\n";
  841. }
  842. $question['ANSWER'] = "\n<ul>\n".$question['ANSWER']."</ul>\n";
  843. break;
  844. // ==================================================================
  845. case "S": //SHORT TEXT
  846. $question['QUESTION_TYPE_HELP'] .= $clang->gT("Please write your answer here:");
  847. $question['ANSWER'] = self::_input_type_image('text',$question['QUESTION_TYPE_HELP'], 50);
  848. break;
  849. // ==================================================================
  850. case "T": //LONG TEXT
  851. $question['QUESTION_TYPE_HELP'] .= $clang->gT("Please write your answer here:");
  852. $question['ANSWER'] = self::_input_type_image('textarea',$question['QUESTION_TYPE_HELP'], '100%' , 8);
  853. break;
  854. // ==================================================================
  855. case "U": //HUGE TEXT
  856. $question['QUESTION_TYPE_HELP'] .= $clang->gT("Please write your answer here:");
  857. $question['ANSWER'] = self::_input_type_image('textarea',$question['QUESTION_TYPE_HELP'], '100%' , 30);
  858. break;
  859. // ==================================================================
  860. case "N": //NUMERICAL
  861. $prefix="";
  862. $suffix="";
  863. if($qidattributes['prefix'][$surveyprintlang] != "") {
  864. $prefix=$qidattributes['prefix'][$surveyprintlang];
  865. }
  866. if($qidattributes['suffix'][$surveyprintlang] != "") {
  867. $suffix=$qidattributes['suffix'][$surveyprintlang];
  868. }
  869. $question['QUESTION_TYPE_HELP'] .= $clang->gT("Please write your answer here:");
  870. $question['ANSWER'] = "<ul>\n\t<li>\n\t\t<span>$prefix</span>\n\t\t".self::_input_type_image('text',$question['QUESTION_TYPE_HELP'],20)."\n\t\t<span>$suffix</span>\n\t\t</li>\n\t</ul>";
  871. break;
  872. // ==================================================================
  873. case "Y": //YES/NO
  874. $question['QUESTION_TYPE_HELP'] .= $clang->gT("Please choose *only one* of the following:");
  875. $question['ANSWER'] = "\n<ul>\n\t<li>\n\t\t".self::_input_type_image('radio',$clang->gT('Yes'))."\n\t\t".$clang->gT('Yes').self::_addsgqacode(" (Y)")."\n\t</li>\n";
  876. $question['ANSWER'] .= "\n\t<li>\n\t\t".self::_input_type_image('radio',$clang->gT('No'))."\n\t\t".$clang->gT('No').self::_addsgqacode(" (N)")."\n\t</li>\n</ul>\n";
  877. break;
  878. // ==================================================================
  879. case "A": //ARRAY (5 POINT CHOICE)
  880. $condition = "parent_qid = '{$deqrow['qid']}' AND language= '{$surveyprintlang}'";
  881. $question['QUESTION_TYPE_HELP'] .= $clang->gT("Please choose the appropriate response for each item:");
  882. $question['QUESTION_TYPE_HELP'] .= self::_array_filter_help($qidattributes, $surveyprintlang, $surveyid);
  883. $question['ANSWER'] = "
  884. <table>
  885. <thead>
  886. <tr>
  887. <td>&nbsp;</td>
  888. <th style='font-family:Arial,helvetica,sans-serif;font-weight:normal;'>1&nbsp;&nbsp;&nbsp;&nbsp;".self::_addsgqacode(" (1)")."</th>
  889. <th style='font-family:Arial,helvetica,sans-serif;font-weight:normal;'>2&nbsp;&nbsp;&nbsp;&nbsp;".self::_addsgqacode(" (2)")."</th>
  890. <th style='font-family:Arial,helvetica,sans-serif;font-weight:normal;'>3&nbsp;&nbsp;&nbsp;&nbsp;".self::_addsgqacode(" (3)")."</th>
  891. <th style='font-family:Arial,helvetica,sans-serif;font-weight:normal;'>4&nbsp;&nbsp;&nbsp;&nbsp;".self::_addsgqacode(" (4)")."</th>
  892. <th style='font-family:Arial,helvetica,sans-serif;font-weight:normal;'>5".self::_addsgqacode(" (5)")."</th>
  893. </tr>
  894. </thead>
  895. <tbody>";
  896. $j=0;
  897. $rowclass = 'array1';
  898. $mearesult= Questions::model()->getAllRecords( $condition, array('question_order'));
  899. foreach ($mearesult->readAll() as $mearow)
  900. {
  901. $question['ANSWER'] .= "\t\t<tr class=\"$rowclass\">\n";
  902. $rowclass = alternation($rowclass,'row');
  903. //semantic differential question type?
  904. if (strpos($mearow['question'],'|'))
  905. {
  906. $answertext = substr($mearow['question'],0, strpos($mearow['question'],'|')).self::_addsgqacode(" (".$fieldname.$mearow['title'].")")." ";
  907. }
  908. else
  909. {
  910. $answertext=$mearow['question'].self::_addsgqacode(" (".$fieldname.$mearow['title'].")");
  911. }
  912. $question['ANSWER'] .= "\t\t\t<th class=\"answertext\">$answertext</th>\n";
  913. for ($i=1; $i<=5; $i++)
  914. {
  915. $question['ANSWER'] .= "\t\t\t<td>".self::_input_type_image('radio',$i)."</td>\n";
  916. }
  917. $answertext .= $mearow['question'];
  918. //semantic differential question type?
  919. if (strpos($mearow['question'],'|'))
  920. {
  921. $answertext2 = substr($mearow['question'],strpos($mearow['question'],'|')+1);
  922. $question['ANSWER'] .= "\t\t\t<th class=\"answertextright\">$answertext2</td>\n";
  923. }
  924. $question['ANSWER'] .= "\t\t</tr>\n";
  925. $j++;
  926. }
  927. $question['ANSWER'] .= "\t</tbody>\n</table>\n";
  928. break;
  929. // ==================================================================
  930. case "B": //ARRAY (10 POINT CHOICE)
  931. $question['QUESTION_TYPE_HELP'] .= $clang->gT("Please choose the appropriate response for each item:");
  932. $question['QUESTION_TYPE_HELP'] .= self::_array_filter_help($qidattributes, $surveyprintlang, $surveyid);
  933. $question['ANSWER'] .= "\n<table>\n\t<thead>\n\t\t<tr>\n\t\t\t<td>&nbsp;</td>\n";
  934. for ($i=1; $i<=10; $i++)
  935. {
  936. $question['ANSWER'] .= "\t\t\t<th>$i".self::_addsgqacode(" ($i)")."</th>\n";
  937. }
  938. $question['ANSWER'] .= "\t</thead>\n\n\t<tbody>\n";
  939. $j=0;
  940. $rowclass = 'array1';
  941. $mearesult=Questions::model()->getAllRecords(" parent_qid='{$deqrow['qid']}' AND language='{$surveyprintlang}' ", array('question_order'));
  942. foreach ($mearesult->readAll() as $mearow)
  943. {
  944. $question['ANSWER'] .= "\t\t<tr class=\"$rowclass\">\n\t\t\t<th class=\"answertext\">{$mearow['question']}".self::_addsgqacode(" (".$fieldname.$mearow['title'].")")."</th>\n";
  945. $rowclass = alternation($rowclass,'row');
  946. for ($i=1; $i<=10; $i++)
  947. {
  948. $question['ANSWER'] .= "\t\t\t<td>".self::_input_type_image('radio',$i)."</td>\n";
  949. }
  950. $question['ANSWER'] .= "\t\t</tr>\n";
  951. $j++;
  952. }
  953. $question['ANSWER'] .= "\t</tbody>\n</table>\n";
  954. break;
  955. // ==================================================================
  956. case "C": //ARRAY (YES/UNCERTAIN/NO)
  957. $question['QUESTION_TYPE_HELP'] .= $clang->gT("Please choose the appropriate response for each item:");
  958. $question['QUESTION_TYPE_HELP'] .= self::_array_filter_help($qidattributes, $surveyprintlang, $surveyid);
  959. $question['ANSWER'] = '
  960. <table>
  961. <thead>
  962. <tr>
  963. <td>&nbsp;</td>
  964. <th>'.$clang->gT("Yes").self::_addsgqacode(" (Y)").'</th>
  965. <th>'.$clang->gT("Uncertain").self::_addsgqacode(" (U)").'</th>
  966. <th>'.$clang->gT("No").self::_addsgqacode(" (N)").'</th>
  967. </tr>
  968. </thead>
  969. <tbody>
  970. ';
  971. $j=0;
  972. $rowclass = 'array1';
  973. $mearesult=Questions::model()->getAllRecords(" parent_qid='{$deqrow['qid']}' AND language='{$surveyprintlang}' ", array('question_order'));
  974. foreach ($mearesult->readAll() as $mearow)
  975. {
  976. $question['ANSWER'] .= "\t\t<tr class=\"$rowclass\">\n";
  977. $question['ANSWER'] .= "\t\t\t<th class=\"answertext\">{$mearow['question']}".self::_addsgqacode(" (".$fieldname.$mearow['title'].")")."</th>\n";
  978. $question['ANSWER'] .= "\t\t\t<td>".self::_input_type_image('radio',$clang->gT("Yes"))."</td>\n";
  979. $question['ANSWER'] .= "\t\t\t<td>".self::_input_type_image('radio',$clang->gT("Uncertain"))."</td>\n";
  980. $question['ANSWER'] .= "\t\t\t<td>".self::_input_type_image('radio',$clang->gT("No"))."</td>\n";
  981. $question['ANSWER'] .= "\t\t</tr>\n";
  982. $j++;
  983. $rowclass = alternation($rowclass,'row');
  984. }
  985. $question['ANSWER'] .= "\t</tbody>\n</table>\n";
  986. break;
  987. case "E": //ARRAY (Increase/Same/Decrease)
  988. $question['QUESTION_TYPE_HELP'] .= $clang->gT("Please choose the appropriate response for each item:");
  989. $question['QUESTION_TYPE_HELP'] .= self::_array_filter_help($qidattributes, $surveyprintlang, $surveyid);
  990. $question['ANSWER'] = '
  991. <table>
  992. <thead>
  993. <tr>
  994. <td>&nbsp;</td>
  995. <th>'.$clang->gT("Increase").self::_addsgqacode(" (I)").'</th>
  996. <th>'.$clang->gT("Same").self::_addsgqacode(" (S)").'</th>
  997. <th>'.$clang->gT("Decrease").self::_addsgqacode(" (D)").'</th>
  998. </tr>
  999. </thead>
  1000. <tbody>
  1001. ';
  1002. $j=0;
  1003. $rowclass = 'array1';
  1004. $mearesult=Questions::model()->getAllRecords(" parent_qid='{$deqrow['qid']}' AND language='{$surveyprintlang}' ", array('question_order'));
  1005. foreach ($mearesult->readAll() as $mearow)
  1006. {
  1007. $question['ANSWER'] .= "\t\t<tr class=\"$rowclass\">\n";
  1008. $question['ANSWER'] .= "\t\t\t<th class=\"answertext\">{$mearow['question']}".self::_addsgqacode(" (".$fieldname.$mearow['title'].")")."</th>\n";
  1009. $question['ANSWER'] .= "\t\t\t<td>".self::_input_type_image('radio',$clang->gT("Increase"))."</td>\n";
  1010. $question['ANSWER'] .= "\t\t\t<td>".self::_input_type_image('radio',$clang->gT("Same"))."</td>\n";
  1011. $question['ANSWER'] .= "\t\t\t<td>".self::_input_type_image('radio',$clang->gT("Decrease"))."</td>\n";
  1012. $question['ANSWER'] .= "\t\t</tr>\n";
  1013. $j++;
  1014. $rowclass = alternation($rowclass,'row');
  1015. }
  1016. $question['ANSWER'] .= "\t</tbody>\n</table>\n";
  1017. break;
  1018. // ==================================================================
  1019. case ":": //ARRAY (Multi Flexible) (Numbers)
  1020. $headstyle="style='padding-left: 20px; padding-right: 7px'";
  1021. if (trim($qidattributes['multiflexible_max'])!='' && trim($qidattributes['multiflexible_min']) =='') {
  1022. $maxvalue=$qidattributes['multiflexible_max'];
  1023. $minvalue=1;
  1024. }
  1025. if (trim($qidattributes['multiflexible_min'])!='' && trim($qidattributes['multiflexible_max']) =='') {
  1026. $minvalue=$qidattributes['multiflexible_min'];
  1027. $maxvalue=$qidattributes['multiflexible_min'] + 10;
  1028. }
  1029. if (trim($qidattributes['multiflexible_min'])=='' && trim($qidattributes['multiflexible_max']) =='') {
  1030. $minvalue=1;
  1031. $maxvalue=10;
  1032. }
  1033. if (trim($qidattributes['multiflexible_min']) !='' && trim($qidattributes['multiflexible_max']) !='') {
  1034. if($qidattributes['multiflexible_min'] < $qidattributes['multiflexible_max']){
  1035. $minvalue=$qidattributes['multiflexible_min'];
  1036. $maxvalue=$qidattributes['multiflexible_max'];
  1037. }
  1038. }
  1039. if (trim($qidattributes['multiflexible_step'])!='') {
  1040. $stepvalue=$qidattributes['multiflexible_step'];
  1041. }
  1042. else
  1043. {
  1044. $stepvalue=1;
  1045. }
  1046. if ($qidattributes['multiflexible_checkbox']!=0) {
  1047. $checkboxlayout=true;
  1048. } else {
  1049. $checkboxlayout=false;
  1050. }
  1051. $question['QUESTION_TYPE_HELP'] .= self::_array_filter_help($qidattributes, $surveyprintlang, $surveyid);
  1052. $question['ANSWER'] .= "\n<table>\n\t<thead>\n\t\t<tr>\n\t\t\t<td>&nbsp;</td>\n";
  1053. $fresult=Questions::model()->getAllRecords(" parent_qid='{$deqrow['qid']}' and scale_id=1 AND language='{$surveyprintlang}' ", array('question_order'));
  1054. $fresult = $fresult->readAll();
  1055. $fcount = count($fresult);
  1056. $fwidth = "120";
  1057. $i=0;
  1058. //array to temporary store X axis question codes
  1059. $xaxisarray = array();
  1060. foreach ($fresult as $frow)
  1061. {
  1062. $question['ANSWER'] .= "\t\t\t<th>{$frow['question']}</th>\n";
  1063. $i++;
  1064. //add current question code
  1065. $xaxisarray[$i] = $frow['title'];
  1066. }
  1067. $question['ANSWER'] .= "\t\t</tr>\n\t</thead>\n\n\t<tbody>\n";
  1068. $a=1; //Counter for pdfoutput
  1069. $rowclass = 'array1';
  1070. $mearesult=Questions::model()->getAllRecords(" parent_qid='{$deqrow['qid']}' and scale_id=0 AND language='{$surveyprintlang}' ", array('question_order'));
  1071. $result = $mearesult->readAll();
  1072. foreach ($result as $frow)
  1073. {
  1074. $question['ANSWER'] .= "\t<tr class=\"$rowclass\">\n";
  1075. $rowclass = alternation($rowclass,'row');
  1076. $answertext=$frow['question'];
  1077. if (strpos($answertext,'|')) {$answertext=substr($answertext,0, strpos($answertext,'|'));}
  1078. $question['ANSWER'] .= "\t\t\t\t\t<th class=\"answertext\">$answertext</th>\n";
  1079. //$printablesurveyoutput .="\t\t\t\t\t<td>";
  1080. for ($i=1; $i<=$fcount; $i++)
  1081. {
  1082. $question['ANSWER'] .= "\t\t\t<td>\n";
  1083. if ($checkboxlayout === false)
  1084. {
  1085. $question['ANSWER'] .= "\t\t\t\t".self::_input_type_image('text','',4).self::_addsgqacode(" (".$fieldname.$frow['title']."_".$xaxisarray[$i].") ")."\n";
  1086. }
  1087. else
  1088. {
  1089. $question['ANSWER'] .= "\t\t\t\t".self::_input_type_image('checkbox').self::_addsgqacode(" (".$fieldname.$frow['title']."_".$xaxisarray[$i].") ")."\n";
  1090. }
  1091. $question['ANSWER'] .= "\t\t\t</td>\n";
  1092. }
  1093. $answertext=$frow['question'];
  1094. if (strpos($answertext,'|'))
  1095. {
  1096. $answertext=substr($answertext,strpos($answertext,'|')+1);
  1097. $question['ANSWER'] .= "\t\t\t<th class=\"answertextright\">$answertext</th>\n";
  1098. }
  1099. $question['ANSWER'] .= "\t\t</tr>\n";
  1100. $a++;
  1101. }
  1102. $question['ANSWER'] .= "\t</tbody>\n</table>\n";
  1103. break;
  1104. // ==================================================================
  1105. case ";": //ARRAY (Multi Flexible) (text)
  1106. $headstyle="style='padding-left: 20px; padding-right: 7px'";
  1107. $mearesult=Questions::model()->getAllRecords(" parent_qid='{$deqrow['qid']}' AND scale_id=0 AND language='{$surveyprintlang}' ", array('question_order'));
  1108. $mearesult=$mearesult->readAll();
  1109. $question['QUESTION_TYPE_HELP'] .= self::_array_filter_help($qidattributes, $surveyprintlang, $surveyid);
  1110. $question['ANSWER'] .= "\n<table>\n\t<thead>\n\t\t<tr>\n\t\t\t<td>&nbsp;</td>\n";
  1111. $fresult=Questions::model()->getAllRecords(" parent_qid='{$deqrow['qid']}' AND scale_id=1 AND language='{$surveyprintlang}' ", array('question_order'));
  1112. $fresult = $fresult->readAll();
  1113. $fcount = count($fresult);
  1114. $fwidth = "120";
  1115. $i=0;
  1116. //array to temporary store X axis question codes
  1117. $xaxisarray = array();
  1118. foreach ($fresult as $frow)
  1119. {
  1120. $question['ANSWER'] .= "\t\t\t<th>{$frow['question']}</th>\n";
  1121. $i++;
  1122. //add current question code
  1123. $xaxisarray[$i] = $frow['title'];
  1124. }
  1125. $question['ANSWER'] .= "\t\t</tr>\n\t</thead>\n\n<tbody>\n";
  1126. $a=1;
  1127. $rowclass = 'array1';
  1128. foreach ($mearesult as $mearow)
  1129. {
  1130. $question['ANSWER'] .= "\t\t<tr class=\"$rowclass\">\n";
  1131. $rowclass = alternation($rowclass,'row');
  1132. $answertext=$mearow['question'];
  1133. if (strpos($answertext,'|')) {$answertext=substr($answertext,0, strpos($answertext,'|'));}
  1134. $question['ANSWER'] .= "\t\t\t<th class=\"answertext\">$answertext</th>\n";
  1135. for ($i=1; $i<=$fcount; $i++)
  1136. {
  1137. $question['ANSWER'] .= "\t\t\t<td>\n";
  1138. $question['ANSWER'] .= "\t\t\t\t".self::_input_type_image('text','',23).self::_addsgqacode(" (".$fieldname.$mearow['title']."_".$xaxisarray[$i].") ")."\n";
  1139. $question['ANSWER'] .= "\t\t\t</td>\n";
  1140. }
  1141. $answertext=$mearow['question'];
  1142. if (strpos($answertext,'|'))
  1143. {
  1144. $answertext=substr($answertext,strpos($answertext,'|')+1);
  1145. $question['ANSWER'] .= "\t\t\t\t<th class=\"answertextright\">$answertext</th>\n";
  1146. }
  1147. $question['ANSWER'] .= "\t\t</tr>\n";
  1148. $a++;
  1149. }
  1150. $question['ANSWER'] .= "\t</tbody>\n</table>\n";
  1151. break;
  1152. // ==================================================================
  1153. case "F": //ARRAY (Flexible Labels)
  1154. $question['QUESTION_TYPE_HELP'] .= $clang->gT("Please choose the appropriate response for each item:");
  1155. $question['QUESTION_TYPE_HELP'] .= self::_array_filter_help($qidattributes, $surveyprintlang, $surveyid);
  1156. $fresult=Answers::model()->getAllRecords(" scale_id=0 AND qid='{$deqrow['qid']}' AND language='{$surveyprintlang}'", array('sortorder','code'));
  1157. $fresult = $fresult->readAll();
  1158. $fcount = count($fresult);
  1159. $fwidth = "120";
  1160. $i=1;
  1161. $column_headings = array();
  1162. foreach ($fresult as $frow)
  1163. {
  1164. $column_headings[] = $frow['answer'].self::_addsgqacode(" (".$frow['code'].")");
  1165. }
  1166. if (trim($qidattributes['answer_width'])!='')
  1167. {
  1168. $iAnswerWidth=100-$qidattributes['answer_width'];
  1169. }
  1170. else
  1171. {
  1172. $iAnswerWidth=80;
  1173. }
  1174. if (count($column_headings)>0)
  1175. {
  1176. $col_width = round($iAnswerWidth / count($column_headings));
  1177. }
  1178. else
  1179. {
  1180. $heading='';
  1181. }
  1182. $question['ANSWER'] .= "\n<table>\n\t<thead>\n\t\t<tr>\n";
  1183. $question['ANSWER'] .= "\t\t\t<td>&nbsp;</td>\n";
  1184. foreach($column_headings as $heading)
  1185. {
  1186. $question['ANSWER'] .= "\t\t\t<th style=\"width:$col_width%;\">$heading</th>\n";
  1187. }
  1188. $i++;
  1189. $question['ANSWER'] .= "\t\t</tr>\n\t</thead>\n\n\t<tbody>\n";
  1190. $counter = 1;
  1191. $rowclass = 'array1';
  1192. $mearesult=Questions::model()->getAllRecords(" parent_qid='{$deqrow['qid']}' AND language='{$surveyprintlang}' ", array('question_order'));
  1193. foreach ($mearesult->readAll() as $mearow)
  1194. {
  1195. $question['ANSWER'] .= "\t\t<tr class=\"$rowclass\">\n";
  1196. $rowclass = alternation($rowclass,'row');
  1197. if (trim($answertext)=='') $answertext='&nbsp;';
  1198. //semantic differential question type?
  1199. if (strpos($mearow['question'],'|'))
  1200. {
  1201. $answertext = substr($mearow['question'],0, strpos($mearow['question'],'|')).self::_addsgqacode(" (".$fieldname.$mearow['title'].")")." ";
  1202. }
  1203. else
  1204. {
  1205. $answertext=$mearow['question'].self::_addsgqacode(" (".$fieldname.$mearow['title'].")");
  1206. }
  1207. if (trim($qidattributes['answer_width'])!='')
  1208. {
  1209. $sInsertStyle=' style="width:'.$qidattributes['answer_width'].'%" ';
  1210. }
  1211. else
  1212. {
  1213. $sInsertStyle='';
  1214. }
  1215. $question['ANSWER'] .= "\t\t\t<th $sInsertStyle class=\"answertext\">$answertext</th>\n";
  1216. for ($i=1; $i<=$fcount; $i++)
  1217. {
  1218. $question['ANSWER'] .= "\t\t\t<td>".self::_input_type_image('radio')."</td>\n";
  1219. }
  1220. $counter++;
  1221. $answertext=$mearow['question'];
  1222. //semantic differential question type?
  1223. if (strpos($mearow['question'],'|'))
  1224. {
  1225. $answertext2=substr($mearow['question'],strpos($mearow['question'],'|')+1);
  1226. $question['ANSWER'] .= "\t\t\t<th class=\"answertextright\">$answertext2</th>\n";
  1227. }
  1228. $question['ANSWER'] .= "\t\t</tr>\n";
  1229. }
  1230. $question['ANSWER'] .= "\t</tbody>\n</table>\n";
  1231. break;
  1232. // ==================================================================
  1233. case "1": //ARRAY (Flexible Labels) multi scale
  1234. $leftheader= $qidattributes['dualscale_headerA'][$surveyprintlang];
  1235. $rightheader= $qidattributes['dualscale_headerB'][$surveyprintlang];
  1236. $headstyle = 'style="padding-left: 20px; padding-right: 7px"';
  1237. $question['QUESTION_TYPE_HELP'] .= $clang->gT("Please choose the appropriate response for each item:");
  1238. $question['QUESTION_TYPE_HELP'] .= self::_array_filter_help($qidattributes, $surveyprintlang, $surveyid);
  1239. $question['ANSWER'] .= "\n<table>\n\t<thead>\n";
  1240. $condition = "qid= '{$deqrow['qid']}' AND language= '{$surveyprintlang}' AND scale_id=0";
  1241. $fresult= Answers::model()->getAllRecords( $condition, array('sortorder', 'code'));
  1242. $fresult = $fresult->readAll();
  1243. $fcount = count($fresult);
  1244. $fwidth = "120";
  1245. $l1=0;
  1246. $printablesurveyoutput2 = "\t\t\t<td>&nbsp;</td>\n";
  1247. $myheader2 = '';
  1248. foreach ($fresult as $frow)
  1249. {
  1250. $printablesurveyoutput2 .="\t\t\t<th>{$frow['answer']}".self::_addsgqacode(" (".$frow['code'].")")."</th>\n";
  1251. $myheader2 .= "<td></td>";
  1252. $l1++;
  1253. }
  1254. // second scale
  1255. $printablesurveyoutput2 .="\t\t\t<td>&nbsp;</td>\n";
  1256. //$fquery1 = "SELECT * FROM {{answers}} WHERE qid='{$deqrow['qid']}' AND language='{$surveyprintlang}' AND scale_id=1 ORDER BY sortorder, code";
  1257. // $fresult1 = Yii::app()->db->createCommand($fquery1)->query();
  1258. $fresult1 = Answers::model()->getAllRecords(" qid='{$deqrow['qid']}' AND language='{$surveyprintlang}' AND scale_id=1 ", array('sortorder','code'));
  1259. $fresult1 = $fresult1->readAll();
  1260. $fcount1 = count ($fresult1);
  1261. $fwidth = "120";
  1262. $l2=0;
  1263. //array to temporary store second scale question codes
  1264. $scale2array = array();
  1265. foreach ($fresult1 as $frow1)
  1266. {
  1267. $printablesurveyoutput2 .="\t\t\t<th>{$frow1['answer']}".self::_addsgqacode(" (".$frow1['code'].")")."</th>\n";
  1268. //add current question code
  1269. $scale2array[$l2] = $frow1['code'];
  1270. $l2++;
  1271. }
  1272. // build header if needed
  1273. if ($leftheader != '' || $rightheader !='')
  1274. {
  1275. $myheader = "\t\t\t<td>&nbsp;</td>";
  1276. $myheader .= "\t\t\t<th colspan=\"".$l1."\">$leftheader</th>\n";
  1277. if ($rightheader !='')
  1278. {
  1279. // $myheader .= "\t\t\t\t\t" .$myheader2;
  1280. $myheader .= "\t\t\t<td>&nbsp;</td>";
  1281. $myheader .= "\t\t\t<th colspan=\"".$l2."\">$rightheader</td>\n";
  1282. }
  1283. $myheader .= "\t\t\t\t</tr>\n";
  1284. }
  1285. else
  1286. {
  1287. $myheader = '';
  1288. }
  1289. $question['ANSWER'] .= $myheader . "\t\t</tr>\n\n\t\t<tr>\n";
  1290. $question['ANSWER'] .= $printablesurveyoutput2;
  1291. $question['ANSWER'] .= "\t\t</tr>\n\t</thead>\n\n\t<tbody>\n";
  1292. $rowclass = 'array1';
  1293. //counter for each subquestion
  1294. $sqcounter = 0;
  1295. $mearesult=Questions::model()->getAllRecords(" parent_qid={$deqrow['qid']} AND language='{$surveyprintlang}' ", array('question_order'));
  1296. foreach ($mearesult->readAll() as $mearow)
  1297. {
  1298. $question['ANSWER'] .= "\t\t<tr class=\"$rowclass\">\n";
  1299. $rowclass = alternation($rowclass,'row');
  1300. $answertext=$mearow['question'].self::_addsgqacode(" (".$fieldname.$mearow['title']."#0) / (".$fieldname.$mearow['title']."#1)");
  1301. if (strpos($answertext,'|')) {$answertext=substr($answertext,0, strpos($answertext,'|'));}
  1302. $question['ANSWER'] .= "\t\t\t<th class=\"answertext\">$answertext</th>\n";
  1303. for ($i=1; $i<=$fcount; $i++)
  1304. {
  1305. $question['ANSWER'] .= "\t\t\t<td>".self::_input_type_image('radio')."</td>\n";
  1306. }
  1307. $question['ANSWER'] .= "\t\t\t<td>&nbsp;</td>\n";
  1308. for ($i=1; $i<=$fcount1; $i++)
  1309. {
  1310. $question['ANSWER'] .= "\t\t\t<td>".self::_input_type_image('radio')."</td>\n";
  1311. }
  1312. $answertext=$mearow['question'];
  1313. if (strpos($answertext,'|'))
  1314. {
  1315. $answertext=substr($answertext,strpos($answertext,'|')+1);
  1316. $question['ANSWER'] .= "\t\t\t<th class=\"answertextright\">$answertext</th>\n";
  1317. }
  1318. $question['ANSWER'] .= "\t\t</tr>\n";
  1319. //increase subquestion counter
  1320. $sqcounter++;
  1321. }
  1322. $question['ANSWER'] .= "\t</tbody>\n</table>\n";
  1323. break;
  1324. // ==================================================================
  1325. case "H": //ARRAY (Flexible Labels) by Column
  1326. //$headstyle="style='border-left-style: solid; border-left-width: 1px; border-left-color: #AAAAAA'";
  1327. $headstyle="style='padding-left: 20px; padding-right: 7px'";
  1328. $condition = "parent_qid= '{$deqrow['qid']}' AND language= '{$surveyprintlang}'";
  1329. $fresult= Questions::model()->getAllRecords( $condition, array('question_order', 'title'));
  1330. $fresult = $fresult->readAll();
  1331. $question['QUESTION_TYPE_HELP'] .= $clang->gT("Please choose the appropriate response for each item:");
  1332. $question['ANSWER'] .= "\n<table>\n\t<thead>\n\t\t<tr>\n\t\t\t<td>&nbsp;</td>\n";
  1333. $fcount = count($fresult);
  1334. $fwidth = "120";
  1335. $i=0;
  1336. foreach ($fresult as $frow)
  1337. {
  1338. $question['ANSWER'] .= "\t\t\t<th>{$frow['question']}".self::_addsgqacode(" (".$fieldname.$frow['title'].")")."</th>\n";
  1339. $i++;
  1340. }
  1341. $question['ANSWER'] .= "\t\t</tr>\n\t</thead>\n\n\t<tbody>\n";
  1342. $a=1;
  1343. $rowclass = 'array1';
  1344. $mearesult=Answers::model()->getAllRecords(" qid='{$deqrow['qid']}' AND scale_id=0 AND language='{$surveyprintlang}' ", array('sortorder','code'));
  1345. foreach ($mearesult->readAll() as $mearow)
  1346. {
  1347. //$_POST['type']=$type;
  1348. $question['ANSWER'] .= "\t\t<tr class=\"$rowclass\">\n";
  1349. $rowclass = alternation($rowclass,'row');
  1350. $question['ANSWER'] .= "\t\t\t<th class=\"answertext\">{$mearow['answer']}".self::_addsgqacode(" (".$mearow['code'].")")."</th>\n";
  1351. //$printablesurveyoutput .="\t\t\t\t\t<td>";
  1352. for ($i=1; $i<=$fcount; $i++)
  1353. {
  1354. $question['ANSWER'] .= "\t\t\t<td>".self::_input_type_image('radio')."</td>\n";
  1355. }
  1356. //$printablesurveyoutput .="\t\t\t\t\t</tr></table></td>\n";
  1357. $question['ANSWER'] .= "\t\t</tr>\n";
  1358. $a++;
  1359. }
  1360. $question['ANSWER'] .= "\t</tbody>\n</table>\n";
  1361. break;
  1362. case "|": // File Upload
  1363. $question['QUESTION_TYPE_HELP'] .= "Kindly attach the aforementioned documents along with the survey";
  1364. break;
  1365. // === END SWITCH ===================================================
  1366. }
  1367. $question['QUESTION_TYPE_HELP'] = self::_star_replace($question['QUESTION_TYPE_HELP']);
  1368. $group['QUESTIONS'] .= self::_populate_template( 'question' , $question);
  1369. }
  1370. if ($bGroupHasVisibleQuestions)
  1371. {
  1372. $survey_output['GROUPS'] .= self::_populate_template( 'group' , $group );
  1373. }
  1374. }
  1375. $survey_output['THEREAREXQUESTIONS'] = str_replace( '{NUMBEROFQUESTIONS}' , $total_questions , $clang->gT('There are {NUMBEROFQUESTIONS} questions in this survey'));
  1376. // START recursive tag stripping.
  1377. // PHP 5.1.0 introduced the count parameter for preg_replace() and thus allows this procedure to run with only one regular expression.
  1378. // Previous version of PHP needs two regular expressions to do the same thing and thus will run a bit slower.
  1379. $server_is_newer = version_compare(PHP_VERSION , '5.1.0' , '>');
  1380. $rounds = 0;
  1381. while($rounds < 1)
  1382. {
  1383. $replace_count = 0;
  1384. if($server_is_newer) // Server version of PHP is at least 5.1.0 or newer
  1385. {
  1386. $survey_output['GROUPS'] = preg_replace(
  1387. array(
  1388. '/<td>(?:&nbsp;|&#160;| )?<\/td>/isU'
  1389. ,'/<th[^>]*>(?:&nbsp;|&#160;| )?<\/th>/isU'
  1390. ,'/<([^ >]+)[^>]*>(?:&nbsp;|&#160;|\r\n|\n\r|\n|\r|\t| )*<\/\1>/isU'
  1391. )
  1392. ,array(
  1393. '[[EMPTY-TABLE-CELL]]'
  1394. ,'[[EMPTY-TABLE-CELL-HEADER]]'
  1395. ,''
  1396. )
  1397. ,$survey_output['GROUPS']
  1398. ,-1
  1399. ,$replace_count
  1400. );
  1401. }
  1402. else // Server version of PHP is older than 5.1.0
  1403. {
  1404. $survey_output['GROUPS'] = preg_replace(
  1405. array(
  1406. '/<td>(?:&nbsp;|&#160;| )?<\/td>/isU'
  1407. ,'/<th[^>]*>(?:&nbsp;|&#160;| )?<\/th>/isU'
  1408. ,'/<([^ >]+)[^>]*>(?:&nbsp;|&#160;|\r\n|\n\r|\n|\r|\t| )*<\/\1>/isU'
  1409. )
  1410. ,array(
  1411. '[[EMPTY-TABLE-CELL]]'
  1412. ,'[[EMPTY-TABLE-CELL-HEADER]]'
  1413. ,''
  1414. )
  1415. ,$survey_output['GROUPS']
  1416. );
  1417. $replace_count = preg_match(
  1418. '/<([^ >]+)[^>]*>(?:&nbsp;|&#160;|\r\n|\n\r|\n|\r|\t| )*<\/\1>/isU'
  1419. , $survey_output['GROUPS']
  1420. );
  1421. }
  1422. if($replace_count == 0)
  1423. {
  1424. ++$rounds;
  1425. $survey_output['GROUPS'] = preg_replace(
  1426. array(
  1427. '/\[\[EMPTY-TABLE-CELL\]\]/'
  1428. ,'/\[\[EMPTY-TABLE-CELL-HEADER\]\]/'
  1429. ,'/\n(?:\t*\n)+/'
  1430. )
  1431. ,array(
  1432. '<td>&nbsp;</td>'
  1433. ,'<th>&nbsp;</th>'
  1434. ,"\n"
  1435. )
  1436. ,$survey_output['GROUPS']
  1437. );
  1438. }
  1439. }
  1440. $survey_output['GROUPS'] = preg_replace( '/(<div[^>]*>){NOTEMPTY}(<\/div>)/' , '\1&nbsp;\2' , $survey_output['GROUPS']);
  1441. // END recursive empty tag stripping.
  1442. echo self::_populate_template( 'survey' , $survey_output );
  1443. }// End print
  1444. }
  1445. /**
  1446. * A poor mans templating system.
  1447. *
  1448. * $template template filename (path is privided by config.php)
  1449. * $input a key => value array containg all the stuff to be put into the template
  1450. * $line for debugging purposes only.
  1451. *
  1452. * Returns a formatted string containing template with
  1453. * keywords replaced by variables.
  1454. *
  1455. * How:
  1456. */
  1457. private function _populate_template( $template , $input , $line = '')
  1458. {
  1459. $full_path = PRINT_TEMPLATE_DIR.'print_'.$template.'.pstpl';
  1460. $full_constant = 'TEMPLATE'.$template.'.pstpl';
  1461. if(!defined($full_constant))
  1462. {
  1463. if(is_file($full_path))
  1464. {
  1465. define( $full_constant , file_get_contents($full_path));
  1466. $template_content = constant($full_constant);
  1467. $test_empty = trim($template_content);
  1468. if(empty($test_empty))
  1469. {
  1470. return "<!--\n\t$full_path\n\tThe template was empty so is useless.\n-->";
  1471. }
  1472. }
  1473. else
  1474. {
  1475. define($full_constant , '');
  1476. return "<!--\n\t$full_path is not a propper file or is missing.\n-->";
  1477. }
  1478. }
  1479. else
  1480. {
  1481. $template_content = constant($full_constant);
  1482. $test_empty = trim($template_content);
  1483. if(empty($test_empty))
  1484. {
  1485. return "<!--\n\t$full_path\n\tThe template was empty so is useless.\n-->";
  1486. }
  1487. }
  1488. if(is_array($input))
  1489. {
  1490. foreach($input as $key => $value)
  1491. {
  1492. $find[] = '{'.$key.'}';
  1493. $replace[] = $value;
  1494. }
  1495. return str_replace( $find , $replace , $template_content );
  1496. }
  1497. else
  1498. {
  1499. if(Yii::app()->getConfig('debug') > 0)
  1500. {
  1501. if(!empty($line))
  1502. {
  1503. $line = 'LINE '.$line.': ';
  1504. }
  1505. return '<!-- '.$line.'There was nothing to put into the template -->'."\n";
  1506. }
  1507. }
  1508. }
  1509. private function _min_max_answers_help($qidattributes, $surveyprintlang, $surveyid) {
  1510. $clang = $this->getController()->lang;
  1511. $output = "";
  1512. if(!empty($qidattributes['min_answers'])) {
  1513. $output .= "\n<p class='extrahelp'>".sprintf($clang->gT("Please choose at least %s items."), $qidattributes['min_answers'])."</p>\n";
  1514. }
  1515. if(!empty($qidattributes['max_answers'])) {
  1516. $output .= "\n<p class='extrahelp'>".sprintf($clang->gT("Please choose no more than %s items."),$qidattributes['max_answers'])."</p>\n";
  1517. }
  1518. return $output;
  1519. }
  1520. private function _input_type_image( $type , $title = '' , $x = 40 , $y = 1 , $line = '' )
  1521. {
  1522. if($type == 'other' or $type == 'othercomment')
  1523. {
  1524. $x = 1;
  1525. }
  1526. $tail = substr($x , -1 , 1);
  1527. switch($tail)
  1528. {
  1529. case '%':
  1530. case 'm':
  1531. case 'x': $x_ = $x;
  1532. break;
  1533. default: $x_ = $x / 2;
  1534. }
  1535. if($y < 2)
  1536. {
  1537. $y_ = 2;
  1538. }
  1539. else
  1540. {
  1541. $y_ = $y * 2;
  1542. }
  1543. if(!empty($title))
  1544. {
  1545. $div_title = ' title="'.htmlspecialchars($title).'"';
  1546. }
  1547. else
  1548. {
  1549. $div_title = '';
  1550. }
  1551. switch($type)
  1552. {
  1553. case 'textarea':
  1554. case 'text': $style = ' style="width:'.$x_.'em; height:'.$y_.'em;"';
  1555. break;
  1556. default: $style = '';
  1557. }
  1558. switch($type)
  1559. {
  1560. case 'radio':
  1561. case 'checkbox':if(!defined('IMAGE_'.$type.'_SIZE'))
  1562. {
  1563. $image_dimensions = getimagesize(PRINT_TEMPLATE_DIR.'print_img_'.$type.'.png');
  1564. // define('IMAGE_'.$type.'_SIZE' , ' width="'.$image_dimensions[0].'" height="'.$image_dimensions[1].'"');
  1565. define('IMAGE_'.$type.'_SIZE' , ' width="14" height="14"');
  1566. }
  1567. $output = '<img src="'.PRINT_TEMPLATE_URL.'print_img_'.$type.'.png"'.constant('IMAGE_'.$type.'_SIZE').' alt="'.htmlspecialchars($title).'" class="input-'.$type.'" />';
  1568. break;
  1569. case 'rank':
  1570. case 'other':
  1571. case 'othercomment':
  1572. case 'text':
  1573. case 'textarea':$output = '<div class="input-'.$type.'"'.$style.$div_title.'>{NOTEMPTY}</div>';
  1574. break;
  1575. default: $output = '';
  1576. }
  1577. return $output;
  1578. }
  1579. private function _star_replace($input)
  1580. {
  1581. return preg_replace(
  1582. '/\*(.*)\*/U'
  1583. ,'<strong>\1</strong>'
  1584. ,$input
  1585. );
  1586. }
  1587. private function _array_filter_help($qidattributes, $surveyprintlang, $surveyid)
  1588. {
  1589. $clang = $this->getController()->lang;
  1590. $output = "";
  1591. if(!empty($qidattributes['array_filter']))
  1592. {
  1593. $newquestiontext = Questions::model()->findByAttributes(array('title' => $qidattributes['array_filter'], 'language' => $surveyprintlang, 'sid' => $surveyid))->getAttribute('question');
  1594. $output .= "\n<p class='extrahelp'>
  1595. ".sprintf($clang->gT("Only answer this question for the items you selected in question %s ('%s')"),$qidattributes['array_filter'], flattenText(breakToNewline($newquestiontext['question'])))."
  1596. </p>\n";
  1597. }
  1598. if(!empty($qidattributes['array_filter_exclude']))
  1599. {
  1600. $newquestiontext = Questions::model()->findByAttributes(array('title' => $qidattributes['array_filter_exclude'], 'language' => $surveyprintlang, 'sid' => $surveyid))->getAttribute('question');
  1601. $output .= "\n <p class='extrahelp'>
  1602. ".sprintf($clang->gT("Only answer this question for the items you did not select in question %s ('%s')"),$qidattributes['array_filter_exclude'], breakToNewline($newquestiontext['question']))."
  1603. </p>\n";
  1604. }
  1605. return $output;
  1606. }
  1607. /*
  1608. * $code: Text string containing the reference (column heading) for the current (sub-) question
  1609. *
  1610. * Checks if the $showsgqacode setting is enabled at config and adds references to the column headings
  1611. * to the output so it can be used as a code book for customized SQL queries when analysing data.
  1612. *
  1613. * return: adds the text string to the overview
  1614. */
  1615. private function _addsgqacode($code)
  1616. {
  1617. $showsgqacode = Yii::app()->getConfig('showsgqacode');
  1618. if(isset($showsgqacode) && $showsgqacode == true)
  1619. {
  1620. return $code;
  1621. }
  1622. }
  1623. }