reporting.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php // $Id: reporting.php 19004 2009-03-12 18:04:08Z juliomontoya $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2008 Dokeos SPRL
  6. Copyright (c) 2003 Ghent University (UGent)
  7. For a full list of contributors, see "credits.txt".
  8. The full license can be read in "license.txt".
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13. See the GNU General Public License for more details.
  14. Contact: Dokeos, rue Notre Dame, 152, B-1140 Evere, Belgium, info@dokeos.com
  15. ==============================================================================
  16. */
  17. /**
  18. * @package dokeos.survey
  19. * @author unknown, the initial survey that did not make it in 1.8 because of bad code
  20. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of the code
  21. * @version $Id: reporting.php 19004 2009-03-12 18:04:08Z juliomontoya $
  22. *
  23. * @todo The question has to be more clearly indicated (same style as when filling the survey)
  24. */
  25. // name of the language file that needs to be included
  26. $language_file = 'survey';
  27. // including the global dokeos file
  28. require ('../inc/global.inc.php');
  29. require_once('survey.lib.php');
  30. $survey_id = Security::remove_XSS($_GET['survey_id']);
  31. // export
  32. /**
  33. * @todo use export_table_csv($data, $filename = 'export')
  34. */
  35. if ($_POST['export_report'])
  36. {
  37. switch($_POST['export_format'])
  38. {
  39. case 'xls':
  40. $survey_data = survey_manager::get_survey($survey_id);
  41. $filename = 'survey_results_'.$survey_id.'.xls';
  42. $data = SurveyUtil::export_complete_report_xls($filename, $_GET['user_id']);
  43. exit;
  44. break;
  45. case 'csv':
  46. default:
  47. $survey_data = survey_manager::get_survey($survey_id);
  48. $data = SurveyUtil::export_complete_report($_GET['user_id']);
  49. //$filename = 'fileexport.csv';
  50. $filename = 'survey_results_'.$survey_id.'.csv';
  51. header('Content-type: application/octet-stream');
  52. header('Content-Type: application/force-download');
  53. if (preg_match("/MSIE 5.5/", $_SERVER['HTTP_USER_AGENT']))
  54. {
  55. header('Content-Disposition: filename= '.$filename);
  56. }
  57. else
  58. {
  59. header('Content-Disposition: attachment; filename= '.$filename);
  60. }
  61. if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE'))
  62. {
  63. header('Pragma: ');
  64. header('Cache-Control: ');
  65. header('Cache-Control: public'); // IE cannot download from sessions without a cache
  66. }
  67. header('Content-Description: '.$filename);
  68. header('Content-transfer-encoding: binary');
  69. echo $data;
  70. exit;
  71. break;
  72. }
  73. }
  74. // including additional libraries
  75. //require_once (api_get_path(LIBRARY_PATH)."/survey.lib.php");
  76. require_once (api_get_path(LIBRARY_PATH)."/course.lib.php");
  77. // Checking the parameters
  78. SurveyUtil::check_parameters();
  79. /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
  80. if (!api_is_allowed_to_edit(false,true))
  81. {
  82. Display :: display_header(get_lang('Survey'));
  83. Display :: display_error_message(get_lang('NotAllowed'), false);
  84. Display :: display_footer();
  85. exit;
  86. }
  87. // Database table definitions
  88. $table_survey = Database :: get_course_table(TABLE_SURVEY);
  89. $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  90. $table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
  91. $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  92. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  93. $user_info = Database :: get_main_table(TABLE_MAIN_SURVEY_REMINDER);
  94. // getting the survey information
  95. $survey_data = survey_manager::get_survey($survey_id);
  96. if (empty($survey_data)) {
  97. Display :: display_header(get_lang('Survey'));
  98. Display :: display_error_message(get_lang('InvallidSurvey'), false);
  99. Display :: display_footer();
  100. exit;
  101. }
  102. $urlname = strip_tags(substr(html_entity_decode($survey_data['title'],ENT_QUOTES,$charset), 0, 40));
  103. if (strlen(strip_tags($survey_data['title'])) > 40)
  104. {
  105. $urlname .= '...';
  106. }
  107. // breadcrumbs
  108. $interbreadcrumb[] = array ("url" => "survey_list.php", "name" => get_lang('SurveyList'));
  109. $interbreadcrumb[] = array ('url' => 'survey.php?survey_id='.$survey_id, 'name' => $urlname);
  110. if (!$_GET['action'] OR $_GET['action'] == 'overview')
  111. {
  112. $tool_name = get_lang('Reporting');
  113. }
  114. else
  115. {
  116. $interbreadcrumb[] = array ("url" => "reporting.php?survey_id=".$survey_id, "name" => get_lang('Reporting'));
  117. switch ($_GET['action'])
  118. {
  119. case 'questionreport':
  120. $tool_name = get_lang('DetailedReportByQuestion');
  121. break;
  122. case 'userreport':
  123. $tool_name = get_lang('DetailedReportByUser');
  124. break;
  125. case 'comparativereport':
  126. $tool_name = get_lang('ComparativeReport');
  127. break;
  128. case 'completereport':
  129. $tool_name = get_lang('CompleteReport');
  130. break;
  131. }
  132. }
  133. // Displaying the header
  134. Display::display_header($tool_name,'Survey');
  135. // Action handling
  136. SurveyUtil::handle_reporting_actions();
  137. if (!$_GET['action'] OR $_GET['action'] == 'overview') {
  138. $myweb_survey_id = $survey_id;
  139. echo '<div class="sectiontitle"><a href="reporting.php?action=questionreport&amp;survey_id='.$myweb_survey_id.'">'.get_lang('DetailedReportByQuestion').'</a></div><div class="sectioncomment">'.get_lang('DetailedReportByQuestionDetail').' </div>';
  140. echo '<div class="sectiontitle"><a href="reporting.php?action=userreport&amp;survey_id='.$myweb_survey_id.'">'.get_lang('DetailedReportByUser').'</a></div><div class="sectioncomment">'.get_lang('DetailedReportByUserDetail').'.</div>';
  141. echo '<div class="sectiontitle"><a href="reporting.php?action=comparativereport&amp;survey_id='.$myweb_survey_id.'">'.get_lang('ComparativeReport').'</a></div><div class="sectioncomment">'.get_lang('ComparativeReportDetail').'.</div>';
  142. echo '<div class="sectiontitle"><a href="reporting.php?action=completereport&amp;survey_id='.$myweb_survey_id.'">'.get_lang('CompleteReport').'</a></div><div class="sectioncomment">'.get_lang('CompleteReportDetail').'</div>';
  143. }
  144. // Footer
  145. Display :: display_footer();