reporting.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. require_once __DIR__.'/../inc/global.inc.php';
  12. $this_section = SECTION_COURSES;
  13. $cidReq = api_get_cidreq();
  14. $survey_id = intval($_GET['survey_id']);
  15. $userId = isset($_GET['user_id']) ? $_GET['user_id'] : 0;
  16. $survey_data = SurveyManager::get_survey($survey_id);
  17. // Export
  18. /**
  19. * @todo use Export::arrayToCsv($data, $filename = 'export')
  20. */
  21. if (isset($_POST['export_report']) && $_POST['export_report']) {
  22. switch ($_POST['export_format']) {
  23. case 'xls':
  24. $filename = 'survey_results_'.$survey_id.'.xlsx';
  25. $data = SurveyUtil::export_complete_report_xls(
  26. $survey_data,
  27. $filename,
  28. $userId
  29. );
  30. exit;
  31. break;
  32. case 'csv':
  33. default:
  34. $data = SurveyUtil::export_complete_report(
  35. $survey_data,
  36. $userId
  37. );
  38. $filename = 'survey_results_'.$survey_id.'.csv';
  39. header('Content-type: application/octet-stream');
  40. header('Content-Type: application/force-download');
  41. if (preg_match("/MSIE 5.5/", $_SERVER['HTTP_USER_AGENT'])) {
  42. header('Content-Disposition: filename= '.$filename);
  43. } else {
  44. header('Content-Disposition: attachment; filename= '.$filename);
  45. }
  46. if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
  47. header('Pragma: ');
  48. header('Cache-Control: ');
  49. header('Cache-Control: public'); // IE cannot download from sessions without a cache
  50. }
  51. header('Content-Description: '.$filename);
  52. header('Content-transfer-encoding: binary');
  53. echo $data;
  54. exit;
  55. break;
  56. }
  57. }
  58. if ($survey_data['anonymous'] == 0) {
  59. $people_filled_full_data = true;
  60. } else {
  61. $people_filled_full_data = false;
  62. }
  63. $people_filled = SurveyManager::get_people_who_filled_survey(
  64. $_GET['survey_id'],
  65. $people_filled_full_data
  66. );
  67. // Checking the parameters
  68. SurveyUtil::check_parameters($people_filled);
  69. $survey_data = SurveyManager::get_survey($survey_id);
  70. // Getting the survey information
  71. if (empty($survey_data)) {
  72. api_not_allowed(true);
  73. }
  74. $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
  75. api_get_user_id(),
  76. api_get_course_info()
  77. );
  78. /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
  79. if (!api_is_allowed_to_edit(false, true) || $isDrhOfCourse) {
  80. // Show error message if the survey can be seen only by tutors
  81. if ($survey_data['visible_results'] == SURVEY_VISIBLE_TUTOR) {
  82. api_not_allowed(true);
  83. exit;
  84. }
  85. Display :: display_header(get_lang('ToolSurvey'));
  86. SurveyUtil::handle_reporting_actions($survey_data, $people_filled);
  87. Display :: display_footer();
  88. exit;
  89. }
  90. // Database table definitions
  91. $table_course = Database::get_main_table(TABLE_MAIN_COURSE);
  92. $table_user = Database::get_main_table(TABLE_MAIN_USER);
  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. $singlePage = isset($_GET['single_page']) ? intval($_GET['single_page']) : 0;
  110. $tool_name = $singlePage ? get_lang('QuestionsOverallReport') : 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, 'Survey');
  125. // Action handling
  126. SurveyUtil::handle_reporting_actions($survey_data, $people_filled);
  127. // Actions bar
  128. echo '<div class="actions">';
  129. echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'">'.
  130. Display::return_icon('back.png', get_lang('BackToSurvey'), '', ICON_SIZE_MEDIUM).'</a>';
  131. echo '</div>';
  132. // Content
  133. if (!isset($_GET['action']) ||
  134. isset($_GET['action']) &&
  135. $_GET['action'] == 'overview'
  136. ) {
  137. $myweb_survey_id = $survey_id;
  138. echo '<div class="sectiontitle"><a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action=questionreport&survey_id='.$myweb_survey_id.'&'.$cidReq.'&single_page=1">'.
  139. Display::return_icon('survey_reporting_overall.png', get_lang('QuestionsOverallReport')).' '.get_lang('QuestionsOverallReport').'</a></div><div class="sectioncomment">'.get_lang('QuestionsOverallReportDetail').' </div>';
  140. echo '<div class="sectiontitle"><a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action=questionreport&survey_id='.$myweb_survey_id.'&'.$cidReq.'">'.
  141. Display::return_icon('survey_reporting_question.gif', get_lang('DetailedReportByQuestion')).' '.get_lang('DetailedReportByQuestion').'</a></div><div class="sectioncomment">'.get_lang('DetailedReportByQuestionDetail').' </div>';
  142. echo '<div class="sectiontitle"><a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action=userreport&survey_id='.$myweb_survey_id.'&'.$cidReq.'">'.
  143. Display::return_icon('survey_reporting_user.gif', get_lang('DetailedReportByUser')).' '.get_lang('DetailedReportByUser').'</a></div><div class="sectioncomment">'.get_lang('DetailedReportByUserDetail').'.</div>';
  144. echo '<div class="sectiontitle"><a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action=comparativereport&survey_id='.$myweb_survey_id.'&'.$cidReq.'">'.
  145. Display::return_icon('survey_reporting_comparative.gif', get_lang('ComparativeReport')).' '.get_lang('ComparativeReport').'</a></div><div class="sectioncomment">'.get_lang('ComparativeReportDetail').'.</div>';
  146. echo '<div class="sectiontitle"><a href="reporting.php?action=completereport&survey_id='.$myweb_survey_id.'&'.$cidReq.'">'.
  147. Display::return_icon('survey_reporting_complete.gif', get_lang('CompleteReport')).' '.get_lang('CompleteReport').'</a></div><div class="sectioncomment">'.get_lang('CompleteReportDetail').'</div>';
  148. }
  149. Display :: display_footer();