logins_details.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @author Thomas Depraetere
  5. * @author Hugues Peeters
  6. * @author Christophe Gesche
  7. * @author Sebastien Piraux
  8. *
  9. * @package chamilo.tracking
  10. */
  11. /**
  12. * Code
  13. */
  14. // TODO: Is this file deprecated?
  15. exit;
  16. /* INIT SECTION */
  17. $uInfo = $_REQUEST['uInfo'];
  18. if (!isset($_REQUEST['reqdate']))
  19. $reqdate = time();
  20. else
  21. $reqdate = $_REQUEST['reqdate'];
  22. $period = $_REQUEST['period'];
  23. if (!isset($_REQUEST['view']))
  24. $view = "0000000";
  25. else
  26. $view = $_REQUEST['view'];
  27. // name of the language file that needs to be included
  28. $language_file = "tracking";
  29. include('../inc/global.inc.php');
  30. $interbreadcrumb[] = array("url" => "../user/user.php", "name" => get_lang('Users'));
  31. $nameTools = get_lang('ToolName');
  32. $htmlHeadXtra[] = "<style type='text/css'>
  33. /*<![CDATA[*/
  34. .secLine {background-color : #E6E6E6;}
  35. .content {padding-left : 15px;padding-right : 15px; }
  36. .specialLink{color : #0000FF;}
  37. /*]]>*/
  38. </style>
  39. <style media='print' type='text/css'>
  40. /*<![CDATA[*/
  41. td {border-bottom: thin dashed gray;}
  42. /*]]>*/
  43. </style>";
  44. $TABLECOURSUSER = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  45. $TABLECOURSE_GROUPSUSER = Database::get_course_table(TABLE_GROUP_USER);
  46. $TABLEUSER = Database::get_main_table(TABLE_MAIN_USER);
  47. $TABLETRACK_ACCESS = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ACCESS);
  48. Display::display_header($nameTools, "Tracking");
  49. include(api_get_path(LIBRARY_PATH) . "statsUtils.lib.inc.php");
  50. // the variables for the days and the months
  51. // Defining the shorts for the days
  52. $DaysShort = api_get_week_days_short();
  53. // Defining the days of the week to allow translation of the days
  54. $DaysLong = api_get_week_days_long();
  55. // Defining the months of the year to allow translation of the months
  56. $MonthsLong = api_get_months_long();
  57. // Defining the months of the year to allow translation of the months
  58. $MonthsShort = api_get_months_short();
  59. $is_allowedToTrack = $is_groupTutor; // allowed to track only user of one group
  60. $is_allowedToTrackEverybodyInCourse = api_is_course_admin(); // allowed to track all student in course
  61. ?>
  62. <h3>
  63. <?php echo $nameTools ?>
  64. </h3>
  65. <table width="100%" cellpadding="2" cellspacing="3" border="0">
  66. <?php
  67. // check if uid is tutor of this group
  68. if (( $is_allowedToTrack || $is_allowedToTrackEverybodyInCourse)) {
  69. if ($is_allowedToTrackEverybodyInCourse) {
  70. $sql = "SELECT u.firstname,u.lastname, u.email
  71. FROM $TABLECOURSUSER cu , $TABLEUSER u
  72. WHERE cu.user_id = u.user_id AND cu.relation_type<>" . COURSE_RELATION_TYPE_RRHH . "
  73. AND cu.course_code = '$_cid'
  74. AND u.user_id = '$uInfo'";
  75. } else {
  76. $sql = "SELECT u.firstname,u.lastname, u.email
  77. FROM $TABLECOURSE_GROUPSUSER gu , $TABLEUSER u
  78. WHERE gu.user_id = u.user_id
  79. AND gu.group_id = '$_gid'
  80. AND u.user_id = '$uInfo'";
  81. }
  82. $query = Database::query($sql);
  83. $res = @Database::fetch_array($query);
  84. if (is_array($res)) {
  85. $res[2] == "" ? $res2 = get_lang('NoEmail') : $res2 = Display::encrypted_mailto_link($res[2]);
  86. echo "<tr><td>";
  87. echo $informationsAbout . " : <br>";
  88. echo "<ul>\n"
  89. . "<li>" . get_lang('FirstName') . " : " . $res[0] . "</li>\n"
  90. . "<li>" . get_lang('LastName') . " : " . $res[1] . "</li>\n"
  91. . "<li>" . get_lang('Email') . " : " . $res2 . "</li>\n"
  92. . "</ul>";
  93. echo "</td></tr>";
  94. /* * ***** MENU ******* */
  95. echo "<tr>
  96. <td>
  97. ";
  98. echo " &nbsp;&nbsp;&nbsp;||&nbsp;&nbsp;&nbsp;
  99. [<a href='" . api_get_self() . "?uInfo=$uInfo&view=$view&period=week&reqdate=$reqdate' class='specialLink'>" . get_lang('PeriodWeek') . "</a>]
  100. [<a href='" . api_get_self() . "?uInfo=$uInfo&view=$view&period=month&reqdate=$reqdate' class='specialLink'>" . get_lang('PeriodMonth') . "</a>]
  101. &nbsp;&nbsp;&nbsp;||&nbsp;&nbsp;&nbsp;
  102. ";
  103. switch ($period) {
  104. case "week" :
  105. // previous and next date must be evaluated
  106. $previousReqDate = $reqdate - 7 * 86400;
  107. $nextReqDate = $reqdate + 7 * 86400;
  108. echo "
  109. [<a href='" . api_get_self() . "?uInfo=$uInfo&view=$view&period=week&reqdate=$previousReqDate' class='specialLink'>" . get_lang('PreviousWeek') . "</a>]
  110. [<a href='" . api_get_self() . "?uInfo=$uInfo&view=$view&period=week&reqdate=$nextReqDate' class='specialLink'>" . get_lang('NextWeek') . "</a>]
  111. ";
  112. break;
  113. default :
  114. $period = "month";
  115. case "month" :
  116. // previous and next date must be evaluated
  117. // 30 days should be a good approximation
  118. $previousReqDate = mktime(1, 1, 1, date("m", $reqdate) - 1, 1, date("Y", $reqdate));
  119. $nextReqDate = mktime(1, 1, 1, date("m", $reqdate) + 1, 1, date("Y", $reqdate));
  120. echo "
  121. [<a href='" . api_get_self() . "?uInfo=$uInfo&view=$view&period=month&reqdate=$previousReqDate' class='specialLink'>" . get_lang('PreviousMonth') . "</a>]
  122. [<a href='" . api_get_self() . "?uInfo=$uInfo&view=$view&period=month&reqdate=$nextReqDate' class='specialLink'>" . get_lang('NextMonth') . "</a>]
  123. ";
  124. break;
  125. }
  126. echo "
  127. </td>
  128. </tr>
  129. ";
  130. switch ($period) {
  131. case "month" :
  132. $sql = "SELECT access_date
  133. FROM $TABLETRACK_ACCESS
  134. WHERE access_user_id = '$uInfo'
  135. AND access_cours_code = '" . $_cid . "'
  136. AND MONTH(access_date) = MONTH( FROM_UNIXTIME('$reqdate') )
  137. AND YEAR(access_date) = YEAR(FROM_UNIXTIME('$reqdate'))
  138. GROUP BY DAYOFMONTH(access_date)
  139. ORDER BY access_date ASC";
  140. $displayedDate = $MonthsLong[date("n", $reqdate) - 1] . date(" Y", $reqdate);
  141. break;
  142. case "week" :
  143. $sql = "SELECT access_date
  144. FROM $TABLETRACK_ACCESS
  145. WHERE access_user_id = '$uInfo'
  146. AND access_cours_code = '" . $_cid . "'
  147. AND WEEK(access_date) = WEEK( FROM_UNIXTIME('$reqdate') )
  148. AND YEAR(access_date) = YEAR(FROM_UNIXTIME('$reqdate'))
  149. GROUP BY DAYOFMONTH(access_date)
  150. ORDER BY access_date ASC";
  151. $weeklowreqdate = ($reqdate - (86400 * date("w", $reqdate)));
  152. $weekhighreqdate = ($reqdate + (86400 * (6 - date("w", $reqdate)) ));
  153. $displayedDate = get_lang('From') . " " . date("d ", $weeklowreqdate) . $MonthsLong[date("n", $weeklowreqdate) - 1] . date(" Y", $weeklowreqdate)
  154. . " " . get_lang('To') . " " . date("d ", $weekhighreqdate) . $MonthsLong[date("n", $weekhighreqdate) - 1] . date(" Y", $weekhighreqdate);
  155. break;
  156. }
  157. echo "<tr><td>";
  158. $results = getManyResults1Col($sql);
  159. /* * * display of the displayed period ** */
  160. echo "<table width='100%' cellpadding='2' cellspacing='1' border='0' align=center>";
  161. echo "<td bgcolor='#E6E6E6'>" . $displayedDate . "</td>";
  162. if (is_array($results)) {
  163. for ($j = 0; $j < sizeof($results); $j++) {
  164. $beautifulDateTime = api_convert_and_format_date($results[$j], null, date_default_timezone_get());
  165. echo "<tr>";
  166. echo "<td style='padding-left : 40px;' valign='top'>" . $beautifulDateTime . "</td>";
  167. echo"</tr>";
  168. // $limit is used to select only results between $results[$j] (current login) and next one
  169. if ($j == ( sizeof($results) - 1 ))
  170. $limit = date("Y-m-d H:i:s", $nextReqDate);
  171. else
  172. $limit = $results[$j + 1];
  173. // select all access to tool between displayed date and next displayed date or now() if
  174. // displayed date is the last login date
  175. $sql = "SELECT access_tool, count(access_tool)
  176. FROM $TABLETRACK_ACCESS
  177. WHERE access_user_id = '$uInfo'
  178. AND access_tool IS NOT NULL
  179. AND access_date > '" . $results[$j] . "'
  180. AND access_date < '" . $limit . "'
  181. AND access_cours_code = '" . $_cid . "'
  182. GROUP BY access_tool
  183. ORDER BY access_tool ASC";
  184. $results2 = getManyResults2Col($sql);
  185. if (is_array($results2)) {
  186. echo "<tr><td colspan='2'>\n";
  187. echo "<table width='50%' cellpadding='0' cellspacing='0' border='0'>\n";
  188. for ($k = 0; $k < count($results2); $k++) {
  189. echo "<tr>\n";
  190. echo "<td width='70%' style='padding-left : 60px;'>" . get_lang($results2[$k][0]) . "</td>\n";
  191. echo "<td width='30%' align='right' style='padding-right : 40px'>" . $results2[$k][1] . " " . get_lang('Visits') . "</td>\n";
  192. echo "</tr>";
  193. }
  194. echo "</table>\n";
  195. echo "</td></tr>\n";
  196. }
  197. $previousDate = $value;
  198. }
  199. } else {
  200. echo "<tr>";
  201. echo "<td colspan='2' bgcolor='#eeeeee'>" . get_lang('NoResult') . "</td>";
  202. echo "</tr>";
  203. }
  204. echo "</table>";
  205. echo "</td></tr>";
  206. } else {
  207. echo get_lang('ErrorUserNotInGroup');
  208. }
  209. } else {
  210. // not allowed
  211. api_not_allowed();
  212. }
  213. ?>
  214. </table>
  215. <?php
  216. Display::display_footer();