logins_details.php 10 KB

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