96400dc2b1cfa6fe47533a29d061fa94a9d4d571
[mailer.git] / inc / libs / online_functions.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 12/18/2008 *
4  * ================                             Last change: 12/18/2008 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : online_functions.php                             *
8  * -------------------------------------------------------------------- *
9  * Short description : Online functions                                 *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Online-Funktionen                                *
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')) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 }
39
40 // Filter for updates/extends on the online list
41 function FILTER_UPDATE_ONLINE_LIST () {
42         // Do not update online list when extension is deactivated
43         if (!EXT_IS_ACTIVE("online", true)) return;
44
45         // Empty session?
46         if (session_id() == "") {
47                 // This is invalid here!
48                 debug_report_bug("Invalid session.");
49         } // END - if
50
51         // Initialize variables
52         $uid = 0; $rid = 0; $MEM = "N"; $ADMIN = "N";
53
54         // Valid userid?
55         if ((!empty($GLOBALS['userid'])) && ($GLOBALS['userid'] > 0) && (IS_MEMBER())) {
56                 // Is valid user
57                 $uid = bigintval($GLOBALS['userid']);
58                 $MEM = "Y";
59         } // END - if
60
61         if (IS_ADMIN()) {
62                 // Is administrator
63                 $ADMIN = "Y";
64         } // END - if
65
66         if (!empty($GLOBALS['refid'])) {
67                 // Read cookie
68                 $rid = bigintval($GLOBALS['refid']);
69         } // END - if
70
71         // Now search for the user
72         $result = SQL_QUERY_ESC("SELECT timestamp FROM `{!_MYSQL_PREFIX!}_online` WHERE sid='%s' LIMIT 1",
73                 array(session_id()), __FILE__, __LINE__);
74
75         // Entry found?
76         if (SQL_NUMROWS($result) == 1) {
77                 // Then update it
78                 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_online` SET
79 module='%s',
80 action='%s',
81 what='%s',
82 userid=%s,
83 refid=%s,
84 is_member='%s',
85 is_admin='%s',
86 timestamp=UNIX_TIMESTAMP(),
87 ip='%s'
88 WHERE sid='%s' LIMIT 1",
89                         array(
90                                 $GLOBALS['module'],
91                                 $GLOBALS['action'],
92                                 $GLOBALS['what'],
93                                 $uid,
94                                 $rid,
95                                 $MEM,
96                                 $ADMIN,
97                                 GET_REMOTE_ADDR(),
98                                 session_id()
99                         ), __FILE__, __LINE__
100                 );
101         } else {
102                 // No entry does exists so we simply add it!
103                 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_online` (module, action, what, userid, refid, is_member, is_admin, timestamp, sid, ip) VALUES ('%s','%s','%s', %s, %s, '%s','%s', UNIX_TIMESTAMP(), '%s','%s')",
104                         array(
105                                 $GLOBALS['module'],
106                                 $GLOBALS['action'],
107                                 $GLOBALS['what'],
108                                 $uid,
109                                 $rid,
110                                 $MEM,
111                                 $ADMIN,
112                                 session_id(),
113                                 GET_REMOTE_ADDR()
114                         ), __FILE__, __LINE__
115                 );
116         }
117
118         // Free result
119         SQL_FREERESULT($result);
120
121         // Purge old entries
122         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_online` WHERE timestamp <= (UNIX_TIMESTAMP() - %s)",
123                 array(getConfig('online_timeout')), __FILE__, __LINE__);
124 }
125
126 //
127 ?>