course_access_details.php 9.1 KB

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