my_progress.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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. $sqlTime = "SELECT total_time
  124. FROM ".$enreg['db_name'].'.'.$tbl_course_lp_view_item." AS lpi
  125. INNER JOIN ".$enreg['db_name'].'.'.$tbl_course_lp_view." AS lpv
  126. ON lpv.lp_id = lpi.lp_view_id
  127. AND lpv.user_id = ".$_user['user_id']
  128. ;
  129. $result = api_sql_query($sqlTime);
  130. while($totalTime = mysql_fetch_array($result))
  131. {
  132. //print_r($totalTime);
  133. }
  134. $sqlScore = "SELECT exe_result,exe_weighting
  135. FROM $tbl_stats_exercices
  136. WHERE exe_user_id = ".$_user['user_id']."
  137. AND exe_cours_id = '".$enreg['code']."'
  138. ";
  139. $resultScore = api_sql_query($sqlScore);
  140. $i = 0;
  141. $score = 0;
  142. while($a_score = mysql_fetch_array($resultScore))
  143. {
  144. $score = $score + $a_score['exe_result'];
  145. $weighting = $weighting + $a_score['exe_weighting'];
  146. $i++;
  147. }
  148. $totalScore = $totalScore + $score;
  149. $totalWeighting = $totalWeighting + $weighting;
  150. $pourcentageScore = round(($score*100)/$weighting);
  151. $weighting = 0;
  152. $sqlLastAccess = " SELECT access_date
  153. FROM $tbl_stats_lastaccess
  154. WHERE access_user_id = ".$_user['user_id']."
  155. AND access_cours_code = '".$enreg['code']."'
  156. ORDER BY access_date DESC LIMIT 0,1"
  157. ;
  158. $result = api_sql_query($sqlLastAccess);
  159. $lastAccess = mysql_fetch_array($result);
  160. if(!empty($lastAccess['access_date']))
  161. {
  162. $a_lastConnexion = explode(' ',$lastAccess['access_date']);
  163. $a_date = explode('-',$a_lastConnexion[0]);
  164. $a_heure = explode(':',$a_lastConnexion[1]);
  165. $lastConnexion = $a_date[2]."/".$a_date[1]."/".$a_date[0];
  166. $lastAccessTms = mktime ( $a_heure[0], $a_heure[1] ,$a_heure[2] ,$a_date[1], $a_date[2],$a_date[0]);
  167. }
  168. else
  169. {
  170. $lastConnexion = get_lang('NoConnexion');
  171. }
  172. $progress = Tracking :: get_avg_student_progress($_user['user_id'], $enreg['code']);
  173. /*$time = $lastAccessTms - $firstAccessTms;
  174. if($time >= 60)
  175. {
  176. $minute = round($time/60);
  177. if($minute >= 60)
  178. {
  179. $heure = round($minute/60);
  180. $minute = $minute - round((60*(($time/60)/60)));
  181. if($minute == 0)
  182. {
  183. $minute = '00';
  184. }
  185. }
  186. else
  187. {
  188. $heure = 0;
  189. }
  190. $temps = $heure.'h'.$minute;
  191. }
  192. else
  193. {
  194. $temps = '0h00';
  195. }
  196. $totalTime .= $time; */
  197. ?>
  198. <tr class='<?php echo $i?'row_odd':'row_even'; ?>'>
  199. <td>
  200. <?php echo htmlentities($enreg['title']); ?>
  201. </td>
  202. <td align='center'>
  203. <?php echo $temps; ?>
  204. </td>
  205. <td align='center'>
  206. <?php echo $progress.'%'; ?>
  207. </td>
  208. <td align='center'>
  209. <?php echo $pourcentageScore.'%'; ?>
  210. </td>
  211. <td align='center'>
  212. <?php echo $lastConnexion; ?>
  213. </td>
  214. <td align='center'>
  215. <a href="<?php echo $SERVER['PHP_SELF']; ?>?id_session=<?php echo $id_session ?>&course=<?php echo $enreg['code']; ?>"> -> </a>
  216. </td>
  217. </tr>
  218. <?php
  219. $i=$i ? 0 : 1;
  220. }
  221. ?>
  222. </table>
  223. <br/><br/>
  224. <?php
  225. /*
  226. * **********************************************************************************************
  227. *
  228. * Details for one course
  229. *
  230. * **********************************************************************************************
  231. */
  232. if(isset($_GET['course']))
  233. {
  234. $sqlInfosCourse = " SELECT course.code,course.title,course.db_name,CONCAT(user.firstname,' ',user.lastname,' / ',user.email) as tutor_infos
  235. FROM $tbl_user as user,$tbl_course as course
  236. INNER JOIN $tbl_session_course as sessionCourse
  237. ON sessionCourse.course_code = course.code
  238. WHERE sessionCourse.id_coach = user.user_id
  239. AND course.code= '".$_GET['course']."'
  240. ";
  241. $resultInfosCourse = api_sql_query($sqlInfosCourse);
  242. $a_infosCours = mysql_fetch_array($resultInfosCourse);
  243. $tableTitle = $a_infosCours['title'].' - '.get_lang('Tutor').' : '.$a_infosCours['tutor_infos'];
  244. ?>
  245. <table class="data_table" width="100%">
  246. <tr class="tableName">
  247. <td colspan="4">
  248. <strong><?php echo $tableTitle; ?></strong>
  249. </td>
  250. </tr>
  251. <tr>
  252. <th class="head"><?php echo get_lang('Learnpath'); ?></th>
  253. <th class="head"><?php echo get_lang('Time'); ?></th>
  254. <th class="head"><?php echo get_lang('Progress'); ?></th>
  255. <th class="head"><?php echo get_lang('LastConnexion'); ?></th>
  256. </tr>
  257. <?php
  258. $sqlLearnpath = " SELECT lp.name,lp.id
  259. FROM ".$a_infosCours['db_name'].".".$tbl_course_lp." AS lp
  260. ";
  261. $resultLearnpath = api_sql_query($sqlLearnpath);
  262. if(mysql_num_rows($resultLearnpath)>0)
  263. {
  264. while($a_learnpath = mysql_fetch_array($resultLearnpath))
  265. {
  266. $sqlProgress = "SELECT COUNT(DISTINCT lp_item_id) AS nbItem
  267. FROM ".$a_infosCours['db_name'].".".$tbl_course_lp_view_item." AS item_view
  268. INNER JOIN ".$a_infosCours['db_name'].".".$tbl_course_lp_view." AS view
  269. ON item_view.lp_view_id = view.id
  270. AND view.lp_id = ".$a_learnpath['id']."
  271. AND view.user_id = ".$_user['user_id']."
  272. WHERE item_view.status = 'completed' OR item_view.status = 'passed'
  273. ";
  274. $resultProgress = api_sql_query($sqlProgress);
  275. $a_nbItem = mysql_fetch_array($resultProgress);
  276. $sqlTotalItem = " SELECT COUNT(item_type) AS totalItem
  277. FROM ".$a_infosCours['db_name'].".".$tbl_course_lp_item."
  278. WHERE lp_id = ".$a_learnpath['id']."
  279. AND item_type != 'chapter'
  280. AND item_type != 'dokeos_chapter'
  281. AND item_type != 'dir'"
  282. ;
  283. $resultItem = api_sql_query($sqlTotalItem);
  284. $a_totalItem = mysql_fetch_array($resultItem);
  285. $progress = round(($a_nbItem['nbItem'] * 100)/$a_totalItem['totalItem']);
  286. // calculates last connection time
  287. $sql = 'SELECT MAX(start_time)
  288. FROM '.$a_infosCours['db_name'].'.'.$tbl_course_lp_view_item.' AS item_view
  289. INNER JOIN '.$a_infosCours['db_name'].'.'.$tbl_course_lp_view.' AS view
  290. ON item_view.lp_view_id = view.id
  291. AND view.lp_id = '.$a_learnpath['id'].'
  292. AND view.user_id = '.$_user['user_id'];
  293. $rs = api_sql_query($sql, __FILE__, __LINE__);
  294. $start_time = mysql_result($rs, 0, 0);
  295. echo "<tr>
  296. <td>
  297. ";
  298. echo $a_learnpath['name'];
  299. echo " </td>
  300. <td>
  301. ";
  302. echo " </td>
  303. <td align='center'>
  304. ";
  305. echo $progress.'%';
  306. echo " </td>
  307. <td align='center'>
  308. ";
  309. echo date('Y-m-d',$start_time);
  310. echo " </td>
  311. </tr>
  312. ";
  313. }
  314. }
  315. else
  316. {
  317. echo " <tr>
  318. <td colspan='4'>
  319. ".get_lang('NoLearnpath')."
  320. </td>
  321. </tr>
  322. ";
  323. }
  324. ?>
  325. <tr>
  326. <th class="head"><?php echo get_lang('Exercices'); ?></th>
  327. <th class="head"><?php echo get_lang('Score'); ?></th>
  328. <th class="head"><?php echo get_lang('Attempts'); ?></th>
  329. <th class="head"><?php echo get_lang('Details'); ?></th>
  330. </tr>
  331. <?php
  332. $sqlExercices = " SELECT quiz.title,id
  333. FROM ".$a_infosCours['db_name'].".".$tbl_course_quiz." AS quiz
  334. ";
  335. $resuktExercices = api_sql_query($sqlExercices);
  336. while($a_exercices = mysql_fetch_array($resuktExercices))
  337. {
  338. $sqlEssais = " SELECT COUNT(ex.exe_id) as essais
  339. FROM $tbl_stats_exercices AS ex
  340. WHERE ex.exe_cours_id = '".$a_infosCours['code']."'
  341. AND ex.exe_exo_id = ".$a_exercices['id']
  342. ;
  343. $resultEssais = api_sql_query($sqlEssais);
  344. $a_essais = mysql_fetch_array($resultEssais);
  345. $sqlScore = "SELECT exe_id , exe_result,exe_weighting
  346. FROM $tbl_stats_exercices
  347. WHERE exe_user_id = ".$_user['user_id']."
  348. AND exe_cours_id = '".$a_infosCours['code']."'
  349. AND exe_exo_id = ".$a_exercices['id']."
  350. ORDER BY exe_date DESC LIMIT 1"
  351. ;
  352. $resultScore = api_sql_query($sqlScore);
  353. $score = 0;
  354. while($a_score = mysql_fetch_array($resultScore))
  355. {
  356. $score = $score + $a_score['exe_result'];
  357. $weighting = $weighting + $a_score['exe_weighting'];
  358. $exe_id = $a_score['exe_id'];
  359. }
  360. $pourcentageScore = round(($score*100)/$weighting);
  361. $weighting = 0;
  362. echo "<tr>
  363. <td>
  364. ";
  365. echo $a_exercices['title'];
  366. echo " </td>
  367. ";
  368. echo " <td align='center'>
  369. ";
  370. echo $pourcentageScore.'%';
  371. echo " </td>
  372. <td align='center'>
  373. ";
  374. echo $a_essais['essais'];
  375. echo ' </td>
  376. <td align="center" width="25">
  377. ';
  378. if($a_essais['essais']>0)
  379. echo '<a href="../exercice/exercise_show.php?id='.$exe_id.'&cidReq='.$a_infosCours['code'].'"> <img src="'.api_get_path(WEB_IMG_PATH).'quiz.gif" border="0"> </a>';
  380. echo " </td>
  381. </tr>
  382. ";
  383. }
  384. ?>
  385. </table>
  386. <?php
  387. }
  388. Display :: display_footer();
  389. ?>