reporting.php 6.0 KB

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