reporting.php 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180
  1. <?php
  2. /*
  3. DOKEOS - elearning and course management software
  4. For a full list of contributors, see documentation/credits.html
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. See "documentation/licence.html" more details.
  10. Contact:
  11. Dokeos
  12. Rue des Palais 44 Paleizenstraat
  13. B-1030 Brussels - Belgium
  14. Tel. +32 (2) 211 34 56
  15. */
  16. /**
  17. * @package dokeos.survey
  18. * @author unknown, the initial survey that did not make it in 1.8 because of bad code
  19. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of the code
  20. * @version $Id: reporting.php 11685 2007-03-25 21:14:55Z pcool $
  21. *
  22. * @todo The question has to be more clearly indicated (same style as when filling the survey)
  23. */
  24. // name of the language file that needs to be included
  25. $language_file = 'survey';
  26. // including the global dokeos file
  27. require ('../inc/global.inc.php');
  28. // export
  29. /**
  30. * @todo use export_table_csv($data, $filename = 'export')
  31. */
  32. if ($_POST['export_report'])
  33. {
  34. $data = export_complete_report();
  35. $filename = 'fileexport.csv';
  36. header('Content-type: application/octet-stream');
  37. header('Content-Type: application/force-download');
  38. header('Content-length: '.$len);
  39. if (preg_match("/MSIE 5.5/", $_SERVER['HTTP_USER_AGENT']))
  40. {
  41. header('Content-Disposition: filename= '.$filename);
  42. }
  43. else
  44. {
  45. header('Content-Disposition: attachment; filename= '.$filename);
  46. }
  47. if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE'))
  48. {
  49. header('Pragma: ');
  50. header('Cache-Control: ');
  51. header('Cache-Control: public'); // IE cannot download from sessions without a cache
  52. }
  53. header('Content-Description: '.$filename);
  54. header('Content-transfer-encoding: binary');
  55. echo $data;
  56. exit;
  57. }
  58. // including additional libraries
  59. //require_once (api_get_path(LIBRARY_PATH)."/survey.lib.php");
  60. require_once('survey.lib.php');
  61. require_once (api_get_path(LIBRARY_PATH)."/course.lib.php");
  62. // Checking the parameters
  63. check_parameters();
  64. /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
  65. if (!api_is_allowed_to_edit())
  66. {
  67. Display :: display_header();
  68. Display :: display_error_message(get_lang('NotAllowedHere'), false);
  69. Display :: display_footer();
  70. exit;
  71. }
  72. // Database table definitions
  73. $table_survey = Database :: get_course_table(TABLE_SURVEY);
  74. $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  75. $table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
  76. $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  77. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  78. $user_info = Database :: get_main_table(TABLE_MAIN_SURVEY_REMINDER);
  79. // getting the survey information
  80. $survey_data = survey_manager::get_survey($_GET['survey_id']);
  81. $urlname = substr(strip_tags($survey_data['title']), 0, 40);
  82. if (strlen(strip_tags($survey_data['title'])) > 40)
  83. {
  84. $urlname .= '...';
  85. }
  86. // breadcrumbs
  87. $interbreadcrumb[] = array ("url" => "survey_list.php", "name" => get_lang('SurveyList'));
  88. $interbreadcrumb[] = array ('url' => 'survey.php?survey_id='.$_GET['survey_id'], 'name' => $urlname);
  89. if (!$_GET['action'] OR $_GET['action'] == 'overview')
  90. {
  91. $tool_name = get_lang('Reporting');
  92. }
  93. else
  94. {
  95. $interbreadcrumb[] = array ("url" => "reporting.php?survey_id=".$_GET['survey_id'], "name" => get_lang('Reporting'));
  96. switch ($_GET['action'])
  97. {
  98. case 'questionreport':
  99. $tool_name = get_lang('DetailedReportByQuestion');
  100. break;
  101. case 'userreport':
  102. $tool_name = get_lang('DetailedReportByUser');
  103. break;
  104. case 'comparativereport':
  105. $tool_name = get_lang('ComparativeReport');
  106. break;
  107. case 'completereport':
  108. $tool_name = get_lang('CompleteReport');
  109. break;
  110. }
  111. }
  112. // Displaying the header
  113. Display::display_header($tool_name);
  114. // Action handling
  115. handle_reporting_actions();
  116. if (!$_GET['action'] OR $_GET['action'] == 'overview')
  117. {
  118. echo '<b><a href="reporting.php?action=questionreport&amp;survey_id='.$_GET['survey_id'].'">'.get_lang('DetailedReportByQuestion').'</a></b> <br />'.get_lang('DetailedReportByQuestionDetail').' <br /><br />';
  119. echo '<b><a href="reporting.php?action=userreport&amp;survey_id='.$_GET['survey_id'].'">'.get_lang('DetailedReportByUser').'</a></b><br />'.get_lang('DetailedReportByUserDetail').'.<br /><br />';
  120. echo '<b><a href="reporting.php?action=comparativereport&amp;survey_id='.$_GET['survey_id'].'">'.get_lang('ComparativeReport').'</a></b><br />'.get_lang('ComparativeReportDetail').'.<br /><br />';
  121. echo '<b><a href="reporting.php?action=completereport&amp;survey_id='.$_GET['survey_id'].'">'.get_lang('CompleteReport').'</a></b><br />'.get_lang('CompleteReportDetail').'<br /><br />';
  122. }
  123. // Footer
  124. Display :: display_footer();
  125. /**
  126. * This function checks the parameters that are used in this page
  127. *
  128. * @return the header, an error and the footer if any parameter fails, else it returns true
  129. *
  130. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  131. * @version February 2007
  132. */
  133. function check_parameters()
  134. {
  135. $error = false;
  136. // $_GET['survey_id'] has to be numeric
  137. if (!is_numeric($_GET['survey_id']))
  138. {
  139. $error = get_lang('IllegalSurveyId');
  140. }
  141. // $_GET['action']
  142. $allowed_actions = array('overview', 'questionreport', 'userreport', 'comparativereport', 'completereport');
  143. if (isset($_GET['action']) AND !in_array($_GET['action'], $allowed_actions))
  144. {
  145. $error = get_lang('ActionNotAllowed');
  146. }
  147. // user report
  148. if ($_GET['action'] == 'userreport')
  149. {
  150. global $people_filled;
  151. $people_filled = survey_manager::get_people_who_filled_survey($_GET['survey_id']);
  152. if (isset($_GET['user']) AND !in_array($_GET['user'], $people_filled))
  153. {
  154. $error = get_lang('UnknowUser');
  155. }
  156. }
  157. // question report
  158. if ($_GET['action'] == 'questionreport')
  159. {
  160. if (isset($_GET['question'])AND !is_numeric($_GET['question']))
  161. {
  162. $error = get_lang('UnknowQuestion');
  163. }
  164. }
  165. if ($error)
  166. {
  167. Display::display_header();
  168. Display::display_error_message(get_lang('Error').': '.$error, false);
  169. Display::display_footer();
  170. exit;
  171. }
  172. else
  173. {
  174. return true;
  175. }
  176. }
  177. /**
  178. * This function deals with the action handling
  179. *
  180. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  181. * @version February 2007
  182. */
  183. function handle_reporting_actions()
  184. {
  185. // getting the number of question
  186. $temp_questions_data = survey_manager::get_questions($_GET['survey_id']);
  187. // sorting like they should be displayed and removing the non-answer question types (comment and pagebreak)
  188. foreach ($temp_questions_data as $key=>$value)
  189. {
  190. if ($value['type'] <> 'comment' AND $value['type']<>'pagebreak')
  191. {
  192. $questions_data[$value['sort']]=$value;
  193. }
  194. }
  195. // counting the number of questions that are relevant for the reporting
  196. $survey_data['number_of_questions'] = count($questions_data);
  197. if ($_GET['action'] == 'questionreport')
  198. {
  199. display_question_report($survey_data);
  200. }
  201. if ($_GET['action'] == 'userreport')
  202. {
  203. display_user_report();
  204. }
  205. if ($_GET['action'] == 'comparativereport')
  206. {
  207. display_comparative_report();
  208. }
  209. if ($_GET['action'] == 'completereport')
  210. {
  211. display_complete_report();
  212. }
  213. }
  214. /**
  215. * This function displays the user report which is basically nothing more than a one-page display of all the questions
  216. * of the survey that is filled with the answers of the person who filled the survey.
  217. *
  218. * @return html code of the one-page survey with the answers of the selected user
  219. *
  220. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  221. * @version February 2007
  222. */
  223. function display_user_report()
  224. {
  225. global $people_filled;
  226. // Database table definitions
  227. $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  228. $table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
  229. $table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER);
  230. // step 1: selection of the user
  231. echo "<script language=\"JavaScript\" type=\"text/JavaScript\">
  232. <!--
  233. function jumpMenu(targ,selObj,restore)
  234. {
  235. eval(targ+\".location='\"+selObj.options[selObj.selectedIndex].value+\"'\");
  236. if (restore) selObj.selectedIndex=0;
  237. }
  238. //-->
  239. </script>
  240. ";
  241. echo get_lang('SelectUserWhoFilledSurvey').'<br />';
  242. echo '<select name="user" onchange="jumpMenu(\'parent\',this,0)">';
  243. echo '<option value="reporting.php?action='.$_GET['action'].'&amp;survey_id='.$_GET['survey_id'].'">'.get_lang('SelectUser').'</option>';
  244. foreach ($people_filled as $key=>$person)
  245. {
  246. echo '<option value="reporting.php?action='.$_GET['action'].'&amp;survey_id='.$_GET['survey_id'].'&amp;user='.$person.'" ';
  247. if ($_GET['user'] == $person)
  248. {
  249. echo 'selected="selected"';
  250. }
  251. echo '>'.$person.'</option>';
  252. }
  253. echo '</select>';
  254. // step 2: displaying the survey and the answer of the selected users
  255. if (isset($_GET['user']))
  256. {
  257. Display::display_normal_message(get_lang('AllQuestionsOnOnePage'), false);
  258. // getting all the questions and options
  259. $sql = "SELECT survey_question.question_id, survey_question.survey_id, survey_question.survey_question, survey_question.display, survey_question.max_value, survey_question.sort, survey_question.type,
  260. survey_question_option.question_option_id, survey_question_option.option_text, survey_question_option.sort as option_sort
  261. FROM $table_survey_question survey_question
  262. LEFT JOIN $table_survey_question_option survey_question_option
  263. ON survey_question.question_id = survey_question_option.question_id
  264. WHERE survey_question.survey_id = '".Database::escape_string($_GET['survey_id'])."'
  265. ORDER BY survey_question.sort ASC";
  266. $result = api_sql_query($sql, __FILE__, __LINE__);
  267. while ($row = mysql_fetch_assoc($result))
  268. {
  269. if($row['type'] <> 'pagebreak')
  270. {
  271. $questions[$row['sort']]['question_id'] = $row['question_id'];
  272. $questions[$row['sort']]['survey_id'] = $row['survey_id'];
  273. $questions[$row['sort']]['survey_question'] = $row['survey_question'];
  274. $questions[$row['sort']]['display'] = $row['display'];
  275. $questions[$row['sort']]['type'] = $row['type'];
  276. $questions[$row['sort']]['maximum_score'] = $row['max_value'];
  277. $questions[$row['sort']]['options'][$row['question_option_id']] = $row['option_text'];
  278. }
  279. }
  280. // getting all the answers of the user
  281. $sql = "SELECT * FROM $table_survey_answer WHERE survey_id = '".Database::escape_string($_GET['survey_id'])."' AND user = '".Database::escape_string($_GET['user'])."'";
  282. $result = api_sql_query($sql, __FILE__, __LINE__);
  283. while ($row = mysql_fetch_assoc($result))
  284. {
  285. $answers[$row['question_id']][] = $row['option_id'];
  286. $all_answers[$row['question_id']][] = $row;
  287. }
  288. // displaying all the questions
  289. foreach ($questions as $key=>$question)
  290. {
  291. // if the question type is a scoring then we have to format the answers differently
  292. if ($question['type'] == 'score')
  293. {
  294. foreach($all_answers[$question['question_id']] as $key=>$answer_array)
  295. {
  296. $second_parameter[$answer_array['option_id']] = $answer_array['value'];
  297. }
  298. }
  299. else
  300. {
  301. $second_parameter = $answers[$question['question_id']];
  302. }
  303. $display = new $question['type'];
  304. $display->render_question($question, $second_parameter);
  305. // echo '<pre>';
  306. // print_r($answers[$question['question_id']]);
  307. // echo '</pre>';
  308. }
  309. }
  310. }
  311. /**
  312. * This function displays the report by question.
  313. * It displays a table with all the options of the question and the number of users who have answered positively on the option.
  314. * The number of users who answered positive on a given option is expressed in an absolute number, in a percentage of the total
  315. * and graphically using bars
  316. * By clicking on the absolute number you get a list with the persons who have answered this.
  317. * You can then click on the name of the person and you will then go to the report by user where you see all the
  318. * answers of that user.
  319. *
  320. * @param array $survey_data all the data of the survey
  321. *
  322. * @return html code that displays the report by question
  323. *
  324. * @todo allow switching between horizontal and vertical.
  325. * @todo multiple response: percentage are probably not OK
  326. * @todo the question and option text have to be shortened and should expand when the user clicks on it.
  327. * @todo the pagebreak and comment question types should not be shown => removed from $survey_data before
  328. *
  329. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  330. * @version February 2007
  331. */
  332. function display_question_report($survey_data)
  333. {
  334. // Database table definitions
  335. $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  336. $table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
  337. $table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER);
  338. // determining the offset of the sql statement (the n-th question of the survey)
  339. if (!isset($_GET['question']))
  340. {
  341. $offset = 0;
  342. }
  343. else
  344. {
  345. $offset = $_GET['question'];
  346. }
  347. echo '<div id="question_report_questionnumbers">';
  348. for($i=1; $i<=($survey_data['number_of_questions']); $i++ )
  349. {
  350. if ($offset <> $i-1)
  351. {
  352. echo '<a href="reporting.php?action=questionreport&amp;survey_id='.(int)$_GET['survey_id'].'&amp;question='.($i-1).'">'.$i.'</a>';
  353. }
  354. else
  355. {
  356. echo $i;
  357. }
  358. if ($i < $survey_data['number_of_questions'])
  359. {
  360. echo ' | ';
  361. }
  362. }
  363. echo '</div>';
  364. // getting the question information
  365. $sql = "SELECT * FROM $table_survey_question WHERE survey_id='".Database::escape_string($_GET['survey_id'])."' AND type<>'pagebreak' AND type<>'comment' ORDER BY sort ASC LIMIT ".$offset.",1";
  366. $result = api_sql_query($sql, __FILE__, __LINE__);
  367. $question = mysql_fetch_assoc($result);
  368. // navigate through the questions (next and previous)
  369. if ($_GET['question'] <> 0)
  370. {
  371. echo '<a href="reporting.php?action='.$_GET['action'].'&amp;survey_id='.$_GET['survey_id'].'&amp;question='.($offset-1).'"> &lt;&lt; '.get_lang('PreviousQuestion').'</a> ';
  372. }
  373. else
  374. {
  375. echo '&lt;&lt;'.get_lang('PreviousQuestion').' ';
  376. }
  377. echo ' | ';
  378. if ($_GET['question'] < ($survey_data['number_of_questions']-1))
  379. {
  380. echo '<a href="reporting.php?action='.$_GET['action'].'&amp;survey_id='.$_GET['survey_id'].'&amp;question='.($offset+1).'">'.get_lang('NextQuestion').'&gt;&gt; </a>';
  381. }
  382. else
  383. {
  384. echo get_lang('NextQuestion'). '&gt;&gt;';
  385. }
  386. echo '<br />';
  387. echo $question['survey_question'];
  388. echo '<br />';
  389. if ($question['type'] == 'score')
  390. {
  391. /** @todo this function should return the options as this is needed further in the code */
  392. $options = display_question_report_score($survey_data, $question, $offset);
  393. }
  394. elseif ($question['type'] == 'open')
  395. {
  396. /** @todo also get the user who has answered this */
  397. $sql = "SELECT * FROM $table_survey_answer WHERE survey_id='".Database::escape_string($_GET['survey_id'])."'
  398. AND question_id = '".Database::escape_string($question['question_id'])."'";
  399. $result = api_sql_query($sql, __FILE__, __LINE__);
  400. while ($row = mysql_fetch_assoc($result))
  401. {
  402. echo $row['option_id'].'<hr noshade="noshade" size="1" />';
  403. }
  404. }
  405. else
  406. {
  407. // getting the options
  408. $sql = "SELECT * FROM $table_survey_question_option
  409. WHERE survey_id='".Database::escape_string($_GET['survey_id'])."'
  410. AND question_id = '".Database::escape_string($question['question_id'])."'
  411. ORDER BY sort ASC";
  412. $result = api_sql_query($sql, __FILE__, __LINE__);
  413. while ($row = mysql_fetch_assoc($result))
  414. {
  415. $options[$row['question_option_id']] = $row;
  416. }
  417. // getting the answers
  418. $sql = "SELECT *, count(answer_id) as total FROM $table_survey_answer
  419. WHERE survey_id='".Database::escape_string($_GET['survey_id'])."'
  420. AND question_id = '".Database::escape_string($question['question_id'])."'
  421. GROUP BY option_id, value";
  422. $result = api_sql_query($sql, __FILE__, __LINE__);
  423. while ($row = mysql_fetch_assoc($result))
  424. {
  425. $number_of_answers += $row['total'];
  426. $data[$row['option_id']] = $row;
  427. }
  428. // displaying the table: headers
  429. echo '<table>';
  430. echo ' <tr>';
  431. echo ' <th>&nbsp;</th>';
  432. echo ' <th>'.get_lang('AbsoluteTotal').'</th>';
  433. echo ' <th>'.get_lang('Percentage').'</th>';
  434. echo ' <th>'.get_lang('VisualRepresentation').'</th>';
  435. echo ' <tr>';
  436. // displaying the table: the content
  437. foreach ($options as $key=>$value)
  438. {
  439. $absolute_number = $data[$value['question_option_id']]['total'];
  440. echo ' <tr>';
  441. echo ' <td>'.$value['option_text'].'</td>';
  442. echo ' <td><a href="reporting.php?action='.$_GET['action'].'&amp;survey_id='.$_GET['survey_id'].'&amp;question='.$offset.'&amp;viewoption='.$value['question_option_id'].'">'.$absolute_number.'</a></td>';
  443. echo ' <td>'.round($absolute_number/$number_of_answers*100, 2).' %</td>';
  444. echo ' <td><div style="background-color:#0066CC; height:10px; width:'.($absolute_number/$number_of_answers*100*2).'px">&nbsp;</div></td>';
  445. echo ' </tr>';
  446. }
  447. // displaying the table: footer (totals)
  448. echo ' <tr>';
  449. echo ' <td style="border-top:1px solid black"><b>'.get_lang('Total').'</b></td>';
  450. echo ' <td style="border-top:1px solid black"><b>'.$number_of_answers.'</b></td>';
  451. echo ' <td style="border-top:1px solid black">&nbsp;</td>';
  452. echo ' <td style="border-top:1px solid black">&nbsp;</td>';
  453. echo ' </tr>';
  454. echo '</table>';
  455. }
  456. if (isset($_GET['viewoption']))
  457. {
  458. echo get_lang('PeopleWhoAnswered').': '.$options[$_GET['viewoption']]['option_text'].'<br />';
  459. if (is_numeric($_GET['value']))
  460. {
  461. $sql_restriction = "AND value='".Database::escape_string($_GET['value'])."'";
  462. }
  463. $sql = "SELECT user FROM $table_survey_answer WHERE option_id = '".Database::escape_string($_GET['viewoption'])."' $sql_restriction";
  464. $result = api_sql_query($sql, __FILE__, __LINE__);
  465. while ($row = mysql_fetch_assoc($result))
  466. {
  467. echo '<a href="reporting.php?action=userreport&survey_id='.$_GET['survey_id'].'&user='.$row['user'].'">'.$row['user'].'</a><br />';
  468. }
  469. }
  470. }
  471. function display_question_report_score($survey_data, $question, $offset)
  472. {
  473. // Database table definitions
  474. $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  475. $table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
  476. $table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER);
  477. // getting the options
  478. $sql = "SELECT * FROM $table_survey_question_option
  479. WHERE survey_id='".Database::escape_string($_GET['survey_id'])."'
  480. AND question_id = '".Database::escape_string($question['question_id'])."'
  481. ORDER BY sort ASC";
  482. $result = api_sql_query($sql, __FILE__, __LINE__);
  483. while ($row = mysql_fetch_assoc($result))
  484. {
  485. $options[$row['question_option_id']] = $row;
  486. }
  487. // getting the answers
  488. $sql = "SELECT *, count(answer_id) as total FROM $table_survey_answer
  489. WHERE survey_id='".Database::escape_string($_GET['survey_id'])."'
  490. AND question_id = '".Database::escape_string($question['question_id'])."'
  491. GROUP BY option_id, value";
  492. $result = api_sql_query($sql, __FILE__, __LINE__);
  493. while ($row = mysql_fetch_assoc($result))
  494. {
  495. $number_of_answers += $row['total'];
  496. $data[$row['option_id']][$row['value']] = $row;
  497. }
  498. /*
  499. echo '<pre>';
  500. print_r($data);
  501. echo '</pre>';
  502. */
  503. // displaying the table: headers
  504. echo '<table>';
  505. echo ' <tr>';
  506. echo ' <th>&nbsp;</th>';
  507. echo ' <th>'.get_lang('Score').'</th>';
  508. echo ' <th>'.get_lang('AbsoluteTotal').'</th>';
  509. echo ' <th>'.get_lang('Percentage').'</th>';
  510. echo ' <th>'.get_lang('VisualRepresentation').'</th>';
  511. echo ' <tr>';
  512. // displaying the table: the content
  513. foreach ($options as $key=>$value)
  514. {
  515. for ($i=1; $i<=$question['max_value']; $i++)
  516. {
  517. $absolute_number = $data[$value['question_option_id']][$i]['total'];
  518. echo ' <tr>';
  519. echo ' <td>'.$value['option_text'].'</td>';
  520. echo ' <td>'.$i.'</td>';
  521. echo ' <td><a href="reporting.php?action='.$_GET['action'].'&amp;survey_id='.$_GET['survey_id'].'&amp;question='.$offset.'&amp;viewoption='.$value['question_option_id'].'&amp;value='.$i.'">'.$absolute_number.'</a></td>';
  522. echo ' <td>'.round($absolute_number/$number_of_answers*100, 2).' %</td>';
  523. echo ' <td><div style="background-color:#0066CC; height:10px; width:'.($absolute_number/$number_of_answers*100*2).'px">&nbsp;</div></td>';
  524. echo ' </tr>';
  525. }
  526. }
  527. // displaying the table: footer (totals)
  528. echo ' <tr>';
  529. echo ' <td style="border-top:1px solid black"><b>'.get_lang('Total').'</b></td>';
  530. echo ' <td style="border-top:1px solid black">&nbsp;</td>';
  531. echo ' <td style="border-top:1px solid black"><b>'.$number_of_answers.'</b></td>';
  532. echo ' <td style="border-top:1px solid black">&nbsp;</td>';
  533. echo ' <td style="border-top:1px solid black">&nbsp;</td>';
  534. echo ' </tr>';
  535. echo '</table>';
  536. }
  537. /**
  538. * This functions displays the complete reporting
  539. *
  540. * @return html code
  541. *
  542. * @todo open questions are not in the complete report yet.
  543. *
  544. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  545. * @version February 2007
  546. */
  547. function display_complete_report()
  548. {
  549. // Database table definitions
  550. $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  551. $table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
  552. $table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER);
  553. // the form
  554. echo '<form id="form1" name="form1" method="post" action="'.$_SERVER['PHP_SELF'].'?action='.$_GET['action'].'&survey_id='.$_GET['survey_id'].'">';
  555. // the export button
  556. echo '<input type="submit" name="export_report" value="'.get_lang('ExportCurrentReport').'" />';
  557. // the table
  558. echo '<table class="data_table" border="1">';
  559. // getting the number of options per question
  560. echo ' <tr>';
  561. echo ' <th>';
  562. if ($_POST['submit_question_filter'] OR $_POST['export_report'])
  563. {
  564. echo ' <input type="submit" name="reset_question_filter" value="'.get_lang('ResetQuestionFilter').'" />';
  565. }
  566. echo ' <input type="submit" name="submit_question_filter" value="'.get_lang('SubmitQuestionFilter').'" />';
  567. echo '</th>';
  568. $sql = "SELECT questions.question_id, questions.type, questions.survey_question, count(options.question_option_id) as number_of_options
  569. FROM $table_survey_question questions LEFT JOIN $table_survey_question_option options
  570. ON questions.question_id = options.question_id
  571. /*WHERE questions.question_id = options.question_id*/
  572. AND questions.survey_id = '".Database::escape_string($_GET['survey_id'])."'
  573. GROUP BY questions.question_id";
  574. $result = api_sql_query($sql, __FILE__, __LINE__);
  575. while ($row = mysql_fetch_assoc($result))
  576. {
  577. // we show the questions if
  578. // 1. there is no question filter and the export button has not been clicked
  579. // 2. there is a quesiton filter but the question is selected for display
  580. if (!($_POST['submit_question_filter'] OR $_POST['export_report']) OR in_array($row['question_id'], $_POST['questions_filter']))
  581. {
  582. // we do not show comment and pagebreak question types
  583. if ($row['type'] <> 'comment' AND $row['type'] <> 'pagebreak')
  584. {
  585. echo ' <th';
  586. if ($row['number_of_options'] >0)
  587. {
  588. echo ' colspan="'.$row['number_of_options'].'"';
  589. }
  590. echo '>';
  591. echo '<label><input type="checkbox" name="questions_filter[]" value="'.$row['question_id'].'" checked="checked"/> ';
  592. echo $row['survey_question'];
  593. echo '</label>';
  594. echo '</th>';
  595. }
  596. }
  597. }
  598. echo ' </tr>';
  599. // getting all the questions and options
  600. echo ' <tr>';
  601. echo ' <th>&nbsp;</th>'; // the user column
  602. $sql = "SELECT survey_question.question_id, survey_question.survey_id, survey_question.survey_question, survey_question.display, survey_question.sort, survey_question.type,
  603. survey_question_option.question_option_id, survey_question_option.option_text, survey_question_option.sort as option_sort
  604. FROM $table_survey_question survey_question
  605. LEFT JOIN $table_survey_question_option survey_question_option
  606. ON survey_question.question_id = survey_question_option.question_id
  607. WHERE survey_question.survey_id = '".Database::escape_string($_GET['survey_id'])."'
  608. ORDER BY survey_question.sort ASC";
  609. $result = api_sql_query($sql, __FILE__, __LINE__);
  610. while ($row = mysql_fetch_assoc($result))
  611. {
  612. // we show the options if
  613. // 1. there is no question filter and the export button has not been clicked
  614. // 2. there is a quesiton filter but the question is selected for display
  615. if (!($_POST['submit_question_filter'] OR $_POST['export_report']) OR in_array($row['question_id'], $_POST['questions_filter']))
  616. {
  617. // we do not show comment and pagebreak question types
  618. if ($row['type'] <> 'comment' AND $row['type'] <> 'pagebreak')
  619. {
  620. echo ' <th>';
  621. echo $row['option_text'];
  622. echo '</th>';
  623. $possible_answers[$row['question_id']][$row['question_option_id']] =$row['question_option_id'];
  624. }
  625. }
  626. }
  627. echo ' </tr>';
  628. // getting all the answers of the users
  629. $old_user='';
  630. $answers_of_user = array();
  631. $sql = "SELECT * FROM $table_survey_answer WHERE survey_id='".Database::escape_string($_GET['survey_id'])."' ORDER BY user ASC";
  632. $result = api_sql_query($sql, __FILE__, __LINE__);
  633. while ($row = mysql_fetch_assoc($result))
  634. {
  635. if ($old_user <> $row['user'] AND $old_user<>'')
  636. {
  637. display_complete_report_row($possible_answers, $answers_of_user, $old_user);
  638. $answers_of_user=array();
  639. }
  640. $answers_of_user[$row['question_id']][$row['option_id']] = $row;
  641. $old_user = $row['user'];
  642. }
  643. display_complete_report_row($possible_answers, $answers_of_user, $old_user); // this is to display the last user
  644. echo '</table>';
  645. echo '</form>';
  646. }
  647. /**
  648. * This function displays a row (= a user and his/her answers) in the table of the complete report.
  649. *
  650. * @param array $possible_answers all the possible options
  651. * @param array $answers_of_user the answers of the user
  652. * @param string $user the user
  653. *
  654. * @todo rename $possible_answers to $possible_options ?
  655. *
  656. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  657. * @version February 2007
  658. */
  659. function display_complete_report_row($possible_answers, $answers_of_user, $user)
  660. {
  661. echo '<tr>';
  662. echo ' <th><a href="'.$_SERVER['PHP_SELF'].'?action=userreport&survey_id='.$_GET['survey_id'].'&user='.$user.'">'.$user.'</a></th>'; // the user column
  663. foreach ($possible_answers as $question_id=>$possible_option)
  664. {
  665. foreach ($possible_option as $option_id=>$value)
  666. {
  667. echo '<td align="center">';
  668. if (!empty($answers_of_user[$question_id][$option_id]))
  669. {
  670. if ($answers_of_user[$question_id][$option_id]['value']<>0)
  671. {
  672. echo $answers_of_user[$question_id][$option_id]['value'];
  673. }
  674. else
  675. {
  676. echo 'v';
  677. }
  678. }
  679. echo '</td>';
  680. }
  681. }
  682. echo '</tr>';
  683. }
  684. /**
  685. * the function is quite similar to display_complete_report and return a html string that can be used in a csv file
  686. *
  687. * @todo consider merging this function with display_complete_report
  688. *
  689. * @return string $return the content of a csv file
  690. *
  691. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  692. * @version February 2007
  693. */
  694. function export_complete_report()
  695. {
  696. // Database table definitions
  697. $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  698. $table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
  699. $table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER);
  700. // the first column
  701. $return = ';';
  702. $sql = "SELECT questions.question_id, questions.type, questions.survey_question, count(options.question_option_id) as number_of_options
  703. FROM $table_survey_question questions LEFT JOIN $table_survey_question_option options
  704. ON questions.question_id = options.question_id
  705. /*WHERE questions.question_id = options.question_id*/
  706. AND questions.survey_id = '".Database::escape_string($_GET['survey_id'])."'
  707. GROUP BY questions.question_id";
  708. $result = api_sql_query($sql, __FILE__, __LINE__);
  709. while ($row = mysql_fetch_assoc($result))
  710. {
  711. // we show the questions if
  712. // 1. there is no question filter and the export button has not been clicked
  713. // 2. there is a quesiton filter but the question is selected for display
  714. if (!($_POST['submit_question_filter'] OR $_POST['export_report']) OR in_array($row['question_id'], $_POST['questions_filter']))
  715. {
  716. // we do not show comment and pagebreak question types
  717. if ($row['type'] <> 'comment' AND $row['type'] <> 'pagebreak')
  718. {
  719. for ($ii = 0; $ii < $row['number_of_options']; $ii ++)
  720. {
  721. $return .= strip_tags($row['survey_question']).';';
  722. }
  723. }
  724. }
  725. }
  726. $return .= "\n";
  727. // getting all the questions and options
  728. $return .= ';';
  729. $sql = "SELECT survey_question.question_id, survey_question.survey_id, survey_question.survey_question, survey_question.display, survey_question.sort, survey_question.type,
  730. survey_question_option.question_option_id, survey_question_option.option_text, survey_question_option.sort as option_sort
  731. FROM $table_survey_question survey_question
  732. LEFT JOIN $table_survey_question_option survey_question_option
  733. ON survey_question.question_id = survey_question_option.question_id
  734. WHERE survey_question.survey_id = '".Database::escape_string($_GET['survey_id'])."'
  735. ORDER BY survey_question.sort ASC";
  736. $result = api_sql_query($sql, __FILE__, __LINE__);
  737. while ($row = mysql_fetch_assoc($result))
  738. {
  739. // we show the options if
  740. // 1. there is no question filter and the export button has not been clicked
  741. // 2. there is a quesiton filter but the question is selected for display
  742. if (!($_POST['submit_question_filter'] OR $_POST['export_report']) OR in_array($row['question_id'], $_POST['questions_filter']))
  743. {
  744. // we do not show comment and pagebreak question types
  745. if ($row['type'] <> 'comment' AND $row['type'] <> 'pagebreak')
  746. {
  747. $return .= $row['option_text'].';';
  748. $possible_answers[$row['question_id']][$row['question_option_id']] =$row['question_option_id'];
  749. }
  750. }
  751. }
  752. $return .= "\n";
  753. // getting all the answers of the users
  754. $old_user='';
  755. $answers_of_user = array();
  756. $sql = "SELECT * FROM $table_survey_answer WHERE survey_id='".Database::escape_string($_GET['survey_id'])."' ORDER BY user ASC";
  757. $result = api_sql_query($sql, __FILE__, __LINE__);
  758. while ($row = mysql_fetch_assoc($result))
  759. {
  760. if ($old_user <> $row['user'] AND $old_user<>'')
  761. {
  762. $return .= export_complete_report_row($possible_answers, $answers_of_user, $old_user);
  763. $answers_of_user=array();
  764. }
  765. $answers_of_user[$row['question_id']][$row['option_id']] = $row;
  766. $old_user = $row['user'];
  767. }
  768. $return .= export_complete_report_row($possible_answers, $answers_of_user, $old_user); // this is to display the last user
  769. return $return;
  770. }
  771. /**
  772. * add a line to the csv file
  773. *
  774. * @param array $possible_answers all the possible answers
  775. * @param array $answers_of_user the answers of the user
  776. * @param string $user the user
  777. *
  778. * @return string $return line of the csv file
  779. *
  780. * @todo rename $possible_answers to $possible_options ?
  781. *
  782. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  783. * @version February 2007
  784. */
  785. function export_complete_report_row($possible_answers, $answers_of_user, $user)
  786. {
  787. $return = $user.';'; // the user column
  788. foreach ($possible_answers as $question_id=>$possible_option)
  789. {
  790. foreach ($possible_option as $option_id=>$value)
  791. {
  792. if (!empty($answers_of_user[$question_id][$option_id]))
  793. {
  794. $return .= 'v';
  795. }
  796. $return .= ';';
  797. }
  798. }
  799. $return .= "\n";
  800. return $return;
  801. }
  802. /**
  803. * This function displays the comparative report which allows you to compare two questions
  804. * A comparative report creates a table where one question is on the x axis and a second question is on the y axis.
  805. * In the intersection is the number of people who have answerd positive on both options.
  806. *
  807. * @return html code
  808. *
  809. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  810. * @version February 2007
  811. */
  812. function display_comparative_report()
  813. {
  814. // allowed question types for comparative report
  815. $allowed_question_types = array('yesno', 'multiplechoice', 'multipleresponse', 'dropdown', 'percentage', 'score');
  816. // getting all the questions
  817. $questions = survey_manager::get_questions($_GET['survey_id']);
  818. // displaying an information message that only the questions with predefined answers can be used in a comparative report
  819. Display::display_normal_message(get_lang('OnlyQuestionsWithPredefinedAnswers'), false);
  820. // The form for selecting the axis of the table
  821. echo '<form id="form1" name="form1" method="get" action="'.$_SERVER['PHP_SELF'].'?action='.$_GET['action'].'&survey_id='.$_GET['survey_id'].'&xaxis='.$_GET['xaxis'].'&y='.$_GET['yaxis'].'">';
  822. // survey_id
  823. echo '<input type="hidden" name="action" value="'.$_GET['action'].'"/>';
  824. echo '<input type="hidden" name="survey_id" value="'.(int)$_GET['survey_id'].'"/>';
  825. // X axis
  826. echo get_lang('SelectXAxis').': ';
  827. echo '<select name="xaxis">';
  828. echo '<option value="">---</option>';
  829. foreach ($questions as $key=>$question)
  830. {
  831. if (in_array($question['type'], $allowed_question_types))
  832. {
  833. echo '<option value="'.$question['question_id'].'"';
  834. if ($_GET['xaxis'] == $question['question_id'])
  835. {
  836. echo ' selected="selected"';
  837. }
  838. echo '">'.substr(strip_tags($question['question']), 0, 50).'</option>';
  839. }
  840. }
  841. echo '</select><br /><br />';
  842. // Y axis
  843. echo get_lang('SelectYAxis').': ';
  844. echo '<select name="yaxis">';
  845. echo '<option value="">---</option>';
  846. foreach ($questions as $key=>$question)
  847. {
  848. if (in_array($question['type'], $allowed_question_types))
  849. {
  850. echo '<option value="'.$question['question_id'].'"';
  851. if ($_GET['yaxis'] == $question['question_id'])
  852. {
  853. echo ' selected="selected"';
  854. }
  855. echo '">'.substr(strip_tags($question['question']), 0, 50).'</option>';
  856. }
  857. }
  858. echo '</select><br /><br />';
  859. echo '<input type="submit" name="Submit" value="Submit" />';
  860. echo '</form>';
  861. // getting all the information of the x axis
  862. if (isset($_GET['xaxis']) AND is_numeric($_GET['xaxis']))
  863. {
  864. $question_x = survey_manager::get_question($_GET['xaxis']);
  865. }
  866. // getting all the information of the y axis
  867. if (isset($_GET['yaxis']) AND is_numeric($_GET['yaxis']))
  868. {
  869. $question_y = survey_manager::get_question($_GET['yaxis']);
  870. }
  871. if (isset($_GET['xaxis']) AND is_numeric($_GET['xaxis']) AND isset($_GET['yaxis']) AND is_numeric($_GET['yaxis']))
  872. {
  873. // getting the answers of the two questions
  874. $answers_x = get_answers_of_question_by_user($_GET['survey_id'], $_GET['xaxis']);
  875. $answers_y = get_answers_of_question_by_user($_GET['survey_id'], $_GET['yaxis']);
  876. // displaying the table
  877. echo '<table border="1" class="data_table">';
  878. // the header
  879. echo ' <tr>';
  880. for ($ii=0; $ii<=count($question_x['answers']); $ii++)
  881. {
  882. if ($ii == 0)
  883. {
  884. echo ' <th>&nbsp;</th>';
  885. }
  886. else
  887. {
  888. if ($question_x['type']=='score')
  889. {
  890. for($x=1; $x<=$question_x['maximum_score']; $x++)
  891. {
  892. echo ' <th>'.$question_x['answers'][($ii-1)].'<br />'.$x.'</th>';
  893. }
  894. $x='';
  895. }
  896. else
  897. {
  898. echo ' <th>'.$question_x['answers'][($ii-1)].'</th>';
  899. }
  900. }
  901. }
  902. echo ' </tr>';
  903. // the main part
  904. for ($ij=0; $ij<count($question_y['answers']); $ij++)
  905. {
  906. // The Y axis is a scoring question type so we have more rows than the options (actually options * maximum score)
  907. if ($question_y['type'] == 'score')
  908. {
  909. for($y=1; $y<=$question_y['maximum_score']; $y++)
  910. {
  911. echo ' <tr>';
  912. for ($ii=0; $ii<=count($question_x['answers']); $ii++)
  913. {
  914. if ($question_x['type']=='score')
  915. {
  916. for($x=1; $x<=$question_x['maximum_score']; $x++)
  917. {
  918. if ($ii == 0)
  919. {
  920. echo ' <th>'.$question_y['answers'][($ij)].' '.$y.'</th>';
  921. break;
  922. }
  923. else
  924. {
  925. echo ' <td align="center">';
  926. echo comparative_check($answers_x, $answers_y, $question_x['answersid'][($ii-1)], $question_y['answersid'][($ij)], $x, $y);
  927. echo '</td>';
  928. }
  929. }
  930. }
  931. else
  932. {
  933. if ($ii == 0)
  934. {
  935. echo ' <th>'.$question_y['answers'][($ij)].' '.$y.'</th>';
  936. }
  937. else
  938. {
  939. echo ' <td align="center">';
  940. echo comparative_check($answers_x, $answers_y, $question_x['answersid'][($ii-1)], $question_y['answersid'][($ij)], 0, $y);
  941. echo '</td>';
  942. }
  943. }
  944. }
  945. echo ' </tr>';
  946. }
  947. }
  948. // The Y axis is NOT a score question type so the number of rows = the number of options
  949. else
  950. {
  951. echo ' <tr>';
  952. for ($ii=0; $ii<=count($question_x['answers']); $ii++)
  953. {
  954. if ($question_x['type']=='score')
  955. {
  956. for($x=1; $x<=$question_x['maximum_score']; $x++)
  957. {
  958. if ($ii == 0)
  959. {
  960. echo ' <th>'.$question_y['answers'][($ij)].'</th>';
  961. break;
  962. }
  963. else
  964. {
  965. echo ' <td align="center">';
  966. echo comparative_check($answers_x, $answers_y, $question_x['answersid'][($ii-1)], $question_y['answersid'][($ij)], $x, 0);
  967. echo '</td>';
  968. }
  969. }
  970. }
  971. else
  972. {
  973. if ($ii == 0)
  974. {
  975. echo ' <th>'.$question_y['answers'][($ij)].'</th>';
  976. }
  977. else
  978. {
  979. echo ' <td align="center">';
  980. echo comparative_check($answers_x, $answers_y, $question_x['answersid'][($ii-1)], $question_y['answersid'][($ij)]);
  981. echo '</td>';
  982. }
  983. }
  984. }
  985. echo ' </tr>';
  986. }
  987. }
  988. echo '</table>';
  989. }
  990. }
  991. /**
  992. * get all the answers of a question grouped by user
  993. *
  994. * @param integer $survey_id the id of the survey
  995. * @param integer $question_id the id of the question
  996. * @return array $return an array countaining all the answers of all the users grouped by user
  997. *
  998. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  999. * @version February 2007
  1000. */
  1001. function get_answers_of_question_by_user($survey_id, $question_id)
  1002. {
  1003. // Database table definitions
  1004. $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  1005. $table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
  1006. $table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER);
  1007. $sql = "SELECT * FROM $table_survey_answer
  1008. WHERE survey_id='".Database::escape_string($survey_id)."'
  1009. AND question_id='".Database::escape_string($question_id)."'
  1010. ORDER BY USER ASC";
  1011. $result = api_sql_query($sql, __FILE__, __LINE__);
  1012. while ($row = mysql_fetch_assoc($result))
  1013. {
  1014. if ($row['value'] == 0)
  1015. {
  1016. $return[$row['user']][] = $row['option_id'];
  1017. }
  1018. else
  1019. {
  1020. $return[$row['user']][] = $row['option_id'].'*'.$row['value'];
  1021. }
  1022. }
  1023. return $return;
  1024. }
  1025. /**
  1026. * count the number of users who answer positively on both options
  1027. *
  1028. * @param array $answers_x all the answers of the x axis
  1029. * @param array $answers_y all the answers of the y axis
  1030. * @param integer $option_x the x axis value (= the option_id of the first question)
  1031. * @param integer $option_y the y axis value (= the option_id of the second question)
  1032. * @return integer the number of users who have answered positively on both options
  1033. *
  1034. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1035. * @version February 2007
  1036. */
  1037. function comparative_check($answers_x, $answers_y, $option_x, $option_y, $value_x=0, $value_y=0)
  1038. {
  1039. if ($value_x==0)
  1040. {
  1041. $check_x = $option_x;
  1042. }
  1043. else
  1044. {
  1045. $check_x = $option_x.'*'.$value_x;
  1046. }
  1047. if ($value_y==0)
  1048. {
  1049. $check_y = $option_y;
  1050. }
  1051. else
  1052. {
  1053. $check_y = $option_y.'*'.$value_y;
  1054. }
  1055. $counter = 0;
  1056. foreach ($answers_x as $user => $answers)
  1057. {
  1058. // check if the user has given $option_x as answer
  1059. if (in_array($check_x, $answers))
  1060. {
  1061. // check if the user has given $option_y as an answer
  1062. if (in_array($check_y, $answers_y[$user]))
  1063. {
  1064. $counter++;
  1065. }
  1066. }
  1067. }
  1068. return $counter;
  1069. }
  1070. ?>