my_progress.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. <?php
  2. // name of the language file that needs to be included
  3. $language_file = array('registration','tracking','exercice','admin');
  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. echo '<div class="actions-title" >';
  44. echo $nameTools;
  45. echo '</div>';
  46. $now=date('Y-m-d');
  47. ?>
  48. <table class="data_table" width="100%">
  49. <tr class="tableName">
  50. <td colspan="6">
  51. <strong><?php echo get_lang('MyCourses'); ?></strong>
  52. </td>
  53. </tr>
  54. <tr>
  55. <th><?php echo get_lang('Course'); ?></th>
  56. <th><?php echo get_lang('Time'); ?></th>
  57. <th><?php echo get_lang('Progress'); ?></th>
  58. <th><?php
  59. echo get_lang('Score');
  60. Display :: display_icon('info3.gif',get_lang('ScormAndLPTestTotalAverage') , array ('style' => 'margin-bottom:-3px;'));
  61. ?></th>
  62. <th><?php echo get_lang('LastConnexion'); ?></th>
  63. <th><?php echo get_lang('Details'); ?></th>
  64. </tr>
  65. <?php
  66. $i = 0;
  67. $totalWeighting = 0;
  68. $totalScore = 0;
  69. $totalItem = 0;
  70. $totalProgress = 0;
  71. foreach($Courses as $enreg)
  72. {
  73. $weighting = 0;
  74. $lastConnexion = Tracking :: get_last_connection_date_on_the_course($_user['user_id'],$enreg['code']);
  75. $progress = Tracking :: get_avg_student_progress($_user['user_id'], $enreg['code']);
  76. $total_time_login=Tracking :: get_time_spent_on_the_course($_user['user_id'], $enreg['code']);
  77. $time = api_time_to_hms($total_time_login);
  78. $pourcentageScore = Tracking :: get_average_test_scorm_and_lp ($_user['user_id'], $enreg['code']);
  79. ?>
  80. <tr class='<?php echo $i?'row_odd':'row_even'; ?>'>
  81. <td>
  82. <?php echo api_html_entity_decode($enreg['title'],ENT_QUOTES,$charset); ?>
  83. </td>
  84. <td align='center'>
  85. <?php echo $time; ?>
  86. </td>
  87. <td align='center'>
  88. <?php echo $progress.'%'; ?>
  89. </td>
  90. <td align='center'>
  91. <?php
  92. if (!is_null($pourcentageScore)) {
  93. echo $pourcentageScore.'%';
  94. } else {
  95. echo '0%';
  96. }
  97. ?>
  98. </td>
  99. <td align='center' >
  100. <?php echo $lastConnexion ?>
  101. </td>
  102. <td align='center'>
  103. <a href="<?php echo api_get_self(); ?>?course=<?php echo $enreg['code']; ?>"> <?php Display::display_icon('2rightarrow.gif'); ?> </a>
  104. </td>
  105. </tr>
  106. <?php
  107. $i=$i ? 0 : 1;
  108. }
  109. ?>
  110. </table>
  111. <br/><br/>
  112. <?php
  113. /*
  114. * **********************************************************************************************
  115. *
  116. * Details for one course
  117. *
  118. * **********************************************************************************************
  119. */
  120. if(isset($_GET['course']))
  121. {
  122. $course = Database::escape_string($_GET['course']);
  123. $a_infosCours = CourseManager::get_course_information($course);
  124. //get coach and session_name if there is one and if session_mode is activated
  125. if(api_get_setting('use_session_mode')=='true')
  126. {
  127. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  128. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  129. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  130. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  131. $sql = 'SELECT id_session
  132. FROM '.$tbl_session_course_user.' session_course_user
  133. WHERE session_course_user.id_user = '.intval($_user['user_id']).'
  134. AND session_course_user.course_code = "'.Database::escape_string($course).'"
  135. ORDER BY id_session DESC';
  136. $rs = api_sql_query($sql,__FILE__,__LINE__);
  137. $row=Database::fetch_array($rs);
  138. if (!empty ($row[0]))
  139. {
  140. $session_id =intval($row[0]);
  141. }
  142. //$session_id =intval(Database::result($rs,0,0));
  143. if($session_id>0)
  144. {
  145. // get session name and coach of the session
  146. $sql = 'SELECT name, id_coach FROM '.$tbl_session.'
  147. WHERE id='.$session_id;
  148. $rs = api_sql_query($sql,__FILE__,__LINE__);
  149. $session_name = Database::result($rs,0,'name');
  150. $session_coach_id = intval(Database::result($rs,0,'id_coach'));
  151. // get coach of the course in the session
  152. $sql = 'SELECT id_coach FROM '.$tbl_session_course.'
  153. WHERE id_session='.$session_id.'
  154. AND course_code = "'.Database::escape_string($_GET['course']).'"';
  155. $rs = api_sql_query($sql,__FILE__,__LINE__);
  156. $session_course_coach_id = intval(Database::result($rs,0,0));
  157. if($session_course_coach_id!=0)
  158. {
  159. $coach_infos = UserManager :: get_user_info_by_id($session_course_coach_id);
  160. $a_infosCours['tutor_name'] = $coach_infos['firstname'].' '.$coach_infos['lastname'];
  161. }
  162. else if($session_coach_id!=0)
  163. {
  164. $coach_infos = UserManager :: get_user_info_by_id($session_coach_id);
  165. $a_infosCours['tutor_name'] = $coach_infos['firstname'].' '.$coach_infos['lastname'];
  166. }
  167. }
  168. } // end if(api_get_setting('use_session_mode')=='true')
  169. $tableTitle = $a_infosCours['title'].' | Coach : '.$a_infosCours['tutor_name'].((!empty($session_name)) ? ' | '.get_lang('Session').' : '.$session_name : '');
  170. ?>
  171. <table class="data_table" width="100%">
  172. <tr class="tableName">
  173. <td colspan="4">
  174. <strong><?php echo $tableTitle; ?></strong>
  175. </td>
  176. </tr>
  177. <tr>
  178. <th class="head"><?php echo get_lang('Learnpath'); ?></th>
  179. <th class="head"><?php echo get_lang('Time'); ?></th>
  180. <th class="head"><?php echo get_lang('Progress'); ?></th>
  181. <th class="head"><?php echo get_lang('LastConnexion'); ?></th>
  182. </tr>
  183. <?php
  184. $sqlLearnpath = " SELECT lp.name,lp.id
  185. FROM ".$a_infosCours['db_name'].".".$tbl_course_lp." AS lp
  186. ";
  187. $resultLearnpath = api_sql_query($sqlLearnpath);
  188. if(Database::num_rows($resultLearnpath)>0) {
  189. while($a_learnpath = Database::fetch_array($resultLearnpath)) {
  190. $progress = learnpath :: get_db_progress($a_learnpath['id'],$_user['user_id'], '%',$a_infosCours['db_name']);
  191. // calculates last connection time
  192. $sql = 'SELECT MAX(start_time)
  193. FROM '.$a_infosCours['db_name'].'.'.$tbl_course_lp_view_item.' AS item_view
  194. INNER JOIN '.$a_infosCours['db_name'].'.'.$tbl_course_lp_view.' AS view
  195. ON item_view.lp_view_id = view.id
  196. AND view.lp_id = '.$a_learnpath['id'].'
  197. AND view.user_id = '.$_user['user_id'];
  198. $rs = api_sql_query($sql, __FILE__, __LINE__);
  199. $start_time = Database::result($rs, 0, 0);
  200. // calculates time
  201. $sql = 'SELECT SUM(total_time)
  202. FROM '.$a_infosCours['db_name'].'.'.$tbl_course_lp_view_item.' AS item_view
  203. INNER JOIN '.$a_infosCours['db_name'].'.'.$tbl_course_lp_view.' AS view
  204. ON item_view.lp_view_id = view.id
  205. AND view.lp_id = '.$a_learnpath['id'].'
  206. AND view.user_id = '.$_user['user_id'];
  207. $rs = api_sql_query($sql, __FILE__, __LINE__);
  208. $total_time = Database::result($rs, 0, 0);
  209. echo "<tr>
  210. <td>
  211. ";
  212. echo stripslashes($a_learnpath['name']);
  213. echo " </td>
  214. <td align='center'>
  215. ";
  216. echo api_time_to_hms($total_time);
  217. echo " </td>
  218. <td align='center'>
  219. ";
  220. echo $progress;
  221. echo " </td>
  222. <td align='center' width=180px >
  223. ";
  224. if($start_time!=''){
  225. echo $lastConnexion;
  226. }
  227. else{
  228. echo '-';
  229. }
  230. echo " </td>
  231. </tr>
  232. ";
  233. }
  234. }
  235. else
  236. {
  237. echo " <tr>
  238. <td colspan='4'>
  239. ".get_lang('NoLearnpath')."
  240. </td>
  241. </tr>
  242. ";
  243. }
  244. ?>
  245. <tr>
  246. <th class="head"><?php echo get_lang('Exercices'); ?></th>
  247. <th class="head"><?php echo get_lang('Score'); ?></th>
  248. <th class="head"><?php echo get_lang('Attempts'); ?></th>
  249. <th class="head"><?php echo get_lang('Details'); ?></th>
  250. </tr>
  251. <?php
  252. $sql='SELECT visibility FROM '.$a_infosCours['db_name'].'.'.TABLE_TOOL_LIST.' WHERE name="quiz"';
  253. $resultVisibilityTests = api_sql_query($sql);
  254. if (Database::result($resultVisibilityTests,0,'visibility')==1) {
  255. $sqlExercices = " SELECT quiz.title,id, results_disabled
  256. FROM ".$a_infosCours['db_name'].".".$tbl_course_quiz." AS quiz
  257. WHERE active='1'";
  258. $resuktExercices = api_sql_query($sqlExercices);
  259. if (Database::num_rows($resuktExercices)>0) {
  260. while ($a_exercices = Database::fetch_array($resuktExercices)) {
  261. $sqlEssais = " SELECT COUNT(ex.exe_id) as essais
  262. FROM $tbl_stats_exercices AS ex
  263. WHERE ex.exe_user_id='".$_user['user_id']."' AND ex.exe_cours_id = '".$a_infosCours['code']."'
  264. AND ex.exe_exo_id = ".$a_exercices['id']."
  265. AND orig_lp_id = 0
  266. AND orig_lp_item_id = 0 "
  267. ;
  268. $resultEssais = api_sql_query($sqlEssais);
  269. $a_essais = Database::fetch_array($resultEssais);
  270. $sqlScore = "SELECT exe_id , exe_result,exe_weighting
  271. FROM $tbl_stats_exercices
  272. WHERE exe_user_id = ".$_user['user_id']."
  273. AND exe_cours_id = '".$a_infosCours['code']."'
  274. AND exe_exo_id = ".$a_exercices['id']."
  275. AND orig_lp_id = 0
  276. AND orig_lp_item_id = 0
  277. ORDER BY exe_date DESC LIMIT 1";
  278. $resultScore = api_sql_query($sqlScore);
  279. $score = 0;
  280. while($a_score = Database::fetch_array($resultScore)) {
  281. $score = $score + $a_score['exe_result'];
  282. $weighting = $weighting + $a_score['exe_weighting'];
  283. $exe_id = $a_score['exe_id'];
  284. }
  285. if ($weighting>0) {
  286. // i.e 10.50%
  287. $pourcentageScore = round(($score*100)/$weighting,2);
  288. } else {
  289. $pourcentageScore=0;
  290. }
  291. $weighting = 0;
  292. echo '<tr>
  293. <td>';
  294. echo $a_exercices['title'];
  295. echo '</td>';
  296. if ($a_exercices['results_disabled']==0) {
  297. echo '<td align="center">';
  298. if ($a_essais['essais']>0) {
  299. echo $pourcentageScore.'%';
  300. } else {
  301. echo '/';
  302. }
  303. echo '</td>';
  304. echo '<td align="center">';
  305. echo $a_essais['essais'];
  306. echo '</td>
  307. <td align="center" width="25">';
  308. if($a_essais['essais']>0)
  309. echo '<a href="../exercice/exercise_show.php?origin=myprogress&id='.$exe_id.'&cidReq='.$a_infosCours['code'].'&id_session='.Security::remove_XSS($_GET['id_session']).'"> '.Display::return_icon('quiz.gif', get_lang('Quiz')).' </a>';
  310. echo '</td>';
  311. } else {
  312. // we show or not the results if the teacher wants to
  313. echo '<td align="center">';
  314. echo get_lang('CantShowResults');
  315. echo '</td>';
  316. echo '<td align="center">';
  317. echo ' -- ';
  318. echo '</td>
  319. <td align="center" width="25">';
  320. echo ' -- ';
  321. echo '</td>';
  322. }
  323. echo '</tr>';
  324. }
  325. } else {
  326. echo '<tr><td colspan="4">'.get_lang('NoEx').'</td></tr>';
  327. }
  328. }
  329. else{
  330. echo '<tr><td colspan="4">'.get_lang('NoEx').'</td></tr>';
  331. }
  332. ?>
  333. </table>
  334. <?php
  335. }
  336. Display :: display_footer();
  337. ?>