reporting.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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($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($_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. // Checking the parameters
  56. SurveyUtil::check_parameters();
  57. /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
  58. if (!api_is_allowed_to_edit(false, true)) {
  59. Display :: display_header(get_lang('ToolSurvey'));
  60. Display :: display_error_message(get_lang('NotAllowed'), false);
  61. Display :: display_footer();
  62. exit;
  63. }
  64. // Database table definitions
  65. $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  66. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  67. // Getting the survey information
  68. $survey_data = survey_manager::get_survey($survey_id);
  69. if (empty($survey_data)) {
  70. Display :: display_header(get_lang('ToolSurvey'));
  71. Display :: display_error_message(get_lang('InvallidSurvey'), false);
  72. Display :: display_footer();
  73. exit;
  74. }
  75. $urlname = strip_tags(api_substr(api_html_entity_decode($survey_data['title'], ENT_QUOTES), 0, 40));
  76. if (api_strlen(strip_tags($survey_data['title'])) > 40) {
  77. $urlname .= '...';
  78. }
  79. // Breadcrumbs
  80. $interbreadcrumb[] = array('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
  81. $interbreadcrumb[] = array('url' => 'survey.php?survey_id='.$survey_id, 'name' => $urlname);
  82. if (!$_GET['action'] OR $_GET['action'] == 'overview') {
  83. $tool_name = get_lang('Reporting');
  84. } else {
  85. $interbreadcrumb[] = array('url' => 'reporting.php?survey_id='.$survey_id, 'name' => get_lang('Reporting'));
  86. switch ($_GET['action']) {
  87. case 'questionreport':
  88. $tool_name = get_lang('DetailedReportByQuestion');
  89. break;
  90. case 'userreport':
  91. $tool_name = get_lang('DetailedReportByUser');
  92. break;
  93. case 'comparativereport':
  94. $tool_name = get_lang('ComparativeReport');
  95. break;
  96. case 'completereport':
  97. $tool_name = get_lang('CompleteReport');
  98. break;
  99. }
  100. }
  101. // Displaying the header
  102. Display::display_header($tool_name, 'Survey');
  103. // Action handling
  104. SurveyUtil::handle_reporting_actions();
  105. // Actions bar
  106. echo '<div class="actions">';
  107. echo '<a href="survey.php?survey_id='.$survey_id.'">'.Display::return_icon('back.png', get_lang('BackToSurvey'),'',ICON_SIZE_MEDIUM).'</a>';
  108. echo '</div>';
  109. // Content
  110. if (!$_GET['action'] || $_GET['action'] == 'overview') {
  111. $myweb_survey_id = $survey_id;
  112. echo '<div class="sectiontitle"><a href="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>';
  113. echo '<div class="sectiontitle"><a href="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>';
  114. echo '<div class="sectiontitle"><a href="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>';
  115. 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>';
  116. }
  117. // Footer
  118. Display :: display_footer();