reporting.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. // Including the global initialization file
  12. require_once '../inc/global.inc.php';
  13. $this_section = SECTION_COURSES;
  14. $cidReq = api_get_cidreq();
  15. $survey_id = intval($_GET['survey_id']);
  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.'.xls';
  25. $data = SurveyUtil::export_complete_report_xls(
  26. $survey_data,
  27. $filename,
  28. $_GET['user_id']
  29. );
  30. exit;
  31. break;
  32. case 'csv':
  33. default:
  34. $data = SurveyUtil::export_complete_report(
  35. $survey_data,
  36. $_GET['user_id']
  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. $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
  71. api_get_user_id(),
  72. api_get_course_info()
  73. );
  74. /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
  75. if (!api_is_allowed_to_edit(false, true) || $isDrhOfCourse) {
  76. Display :: display_header(get_lang('ToolSurvey'));
  77. // Show error message if the survey can be seen only by tutors
  78. if ($survey_data['visible_results'] != SURVEY_VISIBLE_TUTOR) {
  79. SurveyUtil::handle_reporting_actions($survey_data, $people_filled);
  80. } else {
  81. Display :: display_error_message(get_lang('NotAllowed'), false);
  82. }
  83. Display :: display_footer();
  84. exit;
  85. }
  86. // Database table definitions
  87. $table_course = Database:: get_main_table(TABLE_MAIN_COURSE);
  88. $table_user = Database:: get_main_table(TABLE_MAIN_USER);
  89. // Getting the survey information
  90. if (empty($survey_data)) {
  91. Display :: display_header(get_lang('ToolSurvey'));
  92. Display :: display_error_message(get_lang('InvallidSurvey'), false);
  93. Display :: display_footer();
  94. exit;
  95. }
  96. $urlname = strip_tags(api_substr(api_html_entity_decode($survey_data['title'], ENT_QUOTES), 0, 40));
  97. if (api_strlen(strip_tags($survey_data['title'])) > 40) {
  98. $urlname .= '...';
  99. }
  100. // Breadcrumbs
  101. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php', 'name' => get_lang('SurveyList'));
  102. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id, 'name' => $urlname);
  103. if (!isset($_GET['action']) || isset($_GET['action']) && $_GET['action'] == 'overview') {
  104. $tool_name = get_lang('Reporting');
  105. } else {
  106. $interbreadcrumb[] = array(
  107. 'url' => api_get_path(WEB_CODE_PATH).'survey/reporting.php?survey_id='.$survey_id,
  108. 'name' => get_lang('Reporting')
  109. );
  110. switch ($_GET['action']) {
  111. case 'questionreport':
  112. $singlePage = isset($_GET['single_page']) ? intval($_GET['single_page']) : 0;
  113. $tool_name = $singlePage ? get_lang('QuestionsOverallReport') : get_lang('DetailedReportByQuestion');
  114. break;
  115. case 'userreport':
  116. $tool_name = get_lang('DetailedReportByUser');
  117. break;
  118. case 'comparativereport':
  119. $tool_name = get_lang('ComparativeReport');
  120. break;
  121. case 'completereport':
  122. $tool_name = get_lang('CompleteReport');
  123. break;
  124. }
  125. }
  126. // Displaying the header
  127. Display::display_header($tool_name, 'Survey');
  128. // Action handling
  129. SurveyUtil::handle_reporting_actions($survey_data, $people_filled);
  130. // Actions bar
  131. echo '<div class="actions">';
  132. echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'">'.
  133. Display::return_icon('back.png', get_lang('BackToSurvey'),'',ICON_SIZE_MEDIUM).'</a>';
  134. echo '</div>';
  135. // Content
  136. if (!isset($_GET['action']) ||
  137. isset($_GET['action']) &&
  138. $_GET['action'] == 'overview'
  139. ) {
  140. $myweb_survey_id = $survey_id;
  141. echo '<div class="sectiontitle"><a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action=questionreport&amp;survey_id='.$myweb_survey_id.'&amp;'.$cidReq.'&amp;single_page=1">'.
  142. Display::return_icon('survey_reporting_overall.png',get_lang('QuestionsOverallReport')).' '.get_lang('QuestionsOverallReport').'</a></div><div class="sectioncomment">'.get_lang('QuestionsOverallReportDetail').' </div>';
  143. echo '<div class="sectiontitle"><a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action=questionreport&amp;survey_id='.$myweb_survey_id.'&'.$cidReq.'">'.
  144. Display::return_icon('survey_reporting_question.gif',get_lang('DetailedReportByQuestion')).' '.get_lang('DetailedReportByQuestion').'</a></div><div class="sectioncomment">'.get_lang('DetailedReportByQuestionDetail').' </div>';
  145. echo '<div class="sectiontitle"><a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action=userreport&amp;survey_id='.$myweb_survey_id.'&'.$cidReq.'">'.
  146. Display::return_icon('survey_reporting_user.gif',get_lang('DetailedReportByUser')).' '.get_lang('DetailedReportByUser').'</a></div><div class="sectioncomment">'.get_lang('DetailedReportByUserDetail').'.</div>';
  147. echo '<div class="sectiontitle"><a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action=comparativereport&amp;survey_id='.$myweb_survey_id.'&'.$cidReq.'">'.
  148. Display::return_icon('survey_reporting_comparative.gif',get_lang('ComparativeReport')).' '.get_lang('ComparativeReport').'</a></div><div class="sectioncomment">'.get_lang('ComparativeReportDetail').'.</div>';
  149. echo '<div class="sectiontitle"><a href="reporting.php?action=completereport&amp;survey_id='.$myweb_survey_id.'&'.$cidReq.'">'.
  150. Display::return_icon('survey_reporting_complete.gif',get_lang('CompleteReport')).' '.get_lang('CompleteReport').'</a></div><div class="sectioncomment">'.get_lang('CompleteReportDetail').'</div>';
  151. }
  152. // Footer
  153. Display :: display_footer();