course_session_report.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <?php
  2. $language_file = array ('registration', 'index', 'tracking', 'exercice','survey');
  3. $cidReset = true;
  4. require_once '../inc/global.inc.php';
  5. require_once api_get_path(LIBRARY_PATH).'course.lib.php';
  6. require_once (api_get_path(LIBRARY_PATH).'tracking.lib.php');
  7. require_once api_get_path(LIBRARY_PATH).'sessionmanager.lib.php';
  8. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  9. require_once api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer.php';
  10. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
  11. require_once api_get_path(SYS_CODE_PATH).'exercice/question.class.php';
  12. require_once api_get_path(LIBRARY_PATH).'events.lib.inc.php';
  13. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathList.class.php';
  14. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php';
  15. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathList.class.php';
  16. $this_section = "session_my_space";
  17. $is_allowedToTrack = $is_courseAdmin || $is_platformAdmin || $is_courseCoach || $is_sessionAdmin;
  18. if(!$is_allowedToTrack) {
  19. Display :: display_header(null);
  20. api_not_allowed();
  21. Display :: display_footer();
  22. }
  23. $export_to_xls = false;
  24. if (isset($_GET['export'])) {
  25. $export_to_xls = true;
  26. }
  27. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  28. $tbl_stats_exercices = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  29. if (api_is_platform_admin() ) {
  30. $global = true;
  31. } else {
  32. $global = false;
  33. }
  34. $global = true;
  35. $session_id = intval($_GET['session_id']);
  36. if (empty($session_id)) {
  37. $session_id = 1;
  38. }
  39. $form = new FormValidator('search_simple','POST','','',null,false);
  40. //Get session list
  41. $session_list = SessionManager::get_sessions_list(array(), array('name'));
  42. $my_session_list = array();
  43. foreach($session_list as $sesion_item) {
  44. $my_session_list[$sesion_item['id']] = $sesion_item['name'];
  45. }
  46. if (count($session_list) == 0) {
  47. $my_session_list[0] = get_lang('None');
  48. }
  49. $form->addElement('select', 'session_id', get_lang('Sessions'), $my_session_list);
  50. $form->addElement('style_submit_button','submit',get_lang('Filter'));
  51. if (!empty($_REQUEST['score'])) $filter_score = intval($_REQUEST['score']); else $filter_score = 70;
  52. if (!empty($_REQUEST['session_id'])) $session_id = intval($_REQUEST['session_id']); else $session_id = 0;
  53. if (empty($session_id)) {
  54. $session_id = key($my_session_list);
  55. }
  56. $form->setDefaults(array('session_id'=>$session_id));
  57. $course_list = SessionManager::get_course_list_by_session_id($session_id);
  58. if (!$export_to_xls) {
  59. Display :: display_header(get_lang("MySpace"));
  60. echo '<div class="actions" style ="font-size:10pt;" >';
  61. if ($global) {
  62. $menu_items[] = '<a href="'.api_get_path(WEB_CODE_PATH).'mySpace/?view=teacher">'.get_lang('TeacherInterface').'</a>';
  63. $menu_items[] = get_lang('AdminInterface');
  64. $menu_items[] = '<a href="'.api_get_path(WEB_CODE_PATH).'tracking/exams.php">'.get_lang('ExamTracking').'</a>';
  65. $nb_menu_items = count($menu_items);
  66. if($nb_menu_items>1) {
  67. foreach($menu_items as $key=> $item) {
  68. echo $item;
  69. if($key!=$nb_menu_items-1) {
  70. echo ' | ';
  71. }
  72. }
  73. echo '<br />';
  74. }
  75. } else {
  76. echo '<div style="float:left; clear:left">
  77. <a href="courseLog.php?'.api_get_cidreq().'&studentlist=true">'.get_lang('StudentsTracking').'</a>&nbsp;|
  78. <a href="courseLog.php?'.api_get_cidreq().'&studentlist=false">'.get_lang('CourseTracking').'</a>&nbsp;';
  79. echo '</div>';
  80. }
  81. echo '</div>';
  82. echo '<h4>'.get_lang('CoachList').'</h4>';
  83. if (api_is_platform_admin()) {
  84. echo '<a href="'.api_get_path(WEB_CODE_PATH).'mySpace/?view=admin&amp;display=coaches">'.get_lang('DisplayCoaches').'</a> | ';
  85. echo '<a href="'.api_get_path(WEB_CODE_PATH).'mySpace/?view=admin&amp;display=useroverview">'.get_lang('DisplayUserOverview').'</a>';
  86. echo ' | <a href="'.api_get_path(WEB_CODE_PATH).'mySpace/?view=admin&amp;display=sessionoverview">'.get_lang('DisplaySessionOverview').'</a>';
  87. echo ' | <a href="'.api_get_path(WEB_CODE_PATH).'mySpace/?view=admin&amp;display=courseoverview">'.get_lang('DisplayCourseOverview').'</a>';
  88. echo ' | <a href="'.api_get_path(WEB_CODE_PATH).'tracking/question_course_report.php?view=admin">'.get_lang('LPQuestionListResults').'</a>';
  89. echo ' | '.get_lang('LPExerciseResultsBySession').'';
  90. }
  91. echo '<h2>'.get_lang('LPExerciseResultsBySession').'</h2>';
  92. $form->display();
  93. Display::display_normal_message(get_lang('StudentScoreAverageIsCalculatedBaseInAllLPsAndAllAttempts'));
  94. //echo '<h3>'.sprintf(get_lang('FilteringWithScoreX'), $filter_score).'%</h3>';
  95. // echo '<a href="'.api_get_self().'?export=1&score='.$filter_score.'&exercise_id='.$exercise_id.'"><img align="absbottom" src="../img/excel.gif">&nbsp;'.get_lang('ExportAsXLS').'</a><br /><br />';
  96. }
  97. $users = SessionManager::get_users_by_session($session_id);
  98. $course_average = $course_average_counter = array();
  99. $counter = 0;
  100. $main_result = array();
  101. //Getting course list
  102. foreach($course_list as $current_course ) {
  103. $course_info = api_get_course_info($current_course['code']);
  104. $_course = $course_info;
  105. $attempt_result = array();
  106. //Getting LP list
  107. $list = new learnpathList('', $current_course['code'], $session_id);
  108. $lp_list = $list->get_flat_list();
  109. // Looping LPs
  110. foreach ($lp_list as $lp_id =>$lp) {
  111. $exercise_list = get_all_exercises_from_lp($lp_id, $current_course['db_name']);
  112. //Looping Chamilo Exercises in LP
  113. foreach ($exercise_list as $exercise) {
  114. $exercise_stats = get_all_exercise_event_from_lp($exercise['path'],$course_info['id'], $session_id);
  115. //Looping Exercise Attempts
  116. foreach($exercise_stats as $stats) {
  117. $attempt_result[$stats['exe_user_id']]['result'] += $stats['exe_result'] / $stats['exe_weighting'];
  118. $attempt_result[$stats['exe_user_id']]['attempts']++;
  119. }
  120. }
  121. }
  122. $main_result[$current_course['code']] = $attempt_result;
  123. }
  124. //var_dump($main_result);
  125. $total_average_score = 0;
  126. $total_average_score_count = 0;
  127. if (!empty($users) && is_array($users)) {
  128. $html_result .= '<table class="data_table">';
  129. $html_result .= '<tr><th>'.get_lang('User').'</th>';
  130. foreach($course_list as $item ) {
  131. $html_result .= '<th>'.$item['title'].'<br /> '.get_lang('AverageScore').' %</th>';
  132. }
  133. $html_result .= '<th>'.get_lang('AverageScore').' %</th>';
  134. $html_result .= '<th>'.get_lang('LastConnexionDate').'</th></tr>';
  135. foreach ($users as $user) {
  136. $total_student = 0;
  137. $counter ++;
  138. $s_css_class = 'row_even';
  139. if ($counter % 2 ==0 ) {
  140. $s_css_class = 'row_odd';
  141. }
  142. $html_result .= "<tr class='$s_css_class'>
  143. <td >";
  144. $html_result .= $user['firstname'].' '.$user['lastname'];
  145. $html_result .= "</td>";
  146. //Getting course list
  147. $counter = 0;
  148. $total_result_by_user = 0;
  149. foreach($course_list as $current_course ) {
  150. $total_course = 0;
  151. $user_info_stat = $main_result[$current_course['code']][$user['user_id']];
  152. $html_result .= "<td align=\"center\" >";
  153. if (!empty($user_info_stat['result']) && !empty($user_info_stat['attempts'])) {
  154. $result =round($user_info_stat['result']/$user_info_stat['attempts'] * 100, 2);
  155. $total_course +=$result;
  156. $total_result_by_user +=$result;
  157. $course_average[$current_course['code']] += $total_course;
  158. $course_average_counter[$current_course['code']]++;
  159. $result = $result .' ('.$user_info_stat['attempts'].' '.get_lang('Attempts').')';
  160. $counter++;
  161. } else {
  162. $result = '-';
  163. }
  164. $html_result .= $result;
  165. $html_result .= "</td>";
  166. }
  167. if (empty($counter)) {
  168. $total_student = '-';
  169. } else {
  170. $total_student = $total_result_by_user/$counter;
  171. $total_average_score+=$total_student;
  172. $total_average_score_count++;
  173. }
  174. $string_date=Tracking :: get_last_connection_date($user['user_id'],true);
  175. $html_result .="<td align=\"center\">$total_student</td><td>$string_date</td></tr>";
  176. }
  177. $html_result .="<tr><th>".get_lang('AverageScore')."</th>";
  178. $total_average = 0;
  179. $counter = 0;
  180. foreach($course_list as $course_item) {
  181. if (!empty($course_average_counter[$course_item['code']])) {
  182. $average_per_course = round($course_average[$course_item['code']]/($course_average_counter[$course_item['code']]*100)*100,2);
  183. } else {
  184. $average_per_course = '-';
  185. }
  186. if (!empty($average_per_course)) {
  187. $counter++;
  188. }
  189. $total_average = $total_average + $average_per_course;
  190. $html_result .="<td align=\"center\">$average_per_course</td>";
  191. }
  192. if (!empty($total_average_score_count)) {
  193. $total_average = round($total_average_score/($total_average_score_count*100)*100,2);
  194. } else {
  195. $total_average = '-';
  196. }
  197. $html_result .='<td align="center">'.$total_average.'</td>';
  198. $html_result .="<td>-</td>";
  199. $html_result .="</tr>";
  200. $html_result .= '</table>';
  201. } else {
  202. Display::display_warning_message(get_lang('NoResults'));
  203. }
  204. if (!$export_to_xls) {
  205. echo $html_result;
  206. }
  207. $filename = 'exam-reporting-'.date('Y-m-d-h:i:s').'.xls';
  208. if ($export_to_xls) {
  209. echo $html_result;
  210. export_complete_report_xls($filename, $export_array);
  211. exit;
  212. }
  213. function sort_user($a, $b) {
  214. if (is_numeric($a['score']) && is_numeric($b['score'])) {
  215. echo $a['score'].' : '.$b['score'];
  216. echo '<br />';
  217. if ($a['score'] < $b['score']) {
  218. return 1;
  219. }
  220. return 0;
  221. }
  222. return 1;
  223. }
  224. function export_complete_report_xls($filename, $array) {
  225. global $charset;
  226. $workbook = new Spreadsheet_Excel_Writer();
  227. $workbook ->setTempDir(api_get_path(SYS_ARCHIVE_PATH));
  228. $workbook->send($filename);
  229. $workbook->setVersion(8); // BIFF8
  230. $worksheet =& $workbook->addWorksheet('Report');
  231. //$worksheet->setInputEncoding(api_get_system_encoding());
  232. $worksheet->setInputEncoding($charset);
  233. /*
  234. $line = 0;
  235. $column = 1; // Skip the first column (row titles)
  236. foreach ($array as $elem) {
  237. $worksheet->write($line, $column, $elem);
  238. $column++;
  239. }
  240. $workbook->close();*/
  241. exit;
  242. }
  243. Display :: display_footer();