my_progress.php 13 KB

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