my_progress.php 13 KB

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