my_progress.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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 html_entity_decode($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 api_get_self(); ?>?course=<?php echo $enreg['code']; ?>"> <?php Display::display_icon('2rightarrow.gif'); ?> </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. $row=Database::fetch_array($rs);
  126. if (!empty ($row[0]))
  127. {
  128. $session_id =intval($row[0]);
  129. }
  130. //$session_id =intval(Database::result($rs,0,0));
  131. if($session_id>0)
  132. {
  133. // get session name and coach of the session
  134. $sql = 'SELECT name, id_coach FROM '.$tbl_session.'
  135. WHERE id='.$session_id;
  136. $rs = api_sql_query($sql,__FILE__,__LINE__);
  137. $session_name = Database::result($rs,0,'name');
  138. $session_coach_id = intval(Database::result($rs,0,'id_coach'));
  139. // get coach of the course in the session
  140. $sql = 'SELECT id_coach FROM '.$tbl_session_course.'
  141. WHERE id_session='.$session_id.'
  142. AND course_code = "'.Database::escape_string($_GET['course']).'"';
  143. $rs = api_sql_query($sql,__FILE__,__LINE__);
  144. $session_course_coach_id = intval(Database::result($rs,0,0));
  145. if($session_course_coach_id!=0)
  146. {
  147. $coach_infos = UserManager :: get_user_info_by_id($session_course_coach_id);
  148. $a_infosCours['tutor_name'] = $coach_infos['firstname'].' '.$coach_infos['lastname'];
  149. }
  150. else if($session_coach_id!=0)
  151. {
  152. $coach_infos = UserManager :: get_user_info_by_id($session_coach_id);
  153. $a_infosCours['tutor_name'] = $coach_infos['firstname'].' '.$coach_infos['lastname'];
  154. }
  155. }
  156. } // end if(api_get_setting('use_session_mode')=='true')
  157. $tableTitle = $a_infosCours['title'].' | Coach : '.$a_infosCours['tutor_name'].((!empty($session_name)) ? ' | '.get_lang('Session').' : '.$session_name : '');
  158. ?>
  159. <table class="data_table" width="100%">
  160. <tr class="tableName">
  161. <td colspan="4">
  162. <strong><?php echo $tableTitle; ?></strong>
  163. </td>
  164. </tr>
  165. <tr>
  166. <th class="head"><?php echo get_lang('Learnpath'); ?></th>
  167. <th class="head"><?php echo get_lang('Time'); ?></th>
  168. <th class="head"><?php echo get_lang('Progress'); ?></th>
  169. <th class="head"><?php echo get_lang('LastConnexion'); ?></th>
  170. </tr>
  171. <?php
  172. $sqlLearnpath = " SELECT lp.name,lp.id
  173. FROM ".$a_infosCours['db_name'].".".$tbl_course_lp." AS lp
  174. ";
  175. $resultLearnpath = api_sql_query($sqlLearnpath);
  176. if(Database::num_rows($resultLearnpath)>0)
  177. {
  178. while($a_learnpath = Database::fetch_array($resultLearnpath))
  179. {
  180. $progress = learnpath :: get_db_progress($a_learnpath['id'],$_user['user_id'], '%',$a_infosCours['db_name']);
  181. // calculates last connection time
  182. $sql = 'SELECT MAX(start_time)
  183. FROM '.$a_infosCours['db_name'].'.'.$tbl_course_lp_view_item.' AS item_view
  184. INNER JOIN '.$a_infosCours['db_name'].'.'.$tbl_course_lp_view.' AS view
  185. ON item_view.lp_view_id = view.id
  186. AND view.lp_id = '.$a_learnpath['id'].'
  187. AND view.user_id = '.$_user['user_id'];
  188. $rs = api_sql_query($sql, __FILE__, __LINE__);
  189. $start_time = Database::result($rs, 0, 0);
  190. // calculates time
  191. $sql = 'SELECT SUM(total_time)
  192. FROM '.$a_infosCours['db_name'].'.'.$tbl_course_lp_view_item.' AS item_view
  193. INNER JOIN '.$a_infosCours['db_name'].'.'.$tbl_course_lp_view.' AS view
  194. ON item_view.lp_view_id = view.id
  195. AND view.lp_id = '.$a_learnpath['id'].'
  196. AND view.user_id = '.$_user['user_id'];
  197. $rs = api_sql_query($sql, __FILE__, __LINE__);
  198. $total_time = Database::result($rs, 0, 0);
  199. echo "<tr>
  200. <td>
  201. ";
  202. echo stripslashes($a_learnpath['name']);
  203. echo " </td>
  204. <td>
  205. ";
  206. echo api_time_to_hms($total_time);
  207. echo " </td>
  208. <td align='center'>
  209. ";
  210. echo $progress;
  211. echo " </td>
  212. <td align='center'>
  213. ";
  214. if($start_time!=''){
  215. echo format_locale_date(get_lang('dateFormatLong'),$start_time);
  216. }
  217. else{
  218. echo '-';
  219. }
  220. echo " </td>
  221. </tr>
  222. ";
  223. }
  224. }
  225. else
  226. {
  227. echo " <tr>
  228. <td colspan='4'>
  229. ".get_lang('NoLearnpath')."
  230. </td>
  231. </tr>
  232. ";
  233. }
  234. ?>
  235. <tr>
  236. <th class="head"><?php echo get_lang('Exercices'); ?></th>
  237. <th class="head"><?php echo get_lang('Score'); ?></th>
  238. <th class="head"><?php echo get_lang('Attempts'); ?></th>
  239. <th class="head"><?php echo get_lang('Details'); ?></th>
  240. </tr>
  241. <?php
  242. $sql='SELECT visibility FROM '.$a_infosCours['db_name'].'.'.TABLE_TOOL_LIST.' WHERE name="quiz"';
  243. $resultVisibilityTests = api_sql_query($sql);
  244. if(Database::result($resultVisibilityTests,0,'visibility')==1){
  245. $sqlExercices = " SELECT quiz.title,id
  246. FROM ".$a_infosCours['db_name'].".".$tbl_course_quiz." AS quiz
  247. WHERE active='1'
  248. ";
  249. $resuktExercices = api_sql_query($sqlExercices);
  250. if(Database::num_rows($resuktExercices)>0){
  251. while($a_exercices = Database::fetch_array($resuktExercices))
  252. {
  253. $sqlEssais = " SELECT COUNT(ex.exe_id) as essais
  254. FROM $tbl_stats_exercices AS ex
  255. WHERE ex.exe_user_id='".$_user['user_id']."' AND ex.exe_cours_id = '".$a_infosCours['code']."'
  256. AND ex.exe_exo_id = ".$a_exercices['id']."
  257. AND orig_lp_id = 0
  258. AND orig_lp_item_id = 0 "
  259. ;
  260. $resultEssais = api_sql_query($sqlEssais);
  261. $a_essais = Database::fetch_array($resultEssais);
  262. $sqlScore = "SELECT exe_id , exe_result,exe_weighting
  263. FROM $tbl_stats_exercices
  264. WHERE exe_user_id = ".$_user['user_id']."
  265. AND exe_cours_id = '".$a_infosCours['code']."'
  266. AND exe_exo_id = ".$a_exercices['id']."
  267. AND orig_lp_id = 0
  268. AND orig_lp_item_id = 0
  269. ORDER BY exe_date DESC LIMIT 1"
  270. ;
  271. $resultScore = api_sql_query($sqlScore);
  272. $score = 0;
  273. while($a_score = Database::fetch_array($resultScore))
  274. {
  275. $score = $score + $a_score['exe_result'];
  276. $weighting = $weighting + $a_score['exe_weighting'];
  277. $exe_id = $a_score['exe_id'];
  278. }
  279. if ($weighting>0)
  280. {
  281. $pourcentageScore = round(($score*100)/$weighting,1);
  282. }
  283. else
  284. {
  285. $pourcentageScore=0;
  286. }
  287. $weighting = 0;
  288. echo "<tr>
  289. <td>
  290. ";
  291. echo $a_exercices['title'];
  292. echo " </td>
  293. ";
  294. echo " <td align='center'>
  295. ";
  296. echo $pourcentageScore.'%';
  297. echo " </td>
  298. <td align='center'>
  299. ";
  300. echo $a_essais['essais'];
  301. echo ' </td>
  302. <td align="center" width="25">
  303. ';
  304. if($a_essais['essais']>0)
  305. echo '<a href="../exercice/exercise_show.php?origin=myprogress&id='.$exe_id.'&cidReq='.$a_infosCours['code'].'&id_session='.$_GET['id_session'].'"> '.Display::return_icon('quiz.gif', get_lang('Quiz')).' </a>';
  306. echo " </td>
  307. </tr>
  308. ";
  309. }
  310. }
  311. else{
  312. echo '<tr><td colspan="4">'.get_lang('NoEx').'</td></tr>';
  313. }
  314. }
  315. else{
  316. echo '<tr><td colspan="4">'.get_lang('NoEx').'</td></tr>';
  317. }
  318. ?>
  319. </table>
  320. <?php
  321. }
  322. Display :: display_footer();
  323. ?>