toolaccess_details.php 11 KB

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