made a copy
[atutor.git] / tools / tracker / index.php
1 <?php\r
2 /************************************************************************/\r
3 /* ATutor                                                               */\r
4 /************************************************************************/\r
5 /* Copyright (c) 2002-2008 by Greg Gay, Joel Kronenberg & Heidi Hazelton*/\r
6 /* Adaptive Technology Resource Centre / University of Toronto          */\r
7 /* http://atutor.ca                                                     */\r
8 /*                                                                      */\r
9 /* This program is free software. You can redistribute it and/or        */\r
10 /* modify it under the terms of the GNU General Public License          */\r
11 /* as published by the Free Software Foundation.                        */\r
12 /************************************************************************/\r
13 // $Id$\r
14 \r
15 define('AT_INCLUDE_PATH', '../../include/');\r
16 require(AT_INCLUDE_PATH.'vitals.inc.php');\r
17 authenticate(AT_PRIV_CONTENT);\r
18 \r
19 require(AT_INCLUDE_PATH.'header.inc.php');\r
20 \r
21 \r
22 $orders = array('asc' => 'desc', 'desc' => 'asc');\r
23 $cols   = array('total_hits' => 1, 'unique_hits' => 1, 'average_duration' => 1, 'total_duration' => 1);\r
24 \r
25 if (isset($_GET['asc'])) {\r
26         $order = 'asc';\r
27         $col   = isset($cols[$_GET['asc']]) ? $_GET['asc'] : 'total_hits';\r
28 } else if (isset($_GET['desc'])) {\r
29         $order = 'desc';\r
30         $col   = isset($cols[$_GET['desc']]) ? $_GET['desc'] : 'total_hits';\r
31 } else {\r
32         // no order set\r
33         $order = 'desc';\r
34         $col   = 'total_hits';\r
35 }\r
36 \r
37 $page_string = SEP.$order.'='.$col;\r
38 \r
39 if (!isset($_GET['cnt'])) {\r
40         $sql    = "SELECT COUNT(DISTINCT content_id) AS cnt FROM ".TABLE_PREFIX."member_track WHERE course_id=$_SESSION[course_id]";\r
41         $result = mysql_query($sql, $db);\r
42         $row = mysql_fetch_assoc($result);\r
43         $cnt = $row['cnt'];\r
44 } else {\r
45         $cnt = intval($_GET['cnt']);\r
46 }\r
47 \r
48 $num_results = $cnt;\r
49 $results_per_page = 15;\r
50 $num_pages = max(ceil($num_results / $results_per_page), 1);\r
51 $page = intval($_GET['p']);\r
52 if (!$page) {\r
53         $page = 1;\r
54 }       \r
55 $count = (($page-1) * $results_per_page) + 1;\r
56 \r
57 $offset = ($page-1)*$results_per_page;\r
58 \r
59 /*create a table that lists all the content pages and the number of time they were viewed*/\r
60 $sql = "SELECT content_id, COUNT(*) AS unique_hits, SUM(counter) AS total_hits, SEC_TO_TIME(SUM(duration)/SUM(counter)) AS average_duration, SEC_TO_TIME(SUM(duration)) AS total_duration FROM ".TABLE_PREFIX."member_track WHERE course_id=$_SESSION[course_id] GROUP BY content_id ORDER BY $col $order LIMIT $offset, $results_per_page";\r
61 $result = mysql_query($sql, $db);\r
62 \r
63 ?>\r
64 <div class="paging">\r
65         <ul>\r
66         <?php for ($i=1; $i<=$num_pages; $i++): ?>\r
67                 <li>\r
68                         <?php if ($i == $page) : ?>\r
69                                 <a class="current" href="<?php echo $_SERVER['PHP_SELF']; ?>?p=<?php echo $i.$page_string; ?>"><em><?php echo $i; ?></em></a>\r
70                         <?php else: ?>\r
71                                 <a href="<?php echo $_SERVER['PHP_SELF']; ?>?p=<?php echo $i.$page_string; ?>"><?php echo $i; ?></a>\r
72                         <?php endif; ?>\r
73                 </li>\r
74         <?php endfor; ?>\r
75         </ul>\r
76 </div>\r
77 \r
78 <table class="data" rules="cols" summary="">\r
79 <colgroup>\r
80         <?php if ($col == 'total_hits'): ?>\r
81                 <col />\r
82                 <col class="sort" />\r
83                 <col span="4" />\r
84         <?php elseif($col == 'unique_hits'): ?>\r
85                 <col span="2" />\r
86                 <col class="sort" />\r
87                 <col span="3" />\r
88         <?php elseif($col == 'average_duration'): ?>\r
89                 <col span="3" />\r
90                 <col class="sort" />\r
91                 <col span="2" />\r
92         <?php elseif($col == 'total_duration'): ?>\r
93                 <col span="4" />\r
94                 <col class="sort" />\r
95                 <col />\r
96         <?php endif; ?>\r
97 </colgroup>\r
98 <thead>\r
99 <tr>\r
100         <th scope="col"><?php echo _AT('page'); ?></th>\r
101         <th scope="col"><a href="tools/tracker/index.php?<?php echo $orders[$order]; ?>=total_hits"><?php echo _AT('visits');             ?></a></th>\r
102         <th scope="col"><a href="tools/tracker/index.php?<?php echo $orders[$order]; ?>=unique_hits"><?php echo _AT('unique_visits');     ?></a></th>\r
103         <th scope="col"><a href="tools/tracker/index.php?<?php echo $orders[$order]; ?>=average_duration"><?php echo _AT('avg_duration'); ?></a></th>\r
104         <th scope="col"><a href="tools/tracker/index.php?<?php echo $orders[$order]; ?>=total_duration"><?php echo _AT('duration');       ?></a></th>\r
105         <th scope="col"><?php echo _AT('details');       ?></th>\r
106 </tr>\r
107 </thead>\r
108 <tbody>\r
109 <?php if ($row = mysql_fetch_assoc($result)): ?>\r
110         <?php do { ?>\r
111                 <tr onmousedown="document.location='<?php echo AT_BASE_HREF; ?>tools/tracker/page_student_stats.php?content_id=<?php echo $row['content_id']; ?>'" title="<?php echo _AT('details'); ?>">\r
112                         <td><?php echo $contentManager->_menu_info[$row['content_id']]['title']; ?></td>\r
113                         <td><?php echo $row['total_hits'];       ?></td>\r
114                         <td><?php echo $row['unique_hits'];      ?></td>\r
115                         <td><?php echo $row['average_duration']; ?></td>\r
116                         <td><?php echo $row['total_duration'];   ?></td>\r
117                         <td><a href="tools/tracker/page_student_stats.php?content_id=<?php echo $row['content_id']; ?>"><?php echo _AT('details'); ?></a></td>\r
118                 </tr>\r
119         <?php } while ($row = mysql_fetch_assoc($result)); ?>\r
120 <?php else: ?>\r
121         <tr>\r
122                 <td colspan="6"><?php echo _AT('none_found'); ?></td>\r
123         </tr>\r
124 <?php endif; ?>\r
125 </tbody>\r
126 </table>\r
127 \r
128 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>