- Surfbar further extended, currently broken!
[mailer.git] / inc / libs / rallye_functions.php
index ad8d6c5f15139b4ee33102c70a208d6ace4d4dcf..50881d58eb96dee6d1b3977279978ed8f190b9db 100644 (file)
  ************************************************************************/
 
 // Some security stuff...
-if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
-{
+if (!defined('__SECURITY')) {
        $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
        require($INC);
 }
+
 //
 function RALLYE_AUTOSTART_RALLYES($result)
 {
@@ -94,7 +94,7 @@ function RALLYE_AUTOSTART_RALLYES($result)
 
                // Get refs by userid
                $cnt = RALLYE_GET_REFCOUNT($uid);
-               if (empty($cnt)) $cnt = "0"; // Added prevent some unknown troubles... :-?
+               if (empty($cnt)) $cnt = 0; // Added prevent some unknown troubles... :-?
 
                // Check if line is already included...
                $result_ref = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_rallye_users WHERE rallye_id=%s AND userid=%s LIMIT 1",
@@ -194,7 +194,11 @@ function RALLYE_ADD_PRICES($rallye,$mode="email")
 function RALLYE_ADD_TOPUSERS($rallye,$default=0)
 {
        global $_CONFIG;
-       $since = (time() - $_CONFIG['ap_in_since']);
+       // Init variable
+       $since = 0;
+       if (EXT_IS_ACTIVE("autopurge")) {
+               $since = $_CONFIG['ap_inactive_since'];
+       } // END - if
 
        // First check how many prices are set
        $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_rallye_prices WHERE rallye_id=%s ORDER BY price_level",
@@ -225,12 +229,12 @@ WHERE u.rallye_id=%s AND r.counter > 0 ORDER BY u.refs DESC",
                $result_ref = SQL_QUERY_ESC("SELECT DISTINCT p.points FROM "._MYSQL_PREFIX."_user_points AS p
 LEFT JOIN "._MYSQL_PREFIX."_user_data AS d
 ON p.userid=d.userid
-WHERE d.userid=%s AND d.status='CONFIRMED' AND p.ref_depth=1 AND d.max_mails > 0 AND d.mails_confirmed >= %s AND d.last_online >= %s
+WHERE d.userid=%s AND d.status='CONFIRMED' AND p.ref_depth=1 AND d.max_mails > 0 AND d.mails_confirmed >= %s AND d.last_online >= (UNIX_TIMESTAMP() - %s)
 LIMIT 1", array(bigintval($uid), $_CONFIG['ref_payout'], $since), __FILE__, __LINE__);
                list($refpoints) = SQL_FETCHROW($result_ref);
                SQL_FREERESULT($result_ref);
 
-               if (empty($refpoints)) $refpoints = "0";
+               if (empty($refpoints)) $refpoints = 0;
 
                // And subtract start refs
                $cnt -= $refs;
@@ -316,7 +320,7 @@ VALUES ('%s', '%s', '0')",
                        $DATA['now_t'] = MAKE_DATETIME(time(), "2");
                        $DATA['title'] = $title;
                        $DATA['id']    = $id;  // ID for the rallye details link
-                       $DATA['ref']   = "0";
+                       $DATA['ref']   = 0;
 
                        // Load prices
                        $prices = RALLYE_ADD_PRICES($id);
@@ -333,7 +337,10 @@ function RALLYE_EXPIRE_RALLYES($result)
        global $DATA, $_CONFIG;
 
        // Latest online time
-       $since = (time() - $_CONFIG['ap_in_since']);
+       $since = 0;
+       if (EXT_IS_ACTIVE("autopurge")) {
+               $since = $_CONFIG['ap_inactive_since'];
+       } // END - if
 
        // Load rallye data
        list($id, $title, $start, $end, $notify, $min_users, $min_prices) = SQL_FETCHROW($result);
@@ -352,14 +359,14 @@ function RALLYE_EXPIRE_RALLYES($result)
 
        // Just count...
        $TOTAL = 0;
-       foreach($prices['uid'] as $key=>$uid)
+       foreach($prices['uid'] as $key => $uid)
        {
                // Check status
                //   active = 1: account is still confirmed
                //   active = 0: account is deleted or locked
                $result = SQL_QUERY_ESC("SELECT COUNT(userid) AS active
 FROM "._MYSQL_PREFIX."_user_data
-WHERE userid=%s AND status='CONFIRMED' AND last_online >= %s
+WHERE userid=%s AND status='CONFIRMED' AND last_online >= (UNIX_TIMESTAMP() - %s)
 LIMIT 1", array(bigintval($uid), $since), __FILE__, __LINE__);
                list($active) = SQL_FETCHROW($result);
                SQL_FREERESULT($result);
@@ -384,7 +391,7 @@ LIMIT 1", array(bigintval($uid), $since), __FILE__, __LINE__);
         array(bigintval($id)), __FILE__, __LINE__);
 
        // Run array through (by uid is the most important 2nd-level-array)
-       foreach($prices['uid'] as $key=>$uid)
+       foreach($prices['uid'] as $key => $uid)
        {
                // Allow valid and active users with at least one ref to get points
                if (($uid > 0) && ($prices['ref'][$key] > 0) && ($prices['active'][$key] == 1) && ($prices['cpoints'][$key] > 0))
@@ -481,12 +488,12 @@ function RALLYE_LOAD_USER_DATA($uids_array)
        $uid_string = implode(",", $uids_array['uid']);
 
        // Load users
-       $result = SQL_QUERY_ESC("SELECT userid, sex, surname, family, email FROM "._MYSQL_PREFIX."_user_data WHERE userid IN(%s) AND status='CONFIRMED' ORDER BY userid LIMIT %s",
+       $result = SQL_QUERY_ESC("SELECT userid, gender, surname, family, email FROM "._MYSQL_PREFIX."_user_data WHERE userid IN(%s) AND status='CONFIRMED' ORDER BY userid LIMIT %s",
         array($uid_string, count($uids_array)), __FILE__, __LINE__);
        $ret = "";
-       while (list($u, $sex, $surname, $family, $email) = SQL_FETCHROW($result))
+       while (list($u, $gender, $surname, $family, $email) = SQL_FETCHROW($result))
        {
-               $ret .= TRANSLATE_SEX($sex)." ".$surname." ".$family." (".$email.") - ".$uids_array['poi'][$u]."\n";
+               $ret .= TRANSLATE_GENDER($gender)." ".$surname." ".$family." (".$email.") - ".$uids_array['poi'][$u]."\n";
        }
 
        // Return result
@@ -551,7 +558,7 @@ WHERE d.status='CONFIRMED' AND d.max_mails > 0 AND d.mails_confirmed >= %s AND p
                list($refpoints) = SQL_FETCHROW($result_ref);
                SQL_FREERESULT($result_ref);
 
-               if (empty($refpoints)) $refpoints = "0";
+               if (empty($refpoints)) $refpoints = 0;
 
                // Store calculated new refs to array
                $users['uid'][]     = $uid;
@@ -569,7 +576,7 @@ WHERE d.status='CONFIRMED' AND d.max_mails > 0 AND d.mails_confirmed >= %s AND p
        $prices = RALLYE_LOAD_PRICES_ARRAY($rallye);
 
        // Merge users into prices
-       foreach ($prices['level'] as $k=>$lvl)
+       foreach ($prices['level'] as $k => $lvl)
        {
                $prices['uid'][$k]  = $users['uid'][$k];
                if (empty($prices['uid'][$k])) $prices['uid'][$k]  = "---";
@@ -657,9 +664,11 @@ function RALLYE_DELETE_EXPIRED_RALLYES()
 {
        global $DATA, $_CONFIG;
        // Check for expired rallyes
-       $EXPIRE = time() - ONE_DAY * 3; // The hard-coded value...
-       $result_rallye = SQL_QUERY_ESC("SELECT id, title, start_time, end_time FROM "._MYSQL_PREFIX."_rallye_data WHERE end_time <= %s AND expired='Y'",
-        array($EXPIRE), __FILE__, __LINE__);
+       $EXPIRE = $_CONFIG['one_day'] * 3; // @TODO The hard-coded value...
+       $result_rallye = SQL_QUERY_ESC("SELECT id, title, start_time, end_time
+FROM "._MYSQL_PREFIX."_rallye_data
+WHERE end_time <= (UNIX_TIMESTAMP() - %s) AND expired='Y'",
+               array($EXPIRE), __FILE__, __LINE__);
 
        if (SQL_NUMROWS($result_rallye) > 0)
        {
@@ -742,13 +751,13 @@ function RALLYE_TEMPLATE_SELECTION($name="template", $default="")
 //
 function RALLYE_GET_REFCOUNT($uid, $old=0)
 {
-       global $_CONFIG;
+       global $_CONFIG, $cacheArray;
        // Check current refs
        if (GET_EXT_VERSION("cache") >= "0.1.2")
        {
                // Get refs from cache
                $cnt = 0;
-               foreach ($cacheArray['ref_system']['userid'] as $id=>$u_id)
+               foreach ($cacheArray['ref_system']['userid'] as $id => $u_id)
                {
                        if (($u_id == $uid) && ($cacheArray['ref_system']['level'][$id] == 0))
                        {
@@ -798,7 +807,7 @@ WHERE s.userid=%s AND s.level=0", array(bigintval($uid)), __FILE__, __LINE__);
                SQL_FREERESULT($result_ref);
                if (empty($cnt))
                {
-                       $cnt = "0";
+                       $cnt = 0;
                }
                 else
                {