Admin surfbar stats finished
[mailer.git] / inc / modules / admin / what-surfbar_stats.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 09/09/2008 *
4  * ================                             Last change: 09/09/2008 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-surfbar_stats.php                           *
8  * -------------------------------------------------------------------- *
9  * Short description : Surfbar URL statistics                           *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : URL-Statistiken fuer die Surfbar                 *
12  * -------------------------------------------------------------------- *
13  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 }
39
40 // Add description as navigation point
41 ADD_DESCR("admin", __FILE__);
42
43 // Is the 'url_id' set?
44 if (isset($_GET['url_id'])) {
45         // Generate general statistics
46         $result = SQL_QUERY_ESC("SELECT `userid`, `count` AS `total_visits`, UNIX_TIMESTAMP(`last_online`) AS `last_online`
47 FROM `"._MYSQL_PREFIX."_surfbar_stats`
48 WHERE `url_id`=%s
49 ORDER BY `userid` ASC",
50                 array(bigintval($_GET['url_id'])), __FILE__, __LINE__);
51
52         // Entries found?
53         if (SQL_NUMROWS($result) > 0) {
54                 // Get all rows
55                 $OUT = ""; $SW = 2; $cnt = 0; $visits = 0;
56                 while ($content = SQL_FETCHARRAY($result)) {
57                         // Count totals
58                         $visits += $content['total_visits'];
59
60                         // "Translate" some data
61                         $content['userid']       = ADMIN_USER_PROFILE_LINK($content['userid']);
62                         $content['total_visits'] = TRANSLATE_COMMA($content['total_visits']);
63                         $content['last_online']  = MAKE_DATETIME($content['last_online'], "2");
64
65                         // Load row template
66                         $OUT .= LOAD_TEMPLATE("admin_surfbar_url_stats_row", true, $content);
67                         $cnt++;
68                 } // END - while
69
70                 // Prepare content
71                 $content = array(
72                         'rows'    => $OUT,
73                         'userids' => $cnt,
74                         'visits'  => $visits
75                 );
76
77
78                 // Load main template
79                 LOAD_TEMPLATE("admin_surfbar_url_stats", false, $content);
80         } else {
81                 // No statistics so far
82                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_SURFBAR_NO_URL_STATS);
83         }
84 } else {
85         // Generate general statistics
86         $result = SQL_QUERY("SELECT `userid`, COUNT(`url_id`) AS `visited_urls`, SUM(`count`) AS `total_visits`
87 FROM `"._MYSQL_PREFIX."_surfbar_stats`
88 GROUP BY `userid`
89 ORDER BY `userid` ASC", __FILE__, __LINE__);
90
91         // Entries found?
92         if (SQL_NUMROWS($result) > 0) {
93                 // Get all rows
94                 $OUT = ""; $SW = 2; $urls = 0; $visits = 0;
95                 while ($content = SQL_FETCHARRAY($result)) {
96                         // Count totals
97                         $urls   += $content['visited_urls'];
98                         $visits += $content['total_visits'];
99
100                         // "Translate" some data
101                         $content['userid']       = ADMIN_USER_PROFILE_LINK($content['userid']);
102                         $content['visited_urls'] = TRANSLATE_COMMA($content['visited_urls']);
103                         $content['total_visits'] = TRANSLATE_COMMA($content['total_visits']);
104
105                         // Load row template
106                         $OUT .= LOAD_TEMPLATE("admin_surfbar_stats_row", true, $content);
107                 } // END - while
108
109                 // Prepare content
110                 $content = array(
111                         'rows'   => $OUT,
112                         'urls'   => $urls,
113                         'visits' => $visits
114                 );
115
116
117                 // Load main template
118                 LOAD_TEMPLATE("admin_surfbar_stats", false, $content);
119         } else {
120                 // No statistics so far
121                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_SURFBAR_NO_STATS);
122         }
123 }
124
125 // Free result
126 SQL_FREERESULT($result);
127
128 //
129 ?>