my_progress.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <?php
  2. /* For licensing terms, see /dokeos_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']);
  31. $rs = Database::query($sql, __FILE__, __LINE__);
  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, __FILE__, __LINE__);
  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. * **********************************************************************************************
  115. *
  116. * Details for one course
  117. *
  118. * **********************************************************************************************
  119. */
  120. if (isset($_GET['course'])) {
  121. $course = Database::escape_string($_GET['course']);
  122. $course_info = CourseManager::get_course_information($course);
  123. //get coach and session_name if there is one and if session_mode is activated
  124. if (api_get_setting('use_session_mode') == 'true') {
  125. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  126. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  127. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  128. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  129. $sql = 'SELECT id_session
  130. FROM '.$tbl_session_course_user.' session_course_user
  131. WHERE session_course_user.id_user = '.intval($_user['user_id']).'
  132. AND session_course_user.course_code = "'.Database::escape_string($course).'"
  133. ORDER BY id_session DESC';
  134. $rs = Database::query($sql, __FILE__, __LINE__);
  135. $row = Database::fetch_array($rs);
  136. if (!empty($row[0])) {
  137. $session_id = intval($row[0]);
  138. }
  139. //$session_id = intval(Database::result($rs, 0, 0));
  140. if ($session_id > 0) {
  141. // get session name and coach of the session
  142. $sql = 'SELECT name, id_coach FROM '.$tbl_session.'
  143. WHERE id='.$session_id;
  144. $rs = Database::query($sql, __FILE__, __LINE__);
  145. $session_name = Database::result($rs, 0, 'name');
  146. $session_coach_id = intval(Database::result($rs, 0, 'id_coach'));
  147. $sql = 'SELECT id_user FROM ' . $tbl_session_course_user . '
  148. WHERE id_session=' . $session_id . '
  149. AND course_code = "' . Database :: escape_string($course) . '" AND status=2';
  150. $rs = Database::query($sql, __FILE__, __LINE__);
  151. $course_coachs = array();
  152. while ($row_coachs = Database::fetch_array($rs)) {
  153. $course_coachs[] = $row_coachs['id_user'];
  154. }
  155. if (!empty($course_coachs)) {
  156. $info_tutor_name = array();
  157. foreach ($course_coachs as $course_coach) {
  158. $coach_infos = UserManager :: get_user_info_by_id($course_coach);
  159. $info_tutor_name[] = api_get_person_name($coach_infos['firstname'], $coach_infos['lastname']);
  160. }
  161. $course_info['tutor_name'] = implode(",",$info_tutor_name);
  162. } else if($session_coach_id != 0) {
  163. $coach_info = UserManager :: get_user_info_by_id($session_coach_id);
  164. $course_info['tutor_name'] = api_get_person_name($coach_info['firstname'], $coach_info['lastname']);
  165. }
  166. }
  167. } // end if (api_get_setting('use_session_mode') == 'true')
  168. $tableTitle = $course_info['title'].' | '.get_lang('Coach').' : '.$course_info['tutor_name'].((!empty($session_name)) ? ' | '.get_lang('Session').' : '.$session_name : '');
  169. ?>
  170. <table class="data_table" width="100%">
  171. <tr class="tableName">
  172. <td colspan="4">
  173. <strong><?php echo $tableTitle; ?></strong>
  174. </td>
  175. </tr>
  176. <tr>
  177. <th class="head" style="color:#000"><?php echo get_lang('Learnpath'); ?></th>
  178. <th class="head" style="color:#000"><?php echo get_lang('Time'); ?></th>
  179. <th class="head" style="color:#000"><?php echo get_lang('Progress'); ?></th>
  180. <th class="head" style="color:#000"><?php echo get_lang('LastConnexion'); ?></th>
  181. </tr>
  182. <?php
  183. $sql_learnpath = "SELECT lp.name,lp.id FROM ".$course_info['db_name'].".".$tbl_course_lp." AS lp";
  184. $result_learnpath = Database::query($sql_learnpath, __FILE__, __LINE__);
  185. if (Database::num_rows($result_learnpath) > 0) {
  186. while($learnpath = Database::fetch_array($result_learnpath)) {
  187. $progress = learnpath :: get_db_progress($learnpath['id'], $_user['user_id'], '%', $course_info['db_name']);
  188. // calculates last connection time
  189. $sql = 'SELECT MAX(start_time)
  190. FROM '.$course_info['db_name'].'.'.$tbl_course_lp_view_item.' AS item_view
  191. INNER JOIN '.$course_info['db_name'].'.'.$tbl_course_lp_view.' AS view
  192. ON item_view.lp_view_id = view.id
  193. AND view.lp_id = '.$learnpath['id'].'
  194. AND view.user_id = '.$_user['user_id'];
  195. $rs = Database::query($sql, __FILE__, __LINE__);
  196. $start_time = Database::result($rs, 0, 0);
  197. // calculates time
  198. $sql = 'SELECT SUM(total_time)
  199. FROM '.$course_info['db_name'].'.'.$tbl_course_lp_view_item.' AS item_view
  200. INNER JOIN '.$course_info['db_name'].'.'.$tbl_course_lp_view.' AS view
  201. ON item_view.lp_view_id = view.id
  202. AND view.lp_id = '.$learnpath['id'].'
  203. AND view.user_id = '.$_user['user_id'];
  204. $rs = Database::query($sql, __FILE__, __LINE__);
  205. $total_time = Database::result($rs, 0, 0);
  206. echo "<tr>
  207. <td>
  208. ";
  209. echo stripslashes($learnpath['name']);
  210. echo " </td>
  211. <td align='center'>
  212. ";
  213. echo api_time_to_hms($total_time);
  214. echo " </td>
  215. <td align='center'>
  216. ";
  217. echo $progress;
  218. echo " </td>
  219. <td align='center' width=180px >
  220. ";
  221. if ($start_time != '') {
  222. echo $last_connection;
  223. } else {
  224. echo '-';
  225. }
  226. echo " </td>
  227. </tr>
  228. ";
  229. }
  230. } else {
  231. echo " <tr>
  232. <td colspan='4'>
  233. ".get_lang('NoLearnpath')."
  234. </td>
  235. </tr>
  236. ";
  237. }
  238. ?>
  239. <tr>
  240. <th class="head" style="color:#000"><?php echo get_lang('Exercices'); ?></th>
  241. <th class="head" style="color:#000"><?php echo get_lang('Score'); ?></th>
  242. <th class="head" style="color:#000"><?php echo get_lang('Attempts'); ?></th>
  243. <th class="head" style="color:#000"><?php echo get_lang('Details'); ?></th>
  244. </tr>
  245. <?php
  246. $sql = 'SELECT visibility FROM '.$course_info['db_name'].'.'.TABLE_TOOL_LIST.' WHERE name="quiz"';
  247. $result_visibility_tests = Database::query($sql, __FILE__, __LINE__);
  248. if (Database::result($result_visibility_tests, 0, 'visibility') == 1) {
  249. $sql_exercices = " SELECT quiz.title,id, results_disabled
  250. FROM ".$course_info['db_name'].".".$tbl_course_quiz." AS quiz
  251. WHERE active='1'";
  252. $result_exercices = Database::query($sql_exercices, __FILE__, __LINE__);
  253. if (Database::num_rows($result_exercices) > 0) {
  254. while ($exercices = Database::fetch_array($result_exercices)) {
  255. $sql_essais = " SELECT COUNT(ex.exe_id) as essais
  256. FROM $tbl_stats_exercices AS ex
  257. WHERE ex.exe_user_id='".$_user['user_id']."' AND ex.exe_cours_id = '".$course_info['code']."'
  258. AND ex.exe_exo_id = ".$exercices['id']."
  259. AND orig_lp_id = 0
  260. AND orig_lp_item_id = 0 "
  261. ;
  262. $result_essais = Database::query($sql_essais , __FILE__, __LINE__);
  263. $essais = Database::fetch_array($result_essais);
  264. $sql_score = "SELECT exe_id , exe_result,exe_weighting
  265. FROM $tbl_stats_exercices
  266. WHERE exe_user_id = ".$_user['user_id']."
  267. AND exe_cours_id = '".$course_info['code']."'
  268. AND exe_exo_id = ".$exercices['id']."
  269. AND orig_lp_id = 0
  270. AND orig_lp_item_id = 0
  271. ORDER BY exe_date DESC LIMIT 1";
  272. $result_score = Database::query($sql_score, __FILE__, __LINE__);
  273. $score = 0;
  274. while($current_score = Database::fetch_array($result_score)) {
  275. $score = $score + $current_score['exe_result'];
  276. $weighting = $weighting + $current_score['exe_weighting'];
  277. $exe_id = $current_score['exe_id'];
  278. }
  279. if ($weighting > 0) {
  280. // i.e 10.50%
  281. $percentage_score = round(($score * 100) / $weighting, 2);
  282. } else {
  283. $percentage_score = 0;
  284. }
  285. $weighting = 0;
  286. echo '<tr>
  287. <td>';
  288. echo $exercices['title'];
  289. echo '</td>';
  290. if ($exercices['results_disabled'] == 0) {
  291. echo '<td align="center">';
  292. if ($essais['essais'] > 0) {
  293. echo $percentage_score.'%';
  294. } else {
  295. echo '/';
  296. }
  297. echo '</td>';
  298. echo '<td align="center">';
  299. echo $essais['essais'];
  300. echo '</td>
  301. <td align="center" width="25">';
  302. if ($essais['essais'] > 0) {
  303. 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>';
  304. }
  305. echo '</td>';
  306. } else {
  307. // we show or not the results if the teacher wants to
  308. echo '<td align="center">';
  309. echo get_lang('CantShowResults');
  310. echo '</td>';
  311. echo '<td align="center">';
  312. echo ' -- ';
  313. echo '</td>
  314. <td align="center" width="25">';
  315. echo ' -- ';
  316. echo '</td>';
  317. }
  318. echo '</tr>';
  319. }
  320. } else {
  321. echo '<tr><td colspan="4">'.get_lang('NoEx').'</td></tr>';
  322. }
  323. } else {
  324. echo '<tr><td colspan="4">'.get_lang('NoEx').'</td></tr>';
  325. }
  326. ?>
  327. </table>
  328. <?php
  329. }
  330. Display :: display_footer();