complete_report.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. $langFile = 'survey';
  3. require_once ('../inc/global.inc.php');
  4. require_once (api_get_path(LIBRARY_PATH)."/course.lib.php");
  5. require (api_get_path(LIBRARY_PATH)."/groupmanager.lib.php");
  6. $cidReq = $_REQUEST['cidReq'];
  7. $tbl_user_survey = Database::get_main_table(MAIN_SURVEY_USER_TABLE);
  8. $tbl_questions = Database::get_course_table('questions');
  9. $tbl_questions_groups = Database::get_course_table('survey_group');
  10. $tbl_answers = Database::get_course_table('survey_report');
  11. require_once (api_get_path(LIBRARY_PATH).'/fileManage.lib.php');
  12. require_once (api_get_path(CONFIGURATION_PATH) ."/add_course.conf.php");
  13. require_once (api_get_path(LIBRARY_PATH)."/add_course.lib.inc.php");
  14. require_once (api_get_path(LIBRARY_PATH)."/surveymanager.lib.php");
  15. $status = surveymanager::get_status();
  16. $surveyid=$_REQUEST['surveyid'];
  17. $db_name = $_REQUEST['db_name'];
  18. if($status==5)
  19. {
  20. api_protect_admin_script();
  21. }
  22. $tool_name = get_lang('SurveyReporting');
  23. $interbreadcrumb[] = array ("url" => "survey_list.php", "name" => get_lang('Survey'));
  24. Display::display_header($tool_name);
  25. /*
  26. $sql = 'SELECT *
  27. FROM '.$tbl_user_survey.' as user_survey,'.$tbl_questions.' as questions, '.$tbl_answers.' as answers, '.$tbl_questions_groups.' as groups
  28. WHERE answers.qid = questions.qid
  29. AND answers.user_id = user_survey.user_id
  30. AND user_survey.survey_id='.$surveyid.'
  31. AND user_survey.db_name="'.$db_name.'"
  32. AND groups.group_id = questions.gid
  33. ORDER BY email, groups.sortby, questions.sortby';
  34. $rs = api_sql_query($sql, __FILE__, __LINE__);
  35. $answers = api_store_result($rs);
  36. */
  37. $users = SurveyManager::listUsers($surveyid, $db_name);
  38. $questions = SurveyManager::listQuestions($surveyid);
  39. $excel_content = '';
  40. $excel_file_name = 'export_survey-'.$surveyid.$db_name.'.csv';
  41. 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/>';
  42. echo '<div style="overflow:scroll;">
  43. <table width="2000" height="300" style="">
  44. <tr style="font-weight:bold">
  45. <td valign="top" align="left" width="120">'.get_lang('LastName').'</td>
  46. <td valign="top" align="left" width="120">'.get_lang('FirstName').'</td>
  47. <td valign="top" align="left" width="200">'.get_lang('EmailAddress').'</td>
  48. <td valign="top" align="left" width="200">'.get_lang('Organisation').'</td>';
  49. $excel_content .= get_lang('LastName').';'.get_lang('FirstName').';'.get_lang('EmailAddress').';'.get_lang('Organisation').';';
  50. foreach($questions as $question){
  51. $question['caption'] = eregi_replace('^<p[^>]*>(.*)</p>','\\1', $question['caption']);
  52. $question['caption'] = eregi_replace('(<[^ ]*) (style=."."[^>]*)(>)','\\1\\3', $question['caption']);
  53. $question['caption'] = eregi_replace('(<[^ ]*) (style=.""[^>]*)(>)','\\1\\3', $question['caption']);
  54. $question['caption'] = eregi_replace('(<[^ ]*)( style=."[^"]*")([^>]*)(>)','\\1\\2\\4', $question['caption']);
  55. $excel_content .= stripslashes($question['caption']).';';
  56. echo '<td valign="top" align="left" width="200">'.stripslashes($question['caption']).'</td>';
  57. }
  58. $excel_content .= "\r\n";
  59. $color = '#FFCCCC';
  60. echo '<td style="background-color:#FFF">&nbsp;</td></tr><tr style="background-color:'.$color.'">';
  61. $lastEmail = $users[O]['email'];
  62. foreach($users as $user){
  63. if($user['email']!=$lastEmail){
  64. $excel_content .= "\r\n";
  65. $color = ($color == '#FFCCCC') ? '#CCCCFF' : '#FFCCCC';
  66. echo '<td style="background-color:#FFF">&nbsp;</td></tr><tr style="background-color:'.$color.'">';
  67. $lastEmail = $user['email'];
  68. $excel_content .= str_replace(array("\r","\n"),array("",""),$user['lastname'].';'.$user['firstname'].';'.$user['email'].';'.$user['organization'].';');
  69. echo ' <td valign="top" align="left" width="120">'.$user['lastname'].'</td>
  70. <td valign="top" align="left" width="120">'.$user['firstname'].'</td>
  71. <td valign="top" align="left" width="200">'.$user['email'].'</td>
  72. <td valign="top" align="left" width="200">'.nl2br($user['organization']).'</td>';
  73. }
  74. foreach($questions as $question){
  75. $sql = 'SELECT answer
  76. FROM '.$tbl_answers.' as answers
  77. WHERE qid='.$question['qid'].'
  78. AND user_id='.$user['user_id'];
  79. $rs = api_sql_query($sql, __FILE__, __LINE__);
  80. $answer = mysql_result($rs, 'answer');
  81. if(in_array($answer,array('a1','a2','a3','a4','a5','a6','a7','a8','a9','a10'))){
  82. $answer = $question[$answer];
  83. }
  84. if($question['qtype']=='Numbered'){
  85. $answers = explode(',',$answer);
  86. $final_answer = '';
  87. for($i=0;$i<count($answers);$i++){
  88. $final_answer.= $question['a'.($i+1)].' : '.$answers[$i].'<br />';
  89. }
  90. $answer = $final_answer;
  91. }
  92. if($question['qtype']=='Multiple Choice (multiple answer)'){
  93. $answers = explode(',',$answer);
  94. $final_answer = '';
  95. for($i=0;$i<count($answers);$i++){
  96. $final_answer.= $question['a'.($i+1)].'<br />';
  97. }
  98. $answer = $final_answer;
  99. }
  100. if(empty($answer))
  101. $answer = '-';
  102. $excel_content .= stripslashes(str_replace(array("\r","\n","<br />"),array("",""," - "),($answer))).';';
  103. echo '<td valign="top" align="left" width="200">'.stripslashes($answer).'</td>';
  104. }
  105. }
  106. echo '</table></div>';
  107. $archivePath=api_get_path(SYS_PATH).$archiveDirName.'/';
  108. $handle = fopen($archivePath.$excel_file_name, 'w');
  109. fwrite($handle, $excel_content);
  110. fclose($handle);
  111. chmod($archivePath.$excel_file_name, 0755);
  112. Display :: display_footer();
  113. ?>