Fixes + asserts
[mailer.git] / inc / filter / online_filter.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 06/02/2011 *
4  * ===================                          Last change: 06/02/2011 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : _filter.php                                      *
8  * -------------------------------------------------------------------- *
9  * Short description : Filters for ext-                                 *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Filter fuer ext-                                 *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2013 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         die();
41 } // END - if
42
43 // Filter for updates/extends on the online list
44 function FILTER_UPDATE_ONLINE_LIST ($filterData) {
45         // Do not update online list when extension is deactivated
46         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
47         if (!isExtensionActive('online')) {
48                 // Extension not active
49                 /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Extension ext-online is not active.');
50                 return $filterData;
51         } // END - if
52
53         // Empty session?
54         if (!isValidSession()) {
55                 // This is invalid here!
56                 reportBug(__FUNCTION__, __LINE__, 'Invalid session.');
57         } // END - if
58
59         // Initialize variables
60         $userid   = NULL;
61         $isMember = convertBooleanToYesNo(isMember());
62         $isAdmin  = convertBooleanToYesNo(isAdmin());
63         $action   = getActionFromModuleWhat(getModule(), getWhat(FALSE));
64
65         // Valid userid?
66         if (isMember()) {
67                 // Is valid user, so get the userid
68                 $userid = getMemberId();
69         } // END - if
70
71         // Now search for the user
72         $result = sqlQueryEscaped("SELECT `timestamp` FROM `{?_MYSQL_PREFIX?}_online` WHERE `sid`='%s' LIMIT 1",
73                 array(session_id()), __FUNCTION__, __LINE__);
74
75         // Entry found?
76         if (sqlNumRows($result) == 1) {
77                 // Then update it
78                 sqlQueryEscaped("UPDATE
79         `{?_MYSQL_PREFIX?}_online`
80 SET
81         `module`='%s',
82         `action`='%s',
83         `what`='%s',
84         `userid`=%s,
85         `refid`=%s,
86         `is_member`='%s',
87         `is_admin`='%s',
88         `timestamp`=UNIX_TIMESTAMP(),
89         `ip`='%s'
90 WHERE
91         `sid`='%s'
92 LIMIT 1",
93                 array(
94                         getModule(),
95                         $action,
96                         getWhat(FALSE),
97                         convertZeroToNull($userid),
98                         convertZeroToNull(determineReferralId()),
99                         $isMember,
100                         $isAdmin,
101                         detectRemoteAddr(),
102                         session_id()
103                 ), __FUNCTION__, __LINE__);
104         } else {
105                 // No entry does exists so we simply add it!
106                 sqlQueryEscaped("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')",
107                         array(
108                                 getModule(),
109                                 $action,
110                                 getWhat(FALSE),
111                                 convertZeroToNull($userid),
112                                 convertZeroToNull(determineReferralId()),
113                                 $isMember,
114                                 $isAdmin,
115                                 session_id(),
116                                 detectRemoteAddr()
117                         ), __FUNCTION__, __LINE__);
118         }
119
120         // Free result
121         sqlFreeResult($result);
122
123         // Purge old entries
124         sqlQuery('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_online` WHERE (UNIX_TIMESTAMP() - `timestamp`) >= {?online_timeout?}', __FUNCTION__, __LINE__);
125
126         // Return data
127         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
128         return $filterData;
129 }
130
131 // [EOF]
132 ?>