access_details.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This is the tracking library for Dokeos.
  5. * Include/require it in your code to use its functionality.
  6. *
  7. * @package chamilo.library
  8. *
  9. * Calculates the time spent on the course
  10. * @param integer $user_id the user id
  11. * @param string $course_code the course code
  12. * @author Mario per testare cose
  13. * @author Julio Montoya <gugli100@gmail.col>
  14. *
  15. */
  16. // name of the language file that needs to be included
  17. $language_file = array ('registration', 'index', 'tracking');
  18. // including the global Dokeos file
  19. require_once '../inc/global.inc.php';
  20. // including additional libraries
  21. require_once api_get_path(LIBRARY_PATH).'pchart/pData.class.php';
  22. require_once api_get_path(LIBRARY_PATH).'pchart/pChart.class.php';
  23. require_once api_get_path(LIBRARY_PATH).'pchart/pCache.class.php';
  24. require_once 'myspace.lib.php';
  25. // the section (for the tabs)
  26. $this_section = SECTION_TRACKING;
  27. /* MAIN */
  28. $user_id = intval($_REQUEST['student']);
  29. $session_id = intval($_GET['id_session']);
  30. $course_code = Security::remove_XSS($_REQUEST['course']);
  31. $connections = MySpace::get_connections_to_course($user_id, $course_code, $session_id);
  32. if (api_is_xml_http_request()) {
  33. $type = Security::remove_XSS($_GET['type']);
  34. $main_year = $main_month_year = $main_day = array();
  35. // get last 8 days/months
  36. $last_days = 8;
  37. $last_months = 5;
  38. for ($i = $last_days; $i >= 0; $i--) {
  39. $main_day[date ('d-m-Y', mktime () - $i * 3600 * 24)] = 0;
  40. }
  41. for ($i = $last_months; $i >= 0; $i--) {
  42. $main_month_year[date ('m-Y', mktime () - $i * 30 * 3600 * 24)] = 0;
  43. }
  44. $i = 0;
  45. if (is_array($connections) && count($connections) > 0) {
  46. foreach ($connections as $key => $data) {
  47. //creating the main array
  48. $main_month_year[date('m-Y', $data['login'])] += float_format(($data['logout'] - $data['login']) / 60, 0);
  49. $main_day[date('d-m-Y', $data['login'])] += float_format(($data['logout'] - $data['login']) / 60, 0);
  50. if ($i > 500) {
  51. break;
  52. }
  53. $i++;
  54. }
  55. switch ($type) {
  56. case 'day':
  57. $main_date = $main_day;
  58. break;
  59. case 'month':
  60. $main_date = $main_month_year;
  61. break;
  62. case 'year':
  63. $main_date = $main_year;
  64. break;
  65. }
  66. // the nice graphics :D
  67. $labels = array_keys($main_date);
  68. if (count($main_date) == 1) {
  69. $labels = $labels[0];
  70. $main_date = $main_date[$labels];
  71. }
  72. $data_set = new pData;
  73. $data_set->AddPoint($main_date, 'Q');
  74. if (count($main_date)!= 1) {
  75. $data_set->AddPoint($labels, 'Date');
  76. }
  77. $data_set->AddAllSeries();
  78. $data_set->RemoveSerie('Date');
  79. $data_set->SetAbsciseLabelSerie('Date');
  80. $data_set->SetYAxisName(get_lang('Minutes', ''));
  81. $graph_id = api_get_user_id().'AccessDetails'.api_get_course_id();
  82. $data_set->AddAllSeries();
  83. $cache = new pCache();
  84. // the graph id
  85. $data = $data_set->GetData();
  86. if ($cache->IsInCache($graph_id, $data_set->GetData())) {
  87. //if (0) {
  88. //if we already created the img
  89. // echo 'in cache';
  90. $img_file = $cache->GetHash($graph_id, $data_set->GetData());
  91. } else {
  92. // if the image does not exist in the archive/ folder
  93. // Initialise the graph
  94. $test = new pChart(760, 230);
  95. //which schema of color will be used
  96. $quant_resources = count($data[0]) - 1;
  97. // Adding the color schemma
  98. $test->loadColorPalette(api_get_path(LIBRARY_PATH).'pchart/palette/default.txt');
  99. $test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf', 8);
  100. $test->setGraphArea(70, 30, 680, 200);
  101. $test->drawFilledRoundedRectangle(7, 7, 693, 223, 5, 240, 240, 240);
  102. $test->drawRoundedRectangle(5, 5, 695, 225, 5, 230, 230, 230);
  103. $test->drawGraphArea(255, 255, 255, TRUE);
  104. $test->drawScale($data_set->GetData(), $data_set->GetDataDescription(), SCALE_START0, 150, 150, 150, TRUE, 0, 0);
  105. $test->drawGrid(4, TRUE, 230, 230, 230, 50);
  106. $test->setLineStyle(2);
  107. // Draw the 0 line
  108. $test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf', 6);
  109. $test->drawTreshold(0, 143, 55, 72, TRUE, TRUE);
  110. if (count($main_date) == 1) {
  111. //Draw a graph
  112. echo '<strong>'.$labels.'</strong><br/>';
  113. $test->drawBarGraph($data_set->GetData(), $data_set->GetDataDescription(), TRUE);
  114. } else {
  115. //Draw the line graph
  116. $test->drawLineGraph($data_set->GetData(), $data_set->GetDataDescription());
  117. $test->drawPlotGraph($data_set->GetData(), $data_set->GetDataDescription(), 3, 2, 255, 255, 255);
  118. }
  119. // Finish the graph
  120. $test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf', 8);
  121. $test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf', 10);
  122. $test->drawTitle(60, 22, get_lang('AccessDetails', ''), 50, 50, 50, 585);
  123. //------------------
  124. //echo 'not in cache';
  125. $cache->WriteToCache($graph_id, $data_set->GetData(), $test);
  126. ob_start();
  127. $test->Stroke();
  128. ob_end_clean();
  129. $img_file = $cache->GetHash($graph_id, $data_set->GetData());
  130. }
  131. echo '<img src="'.api_get_path(WEB_ARCHIVE_PATH).$img_file.'">';
  132. } else {
  133. Display::display_warning_message(api_convert_encoding(get_lang('GraphicNotAvailable'),'UTF-8'));
  134. }
  135. exit;
  136. }
  137. $nameTools = get_lang('AccessDetails');
  138. //StudentDetails
  139. if (isset($_GET['origin']) && strcmp($_GET['origin'], 'tracking_course') === 0) {
  140. $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"));
  141. $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'));
  142. $interbreadcrumb[] = array ("url" => "javascript: void(0);", "name" => get_lang("Details"));
  143. } elseif (isset($_GET['origin']) && strcmp($_GET['origin'], 'user_course') === 0) {
  144. $interbreadcrumb[] = array ("url" => "../user/user.php?cidReq=".Security::remove_XSS($_GET['course']), "name" => get_lang("Users"));
  145. $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'));
  146. $interbreadcrumb[] = array ("url" => "javascript: void(0);", "name" => get_lang("Details"));
  147. }
  148. $htmlHeadXtra[] = '<script src="../inc/lib/javascript/jquery.js" type="text/javascript" language="javascript"></script>'; //jQuery
  149. $htmlHeadXtra[] = '<script src="../inc/lib/javascript/jquery-1.1.3.1.pack.js" type="text/javascript"></script>';
  150. $htmlHeadXtra[] = '<script src="../inc/lib/javascript/jquery.history_remote.pack.js" type="text/javascript"></script>';
  151. $htmlHeadXtra[] = '<script src="../inc/lib/javascript/jquery.tabs.pack.js" type="text/javascript"></script>';
  152. $htmlHeadXtra[] = '<link rel="stylesheet" href="../inc/lib/javascript/jquery.tabs.css" type="text/css" media="print, projection, screen">';
  153. $htmlHeadXtra[] = '<script type="text/javascript">
  154. $(function() {
  155. $("#container-9").tabs({ remote: true});
  156. });
  157. </script>';
  158. Display :: display_header('');
  159. $tbl_userinfo_def = Database :: get_course_table(TABLE_USER_INFO);
  160. $main_user_info = api_get_user_info($user_id);
  161. $result_to_print = '';
  162. $main_date_array = array();
  163. foreach ($connections as $key => $data) {
  164. $result_to_print .= '&nbsp;&nbsp;'.date('d-m-Y (H:i:s)', $data['login']).' - '.api_time_to_hms($data['logout'] - $data['login']).'<br />'."\n";
  165. }
  166. api_display_tool_title(get_lang('DetailsStudentInCourse'));
  167. echo '<div class="actions">';
  168. echo '<strong>'.get_lang('User').': '.api_get_person_name($main_user_info['firstName'], $main_user_info['lastName']).'</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>'.get_lang('Course').': '.$course_code.'</strong></div>';
  169. ?>
  170. <div id="container-9">
  171. <ul>
  172. <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>
  173. <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>
  174. </ul>
  175. <?php echo '<div id="show"></div>'; ?>
  176. </div>
  177. <?php
  178. echo '<div id="graph"></div><br />';
  179. echo '<div class="actions"><strong>', get_lang('DateAndTimeOfAccess'), ' - ', get_lang('Duration'), '</strong></div><br />';
  180. echo $result_to_print;
  181. /* Login time against logout time
  182. foreach ($connections as $key => $data) {
  183. 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>");
  184. }
  185. */
  186. /*
  187. foreach ($connections as $key => $data) {
  188. echo ("<tr><td>".date("d-m-Y (H:i:s)", $data['login'])."</td><td>".api_time_to_hms($data['logout'] - $data['login'])."</td></tr>");
  189. }
  190. echo ("</table>");
  191. */
  192. Display:: display_footer();