course_access_details.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. require_once '../inc/global.inc.php';
  19. $courseId = api_get_course_int_id();
  20. $interbreadcrumb[]= array ("url"=>"courseLog.php", "name"=> get_lang('ToolName'));
  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. {
  53. if( !isset($reqdate) || $reqdate < 0 || $reqdate > 2149372861 )
  54. $reqdate = time();
  55. //** dislayed period
  56. echo "<tr><td><b>";
  57. switch($period)
  58. {
  59. case "year" :
  60. echo date(" Y", $reqdate);
  61. break;
  62. case "month" :
  63. echo $MonthsLong[date("n", $reqdate)-1].date(" Y", $reqdate);
  64. break;
  65. // default == day
  66. default :
  67. $period = "day";
  68. case "day" :
  69. echo $DaysLong[date("w" , $reqdate)].date(" d " , $reqdate).$MonthsLong[date("n", $reqdate)-1].date(" Y" , $reqdate);
  70. break;
  71. }
  72. echo "</b></tr></td>";
  73. //** menu
  74. echo "<tr>
  75. <td>
  76. ";
  77. echo " ".get_lang('PeriodToDisplay')." : [<a href='".api_get_self()."?period=year&reqdate=$reqdate' class='specialLink'>".get_lang('PeriodYear')."</a>]
  78. [<a href='".api_get_self()."?period=month&reqdate=$reqdate' class='specialLink'>".get_lang('PeriodMonth')."</a>]
  79. [<a href='".api_get_self()."?period=day&reqdate=$reqdate' class='specialLink'>".get_lang('PeriodDay')."</a>]
  80. &nbsp;&nbsp;&nbsp;||&nbsp;&nbsp;&nbsp;
  81. ".get_lang('DetailView')." :
  82. ";
  83. switch($period)
  84. {
  85. case "year" :
  86. //-- if period is "year" display can be by month, day or hour
  87. echo " [<a href='".api_get_self()."?period=$period&reqdate=$reqdate&displayType=month' class='specialLink'>".get_lang('PeriodMonth')."</a>]";
  88. case "month" :
  89. //-- if period is "month" display can be by day or hour
  90. echo " [<a href='".api_get_self()."?period=$period&reqdate=$reqdate&displayType=day' class='specialLink'>".get_lang('PeriodDay')."</a>]";
  91. case "day" :
  92. //-- if period is "day" display can only be by hour
  93. echo " [<a href='".api_get_self()."?period=$period&reqdate=$reqdate&displayType=hour' class='specialLink'>".get_lang('PeriodHour')."</a>]";
  94. break;
  95. }
  96. echo "&nbsp;&nbsp;&nbsp;||&nbsp;&nbsp;&nbsp;";
  97. switch($period)
  98. {
  99. case "year" :
  100. // previous and next date must be evaluated
  101. // 30 days should be a good approximation
  102. $previousReqDate = mktime(1,1,1,1,1,date("Y",$reqdate)-1);
  103. $nextReqDate = mktime(1,1,1,1,1,date("Y",$reqdate)+1);
  104. echo "
  105. [<a href='".api_get_self()."?period=$period&reqdate=$previousReqDate&displayType=$displayType' class='specialLink'>".get_lang('PreviousYear')."</a>]
  106. [<a href='".api_get_self()."?period=$period&reqdate=$nextReqDate&displayType=$displayType' class='specialLink'>".get_lang('NextYear')."</a>]
  107. ";
  108. break;
  109. case "month" :
  110. // previous and next date must be evaluated
  111. // 30 days should be a good approximation
  112. $previousReqDate = mktime(1,1,1,date("m",$reqdate)-1,1,date("Y",$reqdate));
  113. $nextReqDate = mktime(1,1,1,date("m",$reqdate)+1,1,date("Y",$reqdate));
  114. echo "
  115. [<a href='".api_get_self()."?period=$period&reqdate=$previousReqDate&displayType=$displayType' class='specialLink'>".get_lang('PreviousMonth')."</a>]
  116. [<a href='".api_get_self()."?period=$period&reqdate=$nextReqDate&displayType=$displayType' class='specialLink'>".get_lang('NextMonth')."</a>]
  117. ";
  118. break;
  119. case "day" :
  120. // previous and next date must be evaluated
  121. $previousReqDate = $reqdate - 86400;
  122. $nextReqDate = $reqdate + 86400;
  123. echo "
  124. [<a href='".api_get_self()."?period=$period&reqdate=$previousReqDate&displayType=$displayType' class='specialLink'>".get_lang('PreviousDay')."</a>]
  125. [<a href='".api_get_self()."?period=$period&reqdate=$nextReqDate&displayType=$displayType' class='specialLink'>".get_lang('NextDay')."</a>]
  126. ";
  127. break;
  128. }
  129. echo "
  130. </td>
  131. </tr>
  132. ";
  133. // display information about this period
  134. switch($period) {
  135. // all days
  136. case "year" :
  137. $sql = "SELECT UNIX_TIMESTAMP( access_date )
  138. FROM $TABLETRACK_ACCESS
  139. WHERE YEAR( access_date ) = YEAR( FROM_UNIXTIME( '$reqdate' ) )
  140. AND c_id = $courseId
  141. AND access_tool IS NULL ";
  142. if ($displayType == "month") {
  143. $sql .= "ORDER BY UNIX_TIMESTAMP( access_date)";
  144. $month_array = StatsUtils::monthTab($sql);
  145. StatsUtils::makeHitsTable($month_array,get_lang('PeriodMonth'));
  146. } elseif($displayType == "day") {
  147. $sql .= "ORDER BY DAYOFYEAR( access_date)";
  148. $days_array = StatsUtils::daysTab($sql);
  149. StatsUtils::makeHitsTable($days_array,get_lang('PeriodDay'));
  150. } else {
  151. // by hours by default
  152. $sql .= "ORDER BY HOUR( access_date)";
  153. $hours_array = StatsUtils::hoursTab($sql);
  154. StatsUtils::makeHitsTable($hours_array,get_lang('PeriodHour'));
  155. }
  156. break;
  157. // all days
  158. case "month" :
  159. $sql = "SELECT UNIX_TIMESTAMP( access_date )
  160. FROM $TABLETRACK_ACCESS
  161. WHERE MONTH(access_date) = MONTH (FROM_UNIXTIME( '$reqdate' ) )
  162. AND YEAR( access_date ) = YEAR( FROM_UNIXTIME( '$reqdate' ) )
  163. AND c_id = $courseId
  164. AND access_tool IS NULL ";
  165. if($displayType == "day")
  166. {
  167. $sql .= "ORDER BY DAYOFYEAR( access_date)";
  168. $days_array = StatsUtils::daysTab($sql);
  169. StatsUtils::makeHitsTable($days_array,get_lang('PeriodDay'));
  170. }
  171. else // by hours by default
  172. {
  173. $sql .= "ORDER BY HOUR( access_date)";
  174. $hours_array = StatsUtils::hoursTab($sql);
  175. StatsUtils:: makeHitsTable($hours_array,get_lang('PeriodHour'));
  176. }
  177. break;
  178. // all hours
  179. case "day" :
  180. $sql = "SELECT UNIX_TIMESTAMP( access_date )
  181. FROM $TABLETRACK_ACCESS
  182. WHERE DAYOFMONTH(access_date) = DAYOFMONTH(FROM_UNIXTIME( '$reqdate' ) )
  183. AND MONTH(access_date) = MONTH (FROM_UNIXTIME( '$reqdate' ) )
  184. AND YEAR( access_date ) = YEAR( FROM_UNIXTIME( '$reqdate' ) )
  185. AND c_id = $courseId
  186. AND access_tool IS NULL
  187. ORDER BY HOUR( access_date )";
  188. $hours_array = StatsUtils::hoursTab($sql,$reqdate);
  189. StatsUtils::makeHitsTable($hours_array,get_lang('PeriodHour'));
  190. break;
  191. }
  192. }
  193. else // not allowed to track
  194. {
  195. api_not_allowed();
  196. }
  197. ?>
  198. </table>
  199. <?php
  200. Display::display_footer();