toolaccess_details.php 11 KB

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