reporting.php 7.4 KB

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