access_details.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. <?php
  2. // $Id:
  3. /*
  4. ==============================================================================
  5. Dokeos - elearning and course management software
  6. Copyright (c) 2009 Dokeos SPRL
  7. Copyright (c) 2008 Furio Petrossi
  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. // name of the language file that needs to be included
  31. $language_file = array ('registration', 'index', 'tracking');
  32. // including the global Dokeos file
  33. require '../inc/global.inc.php';
  34. // including additional libraries
  35. require_once api_get_path(LIBRARY_PATH).'pchart/pData.class.php';
  36. require_once api_get_path(LIBRARY_PATH).'pchart/pChart.class.php';
  37. require_once api_get_path(LIBRARY_PATH).'pchart/pCache.class.php';
  38. // the section (for the tabs)
  39. $this_section = "session_my_space";
  40. /* MAIN */
  41. $user_id = Security::remove_XSS($_REQUEST['student']);
  42. $course_code = Security::remove_XSS($_REQUEST['course']);
  43. $connections = get_connections_to_course($user_id, $course_code);
  44. if (api_is_xml_http_request()) {
  45. $type = Security::remove_XSS($_GET['type']);
  46. $main_year = $main_month_year = $main_day = array();
  47. // get last 8 days/months
  48. $last_days = 8;
  49. $last_months = 5;
  50. for ($i = $last_days; $i >= 0; $i--) {
  51. $main_day[date ('d-m-Y', mktime () - $i * 3600 * 24)] = 0;
  52. }
  53. for ($i = $last_months; $i >= 0; $i--) {
  54. $main_month_year[date ('m-Y', mktime () - $i * 30 * 3600 * 24)] = 0;
  55. }
  56. $i = 0;
  57. if (is_array($connections) && count($connections) > 0) {
  58. foreach ($connections as $key => $data) {
  59. //creating the main array
  60. $main_month_year[date('m-Y', $data['login'])] += float_format(($data['logout'] - $data['login']) / 60, 0);
  61. $main_day[date('d-m-Y', $data['login'])] += float_format(($data['logout'] - $data['login']) / 60, 0);
  62. if ($i > 500) {
  63. break;
  64. }
  65. $i++;
  66. }
  67. switch ($type) {
  68. case 'day':
  69. $main_date = $main_day;
  70. break;
  71. case 'month':
  72. $main_date = $main_month_year;
  73. break;
  74. case 'year':
  75. $main_date = $main_year;
  76. break;
  77. }
  78. // the nice graphics :D
  79. $labels = array_keys($main_date);
  80. if (count($main_date) == 1) {
  81. $labels = $labels[0];
  82. $main_date = $main_date[$labels];
  83. }
  84. $DataSet = new pData;
  85. $DataSet->AddPoint($main_date, 'Q');
  86. if (count($main_date)!= 1) {
  87. $DataSet->AddPoint($labels, 'Date');
  88. }
  89. $DataSet->AddAllSeries();
  90. $DataSet->RemoveSerie('Date');
  91. $DataSet->SetAbsciseLabelSerie('Date');
  92. $DataSet->SetYAxisName(get_lang('Minutes', ''));
  93. $graph_id = api_get_user_id().'AccessDetails'.api_get_course_id();
  94. $DataSet->AddAllSeries();
  95. $Cache = new pCache();
  96. // the graph id
  97. $data = $DataSet->GetData();
  98. if ($Cache->IsInCache($graph_id, $DataSet->GetData())) {
  99. //if (0) {
  100. //if we already created the img
  101. // echo 'in cache';
  102. $img_file = $Cache->GetHash($graph_id, $DataSet->GetData());
  103. } else {
  104. // if the image does not exist in the archive/ folder
  105. // Initialise the graph
  106. $Test = new pChart(760, 230);
  107. //which schema of color will be used
  108. $quant_resources = count($data[0]) - 1;
  109. // Adding the color schemma
  110. $Test->loadColorPalette(api_get_path(LIBRARY_PATH).'pchart/palette/default.txt');
  111. $Test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf', 8);
  112. $Test->setGraphArea(70, 30, 680, 200);
  113. $Test->drawFilledRoundedRectangle(7, 7, 693, 223, 5, 240, 240, 240);
  114. $Test->drawRoundedRectangle(5, 5, 695, 225, 5, 230, 230, 230);
  115. $Test->drawGraphArea(255, 255, 255, TRUE);
  116. $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_START0, 150, 150, 150, TRUE, 0, 0);
  117. $Test->drawGrid(4, TRUE, 230, 230, 230, 50);
  118. $Test->setLineStyle(2);
  119. // Draw the 0 line
  120. $Test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf', 6);
  121. $Test->drawTreshold(0, 143, 55, 72, TRUE, TRUE);
  122. if (count($main_date) == 1) {
  123. //Draw a graph
  124. echo '<strong>'.$labels.'</strong><br/>';
  125. $Test->drawBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), TRUE);
  126. } else {
  127. //Draw the line graph
  128. $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription());
  129. $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 2, 255, 255, 255);
  130. }
  131. // Finish the graph
  132. $Test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf', 8);
  133. $Test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf', 10);
  134. $Test->drawTitle(60, 22, get_lang('AccessDetails', ''), 50, 50, 50, 585);
  135. //------------------
  136. //echo 'not in cache';
  137. $Cache->WriteToCache($graph_id, $DataSet->GetData(), $Test);
  138. ob_start();
  139. $Test->Stroke();
  140. ob_end_clean();
  141. $img_file = $Cache->GetHash($graph_id, $DataSet->GetData());
  142. }
  143. echo '<img src="'.api_get_path(WEB_ARCHIVE_PATH).$img_file.'">';
  144. } else {
  145. Display::display_warning_message (get_lang('GraphicNotAvailable'));
  146. }
  147. exit;
  148. }
  149. $nameTools = get_lang('AccessDetails');
  150. //StudentDetails
  151. if (isset($_GET['origin']) && strcmp($_GET['origin'], 'tracking_course') === 0) {
  152. $interbreadcrumb[] = array ("url" => "../tracking/courseLog.php?cidReq=".Security::remove_XSS($_GET['course'])."&amp;studentlist=true&id_session=".api_get_session_id(), "name" => get_lang("Tracking"));
  153. $interbreadcrumb[] = array ("url" => "myStudents.php?student=".Security::remove_XSS($_GET['student'])."&details=true&origin=".Security::remove_XSS($_GET['origin'])."&amp;course=".Security::remove_XSS($_GET['course']).'&amp;cidReq='.Security::remove_XSS($_GET['course']), "name" => get_lang('DetailsStudentInCourse'));
  154. $interbreadcrumb[] = array ("url" => "javascript: void(0);", "name" => get_lang("Details"));
  155. } elseif (isset($_GET['origin']) && strcmp($_GET['origin'], 'user_course') === 0) {
  156. $interbreadcrumb[] = array ("url" => "../user/user.php?cidReq=".Security::remove_XSS($_GET['course']), "name" => get_lang("Users"));
  157. $interbreadcrumb[] = array ("url" => "myStudents.php?student=".Security::remove_XSS($_GET['student'])."&details=true&origin=".Security::remove_XSS($_GET['origin'])."&amp;course=".Security::remove_XSS($_GET['course']).'&amp;cidReq='.Security::remove_XSS($_GET['course']), "name" => get_lang('DetailsStudentInCourse'));
  158. $interbreadcrumb[] = array ("url" => "javascript: void(0);", "name" => get_lang("Details"));
  159. }
  160. $htmlHeadXtra[] = '<script src="../inc/lib/javascript/jquery.js" type="text/javascript" language="javascript"></script>'; //jQuery
  161. $htmlHeadXtra[] = '<script src="../inc/lib/javascript/jquery-1.1.3.1.pack.js" type="text/javascript"></script>';
  162. $htmlHeadXtra[] = '<script src="../inc/lib/javascript/jquery.history_remote.pack.js" type="text/javascript"></script>';
  163. $htmlHeadXtra[] = '<script src="../inc/lib/javascript/jquery.tabs.pack.js" type="text/javascript"></script>';
  164. $htmlHeadXtra[] = '<link rel="stylesheet" href="../inc/lib/javascript/jquery.tabs.css" type="text/css" media="print, projection, screen">';
  165. $htmlHeadXtra[] = '<script type="text/javascript">
  166. $(function() {
  167. $("#container-9").tabs({ remote: true});
  168. });
  169. </script>';
  170. Display :: display_header('');
  171. $TBL_USERINFO_DEF = Database :: get_course_table(TABLE_USER_INFO);
  172. $mainUserInfo = api_get_user_info($user_id);
  173. $result_to_print = '';
  174. $main_date_array = array();
  175. foreach ($connections as $key => $data) {
  176. $result_to_print .= '&nbsp;&nbsp;'.date('d-m-Y (H:i:s)', $data['login']).' - '.api_time_to_hms($data['logout'] - $data['login']).'<br />'."\n";
  177. }
  178. api_display_tool_title(get_lang('DetailsStudentInCourse'));
  179. echo '<div class="actions">';
  180. echo '<strong>'.get_lang('User').': '.api_get_person_name($mainUserInfo['firstName'], $mainUserInfo['lastName']).'</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>'.get_lang('Course').': '.$course_code.'</strong></div>';
  181. ?>
  182. <div id="container-9">
  183. <ul>
  184. <li><a href="access_details.php?type=day&course=<?php echo $course_code?>&student=<?php echo $user_id?>"><span> <?php echo api_ucfirst(get_lang('Day')); ?></span></a></li>
  185. <li><a href="access_details.php?type=month&course=<?php echo $course_code?>&student=<?php echo $user_id?>"><span><?php echo api_ucfirst(get_lang('MinMonth')); ?></span></a></li>
  186. </ul>
  187. <?php echo '<div id="show"></div>'; ?>
  188. </div>
  189. <?php
  190. echo '<div id="graph"></div><br />';
  191. echo '<div class="actions"><strong>', get_lang('DateAndTimeOfAccess'), ' - ', get_lang('Duration'), '</strong></div><br />';
  192. echo $result_to_print;
  193. /* Login time against logout time
  194. foreach ($connections as $key => $data) {
  195. 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>");
  196. }
  197. */
  198. /*
  199. foreach ($connections as $key => $data) {
  200. echo ("<tr><td>".date("d-m-Y (H:i:s)", $data['login'])."</td><td>".api_time_to_hms($data['logout'] - $data['login'])."</td></tr>");
  201. }
  202. echo ("</table>");
  203. */
  204. Display:: display_footer();
  205. /*
  206. -----------------------------------------------------------
  207. Functions
  208. -----------------------------------------------------------
  209. */
  210. /**
  211. * Gets the connections to a course as an array of login and logout time
  212. *
  213. * @param unknown_type $user_id
  214. * @param unknown_type $course_code
  215. * @return unknown
  216. */
  217. function get_connections_to_course($user_id, $course_code) {
  218. // Database table definitions
  219. $tbl_track_course = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  220. $tbl_main = Database :: get_main_table(TABLE_MAIN_COURSE);
  221. $sql_query = 'SELECT visual_code as course_code FROM '.$tbl_main.' c WHERE code="'.Database::escape_string($course_code).'";';
  222. $result = Database::query($sql_query, __FILE__, __LINE__);
  223. $row_query = Database::fetch_array($result, 'ASSOC');
  224. $course_true = isset($row_query['course_code']) ? $row_query['course_code']: $course_code;
  225. $sql = 'SELECT login_course_date, logout_course_date FROM ' . $tbl_track_course . '
  226. WHERE user_id = ' . intval($user_id) . '
  227. AND course_code="' . Database::escape_string($course_true) . '" ORDER BY login_course_date ASC';
  228. $rs = Database::query($sql, __FILE__, __LINE__);
  229. $connections = array();
  230. while ($row = Database::fetch_array($rs)) {
  231. $login_date = $row['login_course_date'];
  232. $logout_date = $row['logout_course_date'];
  233. $timestamp_login_date = strtotime($login_date);
  234. $timestamp_logout_date = strtotime($logout_date);
  235. $connections[] = array('login' => $timestamp_login_date, 'logout' => $timestamp_logout_date);
  236. }
  237. return $connections;
  238. }
  239. /**
  240. * TODO: Not used, to b deleted?
  241. * Enter description here...
  242. *
  243. * @param unknown_type $user_id
  244. * @param unknown_type $course_code
  245. * @param unknown_type $year
  246. * @param unknown_type $month
  247. * @param unknown_type $day
  248. * @return unknown
  249. */
  250. function get_connections_to_course_by_time($user_id, $course_code, $year = '', $month = '', $day = '') {
  251. // Database table definitions
  252. $tbl_track_course = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  253. $tbl_main = Database :: get_main_table(TABLE_MAIN_COURSE);
  254. $sql_query = 'SELECT visual_code as course_code FROM '.$tbl_main.' c WHERE code="'.Database :: escape_string($course_code).'";';
  255. $result = Database::query($sql_query, __FILE__, __LINE__);
  256. $row_query = Database::fetch_array($result,'ASSOC');
  257. $course_true = isset($row_query['course_code']) ? $row_query['course_code']: $course_code;
  258. $sql = 'SELECT login_course_date, logout_course_date FROM ' . $tbl_track_course . '
  259. WHERE user_id = ' . intval($user_id) . '
  260. AND course_code="' . Database::escape_string($course_true) . '"
  261. ORDER BY login_course_date DESC';
  262. $rs = Database::query($sql, __FILE__, __LINE__);
  263. $connections = array();
  264. while ($row = Database::fetch_array($rs)) {
  265. $login_date = $row['login_course_date'];
  266. $logout_date = $row['logout_course_date'];
  267. $timestamp_login_date = strtotime($login_date);
  268. $timestamp_logout_date = strtotime($logout_date);
  269. $connections[] = array('login' => $timestamp_login_date, 'logout' => $timestamp_logout_date);
  270. }
  271. return $connections;
  272. }