reporting.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. $survey_id = isset($_GET['survey_id']) ? (int) $_GET['survey_id'] : 0;
  14. $userId = isset($_GET['user_id']) ? $_GET['user_id'] : 0;
  15. $action = isset($_GET['action']) ? $_GET['action'] : 'overview';
  16. $survey_data = SurveyManager::get_survey($survey_id);
  17. if (empty($survey_data)) {
  18. api_not_allowed(true);
  19. }
  20. if ($survey_data['anonymous'] == 0) {
  21. $people_filled_full_data = true;
  22. } else {
  23. $people_filled_full_data = false;
  24. }
  25. $people_filled = SurveyManager::get_people_who_filled_survey(
  26. $survey_id,
  27. $people_filled_full_data
  28. );
  29. // Checking the parameters
  30. SurveyUtil::check_parameters($people_filled);
  31. $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
  32. api_get_user_id(),
  33. api_get_course_info()
  34. );
  35. /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
  36. if (!api_is_allowed_to_edit(false, true) || $isDrhOfCourse) {
  37. // Show error message if the survey can be seen only by tutors
  38. if ($survey_data['visible_results'] == SURVEY_VISIBLE_TUTOR) {
  39. api_not_allowed(true);
  40. exit;
  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. $data = SurveyUtil::export_complete_report_xls(
  57. $survey_data,
  58. $filename,
  59. $userId
  60. );
  61. exit;
  62. break;
  63. case 'csv':
  64. default:
  65. $data = SurveyUtil::export_complete_report(
  66. $survey_data,
  67. $userId
  68. );
  69. $filename = 'survey_results_'.$survey_id.'.csv';
  70. header('Content-type: application/octet-stream');
  71. header('Content-Type: application/force-download');
  72. if (preg_match("/MSIE 5.5/", $_SERVER['HTTP_USER_AGENT'])) {
  73. header('Content-Disposition: filename= '.$filename);
  74. } else {
  75. header('Content-Disposition: attachment; filename= '.$filename);
  76. }
  77. if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
  78. header('Pragma: ');
  79. header('Cache-Control: ');
  80. header('Cache-Control: public'); // IE cannot download from sessions without a cache
  81. }
  82. header('Content-Description: '.$filename);
  83. header('Content-transfer-encoding: binary');
  84. echo $data;
  85. exit;
  86. break;
  87. }
  88. }
  89. $urlname = strip_tags(
  90. api_substr(api_html_entity_decode($survey_data['title'], ENT_QUOTES), 0, 40)
  91. );
  92. if (api_strlen(strip_tags($survey_data['title'])) > 40) {
  93. $urlname .= '...';
  94. }
  95. // Breadcrumbs
  96. $interbreadcrumb[] = array(
  97. 'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq(),
  98. 'name' => get_lang('SurveyList')
  99. );
  100. $interbreadcrumb[] = array(
  101. 'url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&'.api_get_cidreq(),
  102. 'name' => $urlname
  103. );
  104. if ($action == 'overview') {
  105. $tool_name = get_lang('Reporting');
  106. } else {
  107. $interbreadcrumb[] = array(
  108. 'url' => api_get_path(WEB_CODE_PATH).'survey/reporting.php?survey_id='.$survey_id,
  109. 'name' => get_lang('Reporting')
  110. );
  111. switch ($action) {
  112. case 'questionreport':
  113. $singlePage = isset($_GET['single_page']) ? intval($_GET['single_page']) : 0;
  114. $tool_name = $singlePage ? get_lang('QuestionsOverallReport') : get_lang('DetailedReportByQuestion');
  115. break;
  116. case 'userreport':
  117. $tool_name = get_lang('DetailedReportByUser');
  118. break;
  119. case 'comparativereport':
  120. $tool_name = get_lang('ComparativeReport');
  121. break;
  122. case 'completereport':
  123. $tool_name = get_lang('CompleteReport');
  124. break;
  125. }
  126. }
  127. // Displaying the header
  128. Display::display_header($tool_name, 'Survey');
  129. // Action handling
  130. SurveyUtil::handle_reporting_actions($survey_data, $people_filled);
  131. // Content
  132. if ($action == 'overview') {
  133. $html = null;
  134. $url = api_get_path(WEB_CODE_PATH).'survey/reporting.php?'.api_get_cidreq().'&';
  135. $html .= '<div class="survey-reports">';
  136. $html .= '<div class="list-group">';
  137. $html .= Display::url(
  138. Display::return_icon(
  139. 'survey_reporting_overall.png',
  140. get_lang('QuestionsOverallReport'),
  141. null,
  142. ICON_SIZE_MEDIUM
  143. ).'<h4>'.get_lang('QuestionsOverallReport').'</h4><p>'.get_lang('QuestionsOverallReportDetail').'</p>',
  144. $url.'action=questionreport&survey_id='.$survey_id.'&single_page=1',
  145. array('class' => 'list-group-item')
  146. );
  147. $html .= Display::url(
  148. Display::return_icon(
  149. 'survey_reporting_question.png',
  150. get_lang('DetailedReportByQuestion'),
  151. null,
  152. ICON_SIZE_MEDIUM
  153. ).'<h4>'.get_lang('DetailedReportByQuestion').'</h4><p>'.get_lang('DetailedReportByQuestionDetail').'</p>',
  154. $url.'action=questionreport&survey_id='.$survey_id,
  155. array('class' => 'list-group-item')
  156. );
  157. $html .= Display::url(
  158. Display::return_icon(
  159. 'survey_reporting_user.png',
  160. get_lang('DetailedReportByUser'),
  161. null,
  162. ICON_SIZE_MEDIUM
  163. ).'<h4>'.get_lang('DetailedReportByUser').'</h4><p>'.get_lang('DetailedReportByUserDetail').'</p>',
  164. $url.'action=userreport&survey_id='.$survey_id,
  165. array('class' => 'list-group-item')
  166. );
  167. $html .= Display::url(
  168. Display::return_icon(
  169. 'survey_reporting_comparative.png',
  170. get_lang('ComparativeReport'),
  171. null,
  172. ICON_SIZE_MEDIUM
  173. ).'<h4>'.get_lang('ComparativeReport').'</h4><p>'.get_lang('ComparativeReportDetail').'</p>',
  174. $url.'action=comparativereport&survey_id='.$survey_id,
  175. array('class' => 'list-group-item')
  176. );
  177. $html .= Display::url(
  178. Display::return_icon(
  179. 'survey_reporting_complete.png',
  180. get_lang('CompleteReport'),
  181. null,
  182. ICON_SIZE_MEDIUM
  183. ).'<h4>'.get_lang('CompleteReport').'</h4><p>'.get_lang('CompleteReportDetail').'</p>',
  184. $url.'action=completereport&survey_id='.$survey_id,
  185. array('class' => 'list-group-item')
  186. );
  187. $html .= '</div>';
  188. $html .= '</div>';
  189. echo $html;
  190. }
  191. Display::display_footer();