reporting.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 15091 2008-04-25 05:18:30Z 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. $survey_data = survey_manager::get_survey($_GET['survey_id']);
  38. $filename = 'survey_results_'.$_GET['survey_id'].'.xls';
  39. $data = SurveyUtil::export_complete_report_xls($filename);
  40. exit;
  41. break;
  42. case 'csv':
  43. default:
  44. $survey_data = survey_manager::get_survey($_GET['survey_id']);
  45. $data = SurveyUtil::export_complete_report();
  46. //$filename = 'fileexport.csv';
  47. $filename = 'survey_results_'.$_GET['survey_id'].'.csv';
  48. header('Content-type: application/octet-stream');
  49. header('Content-Type: application/force-download');
  50. header('Content-length: '.$len);
  51. if (preg_match("/MSIE 5.5/", $_SERVER['HTTP_USER_AGENT']))
  52. {
  53. header('Content-Disposition: filename= '.$filename);
  54. }
  55. else
  56. {
  57. header('Content-Disposition: attachment; filename= '.$filename);
  58. }
  59. if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE'))
  60. {
  61. header('Pragma: ');
  62. header('Cache-Control: ');
  63. header('Cache-Control: public'); // IE cannot download from sessions without a cache
  64. }
  65. header('Content-Description: '.$filename);
  66. header('Content-transfer-encoding: binary');
  67. echo $data;
  68. exit;
  69. break;
  70. }
  71. }
  72. // including additional libraries
  73. //require_once (api_get_path(LIBRARY_PATH)."/survey.lib.php");
  74. require_once (api_get_path(LIBRARY_PATH)."/course.lib.php");
  75. // Checking the parameters
  76. SurveyUtil::check_parameters();
  77. /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
  78. if (!api_is_allowed_to_edit())
  79. {
  80. Display :: display_header(get_lang('Survey'));
  81. Display :: display_error_message(get_lang('NotAllowed'), false);
  82. Display :: display_footer();
  83. exit;
  84. }
  85. // Database table definitions
  86. $table_survey = Database :: get_course_table(TABLE_SURVEY);
  87. $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  88. $table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
  89. $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  90. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  91. $user_info = Database :: get_main_table(TABLE_MAIN_SURVEY_REMINDER);
  92. // getting the survey information
  93. $survey_data = survey_manager::get_survey($_GET['survey_id']);
  94. $urlname = substr(strip_tags($survey_data['title']), 0, 40);
  95. if (strlen(strip_tags($survey_data['title'])) > 40)
  96. {
  97. $urlname .= '...';
  98. }
  99. // breadcrumbs
  100. $interbreadcrumb[] = array ("url" => "survey_list.php", "name" => get_lang('SurveyList'));
  101. $interbreadcrumb[] = array ('url' => 'survey.php?survey_id='.$_GET['survey_id'], 'name' => $urlname);
  102. if (!$_GET['action'] OR $_GET['action'] == 'overview')
  103. {
  104. $tool_name = get_lang('Reporting');
  105. }
  106. else
  107. {
  108. $interbreadcrumb[] = array ("url" => "reporting.php?survey_id=".$_GET['survey_id'], "name" => get_lang('Reporting'));
  109. switch ($_GET['action'])
  110. {
  111. case 'questionreport':
  112. $tool_name = get_lang('DetailedReportByQuestion');
  113. break;
  114. case 'userreport':
  115. $tool_name = get_lang('DetailedReportByUser');
  116. break;
  117. case 'comparativereport':
  118. $tool_name = get_lang('ComparativeReport');
  119. break;
  120. case 'completereport':
  121. $tool_name = get_lang('CompleteReport');
  122. break;
  123. }
  124. }
  125. // Displaying the header
  126. Display::display_header($tool_name);
  127. // Action handling
  128. SurveyUtil::handle_reporting_actions();
  129. if (!$_GET['action'] OR $_GET['action'] == 'overview')
  130. {
  131. $myweb_survey_id = Security::remove_XSS($_GET['survey_id']);
  132. 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 />';
  133. 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 />';
  134. 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 />';
  135. 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 />';
  136. }
  137. // Footer
  138. Display :: display_footer();