root/trunk/wifidog-auth/wifidog/classes/StatisticReport/UserReport.php @ 1013

Revision 1013, 14.5 KB (checked in by benoitg, 7 years ago)

* dump_initial_data_postgres.sh: Add the
content_available_display_pages table to the dump, can someone
re-generate the initial data from a working install
* Remove the ?> tags from all the classes.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2
3/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5// +-------------------------------------------------------------------+
6// | WiFiDog Authentication Server                                     |
7// | =============================                                     |
8// |                                                                   |
9// | The WiFiDog Authentication Server is part of the WiFiDog captive  |
10// | portal suite.                                                     |
11// +-------------------------------------------------------------------+
12// | PHP version 5 required.                                           |
13// +-------------------------------------------------------------------+
14// | Homepage:     http://www.wifidog.org/                             |
15// | Source Forge: http://sourceforge.net/projects/wifidog/            |
16// +-------------------------------------------------------------------+
17// | This program is free software; you can redistribute it and/or     |
18// | modify it under the terms of the GNU General Public License as    |
19// | published by the Free Software Foundation; either version 2 of    |
20// | the License, or (at your option) any later version.               |
21// |                                                                   |
22// | This program is distributed in the hope that it will be useful,   |
23// | but WITHOUT ANY WARRANTY; without even the implied warranty of    |
24// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     |
25// | GNU General Public License for more details.                      |
26// |                                                                   |
27// | You should have received a copy of the GNU General Public License |
28// | along with this program; if not, contact:                         |
29// |                                                                   |
30// | Free Software Foundation           Voice:  +1-617-542-5942        |
31// | 59 Temple Place - Suite 330        Fax:    +1-617-542-2652        |
32// | Boston, MA  02111-1307,  USA       gnu@gnu.org                    |
33// |                                                                   |
34// +-------------------------------------------------------------------+
35
36/**
37 * @package    WiFiDogAuthServer
38 * @subpackage Statistics
39 * @author     Philippe April
40 * @copyright  2005-2006 Philippe April
41 * @version    Subversion $Id$
42 * @link       http://www.wifidog.org/
43 */
44
45/**
46 * Load required classes
47 */
48require_once('classes/StatisticReport.php');
49
50/**
51 * General report about a user
52 *
53 * @package    WiFiDogAuthServer
54 * @subpackage Statistics
55 * @author     Philippe April
56 * @copyright  2005-2006 Philippe April
57 */
58class UserReport extends StatisticReport
59{
60    /** Get the report's name.  Must be overriden by the report class
61     * @return a localised string */
62    public static function getReportName()
63    {
64        return _("Individual user report");
65    }
66
67    /** Constructor
68         * @param $statistics_object Mandatory to give the report it's context */
69    protected function __construct(Statistics $statistics_object)
70    {
71        parent :: __construct($statistics_object);
72    }
73
74    /** Get the actual report.
75     * Classes must override this, but must call the parent's method with what
76     * would otherwise be their return value and return that instead.
77     * @param $child_html The child method's return value
78     * @return A html fragment
79     */
80    public function getReportUI($child_html = null)
81    {
82        // Define globals
83        global $db;
84        global $account_status_to_text;
85        global $token_to_text;
86
87        // Init values
88        $html = "";
89        $_date_from = "";
90        $_date_to = "";
91
92        // Process input
93        if (isset($_REQUEST['date_from'])) {
94            $_date_from = $_REQUEST['date_from'];
95        }
96
97        if (isset($_REQUEST['date_to'])) {
98            $_date_to = $_REQUEST['date_to'];
99        }
100
101        $selected_users = $this->stats->getSelectedUsers();
102        if ($selected_users) {
103            foreach ($selected_users as $user_id => $userObject) {
104                if ($userObject) {
105                    $userinfo = null;
106                    $user_id = $db->escapeString($user_id);
107                    $sql = "SELECT * FROM users WHERE user_id='{$user_id}'";
108                    $db->execSqlUniqueRes($sql, $userinfo, false);
109
110                    if ($userinfo == null) {
111                        throw new Exception(sprintf(_("User id: %s could not be found in the database"), $user_id));
112                    }
113
114                    $userinfo['account_status_description'] = $account_status_to_text[$userinfo['account_status']];
115
116                    $html .= "<fieldset class='pretty_fieldset'>\n";
117                    $html .= "<legend>"._("Profile")."</legend>\n";
118
119                    $html .= "<table>\n";
120
121                    $html .= "<tr class='odd'>\n";
122                    $html .= "  <th>"._("Username").":</th>\n";
123                    $html .= "  <td>".$userinfo['username']."</td>\n";
124                    $html .= "</tr>\n";
125
126                    $html .= "<tr>\n";
127                    $html .= "  <th>"._("Real Name").":</th>\n";
128                    $html .= "  <td>".$userinfo['real_name']."</td>\n";
129                    $html .= "</tr>\n";
130
131                    $html .= "<tr class='odd'>\n";
132                    $html .= "  <th>"._("Email").":</th>\n";
133                    $html .= "  <td>".$userinfo['email']."</td>\n";
134                    $html .= "</tr>\n";
135
136                    $html .= "<tr>\n";
137                    $html .= "  <th>"._("Network").":</th>\n";
138                    $html .= "  <td><a href='?date_from={$_date_from}&date_to={$_date_to}&network_id={$userinfo['account_origin']}'>{$userinfo['account_origin']}</a></td>\n";
139                    $html .= "</tr>\n";
140
141                    $html .= "<tr class='odd'>\n";
142                    $html .= "  <th>"._("Unique ID").":</th>\n";
143                    $html .= "  <td>".$userinfo['user_id']."</td>\n";
144                    $html .= "</tr>\n";
145
146                    $html .= "<tr>\n";
147                    $html .= "  <th>"._("Member since").":</th>\n";
148                    $html .= "  <td>".strftime("%c", strtotime($userinfo['reg_date']))."</td>\n";
149                    $html .= "</tr>\n";
150
151                    $html .= "<tr class='odd'>\n";
152                    $html .= "  <th>"._("Account Status").":</th>\n";
153                    $html .= "  <td>".$userinfo['account_status_description']."</td>\n";
154                    $html .= "</tr>\n";
155
156                    $html .= "<tr>\n";
157                    $html .= "  <th>"._("Website").":</th>\n";
158                    $html .= "  <td>".$userinfo['website']."</td>\n";
159                    $html .= "</tr>\n";
160
161                    $html .= "<tr class='odd'>\n";
162                    $html .= "  <th>"._("Prefered Locale").":</th>\n";
163                    $html .= "  <td>".$userinfo['prefered_locale']."</td>\n";
164                    $html .= "</tr>\n";
165
166                    $html .= "</table>\n";
167                    $html .= "</fieldset>\n";
168                }
169
170                /******* Connections **********/
171                $html .= "<fieldset class='pretty_fieldset'>\n";
172                $candidate_connections_sql = $this->stats->getSqlCandidateConnectionsQuery("*");
173                $sql = "$candidate_connections_sql ORDER BY timestamp_in DESC";
174                $db->execSql($sql, $connections, false);
175                $html .= "<legend>".sprintf(_("%d Connections"), count($connections))."</legend>\n";
176
177                // Variables init
178                $even = 0;
179                $total = array ();
180                $total['incoming'] = 0;
181                $total['outgoing'] = 0;
182                $total['time_spent'] = 0;
183                if (count($connections) == 0) {
184                    $html .= _("No information found matching the report configuration");
185                } else {
186                    $html .= "<table class='smaller'>\n";
187                    $html .= "<thead>\n";
188                    $html .= "<tr>\n";
189                    $html .= "  <th>"._("Logged in")."</th>\n";
190                    $html .= "  <th>"._("Time spent")."</th>\n";
191                    $html .= "  <th>"._("Token status")."</th>\n";
192                    $html .= "  <th>"._("Node")."</th>\n";
193                    $html .= "  <th>"._("IP")."</th>\n";
194                    $html .= "  <th>"._("D")."</th>\n";
195                    $html .= "  <th>"._("U")."</th>\n";
196                    $html .= "</tr>\n";
197                    $html .= "</thead>\n";
198
199                    foreach ($connections as $connection) {
200                        $timestamp_in = !empty ($connection['timestamp_in']) ? strtotime($connection['timestamp_in']) : null;
201                        $timestamp_out = !empty ($connection['timestamp_out']) ? strtotime($connection['timestamp_out']) : null;
202
203                        $nodeObject = Node :: getObject($connection['node_id']);
204                        $total['incoming'] += $connection['incoming'];
205                        $total['outgoing'] += $connection['outgoing'];
206
207                        $connection['token_status_description'] = $token_to_text[$connection['token_status']];
208                        $html .= $even ? "<tr>\n" : "<tr class='odd'>\n";
209
210                        if ($even == 0) {
211                            $even = 1;
212                        } else {
213                            $even = 0;
214                        }
215
216                        $html .= "  <td>".strftime("%c", $timestamp_in)."</td>\n";
217
218                        if (!empty ($timestamp_in) && !empty ($timestamp_out)) {
219                            $total['time_spent'] += ($timestamp_out - $timestamp_in);
220                            $html .= "<td>".Utils :: convertSecondsToWords($timestamp_out - $timestamp_in)."</td>\n";
221                        } else {
222                            $html .= "<td>"._("N/A")."</td>\n";
223                        }
224
225                        $html .= "  <td>".$connection['token_status']."</td>\n";
226                        $html .= "  <td><a href='?date_from={$_REQUEST['date_from']}&date_to={$_REQUEST['date_to']}&node_id={$nodeObject->getId()}'>{$nodeObject->getName()}</a></td>\n";
227                        $html .= "  <td>".$connection['user_ip']."</td>\n";
228                        $html .= "  <td>".Utils :: convertBytesToWords($connection['incoming'])."</td>\n";
229                        $html .= "  <td>".Utils :: convertBytesToWords($connection['outgoing'])."</td>\n";
230                        $html .= "</tr>\n";
231                    }
232                    $html .= "<tr>\n";
233                    $html .= "  <th>"._("Total").":</th>\n";
234                    $html .= "  <th>".Utils :: convertSecondsToWords($total['time_spent'])."</th>\n";
235                    $html .= "  <td></td>\n";
236                    $html .= "  <td></td>\n";
237                    $html .= "  <td></td>\n";
238
239                    $html .= "  <th>".Utils :: convertBytesToWords($total['incoming'])."</th>\n";
240                    $html .= "  <th>".Utils :: convertBytesToWords($total['outgoing'])."</th>\n";
241                    $html .= "</tr>\n";
242                    $html .= "</table>\n";
243                    $html .= "</fieldset>\n";
244                }
245
246                if ($this->stats->getDistinguishUsersBy() == 'user_id') {
247                    /******* MAC addresses **********/
248                    $candidate_connections_sql = $this->stats->getSqlCandidateConnectionsQuery("user_mac,count(user_mac) as nb ");
249
250                    $sql = "$candidate_connections_sql group by user_mac order by nb desc";
251                    $db->execSql($sql, $rows, false);
252
253                    $html .= "<fieldset class='pretty_fieldset'>\n";
254                    $html .= "<legend>".sprintf(_("%d MAC addresses"), count($rows))."</legend>\n";
255                    $html .= "<table>\n";
256                    $html .= "<thead>\n";
257                    $html .= "<tr>\n";
258                    $html .= "  <th>"._("MAC")."</th>\n";
259                    $html .= "  <th>"._("Count")."</th>\n";
260                    $html .= "</tr>\n";
261                    $html .= "</thead>\n";
262
263                    $even = 0;
264                    if ($rows) {
265                        foreach ($rows as $row) {
266                            $html .= $even ? "<tr>\n" : "<tr class='odd'>\n";
267
268                            if ($even == 0) {
269                                $even = 1;
270                            } else {
271                                $even = 0;
272                            }
273
274                            $html .= "  <td>{$row['user_mac']}</td>\n";
275                            $html .= "  <td>".$row['nb']."</td>\n";
276                            $html .= "</tr>\n";
277                        }
278                    }
279
280                    $html .= "</table>\n";
281                    $html .= "</fieldset>\n";
282                } else {
283                    /******* Usernames **********/
284                    $candidate_connections_sql = $this->stats->getSqlCandidateConnectionsQuery("connections.user_id,username, count(connections.user_id) as nb ", true);
285
286                    $sql = "$candidate_connections_sql group by connections.user_id, username order by nb desc, connections.user_id,username";
287                    $db->execSql($sql, $rows, false);
288
289                    $html .= "<fieldset class='pretty_fieldset'>\n";
290                    $html .= "<legend>".sprintf(_("%d users"), count($rows))."</legend>\n";
291                    $html .= "<table>\n";
292                    $html .= "<thead>\n";
293                    $html .= "<tr>\n";
294                    $html .= "  <th>"._("Username")."</th>\n";
295                    $html .= "  <th>"._("Count")."</th>\n";
296                    $html .= "</tr>\n";
297                    $html .= "</thead>\n";
298
299                    $even = 0;
300
301                    if ($rows) {
302                        foreach ($rows as $row) {
303                            $html .= $even ? "<tr>\n" : "<tr class='odd'>\n";
304
305                            if ($even == 0) {
306                                $even = 1;
307                            } else {
308                                $even = 0;
309                            }
310
311                            $html .= "  <td>{$row['username']}</td>\n";
312                            $html .= "  <td>".$row['nb']."</td>\n";
313                            $html .= "</tr>\n";
314                        }
315                    }
316
317                    $html .= "</table>\n";
318                    $html .= "</fieldset>\n";
319                }
320            }
321        }
322
323        return parent :: getReportUI($html);
324    }
325
326}
327
328/*
329 * Local variables:
330 * tab-width: 4
331 * c-basic-offset: 4
332 * c-hanging-comment-ender-p: nil
333 * End:
334 */
335
Note: See TracBrowser for help on using the browser.