reporting.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 du Corbeau, 108
  13. B-1030 Brussels - Belgium
  14. */
  15. /**
  16. * @package dokeos.survey
  17. * @author unknown, the initial survey that did not make it in 1.8 because of bad code
  18. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of the code
  19. * @version $Id: reporting.php 14639 2008-03-18 05:31:08Z yannoo $
  20. *
  21. * @todo The question has to be more clearly indicated (same style as when filling the survey)
  22. */
  23. // name of the language file that needs to be included
  24. $language_file = 'survey';
  25. // including the global dokeos file
  26. require ('../inc/global.inc.php');
  27. require_once('survey.lib.php');
  28. // export
  29. /**
  30. * @todo use export_table_csv($data, $filename = 'export')
  31. */
  32. if ($_POST['export_report'])
  33. {
  34. switch($_POST['export_format'])
  35. {
  36. case 'xls':
  37. $filename = 'survey_results_'.$_GET['survey_id'].'.xls';
  38. $data = SurveyUtil::export_complete_report_xls($filename);
  39. exit;
  40. break;
  41. case 'csv':
  42. default:
  43. $data = SurveyUtil::export_complete_report();
  44. //$filename = 'fileexport.csv';
  45. $filename = 'survey_results_'.$_GET['survey_id'].'.csv';
  46. header('Content-type: application/octet-stream');
  47. header('Content-Type: application/force-download');
  48. header('Content-length: '.$len);
  49. if (preg_match("/MSIE 5.5/", $_SERVER['HTTP_USER_AGENT']))
  50. {
  51. header('Content-Disposition: filename= '.$filename);
  52. }
  53. else
  54. {
  55. header('Content-Disposition: attachment; filename= '.$filename);
  56. }
  57. if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE'))
  58. {
  59. header('Pragma: ');
  60. header('Cache-Control: ');
  61. header('Cache-Control: public'); // IE cannot download from sessions without a cache
  62. }
  63. header('Content-Description: '.$filename);
  64. header('Content-transfer-encoding: binary');
  65. echo $data;
  66. exit;
  67. break;
  68. }
  69. }
  70. // including additional libraries
  71. //require_once (api_get_path(LIBRARY_PATH)."/survey.lib.php");
  72. require_once (api_get_path(LIBRARY_PATH)."/course.lib.php");
  73. // Checking the parameters
  74. SurveyUtil::check_parameters();
  75. /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
  76. if (!api_is_allowed_to_edit())
  77. {
  78. Display :: display_header(get_lang('Survey'));
  79. Display :: display_error_message(get_lang('NotAllowed'), false);
  80. Display :: display_footer();
  81. exit;
  82. }
  83. // Database table definitions
  84. $table_survey = Database :: get_course_table(TABLE_SURVEY);
  85. $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  86. $table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
  87. $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  88. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  89. $user_info = Database :: get_main_table(TABLE_MAIN_SURVEY_REMINDER);
  90. // getting the survey information
  91. $survey_data = survey_manager::get_survey($_GET['survey_id']);
  92. $urlname = substr(strip_tags($survey_data['title']), 0, 40);
  93. if (strlen(strip_tags($survey_data['title'])) > 40)
  94. {
  95. $urlname .= '...';
  96. }
  97. // breadcrumbs
  98. $interbreadcrumb[] = array ("url" => "survey_list.php", "name" => get_lang('SurveyList'));
  99. $interbreadcrumb[] = array ('url' => 'survey.php?survey_id='.$_GET['survey_id'], 'name' => $urlname);
  100. if (!$_GET['action'] OR $_GET['action'] == 'overview')
  101. {
  102. $tool_name = get_lang('Reporting');
  103. }
  104. else
  105. {
  106. $interbreadcrumb[] = array ("url" => "reporting.php?survey_id=".$_GET['survey_id'], "name" => get_lang('Reporting'));
  107. switch ($_GET['action'])
  108. {
  109. case 'questionreport':
  110. $tool_name = get_lang('DetailedReportByQuestion');
  111. break;
  112. case 'userreport':
  113. $tool_name = get_lang('DetailedReportByUser');
  114. break;
  115. case 'comparativereport':
  116. $tool_name = get_lang('ComparativeReport');
  117. break;
  118. case 'completereport':
  119. $tool_name = get_lang('CompleteReport');
  120. break;
  121. }
  122. }
  123. // Displaying the header
  124. Display::display_header($tool_name);
  125. // Action handling
  126. SurveyUtil::handle_reporting_actions();
  127. if (!$_GET['action'] OR $_GET['action'] == 'overview')
  128. {
  129. $myweb_survey_id = Security::remove_XSS($_GET['survey_id']);
  130. echo '<b><a href="reporting.php?action=questionreport&amp;survey_id='.$myweb_survey_id.'">'.get_lang('DetailedReportByQuestion').'</a></b> <br />'.get_lang('DetailedReportByQuestionDetail').' <br /><br />';
  131. echo '<b><a href="reporting.php?action=userreport&amp;survey_id='.$myweb_survey_id.'">'.get_lang('DetailedReportByUser').'</a></b><br />'.get_lang('DetailedReportByUserDetail').'.<br /><br />';
  132. echo '<b><a href="reporting.php?action=comparativereport&amp;survey_id='.$myweb_survey_id.'">'.get_lang('ComparativeReport').'</a></b><br />'.get_lang('ComparativeReportDetail').'.<br /><br />';
  133. echo '<b><a href="reporting.php?action=completereport&amp;survey_id='.$myweb_survey_id.'">'.get_lang('CompleteReport').'</a></b><br />'.get_lang('CompleteReportDetail').'<br /><br />';
  134. }
  135. // Footer
  136. Display :: display_footer();