More improved SQL queries
[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                         $content['sw']           = $SW;
65
66                         // Load row template
67                         $OUT .= LOAD_TEMPLATE("admin_surfbar_url_stats_row", true, $content);
68                         $cnt++; $SW = 3 - $SW;
69                 } // END - while
70
71                 // Prepare content
72                 $content = array(
73                         'rows'    => $OUT,
74                         'userids' => $cnt,
75                         'visits'  => $visits
76                 );
77
78
79                 // Load main template
80                 LOAD_TEMPLATE("admin_surfbar_url_stats", false, $content);
81         } else {
82                 // No statistics so far
83                 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_SURFBAR_NO_URL_STATS'));
84         }
85 } else {
86         // Generate general statistics
87         $result = SQL_QUERY("SELECT `userid`, COUNT(`url_id`) AS `visited_urls`, SUM(`count`) AS `total_visits`
88 FROM `{!_MYSQL_PREFIX!}_surfbar_stats`
89 GROUP BY `userid`
90 ORDER BY `userid` ASC", __FILE__, __LINE__);
91
92         // Entries found?
93         if (SQL_NUMROWS($result) > 0) {
94                 // Get all rows
95                 $OUT = ""; $SW = 2; $urls = 0; $visits = 0;
96                 while ($content = SQL_FETCHARRAY($result)) {
97                         // Count totals
98                         $urls   += $content['visited_urls'];
99                         $visits += $content['total_visits'];
100
101                         // "Translate" some data
102                         $content['userid']       = ADMIN_USER_PROFILE_LINK($content['userid']);
103                         $content['visited_urls'] = TRANSLATE_COMMA($content['visited_urls']);
104                         $content['total_visits'] = TRANSLATE_COMMA($content['total_visits']);
105                         $content['sw']           = $SW;
106
107                         // Load row template
108                         $OUT .= LOAD_TEMPLATE("admin_surfbar_stats_row", true, $content);
109                         $SW = 3 - $SW;
110                 } // END - while
111
112                 // Prepare content
113                 $content = array(
114                         'rows'   => $OUT,
115                         'urls'   => $urls,
116                         'visits' => $visits
117                 );
118
119
120                 // Load main template
121                 LOAD_TEMPLATE("admin_surfbar_stats", false, $content);
122         } else {
123                 // No statistics so far
124                 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_SURFBAR_NO_STATS'));
125         }
126 }
127
128 // Free result
129 SQL_FREERESULT($result);
130
131 //
132 ?>