e87bfc992c00742e10ca310be0f995fa149b66b8
[atutor.git] / docs / mods / _standard / tracker / lib / tracker2.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 if (!defined('AT_INCLUDE_PATH')) { exit; }
14
15 // NOTE: this script should not be altered. its use will soon be deprecated.
16
17
18 //how many content pages are in this course
19 $sql25 = "SELECT content_id from ".TABLE_PREFIX."content where course_id = $_SESSION[course_id]";
20 $result29 = mysql_query($sql25, $db);
21 $num_rows_total = mysql_num_rows($result29);
22 //get the title for each content_id
23 $sql7 = "select
24                         C.title,
25                         C.content_id
26
27                 from
28                         ".TABLE_PREFIX."content C
29                 where
30                         course_id='$_SESSION[course_id]'";
31         if(!$result7 = mysql_query($sql7, $db)){
32                 echo AT_ERRORS_GENERAL;
33                 require(AT_INCLUDE_PATH.'footer.inc.php');
34                 exit;
35         }
36         $title_refs = array();
37         while ($row= mysql_fetch_array($result7)) {
38                 $title_refs[$row['content_id']] = $row['title'];
39
40         }
41
42 $sql2 = "SELECT * from ".TABLE_PREFIX."g_click_data where member_id = $_SESSION[member_id] AND course_id = $_SESSION[course_id]";
43 $result28 = mysql_query($sql2, $db);
44
45 echo '<br /><h3>'._AT('tracker_summary_read', $this_user[$_SESSION["member_id"]]).'</h3>';
46 echo '<a href="'.$_SERVER['PHP_SELF'].'#not_viewed"><img src="images/clr.gif" border="0" alt="'._AT('tracker_not_viewed').'"/></a>';
47
48 echo '<table class="data static" rules="cols" summary="">';
49 echo '<thead>';
50 echo '<tr>';
51
52 echo '<th>' . _AT('page')         . '</th>';
53 echo '<th>' . _AT('visits')       . '</th>';
54 echo '<th>' . _AT('duration_sec') . '</th>';
55 echo '</tr>';
56 echo '</thead>';
57
58
59 while ($row2= mysql_fetch_array($result28)){
60         $duration[$row2['to_cid']] = ($duration[$row2['to_cid']] + $row2['duration']);
61         $visits[$row2['to_cid']] = ($visits[$row2['to_cid']] +1);
62 }
63
64 $sql= "SELECT DISTINCT to_cid from ".TABLE_PREFIX."g_click_data where member_id = $_SESSION[member_id] AND course_id = $_SESSION[course_id]";
65 $result27 = mysql_query($sql, $db);
66 $viewed_page = array();
67
68
69 echo '<tbody>';
70 while ($row = mysql_fetch_array($result27)) {
71         if ($row['to_cid']) {
72                 $viewed_pages[$row['to_cid']] = $title_refs[$row['to_cid']];
73                 $num_rows_read = ($num_rows_read +1);
74                 
75                 if ($title_refs[$row['to_cid']] !='') {
76                         echo '<tr>';
77                         echo '<td>';
78                                 echo '<a href="./index.php?cid='.$row['to_cid'].'">';
79                                 echo $title_refs[$row['to_cid']].'</a></td><td align="center" class="row1"> '.$visits[$row['to_cid']].' </td><td align="center" class="row1"> '.number_format($duration[$row['to_cid']]);
80                         echo '</td>';
81                         echo '</tr>';
82                 }
83         }
84 }
85
86 if(count($viewed_pages) > 0){
87         foreach($viewed_pages as $key1 => $refs1){
88                 $viewed_page_keys[$key1] = $key1;
89         }
90         foreach($title_refs as $key => $ref){
91                 if(!in_array($key, $viewed_page_keys)){
92                                 $missed_pages .= ' <li><a href="./index.php?cid='.$key.SEP.'g=36">'.$ref.'</a></li>';
93                 }
94         }
95 }else{
96         echo '<tr><td>'._AT('tracker_none_viewed').'</td></tr>';
97 }
98
99 if ($num_rows_read < 1) {
100         $num_rows_read = 0;
101 }
102
103 echo '<tr>';
104 echo '<td>'._AT('tracker_pages_total', $num_rows_total, $num_rows_read).'</td>';
105
106 $per_cent = 0;
107 if ($num_rows_total) {
108         $per_cent = number_format((($num_rows_read/$num_rows_total)*100),1);
109
110 }
111 echo '<td>' . _AT('tracker_percent_read',$per_cent) . '%</td>';
112 echo '</tr>';
113 echo '</tbody>';
114 echo '</table>';
115
116 echo '<a name="not_viewed"></a>';
117
118 echo '<br /><hr /><br /><h3>'._AT('unvisited_pages').'</h3>';
119 echo '<div class="results">';
120
121 // show which pages have not been viewed yet
122 if ($missed_pages) {
123         echo '<ul>';
124         echo $missed_pages;
125         echo '</ul>';
126 } else {
127         echo _AT('tracking_all_page_viewed');
128 }
129
130 echo '</div>';
131 ?>