reporting.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.survey
  5. *
  6. * @author unknown, the initial survey that did not make it in 1.8 because of bad code
  7. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup,
  8. * refactoring and rewriting large parts of the code
  9. *
  10. * @todo The question has to be more clearly indicated (same style as when filling the survey)
  11. */
  12. require_once __DIR__.'/../inc/global.inc.php';
  13. $this_section = SECTION_COURSES;
  14. $survey_id = isset($_GET['survey_id']) ? (int) $_GET['survey_id'] : 0;
  15. $userId = isset($_GET['user_id']) ? $_GET['user_id'] : 0;
  16. $action = isset($_GET['action']) ? $_GET['action'] : 'overview';
  17. $survey_data = SurveyManager::get_survey($survey_id);
  18. if (empty($survey_data)) {
  19. api_not_allowed(true);
  20. }
  21. if ($survey_data['anonymous'] == 0) {
  22. $people_filled_full_data = true;
  23. } else {
  24. $people_filled_full_data = false;
  25. }
  26. $people_filled = SurveyManager::get_people_who_filled_survey(
  27. $survey_id,
  28. $people_filled_full_data
  29. );
  30. // Checking the parameters
  31. SurveyUtil::check_parameters($people_filled);
  32. $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
  33. api_get_user_id(),
  34. api_get_course_info()
  35. );
  36. /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
  37. if (!api_is_allowed_to_edit(false, true) || $isDrhOfCourse) {
  38. // Show error message if the survey can be seen only by tutors
  39. if ($survey_data['visible_results'] == SURVEY_VISIBLE_TUTOR) {
  40. api_not_allowed(true);
  41. }
  42. Display::display_header(get_lang('ToolSurvey'));
  43. SurveyUtil::handle_reporting_actions($survey_data, $people_filled);
  44. Display::display_footer();
  45. exit;
  46. }
  47. /**
  48. * @todo use Export::arrayToCsv($data, $filename = 'export')
  49. */
  50. $exportReport = isset($_REQUEST['export_report']) ? $_REQUEST['export_report'] : '';
  51. $format = isset($_REQUEST['export_format']) ? $_REQUEST['export_format'] : '';
  52. if (!empty($exportReport) && !empty($format)) {
  53. switch ($format) {
  54. case 'xls':
  55. $filename = 'survey_results_'.$survey_id.'.xlsx';
  56. SurveyUtil::export_complete_report_xls($survey_data, $filename, $userId);
  57. exit;
  58. break;
  59. case 'csv':
  60. default:
  61. $data = SurveyUtil::export_complete_report($survey_data, $userId);
  62. $filename = 'survey_results_'.$survey_id.'.csv';
  63. header('Content-type: application/octet-stream');
  64. header('Content-Type: application/force-download');
  65. if (preg_match("/MSIE 5.5/", $_SERVER['HTTP_USER_AGENT'])) {
  66. header('Content-Disposition: filename= '.$filename);
  67. } else {
  68. header('Content-Disposition: attachment; filename= '.$filename);
  69. }
  70. if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
  71. header('Pragma: ');
  72. header('Cache-Control: ');
  73. header('Cache-Control: public'); // IE cannot download from sessions without a cache
  74. }
  75. header('Content-Description: '.$filename);
  76. header('Content-transfer-encoding: binary');
  77. echo $data;
  78. exit;
  79. break;
  80. }
  81. }
  82. $urlname = strip_tags(
  83. api_substr(api_html_entity_decode($survey_data['title'], ENT_QUOTES), 0, 40)
  84. );
  85. if (api_strlen(strip_tags($survey_data['title'])) > 40) {
  86. $urlname .= '...';
  87. }
  88. // Breadcrumbs
  89. $interbreadcrumb[] = [
  90. 'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq(),
  91. 'name' => get_lang('SurveyList'),
  92. ];
  93. $interbreadcrumb[] = [
  94. 'url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&'.api_get_cidreq(),
  95. 'name' => $urlname,
  96. ];
  97. if ($action == 'overview') {
  98. $tool_name = get_lang('Reporting');
  99. } else {
  100. $interbreadcrumb[] = [
  101. 'url' => api_get_path(WEB_CODE_PATH).'survey/reporting.php?survey_id='.$survey_id,
  102. 'name' => get_lang('Reporting'),
  103. ];
  104. switch ($action) {
  105. case 'questionreport':
  106. $singlePage = isset($_GET['single_page']) ? (int) $_GET['single_page'] : 0;
  107. $tool_name = $singlePage ? get_lang('QuestionsOverallReport') : get_lang('DetailedReportByQuestion');
  108. break;
  109. case 'userreport':
  110. $tool_name = get_lang('DetailedReportByUser');
  111. break;
  112. case 'comparativereport':
  113. $tool_name = get_lang('ComparativeReport');
  114. break;
  115. case 'completereport':
  116. $tool_name = get_lang('CompleteReport');
  117. break;
  118. }
  119. }
  120. // Displaying the header
  121. Display::display_header($tool_name, 'Survey');
  122. // Action handling
  123. SurveyUtil::handle_reporting_actions($survey_data, $people_filled);
  124. // Content
  125. if ($action == 'overview') {
  126. $html = null;
  127. $url = api_get_path(WEB_CODE_PATH).'survey/reporting.php?'.api_get_cidreq().'&';
  128. $html .= '<div class="survey-reports">';
  129. $html .= '<div class="list-group">';
  130. $html .= Display::url(
  131. Display::return_icon(
  132. 'survey_reporting_overall.png',
  133. get_lang('QuestionsOverallReport'),
  134. null,
  135. ICON_SIZE_MEDIUM
  136. ).'<h4>'.get_lang('QuestionsOverallReport').'</h4><p>'.get_lang('QuestionsOverallReportDetail').'</p>',
  137. $url.'action=questionreport&survey_id='.$survey_id.'&single_page=1',
  138. ['class' => 'list-group-item']
  139. );
  140. $html .= Display::url(
  141. Display::return_icon(
  142. 'survey_reporting_question.png',
  143. get_lang('DetailedReportByQuestion'),
  144. null,
  145. ICON_SIZE_MEDIUM
  146. ).'<h4>'.get_lang('DetailedReportByQuestion').'</h4><p>'.get_lang('DetailedReportByQuestionDetail').'</p>',
  147. $url.'action=questionreport&survey_id='.$survey_id,
  148. ['class' => 'list-group-item']
  149. );
  150. $html .= Display::url(
  151. Display::return_icon(
  152. 'survey_reporting_user.png',
  153. get_lang('DetailedReportByUser'),
  154. null,
  155. ICON_SIZE_MEDIUM
  156. ).'<h4>'.get_lang('DetailedReportByUser').'</h4><p>'.get_lang('DetailedReportByUserDetail').'</p>',
  157. $url.'action=userreport&survey_id='.$survey_id,
  158. ['class' => 'list-group-item']
  159. );
  160. $html .= Display::url(
  161. Display::return_icon(
  162. 'survey_reporting_comparative.png',
  163. get_lang('ComparativeReport'),
  164. null,
  165. ICON_SIZE_MEDIUM
  166. ).'<h4>'.get_lang('ComparativeReport').'</h4><p>'.get_lang('ComparativeReportDetail').'</p>',
  167. $url.'action=comparativereport&survey_id='.$survey_id,
  168. ['class' => 'list-group-item']
  169. );
  170. $html .= Display::url(
  171. Display::return_icon(
  172. 'survey_reporting_complete.png',
  173. get_lang('CompleteReport'),
  174. null,
  175. ICON_SIZE_MEDIUM
  176. ).'<h4>'.get_lang('CompleteReport').'</h4><p>'.get_lang('CompleteReportDetail').'</p>',
  177. $url.'action=completereport&survey_id='.$survey_id,
  178. ['class' => 'list-group-item']
  179. );
  180. $html .= '</div>';
  181. $html .= '</div>';
  182. echo $html;
  183. }
  184. Display::display_footer();