0 AND
d.mails_confirmed >= {?ref_payout?} AND
p.ref_depth=1 AND
p.points > 0
AND d.userid=%s",
array(bigintval($content['userid'])), __FUNCTION__, __LINE__);
// Get points
list($cpoints) = SQL_FETCHROW($result_ref);
// Free result
SQL_FREERESULT($result_ref);
if (empty($cpoints)) $cpoints = '0.00000';
// Add info 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($content['userid']),
bigintval($cnt),
$cpoints
), __FUNCTION__, __LINE__);
$un = true;
} // END - if
// Ignored but for the template required refs (made before start of rallye)
$content['refs'] = $cnt;
// Shall I notify this member?
if (($notify == 'Y') && ($un)) {
// Load email template and send it to the user
$message = loadEmailTemplate('member_rallye_notify', $content, $content['userid']);
sendEmail($content['userid'], getMaskedMessage('RALLYE_MEMBER_NOTIFY', $title), $message);
} // END - if
} // END - while
// Choose the right admin template
$templ = 'admin_rallye_no_notify';
if ($notify == 'Y') $templ = 'admin_rallye_notify';
// Send email to admin
sendAdminNotification(getMaskedMessage('RALLYE_ADMIN_NOTIFY', $title), $templ, $prices);
// Free memory
SQL_FREERESULT($result_user);
}
//
function addReferalRallyePrices ($rallye, $mode='email') {
// Output mode
switch($mode) {
case 'email': $mode = "\n"; break;
case 'html' : $mode = " \n"; break;
} // END - switch
// Load prices
$result_prices = SQL_QUERY_ESC("SELECT
`price_level`, `points`, `info`
FROM
`{?_MYSQL_PREFIX?}_rallye_prices`
WHERE
`rallye_id`=%s
ORDER BY
`price_level` ASC",
array($rallye), __FUNCTION__, __LINE__);
// Entries found?
if (SQL_NUMROWS($result_prices) > 0) {
// Load prices
if ($mode == "\n") $prices = "{--RALLYE_MEMBER_PRICES_ADDED--}:".$mode."------------------------------".$mode;
$prices = '';
while ($content = SQL_FETCHARRAY($result_prices)) {
$prices .= $content['price_level']. '{--RALLYE_PRICE--}: ';
if (!empty($content['info'])) {
$prices .= $content['info'];
} else {
$prices .= $content['points'] . ' {?POINTS?}';
}
$prices .= '' . $mode;
} // END - if
// Free memory
SQL_FREERESULT($result_prices);
} else {
// No prices???
$prices = getMaskedMessage('RALLYE_MEMBER_NO_PRICES', $mode);
}
// Add last line for email mode
if ($mode == "\n") $prices .= '------------------------------';
// Return price list
return $prices;
}
//
function addReferalRallyeTopUsers ($rallye, $default=0) {
// 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",
array(bigintval($rallye)), __FUNCTION__, __LINE__);
$prices = SQL_NUMROWS($result);
SQL_FREERESULT($result);
// And load only limited users
$result = SQL_QUERY_ESC("SELECT
u.userid, u.refs, u.curr_points, rd.min_users, rd.min_prices
FROM
`{?_MYSQL_PREFIX?}_rallye_users` AS u
LEFT JOIN
`{?_MYSQL_PREFIX?}_refsystem` AS r
ON
u.userid=r.userid
LEFT JOIN
`{?_MYSQL_PREFIX?}_rallye_data` AS rd
ON
u.rallye_id=rd.id
WHERE
u.`rallye_id`=%s AND r.counter > 0
ORDER BY
u.refs DESC",
array(bigintval($rallye)), __FUNCTION__, __LINE__);
// Load users
$DATA = array(
'userid' => array(),
'ref' => array(),
'cpoints' => array()
);
while ($content = SQL_FETCHARRAY($result)) {
// Get current refs
$cnt = getReferalRallyeRefsCount($content['userid'], $content['refs']);
// Points of ref's
$result_ref = SQL_QUERY_ESC("SELECT
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 >= {?ref_payout?}
LIMIT 1",
array(bigintval($content['userid'])), __FUNCTION__, __LINE__);
// Get points
list($refpoints) = SQL_FETCHROW($result_ref);
// Free result
SQL_FREERESULT($result_ref);
if (empty($refpoints)) $refpoints = '0';
// Init userid for list
$userid = '---';
// List only users with at least one ref!
//* DEBUG: */ print("*".$cnt.'/'.$content['userid'].'/'.$content['curr_points'].'/'.$refpoints."* ");
if (($cnt > 0) && ($refpoints > $content['curr_points'])) { $userid = $content['userid']; } else { $cnt = ''; }
// Save values to array
$DATA['userid'][] = $userid;
$DATA['ref'][] = $cnt;
$DATA['cpoints'][] = $content['curr_points'];
$min_users = $content['min_users'];
$min_prices = $content['min_prices'];
} // END - while
// Free memory
SQL_FREERESULT($result);
// Sort whole array
array_pk_sort($DATA, array('ref', 'cpoints'), 0, 1, true);
// Generate table
$OUT = loadTemplate('guest_rallye_header', true);
$SW = 2;
for ($idx = '0'; $idx < $prices; $idx++) {
if (empty($DATA['userid'][$idx])) $DATA['userid'][$idx] = '---';
if (empty($DATA['ref'][$idx])) $DATA['ref'][$idx] = '---';
// Add row
$OUT .= "
");
//* DEBUG: */ shutdown();
if ($cnt > 0) {
// Count cache hits
incrementStatsEntry('cache_hits');
// Remove old refs
//* DEBUG: */ print('+'.$cnt.'/'.$old."+ ");
$cnt -= $old;
} // END - if
} else {
// Load current refs from database
$result_ref = SQL_QUERY_ESC("SELECT
SUM(s.counter) AS cnt
FROM
`{?_MYSQL_PREFIX?}_refsystem` AS s
LEFT JOIN
`{?_MYSQL_PREFIX?}_refdepths` AS d
ON
s.level=d.level
WHERE
s.userid=%s AND
s.level=1",
array(
bigintval($userid)
), __FUNCTION__, __LINE__);
// Load count @TODO Can't we rewrite this to our API?
list($cnt) = SQL_FETCHROW($result_ref);
// Free result
SQL_FREERESULT($result_ref);
if (empty($cnt)) {
$cnt = '0';
} else {
$cnt -= $old;
}
}
// Return count
//* DEBUG: */ print("*".$userid.'/'.$old.'/'.$cnt."* ");
return $cnt;
}
// Determines the right language string for min_users
function determineReferalRallyeMinimumUsers ($min_users) {
// Rallye ends without user limitation is the default
$return = getMessage('RALLYE_END_NO_USER_LIMITATION');
if ($min_users > 0) {
// Rallye ends when X members are totally in your exchange
$return = getMaskedMessage('RALLYE_END_USERS', $min_users);
} // END - if
// Return
return $return;
}
// Determines the right language string for min_prices
function determineReferalRallyeMinimumPrices ($min_prices) {
// Rallye ends without user limitation is the default
$return = getMessage('RALLYE_END_NO_PRICE_LIMITATION');
if ($min_prices > 0) {
// Rallye ends when X members are totally in your exchange
$return = getMaskedMessage('RALLYE_END_PRICES', $min_prices);
} // END - if
// Return
return $return;
}
// Filter for extra-autpurge
function FILTER_RALLYE_EXTRA_AUTOPURGE () {
// Check expired rallyes (hard-coded 3 days limit for displaying expired rallyes!)
purgeExpiredReferalRallyes();
}
// [EOF]
?>