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