course_access_details.php 9.1 KB

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