my_progress.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. // name of the language file that needs to be included
  4. $language_file = array('registration', 'tracking', 'exercice', 'admin');
  5. $cidReset = true;
  6. require_once '../inc/global.inc.php';
  7. require_once api_get_path(LIBRARY_PATH).'tracking.lib.php';
  8. require_once api_get_path(LIBRARY_PATH).'course.lib.php';
  9. require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
  10. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php';
  11. $this_section = SECTION_TRACKING;
  12. $nameTools = get_lang('MyProgress');
  13. api_block_anonymous_users();
  14. Display :: display_header($nameTools);
  15. // Database table definitions
  16. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  17. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  18. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  19. $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  20. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  21. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  22. $tbl_stats_lastaccess = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
  23. $tbl_stats_exercices = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  24. $tbl_course_lp_view = Database :: get_course_table(TABLE_LP_VIEW);
  25. $tbl_course_lp_view_item = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  26. $tbl_course_lp = Database :: get_course_table(TABLE_LP_MAIN);
  27. $tbl_course_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  28. $tbl_course_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
  29. // get course list
  30. $sql = 'SELECT course_code FROM '.$tbl_course_user.' WHERE user_id='.intval($_user['user_id']).' AND relation_type<>'.COURSE_RELATION_TYPE_RRHH.' ';
  31. $rs = Database::query($sql);
  32. $courses = array();
  33. while($row = Database :: fetch_array($rs)) {
  34. $courses[$row['course_code']] = CourseManager::get_course_information($row['course_code']);
  35. }
  36. // get the list of sessions where the user is subscribed as student
  37. $sql = 'SELECT DISTINCT course_code FROM '.Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER).' WHERE id_user='.intval($_user['user_id']);
  38. $rs = Database::query($sql);
  39. while($row = Database :: fetch_array($rs)) {
  40. $courses[$row['course_code']] = CourseManager::get_course_information($row['course_code']);
  41. }
  42. echo '<div class="actions-title" >';
  43. echo $nameTools;
  44. echo '</div>';
  45. $now = date('Y-m-d');
  46. ?>
  47. <table class="data_table" width="100%">
  48. <tr class="tableName">
  49. <td colspan="6">
  50. <strong><?php echo get_lang('MyCourses'); ?></strong>
  51. </td>
  52. </tr>
  53. <tr>
  54. <th><?php echo get_lang('Course'); ?></th>
  55. <th><?php echo get_lang('Time'); ?></th>
  56. <th><?php echo get_lang('Progress'); ?></th>
  57. <th><?php echo get_lang('Score'); Display :: display_icon('info3.gif', get_lang('ScormAndLPTestTotalAverage'), array ('align' => 'absmiddle', 'hspace' => '3px')); ?></th>
  58. <th><?php echo get_lang('LastConnexion'); ?></th>
  59. <th><?php echo get_lang('Details'); ?></th>
  60. </tr>
  61. <?php
  62. $i = 0;
  63. foreach ($courses as $enreg) {
  64. $weighting = 0;
  65. $last_connection = Tracking :: get_last_connection_date_on_the_course($_user['user_id'], $enreg['code']);
  66. $progress = Tracking :: get_avg_student_progress($_user['user_id'], $enreg['code']);
  67. $total_time_login = Tracking :: get_time_spent_on_the_course($_user['user_id'], $enreg['code']);
  68. $time = api_time_to_hms($total_time_login);
  69. $percentage_score = Tracking :: get_average_test_scorm_and_lp ($_user['user_id'], $enreg['code']);
  70. ?>
  71. <tr class='<?php echo $i?'row_odd':'row_even'; ?>'>
  72. <td>
  73. <?php echo api_html_entity_decode($enreg['title'], ENT_QUOTES, api_get_system_encoding()); ?>
  74. </td>
  75. <td align='center'>
  76. <?php echo $time; ?>
  77. </td>
  78. <td align='center'>
  79. <?php echo $progress.'%'; ?>
  80. </td>
  81. <td align='center'>
  82. <?php
  83. if (!is_null($percentage_score)) {
  84. echo $percentage_score.'%';
  85. } else {
  86. echo '0%';
  87. }
  88. ?>
  89. </td>
  90. <td align='center' >
  91. <?php echo $last_connection; ?>
  92. </td>
  93. <td align='center'>
  94. <?php
  95. if ($enreg['code'] == $_GET['course']) {
  96. echo '<a href="#">';
  97. Display::display_icon('2rightarrow_na.gif', get_lang('Details'));
  98. } else {
  99. echo '<a href="'.api_get_self().'?course='.$enreg['code'].'">';
  100. Display::display_icon('2rightarrow.gif', get_lang('Details'));
  101. }
  102. echo '</a>';
  103. ?>
  104. </td>
  105. </tr>
  106. <?php
  107. $i = $i ? 0 : 1;
  108. }
  109. ?>
  110. </table>
  111. <br /><br />
  112. <?php
  113. /*
  114. * Details for one course
  115. *
  116. */
  117. if (isset($_GET['course'])) {
  118. $course = Database::escape_string($_GET['course']);
  119. $course_info = CourseManager::get_course_information($course);
  120. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  121. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  122. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  123. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  124. $tbl_course_lp_view = Database :: get_course_table(TABLE_LP_VIEW, $course_info['db_name']);
  125. $tbl_course_lp_view_item = Database :: get_course_table(TABLE_LP_ITEM_VIEW, $course_info['db_name']);
  126. $tbl_course_lp = Database :: get_course_table(TABLE_LP_MAIN, $course_info['db_name']);
  127. $tbl_course_lp_item = Database :: get_course_table(TABLE_LP_ITEM, $course_info['db_name']);
  128. $tbl_course_quiz = Database :: get_course_table(TABLE_QUIZ_TEST, $course_info['db_name']);
  129. //get coach and session_name if there is one and if session_mode is activated
  130. if (api_get_setting('use_session_mode') == 'true') {
  131. $sql = 'SELECT id_session
  132. FROM '.$tbl_session_course_user.' session_course_user
  133. WHERE session_course_user.id_user = '.intval($_user['user_id']).'
  134. AND session_course_user.course_code = "'.Database::escape_string($course).'"
  135. ORDER BY id_session DESC';
  136. $rs = Database::query($sql);
  137. $row = Database::fetch_array($rs);
  138. if (!empty($row[0])) {
  139. $session_id = intval($row[0]);
  140. }
  141. //$session_id = intval(Database::result($rs, 0, 0));
  142. if ($session_id > 0) {
  143. // get session name and coach of the session
  144. $sql = 'SELECT name, id_coach FROM '.$tbl_session.'
  145. WHERE id='.$session_id;
  146. $rs = Database::query($sql);
  147. $session_name = Database::result($rs, 0, 'name');
  148. $session_coach_id = intval(Database::result($rs, 0, 'id_coach'));
  149. $sql = 'SELECT id_user FROM ' . $tbl_session_course_user . '
  150. WHERE id_session=' . $session_id . '
  151. AND course_code = "' . Database :: escape_string($course) . '" AND status=2';
  152. $rs = Database::query($sql);
  153. $course_coachs = array();
  154. while ($row_coachs = Database::fetch_array($rs)) {
  155. $course_coachs[] = $row_coachs['id_user'];
  156. }
  157. if (!empty($course_coachs)) {
  158. $info_tutor_name = array();
  159. foreach ($course_coachs as $course_coach) {
  160. $coach_infos = UserManager :: get_user_info_by_id($course_coach);
  161. $info_tutor_name[] = api_get_person_name($coach_infos['firstname'], $coach_infos['lastname']);
  162. }
  163. $course_info['tutor_name'] = implode(",",$info_tutor_name);
  164. } else if($session_coach_id != 0) {
  165. $coach_info = UserManager :: get_user_info_by_id($session_coach_id);
  166. $course_info['tutor_name'] = api_get_person_name($coach_info['firstname'], $coach_info['lastname']);
  167. }
  168. }
  169. } // end if (api_get_setting('use_session_mode') == 'true')
  170. $tableTitle = $course_info['title'].' | '.get_lang('Coach').' : '.$course_info['tutor_name'].((!empty($session_name)) ? ' | '.get_lang('Session').' : '.$session_name : '');
  171. ?>
  172. <table class="data_table" width="100%">
  173. <tr class="tableName">
  174. <td colspan="4">
  175. <strong><?php echo $tableTitle; ?></strong>
  176. </td>
  177. </tr>
  178. <tr>
  179. <th class="head" style="color:#000"><?php echo get_lang('Learnpath'); ?></th>
  180. <th class="head" style="color:#000"><?php echo get_lang('Time'); ?></th>
  181. <th class="head" style="color:#000"><?php echo get_lang('Progress'); ?></th>
  182. <th class="head" style="color:#000"><?php echo get_lang('LastConnexion'); ?></th>
  183. </tr>
  184. <?php
  185. $sql_learnpath = "SELECT lp.name,lp.id FROM ".$tbl_course_lp." AS lp ORDER BY lp.display_order";
  186. $result_learnpath = Database::query($sql_learnpath);
  187. if (Database::num_rows($result_learnpath) > 0) {
  188. while($learnpath = Database::fetch_array($result_learnpath)) {
  189. $progress = learnpath :: get_db_progress($learnpath['id'], $_user['user_id'], '%', $course_info['db_name']);
  190. // calculates last connection time
  191. $sql = 'SELECT MAX(start_time)
  192. FROM '.$tbl_course_lp_view_item.' AS item_view
  193. INNER JOIN '.$tbl_course_lp_view.' AS view
  194. ON item_view.lp_view_id = view.id
  195. AND view.lp_id = '.$learnpath['id'].'
  196. AND view.user_id = '.$_user['user_id'];
  197. $rs = Database::query($sql);
  198. $start_time = Database::result($rs, 0, 0);
  199. // calculates time
  200. $sql = 'SELECT SUM(total_time)
  201. FROM '.$tbl_course_lp_view_item.' AS item_view
  202. INNER JOIN '.$tbl_course_lp_view.' AS view
  203. ON item_view.lp_view_id = view.id
  204. AND view.lp_id = '.$learnpath['id'].'
  205. AND view.user_id = '.$_user['user_id'];
  206. $rs = Database::query($sql);
  207. $total_time = Database::result($rs, 0, 0);
  208. echo "<tr>
  209. <td>
  210. ";
  211. echo stripslashes($learnpath['name']);
  212. echo " </td>
  213. <td align='center'>
  214. ";
  215. echo api_time_to_hms($total_time);
  216. echo " </td>
  217. <td align='center'>
  218. ";
  219. echo $progress;
  220. echo " </td>
  221. <td align='center' width=180px >
  222. ";
  223. $last_connection_in_lp = Tracking::get_last_connection_time_in_lp($_user['user_id'], $course, $learnpath['id']);
  224. if (!empty($last_connection_in_lp)) {
  225. echo api_get_utc_datetime($last_connection_in_lp);
  226. } else {
  227. echo '-';
  228. }
  229. echo " </td>
  230. </tr>
  231. ";
  232. }
  233. } else {
  234. echo ' <tr>
  235. <td colspan="4" align="center">
  236. '.get_lang('NoLearnpath').'
  237. </td>
  238. </tr>
  239. ';
  240. }
  241. ?>
  242. <?php
  243. // This code was commented on purpose see BT#924
  244. /*$sql = 'SELECT visibility FROM '.$course_info['db_name'].'.'.TABLE_TOOL_LIST.' WHERE name="quiz"';
  245. $result_visibility_tests = Database::query($sql);
  246. if (Database::result($result_visibility_tests, 0, 'visibility') == 1) {*/
  247. $sql_exercices = " SELECT quiz.title,id, results_disabled
  248. FROM ".$tbl_course_quiz." AS quiz
  249. WHERE active='1'";
  250. echo '<tr>
  251. <th class="head" style="color:#000">'.get_lang('Exercices').'</th>
  252. <th class="head" style="color:#000">'.get_lang('Score').'</th>
  253. <th class="head" style="color:#000">'.get_lang('Attempts').'</th>
  254. <th class="head" style="color:#000">'.get_lang('Details').'</th>
  255. </tr>';
  256. $result_exercices = Database::query($sql_exercices);
  257. if (Database::num_rows($result_exercices) > 0) {
  258. while ($exercices = Database::fetch_array($result_exercices)) {
  259. $sql_essais = " SELECT COUNT(ex.exe_id) as essais
  260. FROM $tbl_stats_exercices AS ex
  261. WHERE ex.exe_user_id='".$_user['user_id']."' AND ex.exe_cours_id = '".$course_info['code']."'
  262. AND ex.exe_exo_id = ".$exercices['id']."
  263. AND orig_lp_id = 0
  264. AND orig_lp_item_id = 0 "
  265. ;
  266. $result_essais = Database::query($sql_essais);
  267. $essais = Database::fetch_array($result_essais);
  268. $sql_score = "SELECT exe_id , exe_result,exe_weighting
  269. FROM $tbl_stats_exercices
  270. WHERE exe_user_id = ".$_user['user_id']."
  271. AND exe_cours_id = '".$course_info['code']."'
  272. AND exe_exo_id = ".$exercices['id']."
  273. AND orig_lp_id = 0
  274. AND orig_lp_item_id = 0
  275. ORDER BY exe_date DESC LIMIT 1";
  276. $result_score = Database::query($sql_score);
  277. $score = 0;
  278. while($current_score = Database::fetch_array($result_score)) {
  279. $score = $score + $current_score['exe_result'];
  280. $weighting = $weighting + $current_score['exe_weighting'];
  281. $exe_id = $current_score['exe_id'];
  282. }
  283. if ($weighting > 0) {
  284. // i.e 10.50%
  285. $percentage_score = round(($score * 100) / $weighting, 2);
  286. } else {
  287. $percentage_score = 0;
  288. }
  289. $weighting = 0;
  290. echo '<tr>
  291. <td>';
  292. echo $exercices['title'];
  293. echo '</td>';
  294. if ($exercices['results_disabled'] == 0) {
  295. echo '<td align="center">';
  296. if ($essais['essais'] > 0) {
  297. echo $percentage_score.'%';
  298. } else {
  299. echo '/';
  300. }
  301. echo '</td>';
  302. echo '<td align="center">';
  303. echo $essais['essais'];
  304. echo '</td>
  305. <td align="center" width="25">';
  306. if ($essais['essais'] > 0) {
  307. echo '<a href="../exercice/exercise_show.php?origin=myprogress&id='.$exe_id.'&cidReq='.$course_info['code'].'&id_session='.Security::remove_XSS($_GET['id_session']).'"> '.Display::return_icon('quiz.gif', get_lang('Quiz')).' </a>';
  308. }
  309. echo '</td>';
  310. } else {
  311. // we show or not the results if the teacher wants to
  312. echo '<td align="center">';
  313. echo get_lang('CantShowResults');
  314. echo '</td>';
  315. echo '<td align="center">';
  316. echo ' -- ';
  317. echo '</td>
  318. <td align="center" width="25">';
  319. echo ' -- ';
  320. echo '</td>';
  321. }
  322. echo '</tr>';
  323. }
  324. } else {
  325. echo '<tr><td colspan="4" align="center">'.get_lang('NoEx').'</td></tr>';
  326. }
  327. /*} else {
  328. echo '<tr><td colspan="4">'.get_lang('NoEx').'</td></tr>';
  329. }*/
  330. ?>
  331. </table>
  332. <?php
  333. }
  334. Display :: display_footer();