my_progress.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. <?php
  2. // name of the language file that needs to be included
  3. $language_file = array('registration','tracking','exercice');
  4. $cidReset = true;
  5. require ('../inc/global.inc.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 ('../newscorm/learnpath.class.php');
  10. $nameTools=get_lang('MyProgress');
  11. $this_section = 'session_my_progress';
  12. api_block_anonymous_users();
  13. Display :: display_header($nameTools);
  14. // Database table definitions
  15. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  16. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  17. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  18. $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  19. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  20. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  21. $tbl_stats_lastaccess = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
  22. $tbl_stats_exercices = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  23. $tbl_course_lp_view = Database :: get_course_table('lp_view');
  24. $tbl_course_lp_view_item = Database :: get_course_table('lp_item_view');
  25. $tbl_course_lp = Database :: get_course_table('lp');
  26. $tbl_course_lp_item = Database :: get_course_table('lp_item');
  27. $tbl_course_quiz = Database :: get_course_table('quiz');
  28. // get course list
  29. $sql = 'SELECT course_code FROM '.$tbl_course_user.' WHERE user_id='.$_user['user_id'];
  30. $rs = api_sql_query($sql, __FILE__, __LINE__);
  31. $Courses = array();
  32. while($row = Database :: fetch_array($rs))
  33. {
  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 = api_sql_query($sql, __FILE__, __LINE__);
  39. while($row = Database :: fetch_array($rs))
  40. {
  41. $Courses[$row['course_code']] = CourseManager::get_course_information($row['course_code']);
  42. }
  43. api_display_tool_title($nameTools);
  44. $now=date('Y-m-d');
  45. ?>
  46. <table class="data_table" width="100%">
  47. <tr class="tableName">
  48. <td colspan="6">
  49. <strong><?php echo get_lang('MyCourses'); ?></strong>
  50. </td>
  51. </tr>
  52. <tr>
  53. <th><?php echo get_lang('Course'); ?></th>
  54. <th><?php echo get_lang('Time'); ?></th>
  55. <th><?php echo get_lang('Progress'); ?></th>
  56. <th><?php echo get_lang('Score'); ?></th>
  57. <th><?php echo get_lang('LastConnexion'); ?></th>
  58. <th><?php echo get_lang('Details'); ?></th>
  59. </tr>
  60. <?php
  61. $i = 0;
  62. $totalWeighting = 0;
  63. $totalScore = 0;
  64. $totalItem = 0;
  65. $totalProgress = 0;
  66. foreach($Courses as $enreg)
  67. {
  68. $weighting = 0;
  69. $lastConnexion = Tracking :: get_last_connection_date_on_the_course($_user['user_id'],$enreg['code']);
  70. $progress = Tracking :: get_avg_student_progress($_user['user_id'], $enreg['code']);
  71. $time = api_time_to_hms(Tracking :: get_time_spent_on_the_course($_user['user_id'], $enreg['code']));
  72. $pourcentageScore = Tracking :: get_avg_student_score($_user['user_id'], $enreg['code']);
  73. ?>
  74. <tr class='<?php echo $i?'row_odd':'row_even'; ?>'>
  75. <td>
  76. <?php echo htmlentities($enreg['title'],ENT_QUOTES,$charset); ?>
  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 echo $pourcentageScore.'%'; ?>
  86. </td>
  87. <td align='center'>
  88. <?php echo $lastConnexion; ?>
  89. </td>
  90. <td align='center'>
  91. <a href="<?php echo $SERVER['PHP_SELF']; ?>?course=<?php echo $enreg['code']; ?>"> <?php echo '<img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" />';?> </a>
  92. </td>
  93. </tr>
  94. <?php
  95. $i=$i ? 0 : 1;
  96. }
  97. ?>
  98. </table>
  99. <br/><br/>
  100. <?php
  101. /*
  102. * **********************************************************************************************
  103. *
  104. * Details for one course
  105. *
  106. * **********************************************************************************************
  107. */
  108. if(isset($_GET['course']))
  109. {
  110. $course = Database::escape_string($_GET['course']);
  111. $a_infosCours = CourseManager::get_course_information($course);
  112. //get coach and session_name if there is one and if session_mode is activated
  113. if(api_get_setting('use_session_mode')=='true')
  114. {
  115. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  116. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  117. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  118. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  119. $sql = 'SELECT id_session
  120. FROM '.$tbl_session_course_user.' session_course_user
  121. WHERE session_course_user.id_user = '.intval($_user['user_id']).'
  122. AND session_course_user.course_code = "'.Database::escape_string($course).'"
  123. ORDER BY id_session DESC';
  124. $rs = api_sql_query($sql,__FILE__,__LINE__);
  125. $session_id = intval(mysql_result($rs,0,0));
  126. if($session_id>0)
  127. {
  128. // get session name and coach of the session
  129. $sql = 'SELECT name, id_coach FROM '.$tbl_session.'
  130. WHERE id='.$session_id;
  131. $rs = api_sql_query($sql,__FILE__,__LINE__);
  132. $session_name = mysql_result($rs,0,'name');
  133. $session_coach_id = intval(mysql_result($rs,0,'id_coach'));
  134. // get coach of the course in the session
  135. $sql = 'SELECT id_coach FROM '.$tbl_session_course.'
  136. WHERE id_session='.$session_id.'
  137. AND course_code = "'.Database::escape_string($_GET['course']).'"';
  138. $rs = api_sql_query($sql,__FILE__,__LINE__);
  139. $session_course_coach_id = intval(mysql_result($rs,0,0));
  140. if($session_course_coach_id!=0)
  141. {
  142. $coach_infos = UserManager :: get_user_info_by_id($session_course_coach_id);
  143. $a_infosCours['tutor_name'] = $coach_infos['firstname'].' '.$coach_infos['lastname'];
  144. }
  145. else if($session_coach_id!=0)
  146. {
  147. $coach_infos = UserManager :: get_user_info_by_id($session_coach_id);
  148. $a_infosCours['tutor_name'] = $coach_infos['firstname'].' '.$coach_infos['lastname'];
  149. }
  150. }
  151. } // end if(api_get_setting('use_session_mode')=='true')
  152. $tableTitle = $a_infosCours['title'].' | Coach : '.$a_infosCours['tutor_name'].((!empty($session_name)) ? ' | '.get_lang('Session').' : '.$session_name : '');
  153. ?>
  154. <table class="data_table" width="100%">
  155. <tr class="tableName">
  156. <td colspan="4">
  157. <strong><?php echo $tableTitle; ?></strong>
  158. </td>
  159. </tr>
  160. <tr>
  161. <th class="head"><?php echo get_lang('Learnpath'); ?></th>
  162. <th class="head"><?php echo get_lang('Time'); ?></th>
  163. <th class="head"><?php echo get_lang('Progress'); ?></th>
  164. <th class="head"><?php echo get_lang('LastConnexion'); ?></th>
  165. </tr>
  166. <?php
  167. $sqlLearnpath = " SELECT lp.name,lp.id
  168. FROM ".$a_infosCours['db_name'].".".$tbl_course_lp." AS lp
  169. ";
  170. $resultLearnpath = api_sql_query($sqlLearnpath);
  171. if(mysql_num_rows($resultLearnpath)>0)
  172. {
  173. while($a_learnpath = mysql_fetch_array($resultLearnpath))
  174. {
  175. $progress = learnpath :: get_db_progress($a_learnpath['id'],$_user['user_id'], '%',$a_infosCours['db_name']);
  176. // calculates last connection time
  177. $sql = 'SELECT MAX(start_time)
  178. FROM '.$a_infosCours['db_name'].'.'.$tbl_course_lp_view_item.' AS item_view
  179. INNER JOIN '.$a_infosCours['db_name'].'.'.$tbl_course_lp_view.' AS view
  180. ON item_view.lp_view_id = view.id
  181. AND view.lp_id = '.$a_learnpath['id'].'
  182. AND view.user_id = '.$_user['user_id'];
  183. $rs = api_sql_query($sql, __FILE__, __LINE__);
  184. $start_time = mysql_result($rs, 0, 0);
  185. // calculates time
  186. $sql = 'SELECT SUM(total_time)
  187. FROM '.$a_infosCours['db_name'].'.'.$tbl_course_lp_view_item.' AS item_view
  188. INNER JOIN '.$a_infosCours['db_name'].'.'.$tbl_course_lp_view.' AS view
  189. ON item_view.lp_view_id = view.id
  190. AND view.lp_id = '.$a_learnpath['id'].'
  191. AND view.user_id = '.$_user['user_id'];
  192. $rs = api_sql_query($sql, __FILE__, __LINE__);
  193. $total_time = mysql_result($rs, 0, 0);
  194. echo "<tr>
  195. <td>
  196. ";
  197. echo stripslashes($a_learnpath['name']);
  198. echo " </td>
  199. <td>
  200. ";
  201. echo api_time_to_hms($total_time);
  202. echo " </td>
  203. <td align='center'>
  204. ";
  205. echo $progress;
  206. echo " </td>
  207. <td align='center'>
  208. ";
  209. if($start_time!=''){
  210. echo format_locale_date(get_lang('dateFormatLong'),$start_time);
  211. }
  212. else{
  213. echo '-';
  214. }
  215. echo " </td>
  216. </tr>
  217. ";
  218. }
  219. }
  220. else
  221. {
  222. echo " <tr>
  223. <td colspan='4'>
  224. ".get_lang('NoLearnpath')."
  225. </td>
  226. </tr>
  227. ";
  228. }
  229. ?>
  230. <tr>
  231. <th class="head"><?php echo get_lang('Exercices'); ?></th>
  232. <th class="head"><?php echo get_lang('Score'); ?></th>
  233. <th class="head"><?php echo get_lang('Attempts'); ?></th>
  234. <th class="head"><?php echo get_lang('Details'); ?></th>
  235. </tr>
  236. <?php
  237. $sql='SELECT visibility FROM '.$a_infosCours['db_name'].'.'.TABLE_TOOL_LIST.' WHERE name="quiz"';
  238. $resultVisibilityTests = api_sql_query($sql);
  239. if(mysql_result($resultVisibilityTests,0,'visibility')==1){
  240. $sqlExercices = " SELECT quiz.title,id
  241. FROM ".$a_infosCours['db_name'].".".$tbl_course_quiz." AS quiz
  242. WHERE active='1'
  243. ";
  244. $resuktExercices = api_sql_query($sqlExercices);
  245. if(mysql_num_rows($resuktExercices)>0){
  246. while($a_exercices = mysql_fetch_array($resuktExercices))
  247. {
  248. $sqlEssais = " SELECT COUNT(ex.exe_id) as essais
  249. FROM $tbl_stats_exercices AS ex
  250. WHERE ex.exe_user_id='".$_user['user_id']."' AND ex.exe_cours_id = '".$a_infosCours['code']."'
  251. AND ex.exe_exo_id = ".$a_exercices['id']
  252. ;
  253. $resultEssais = api_sql_query($sqlEssais);
  254. $a_essais = mysql_fetch_array($resultEssais);
  255. $sqlScore = "SELECT exe_id , exe_result,exe_weighting
  256. FROM $tbl_stats_exercices
  257. WHERE exe_user_id = ".$_user['user_id']."
  258. AND exe_cours_id = '".$a_infosCours['code']."'
  259. AND exe_exo_id = ".$a_exercices['id']."
  260. ORDER BY exe_date DESC LIMIT 1"
  261. ;
  262. $resultScore = api_sql_query($sqlScore);
  263. $score = 0;
  264. while($a_score = mysql_fetch_array($resultScore))
  265. {
  266. $score = $score + $a_score['exe_result'];
  267. $weighting = $weighting + $a_score['exe_weighting'];
  268. $exe_id = $a_score['exe_id'];
  269. }
  270. $pourcentageScore = round(($score*100)/$weighting);
  271. $weighting = 0;
  272. echo "<tr>
  273. <td>
  274. ";
  275. echo $a_exercices['title'];
  276. echo " </td>
  277. ";
  278. echo " <td align='center'>
  279. ";
  280. echo $pourcentageScore.'%';
  281. echo " </td>
  282. <td align='center'>
  283. ";
  284. echo $a_essais['essais'];
  285. echo ' </td>
  286. <td align="center" width="25">
  287. ';
  288. if($a_essais['essais']>0)
  289. echo '<a href="../exercice/exercise_show.php?origin=student_progress&id='.$exe_id.'&cidReq='.$a_infosCours['code'].'&id_session='.$_GET['id_session'].'"> <img src="'.api_get_path(WEB_IMG_PATH).'quiz.gif" border="0"> </a>';
  290. echo " </td>
  291. </tr>
  292. ";
  293. }
  294. }
  295. else{
  296. echo '<tr><td colspan="4">'.get_lang('NoEx').'</td></tr>';
  297. }
  298. }
  299. else{
  300. echo '<tr><td colspan="4">'.get_lang('NoEx').'</td></tr>';
  301. }
  302. ?>
  303. </table>
  304. <?php
  305. }
  306. Display :: display_footer();
  307. ?>