access_details.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. // $Id:
  3. /*
  4. ==============================================================================
  5. Dokeos - elearning and course management software
  6. Copyright (c) 2008 Furio Petrossi
  7. Copyright (c) 2008 Dokeos SPRL
  8. For a full list of contributors, see "credits.txt".
  9. The full license can be read in "license.txt".
  10. This program is free software; you can redistribute it and/or
  11. modify it under the terms of the GNU General Public License
  12. as published by the Free Software Foundation; either version 2
  13. of the License, or (at your option) any later version.
  14. See the GNU General Public License for more details.
  15. Contact: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium, info@dokeos.com
  16. ==============================================================================
  17. */
  18. /**
  19. ==============================================================================
  20. * This is the tracking library for Dokeos.
  21. * Include/require it in your code to use its functionality.
  22. *
  23. * @package dokeos.library
  24. ==============================================================================
  25. * Calculates the time spent on the course
  26. * @param integer $user_id the user id
  27. * @param string $course_code the course code
  28. * Funzione scritta da Mario per testare cose
  29. */
  30. $language_file = array ('registration', 'index', 'tracking');
  31. require_once('../inc/global.inc.php');
  32. /**
  33. * Gets the connections to a course as an array of login and logout time
  34. */
  35. function get_connections_to_course($user_id, $course_code) {
  36. $course_code = Database::escape_string($course_code);
  37. $tbl_track_course = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  38. $sql = 'SELECT login_course_date, logout_course_date FROM ' . $tbl_track_course . '
  39. WHERE user_id = ' . intval($user_id) . '
  40. AND course_code="' . $course_code . '"ORDER BY login_course_date';
  41. $rs = api_sql_query($sql);
  42. $connections = array();
  43. while ($a_connections = Database::fetch_array($rs)) {
  44. $s_login_date = $a_connections['login_course_date'];
  45. $s_logout_date = $a_connections['logout_course_date'];
  46. $i_timestamp_login_date = strtotime($s_login_date);
  47. $i_timestamp_logout_date = strtotime($s_logout_date);
  48. $connections[] = array('login'=>$i_timestamp_login_date, 'logout'=>$i_timestamp_logout_date);
  49. }
  50. return $connections;
  51. }
  52. /**
  53. * Transforms seconds into a time format
  54. */
  55. function calculHours($seconds)
  56. {
  57. //How many hours ?
  58. $hours = floor($seconds / 3600);
  59. //How many minutes ?
  60. $min = floor(($seconds - ($hours * 3600)) / 60);
  61. if ($min < 10)
  62. $min = '0'.$min;
  63. //How many seconds
  64. $sec = $seconds - ($hours * 3600) - ($min * 60);
  65. if ($sec < 10)
  66. $sec = '0'.$sec;
  67. return $hours.get_lang('HourShort').' '.$min.':'.$sec;
  68. }
  69. /* MAIN */
  70. //Print headers
  71. $nameTools= get_lang('AccessDetails');
  72. Display :: display_header($nameTools);
  73. $user_id = (int)$_REQUEST['student'];
  74. $course_code=Database::escape_string($_REQUEST['course']);
  75. $TBL_USERINFO_DEF = Database :: get_course_table(TABLE_USER_INFO);
  76. $mainUserInfo = api_get_user_info($user_id, $course_code);
  77. echo '<strong>',get_lang('User'),': ',$mainUserInfo['firstName'],' ',$mainUserInfo['lastName'],'</strong> <br />';
  78. $connections = get_connections_to_course($user_id, $course_code);
  79. echo '<strong>'.get_lang('Course').': ',$course_code,' - ',$_course['name'],'</strong><br />';
  80. echo '<strong>',get_lang('DateAndTimeOfAccess'),' - ',get_lang('Duration'),'</strong><br />';
  81. /* Login time against logout time
  82. foreach ($connections as $key=>$data)
  83. {
  84. echo ("<tr><td>".date("d-m-Y (H:i:s)",$data['login'])."</td><td>".date("d-m-Y (H:i:s)",$data['logout'])."</td></tr>");
  85. }
  86. */
  87. /*
  88. foreach ($connections as $key=>$data)
  89. {
  90. echo ("<tr><td>".date("d-m-Y (H:i:s)",$data['login'])."</td><td>".calculHours($data['logout']-$data['login'])."</td></tr>");
  91. }
  92. echo ("</table>");
  93. */
  94. foreach ($connections as $key=>$data)
  95. {
  96. echo '&nbsp;&nbsp;'.date('d-m-Y (H:i:s)',$data['login']).' - '.calculHours($data['logout']-$data['login']).'<br />'."\n";
  97. }
  98. Display:: display_footer();
  99. ?>