toolaccess_details.php 13 KB

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