X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Flibs%2Frallye_functions.php;h=d156ee865bee77833e16ed2f135db978e51f1b27;hb=d52156d35605388b7554c31d08bc29f0bb167079;hp=69dc4de3b288695f2e0a66bfd9bb99475a801c42;hpb=fbd528919a0e2762d423c5bcbc0289436e07a1d4;p=mailer.git
diff --git a/inc/libs/rallye_functions.php b/inc/libs/rallye_functions.php
index 69dc4de3b2..d156ee865b 100644
--- a/inc/libs/rallye_functions.php
+++ b/inc/libs/rallye_functions.php
@@ -32,28 +32,28 @@
************************************************************************/
// 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)
{
// Global data array for LOAD_EMAIL_TEMPLATE()
$DATA = array();
- global $DATA, $_CONFIG;
+ global $DATA;
// Load all rallyes (usally we have only one rallye active per time!
list($id, $title, $start, $end, $notify, $min_users, $min_prices) = SQL_FETCHROW($result);
SQL_FREERESULT($result);
// Set notified to Y
- $result_notified = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_rallye_data SET notified='Y' WHERE id=%d LIMIT 1",
- array(bigintval($id)), __FILE__, __LINE__);
+ SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_rallye_data` SET notified='Y' WHERE id=%s LIMIT 1",
+ array(bigintval($id)), __FILE__, __LINE__);
// Do a snapshot off all user refs
- $result_user = SQL_QUERY("SELECT userid FROM "._MYSQL_PREFIX."_user_data WHERE status='CONFIRMED' ORDER BY userid", __FILE__, __LINE__);
+ $result_user = SQL_QUERY("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `status`='CONFIRMED' ORDER BY userid", __FILE__, __LINE__);
// Transfer all neccessary data to the global $DATA array
$DATA['uid_cnt'] = SQL_NUMROWS($result_user);
@@ -63,23 +63,18 @@ function RALLYE_AUTOSTART_RALLYES($result)
$DATA['title'] = $title;
$DATA['id'] = $id; // ID for the rallye details link
- if ($min_users == 0)
- {
+ if ($min_users == 0) {
// Rallye ends without user limitation
$DATA['min_users'] = RALLYE_END_NO_USER_LIMITATION;
- }
- else
- {
+ } else {
// Rallye ends when X members are totally in your exchange
$DATA['min_users'] = RALLYE_END_USERS_1." ".$min_users." ".RALLYE_END_USERS_2;
}
- if ($min_prices == 0)
- {
+
+ if ($min_prices == 0) {
// Rallye ends without user limitation
$DATA['min_prices'] = RALLYE_END_NO_PRICE_LIMITATION;
- }
- else
- {
+ } else {
// Rallye ends when X members are totally in your exchange
$DATA['min_prices'] = RALLYE_END_PRICES_1." ".$min_prices." ".RALLYE_END_PRICES_2;
}
@@ -88,67 +83,56 @@ function RALLYE_AUTOSTART_RALLYES($result)
$prices = RALLYE_ADD_PRICES($id);
// Let's begin with the userids...
- while (list($uid) = SQL_FETCHROW($result_user))
- {
+ while (list($uid) = SQL_FETCHROW($result_user)) {
$un = false;
// 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=%d AND userid=%d LIMIT 1",
- array(bigintval($id), bigintval($uid)), __FILE__, __LINE__);
- if (SQL_NUMROWS($result_ref) == 0)
- {
+ $result_ref = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_rallye_users` WHERE rallye_id=%s AND userid=%s LIMIT 1",
+ array(bigintval($id), bigintval($uid)), __FILE__, __LINE__);
+ if (SQL_NUMROWS($result_ref) == 0) {
// Free memory
SQL_FREERESULT($result_ref);
// Add userid and his ref count to table
$result_ref = SQL_QUERY_ESC("SELECT DISTINCT SUM(p.points)
-FROM "._MYSQL_PREFIX."_user_points AS p
-LEFT JOIN "._MYSQL_PREFIX."_user_data AS d
+FROM `{!_MYSQL_PREFIX!}_user_points` AS p
+LEFT JOIN `{!_MYSQL_PREFIX!}_user_data` AS d
ON p.userid=d.userid
-WHERE d.status='CONFIRMED' AND d.max_mails > 0 AND d.mails_confirmed >= %s AND p.ref_depth=1 AND p.points > 0 AND d.userid=%d",
- array($_CONFIG['ref_payout'], bigintval($uid)), __FILE__, __LINE__);
+WHERE d.`status`='CONFIRMED' AND d.max_mails > 0 AND d.mails_confirmed >= %s AND p.ref_depth=1 AND p.points > 0 AND d.userid=%s",
+ array(getConfig('ref_payout'), bigintval($uid)), __FILE__, __LINE__);
list($cpoints) = SQL_FETCHROW($result_ref);
SQL_FREERESULT($result_ref);
if (empty($cpoints)) $cpoints = "0.00000";
// Add info line
- $result_ref = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_rallye_users (rallye_id, userid, refs, curr_points)
-VALUES ('%s', '%s', '%s', '%s')",
- array(bigintval($id), bigintval($uid), bigintval($cnt), $cpoints), __FILE__, __LINE__);
+ SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_rallye_users` (rallye_id, userid, refs, curr_points)
+VALUES ('%s','%s','%s','%s')",
+ array(bigintval($id), bigintval($uid), bigintval($cnt), $cpoints), __FILE__, __LINE__);
$un = true;
- }
+ } // END - if
// Ignored but for the template required refs (made before start of rallye)
$DATA['refs'] = $cnt;
// Shall I notify this member?
- if (($notify == "Y") && ($un))
- {
+ if (($notify == "Y") && ($un)) {
// Load email template and send it to the user
- $msg = LOAD_EMAIL_TEMPLATE("member_rallye_notify", $prices, $uid);
+ $msg = LOAD_EMAIL_TEMPLATE("member_rallye_notify", array('prices' => $prices), $uid);
SEND_EMAIL($uid, RALLYE_MEMBER_NOTIFY.$title, $msg);
- }
- }
+ } // END - if
+ } // END - while
- // Send email to admin
+ // Choose the right admin template
$templ = "admin_rallye_no_notify";
if ($notify == "Y") $templ = "admin_rallye_notify";
- if (GET_EXT_VERSION("admins") < "0.4.1")
- {
- // Use old method to send out
- $msg = LOAD_EMAIL_TEMPLATE($templ, $prices, 0);
- SEND_ADMIN_EMAILS(RALLYE_ADMIN_NOTIFY.$title, $msg);
- }
- else
- {
- // Use new system to send out
- SEND_ADMIN_EMAILS_PRO(RALLYE_ADMIN_NOTIFY.$title, $templ, $prices, "0");
- }
+
+ // Send email to admin
+ SEND_ADMIN_NOTIFICATION(RALLYE_ADMIN_NOTIFY.$title, $templ, $prices, "0");
// Free memory
SQL_FREERESULT($result_user);
@@ -157,14 +141,13 @@ VALUES ('%s', '%s', '%s', '%s')",
function RALLYE_ADD_PRICES($rallye,$mode="email")
{
// Output mode
- switch($mode)
- {
+ switch($mode) {
case "email": $mode = "\n"; break;
case "html" : $mode = " \n"; break;
}
// Load prices
- $result_prices = SQL_QUERY("SELECT price_level, points, info FROM "._MYSQL_PREFIX."_rallye_prices WHERE rallye_id='".$rallye."' ORDER BY price_level", __FILE__, __LINE__);
+ $result_prices = SQL_QUERY("SELECT price_level, points, info FROM `{!_MYSQL_PREFIX!}_rallye_prices` WHERE rallye_id='".$rallye."' ORDER BY price_level", __FILE__, __LINE__);
if (SQL_NUMROWS($result_prices) > 0)
{
// Load prices
@@ -201,20 +184,17 @@ function RALLYE_ADD_PRICES($rallye,$mode="email")
//
function RALLYE_ADD_TOPUSERS($rallye,$default=0)
{
- global $_CONFIG;
- $since = (time() - $_CONFIG['ap_in_since']);
-
// First check how many prices are set
- $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_rallye_prices WHERE rallye_id=%d ORDER BY price_level",
+ $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_rallye_prices` WHERE rallye_id=%s ORDER BY price_level",
array(bigintval($rallye)), __FILE__, __LINE__);
$prices = SQL_NUMROWS($result);
SQL_FREERESULT($result);
// And load only limited users
- $result = SQL_QUERY_ESC("SELECT DISTINCT u.userid, u.refs, u.curr_points FROM "._MYSQL_PREFIX."_rallye_users AS u
-LEFT JOIN "._MYSQL_PREFIX."_refsystem AS r
+ $result = SQL_QUERY_ESC("SELECT DISTINCT u.userid, u.refs, u.curr_points FROM `{!_MYSQL_PREFIX!}_rallye_users` AS u
+LEFT JOIN `{!_MYSQL_PREFIX!}_refsystem` AS r
ON u.userid=r.userid
-WHERE u.rallye_id=%d AND r.counter > 0 ORDER BY u.refs DESC",
+WHERE u.rallye_id=%s AND r.counter > 0 ORDER BY u.refs DESC",
array(bigintval($rallye)), __FILE__, __LINE__);
// Load users
@@ -224,27 +204,26 @@ WHERE u.rallye_id=%d AND r.counter > 0 ORDER BY u.refs DESC",
'cpoints' => array()
);
- while(list($uid, $refs, $cpoints) = SQL_FETCHROW($result))
+ while (list($uid, $refs, $cpoints) = SQL_FETCHROW($result))
{
// Get current refs
$cnt = RALLYE_GET_REFCOUNT($uid, $refs);
// Points of ref's
- $result_ref = SQL_QUERY_ESC("SELECT DISTINCT p.points FROM "._MYSQL_PREFIX."_user_points AS p
-LEFT JOIN "._MYSQL_PREFIX."_user_data AS d
+ $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=%d AND d.status='CONFIRMED' AND p.ref_depth=1 AND d.max_mails > 0 AND d.mails_confirmed >= %s AND d.last_online >= %s
-LIMIT 1", array(bigintval($uid), $_CONFIG['ref_payout'], $since), __FILE__, __LINE__);
+WHERE d.userid=%s AND d.`status`='CONFIRMED' AND p.ref_depth=1 AND d.max_mails > 0 AND d.mails_confirmed >= %s
+LIMIT 1", array(bigintval($uid), getConfig('ref_payout')), __FILE__, __LINE__);
list($refpoints) = SQL_FETCHROW($result_ref);
SQL_FREERESULT($result_ref);
- if (empty($refpoints)) $refpoints = "0";
-
- // And subtract start refs
- $cnt -= $refs;
+ if (empty($refpoints)) $refpoints = 0;
+ // Init userid for list
$_uid = "---";
// List only users with at least one ref!
+ //* DEBUG: */ echo "*".$cnt."/".$uid."/".$cpoints."/".$refpoints."* \n";
if (($cnt > 0) && ($refpoints > $cpoints)) { $_uid = $uid; } else { $cnt = ""; }
// Save values to array
@@ -267,19 +246,19 @@ LIMIT 1", array(bigintval($uid), $_CONFIG['ref_payout'], $since), __FILE__, __LI
if (empty($DATA['uid'][$idx])) $DATA['uid'][$idx] = "---";
if (empty($DATA['ref'][$idx])) $DATA['ref'][$idx] = "---";
// Add row
- $OUT .= "