reporting.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php // $Id: reporting.php 21652 2009-06-27 17:07:35Z herodoto $
  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 21652 2009-06-27 17:07:35Z herodoto $
  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. $this_section=SECTION_COURSES;
  31. $survey_id = Security::remove_XSS($_GET['survey_id']);
  32. // export
  33. /**
  34. * @todo use export_table_csv($data, $filename = 'export')
  35. */
  36. if ($_POST['export_report'])
  37. {
  38. switch($_POST['export_format'])
  39. {
  40. case 'xls':
  41. $survey_data = survey_manager::get_survey($survey_id);
  42. $filename = 'survey_results_'.$survey_id.'.xls';
  43. $data = SurveyUtil::export_complete_report_xls($filename, $_GET['user_id']);
  44. exit;
  45. break;
  46. case 'csv':
  47. default:
  48. $survey_data = survey_manager::get_survey($survey_id);
  49. $data = SurveyUtil::export_complete_report($_GET['user_id']);
  50. //$filename = 'fileexport.csv';
  51. $filename = 'survey_results_'.$survey_id.'.csv';
  52. header('Content-type: application/octet-stream');
  53. header('Content-Type: application/force-download');
  54. if (preg_match("/MSIE 5.5/", $_SERVER['HTTP_USER_AGENT']))
  55. {
  56. header('Content-Disposition: filename= '.$filename);
  57. }
  58. else
  59. {
  60. header('Content-Disposition: attachment; filename= '.$filename);
  61. }
  62. if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE'))
  63. {
  64. header('Pragma: ');
  65. header('Cache-Control: ');
  66. header('Cache-Control: public'); // IE cannot download from sessions without a cache
  67. }
  68. header('Content-Description: '.$filename);
  69. header('Content-transfer-encoding: binary');
  70. echo $data;
  71. exit;
  72. break;
  73. }
  74. }
  75. // including additional libraries
  76. //require_once (api_get_path(LIBRARY_PATH)."/survey.lib.php");
  77. require_once (api_get_path(LIBRARY_PATH)."/course.lib.php");
  78. // Checking the parameters
  79. SurveyUtil::check_parameters();
  80. /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
  81. if (!api_is_allowed_to_edit(false,true))
  82. {
  83. Display :: display_header(get_lang('Survey'));
  84. Display :: display_error_message(get_lang('NotAllowed'), false);
  85. Display :: display_footer();
  86. exit;
  87. }
  88. // Database table definitions
  89. $table_survey = Database :: get_course_table(TABLE_SURVEY);
  90. $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  91. $table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
  92. $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  93. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  94. $user_info = Database :: get_main_table(TABLE_MAIN_SURVEY_REMINDER); // TODO: To be checked. TABLE_MAIN_SURVEY_REMINDER has not been defined.
  95. // getting the survey information
  96. $survey_data = survey_manager::get_survey($survey_id);
  97. if (empty($survey_data)) {
  98. Display :: display_header(get_lang('Survey'));
  99. Display :: display_error_message(get_lang('InvallidSurvey'), false);
  100. Display :: display_footer();
  101. exit;
  102. }
  103. $urlname = strip_tags(api_substr(api_html_entity_decode($survey_data['title'],ENT_QUOTES,$charset), 0, 40));
  104. if (api_strlen(strip_tags($survey_data['title'])) > 40)
  105. {
  106. $urlname .= '...';
  107. }
  108. // breadcrumbs
  109. $interbreadcrumb[] = array ("url" => "survey_list.php", "name" => get_lang('SurveyList'));
  110. $interbreadcrumb[] = array ('url' => 'survey.php?survey_id='.$survey_id, 'name' => $urlname);
  111. if (!$_GET['action'] OR $_GET['action'] == 'overview')
  112. {
  113. $tool_name = get_lang('Reporting');
  114. }
  115. else
  116. {
  117. $interbreadcrumb[] = array ("url" => "reporting.php?survey_id=".$survey_id, "name" => get_lang('Reporting'));
  118. switch ($_GET['action'])
  119. {
  120. case 'questionreport':
  121. $tool_name = get_lang('DetailedReportByQuestion');
  122. break;
  123. case 'userreport':
  124. $tool_name = get_lang('DetailedReportByUser');
  125. break;
  126. case 'comparativereport':
  127. $tool_name = get_lang('ComparativeReport');
  128. break;
  129. case 'completereport':
  130. $tool_name = get_lang('CompleteReport');
  131. break;
  132. }
  133. }
  134. // Displaying the header
  135. Display::display_header($tool_name,'Survey');
  136. // Action handling
  137. SurveyUtil::handle_reporting_actions();
  138. // actions bar
  139. echo '<div class="actions">';
  140. echo '<a href="survey.php?survey_id='.Security::remove_XSS($_GET['survey_id']).'">'.Display::return_icon('back.png',get_lang('BackTo').' '.strtolower(get_lang('Survey'))).' '.get_lang('BackTo').' '.strtolower(get_lang('Survey')).'</a>';
  141. echo '</div>';
  142. // content
  143. if (!$_GET['action'] OR $_GET['action'] == 'overview') {
  144. $myweb_survey_id = $survey_id;
  145. echo '<div class="sectiontitle"><a href="reporting.php?action=questionreport&amp;survey_id='.$myweb_survey_id.'">'.Display::return_icon('survey_reporting_question.gif',get_lang('DetailedReportByQuestion')).' '.get_lang('DetailedReportByQuestion').'</a></div><div class="sectioncomment">'.get_lang('DetailedReportByQuestionDetail').' </div>';
  146. echo '<div class="sectiontitle"><a href="reporting.php?action=userreport&amp;survey_id='.$myweb_survey_id.'">'.Display::return_icon('survey_reporting_user.gif',get_lang('DetailedReportByUser')).' '.get_lang('DetailedReportByUser').'</a></div><div class="sectioncomment">'.get_lang('DetailedReportByUserDetail').'.</div>';
  147. echo '<div class="sectiontitle"><a href="reporting.php?action=comparativereport&amp;survey_id='.$myweb_survey_id.'">'.Display::return_icon('survey_reporting_comparative.gif',get_lang('ComparativeReport')).' '.get_lang('ComparativeReport').'</a></div><div class="sectioncomment">'.get_lang('ComparativeReportDetail').'.</div>';
  148. echo '<div class="sectiontitle"><a href="reporting.php?action=completereport&amp;survey_id='.$myweb_survey_id.'">'.Display::return_icon('survey_reporting_complete.gif',get_lang('CompleteReport')).' '.get_lang('CompleteReport').'</a></div><div class="sectioncomment">'.get_lang('CompleteReportDetail').'</div>';
  149. }
  150. // Footer
  151. Display :: display_footer();