toolaccess_details.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. $courseId = api_get_course_int_id();
  56. $tool = $_REQUEST['tool'];
  57. $period = $_REQUEST['period'];
  58. $reqdate = $_REQUEST['reqdate'];
  59. ?>
  60. <table width="100%" cellpadding="2" cellspacing="0" border="0">
  61. <?php
  62. $TABLETRACK_ACCESS = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ACCESS);
  63. if (isset($courseId)) //stats for the current course
  64. {
  65. // to see stats of one course user must be courseAdmin of this course
  66. $is_allowedToTrack = api_is_course_admin();
  67. $courseCodeEqualcidIfNeeded = "AND c_id = '$courseId'";
  68. }
  69. else // stats for all courses
  70. {
  71. // to see stats of all courses user must be platformAdmin
  72. $is_allowedToTrack = api_is_platform_admin();
  73. $courseCodeEqualcidIfNeeded = "";
  74. }
  75. if ( $is_allowedToTrack) {
  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. for($j = 0 ; $j < count($results) ; $j++) {
  105. echo "<tr>";
  106. echo "<td><a href='toolaccess_details.php?tool=".urlencode($results[$j][0])."'>".get_lang($results[$j][0])."</a></td>";
  107. echo "<td align='right'>".$results[$j][1]."</td>";
  108. echo"</tr>";
  109. }
  110. } else {
  111. echo "<tr>";
  112. echo "<td colspan='2'><center>".get_lang('NoResult')."</center></td>";
  113. echo"</tr>";
  114. }
  115. echo "</table></td></tr>";
  116. }
  117. else
  118. {
  119. // this can prevent bug if there is special chars in $tool
  120. $encodedTool = urlencode($tool);
  121. $tool = urldecode($tool);
  122. if( !isset($reqdate) )
  123. $reqdate = time();
  124. echo "<tr>
  125. <td>
  126. ";
  127. if(isset($_cid)) echo "<b>$_cid : </b>";
  128. echo " <b>".get_lang($tool)."</b>
  129. </td>
  130. </tr>
  131. ";
  132. /* ------ display ------ */
  133. // displayed period
  134. echo "<tr><td>";
  135. switch($period)
  136. {
  137. case "month" :
  138. echo $MonthsLong[date("n", $reqdate)-1].date(" Y", $reqdate);
  139. break;
  140. case "week" :
  141. $weeklowreqdate = ($reqdate-(86400*date("w" , $reqdate)));
  142. $weekhighreqdate = ($reqdate+(86400*(6-date("w" , $reqdate)) ));
  143. echo "<b>".$langFrom."</b> ".date("d " , $weeklowreqdate).$MonthsLong[date("n", $weeklowreqdate)-1].date(" Y" , $weeklowreqdate);
  144. echo " <b>".$langTo."</b> ".date("d " , $weekhighreqdate ).$MonthsLong[date("n", $weekhighreqdate)-1].date(" Y" , $weekhighreqdate);
  145. break;
  146. // default == day
  147. default :
  148. $period = "day";
  149. case "day" :
  150. echo $DaysLong[date("w" , $reqdate)].date(" d " , $reqdate).$MonthsLong[date("n", $reqdate)-1].date(" Y" , $reqdate);
  151. break;
  152. }
  153. echo "</tr></td>";
  154. // periode choice
  155. echo "<tr>
  156. <td>
  157. <small>
  158. [<a href='".api_get_self()."?tool=$encodedTool&period=day&reqdate=$reqdate' class='specialLink'>$langPeriodDay</a>]
  159. [<a href='".api_get_self()."?tool=$encodedTool&period=week&reqdate=$reqdate' class='specialLink'>$langPeriodWeek</a>]
  160. [<a href='".api_get_self()."?tool=$encodedTool&period=month&reqdate=$reqdate' class='specialLink'>$langPeriodMonth</a>]
  161. &nbsp;&nbsp;&nbsp;||&nbsp;&nbsp;&nbsp;
  162. ";
  163. switch($period)
  164. {
  165. case "month" :
  166. // previous and next date must be evaluated
  167. // 30 days should be a good approximation
  168. $previousReqDate = mktime(1,1,1,date("m",$reqdate)-1,1,date("Y",$reqdate));
  169. $nextReqDate = mktime(1,1,1,date("m",$reqdate)+1,1,date("Y",$reqdate));
  170. echo "
  171. [<a href='".api_get_self()."?tool=$encodedTool&period=month&reqdate=$previousReqDate' class='specialLink'>$langPreviousMonth</a>]
  172. [<a href='".api_get_self()."?tool=$encodedTool&period=month&reqdate=$nextReqDate' class='specialLink'>$langNextMonth</a>]
  173. ";
  174. break;
  175. case "week" :
  176. // previous and next date must be evaluated
  177. $previousReqDate = $reqdate - 7*86400;
  178. $nextReqDate = $reqdate + 7*86400;
  179. echo "
  180. [<a href='".api_get_self()."?tool=$encodedTool&period=week&reqdate=$previousReqDate' class='specialLink'>$langPreviousWeek</a>]
  181. [<a href='".api_get_self()."?tool=$encodedTool&period=week&reqdate=$nextReqDate' class='specialLink'>$langNextWeek</a>]
  182. ";
  183. break;
  184. case "day" :
  185. // previous and next date must be evaluated
  186. $previousReqDate = $reqdate - 86400;
  187. $nextReqDate = $reqdate + 86400;
  188. echo "
  189. [<a href='".api_get_self()."?tool=$encodedTool&period=day&reqdate=$previousReqDate' class='specialLink'>$langPreviousDay</a>]
  190. [<a href='".api_get_self()."?tool=$encodedTool&period=day&reqdate=$nextReqDate' class='specialLink'>$langNextDay</a>]
  191. ";
  192. break;
  193. }
  194. echo" &nbsp;&nbsp;&nbsp;||&nbsp;&nbsp;&nbsp;
  195. [<a href='".api_get_self()."' class='specialLink'>$langViewToolList</a>]
  196. </small>
  197. </td>
  198. </tr>
  199. ";
  200. // display information about this period
  201. switch($period)
  202. {
  203. // all days
  204. case "month" :
  205. $sql = "SELECT UNIX_TIMESTAMP(access_date)
  206. FROM $TABLETRACK_ACCESS
  207. WHERE access_tool = '$tool'
  208. $courseCodeEqualcidIfNeeded
  209. AND MONTH(access_date) = MONTH(FROM_UNIXTIME('$reqdate'))
  210. AND YEAR(access_date) = YEAR(FROM_UNIXTIME('$reqdate'))
  211. ORDER BY access_date ASC";
  212. $days_array = daysTab($sql);
  213. makeHitsTable($days_array,$langDay);
  214. break;
  215. // all days
  216. case "week" :
  217. $sql = "SELECT UNIX_TIMESTAMP(access_date)
  218. FROM $TABLETRACK_ACCESS
  219. WHERE access_tool = '$tool'
  220. $courseCodeEqualcidIfNeeded
  221. AND WEEK(access_date) = WEEK(FROM_UNIXTIME('$reqdate'))
  222. AND YEAR(access_date) = YEAR(FROM_UNIXTIME('$reqdate'))
  223. ORDER BY access_date ASC";
  224. $days_array = daysTab($sql);
  225. makeHitsTable($days_array,$langDay);
  226. break;
  227. // all hours
  228. case "day" :
  229. $sql = "SELECT UNIX_TIMESTAMP(access_date)
  230. FROM $TABLETRACK_ACCESS
  231. WHERE access_tool = '$tool'
  232. $courseCodeEqualcidIfNeeded
  233. AND DAYOFYEAR(access_date) = DAYOFYEAR(FROM_UNIXTIME('$reqdate'))
  234. AND YEAR(access_date) = YEAR(FROM_UNIXTIME('$reqdate'))
  235. ORDER BY access_date ASC";
  236. $hours_array = hoursTab($sql,$reqdate);
  237. makeHitsTable($hours_array,$langHour);
  238. break;
  239. }
  240. }
  241. } else { // not allowed to track
  242. echo get_lang('NotAllowed');
  243. }
  244. echo '</table>';
  245. Display::display_footer();