toolaccess_details.php 10 KB

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