my_progress.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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. $nameTools=get_lang('MyProgress');
  8. $this_section = 'session_my_progress';
  9. api_block_anonymous_users();
  10. Display :: display_header($nameTools);
  11. // Database table definitions
  12. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  13. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  14. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  15. $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  16. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  17. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  18. $tbl_stats_lastaccess = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
  19. $tbl_stats_exercices = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  20. $tbl_course_lp_view = Database :: get_course_table('lp_view');
  21. $tbl_course_lp_view_item = Database :: get_course_table('lp_item_view');
  22. $tbl_course_lp = Database :: get_course_table('lp');
  23. $tbl_course_lp_item = Database :: get_course_table('lp_item');
  24. $tbl_course_quiz = Database :: get_course_table('quiz');
  25. $result=api_sql_query("SELECT DISTINCT id, name, date_start, date_end FROM session_rel_course_rel_user,session WHERE id_session=id AND id_user=".$_user['user_id']." ORDER BY date_start, date_end, name",__FILE__,__LINE__);
  26. $Sessions=api_store_result($result);
  27. $Courses = array();
  28. foreach($Sessions as $enreg){
  29. $id_session_temp = $enreg['id'];
  30. $sql = "SELECT DISTINCT code,title, CONCAT(lastname, ' ',firstname) coach, username, date_start, date_end, db_name
  31. FROM $tbl_course , $tbl_session_course
  32. LEFT JOIN $tbl_user
  33. ON $tbl_session_course.id_coach = $tbl_user.user_id
  34. INNER JOIN $tbl_session_course_user
  35. ON $tbl_session_course_user.id_session = $tbl_session_course.id_session
  36. AND $tbl_session_course_user.id_user = '".$_user['user_id']."'
  37. INNER JOIN $tbl_session ON $tbl_session.id = $tbl_session_course.id_session
  38. WHERE $tbl_session_course.course_code=code
  39. AND $tbl_session_course.id_session='$id_session_temp'
  40. ORDER BY title";
  41. $result=api_sql_query($sql);
  42. while($a_session_courses = mysql_fetch_array($result)){
  43. $a_session_courses['id_session'] = $id_session_temp;
  44. $Courses[$a_session_courses['code']] = $a_session_courses;
  45. }
  46. }
  47. $sql = "SELECT DISTINCT code,title, db_name
  48. FROM $tbl_course as course, $tbl_course_user as course_rel_user
  49. WHERE course_rel_user.user_id = '".$_user['user_id']."'
  50. AND course_rel_user.course_code = course.code
  51. ";
  52. $result=api_sql_query($sql);
  53. while($a_courses = mysql_fetch_array($result)){
  54. $a_courses['id_session'] = 0;
  55. $Courses[$a_courses['code']] = $a_courses;
  56. }
  57. api_display_tool_title($nameTools);
  58. $now=date('Y-m-d');
  59. ?>
  60. <table class="data_table" width="100%">
  61. <tr class="tableName">
  62. <td colspan="6">
  63. <strong><?php echo get_lang('MyCourses'); ?></strong>
  64. </td>
  65. </tr>
  66. <tr>
  67. <th><?php echo get_lang('Course'); ?></th>
  68. <th><?php echo get_lang('Time'); ?></th>
  69. <th><?php echo get_lang('Progress'); ?></th>
  70. <th><?php echo get_lang('Score'); ?></th>
  71. <th><?php echo get_lang('LastConnexion'); ?></th>
  72. <th><?php echo get_lang('Details'); ?></th>
  73. </tr>
  74. <?php
  75. $i = 0;
  76. $totalWeighting = 0;
  77. $totalScore = 0;
  78. $totalItem = 0;
  79. $totalProgress = 0;
  80. foreach($Courses as $enreg)
  81. {
  82. $weighting = 0;
  83. $lastConnexion = Tracking :: get_last_connection_date_on_the_course($_user['user_id'],$enreg['code']);
  84. $progress = Tracking :: get_avg_student_progress($_user['user_id'], $enreg['code']);
  85. $time = api_time_to_hms(Tracking :: get_time_spent_on_the_course($_user['user_id'], $enreg['code']));
  86. $pourcentageScore = Tracking :: get_avg_student_score($_user['user_id'], $enreg['code']);
  87. ?>
  88. <tr class='<?php echo $i?'row_odd':'row_even'; ?>'>
  89. <td>
  90. <?php echo htmlentities($enreg['title']); ?>
  91. </td>
  92. <td align='center'>
  93. <?php echo $time; ?>
  94. </td>
  95. <td align='center'>
  96. <?php echo $progress.'%'; ?>
  97. </td>
  98. <td align='center'>
  99. <?php echo $pourcentageScore.'%'; ?>
  100. </td>
  101. <td align='center'>
  102. <?php echo $lastConnexion; ?>
  103. </td>
  104. <td align='center'>
  105. <a href="<?php echo $SERVER['PHP_SELF']; ?>?id_session=<?php echo $enreg['id_session'] ?>&course=<?php echo $enreg['code']; ?>"> <?php echo '<img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" />';?> </a>
  106. </td>
  107. </tr>
  108. <?php
  109. $i=$i ? 0 : 1;
  110. }
  111. ?>
  112. </table>
  113. <br/><br/>
  114. <?php
  115. /*
  116. * **********************************************************************************************
  117. *
  118. * Details for one course
  119. *
  120. * **********************************************************************************************
  121. */
  122. if(isset($_GET['course']))
  123. {
  124. $course = Database::escape_string($_GET['course']);
  125. if($_GET['id_session']!=0){
  126. $sqlInfosCourse = " SELECT course.code,course.title,course.db_name,CONCAT(user.firstname,' ',user.lastname,' / ',user.email) as tutor_infos
  127. FROM $tbl_user as user,$tbl_course as course
  128. INNER JOIN $tbl_session_course as sessionCourse
  129. ON sessionCourse.course_code = course.code
  130. WHERE sessionCourse.id_coach = user.user_id
  131. AND course.code= '".$course."'
  132. ";
  133. }
  134. else{
  135. $sqlInfosCourse = " SELECT course.code,course.title,course.db_name
  136. FROM $tbl_course as course
  137. WHERE course.code= '".$course."'
  138. ";
  139. }
  140. $resultInfosCourse = api_sql_query($sqlInfosCourse);
  141. $a_infosCours = mysql_fetch_array($resultInfosCourse);
  142. if($_GET['id_session']!=0){
  143. $tableTitle = $a_infosCours['title'].' - '.get_lang('Tutor').' : '.$a_infosCours['tutor_infos'];
  144. }
  145. else{
  146. $tableTitle = $a_infosCours['title'];
  147. }
  148. ?>
  149. <table class="data_table" width="100%">
  150. <tr class="tableName">
  151. <td colspan="4">
  152. <strong><?php echo $tableTitle; ?></strong>
  153. </td>
  154. </tr>
  155. <tr>
  156. <th class="head"><?php echo get_lang('Learnpath'); ?></th>
  157. <th class="head"><?php echo get_lang('Time'); ?></th>
  158. <th class="head"><?php echo get_lang('Progress'); ?></th>
  159. <th class="head"><?php echo get_lang('LastConnexion'); ?></th>
  160. </tr>
  161. <?php
  162. $sqlLearnpath = " SELECT lp.name,lp.id
  163. FROM ".$a_infosCours['db_name'].".".$tbl_course_lp." AS lp
  164. ";
  165. $resultLearnpath = api_sql_query($sqlLearnpath);
  166. if(mysql_num_rows($resultLearnpath)>0)
  167. {
  168. while($a_learnpath = mysql_fetch_array($resultLearnpath))
  169. {
  170. $sqlProgress = "SELECT COUNT(DISTINCT lp_item_id) AS nbItem
  171. FROM ".$a_infosCours['db_name'].".".$tbl_course_lp_view_item." AS item_view
  172. INNER JOIN ".$a_infosCours['db_name'].".".$tbl_course_lp_view." AS view
  173. ON item_view.lp_view_id = view.id
  174. AND view.lp_id = ".$a_learnpath['id']."
  175. AND view.user_id = ".$_user['user_id']."
  176. WHERE item_view.status = 'completed' OR item_view.status = 'passed'
  177. ";
  178. $resultProgress = api_sql_query($sqlProgress);
  179. $a_nbItem = mysql_fetch_array($resultProgress);
  180. $sqlTotalItem = " SELECT COUNT(item_type) AS totalItem
  181. FROM ".$a_infosCours['db_name'].".".$tbl_course_lp_item."
  182. WHERE lp_id = ".$a_learnpath['id']."
  183. AND item_type != 'chapter'
  184. AND item_type != 'dokeos_chapter'
  185. AND item_type != 'dir'"
  186. ;
  187. $resultItem = api_sql_query($sqlTotalItem);
  188. $a_totalItem = mysql_fetch_array($resultItem);
  189. $progress = round(($a_nbItem['nbItem'] * 100)/$a_totalItem['totalItem']);
  190. // calculates last connection time
  191. $sql = 'SELECT MAX(start_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. $start_time = mysql_result($rs, 0, 0);
  199. // calculates time
  200. $sql = 'SELECT SUM(total_time)
  201. FROM '.$a_infosCours['db_name'].'.'.$tbl_course_lp_view_item.' AS item_view
  202. INNER JOIN '.$a_infosCours['db_name'].'.'.$tbl_course_lp_view.' AS view
  203. ON item_view.lp_view_id = view.id
  204. AND view.lp_id = '.$a_learnpath['id'].'
  205. AND view.user_id = '.$_user['user_id'];
  206. $rs = api_sql_query($sql, __FILE__, __LINE__);
  207. $total_time = mysql_result($rs, 0, 0);
  208. echo "<tr>
  209. <td>
  210. ";
  211. echo stripslashes($a_learnpath['name']);
  212. echo " </td>
  213. <td>
  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'>
  222. ";
  223. if($start_time!=''){
  224. echo format_locale_date(get_lang('dateFormatLong'),$start_time);
  225. }
  226. else{
  227. echo '-';
  228. }
  229. echo " </td>
  230. </tr>
  231. ";
  232. }
  233. }
  234. else
  235. {
  236. echo " <tr>
  237. <td colspan='4'>
  238. ".get_lang('NoLearnpath')."
  239. </td>
  240. </tr>
  241. ";
  242. }
  243. ?>
  244. <tr>
  245. <th class="head"><?php echo get_lang('Exercices'); ?></th>
  246. <th class="head"><?php echo get_lang('Score'); ?></th>
  247. <th class="head"><?php echo get_lang('Attempts'); ?></th>
  248. <th class="head"><?php echo get_lang('Details'); ?></th>
  249. </tr>
  250. <?php
  251. $sql='SELECT visibility FROM '.$a_infosCours['db_name'].'.'.TABLE_TOOL_LIST.' WHERE name="quiz"';
  252. $resultVisibilityTests = api_sql_query($sql);
  253. if(mysql_result($resultVisibilityTests,0,'visibility')==1){
  254. $sqlExercices = " SELECT quiz.title,id
  255. FROM ".$a_infosCours['db_name'].".".$tbl_course_quiz." AS quiz
  256. WHERE active='1'
  257. ";
  258. $resuktExercices = api_sql_query($sqlExercices);
  259. if(mysql_num_rows($resuktExercices)>0){
  260. while($a_exercices = mysql_fetch_array($resuktExercices))
  261. {
  262. $sqlEssais = " SELECT COUNT(ex.exe_id) as essais
  263. FROM $tbl_stats_exercices AS ex
  264. WHERE ex.exe_user_id='".$_user['user_id']."' AND ex.exe_cours_id = '".$a_infosCours['code']."'
  265. AND ex.exe_exo_id = ".$a_exercices['id']
  266. ;
  267. $resultEssais = api_sql_query($sqlEssais);
  268. $a_essais = mysql_fetch_array($resultEssais);
  269. $sqlScore = "SELECT exe_id , exe_result,exe_weighting
  270. FROM $tbl_stats_exercices
  271. WHERE exe_user_id = ".$_user['user_id']."
  272. AND exe_cours_id = '".$a_infosCours['code']."'
  273. AND exe_exo_id = ".$a_exercices['id']."
  274. ORDER BY exe_date DESC LIMIT 1"
  275. ;
  276. $resultScore = api_sql_query($sqlScore);
  277. $score = 0;
  278. while($a_score = mysql_fetch_array($resultScore))
  279. {
  280. $score = $score + $a_score['exe_result'];
  281. $weighting = $weighting + $a_score['exe_weighting'];
  282. $exe_id = $a_score['exe_id'];
  283. }
  284. $pourcentageScore = round(($score*100)/$weighting);
  285. $weighting = 0;
  286. echo "<tr>
  287. <td>
  288. ";
  289. echo $a_exercices['title'];
  290. echo " </td>
  291. ";
  292. echo " <td align='center'>
  293. ";
  294. echo $pourcentageScore.'%';
  295. echo " </td>
  296. <td align='center'>
  297. ";
  298. echo $a_essais['essais'];
  299. echo ' </td>
  300. <td align="center" width="25">
  301. ';
  302. if($a_essais['essais']>0)
  303. 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>';
  304. echo " </td>
  305. </tr>
  306. ";
  307. }
  308. }
  309. else{
  310. echo '<tr><td colspan="4">'.get_lang('NoEx').'</td></tr>';
  311. }
  312. }
  313. else{
  314. echo '<tr><td colspan="4">'.get_lang('NoEx').'</td></tr>';
  315. }
  316. ?>
  317. </table>
  318. <?php
  319. }
  320. Display :: display_footer();
  321. ?>