PageRenderTime 121ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/mods/_standard/tracker/lib/tracker_stats.inc.php

https://github.com/harriswong/ATutor
PHP | 487 lines | 390 code | 71 blank | 26 comment | 56 complexity | 58f51b2fff2825dcfed8b7aea60cc456 MD5 | raw file
  1. <?php
  2. /****************************************************************/
  3. /* ATutor */
  4. /****************************************************************/
  5. /* Copyright (c) 2002-2010 */
  6. /* Inclusive Design Institute */
  7. /* http://atutor.ca */
  8. /* */
  9. /* This program is free software. You can redistribute it and/or*/
  10. /* modify it under the terms of the GNU General Public License */
  11. /* as published by the Free Software Foundation. */
  12. /****************************************************************/
  13. /////////////////////////////
  14. //Display the g_data bar chart for the member selected
  15. if (!defined('AT_INCLUDE_PATH')) { exit; }
  16. // NOTE: this script should not be altered. its use will soon be deprecated.
  17. //get the summary data for all pages
  18. //get the translations for the g numbers
  19. $to_cid = $_GET['to_cid'];
  20. $stats = $_GET['stats'];
  21. $g_id = $_GET['g_id'];
  22. $sql5 = "select * from ".TABLE_PREFIX."g_refs";
  23. $result = mysql_query($sql5, $db);
  24. $refs = array();
  25. while ($row= mysql_fetch_array($result)) {
  26. $refs[$row['g_id']] = $row['reference'];
  27. }
  28. //get the g translation for non content pages
  29. $sql8= "select
  30. G.g,
  31. R.reference,
  32. R.g_id
  33. from
  34. ".TABLE_PREFIX."g_click_data G,
  35. ".TABLE_PREFIX."g_refs R
  36. where
  37. G.g = R.g_id
  38. AND
  39. course_id='$_SESSION[course_id]'";
  40. if(!$result8 = mysql_query($sql8, $db)){
  41. require(AT_INCLUDE_PATH.'footer.inc.php');
  42. exit;
  43. }else{
  44. $title_refs = array();
  45. while ($row= mysql_fetch_assoc($result8)) {
  46. $title_refs2[$row['g']] = $row['reference'];
  47. }
  48. }
  49. //get the translations for the content id numbers
  50. $sql7 = "select
  51. C.title,
  52. C.content_id
  53. from
  54. ".TABLE_PREFIX."content C
  55. where
  56. course_id='$_SESSION[course_id]'";
  57. if(!$result7 = mysql_query($sql7, $db)){
  58. require(AT_INCLUDE_PATH.'footer.inc.php');
  59. exit;
  60. }
  61. $title_refs = array();
  62. while ($row= mysql_fetch_array($result7)) {
  63. $title_refs[$row['content_id']] = $row['title'];
  64. }
  65. //get tools ATutor tools traffic
  66. $sql9="SELECT
  67. G.to_cid,
  68. G.g,
  69. R.g_id,
  70. R.reference
  71. from
  72. ".TABLE_PREFIX."g_click_data G,
  73. ".TABLE_PREFIX."g_refs R
  74. where
  75. G.to_cid = 0
  76. AND
  77. course_id='$_SESSION[course_id]'";
  78. $title_tools = array();
  79. $result9 = mysql_query($sql9, $db);
  80. while ($row= mysql_fetch_array($result9)) {
  81. if($row['g'] == $row['g_id']){
  82. $title_tools[$row['g_id']] = $row['reference'];
  83. $tool_grefs[$row['g_id']] = $row['g_id'];
  84. $gcount[$row['g_id']]++;
  85. }
  86. }
  87. $sql10 = "select count(g) from ".TABLE_PREFIX."g_click_data where course_id='$_SESSION[course_id]' GROUP BY g";
  88. $result10 = mysql_query($sql10, $db);
  89. while($row=mysql_fetch_array($result10)){
  90. $thiscount[]=$row;
  91. }
  92. if($_GET['stats']="summary" && !$to_cid &&!$_GET['csv'] && !$_GET['g_id']){
  93. $sql12= "select to_cid, g, AVG(duration) AS t, count(g) as c from ".TABLE_PREFIX."g_click_data where to_cid='0' AND course_id='$_SESSION[course_id]' GROUP BY g";
  94. if($result12=mysql_query($sql12, $db)){
  95. while($row=mysql_fetch_array($result12)){
  96. if($row['g']){
  97. $nav_total = ($nav_total + $row['c']);
  98. }
  99. if($row['to_cid']==0){
  100. $that_time[$row['g']]= $row['t'];
  101. }
  102. }
  103. }else{
  104. echo _AT('unknown_error');
  105. }
  106. ?>
  107. <br />
  108. <a name="show_pages"></a>
  109. <h3><?php echo _AT('tool_summary'); ?></h3>
  110. <table class="data static" rules="cols" summary="">
  111. <thead>
  112. <tr>
  113. <th><?php echo _AT('at_tools'); ?></th>
  114. <th><?php echo _AT('hit_count'); ?></th>
  115. <th><?php echo _AT('avg_duration'); ?></th>
  116. <th><?php echo _AT('details'); ?></th>
  117. </tr>
  118. </thead>
  119. <tbody>
  120. <?php
  121. //this array needs to be created from the database
  122. //(eventually add new field to g_refs table called "timed" values true/false
  123. $timed_tools=array(14=>14, 15=>15, 16=>16, 17=>17, 18=>18, 20=>20, 21=>21, 23=>23, 27=>27, 28=>28, 29=>29, 31=>31, 32=>32, 35=>35);
  124. foreach($title_tools as $key=>$value) {
  125. $tool_names[$key] = $gcount[$key];
  126. }
  127. if (is_array($tool_names)) {
  128. arsort($tool_names);
  129. foreach($tool_names as $key=>$value) {
  130. echo '<tr>';
  131. echo '<td>' . _AT($title_tools[$key]) . '</td>';
  132. echo '<td><img src="images/bar.gif" height="12" width="' . ((($gcount[$key]/$nav_total)*100)*2) . '" alt="" />' . $value . '</td>';
  133. $that_avgtime='';
  134. if($timed_tools[$key]==$key) {
  135. $that_avgtime=number_format((number_format($that_time[$key], 1 )/$gcount[$key]),1);
  136. }
  137. echo '<td>';
  138. if($that_avgtime) {
  139. echo $that_avgtime;
  140. } else {
  141. echo _AT('na');
  142. }
  143. echo '</td>';
  144. echo '<td><a href="' . $_SERVER['PHP_SELF'] . '?g_id=' . $key . '#show_pages">' . _AT('details') . '</a></td>';
  145. echo '</tr>';
  146. }
  147. }
  148. ?>
  149. </tbody>
  150. </table>
  151. <br /><br />
  152. <h3><?php echo _AT('page_stats'); ?></h3>
  153. <table class="data static" rules="cols" summary="">
  154. <thead>
  155. <tr>
  156. <th><?php echo _AT('page_title'); ?></th>
  157. <th><?php echo _AT('hit_count'); ?></th>
  158. <th><?php echo _AT('avg_duration'); ?></th>
  159. <th><?php echo _AT('details'); ?></th>
  160. </tr>
  161. </thead>
  162. <?php
  163. //get content page traffic
  164. $sql6 = "SELECT G.to_cid, count(*) AS pages, G.g
  165. FROM ".TABLE_PREFIX."g_click_data G
  166. WHERE G.to_cid <> 0 AND course_id='$_SESSION[course_id]'
  167. GROUP BY G.to_cid";
  168. $result6 = mysql_query($sql6, $db);
  169. if(!$result6) {
  170. echo "query failed";
  171. require(AT_INCLUDE_PATH.'footer.inc.php');
  172. exit;
  173. }
  174. $sql11 = "SELECT to_cid, AVG(duration) AS t FROM ".TABLE_PREFIX."g_click_data WHERE course_id='$_SESSION[course_id]' GROUP BY to_cid";
  175. $result11 = mysql_query($sql11, $db);
  176. if ($result11) {
  177. while($row = mysql_fetch_array($result11)) {
  178. $this_time[$row['to_cid']]= $row['t'];
  179. }
  180. }
  181. else {
  182. echo _AT('unknown_error');
  183. }
  184. $max_bar_width='180';
  185. $result9 = mysql_query($sql6, $db);
  186. while($row = mysql_fetch_array($result9)) {
  187. $total_hits=($total_hits + $row["pages"]);
  188. }
  189. if($total_hits) {
  190. $bar_factor = ($max_bar_width/$total_hits);
  191. }
  192. if ($result6 = mysql_query($sql6, $db)) {
  193. echo '<tbody>';
  194. while($row = mysql_fetch_array($result6)) {
  195. if($title_refs[$row['to_cid']] != '') {
  196. echo '<tr>';
  197. echo '<td>' . $title_refs[$row['to_cid']] . '</td>';
  198. echo '<td><img src="images/bar.gif" height="12" width="' . ($row["pages"]*$bar_factor) . '" alt="" />' . $row["pages"] . '</td>';
  199. $this_avgtime=(number_format($this_time[$row['to_cid']], 1 )/$row["pages"]);
  200. echo '<td>' . number_format($this_avgtime, 1) . '</td>';
  201. echo '<td><a href="' . $_SERVER['PHP_SELF'] . '?stats=details' . SEP . 'to_cid=' . $row['to_cid'] . '#show_pages">' . _AT('details') . '</a></td>';
  202. echo '</tr>';
  203. }
  204. }
  205. echo '<tbody>';
  206. }
  207. echo '</table>';
  208. } //end summary
  209. //get the rawdata for a single page
  210. if(authenticate(AT_PRIV_ADMIN, AT_PRIV_RETURN)){
  211. $sql3="select
  212. ".TABLE_PREFIX."content.title,
  213. ".TABLE_PREFIX."content.content_id,
  214. ".TABLE_PREFIX."g_click_data.member_id as m,
  215. ".TABLE_PREFIX."g_click_data.to_cid,
  216. ".TABLE_PREFIX."g_click_data.g,
  217. ".TABLE_PREFIX."g_click_data.timestamp AS t
  218. from
  219. ".TABLE_PREFIX."content,
  220. ".TABLE_PREFIX."g_click_data
  221. where
  222. ".TABLE_PREFIX."content.content_id=".TABLE_PREFIX."g_click_data.to_cid
  223. AND
  224. ".TABLE_PREFIX."g_click_data.to_cid=$to_cid
  225. AND
  226. ".TABLE_PREFIX."g_click_data.course_id=$_SESSION[course_id]";
  227. $result3=mysql_query($sql3, $db);
  228. if($result3){
  229. while($row=mysql_fetch_array($result3)){
  230. $this_data[$row["t"]]= $row;
  231. $this_user[$row["t"]]= $row['m'];
  232. }
  233. ksort($this_data);
  234. $current = current($this_data);
  235. $pre_time = $current[t];
  236. }
  237. }
  238. if($to_cid) {
  239. ?>
  240. <a name="show_pages"></a>
  241. <p>
  242. [<a href="<?php echo $_SERVER['PHP_SELF'].'?stats=summary';?>#show_pages"><?php echo _AT('back_to_summary'); ?></a>]
  243. </p>
  244. <h3><?php echo _AT('access_stats'); ?>: <?php echo $current['title']; ?></h3>
  245. <table class="data static" rules="cols" summary="">
  246. <thead>
  247. <tr>
  248. <th scope="col"><?php echo _AT('access_method'); ?></th>
  249. <th scope="col"><?php echo _AT('count'); ?></th>
  250. </tr>
  251. </thead>
  252. <?php
  253. //get the number of clicks per g
  254. $sql2 = "select
  255. g,
  256. count(*) AS cnt
  257. from
  258. ".TABLE_PREFIX."g_click_data
  259. where
  260. to_cid=$to_cid
  261. AND
  262. course_id='$_SESSION[course_id]'
  263. group by
  264. g";
  265. if($result2 = mysql_query($sql2, $db)){
  266. echo '<tbody>';
  267. while($row = mysql_fetch_array($result2)){
  268. echo '<tr>';
  269. echo '<td>';
  270. foreach($refs AS $key => $value){
  271. if($key==$row["g"]){
  272. echo _AT($value);
  273. }
  274. }
  275. echo '</td>';
  276. echo '<td><img src="images/bar.gif" height="12" width="' . ($row["cnt"]*2) . '" alt="" />' . $row["cnt"] . '</td>';
  277. echo '</tr>';
  278. }
  279. }
  280. echo '</tbody>';
  281. echo '</table>';
  282. echo '<br />';
  283. //////////////
  284. $sql4="select
  285. ".TABLE_PREFIX."g_click_data.g,
  286. ".TABLE_PREFIX."g_click_data.member_id AS m,
  287. ".TABLE_PREFIX."g_click_data.to_cid,
  288. ".TABLE_PREFIX."g_click_data.timestamp AS t
  289. from
  290. ".TABLE_PREFIX."g_click_data
  291. where
  292. ".TABLE_PREFIX."g_click_data.to_cid=0
  293. AND
  294. ".TABLE_PREFIX."g_click_data.to_cid=$to_cid
  295. AND
  296. ".TABLE_PREFIX."g_click_data.course_id=$_SESSION[course_id]
  297. GROUP BY
  298. m
  299. ";
  300. $result4 = mysql_query($sql4, $db);
  301. if($result4){
  302. if($this_data){
  303. echo '<br />';
  304. echo '<a name="show_pages"></a>';
  305. echo '<h3>'._AT('pages_stats', $current["title"]).'</h3>';
  306. echo '<table class="data static" rules="cols" summary="">';
  307. echo '<thead>';
  308. echo '<tr>';
  309. echo '<th scope="col">' . _AT('access_method') . '</th>';
  310. echo '<th scope="col">' . _AT('duration_sec') . '</th>';
  311. echo '<th scope="col">' . _AT('date') . '</th>';
  312. echo '<th scope="col">' . _AT('student_id') . '</th>';
  313. echo '</tr>';
  314. echo '<thead>';
  315. echo '<tbody>';
  316. foreach($this_data AS $key => $value){
  317. if(!$start_date){
  318. $start_date=$pre_time;
  319. }
  320. $diff = abs($value[t] - $pre_time);
  321. if ($diff > 60*45) {
  322. $end_date=$value[t];
  323. echo '<tr>';
  324. echo '<td>';
  325. if($start_date>0 && $start_date!=$pre_time){
  326. echo _AT('session_start').' '.date("F j, Y, g:i a", $start_date).' '._AT('session_end').' '.date("F j, Y, g:i a", $pre_time).' ('._AT('duration').':'.date('i \m\i\n s \s\e\c',($pre_time-$start_date)).')';
  327. echo '</td>';
  328. echo '</tr>';
  329. }
  330. else if($value[g]==19) {
  331. //don't do anything if its a logout
  332. }
  333. else {
  334. echo _AT('invalid_session');
  335. }
  336. $start_date='';
  337. }
  338. else {
  339. if (!$start_date) {
  340. $start_date=$value[t];
  341. }
  342. }
  343. echo '<tr>';
  344. echo '<td>';
  345. $that_g=$refs[$value['g']];
  346. echo _AT($that_g);
  347. echo '</td>';
  348. echo '<td>';
  349. if ($diff > 60*45) {
  350. echo _AT('na');
  351. $session_time='';
  352. }else{
  353. $this_time=date('i.s', $diff);
  354. echo ' '.$this_time;
  355. $session_time=($session_time+$diff);
  356. }
  357. $remainder = $diff / 60;
  358. echo '</td>';
  359. echo '<td>';
  360. echo $that_date;
  361. echo '</td>';
  362. echo '<td>'.$this_user[$value['m']].'</td>';
  363. echo '</tr>';
  364. $that_date=date("M-j-y g:i:s:a", $value[t]);
  365. $that_title=$value[title]."&nbsp;";
  366. $pre_time = $value['t'];
  367. }
  368. echo '</tbody>';
  369. echo '</table>';
  370. }
  371. }
  372. } /// end page detail
  373. if($_GET['g_id']){
  374. $sql14 = "select member_id, login, first_name, last_name from ".TABLE_PREFIX."members";
  375. $result14=mysql_query($sql14, $db);
  376. while($row=mysql_fetch_array($result14)){
  377. if($row['first_name'] && $row['last_name']){
  378. $this_user[$row['member_id']]= $row['first_name'].' '. $row['last_name'];
  379. }else{
  380. $this_user[$row['member_id']]= $row['login'];
  381. }
  382. }
  383. $sql13 = "select *, timestamp as t from ".TABLE_PREFIX."g_click_data where to_cid='0' AND g='$_GET[g_id]' AND course_id='$_SESSION[course_id]'";
  384. $result13 = mysql_query($sql13, $db);
  385. echo '<a name="show_pages"></a>';
  386. echo '<h3>'._AT('tools_details').' ('._AT($title_refs2[$g_id]).')</h3>';
  387. echo '<p>[<a href="'.$_SERVER['PHP_SELF'].'?stats=summary#show_pages">'._AT('back_to_summary'),'</a>]</p>';
  388. echo '<table class="data static" rules="cols" summary="">';
  389. echo '<thead>';
  390. echo '<tr>';
  391. echo '<th scope="col">' . _AT('origin_page') . '</th>';
  392. echo '<th scope="col">' . _AT('duration_sec') . '</th>';
  393. echo '<th scope="col">' . _AT('date') . '</th>';
  394. echo '<th scope="col">' . _AT('student_id') . '</th>';
  395. echo '</tr>';
  396. echo '</thead>';
  397. echo '<tbody>';
  398. while ($row=mysql_fetch_array($result13)){
  399. echo '<tr>';
  400. if ($row['from_cid'] == 0) {
  401. echo '<td>'._AT($title_refs2[$row['g']]).'</td>';
  402. }
  403. else if ($title_refs[$row['from_cid']] != '') {
  404. echo '<td>'.$title_refs[$row['from_cid']].'</td>';
  405. }
  406. if ($title_refs[$row['from_cid']] != '' || $row['from_cid'] == 0) {
  407. echo '<td>'.$row['duration'].'</td>';
  408. echo '<td>'.date("M-j-y g:i:s:a",$row['t'] ).'</td>';
  409. echo '<td>'.$this_user[$row['member_id']].'</td>';
  410. }
  411. echo '</tr>';
  412. }
  413. echo '</tbody>';
  414. echo '</table>';
  415. }
  416. ?>