course_access_details.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. // TODO: Is this file deprecated?
  12. $reqdate = $_REQUEST['reqdate'];
  13. $period = $_REQUEST['period'];
  14. $displayType = $_REQUEST['displayType'];
  15. require_once '../inc/global.inc.php';
  16. $courseId = api_get_course_int_id();
  17. $interbreadcrumb[] = array(
  18. "url" => "courseLog.php",
  19. "name" => get_lang('ToolName'),
  20. );
  21. $nameTools = get_lang('TrafficDetails');
  22. $htmlHeadXtra[] = "<style type='text/css'>
  23. /*<![CDATA[*/
  24. .secLine {background-color : #E6E6E6;}
  25. .content {padding-left : 15px;padding-right : 15px; }
  26. .specialLink{color : #0000FF;}
  27. /*]]>*/
  28. </style>
  29. <style media='print' type='text/css'>
  30. /*<![CDATA[*/
  31. td {border-bottom: thin dashed gray;}
  32. /*]]>*/
  33. </style>";
  34. //@todo use Database library
  35. $TABLETRACK_ACCESS = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ACCESS);
  36. Display::display_header($nameTools, "Tracking");
  37. // the variables for the days and the months
  38. // Defining the shorts for the days
  39. $DaysShort = api_get_week_days_short();
  40. // Defining the days of the week to allow translation of the days
  41. $DaysLong = api_get_week_days_long();
  42. // Defining the months of the year to allow translation of the months
  43. $MonthsLong = api_get_months_long();
  44. $is_allowedToTrack = $is_courseAdmin;
  45. ?>
  46. <h3>
  47. <?php echo $nameTools ?>
  48. </h3>
  49. <table width="100%" cellpadding="2" cellspacing="3" border="0">
  50. <?php
  51. if ($is_allowedToTrack) {
  52. if (!isset($reqdate) || $reqdate < 0 || $reqdate > 2149372861)
  53. $reqdate = time();
  54. //** dislayed period
  55. echo "<tr><td><b>";
  56. switch($period) {
  57. case "year" :
  58. echo date(" Y", $reqdate);
  59. break;
  60. case "month" :
  61. echo $MonthsLong[date("n", $reqdate)-1].date(" Y", $reqdate);
  62. break;
  63. // default == day
  64. default :
  65. $period = "day";
  66. case "day" :
  67. echo $DaysLong[date("w" , $reqdate)].date(" d " , $reqdate).$MonthsLong[date("n", $reqdate)-1].date(" Y" , $reqdate);
  68. break;
  69. }
  70. echo "</b></tr></td>";
  71. //** menu
  72. echo "<tr>
  73. <td>";
  74. echo " ".get_lang('PeriodToDisplay')." : [<a href='".api_get_self()."?period=year&reqdate=$reqdate' class='specialLink'>".get_lang('PeriodYear')."</a>]
  75. [<a href='".api_get_self()."?period=month&reqdate=$reqdate' class='specialLink'>".get_lang('PeriodMonth')."</a>]
  76. [<a href='".api_get_self()."?period=day&reqdate=$reqdate' class='specialLink'>".get_lang('PeriodDay')."</a>]
  77. &nbsp;&nbsp;&nbsp;||&nbsp;&nbsp;&nbsp;
  78. ".get_lang('DetailView')." :
  79. ";
  80. switch($period) {
  81. case "year" :
  82. //-- if period is "year" display can be by month, day or hour
  83. echo " [<a href='".api_get_self()."?period=$period&reqdate=$reqdate&displayType=month' class='specialLink'>".get_lang('PeriodMonth')."</a>]";
  84. case "month" :
  85. //-- if period is "month" display can be by day or hour
  86. echo " [<a href='".api_get_self()."?period=$period&reqdate=$reqdate&displayType=day' class='specialLink'>".get_lang('PeriodDay')."</a>]";
  87. case "day" :
  88. //-- if period is "day" display can only be by hour
  89. echo " [<a href='".api_get_self()."?period=$period&reqdate=$reqdate&displayType=hour' class='specialLink'>".get_lang('PeriodHour')."</a>]";
  90. break;
  91. }
  92. echo "&nbsp;&nbsp;&nbsp;||&nbsp;&nbsp;&nbsp;";
  93. switch ($period) {
  94. case "year" :
  95. // previous and next date must be evaluated
  96. // 30 days should be a good approximation
  97. $previousReqDate = mktime(1,1,1,1,1,date("Y",$reqdate)-1);
  98. $nextReqDate = mktime(1,1,1,1,1,date("Y",$reqdate)+1);
  99. echo "
  100. [<a href='".api_get_self()."?period=$period&reqdate=$previousReqDate&displayType=$displayType' class='specialLink'>".get_lang('PreviousYear')."</a>]
  101. [<a href='".api_get_self()."?period=$period&reqdate=$nextReqDate&displayType=$displayType' class='specialLink'>".get_lang('NextYear')."</a>]
  102. ";
  103. break;
  104. case "month" :
  105. // previous and next date must be evaluated
  106. // 30 days should be a good approximation
  107. $previousReqDate = mktime(1,1,1,date("m",$reqdate)-1,1,date("Y",$reqdate));
  108. $nextReqDate = mktime(1,1,1,date("m",$reqdate)+1,1,date("Y",$reqdate));
  109. echo "
  110. [<a href='".api_get_self()."?period=$period&reqdate=$previousReqDate&displayType=$displayType' class='specialLink'>".get_lang('PreviousMonth')."</a>]
  111. [<a href='".api_get_self()."?period=$period&reqdate=$nextReqDate&displayType=$displayType' class='specialLink'>".get_lang('NextMonth')."</a>]
  112. ";
  113. break;
  114. case "day" :
  115. // previous and next date must be evaluated
  116. $previousReqDate = $reqdate - 86400;
  117. $nextReqDate = $reqdate + 86400;
  118. echo "
  119. [<a href='".api_get_self()."?period=$period&reqdate=$previousReqDate&displayType=$displayType' class='specialLink'>".get_lang('PreviousDay')."</a>]
  120. [<a href='".api_get_self()."?period=$period&reqdate=$nextReqDate&displayType=$displayType' class='specialLink'>".get_lang('NextDay')."</a>]
  121. ";
  122. break;
  123. }
  124. echo "</td></tr>";
  125. // display information about this period
  126. switch ($period) {
  127. // all days
  128. case "year" :
  129. $sql = "SELECT UNIX_TIMESTAMP( access_date )
  130. FROM $TABLETRACK_ACCESS
  131. WHERE YEAR( access_date ) = YEAR( FROM_UNIXTIME( '$reqdate' ) )
  132. AND c_id = $courseId
  133. AND access_tool IS NULL ";
  134. if ($displayType == "month") {
  135. $sql .= "ORDER BY UNIX_TIMESTAMP( access_date)";
  136. $month_array = StatsUtils::monthTab($sql);
  137. StatsUtils::makeHitsTable($month_array,get_lang('PeriodMonth'));
  138. } elseif($displayType == "day") {
  139. $sql .= "ORDER BY DAYOFYEAR( access_date)";
  140. $days_array = StatsUtils::daysTab($sql);
  141. StatsUtils::makeHitsTable($days_array,get_lang('PeriodDay'));
  142. } else {
  143. // by hours by default
  144. $sql .= "ORDER BY HOUR( access_date)";
  145. $hours_array = StatsUtils::hoursTab($sql);
  146. StatsUtils::makeHitsTable($hours_array,get_lang('PeriodHour'));
  147. }
  148. break;
  149. // all days
  150. case "month" :
  151. $sql = "SELECT UNIX_TIMESTAMP( access_date )
  152. FROM $TABLETRACK_ACCESS
  153. WHERE MONTH(access_date) = MONTH (FROM_UNIXTIME( '$reqdate' ) )
  154. AND YEAR( access_date ) = YEAR( FROM_UNIXTIME( '$reqdate' ) )
  155. AND c_id = $courseId
  156. AND access_tool IS NULL ";
  157. if ($displayType == "day") {
  158. $sql .= "ORDER BY DAYOFYEAR( access_date)";
  159. $days_array = StatsUtils::daysTab($sql);
  160. StatsUtils::makeHitsTable($days_array,get_lang('PeriodDay'));
  161. } else {
  162. // by hours by default
  163. $sql .= "ORDER BY HOUR( access_date)";
  164. $hours_array = StatsUtils::hoursTab($sql);
  165. StatsUtils:: makeHitsTable($hours_array,get_lang('PeriodHour'));
  166. }
  167. break;
  168. // all hours
  169. case "day" :
  170. $sql = "SELECT UNIX_TIMESTAMP( access_date )
  171. FROM $TABLETRACK_ACCESS
  172. WHERE DAYOFMONTH(access_date) = DAYOFMONTH(FROM_UNIXTIME( '$reqdate' ) )
  173. AND MONTH(access_date) = MONTH (FROM_UNIXTIME( '$reqdate' ) )
  174. AND YEAR( access_date ) = YEAR( FROM_UNIXTIME( '$reqdate' ) )
  175. AND c_id = $courseId
  176. AND access_tool IS NULL
  177. ORDER BY HOUR( access_date )";
  178. $hours_array = StatsUtils::hoursTab($sql,$reqdate);
  179. StatsUtils::makeHitsTable($hours_array,get_lang('PeriodHour'));
  180. break;
  181. }
  182. } else {
  183. // not allowed to track
  184. api_not_allowed();
  185. }
  186. ?>
  187. </table>
  188. <?php
  189. Display::display_footer();