reporting.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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(
  94. api_substr(api_html_entity_decode($survey_data['title'], ENT_QUOTES), 0, 40)
  95. );
  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',
  102. 'name' => get_lang('SurveyList')
  103. );
  104. $interbreadcrumb[] = array(
  105. 'url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?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?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?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. $html = null;
  147. $url = api_get_path(WEB_CODE_PATH).'survey/reporting.php?';
  148. $html .= '<div class="survey-reports">';
  149. $html .= '<div class="list-group">';
  150. $html .= Display::url(
  151. Display::return_icon(
  152. 'survey_reporting_overall.png',
  153. get_lang('QuestionsOverallReport'),
  154. null,
  155. ICON_SIZE_MEDIUM
  156. ).'<h4>'.get_lang('QuestionsOverallReport').'</h4><p>'.get_lang('QuestionsOverallReportDetail').'</p>',
  157. $url.'action=questionreport&survey_id='.$survey_id.'&'.$cidReq.'&single_page=1',
  158. array('class' => 'list-group-item')
  159. );
  160. $html .= Display::url(
  161. Display::return_icon(
  162. 'survey_reporting_question.png',
  163. get_lang('DetailedReportByQuestion'),
  164. null,
  165. ICON_SIZE_MEDIUM
  166. ).'<h4>'.get_lang('DetailedReportByQuestion').'</h4><p>'.get_lang('DetailedReportByQuestionDetail').'</p>',
  167. $url.'action=questionreport&survey_id='.$survey_id.'&'.$cidReq,
  168. array('class' => 'list-group-item')
  169. );
  170. $html .= Display::url(
  171. Display::return_icon(
  172. 'survey_reporting_user.png',
  173. get_lang('DetailedReportByUser'),
  174. null,
  175. ICON_SIZE_MEDIUM
  176. ).'<h4>'.get_lang('DetailedReportByUser').'</h4><p>'.get_lang('DetailedReportByUserDetail').'</p>',
  177. $url.'action=userreport&survey_id='.$survey_id.'&'.$cidReq,
  178. array('class' => 'list-group-item')
  179. );
  180. $html .= Display::url(
  181. Display::return_icon(
  182. 'survey_reporting_comparative.png',
  183. get_lang('ComparativeReport'),
  184. null,
  185. ICON_SIZE_MEDIUM
  186. ).'<h4>'.get_lang('ComparativeReport').'</h4><p>'.get_lang('ComparativeReportDetail').'</p>',
  187. $url.'action=comparativereport&survey_id='.$survey_id.'&'.$cidReq,
  188. array('class' => 'list-group-item')
  189. );
  190. $html .= Display::url(
  191. Display::return_icon(
  192. 'survey_reporting_complete.png',
  193. get_lang('CompleteReport'),
  194. null,
  195. ICON_SIZE_MEDIUM
  196. ).'<h4>'.get_lang('CompleteReport').'</h4><p>'.get_lang('CompleteReportDetail').'</p>',
  197. $url.'action=completereport&survey_id='.$survey_id.'&'.$cidReq,
  198. array('class' => 'list-group-item')
  199. );
  200. $html .= '</div>';
  201. $html .= '</div>';
  202. echo $html;
  203. }
  204. Display :: display_footer();