(no commit message)
[atutor.git] / mods / _standard / tracker / tools / index.php
1 <?php\r
2 /************************************************************************/\r
3 /* ATutor                                                               */\r
4 /************************************************************************/\r
5 /* Copyright (c) 2002-2010                                              */\r
6 /* Inclusive Design Institute                                       */\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="toolcontainer">\r
65 <div class="paging">\r
66         <ul>\r
67         <?php for ($i=1; $i<=$num_pages; $i++): ?>\r
68                 <li>\r
69                         <?php if ($i == $page) : ?>\r
70                                 <a class="current" href="<?php echo $_SERVER['PHP_SELF']; ?>?p=<?php echo $i.$page_string; ?>"><strong><?php echo $i; ?></strong></a>\r
71                         <?php else: ?>\r
72                                 <a href="<?php echo $_SERVER['PHP_SELF']; ?>?p=<?php echo $i.$page_string; ?>"><?php echo $i; ?></a>\r
73                         <?php endif; ?>\r
74                 </li>\r
75         <?php endfor; ?>\r
76         </ul>\r
77 </div>\r
78 \r
79 <table class="data" rules="cols" summary="">\r
80 <colgroup>\r
81         <?php if ($col == 'total_hits'): ?>\r
82                 <col />\r
83                 <col class="sort" />\r
84                 <col span="4" />\r
85         <?php elseif($col == 'unique_hits'): ?>\r
86                 <col span="2" />\r
87                 <col class="sort" />\r
88                 <col span="3" />\r
89         <?php elseif($col == 'average_duration'): ?>\r
90                 <col span="3" />\r
91                 <col class="sort" />\r
92                 <col span="2" />\r
93         <?php elseif($col == 'total_duration'): ?>\r
94                 <col span="4" />\r
95                 <col class="sort" />\r
96                 <col />\r
97         <?php endif; ?>\r
98 </colgroup>\r
99 <thead>\r
100 <tr>\r
101         <th scope="col"><?php echo _AT('page'); ?></th>\r
102         <th scope="col"><a href="mods/_standard/tracker/tools/index.php?<?php echo $orders[$order]; ?>=total_hits"><?php echo _AT('visits');             ?></a></th>\r
103         <th scope="col"><a href="mods/_standard/tracker/tools/index.php?<?php echo $orders[$order]; ?>=unique_hits"><?php echo _AT('unique_visits');     ?></a></th>\r
104         <th scope="col"><a href="mods/_standard/tracker/tools/index.php?<?php echo $orders[$order]; ?>=average_duration"><?php echo _AT('avg_duration'); ?></a></th>\r
105         <th scope="col"><a href="mods/_standard/tracker/tools/index.php?<?php echo $orders[$order]; ?>=total_duration"><?php echo _AT('duration');       ?></a></th>\r
106         <th scope="col"><?php echo _AT('details');       ?></th>\r
107 </tr>\r
108 </thead>\r
109 <tbody>\r
110 <?php if ($row = mysql_fetch_assoc($result)): ?>\r
111         <?php do { ?>\r
112                 <tr onmousedown="document.location='<?php echo AT_BASE_HREF; ?>mods/_standard/tracker/tools/page_student_stats.php?content_id=<?php echo $row['content_id']; ?>'" title="<?php echo _AT('details'); ?>">\r
113                         <td><?php echo $contentManager->_menu_info[$row['content_id']]['title']; ?></td>\r
114                         <td><?php echo $row['total_hits'];       ?></td>\r
115                         <td><?php echo $row['unique_hits'];      ?></td>\r
116                         <td><?php echo $row['average_duration']; ?></td>\r
117                         <td><?php echo $row['total_duration'];   ?></td>\r
118                         <td><a href="mods/_standard/tracker/tools/page_student_stats.php?content_id=<?php echo $row['content_id']; ?>"><?php echo _AT('details'); ?></a></td>\r
119                 </tr>\r
120         <?php } while ($row = mysql_fetch_assoc($result)); ?>\r
121 <?php else: ?>\r
122         <tr>\r
123                 <td colspan="6"><?php echo _AT('none_found'); ?></td>\r
124         </tr>\r
125 <?php endif; ?>\r
126 </tbody>\r
127 </table>\r
128 </div>\r
129 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>