toolaccess_details.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <?php // $Id: toolaccess_details.php 9246 2006-09-25 13:24:53Z bmol $
  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. $tool = $_REQUEST['tool'];
  35. $period = $_REQUEST['period'];
  36. $reqDate = $_REQUEST['reqDate'];
  37. $langFile = "tracking";
  38. include('../inc/global.inc.php');
  39. $nameTools = get_lang('ToolName');
  40. $interbreadcrumb[]= array ("url"=>"courseLog.php", "name"=> "Statistics");
  41. $htmlHeadXtra[] = "<style type='text/css'>
  42. /*<![CDATA[*/
  43. .mainLine {font-weight : bold;color : #FFFFFF;background-color : $colorDark;padding-left : 15px;padding-right : 15px;}
  44. .secLine {color : #000000;background-color : $666666;padding-left : 15px;padding-right : 15px;}
  45. .content {padding-left : 25px;}
  46. .specialLink{color : #0000FF;}
  47. .minilink{}
  48. .minitext{}
  49. /*]]>*/
  50. </style>
  51. <style media='print' type='text/css'>
  52. /*<![CDATA[*/
  53. td {border-bottom: thin dashed gray;}
  54. /*]]>*/
  55. </style>";
  56. Display::display_header($nameTools,"Tracking");
  57. ?>
  58. <h3>
  59. <?php echo $nameTools; ?>
  60. </h3>
  61. <?php
  62. include(api_get_path(LIBRARY_PATH)."statsUtils.lib.inc.php");
  63. // the variables for the days and the months
  64. // Defining the shorts for the days
  65. $DaysShort = array (get_lang("SundayShort"), get_lang("MondayShort"), get_lang("TuesdayShort"), get_lang("WednesdayShort"), get_lang("ThursdayShort"), get_lang("FridayShort"), get_lang("SaturdayShort"));
  66. // Defining the days of the week to allow translation of the days
  67. $DaysLong = array (get_lang("SundayLong"), get_lang("MondayLong"), get_lang("TuesdayLong"), get_lang("WednesdayLong"), get_lang("ThursdayLong"), get_lang("FridayLong"), get_lang("SaturdayLong"));
  68. // Defining the months of the year to allow translation of the months
  69. $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"));
  70. // Defining the months of the year to allow translation of the months
  71. $MonthsShort = array (get_lang("JanuaryShort"), get_lang("FebruaryShort"), get_lang("MarchShort"), get_lang("AprilShort"), get_lang("MayShort"), get_lang("JuneShort"), get_lang("JulyShort"), get_lang("AugustShort"), get_lang("SeptemberShort"), get_lang("OctoberShort"), get_lang("NovemberShort"), get_lang("DecemberShort"));
  72. $tool=$_REQUEST['tool'];
  73. $period=$_REQUEST['period'];
  74. $reqdate=$_REQUEST['reqdate'];
  75. ?>
  76. <table width="100%" cellpadding="2" cellspacing="0" border="0">
  77. <?php
  78. $TABLETRACK_ACCESS = $statsDbName."`.`track_e_access";
  79. if(isset($_cid)) //stats for the current course
  80. {
  81. // to see stats of one course user must be courseAdmin of this course
  82. $is_allowedToTrack = $is_courseAdmin;
  83. $courseCodeEqualcidIfNeeded = "AND `access_cours_code` = '$_cid'";
  84. }
  85. else // stats for all courses
  86. {
  87. // to see stats of all courses user must be platformAdmin
  88. $is_allowedToTrack = $is_platformAdmin;
  89. $courseCodeEqualcidIfNeeded = "";
  90. }
  91. if( $is_allowedToTrack && $is_trackingEnabled)
  92. {
  93. // list of all tools
  94. if (!isset($tool))
  95. {
  96. $sql = "SELECT `access_tool`, count( access_tool )
  97. FROM `$TABLETRACK_ACCESS`
  98. WHERE `access_tool` IS NOT NULL
  99. ".$courseCodeEqualcidIfNeeded."
  100. GROUP BY `access_tool`";
  101. echo "<tr><td>";
  102. echo "<tr>
  103. <td>
  104. ";
  105. if(isset($_cid)) echo "<b>$_cid : </b>";
  106. echo " <b>$langToolList</b>
  107. </td>
  108. </tr>
  109. ";
  110. $results = getManyResults2Col($sql);
  111. echo "<table cellpadding='0' cellspacing='0' border='0' align=center>";
  112. echo "<tr bgcolor='#E6E6E6'>
  113. <td width='70%'>
  114. $langToolTitleToolnameColumn
  115. </td>
  116. <td width='30%'>
  117. $langToolTitleCountColumn
  118. </td>
  119. </tr>";
  120. if (is_array($results))
  121. {
  122. for($j = 0 ; $j < count($results) ; $j++)
  123. {
  124. echo "<tr>";
  125. echo "<td><a href='toolaccess_details.php?tool=".urlencode($results[$j][0])."'>".get_lang($results[$j][0])."</a></td>";
  126. echo "<td align='right'>".$results[$j][1]."</td>";
  127. echo"</tr>";
  128. }
  129. }
  130. else
  131. {
  132. echo "<tr>";
  133. echo "<td colspan='2'><center>".$langNoResult."</center></td>";
  134. echo"</tr>";
  135. }
  136. echo "</table></td></tr>";
  137. }
  138. else
  139. {
  140. // this can prevent bug if there is special chars in $tool
  141. $encodedTool = urlencode($tool);
  142. $tool = urldecode($tool);
  143. if( !isset($reqdate) )
  144. $reqdate = time();
  145. echo "<tr>
  146. <td>
  147. ";
  148. if(isset($_cid)) echo "<b>$_cid : </b>";
  149. echo " <b>".get_lang($tool)."</b>
  150. </td>
  151. </tr>
  152. ";
  153. /* ------ display ------ */
  154. // displayed period
  155. echo "<tr><td>";
  156. switch($period)
  157. {
  158. case "month" :
  159. echo $MonthsLong[date("n", $reqdate)-1].date(" Y", $reqdate);
  160. break;
  161. case "week" :
  162. $weeklowreqdate = ($reqdate-(86400*date("w" , $reqdate)));
  163. $weekhighreqdate = ($reqdate+(86400*(6-date("w" , $reqdate)) ));
  164. echo "<b>".$langFrom."</b> ".date("d " , $weeklowreqdate).$MonthsLong[date("n", $weeklowreqdate)-1].date(" Y" , $weeklowreqdate);
  165. echo " <b>".$langTo."</b> ".date("d " , $weekhighreqdate ).$MonthsLong[date("n", $weekhighreqdate)-1].date(" Y" , $weekhighreqdate);
  166. break;
  167. // default == day
  168. default :
  169. $period = "day";
  170. case "day" :
  171. echo $DaysLong[date("w" , $reqdate)].date(" d " , $reqdate).$MonthsLong[date("n", $reqdate)-1].date(" Y" , $reqdate);
  172. break;
  173. }
  174. echo "</tr></td>";
  175. // periode choice
  176. echo "<tr>
  177. <td>
  178. <small>
  179. [<a href='".$_SERVER['PHP_SELF']."?tool=$encodedTool&period=day&reqdate=$reqdate' class='specialLink'>$langPeriodDay</a>]
  180. [<a href='".$_SERVER['PHP_SELF']."?tool=$encodedTool&period=week&reqdate=$reqdate' class='specialLink'>$langPeriodWeek</a>]
  181. [<a href='".$_SERVER['PHP_SELF']."?tool=$encodedTool&period=month&reqdate=$reqdate' class='specialLink'>$langPeriodMonth</a>]
  182. &nbsp;&nbsp;&nbsp;||&nbsp;&nbsp;&nbsp;
  183. ";
  184. switch($period)
  185. {
  186. case "month" :
  187. // previous and next date must be evaluated
  188. // 30 days should be a good approximation
  189. $previousReqDate = mktime(1,1,1,date("m",$reqdate)-1,1,date("Y",$reqdate));
  190. $nextReqDate = mktime(1,1,1,date("m",$reqdate)+1,1,date("Y",$reqdate));
  191. echo "
  192. [<a href='".$_SERVER['PHP_SELF']."?tool=$encodedTool&period=month&reqdate=$previousReqDate' class='specialLink'>$langPreviousMonth</a>]
  193. [<a href='".$_SERVER['PHP_SELF']."?tool=$encodedTool&period=month&reqdate=$nextReqDate' class='specialLink'>$langNextMonth</a>]
  194. ";
  195. break;
  196. case "week" :
  197. // previous and next date must be evaluated
  198. $previousReqDate = $reqdate - 7*86400;
  199. $nextReqDate = $reqdate + 7*86400;
  200. echo "
  201. [<a href='".$_SERVER['PHP_SELF']."?tool=$encodedTool&period=week&reqdate=$previousReqDate' class='specialLink'>$langPreviousWeek</a>]
  202. [<a href='".$_SERVER['PHP_SELF']."?tool=$encodedTool&period=week&reqdate=$nextReqDate' class='specialLink'>$langNextWeek</a>]
  203. ";
  204. break;
  205. case "day" :
  206. // previous and next date must be evaluated
  207. $previousReqDate = $reqdate - 86400;
  208. $nextReqDate = $reqdate + 86400;
  209. echo "
  210. [<a href='".$_SERVER['PHP_SELF']."?tool=$encodedTool&period=day&reqdate=$previousReqDate' class='specialLink'>$langPreviousDay</a>]
  211. [<a href='".$_SERVER['PHP_SELF']."?tool=$encodedTool&period=day&reqdate=$nextReqDate' class='specialLink'>$langNextDay</a>]
  212. ";
  213. break;
  214. }
  215. echo" &nbsp;&nbsp;&nbsp;||&nbsp;&nbsp;&nbsp;
  216. [<a href='".$_SERVER['PHP_SELF']."' class='specialLink'>$langViewToolList</a>]
  217. </small>
  218. </td>
  219. </tr>
  220. ";
  221. // display information about this period
  222. switch($period)
  223. {
  224. // all days
  225. case "month" :
  226. $sql = "SELECT UNIX_TIMESTAMP(`access_date`)
  227. FROM `$TABLETRACK_ACCESS`
  228. WHERE `access_tool` = '$tool'
  229. ".$courseCodeEqualcidIfNeeded."
  230. AND MONTH(`access_date`) = MONTH(FROM_UNIXTIME('$reqdate'))
  231. AND YEAR(`access_date`) = YEAR(FROM_UNIXTIME('$reqdate'))
  232. ORDER BY `access_date` ASC";
  233. $days_array = daysTab($sql);
  234. makeHitsTable($days_array,$langDay);
  235. break;
  236. // all days
  237. case "week" :
  238. $sql = "SELECT UNIX_TIMESTAMP(`access_date`)
  239. FROM `$TABLETRACK_ACCESS`
  240. WHERE `access_tool` = '$tool'
  241. ".$courseCodeEqualcidIfNeeded."
  242. AND WEEK(`access_date`) = WEEK(FROM_UNIXTIME('$reqdate'))
  243. AND YEAR(`access_date`) = YEAR(FROM_UNIXTIME('$reqdate'))
  244. ORDER BY `access_date` ASC";
  245. $days_array = daysTab($sql);
  246. makeHitsTable($days_array,$langDay);
  247. break;
  248. // all hours
  249. case "day" :
  250. $sql = "SELECT UNIX_TIMESTAMP(`access_date`)
  251. FROM `$TABLETRACK_ACCESS`
  252. WHERE `access_tool` = '$tool'
  253. ".$courseCodeEqualcidIfNeeded."
  254. AND DAYOFYEAR(`access_date`) = DAYOFYEAR(FROM_UNIXTIME('$reqdate'))
  255. AND YEAR(`access_date`) = YEAR(FROM_UNIXTIME('$reqdate'))
  256. ORDER BY `access_date` ASC";
  257. $hours_array = hoursTab($sql,$reqdate);
  258. makeHitsTable($hours_array,$langHour);
  259. break;
  260. }
  261. }
  262. }
  263. else // not allowed to track
  264. {
  265. if(!$is_trackingEnabled)
  266. {
  267. echo $langTrackingDisabled;
  268. }
  269. else
  270. {
  271. echo $langNotAllowed;
  272. }
  273. }
  274. ?>
  275. </table>
  276. <?php
  277. // footer
  278. Display::display_footer();
  279. ?>