toolaccess_details.php 11 KB

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