complete_report.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. /*
  3. DOKEOS - elearning and course management software
  4. For a full list of contributors, see documentation/credits.html
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. See "documentation/licence.html" more details.
  10. Contact:
  11. Dokeos
  12. Rue des Palais 44 Paleizenstraat
  13. B-1030 Brussels - Belgium
  14. Tel. +32 (2) 211 34 56
  15. */
  16. /**
  17. * @package dokeos.survey
  18. * @author
  19. * @version $Id: complete_report.php 10705 2007-01-12 22:40:01Z pcool $
  20. */
  21. // name of the language file that needs to be included
  22. $language_file = 'survey';
  23. // including the global dokeos file
  24. require_once ('../inc/global.inc.php');
  25. // including additional libraries
  26. /** @todo check if these are all needed */
  27. /** @todo check if the starting / is needed. api_get_path probably ends with an / */
  28. require_once (api_get_path(LIBRARY_PATH)."/course.lib.php");
  29. require_once (api_get_path(LIBRARY_PATH)."/groupmanager.lib.php");
  30. require_once (api_get_path(LIBRARY_PATH).'/fileManage.lib.php');
  31. require_once (api_get_path(CONFIGURATION_PATH) ."/add_course.conf.php");
  32. require_once (api_get_path(LIBRARY_PATH)."/add_course.lib.inc.php");
  33. require_once (api_get_path(LIBRARY_PATH)."/surveymanager.lib.php");
  34. /** @todo replace this with the correct code */
  35. /*
  36. $status = surveymanager::get_status();
  37. api_protect_course_script();
  38. if($status==5)
  39. {
  40. api_protect_admin_script();
  41. }
  42. */
  43. /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
  44. if (!api_is_allowed_to_edit())
  45. {
  46. Display :: display_header();
  47. Display :: display_error_message(get_lang('NotAllowedHere'));
  48. Display :: display_footer();
  49. exit;
  50. }
  51. // Database table definitions
  52. /** @todo use database constants for the survey tables */
  53. $tbl_user_survey = Database :: get_main_table(TABLE_MAIN_SURVEY_USER);
  54. $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  55. $tbl_questions_groups = Database :: get_course_table(TABLE_SURVEY_GROUP);
  56. $tbl_answers = Database :: get_course_table(TABLE_SURVEY_REPORT);
  57. // Path variables
  58. /** @todo these variables are probably not used here */
  59. // Language variables
  60. // breadcrumbs
  61. $interbreadcrumb[] = array ("url" => "survey_list.php", "name" => get_lang('Survey'));
  62. // $_GET and $_POST
  63. /** @todo replace $_REQUEST with $_GET or $_POST */
  64. $surveyid = $_REQUEST['surveyid'];
  65. $tool_name = get_lang('SurveyReporting');
  66. Display::display_header($tool_name);
  67. $users = SurveyManager::listUsers($surveyid, $db_name);
  68. $questions = SurveyManager::listQuestions($surveyid);
  69. $excel_content = '';
  70. $excel_file_name = 'export_survey-'.$surveyid.$db_name.'.csv';
  71. echo '<a href="../course_info/download.php?archive='.$excel_file_name.'"><img border="0" src="../img/xls.gif" align="middle"/>'.get_lang('ExportInExcel').'</a><br /><br/>';
  72. echo '<div style="overflow:scroll;">
  73. <table width="2000" height="300" style="">
  74. <tr style="font-weight:bold">
  75. <td valign="top" align="left" width="120">'.get_lang('LastName').'</td>
  76. <td valign="top" align="left" width="120">'.get_lang('FirstName').'</td>
  77. <td valign="top" align="left" width="200">'.get_lang('EmailAddress').'</td>
  78. <td valign="top" align="left" width="200">'.get_lang('Organisation').'</td>';
  79. $excel_content .= get_lang('LastName').';'.get_lang('FirstName').';'.get_lang('EmailAddress').';'.get_lang('Organisation').';';
  80. foreach($questions as $question){
  81. $question['caption'] = eregi_replace('^<p[^>]*>(.*)</p>','\\1', $question['caption']);
  82. $question['caption'] = eregi_replace('(<[^ ]*) (style=."."[^>]*)(>)','\\1\\3', $question['caption']);
  83. $question['caption'] = eregi_replace('(<[^ ]*) (style=.""[^>]*)(>)','\\1\\3', $question['caption']);
  84. $question['caption'] = eregi_replace('(<[^ ]*)( style=."[^"]*")([^>]*)(>)','\\1\\2\\4', $question['caption']);
  85. $excel_content .= stripslashes($question['caption']).';';
  86. echo '<td valign="top" align="left" width="200">'.stripslashes($question['caption']).'</td>';
  87. }
  88. $excel_content .= "\r\n";
  89. $color = '#FFCCCC';
  90. echo '<td style="background-color:#FFF">&nbsp;</td></tr><tr style="background-color:'.$color.'">';
  91. $lastEmail = $users[O]['email'];
  92. foreach($users as $user){
  93. if($user['email']!=$lastEmail){
  94. $excel_content .= "\r\n";
  95. $color = ($color == '#FFCCCC') ? '#CCCCFF' : '#FFCCCC';
  96. echo '<td style="background-color:#FFF">&nbsp;</td></tr><tr style="background-color:'.$color.'">';
  97. $lastEmail = $user['email'];
  98. $excel_content .= str_replace(array("\r","\n"),array("",""),$user['lastname'].';'.$user['firstname'].';'.$user['email'].';'.$user['organization'].';');
  99. echo ' <td valign="top" align="left" width="120">'.$user['lastname'].'</td>
  100. <td valign="top" align="left" width="120">'.$user['firstname'].'</td>
  101. <td valign="top" align="left" width="200">'.$user['email'].'</td>
  102. <td valign="top" align="left" width="200">'.nl2br($user['organization']).'</td>';
  103. }
  104. foreach($questions as $question){
  105. $sql = 'SELECT answer
  106. FROM '.$tbl_answers.' as answers
  107. WHERE qid='.$question['qid'].'
  108. AND user_id='.$user['user_id'];
  109. $rs = api_sql_query($sql, __FILE__, __LINE__);
  110. $answer = mysql_result($rs, 'answer');
  111. if(in_array($answer,array('a1','a2','a3','a4','a5','a6','a7','a8','a9','a10'))){
  112. $answer = $question[$answer];
  113. }
  114. if($question['qtype']=='Numbered'){
  115. $answers = explode(',',$answer);
  116. $final_answer = '';
  117. for($i=0;$i<count($answers);$i++){
  118. $final_answer.= $question['a'.($i+1)].' : '.$answers[$i].'<br />';
  119. }
  120. $answer = $final_answer;
  121. }
  122. if($question['qtype']=='Multiple Choice (multiple answer)'){
  123. $answers = explode(',',$answer);
  124. $final_answer = '';
  125. for($i=0;$i<count($answers);$i++){
  126. $final_answer.= $question['a'.($i+1)].'<br />';
  127. }
  128. $answer = $final_answer;
  129. }
  130. if(empty($answer))
  131. $answer = '-';
  132. $excel_content .= stripslashes(str_replace(array("\r","\n","<br />"),array("",""," - "),($answer))).';';
  133. echo '<td valign="top" align="left" width="200">'.stripslashes($answer).'</td>';
  134. }
  135. }
  136. echo '</table></div>';
  137. $archivePath=api_get_path(SYS_PATH).$archiveDirName.'/';
  138. $handle = fopen($archivePath.$excel_file_name, 'w');
  139. fwrite($handle, $excel_content);
  140. fclose($handle);
  141. chmod($archivePath.$excel_file_name, 0755);
  142. // Display the footer
  143. Display :: display_footer();
  144. ?>