8ee83afabde36e409aee50182c7f108c39739e87
[atutor.git] / docs / mods / _standard / tracker / lib / tracker.inc.php
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 //get the translations to the gdata numbers first
16 if (!defined('AT_INCLUDE_PATH')) { exit; }
17
18 // NOTE: this script should not be altered. its use will soon be deprecated.
19
20
21 $sql5 = "select * from ".TABLE_PREFIX."g_refs";
22 $result = mysql_query($sql5, $db);
23 $refs = array();
24 while ($row= mysql_fetch_array($result)) {
25         $refs[$row['g_id']] = $row['reference'];
26 }
27 /* this if-statement doesn't make any sense: */
28 if ($_GET['member_id']){
29         $this_member = $_GET['member_id']; 
30 } else {
31         $this_member=$_SESSION['member_id'];
32         if(!authenticate(AT_PRIV_ADMIN, AT_PRIV_RETURN)){
33                 $_GET['member_id'] = $_SESSION['member_id'];
34         }
35 }
36
37 $sql2 = "SELECT g, count(*) AS cnt
38                 FROM ".TABLE_PREFIX."g_click_data
39                 WHERE member_id=$this_member AND course_id='$_SESSION[course_id]'
40                 GROUP BY g
41                 ORDER BY cnt DESC";
42
43 if ($result7 = mysql_query($sql2, $db)) {
44         while($row2 = mysql_fetch_array($result7)) {
45                         $nav_total = ($nav_total + $row2["cnt"]);
46         }
47 }
48
49 if (($result = mysql_query($sql2, $db)) && $_GET['member_id']) {
50         echo '<h3>'._AT('nav_tendencies').' '.$this_user[$this_member].'</h3>';
51
52         echo '<table class="data static" rules="cols" summary="">';
53         echo '<thead>';
54         echo '<tr>';
55                 echo '<th>' . _AT('access_method') . '</th>';
56                 echo '<th>' . _AT('count') . '</th>';
57         echo '</tr>';
58         echo '</thead>';
59
60         echo '<tbody>';
61         while($row = mysql_fetch_array($result)){
62                 echo '<tr>';
63                 echo '<td>';
64                 foreach($refs AS $key => $value){
65                         if($key==$row["g"]){
66                                 echo _AT($value);
67                         }
68                 }
69                 echo '</td>';
70                 
71                 echo '<td><img src="images/bar.gif" height="12" width="'.((($row["cnt"]/$nav_total)*100)*3).'" alt="" />' . $row["cnt"] . '</td>';
72                 echo '</tr>';
73         }
74         echo '</tbody>';
75         echo '</table>';
76         echo '<br /><br />';
77
78
79 ////////////////////////////
80 //Show the member's click path
81         echo '<a name="access"></a>';
82         echo '<h3>'._AT('nav_path').' '.$this_user[$this_member].'</h3>';
83         echo '<table class="data static" rules="cols" summary="">';
84         echo '<thead>';
85         echo '<tr>';
86                 echo '<th>' . _AT('access_method') . '</th>';
87                 echo '<th>' . _AT('page_viewed')   . '</th>';
88                 echo '<th>' . _AT('duration')      . '</th>';
89                 echo '<th>' . _AT('date')          . '</th>';
90         echo '</tr>';
91         echo '</thead>';
92
93         if (authenticate(AT_PRIV_ADMIN, AT_PRIV_RETURN)) {
94                 $sql = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."g_click_data WHERE course_id=$_SESSION[course_id] AND member_id='$_GET[member_id]'";
95         }
96         else {
97                 $sql = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."g_click_data WHERE course_id=$_SESSION[course_id] AND member_id='$_SESSION[member_id]'";
98         }
99         
100         //create the paginator
101         if (!$result = mysql_query($sql, $db)) {
102                 echo _AT('page_error');
103         } else {
104                 $num_rows = mysql_fetch_assoc($result);
105                 
106                 $sql3="SELECT 
107                                 ".TABLE_PREFIX."content.title,
108                                 ".TABLE_PREFIX."content.content_id,
109                                 ".TABLE_PREFIX."g_click_data.to_cid,
110                                 ".TABLE_PREFIX."g_click_data.g,
111                                 ".TABLE_PREFIX."g_click_data.duration,
112                                 ".TABLE_PREFIX."g_click_data.timestamp AS t
113                         FROM
114                                 ".TABLE_PREFIX."content, 
115                                 ".TABLE_PREFIX."g_click_data
116                         WHERE 
117                                 ".TABLE_PREFIX."content.content_id=".TABLE_PREFIX."g_click_data.to_cid
118                                 AND
119                                 ".TABLE_PREFIX."g_click_data.member_id=$this_member
120                                 AND
121                                 ".TABLE_PREFIX."g_click_data.course_id=$_SESSION[course_id]";
122                 
123                 $sql4="select
124                                 ".TABLE_PREFIX."g_click_data.g,
125                                 ".TABLE_PREFIX."g_click_data.member_id, 
126                                 ".TABLE_PREFIX."g_click_data.to_cid, 
127                                 ".TABLE_PREFIX."g_click_data.duration,
128                                 ".TABLE_PREFIX."g_click_data.timestamp AS t
129                         from 
130                                 ".TABLE_PREFIX."g_click_data 
131                         where 
132                                 ".TABLE_PREFIX."g_click_data.to_cid=0 
133                                 AND
134                                 ".TABLE_PREFIX."g_click_data.member_id=$this_member
135                                 AND
136                                 ".TABLE_PREFIX."g_click_data.course_id=$_SESSION[course_id]
137                         order by
138                                 t DESC";
139                 
140                 if ($result=mysql_query($sql3, $db)) {
141                         while($row=mysql_fetch_assoc($result)){
142                                 $this_data[$row['t']]= $row;
143                                 $page_rows++;
144                         }
145                 }
146                 //$num_records = count($this_data);
147                 if ($result2 = mysql_query($sql4, $db)) {
148                         while ($row=mysql_fetch_assoc($result2)) {
149                                 $row['title'] = $refs[$row['g']];
150                                 $this_data[$row['t']] = $row;
151                                 $tool_rows++;
152                         }
153                 }
154                                 
155                 $num_records = ($num_records+count($this_data));        
156                 //$num_records = $num_rows['cnt'];
157
158                 $num_per_page = 30;
159                 if (!$_GET['page']) {
160                         $page = 1;
161                 } else {
162                         $page = intval($_GET['page']);
163                 }
164                 $start = ($page-1)*$num_per_page;
165                 $num_pages = ceil($num_records/$num_per_page);
166                 echo '<tbody>';
167                 echo '<tr>';
168                 echo '<td>'._AT('page').': ';
169                         for ($i=1; $i<=$num_pages; $i++) {
170                                 if ($i == $page) {
171                                         echo $i;
172                                 } else {
173                                         echo '<a href="' . $_SERVER['PHP_SELF'] . '?coverage=raw' . SEP . 'member_id=' . $_GET["member_id"] . SEP . 'page=' . $i . '#access">' . $i . '</a>';
174                                 }
175
176                                 if ($i<$num_pages){
177                                         echo ' <span class="spacer">|</span> ';
178                                 }
179                         }
180                 echo '</td>';
181                 echo '</tr>';
182         }
183
184 if($this_data){
185         ksort($this_data);
186         $current = current($this_data);
187         $pre_time = $current[t];
188         $q = '';
189         foreach ($this_data AS $key => $value) {
190                 $this_page = $p;
191                 if ($q >= $start && $q < ($start+$num_per_page)) {
192                         $diff = $value['duration']; // - $pre_time);
193                         $that_g = $refs[$value['g']];
194         
195                         if ($that_g != '') {
196                                 echo '<tr>';
197                                 if ($that_g == _AT('g_session_start')) {
198                                         echo '<td>';
199                                 } 
200                                 else {
201                                         echo '<td>';
202                                 }
203
204                                 echo _AT($that_g);
205                                 echo '</td>';
206
207                                 if ($that_g == _AT('g_session_start')) {
208                                         echo '<td>';
209                                 } else {
210                                         echo '<td>';
211                                 }
212
213                                 if (substr($value['title'], 0 ,2) == "g_" ) {
214                                         echo _AT($value['title']);
215                                 }
216                                 else {
217                                         echo $value['title'];
218                                 }
219                                 
220                                 echo '</td>';
221                                 if ($that_g == _AT('g_session_start')) {
222                                         echo '<td>';
223                                 }else{
224                                         echo '<td>';
225                                 }
226         
227                                 if ($diff > 60*45) {
228                                         /* time out */
229                                         echo _AT('na');
230                                         $session_time='';
231                                 } else {
232                                         $this_time=date('i:s', $diff);
233                                         echo ' '.$this_time;
234                                         $session_time=($session_time+$diff);
235                                 }
236                                 $remainder = $diff / 60;
237                                 echo '</td>';
238
239                                 if ($that_g == _AT('g_session_start')) {
240                                         echo '<td>';
241                                 } else {
242                                         echo '<td>';
243                                 }
244
245                                 echo $that_date;
246                                 echo '</td>';
247                                 echo '</tr>';
248                         }
249                         
250                         }
251
252                 $that_date=date("M-j-y g:i:s:a", $value[t]);
253                 $that_g=$refs[$value['g']];
254                 $that_title=$value['title']."&nbsp;";
255                 $pre_time = $value['t'];
256                 $q++;
257                 }
258 }
259         echo '<tr>';
260         echo '<td>';
261
262         if ($start_date>0 && $start_date!=$pre_time) {
263                 echo _AT('g_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)).')';
264         }
265
266         else {
267                 //echo _AT('invalid_session');
268         }
269         echo '</td>';
270         echo '</tr>';
271         echo '</tbody>';
272         echo '</table>';
273 }
274 ?>