my_progress.php 13 KB

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