Code cleanup, more usage of API functions
[mailer.git] / inc / libs / online_functions.php
index 7d1eb61339e95b7faec89c03b4371c98c7a259c4..a989e1f2a29be41dd08731557fc402900e5a277d 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 12/18/2008 *
- * ================                             Last change: 12/18/2008 *
+ * Mailer v0.2.1-FINAL                                Start: 12/18/2008 *
+ * ===================                          Last change: 12/18/2008 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : online_functions.php                             *
  * $Date::                                                            $ *
  * $Tag:: 0.2.1-FINAL                                                 $ *
  * $Author::                                                          $ *
- * Needs to be in all Files and every File needs "svn propset           *
- * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
  * -------------------------------------------------------------------- *
- * Copyright (c) 2003 - 2008 by Roland Haeder                           *
+ * Copyright (c) 2003 - 2009 by Roland Haeder                           *
+ * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
  * For more information visit: http://www.mxchange.org                  *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
 
 // Some security stuff...
 if (!defined('__SECURITY')) {
-       $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
-       require($INC);
-}
+       die();
+} // END - if
 
 // Filter for updates/extends on the online list
 function FILTER_UPDATE_ONLINE_LIST () {
        // Do not update online list when extension is deactivated
-       if (!EXT_IS_ACTIVE('online', true)) return;
+       if (!isExtensionActive('online', true)) return;
 
        // Empty session?
        if (session_id() == '') {
                // This is invalid here!
-               debug_report_bug("Invalid session.");
+               debug_report_bug(__FUNCTION__, __LINE__, 'Invalid session.');
        } // END - if
 
        // Initialize variables
-       $uid = 0; $rid = 0; $MEM = 'N'; $ADMIN = 'N';
+       $userid = '0';
+       $isMember = 'N';
+       $isAdmin = 'N';
+       $action = getActionFromModuleWhat(getModule(), getWhat());
 
        // Valid userid?
-       if ((isUserIdSet()) && (getUserId() > 0) && (IS_MEMBER())) {
+       if (isMember()) {
                // Is valid user
-               $uid = getUserId();
-               $MEM = 'Y';
+               $userid = getMemberId();
+               $isMember = 'Y';
        } // END - if
 
-       if (IS_ADMIN()) {
+       if (isAdmin()) {
                // Is administrator
-               $ADMIN = 'Y';
-       } // END - if
-
-       if (!empty($GLOBALS['refid'])) {
-               // Read cookie
-               $rid = bigintval($GLOBALS['refid']);
+               $isAdmin = 'Y';
        } // END - if
 
        // Now search for the user
-       $result = SQL_QUERY_ESC("SELECT timestamp FROM `{!_MYSQL_PREFIX!}_online` WHERE sid='%s' LIMIT 1",
-       array(session_id()), __FUNCTION__, __LINE__);
+       $result = SQL_QUERY_ESC("SELECT `timestamp` FROM `{?_MYSQL_PREFIX?}_online` WHERE `sid`='%s' LIMIT 1",
+               array(session_id()), __FUNCTION__, __LINE__);
 
        // Entry found?
        if (SQL_NUMROWS($result) == 1) {
                // Then update it
-               SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_online` SET
-`module`='%s',
-`action`='%s',
-`what`='%s',
-userid=%s,
-refid=%s,
-is_member='%s',
-is_admin='%s',
-timestamp=UNIX_TIMESTAMP(),
-ip='%s'
-WHERE sid='%s' LIMIT 1",
+               SQL_QUERY_ESC("UPDATE
+       `{?_MYSQL_PREFIX?}_online`
+SET
+       `module`='%s',
+       `action`='%s',
+       `what`='%s',
+       `userid`=%s,
+       `refid`=%s,
+       `is_member`='%s',
+       `is_admin`='%s',
+       `timestamp`=UNIX_TIMESTAMP(),
+       `ip`='%s'
+WHERE 
+       `sid`='%s'
+LIMIT 1",
                array(
-               $GLOBALS['module'],
-               $GLOBALS['action'],
-               $GLOBALS['what'],
-               $uid,
-               $rid,
-               $MEM,
-               $ADMIN,
-               detectRemoteAddr(),
-               session_id()
-               ), __FUNCTION__, __LINE__
-               );
+                       getModule(),
+                       $action,
+                       getWhat(),
+                       makeDatabaseUserId($userid),
+                       makeDatabaseUserId(determineReferalId()),
+                       $isMember,
+                       $isAdmin,
+                       detectRemoteAddr(),
+                       session_id()
+               ), __FUNCTION__, __LINE__);
        } else {
                // No entry does exists so we simply add it!
-               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')",
-               array(
-               $GLOBALS['module'],
-               $GLOBALS['action'],
-               $GLOBALS['what'],
-               $uid,
-               $rid,
-               $MEM,
-               $ADMIN,
-               session_id(),
-               detectRemoteAddr()
-               ), __FUNCTION__, __LINE__
-               );
+               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')",
+                       array(
+                               getModule(),
+                               $action,
+                               getWhat(),
+                               makeDatabaseUserId($userid),
+                               makeDatabaseUserId(determineReferalId()),
+                               $isMember,
+                               $isAdmin,
+                               session_id(),
+                               detectRemoteAddr()
+                       ), __FUNCTION__, __LINE__);
        }
 
        // Free result
        SQL_FREERESULT($result);
 
        // Purge old entries
-       SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_online` WHERE timestamp <= (UNIX_TIMESTAMP() - %s)",
-       array(getConfig('online_timeout')), __FUNCTION__, __LINE__);
+       SQL_QUERY('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_online` WHERE `timestamp` <= (UNIX_TIMESTAMP() - {?online_timeout?})', __FUNCTION__, __LINE__);
 }
 
-//
+// [EOF]
 ?>