course_access_details.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos S.A.
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  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 address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  16. Mail: info@dokeos.com
  17. ==============================================================================
  18. */
  19. /**
  20. ==============================================================================
  21. * @author Thomas Depraetere
  22. * @author Hugues Peeters
  23. * @author Christophe Gesche
  24. * @author Sebastien Piraux
  25. *
  26. * @package dokeos.tracking
  27. ==============================================================================
  28. */
  29. /*
  30. ==============================================================================
  31. INIT SECTION
  32. ==============================================================================
  33. */
  34. $reqdate = $_REQUEST['reqdate'];
  35. $period = $_REQUEST['period'];
  36. $displayType = $_REQUEST['displayType'];
  37. // name of the language file that needs to be included
  38. $language_file = "tracking";
  39. include('../inc/global.inc.php');
  40. $interbreadcrumb[]= array ("url"=>"courseLog.php", "name"=> get_lang('ToolName'));
  41. $nameTools = get_lang('TrafficDetails');
  42. $htmlHeadXtra[] = "<style type='text/css'>
  43. /*<![CDATA[*/
  44. .secLine {background-color : #E6E6E6;}
  45. .content {padding-left : 15px;padding-right : 15px; }
  46. .specialLink{color : #0000FF;}
  47. /*]]>*/
  48. </style>
  49. <style media='print' type='text/css'>
  50. /*<![CDATA[*/
  51. td {border-bottom: thin dashed gray;}
  52. /*]]>*/
  53. </style>";
  54. //@todo use Database library
  55. $TABLETRACK_ACCESS = $_configuration['statistics_database']."`.`track_e_access";
  56. Display::display_header($nameTools,"Tracking");
  57. include(api_get_path(LIBRARY_PATH)."statsUtils.lib.inc.php");
  58. // the variables for the days and the months
  59. // Defining the shorts for the days
  60. $DaysShort = array (get_lang("SundayShort"), get_lang("MondayShort"), get_lang("TuesdayShort"), get_lang("WednesdayShort"), get_lang("ThursdayShort"), get_lang("FridayShort"), get_lang("SaturdayShort"));
  61. // Defining the days of the week to allow translation of the days
  62. $DaysLong = array (get_lang("SundayLong"), get_lang("MondayLong"), get_lang("TuesdayLong"), get_lang("WednesdayLong"), get_lang("ThursdayLong"), get_lang("FridayLong"), get_lang("SaturdayLong"));
  63. // Defining the months of the year to allow translation of the months
  64. $MonthsLong = array (get_lang("JanuaryLong"), get_lang("FebruaryLong"), get_lang("MarchLong"), get_lang("AprilLong"), get_lang("MayLong"), get_lang("JuneLong"), get_lang("JulyLong"), get_lang("AugustLong"), get_lang("SeptemberLong"), get_lang("OctoberLong"), get_lang("NovemberLong"), get_lang("DecemberLong"));
  65. $is_allowedToTrack = $is_courseAdmin;
  66. ?>
  67. <h3>
  68. <?php echo $nameTools ?>
  69. </h3>
  70. <table width="100%" cellpadding="2" cellspacing="3" border="0">
  71. <?php
  72. if( $is_allowedToTrack && $_configuration['tracking_enabled'])
  73. {
  74. if( !isset($reqdate) || $reqdate < 0 || $reqdate > 2149372861 )
  75. $reqdate = time();
  76. //** dislayed period
  77. echo "<tr><td><b>";
  78. switch($period)
  79. {
  80. case "year" :
  81. echo date(" Y", $reqdate);
  82. break;
  83. case "month" :
  84. echo $MonthsLong[date("n", $reqdate)-1].date(" Y", $reqdate);
  85. break;
  86. // default == day
  87. default :
  88. $period = "day";
  89. case "day" :
  90. echo $DaysLong[date("w" , $reqdate)].date(" d " , $reqdate).$MonthsLong[date("n", $reqdate)-1].date(" Y" , $reqdate);
  91. break;
  92. }
  93. echo "</b></tr></td>";
  94. //** menu
  95. echo "<tr>
  96. <td>
  97. ";
  98. echo " ".get_lang('PeriodToDisplay')." : [<a href='".api_get_self()."?period=year&reqdate=$reqdate' class='specialLink'>".get_lang('PeriodYear')."</a>]
  99. [<a href='".api_get_self()."?period=month&reqdate=$reqdate' class='specialLink'>".get_lang('PeriodMonth')."</a>]
  100. [<a href='".api_get_self()."?period=day&reqdate=$reqdate' class='specialLink'>".get_lang('PeriodDay')."</a>]
  101. &nbsp;&nbsp;&nbsp;||&nbsp;&nbsp;&nbsp;
  102. ".get_lang('DetailView')." :
  103. ";
  104. switch($period)
  105. {
  106. case "year" :
  107. //-- if period is "year" display can be by month, day or hour
  108. echo " [<a href='".api_get_self()."?period=$period&reqdate=$reqdate&displayType=month' class='specialLink'>".get_lang('PeriodMonth')."</a>]";
  109. case "month" :
  110. //-- if period is "month" display can be by day or hour
  111. echo " [<a href='".api_get_self()."?period=$period&reqdate=$reqdate&displayType=day' class='specialLink'>".get_lang('PeriodDay')."</a>]";
  112. case "day" :
  113. //-- if period is "day" display can only be by hour
  114. echo " [<a href='".api_get_self()."?period=$period&reqdate=$reqdate&displayType=hour' class='specialLink'>".get_lang('PeriodHour')."</a>]";
  115. break;
  116. }
  117. echo "&nbsp;&nbsp;&nbsp;||&nbsp;&nbsp;&nbsp;";
  118. switch($period)
  119. {
  120. case "year" :
  121. // previous and next date must be evaluated
  122. // 30 days should be a good approximation
  123. $previousReqDate = mktime(1,1,1,1,1,date("Y",$reqdate)-1);
  124. $nextReqDate = mktime(1,1,1,1,1,date("Y",$reqdate)+1);
  125. echo "
  126. [<a href='".api_get_self()."?period=$period&reqdate=$previousReqDate&displayType=$displayType' class='specialLink'>".get_lang('PreviousYear')."</a>]
  127. [<a href='".api_get_self()."?period=$period&reqdate=$nextReqDate&displayType=$displayType' class='specialLink'>".get_lang('NextYear')."</a>]
  128. ";
  129. break;
  130. case "month" :
  131. // previous and next date must be evaluated
  132. // 30 days should be a good approximation
  133. $previousReqDate = mktime(1,1,1,date("m",$reqdate)-1,1,date("Y",$reqdate));
  134. $nextReqDate = mktime(1,1,1,date("m",$reqdate)+1,1,date("Y",$reqdate));
  135. echo "
  136. [<a href='".api_get_self()."?period=$period&reqdate=$previousReqDate&displayType=$displayType' class='specialLink'>".get_lang('PreviousMonth')."</a>]
  137. [<a href='".api_get_self()."?period=$period&reqdate=$nextReqDate&displayType=$displayType' class='specialLink'>".get_lang('NextMonth')."</a>]
  138. ";
  139. break;
  140. case "day" :
  141. // previous and next date must be evaluated
  142. $previousReqDate = $reqdate - 86400;
  143. $nextReqDate = $reqdate + 86400;
  144. echo "
  145. [<a href='".api_get_self()."?period=$period&reqdate=$previousReqDate&displayType=$displayType' class='specialLink'>".get_lang('PreviousDay')."</a>]
  146. [<a href='".api_get_self()."?period=$period&reqdate=$nextReqDate&displayType=$displayType' class='specialLink'>".get_lang('NextDay')."</a>]
  147. ";
  148. break;
  149. }
  150. echo "
  151. </td>
  152. </tr>
  153. ";
  154. //**
  155. // display information about this period
  156. switch($period)
  157. {
  158. // all days
  159. case "year" :
  160. $sql = "SELECT UNIX_TIMESTAMP( `access_date` )
  161. FROM `$TABLETRACK_ACCESS`
  162. WHERE YEAR( `access_date` ) = YEAR( FROM_UNIXTIME( '$reqdate' ) )
  163. AND `access_cours_code` = '$_cid'
  164. AND `access_tool` IS NULL ";
  165. if($displayType == "month")
  166. {
  167. $sql .= "ORDER BY UNIX_TIMESTAMP( `access_date`)";
  168. $month_array = monthTab($sql);
  169. makeHitsTable($month_array,get_lang('PeriodMonth'));
  170. }
  171. elseif($displayType == "day")
  172. {
  173. $sql .= "ORDER BY DAYOFYEAR( `access_date`)";
  174. $days_array = daysTab($sql);
  175. makeHitsTable($days_array,get_lang('PeriodDay'));
  176. }
  177. else // by hours by default
  178. {
  179. $sql .= "ORDER BY HOUR( `access_date`)";
  180. $hours_array = hoursTab($sql);
  181. makeHitsTable($hours_array,get_lang('PeriodHour'));
  182. }
  183. break;
  184. // all days
  185. case "month" :
  186. $sql = "SELECT UNIX_TIMESTAMP( `access_date` )
  187. FROM `$TABLETRACK_ACCESS`
  188. WHERE MONTH(`access_date`) = MONTH (FROM_UNIXTIME( '$reqdate' ) )
  189. AND YEAR( `access_date` ) = YEAR( FROM_UNIXTIME( '$reqdate' ) )
  190. AND `access_cours_code` = '$_cid'
  191. AND `access_tool` IS NULL ";
  192. if($displayType == "day")
  193. {
  194. $sql .= "ORDER BY DAYOFYEAR( `access_date`)";
  195. $days_array = daysTab($sql);
  196. makeHitsTable($days_array,get_lang('PeriodDay'));
  197. }
  198. else // by hours by default
  199. {
  200. $sql .= "ORDER BY HOUR( `access_date`)";
  201. $hours_array = hoursTab($sql);
  202. makeHitsTable($hours_array,get_lang('PeriodHour'));
  203. }
  204. break;
  205. // all hours
  206. case "day" :
  207. $sql = "SELECT UNIX_TIMESTAMP( `access_date` )
  208. FROM `$TABLETRACK_ACCESS`
  209. WHERE DAYOFMONTH(`access_date`) = DAYOFMONTH(FROM_UNIXTIME( '$reqdate' ) )
  210. AND MONTH(`access_date`) = MONTH (FROM_UNIXTIME( '$reqdate' ) )
  211. AND YEAR( `access_date` ) = YEAR( FROM_UNIXTIME( '$reqdate' ) )
  212. AND `access_cours_code` = '$_cid'
  213. AND `access_tool` IS NULL
  214. ORDER BY HOUR( `access_date` )";
  215. $hours_array = hoursTab($sql,$reqdate);
  216. makeHitsTable($hours_array,get_lang('PeriodHour'));
  217. break;
  218. }
  219. }
  220. else // not allowed to track
  221. {
  222. if(!$_configuration['tracking_enabled'])
  223. {
  224. echo get_lang('TrackingDisabled');
  225. }
  226. else
  227. {
  228. api_not_allowed();
  229. }
  230. }
  231. ?>
  232. </table>
  233. <?php
  234. Display::display_footer();
  235. ?>