course_session_report.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. $form->addElement('select', 'session_id', get_lang('Sessions'), $my_session_list);
  47. $form->addElement('submit','submit',get_lang('Filter'));
  48. if (!empty($_REQUEST['score'])) $filter_score = intval($_REQUEST['score']); else $filter_score = 70;
  49. if (!empty($_REQUEST['session_id'])) $session_id = intval($_REQUEST['session_id']); else $session_id = 0;
  50. if (empty($session_id)) {
  51. $session_id = key($my_session_list);
  52. }
  53. $form->setDefaults(array('session_id'=>$session_id));
  54. $course_list = SessionManager::get_course_list_by_session_id($session_id);
  55. if (!$export_to_xls) {
  56. Display :: display_header(get_lang("MySpace"));
  57. echo '<div class="actions">';
  58. if ($global) {
  59. $menu_items[] = '<a href="'.api_get_path(WEB_CODE_PATH).'mySpace/?view=teacher">'.get_lang('TeacherInterface').'</a>';
  60. $menu_items[] = get_lang('AdminInterface');
  61. $nb_menu_items = count($menu_items);
  62. if($nb_menu_items>1) {
  63. foreach($menu_items as $key=> $item) {
  64. echo $item;
  65. if($key!=$nb_menu_items-1) {
  66. echo ' | ';
  67. }
  68. }
  69. echo '<br />';
  70. }
  71. } else {
  72. echo '<div style="float:left; clear:left">
  73. <a href="courseLog.php?'.api_get_cidreq().'&studentlist=true">'.get_lang('StudentsTracking').'</a>&nbsp;|
  74. <a href="courseLog.php?'.api_get_cidreq().'&studentlist=false">'.get_lang('CourseTracking').'</a>&nbsp;';
  75. echo '</div>';
  76. }
  77. echo '</div>';
  78. echo '<h4>'.get_lang('CoachList').'</h4>';
  79. if (api_is_platform_admin()) {
  80. echo '<a href="'.api_get_path(WEB_CODE_PATH).'mySpace/?view=admin&amp;display=coaches">'.get_lang('DisplayCoaches').'</a> | ';
  81. echo '<a href="'.api_get_path(WEB_CODE_PATH).'mySpace/?view=admin&amp;display=useroverview">'.get_lang('DisplayUserOverview').'</a>';
  82. echo ' | <a href="'.api_get_path(WEB_CODE_PATH).'mySpace/?view=admin&amp;display=sessionoverview">'.get_lang('DisplaySessionOverview').'</a>';
  83. echo ' | <a href="'.api_get_path(WEB_CODE_PATH).'mySpace/?view=admin&amp;display=courseoverview">'.get_lang('DisplayCourseOverview').'</a>';
  84. echo ' | <a href="'.api_get_path(WEB_CODE_PATH).'tracking/question_course_report.php?view=admin">'.get_lang('LPQuestionListResults').'</a>';
  85. echo ' | '.get_lang('LPExerciseResultsBySession').'';
  86. }
  87. echo '<h2>'.get_lang('LPExerciseResultsBySession').'</h2>';
  88. $form->display();
  89. Display::display_normal_message(get_lang('StudentScoreAverageIsCalculatedBaseInAllLPsAndAllAttempts'));
  90. //echo '<h3>'.sprintf(get_lang('FilteringWithScoreX'), $filter_score).'%</h3>';
  91. // 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 />';
  92. }
  93. $users = SessionManager::get_users_by_session($session_id);
  94. $course_average = $course_average_counter = array();
  95. $counter = 0;
  96. $main_result = array();
  97. //Getting course list
  98. foreach($course_list as $current_course ) {
  99. $course_info = api_get_course_info($current_course['code']);
  100. $_course = $course_info;
  101. $attempt_result = array();
  102. //Getting LP list
  103. $list = new learnpathList('', $current_course['code'], $session_id);
  104. $lp_list = $list->get_flat_list();
  105. // Looping LPs
  106. foreach ($lp_list as $lp_id =>$lp) {
  107. $exercise_list = get_all_exercises_from_lp($lp_id, $current_course['db_name']);
  108. //Looping Chamilo Exercises in LP
  109. foreach ($exercise_list as $exercise) {
  110. $exercise_stats = get_all_exercise_event_from_lp($exercise['path'],$course_info['id'], $session_id);
  111. //Looping Exercise Attempts
  112. foreach($exercise_stats as $stats) {
  113. $attempt_result[$stats['exe_user_id']]['result'] += $stats['exe_result'] / $stats['exe_weighting'];
  114. $attempt_result[$stats['exe_user_id']]['attempts']++;
  115. }
  116. }
  117. }
  118. $main_result[$current_course['code']] = $attempt_result;
  119. }
  120. //var_dump($main_result);
  121. $total_average_score = 0;
  122. $total_average_score_count = 0;
  123. if (!empty($users) && is_array($users)) {
  124. $html_result .= '<table class="data_table">';
  125. $html_result .= '<tr><th>'.get_lang('User').'</th>';
  126. foreach($course_list as $item ) {
  127. $html_result .= '<th>'.$item['title'].'<br /> '.get_lang('AverageScore').' %</th>';
  128. }
  129. $html_result .= '<th>'.get_lang('AverageScore').' %</th>';
  130. $html_result .= '<th>'.get_lang('LastConnexionDate').'</th></tr>';
  131. foreach ($users as $user) {
  132. $total_student = 0;
  133. $counter ++;
  134. $s_css_class = 'row_even';
  135. if ($counter % 2 ==0 ) {
  136. $s_css_class = 'row_odd';
  137. }
  138. $html_result .= "<tr class='$s_css_class'>
  139. <td >";
  140. $html_result .= $user['firstname'].' '.$user['lastname'];
  141. $html_result .= "</td>";
  142. //Getting course list
  143. $counter = 0;
  144. $total_result_by_user = 0;
  145. foreach($course_list as $current_course ) {
  146. $total_course = 0;
  147. $user_info_stat = $main_result[$current_course['code']][$user['user_id']];
  148. $html_result .= "<td align=\"center\" >";
  149. if (!empty($user_info_stat['result']) && !empty($user_info_stat['attempts'])) {
  150. $result =round($user_info_stat['result']/$user_info_stat['attempts'] * 100, 2);
  151. $total_course +=$result;
  152. $total_result_by_user +=$result;
  153. $course_average[$current_course['code']] += $total_course;
  154. $course_average_counter[$current_course['code']]++;
  155. $result = $result .' ('.$user_info_stat['attempts'].' '.get_lang('Attempts').')';
  156. $counter++;
  157. } else {
  158. $result = '-';
  159. }
  160. $html_result .= $result;
  161. $html_result .= "</td>";
  162. }
  163. if (empty($counter)) {
  164. $total_student = '-';
  165. } else {
  166. $total_student = $total_result_by_user/$counter;
  167. $total_average_score+=$total_student;
  168. $total_average_score_count++;
  169. }
  170. $string_date=Tracking :: get_last_connection_date($user['user_id'],true);
  171. $html_result .="<td align=\"center\">$total_student</td><td>$string_date</td></tr>";
  172. }
  173. $html_result .="<tr><th>".get_lang('AverageScore')."</th>";
  174. $total_average = 0;
  175. $counter = 0;
  176. foreach($course_list as $course_item) {
  177. if (!empty($course_average_counter[$course_item['code']])) {
  178. $average_per_course = round($course_average[$course_item['code']]/($course_average_counter[$course_item['code']]*100)*100,2);
  179. } else {
  180. $average_per_course = '-';
  181. }
  182. if (!empty($average_per_course)) {
  183. $counter++;
  184. }
  185. $total_average = $total_average + $average_per_course;
  186. $html_result .="<td align=\"center\">$average_per_course</td>";
  187. }
  188. if (!empty($total_average_score_count)) {
  189. $total_average = round($total_average_score/($total_average_score_count*100)*100,2);
  190. } else {
  191. $total_average = '-';
  192. }
  193. $html_result .='<td align="center">'.$total_average.'</td>';
  194. $html_result .="<td>-</td>";
  195. $html_result .="</tr>";
  196. $html_result .= '</table>';
  197. } else {
  198. Display::display_warning_message(get_lang('NoResults'));
  199. }
  200. if (!$export_to_xls) {
  201. echo $html_result;
  202. }
  203. $filename = 'exam-reporting-'.date('Y-m-d-h:i:s').'.xls';
  204. if ($export_to_xls) {
  205. echo $html_result;
  206. export_complete_report_xls($filename, $export_array);
  207. exit;
  208. }
  209. function sort_user($a, $b) {
  210. if (is_numeric($a['score']) && is_numeric($b['score'])) {
  211. echo $a['score'].' : '.$b['score'];
  212. echo '<br />';
  213. if ($a['score'] < $b['score']) {
  214. return 1;
  215. }
  216. return 0;
  217. }
  218. return 1;
  219. }
  220. function export_complete_report_xls($filename, $array) {
  221. global $charset;
  222. $workbook = new Spreadsheet_Excel_Writer();
  223. $workbook ->setTempDir(api_get_path(SYS_ARCHIVE_PATH));
  224. $workbook->send($filename);
  225. $workbook->setVersion(8); // BIFF8
  226. $worksheet =& $workbook->addWorksheet('Report');
  227. //$worksheet->setInputEncoding(api_get_system_encoding());
  228. $worksheet->setInputEncoding($charset);
  229. /*
  230. $line = 0;
  231. $column = 1; // Skip the first column (row titles)
  232. foreach ($array as $elem) {
  233. $worksheet->write($line, $column, $elem);
  234. $column++;
  235. }
  236. $workbook->close();*/
  237. exit;
  238. }
  239. Display :: display_footer();