reporting.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.survey
  5. * @author unknown, the initial survey that did not make it in 1.8 because of bad code
  6. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of the code
  7. * @version $Id: reporting.php 21652 2009-06-27 17:07:35Z herodoto $
  8. *
  9. * @todo The question has to be more clearly indicated (same style as when filling the survey)
  10. */
  11. // Language file that needs to be included
  12. $language_file = 'survey';
  13. // Including the global initialization file
  14. require_once '../inc/global.inc.php';
  15. require_once 'survey.lib.php';
  16. $this_section = SECTION_COURSES;
  17. $survey_id = intval($_GET['survey_id']);
  18. $survey_data = survey_manager::get_survey($survey_id);
  19. // Export
  20. /**
  21. * @todo use export_table_csv($data, $filename = 'export')
  22. */
  23. if (isset($_POST['export_report']) && $_POST['export_report']) {
  24. switch ($_POST['export_format']) {
  25. case 'xls':
  26. $filename = 'survey_results_'.$survey_id.'.xls';
  27. $data = SurveyUtil::export_complete_report_xls(
  28. $survey_data,
  29. $filename,
  30. $_GET['user_id']
  31. );
  32. exit;
  33. break;
  34. case 'csv':
  35. default:
  36. $data = SurveyUtil::export_complete_report(
  37. $survey_data,
  38. $_GET['user_id']
  39. );
  40. $filename = 'survey_results_'.$survey_id.'.csv';
  41. header('Content-type: application/octet-stream');
  42. header('Content-Type: application/force-download');
  43. if (preg_match("/MSIE 5.5/", $_SERVER['HTTP_USER_AGENT'])) {
  44. header('Content-Disposition: filename= '.$filename);
  45. } else {
  46. header('Content-Disposition: attachment; filename= '.$filename);
  47. }
  48. if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
  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. break;
  58. }
  59. }
  60. if ($survey_data['anonymous'] == 0) {
  61. $people_filled_full_data = true;
  62. } else {
  63. $people_filled_full_data = false;
  64. }
  65. $people_filled = survey_manager::get_people_who_filled_survey(
  66. $_GET['survey_id'],
  67. $people_filled_full_data
  68. );
  69. // Checking the parameters
  70. SurveyUtil::check_parameters($people_filled);
  71. $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
  72. api_get_user_id(),
  73. api_get_course_info()
  74. );
  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(false, true) || $isDrhOfCourse)) {
  77. Display :: display_header(get_lang('ToolSurvey'));
  78. Display :: display_error_message(get_lang('NotAllowed'), false);
  79. Display :: display_footer();
  80. exit;
  81. }
  82. // Database table definitions
  83. $table_course = Database:: get_main_table(TABLE_MAIN_COURSE);
  84. $table_user = Database:: get_main_table(TABLE_MAIN_USER);
  85. // Getting the survey information
  86. $survey_data = survey_manager::get_survey($survey_id);
  87. if (empty($survey_data)) {
  88. Display :: display_header(get_lang('ToolSurvey'));
  89. Display :: display_error_message(get_lang('InvallidSurvey'), false);
  90. Display :: display_footer();
  91. exit;
  92. }
  93. $urlname = strip_tags(api_substr(api_html_entity_decode($survey_data['title'], ENT_QUOTES), 0, 40));
  94. if (api_strlen(strip_tags($survey_data['title'])) > 40) {
  95. $urlname .= '...';
  96. }
  97. // Breadcrumbs
  98. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php', 'name' => get_lang('SurveyList'));
  99. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id, 'name' => $urlname);
  100. if (!isset($_GET['action']) || isset($_GET['action']) && $_GET['action'] == 'overview') {
  101. $tool_name = get_lang('Reporting');
  102. } else {
  103. $interbreadcrumb[] = array(
  104. 'url' => api_get_path(WEB_CODE_PATH).'survey/reporting.php?survey_id='.$survey_id,
  105. 'name' => get_lang('Reporting')
  106. );
  107. switch ($_GET['action']) {
  108. case 'questionreport':
  109. $tool_name = get_lang('DetailedReportByQuestion');
  110. break;
  111. case 'userreport':
  112. $tool_name = get_lang('DetailedReportByUser');
  113. break;
  114. case 'comparativereport':
  115. $tool_name = get_lang('ComparativeReport');
  116. break;
  117. case 'completereport':
  118. $tool_name = get_lang('CompleteReport');
  119. break;
  120. }
  121. }
  122. // Displaying the header
  123. Display::display_header($tool_name, 'Survey');
  124. // Action handling
  125. SurveyUtil::handle_reporting_actions($survey_data, $people_filled);
  126. // Actions bar
  127. echo '<div class="actions">';
  128. echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'">'.
  129. Display::return_icon('back.png', get_lang('BackToSurvey'),'',ICON_SIZE_MEDIUM).'</a>';
  130. echo '</div>';
  131. // Content
  132. if (!isset($_GET['action']) ||
  133. isset($_GET['action']) &&
  134. $_GET['action'] == 'overview'
  135. ) {
  136. $myweb_survey_id = $survey_id;
  137. echo '<div class="sectiontitle"><a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action=questionreport&amp;survey_id='.$myweb_survey_id.'&'.api_get_cidreq().'">'.
  138. Display::return_icon('survey_reporting_question.gif',get_lang('DetailedReportByQuestion')).' '.get_lang('DetailedReportByQuestion').'</a></div><div class="sectioncomment">'.get_lang('DetailedReportByQuestionDetail').' </div>';
  139. echo '<div class="sectiontitle"><a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action=userreport&amp;survey_id='.$myweb_survey_id.'&'.api_get_cidreq().'">'.
  140. Display::return_icon('survey_reporting_user.gif',get_lang('DetailedReportByUser')).' '.get_lang('DetailedReportByUser').'</a></div><div class="sectioncomment">'.get_lang('DetailedReportByUserDetail').'.</div>';
  141. echo '<div class="sectiontitle"><a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action=comparativereport&amp;survey_id='.$myweb_survey_id.'&'.api_get_cidreq().'">'.
  142. Display::return_icon('survey_reporting_comparative.gif',get_lang('ComparativeReport')).' '.get_lang('ComparativeReport').'</a></div><div class="sectioncomment">'.get_lang('ComparativeReportDetail').'.</div>';
  143. echo '<div class="sectiontitle"><a href="reporting.php?action=completereport&amp;survey_id='.$myweb_survey_id.'&'.api_get_cidreq().'">'.
  144. Display::return_icon('survey_reporting_complete.gif',get_lang('CompleteReport')).' '.get_lang('CompleteReport').'</a></div><div class="sectioncomment">'.get_lang('CompleteReportDetail').'</div>';
  145. }
  146. // Footer
  147. Display :: display_footer();