current_courses.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <?php
  2. $language_file = array ('registration', 'index', 'tracking', 'exercice','admin');
  3. require_once '../inc/global.inc.php';
  4. $this_section = SECTION_TRACKING;
  5. require_once api_get_path(LIBRARY_PATH).'sortabletable.class.php';
  6. require_once api_get_path(LIBRARY_PATH).'tracking.lib.php';
  7. require_once api_get_path(LIBRARY_PATH).'course.lib.php';
  8. require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
  9. require_once api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer.php';
  10. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php';
  11. $filename = 'reporting.xls';
  12. if (!api_is_allowed_to_create_course()) {
  13. api_not_allowed(true);
  14. }
  15. $user_id = api_get_user_id();
  16. $my_courses = CourseManager::get_course_list_of_user_as_course_admin($user_id);
  17. $array = array();
  18. $i = 0;
  19. $session_id = 0;
  20. if (!empty($my_courses)) {
  21. foreach ($my_courses as $course) {
  22. $course_info = api_get_course_info($course['course_code']);
  23. //Only show open courses
  24. if ($course_info['visibility'] == 0) {
  25. continue;
  26. }
  27. //$array[$i]['course'] = $course;
  28. $course_code = $course['course_code'];
  29. $course_info = api_get_course_info($course_code);
  30. //$teachers = CourseManager::get_teacher_list_from_course_code($course_code);
  31. $teacher_list = array($course_info['titular']);
  32. /*
  33. if (!empty($teachers)) {
  34. foreach($teachers as $teacher) {
  35. $teacher_list[]= $teacher['firstname'].' '.$teacher['lastname'];
  36. }
  37. }
  38. */
  39. $tmp_students = CourseManager :: get_student_list_from_course_code($course['course_code'], false);
  40. //Cleaning students only REAL students
  41. $students = array();
  42. foreach ($tmp_students as $student) {
  43. $user_info = api_get_user_info($student['user_id']);
  44. if ($user_info['status'] != STUDENT) {
  45. continue;
  46. }
  47. $students[] = $student['user_id'];
  48. }
  49. $t_lp = Database :: get_course_table(TABLE_LP_MAIN, $course_info['dbName']);
  50. $sql_lp = "SELECT lp.name, lp.id FROM $t_lp lp WHERE lp.session_id = 0";
  51. $rs_lp = Database::query($sql_lp);
  52. $t_lpi = Database :: get_course_table(TABLE_LP_ITEM, $course_info['dbName']);
  53. $t_news = Database :: get_course_table(TABLE_ANNOUNCEMENT, $course_info['dbName']);
  54. /*
  55. $total_tools_list = Tracking::get_tools_most_used_by_course($course_code, $session_id);
  56. $total_tools = 0;
  57. foreach($total_tools_list as $tool) {
  58. $total_tools += $tool['count_access_tool'];
  59. }*/
  60. if (Database :: num_rows($rs_lp) > 0) {
  61. while ($learnpath = Database :: fetch_array($rs_lp)) {
  62. $lp_id = $learnpath['id'];
  63. $lp_items =
  64. $array[$i]['lp'] = '<a href="'.api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php?cidReq='.$course_code.'&amp;action=view&amp;lp_id='.$lp_id.'" target="_blank">'.$learnpath['name'].'</a>';
  65. $array[$i]['teachers'] = '';
  66. if (!empty($teacher_list)) {
  67. $array[$i]['teachers'] = implode(', ', $teacher_list);
  68. }
  69. $array[$i]['course_name'] = $course['title'];
  70. $count_students_accessing = 0;
  71. $count_students_complete_all_activities = 0;
  72. $count_students_complete_all_activities_at_50 = 0;
  73. $total_time_spent = 0;
  74. $total_average_progress = 0;
  75. if (!empty($students)) {
  76. foreach ($students as $student_id) {
  77. $avg_student_progress = Tracking::get_avg_student_progress($student_id, $course_code, array($lp_id), $session_id);
  78. $myavg_temp = Tracking::get_avg_student_score($student_id, $course_code, array($lp_id), $session_id);
  79. $avg_progress_in_course = Tracking::get_avg_student_progress($student_id, $course_code, array($lp_id), $session_id);
  80. if (intval($avg_progress_in_course) == 100) {
  81. $count_students_complete_all_activities++;
  82. }
  83. if (intval($avg_progress_in_course) > 0 && intval($avg_progress_in_course) <= 50) {
  84. $count_students_complete_all_activities_at_50 ++;
  85. }
  86. $total_average_progress +=$avg_progress_in_course;
  87. $time_spent = Tracking::get_time_spent_on_the_course($student_id, $course_code, $session_id);
  88. $total_time_spent += $time_spent;
  89. if (!empty($time_spent)) {
  90. $count_students_accessing++;
  91. }
  92. }
  93. }
  94. $student_count = count($students);
  95. $array[$i]['count_students'] = $student_count;
  96. $array[$i]['count_students_accessing'] = 0;
  97. $array[$i]['count_students_accessing_percentage'] = 0;
  98. $array[$i]['count_students_complete_all_activities_at_50'] = 0;
  99. $array[$i]['count_students_complete_all_activities'] = 0;
  100. $array[$i]['average_percentage_activities_completed_per_student'] = 0;
  101. $array[$i]['total_time_spent'] = 0;
  102. $array[$i]['average_time_spent_per_student'] = 0;
  103. $array[$i]['total_time_spent'] = 0;
  104. $array[$i]['average_time_spent_per_student'] = 0;
  105. //$array[$i]['tools_used'] = 0;
  106. $array[$i]['learnpath_docs'] = 0;
  107. $array[$i]['learnpath_exercises'] = 0;
  108. $array[$i]['learnpath_links'] = 0;
  109. $array[$i]['learnpath_forums'] = 0;
  110. $array[$i]['learnpath_assignments'] = 0;
  111. //registering the number of each category of
  112. //items in learning path
  113. $sql_lpi = "SELECT lpi.item_type FROM $t_lpi lpi WHERE lpi.lp_id = $lp_id ORDER BY item_type";
  114. $res_lpi = Database::query($sql_lpi);
  115. while ($row_lpi = Database::fetch_array($res_lpi)) {
  116. switch($row_lpi['item_type']) {
  117. case 'document':
  118. $array[$i]['learnpath_docs']++;
  119. break;
  120. case 'quiz':
  121. $array[$i]['learnpath_exercises']++;
  122. break;
  123. case 'link':
  124. $array[$i]['learnpath_links']++;
  125. break;
  126. case 'forum':
  127. case 'thread':
  128. $array[$i]['learnpath_forums']++;
  129. break;
  130. case 'student_publication':
  131. $array[$i]['learnpath_assignments']++;
  132. break;
  133. }
  134. }
  135. // Count announcements
  136. $array[$i]['total_announcements'] = 0;
  137. $sql_news = "SELECT count(id) FROM $t_news";
  138. $res_news = Database::query($sql_news);
  139. while ($row_news = Database::fetch_array($res_news)) {
  140. $array[$i]['total_announcements'] = $row_news[0];
  141. }
  142. //@todo don't know what means this value
  143. $count_students_complete_all_activities_at_50 = 0;
  144. if (!empty($student_count)) {
  145. $array[$i]['count_students_accessing'] = $count_students_accessing;
  146. $array[$i]['count_students_accessing_percentage'] = round($count_students_accessing / $student_count *100 , 0);
  147. $array[$i]['count_students_complete_all_activities_at_50'] = $count_students_complete_all_activities;
  148. $array[$i]['count_students_complete_all_activities'] = round($count_students_complete_all_activities / $student_count *100 , 0);;
  149. $array[$i]['average_percentage_activities_completed_per_student'] = round($count_students_complete_all_activities/$student_count*100,2);
  150. $array[$i]['total_time_spent'] = 0;
  151. $array[$i]['average_time_spent_per_student'] = 0;
  152. if (!empty($total_time_spent)) {
  153. $array[$i]['total_time_spent'] = api_time_to_hms($total_time_spent);
  154. $array[$i]['average_time_spent_per_student'] = api_time_to_hms($total_time_spent / $student_count);
  155. }
  156. }
  157. $i++;
  158. }
  159. }
  160. }
  161. }
  162. $headers = array(
  163. get_lang('LearningPath'),
  164. get_lang('Teachers'),
  165. get_lang('Courses'),
  166. get_lang('NumberOfStudents'),
  167. get_lang('NumberStudentsAccessingCourse'),
  168. get_lang('PercentageStudentsAccessingCourse'),
  169. get_lang('NumberStudentsCompleteAllActivities'),
  170. get_lang('PercentageStudentsCompleteAllActivities'),
  171. get_lang('AverageOfActivitiesCompletedPerStudent'),
  172. get_lang('TotalTimeSpentInTheCourse'),
  173. get_lang('AverageTimePerStudentInCourse'),
  174. get_lang('NumberOfDocumentsInLearnpath'),
  175. get_lang('NumberOfExercisesInLearnpath'),
  176. get_lang('NumberOfLinksInLearnpath'),
  177. get_lang('NumberOfForumsInLearnpath'),
  178. get_lang('NumberOfAssignmentsInLearnpath'),
  179. get_lang('NumberOfAnnouncementsInCourse'),
  180. );
  181. if (isset($_GET['export'])) {
  182. global $charset;
  183. $workbook = new Spreadsheet_Excel_Writer();
  184. $workbook ->setTempDir(api_get_path(SYS_ARCHIVE_PATH));
  185. $workbook->send($filename);
  186. $workbook->setVersion(8); // BIFF8
  187. $worksheet =& $workbook->addWorksheet('Report');
  188. //$worksheet->setInputEncoding(api_get_system_encoding());
  189. $worksheet->setInputEncoding($charset);
  190. $line = 0;
  191. $column = 0; //skip the first column (row titles)
  192. foreach($headers as $header) {
  193. $worksheet->write($line,$column, $header);
  194. $column++;
  195. }
  196. $line++;
  197. foreach ($array as $row) {
  198. $column = 0;
  199. foreach ($row as $item) {
  200. $worksheet->write($line,$column,html_entity_decode(strip_tags($item)));
  201. $column++;
  202. }
  203. $line++;
  204. }
  205. $line++;
  206. $workbook->close();
  207. exit;
  208. }
  209. Display::display_header();
  210. if (!class_exists('HTML_Table')) {
  211. require_once api_get_path(LIBRARY_PATH).'pear/HTML/Table.php';
  212. }
  213. $table = new HTML_Table(array('class' => 'data_table'));
  214. $row = 0;
  215. $column = 0;
  216. foreach ($headers as $header) {
  217. $table->setHeaderContents($row, $column, $header);
  218. $column++;
  219. }
  220. $row++;
  221. foreach ($array as $row_table) {
  222. $column = 0;
  223. foreach ($row_table as $cell) {
  224. $table->setCellContents($row, $column, $cell);
  225. $table->updateCellAttributes($row, $column, 'align="center"');
  226. $column++;
  227. }
  228. $table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true);
  229. $row++;
  230. }
  231. echo '<div class="actions">';
  232. echo '<a href="'.api_get_path(WEB_CODE_PATH).'mySpace"><img align="absbottom" src="../img/back.png">&nbsp;'.get_lang('Back').'</a> ';
  233. echo '<a href="'.api_get_path(WEB_CODE_PATH).'mySpace/current_courses.php?export=1"><img align="absbottom" src="../img/excel.gif">&nbsp;'.get_lang('CurrentCoursesReport').'</a> ';
  234. echo '</div>';
  235. echo $table->toHtml();
  236. Display::display_footer();