myStudents.php 35 KB

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