myStudents.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110
  1. <?php //$Id: myStudents.php 14945 2008-04-17 21:53:37Z juliomontoya $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2006-2008 Dokeos SPRL
  6. Copyright (c) 2006-2008 Elixir Interactive http://www.elixir-interactive.com
  7. For a full list of contributors, see "credits.txt".
  8. The full license can be read in "license.txt".
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13. See the GNU General Public License for more details.
  14. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  15. Mail: info@dokeos.com
  16. ==============================================================================
  17. */
  18. // name of the language file that needs to be included
  19. $language_file = array ('registration', 'index', 'tracking', 'exercice');
  20. $cidReset=true;
  21. include ('../inc/global.inc.php');
  22. include_once(api_get_path(LIBRARY_PATH).'tracking.lib.php');
  23. include_once(api_get_path(LIBRARY_PATH).'export.lib.inc.php');
  24. include_once(api_get_path(LIBRARY_PATH).'usermanager.lib.php');
  25. include_once(api_get_path(LIBRARY_PATH).'course.lib.php');
  26. include_once('../newscorm/learnpath.class.php');
  27. $export_csv = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
  28. if($export_csv)
  29. {
  30. ob_start();
  31. }
  32. $csv_content = array();
  33. $this_section = "session_my_space";
  34. $nameTools=get_lang("StudentDetails");
  35. if(isset($_GET['details']))
  36. {
  37. if(!empty($_GET['origin']) && $_GET['origin'] == 'user_course')
  38. {
  39. $course_infos = CourseManager :: get_course_information($_GET['course']);
  40. if(empty($cidReq))
  41. $interbreadcrumb[] = array ("url" => api_get_path(WEB_COURSE_PATH).$course_infos['directory'], 'name' => $course_infos['title']);
  42. $interbreadcrumb[] = array ("url" => "../user/user.php?cidReq=".$_GET['course'], "name" => get_lang("Users"));
  43. }
  44. else if(!empty($_GET['origin']) && $_GET['origin'] == 'tracking_course')
  45. {
  46. $course_infos = CourseManager :: get_course_information($_GET['course']);
  47. if(empty($cidReq))
  48. $interbreadcrumb[] = array ("url" => api_get_path(WEB_COURSE_PATH).$course_infos['directory'], 'name' => $course_infos['title']);
  49. $interbreadcrumb[] = array ("url" => "../tracking/courseLog.php?cidReq=".$_GET['course'].'&studentlist=true&id_session='.$_SESSION['id_session'], "name" => get_lang("Tracking"));
  50. }
  51. else
  52. {
  53. $interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
  54. if(isset($_GET['id_coach']) && intval($_GET['id_coach'])!=0){
  55. $interbreadcrumb[] = array ("url" => "student.php?id_coach=".$_GET['id_coach'], "name" => get_lang("CoachStudents"));
  56. $interbreadcrumb[] = array ("url" => "myStudents.php?student=".$_GET['student'].'&id_coach='.$_GET['id_coach'], "name" => get_lang("StudentDetails"));
  57. }
  58. else{
  59. $interbreadcrumb[] = array ("url" => "student.php", "name" => get_lang("MyStudents"));
  60. $interbreadcrumb[] = array ("url" => "myStudents.php?student=".$_GET['student'], "name" => get_lang("StudentDetails"));
  61. }
  62. }
  63. $nameTools=get_lang("DetailsStudentInCourse");
  64. }
  65. else
  66. {
  67. $interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
  68. if(isset($_GET['id_coach']) && intval($_GET['id_coach'])!=0){
  69. if(isset($_GET['id_session']) && intval($_GET['id_session'])!=0){
  70. $interbreadcrumb[] = array ("url" => "student.php?id_coach=".$_GET['id_coach']."&id_session=".$_GET['id_session'], "name" => get_lang("CoachStudents"));
  71. }
  72. else{
  73. $interbreadcrumb[] = array ("url" => "student.php?id_coach=".$_GET['id_coach'], "name" => get_lang("CoachStudents"));
  74. }
  75. }
  76. else{
  77. $interbreadcrumb[] = array ("url" => "student.php", "name" => get_lang("MyStudents"));
  78. }
  79. }
  80. api_block_anonymous_users();
  81. if(empty($_SESSION['is_allowedCreateCourse']) && !api_is_coach() && $_user['status']!=DRH && $_user['status']!=SESSIONADMIN){
  82. api_not_allowed(true);
  83. }
  84. Display :: display_header($nameTools);
  85. /*
  86. * ======================================================================================
  87. * FUNCTIONS
  88. * ======================================================================================
  89. */
  90. function calculHours($seconds)
  91. {
  92. //How many hours ?
  93. $hours = floor($seconds / 3600);
  94. //How many minutes ?
  95. $min = floor(($seconds - ($hours * 3600)) / 60);
  96. if ($min < 10)
  97. $min = "0".$min;
  98. //How many seconds
  99. $sec = $seconds - ($hours * 3600) - ($min * 60);
  100. if ($sec < 10)
  101. $sec = "0".$sec;
  102. return $hours."h".$min."m".$sec."s" ;
  103. }
  104. function is_teacher($course_code){
  105. global $_user;
  106. $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  107. $sql="SELECT 1 FROM $tbl_course_user WHERE user_id='".$_user["user_id"]."' AND course_code='".$course_code."' AND status='1'";
  108. $result=api_sql_query($sql,__FILE__,__LINE__);
  109. if(Database::result($result)!=1)
  110. {
  111. return true;
  112. }
  113. else{
  114. return false;
  115. }
  116. }
  117. /*
  118. *===============================================================================
  119. * MAIN CODE
  120. *===============================================================================
  121. */
  122. // Database Table Definitions
  123. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  124. $tbl_session_user = Database :: get_main_table(TABLE_MAIN_SESSION_USER);
  125. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  126. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  127. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  128. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  129. $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  130. $tbl_stats_exercices = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  131. $tbl_stats_exercices_attempts = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  132. //$tbl_course_lp_view = Database :: get_course_table('lp_view');
  133. //$tbl_course_lp_view_item = Database :: get_course_table('lp_item_view');
  134. //$tbl_course_lp_item = Database :: get_course_table('lp_item');
  135. $tbl_course_lp_view = 'lp_view';
  136. $tbl_course_lp_view_item = 'lp_item_view';
  137. $tbl_course_lp_item = 'lp_item';
  138. $tbl_course_lp = 'lp';
  139. $tbl_course_quiz = 'quiz';
  140. $course_quiz_question = 'quiz_question';
  141. $course_quiz_rel_question = 'quiz_rel_question';
  142. $course_quiz_answer = 'quiz_answer';
  143. $course_student_publication = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  144. if(isset($_GET["user_id"]) && $_GET["user_id"]!="")
  145. {
  146. $i_user_id=$_GET["user_id"];
  147. }
  148. else
  149. {
  150. $i_user_id = $_user['user_id'];
  151. }
  152. if(!empty($_GET['student']))
  153. {
  154. $student_id = intval($_GET['student']);
  155. // infos about user
  156. $a_infosUser = UserManager::get_user_info_by_id($student_id);
  157. if($_user['status']==DRH && $a_infosUser['hr_dept_id']!=$_user['user_id'])
  158. {
  159. api_not_allowed();
  160. }
  161. $a_infosUser['name'] = $a_infosUser['firstname'].' '.$a_infosUser['lastname'];
  162. echo '<div align="right">
  163. <a href="#" onclick="window.print()"><img align="absbottom" src="../img/printmgr.gif">&nbsp;'.get_lang('Print').'</a>
  164. <a href="'.api_get_self().'?'.$_SERVER['QUERY_STRING'].'&export=csv"><img align="absbottom" src="../img/excel.gif">&nbsp;'.get_lang('ExportAsCSV').'</a>
  165. </div>';
  166. // is the user online ?
  167. $statistics_database = Database :: get_statistic_database();
  168. $a_usersOnline = WhoIsOnline($_GET['student'], $statistics_database, 30);
  169. foreach($a_usersOnline as $a_online)
  170. {
  171. if(in_array($_GET['student'],$a_online))
  172. {
  173. $online = get_lang('Yes');
  174. break;
  175. }
  176. else
  177. {
  178. $online = get_lang('No');
  179. }
  180. }
  181. $avg_student_progress = $avg_student_score = $nb_courses = 0;
  182. $sql = 'SELECT course_code FROM '.$tbl_course_user.' WHERE user_id='.$a_infosUser['user_id'];
  183. $rs = api_sql_query($sql, __FILE__, __LINE__);
  184. $a_courses = array();
  185. while($row = Database :: fetch_array($rs))
  186. {
  187. $a_courses[$row['course_code']] = $row['course_code'];
  188. }
  189. // get the list of sessions where the user is subscribed as student
  190. $sql = 'SELECT DISTINCT course_code FROM '.Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER).' WHERE id_user='.intval($a_infosUser['user_id']);
  191. $rs = api_sql_query($sql, __FILE__, __LINE__);
  192. while($row = Database :: fetch_array($rs))
  193. {
  194. $a_courses[$row['course_code']] = $row['course_code'];
  195. }
  196. foreach ($a_courses as $key=>$course_code)
  197. {
  198. if(!CourseManager::is_user_subscribed_in_course($a_infosUser['user_id'], $course_code, true))
  199. {
  200. unset($a_courses[$key]);
  201. }
  202. else
  203. {
  204. $nb_courses++;
  205. $avg_student_progress += Tracking :: get_avg_student_progress($a_infosUser['user_id'],$course_code);
  206. $avg_student_score += Tracking :: get_avg_student_score($a_infosUser['user_id'],$course_code);
  207. }
  208. }
  209. $avg_student_progress = round($avg_student_progress / $nb_courses,2);
  210. $avg_student_score = round($avg_student_score / $nb_courses,2);
  211. $first_connection_date = Tracking::get_first_connection_date($a_infosUser['user_id']);
  212. if($first_connection_date==''){
  213. $first_connection_date=get_lang('NoConnexion');
  214. }
  215. $last_connection_date = Tracking::get_last_connection_date($a_infosUser['user_id'],true);
  216. if($last_connection_date==''){
  217. $last_connection_date=get_lang('NoConnexion');
  218. }
  219. $time_spent_on_the_platform = api_time_to_hms(Tracking::get_time_spent_on_the_platform($a_infosUser['user_id']));
  220. // cvs informations
  221. $csv_content[] = array(get_lang('Informations'));
  222. $csv_content[] = array(get_lang('Name'), get_lang('Email'), get_lang('Tel'));
  223. $csv_content[] = array($a_infosUser['name'], $a_infosUser['email'],$a_infosUser['phone']);
  224. $csv_content[] = array();
  225. // csv tracking
  226. $csv_content[] = array(get_lang('Tracking'));
  227. $csv_content[] = array(get_lang('FirstLogin'),get_lang('LatestLogin'), get_lang('TimeSpentOnThePlatform'), get_lang('Progress'), get_lang('Score'));
  228. $csv_content[] = array(strip_tags($first_connection_date),strip_tags($last_connection_date), $time_spent_on_the_platform , $avg_student_progress.' %',$avg_student_score.' %');
  229. ?>
  230. <a name="infosStudent"></a>
  231. <table class="data_table">
  232. <tr>
  233. <td class="border">
  234. <table width="100%" border="0" >
  235. <tr>
  236. <?php
  237. $image_array=UserManager::get_user_picture_path_by_id($a_infosUser['user_id'],'web',false, true);
  238. echo '<td class="borderRight" width="10%" valign="top">';
  239. echo '<img src="'.$image_array['dir'].$image_array['file'].'" border="1">';
  240. echo '</td>';
  241. ?>
  242. <td class="none" width="40%" valign="top">
  243. <table width="100%">
  244. <tr>
  245. <th>
  246. <?php echo get_lang('Informations'); ?>
  247. </th>
  248. </tr>
  249. <tr>
  250. <td class="none">
  251. <?php
  252. echo get_lang('Name').' : ';
  253. echo $a_infosUser['name'];
  254. ?>
  255. </td>
  256. </tr>
  257. <tr>
  258. <td class="none">
  259. <?php
  260. echo get_lang('Email').' : ';
  261. if(!empty($a_infosUser['email']))
  262. {
  263. echo '<a href="mailto:'.$a_infosUser['email'].'">'.$a_infosUser['email'].'</a>';
  264. }
  265. else
  266. {
  267. echo get_lang('NoEmail');
  268. }
  269. ?>
  270. </td>
  271. </tr>
  272. <tr>
  273. <td class="none">
  274. <?php
  275. echo get_lang('Tel').'. ';
  276. if(!empty($a_infosUser['phone']))
  277. {
  278. echo $a_infosUser['phone'];
  279. }
  280. else
  281. {
  282. echo get_lang('NoTel');
  283. }
  284. ?>
  285. </td>
  286. </tr>
  287. <tr>
  288. <td class="none">
  289. <?php
  290. echo get_lang('OnLine').' : ';
  291. echo $online;
  292. ?>
  293. </td>
  294. </tr>
  295. </table>
  296. </td>
  297. <td class="borderLeft" width="35%" valign="top">
  298. <table width="100%">
  299. <tr>
  300. <th>
  301. <?php echo get_lang('Tracking'); ?>
  302. </th>
  303. </tr>
  304. <tr>
  305. <td>
  306. <table>
  307. <tr>
  308. <td class="none" align="right">
  309. <?php echo get_lang('FirstLogin') ?>
  310. </td>
  311. <td class="none" align="left">
  312. <?php echo $first_connection_date ?>
  313. </td>
  314. </tr>
  315. <tr>
  316. <td class="none" align="right">
  317. <?php echo get_lang('LatestLogin') ?>
  318. </td>
  319. <td class="none" align="left">
  320. <?php echo $last_connection_date ?>
  321. </td>
  322. </tr>
  323. <tr>
  324. <td class="none" align="right">
  325. <?php echo get_lang('TimeSpentOnThePlatform') ?>
  326. </td>
  327. <td class="none" align="left">
  328. <?php echo $time_spent_on_the_platform ?>
  329. </td>
  330. </tr>
  331. <tr>
  332. <td class="none" align="right">
  333. <?php echo get_lang('Progress') ?>
  334. </td>
  335. <td class="none" align="left">
  336. <?php echo $avg_student_progress.' %' ?>
  337. </td>
  338. </tr>
  339. <tr>
  340. <td class="none" align="right">
  341. <?php echo get_lang('Score') ?>
  342. </td>
  343. <td class="none" align="left">
  344. <?php echo $avg_student_score.' %' ?>
  345. </td>
  346. </tr>
  347. </table>
  348. </td>
  349. </tr>
  350. </table>
  351. </td>
  352. <?php
  353. $sendMail = Display::encrypted_mailto_link($a_infosUser['email'], ' '.get_lang('SendMail'));
  354. ?>
  355. <td class="borderLeft" width="15%" valign="top">
  356. <table width="100%">
  357. <tr>
  358. <th>
  359. <?php echo get_lang('Actions'); ?>
  360. </th>
  361. </tr>
  362. <tr>
  363. <?php
  364. if(!empty($a_infosUser['email']))
  365. {
  366. echo "<td class='none'>";
  367. echo '<img align="absbottom" src="../img/send_mail.gif">&nbsp;'.$sendMail;
  368. echo "</td>";
  369. }
  370. else
  371. {
  372. echo "<td class='noLink none'>";
  373. echo '<img align="absbottom" src="../img/send_mail.gif">&nbsp; <strong> > '.get_lang('SendMail').'</strong>';
  374. echo "</td>";
  375. }
  376. ?>
  377. </tr>
  378. </table>
  379. </td>
  380. </tr>
  381. </table>
  382. </td>
  383. </tr>
  384. </table>
  385. <table class="data_table">
  386. <tr>
  387. <td colspan="5" style="border-width: 0px;">&nbsp;</td>
  388. </tr>
  389. <?php
  390. if(!empty($_GET['details']))
  391. {
  392. $a_infosCours = CourseManager :: get_course_information($_GET['course']);
  393. //get coach and session_name if there is one and if session_mode is activated
  394. if(api_get_setting('use_session_mode')=='true')
  395. {
  396. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  397. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  398. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  399. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  400. $sql = 'SELECT id_session
  401. FROM '.$tbl_session_course_user.' session_course_user
  402. WHERE session_course_user.id_user = '.intval($a_infosUser['user_id']).'
  403. AND session_course_user.course_code = "'.Database::escape_string($_GET['course']).'"
  404. ORDER BY id_session DESC';
  405. $rs = api_sql_query($sql,__FILE__,__LINE__);
  406. $le_session_id = intval(Database::result($rs,0,0));
  407. if($le_session_id>0)
  408. {
  409. // get session name and coach of the session
  410. $sql = 'SELECT name, id_coach FROM '.$tbl_session.'
  411. WHERE id='.$le_session_id;
  412. $rs = api_sql_query($sql,__FILE__,__LINE__);
  413. $session_name = Database::result($rs,0,'name');
  414. $session_coach_id = intval(Database::result($rs,0,'id_coach'));
  415. // get coach of the course in the session
  416. $sql = 'SELECT id_coach FROM '.$tbl_session_course.'
  417. WHERE id_session='.$le_session_id.'
  418. AND course_code = "'.Database::escape_string($_GET['course']).'"';
  419. $rs = api_sql_query($sql,__FILE__,__LINE__);
  420. $session_course_coach_id = intval(Database::result($rs,0,0));
  421. if($session_course_coach_id!=0)
  422. {
  423. $coach_infos = UserManager :: get_user_info_by_id($session_course_coach_id);
  424. $a_infosCours['tutor_name'] = $coach_infos['firstname'].' '.$coach_infos['lastname'];
  425. }
  426. else if($session_coach_id!=0)
  427. {
  428. $coach_infos = UserManager :: get_user_info_by_id($session_coach_id);
  429. $a_infosCours['tutor_name'] = $coach_infos['firstname'].' '.$coach_infos['lastname'];
  430. }
  431. }
  432. } // end if(api_get_setting('use_session_mode')=='true')
  433. $a_date_start = explode('-',$a_infosCours['date_start']);
  434. $date_start = $a_date_start[2].'/'.$a_date_start[1].'/'.$a_date_start[0];
  435. $a_date_end = explode('-',$a_infosCours['date_end']);
  436. $date_end = $a_date_end[2].'/'.$a_date_end[1].'/'.$a_date_end[0];
  437. $dateSession = get_lang('From').' '.$date_start.' '.get_lang('To').' '.$date_end;
  438. $nb_login = Tracking :: count_login_per_student($a_infosUser['user_id'], $_GET['course']);
  439. $tableTitle = $a_infosCours['title'].'&nbsp;|&nbsp;'.get_lang('CountToolAccess').' : '.$nb_login.'&nbsp; | &nbsp;'.get_lang('Tutor').' : '.stripslashes($a_infosCours['tutor_name']).((!empty($session_name)) ? ' | '.get_lang('Session').' : '.$session_name : '');
  440. $csv_content[] = array();
  441. $csv_content[] = array(str_replace('&nbsp;','',$tableTitle));
  442. ?>
  443. <tr class="tableName">
  444. <td colspan="6">
  445. <strong><?php echo $tableTitle; ?></strong>
  446. </td>
  447. </tr>
  448. <tr> <!-- line about learnpaths -->
  449. <td>
  450. <table class="data_table">
  451. <tr>
  452. <th>
  453. <?php echo get_lang('Learnpaths'); ?>
  454. </th>
  455. <th>
  456. <?php echo get_lang('Time'); ?>
  457. </th>
  458. <th>
  459. <?php echo get_lang('Score'); ?>
  460. </th>
  461. <th>
  462. <?php echo get_lang('Progress'); ?>
  463. </th>
  464. <th>
  465. <?php echo get_lang('LastConnexion'); ?>
  466. </th>
  467. <th>
  468. <?php echo get_lang('Details'); ?>
  469. </th>
  470. </tr>
  471. <?php
  472. $a_headerLearnpath = array(get_lang('Learnpath'),get_lang('Time'),get_lang('Progress'),get_lang('LastConnexion'));
  473. $sqlLearnpath = " SELECT lp.name,lp.id
  474. FROM ".$a_infosCours['db_name'].".".$tbl_course_lp." AS lp ORDER BY lp.name ASC
  475. ";
  476. $resultLearnpath = api_sql_query($sqlLearnpath,__FILE__,__LINE__);
  477. $csv_content[] = array();
  478. $csv_content[] = array(get_lang('Learnpath'),get_lang('Time'),get_lang('Score'),get_lang('Progress'),get_lang('LastConnexion'));
  479. if(Database::num_rows($resultLearnpath)>0)
  480. {
  481. $i = 0;
  482. while($a_learnpath = Database::fetch_array($resultLearnpath))
  483. {
  484. $any_result = false;
  485. $progress = learnpath :: get_db_progress($a_learnpath['id'],$student_id, '%',$a_infosCours['db_name'],true);
  486. if($progress === null)
  487. {
  488. $progress = '0%';
  489. }
  490. else
  491. {
  492. $any_result = true;
  493. }
  494. // calculates time
  495. $sql = 'SELECT SUM(total_time)
  496. FROM '.$a_infosCours['db_name'].'.'.$tbl_course_lp_view_item.' AS item_view
  497. INNER JOIN '.$a_infosCours['db_name'].'.'.$tbl_course_lp_view.' AS view
  498. ON item_view.lp_view_id = view.id
  499. AND view.lp_id = '.$a_learnpath['id'].'
  500. AND view.user_id = '.intval($_GET['student']);
  501. $rs = api_sql_query($sql, __FILE__, __LINE__);
  502. $total_time = 0;
  503. if(Database::num_rows($rs)>0)
  504. {
  505. $total_time = Database::result($rs, 0, 0);
  506. if($total_time>0) $any_result = true;
  507. }
  508. // calculates last connection time
  509. $sql = 'SELECT MAX(start_time)
  510. FROM '.$a_infosCours['db_name'].'.'.$tbl_course_lp_view_item.' AS item_view
  511. INNER JOIN '.$a_infosCours['db_name'].'.'.$tbl_course_lp_view.' AS view
  512. ON item_view.lp_view_id = view.id
  513. AND view.lp_id = '.$a_learnpath['id'].'
  514. AND view.user_id = '.intval($_GET['student']);
  515. $rs = api_sql_query($sql, __FILE__, __LINE__);
  516. $start_time = null;
  517. if(Database::num_rows($rs)>0)
  518. {
  519. $start_time = Database::result($rs, 0, 0);
  520. if($start_time > 0) $any_result = true;
  521. }
  522. //QUIZZ IN LP
  523. $sql = 'SELECT id as item_id, max_score
  524. FROM '.$a_infosCours['db_name'].'.'.$tbl_course_lp_item.' AS lp_item
  525. WHERE lp_id='.$a_learnpath['id'].'
  526. AND item_type="quiz"';
  527. $rsItems = api_sql_query($sql, __FILE__, __LINE__);
  528. //We get the last view id of this LP
  529. $sql='SELECT max(id) as id FROM '.$a_infosCours['db_name'].'.'.$tbl_course_lp_view.' WHERE lp_id='.$a_learnpath['id'].' AND user_id="'.intval($_GET['student']).'"';
  530. $rs_last_lp_view_id = api_sql_query($sql, __FILE__, __LINE__);
  531. $lp_view_id = 0;
  532. if(Database::num_rows($rs_last_lp_view_id)>0)
  533. {
  534. $lp_view_id = Database::result($rs_last_lp_view_id,0,'id');
  535. if($lp_view_id > 0) $any_result = true;
  536. }
  537. $total_score = $total_weighting = 0;
  538. if($lp_view_id)
  539. {
  540. while($item = Database :: fetch_array($rsItems, 'ASSOC'))
  541. {
  542. $sql = 'SELECT score as student_score
  543. FROM '.$a_infosCours['db_name'].'.'.$tbl_course_lp_view_item.' as lp_view_item
  544. WHERE lp_view_item.lp_item_id = '.$item['item_id'].'
  545. AND lp_view_id = "'.$lp_view_id.'"';
  546. $rsScores = api_sql_query($sql, __FILE__, __LINE__);
  547. if (Database::num_rows($rsScores) > 0)
  548. {
  549. $total_score += Database::result($rsScores, 0, 0);
  550. }
  551. $total_weighting += $item['max_score'];
  552. }
  553. $any_result = true;
  554. }
  555. $sql = 'SELECT id, max_score
  556. FROM '.$a_infosCours['db_name'].'.'.$tbl_course_lp_item.' AS lp_item
  557. WHERE lp_id='.$a_learnpath['id'].'
  558. AND item_type="sco" LIMIT 1';
  559. $rs_lp_item_id_scorm = api_sql_query($sql, __FILE__, __LINE__);
  560. if(Database::num_rows($rs_lp_item_id_scorm)>0){
  561. $lp_item_id = Database::result($rs_lp_item_id_scorm,0,'id');
  562. $lp_item__max_score = Database::result($rs_lp_item_id_scorm,0,'max_score');
  563. $total_weighting+=$lp_item__max_score;
  564. //We get the last view id of this LP
  565. $sql='SELECT max(id) as id FROM '.$a_infosCours['db_name'].'.'.$tbl_course_lp_view.' WHERE lp_id='.$a_learnpath['id'].' AND user_id="'.intval($_GET['student']).'"';
  566. $rs_last_lp_view_id = api_sql_query($sql, __FILE__, __LINE__);
  567. $lp_view_id = Database::result($rs_last_lp_view_id,0,'id');
  568. $sql='SELECT SUM(score)/count(lp_item_id) as score FROM '.$a_infosCours['db_name'].'.'.$tbl_course_lp_view_item.' WHERE lp_view_id="'.$lp_view_id.'" GROUP BY lp_view_id';
  569. $rs_score = api_sql_query($sql, __FILE__, __LINE__);
  570. if(Database::num_rows($rs_score)>0)
  571. {
  572. $lp_scorm_score = Database::result($rs_score,0,'score');
  573. $total_score+=$lp_scorm_score;
  574. $any_result = true;
  575. }
  576. }
  577. $score = 0;
  578. if($total_weighting != 0)
  579. {
  580. $score = round($total_score / $total_weighting * 100,2);
  581. }
  582. if($i%2==0){
  583. $s_css_class="row_odd";
  584. }
  585. else{
  586. $s_css_class="row_even";
  587. }
  588. $i++;
  589. $csv_content[] = array(stripslashes($a_learnpath['name']),api_time_to_hms($total_time),$score.'%',$progress,date('Y-m-d',$start_time));
  590. ?>
  591. <tr class="<?php echo $s_css_class;?>">
  592. <td>
  593. <?php echo stripslashes($a_learnpath['name']); ?>
  594. </td>
  595. <td align="right">
  596. <?php echo api_time_to_hms($total_time) ?>
  597. </td>
  598. <td align="right">
  599. <?php echo $total_weighting>0 ? $score.'%' : '-' ?>
  600. </td>
  601. <td align="right">
  602. <?php echo $progress ?>
  603. </td>
  604. <td align="center">
  605. <?php if($start_time!='' && $start_time>0) echo format_locale_date(get_lang('DateFormatLongWithoutDay'),$start_time); else echo '-'; ?>
  606. </td>
  607. <td align="center">
  608. <?php
  609. if($any_result === true)
  610. {
  611. ?>
  612. <a href="lp_tracking.php?course=<?php echo $_GET['course'] ?>&origin=<?php echo $_GET['origin'] ?>&lp_id=<?php echo $a_learnpath['id']?>&student_id=<?php echo $a_infosUser['user_id'] ?>">
  613. <img src="../img/2rightarrow.gif" border="0" />
  614. </a>
  615. <?php
  616. }
  617. ?>
  618. </td>
  619. </tr>
  620. <?php
  621. $dataLearnpath[$i][] = $a_learnpath['name'];
  622. $dataLearnpath[$i][] = $progress.'%';
  623. $i++;
  624. }
  625. }
  626. else
  627. {
  628. echo " <tr>
  629. <td colspan='6'>
  630. ".get_lang('NoLearnpath')."
  631. </td>
  632. </tr>
  633. ";
  634. }
  635. ?>
  636. </table>
  637. </td>
  638. </tr>
  639. <tr> <!-- line about exercises -->
  640. <td>
  641. <table class="data_table">
  642. <tr>
  643. <th>
  644. <?php echo get_lang('Exercices'); ?>
  645. </th>
  646. <th>
  647. <?php echo get_lang('Score') ?>
  648. </th>
  649. <th>
  650. <?php echo get_lang('Attempts'); ?>
  651. </th>
  652. <th>
  653. <?php echo get_lang('CorrectTest'); ?>
  654. </th>
  655. </tr>
  656. <?php
  657. $csv_content[] = array();
  658. $csv_content[] = array(get_lang('Exercices'),get_lang('Score'),get_lang('Attempts'));
  659. $a_infosCours = CourseManager :: get_course_information($_GET['course']);
  660. $sql='SELECT visibility FROM '.$a_infosCours['db_name'].'.'.TABLE_TOOL_LIST.' WHERE name="quiz"';
  661. $resultVisibilityQuizz = api_sql_query($sql,__FILE__,__LINE__);
  662. if(Database::result($resultVisibilityQuizz,0,'visibility')==1){
  663. $sqlExercices = " SELECT quiz.title,id
  664. FROM ".$a_infosCours['db_name'].".".$tbl_course_quiz." AS quiz
  665. WHERE active='1' ORDER BY quiz.title ASC
  666. ";
  667. $resultExercices = api_sql_query($sqlExercices,__FILE__,__LINE__);
  668. $i = 0;
  669. if(Database::num_rows($resultExercices)>0)
  670. {
  671. while($a_exercices = Database::fetch_array($resultExercices))
  672. {
  673. $sqlEssais = " SELECT COUNT(ex.exe_id) as essais
  674. FROM $tbl_stats_exercices AS ex
  675. WHERE ex.exe_cours_id = '".$a_infosCours['code']."'
  676. AND ex.exe_exo_id = ".$a_exercices['id']."
  677. AND exe_user_id='".$_GET["student"]."'"
  678. ;
  679. $resultEssais = api_sql_query($sqlEssais,__FILE__,__LINE__);
  680. $a_essais = Database::fetch_array($resultEssais);
  681. $sqlScore = "SELECT exe_id, exe_result,exe_weighting
  682. FROM $tbl_stats_exercices
  683. WHERE exe_user_id = ".$_GET['student']."
  684. AND exe_cours_id = '".$a_infosCours['code']."'
  685. AND exe_exo_id = ".$a_exercices['id']."
  686. ORDER BY exe_date DESC LIMIT 1";
  687. $resultScore = api_sql_query($sqlScore,__FILE__,__LINE__);
  688. $score = 0;
  689. while($a_score = Database::fetch_array($resultScore))
  690. {
  691. $score = $score + $a_score['exe_result'];
  692. $weighting = $weighting + $a_score['exe_weighting'];
  693. $exe_id = $a_score['exe_id'];
  694. }
  695. $pourcentageScore = 0;
  696. if($weighting!=0)
  697. {
  698. $pourcentageScore = round(($score*100)/$weighting);
  699. }
  700. $weighting = 0;
  701. $csv_content[] = array($a_exercices['title'], $pourcentageScore.' %', $a_essais['essais']);
  702. if($i%2==0){
  703. $s_css_class="row_odd";
  704. }
  705. else{
  706. $s_css_class="row_even";
  707. }
  708. $i++;
  709. echo "<tr class='$s_css_class'>
  710. <td>
  711. ";
  712. echo $a_exercices['title'];
  713. echo " </td>
  714. ";
  715. echo " <td align='right'>
  716. ";
  717. echo $pourcentageScore.' %';
  718. echo " </td>
  719. <td align='right'>
  720. ";
  721. echo $a_essais['essais'];
  722. echo " </td>
  723. <td align='center'>
  724. ";
  725. $sql_last_attempt='SELECT exe_id FROM '.$tbl_stats_exercices.' WHERE exe_exo_id="'.$a_exercices['id'].'" AND exe_user_id="'.$_GET['student'].'" AND exe_cours_id="'.$a_infosCours['code'].'" ORDER BY exe_date DESC LIMIT 1';
  726. $resultLastAttempt = api_sql_query($sql_last_attempt,__FILE__,__LINE__);
  727. if(Database::num_rows($resultLastAttempt)>0)
  728. {
  729. $id_last_attempt=Database::result($resultLastAttempt,0,0);
  730. if($a_essais['essais']>0)
  731. echo '<a href="../exercice/exercise_show.php?id='.$id_last_attempt.'&cidReq='.$a_infosCours['code'].'&student='.$_GET['student'].'&origin='.(empty($_GET['origin']) ? 'tracking' : $_GET['origin']).'"> <img src="'.api_get_path(WEB_IMG_PATH).'quiz.gif" border="0"> </a>';
  732. }
  733. echo " </td>
  734. </tr>
  735. ";
  736. $dataExercices[$i][] = $a_exercices['title'];
  737. $dataExercices[$i][] = $pourcentageScore.'%';
  738. $dataExercices[$i][] = $a_essais['essais'];
  739. //$dataExercices[$i][] = corrections;
  740. $i++;
  741. }
  742. }
  743. else
  744. {
  745. echo " <tr>
  746. <td colspan='6'>
  747. ".get_lang('NoExercise')."
  748. </td>
  749. </tr>
  750. ";
  751. }
  752. }
  753. else
  754. {
  755. echo " <tr>
  756. <td colspan='6'>
  757. ".get_lang('NoExercise')."
  758. </td>
  759. </tr>
  760. ";
  761. }
  762. ?>
  763. </table>
  764. </td>
  765. </tr>
  766. <tr><!-- line about other tools -->
  767. <td>
  768. <table class="data_table">
  769. <?php
  770. $csv_content[] = array();
  771. $nb_assignments = Tracking :: count_student_assignments($a_infosUser['user_id'], $a_infosCours['code']);
  772. $messages = Tracking :: count_student_messages($a_infosUser['user_id'], $a_infosCours['code']);
  773. $links = Tracking :: count_student_visited_links($a_infosUser['user_id'], $a_infosCours['code']);
  774. $documents = Tracking :: count_student_downloaded_documents($a_infosUser['user_id'], $a_infosCours['code']);
  775. $csv_content[] = array(get_lang('Student_publication'), $nb_assignments);
  776. $csv_content[] = array(get_lang('Messages'), $messages);
  777. $csv_content[] = array(get_lang('LinksDetails'), $links);
  778. $csv_content[] = array(get_lang('DocumentsDetails'), $documents);
  779. ?>
  780. <tr>
  781. <th colspan="2">
  782. <?php echo get_lang('OtherTools'); ?>
  783. </th>
  784. </tr>
  785. <tr><!-- assignments -->
  786. <td width="40%">
  787. <?php echo get_lang('Student_publication') ?>
  788. </td>
  789. <td>
  790. <?php echo $nb_assignments ?>
  791. </td>
  792. </tr>
  793. <tr><!-- messages -->
  794. <td>
  795. <?php echo get_lang('Messages') ?>
  796. </td>
  797. <td>
  798. <?php echo $messages ?>
  799. </td>
  800. </tr>
  801. <tr><!-- links -->
  802. <td>
  803. <?php echo get_lang('LinksDetails') ?>
  804. </td>
  805. <td>
  806. <?php echo $links ?>
  807. </td>
  808. </tr>
  809. <tr><!-- documents -->
  810. <td>
  811. <?php echo get_lang('DocumentsDetails') ?>
  812. </td>
  813. <td>
  814. <?php echo $documents ?>
  815. </td>
  816. </tr>
  817. </table>
  818. </td>
  819. </tr>
  820. </table>
  821. <?php
  822. }
  823. else
  824. {
  825. ?>
  826. <tr>
  827. <th>
  828. <?php echo get_lang('Course'); ?>
  829. </th>
  830. <th>
  831. <?php echo get_lang('Time'); ?>
  832. </th>
  833. <th>
  834. <?php echo get_lang('Progress'); ?>
  835. </th>
  836. <th>
  837. <?php echo get_lang('Score'); ?>
  838. </th>
  839. <th>
  840. <?php echo get_lang('Details'); ?>
  841. </th>
  842. </tr>
  843. <?php
  844. if(!api_is_platform_admin(true) && $_user['status']!=DRH){
  845. // courses followed by user where we are coach
  846. if(!isset($_GET['id_coach'])){
  847. $a_courses = Tracking :: get_courses_followed_by_coach($_user['user_id']);
  848. }
  849. else{
  850. $a_courses = Tracking :: get_courses_followed_by_coach($_GET['id_coach']);
  851. }
  852. }
  853. if(count($a_courses)>0)
  854. {
  855. $csv_content[] = array();
  856. $csv_content[] = array(get_lang('Course'),get_lang('Time'),get_lang('Progress'),get_lang('Score'));
  857. foreach($a_courses as $course_code)
  858. {
  859. if(CourseManager :: is_user_subscribed_in_course($student_id,$course_code, true)){
  860. $course_infos = CourseManager :: get_course_information($course_code);
  861. $time_spent_on_course = api_time_to_hms(Tracking :: get_time_spent_on_the_course($a_infosUser['user_id'], $course_code));
  862. $progress = Tracking :: get_avg_student_progress($a_infosUser['user_id'], $course_code).' %';
  863. $score = Tracking :: get_avg_student_score($a_infosUser['user_id'], $course_code).' %';
  864. $csv_content[] = array($course_infos['title'], $time_spent_on_course, $progress, $score);
  865. echo '
  866. <tr>
  867. <td align="right">
  868. '.$course_infos['title'].'
  869. </td>
  870. <td align="right">
  871. '.$time_spent_on_course.'
  872. </td>
  873. <td align="right">
  874. '.$progress.'
  875. </td>
  876. <td align="right">
  877. '.$score.'
  878. </td>';
  879. if(isset($_GET['id_coach']) && intval($_GET['id_coach'])!=0){
  880. echo '<td align="center" width="10">
  881. <a href="'.api_get_self().'?student='.$a_infosUser['user_id'].'&details=true&course='.$course_infos['code'].'&id_coach='.$_GET['id_coach'].'#infosStudent"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>
  882. </td>';
  883. }
  884. else{
  885. echo '<td align="center" width="10">
  886. <a href="'.api_get_self().'?student='.$a_infosUser['user_id'].'&details=true&course='.$course_infos['code'].'#infosStudent"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>
  887. </td>';
  888. }
  889. echo '</tr>';
  890. }
  891. }
  892. }
  893. else
  894. {
  895. echo "<tr>
  896. <td colspan='5'>
  897. ".get_lang('NoCourse')."
  898. </td>
  899. </tr>
  900. ";
  901. }
  902. }//end of else !empty($details)
  903. ?>
  904. </table>
  905. <br />
  906. <?php
  907. if(!empty($_GET['details']) && $_GET['origin'] != 'tracking_course' && $_GET['origin'] != 'user_course')
  908. {
  909. ?>
  910. <br /><br />
  911. <?php
  912. }
  913. if(!empty($_GET['exe_id']))
  914. {
  915. $sqlExerciceDetails = " SELECT qq.question, qq.ponderation, qq.id
  916. FROM ".$a_infosCours['db_name'].".".$course_quiz_question." as qq
  917. INNER JOIN ".$a_infosCours['db_name'].".".$course_quiz_rel_question." as qrq
  918. ON qrq.question_id = qq.id
  919. AND qrq.exercice_id = ".$_GET['exe_id']
  920. ;
  921. $resultExerciceDetails = api_sql_query($sqlExerciceDetails,__FILE__,__LINE__);
  922. $sqlExName = " SELECT quiz.title
  923. FROM ".$a_infosCours['db_name'].".".$tbl_course_quiz." AS quiz
  924. WHERE quiz.id = ".$_GET['exe_id']
  925. ;
  926. $resultExName = api_sql_query($sqlExName,__FILE__,__LINE__);
  927. $a_exName = Database::fetch_array($resultExName);
  928. echo "<table class='data_table'>
  929. <tr>
  930. <th colspan='2'>
  931. ".$a_exName['title']."
  932. </th>
  933. </tr>
  934. ";
  935. while($a_exerciceDetails = Database::fetch_array($resultExerciceDetails))
  936. {
  937. $sqlAnswer = " SELECT qa.comment, qa.answer
  938. FROM ".$a_infosCours['db_name'].".".$course_quiz_answer." as qa
  939. WHERE qa.question_id = ".$a_exerciceDetails['id']
  940. ;
  941. $resultAnswer = api_sql_query($sqlAnswer,__FILE__,__LINE__);
  942. echo "<a name='infosExe'></a>";
  943. echo"
  944. <tr>
  945. <td colspan='2'>
  946. <strong>".$a_exerciceDetails['question'].' /'.$a_exerciceDetails['ponderation']."</strong>
  947. </td>
  948. </tr>
  949. ";
  950. while($a_answer = Database::fetch_array($resultAnswer))
  951. {
  952. echo"
  953. <tr>
  954. <td>
  955. ".$a_answer['answer']."
  956. </td>
  957. <td>
  958. ";
  959. if(!empty($a_answer['comment']))
  960. echo $a_answer['comment'];
  961. else
  962. echo get_lang('NoComment');
  963. echo "
  964. </td>
  965. </tr>
  966. ";
  967. }
  968. }
  969. echo "</table>";
  970. }
  971. //YW - commented out because it doesn't seem to be used
  972. //$a_header = array_merge($a_headerLearnpath,$a_headerExercices,$a_headerProductions);
  973. }
  974. if($export_csv)
  975. {
  976. ob_end_clean();
  977. Export :: export_table_csv($csv_content, 'reporting_student');
  978. }
  979. /*
  980. ==============================================================================
  981. FOOTER
  982. ==============================================================================
  983. */
  984. Display::display_footer();
  985. ?>