2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 08/22/2004 *
4 * =================== Last change: 08/24/2004 *
6 * -------------------------------------------------------------------- *
7 * File : rallye_functions.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Special functions for rallye extension *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Spezielle Funktion fuer rallye-Erweiterung *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2011 by Mailer Developer Team *
20 * For more information visit: http://mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
43 // Auto-start referral rallyes
44 function autostartReferralRallyes ($result) {
45 // Load all rallyes (usally we have only one rallye active per time!
46 list($id, $title, $start, $end, $notify, $min_users, $min_prices) = SQL_FETCHROW($result);
49 SQL_FREERESULT($result);
53 `{?_MYSQL_PREFIX?}_rallye_data`
59 array(bigintval($id)), __FUNCTION__, __LINE__);
61 // Transfer all neccessary data to the $content array
62 $content['userid_cnt'] = getTotalConfirmedUser();
63 $content['start'] = generateDateTime($start, 2);
64 $content['end'] = generateDateTime($end , 2);
65 $content['now_t'] = generateDateTime(time(), 2);
66 $content['title'] = $title;
67 $content['id'] = $id; // id for the rallye details link
69 // Determine min_users and min_prices
70 $content['min_users'] = determineReferralRallyeMinimumUsers($min_users);
71 $content['min_prices'] = determineReferralRallyeMinimumPrices($min_prices);
74 $content['prices'] = addReferralRallyePrices($id);
77 $result_user = SQL_QUERY("SELECT
80 `{?_MYSQL_PREFIX?}_user_data`
84 `userid` ASC", __FUNCTION__, __LINE__);
86 // Let's begin with the userids...
87 while ($row = SQL_FETCHARRAY($result_user)) {
89 $content = merge_array($content, $row);
94 $count = getReferralRallyeRefsCount($content['userid']);
95 if (empty($count)) $count = '0'; // Added prevent some unknown troubles... :-?
97 // Check if line is already included...
98 $result_ref = SQL_QUERY_ESC("SELECT
101 `{?_MYSQL_PREFIX?}_rallye_users`
106 array(bigintval($id), bigintval($content['userid'])), __FUNCTION__, __LINE__);
107 if (SQL_HASZERONUMS($result_ref)) {
109 // Add userid and his ref count to table
110 $result_ref = SQL_QUERY_ESC("SELECT
111 SUM(p.points) AS `points`
113 `{?_MYSQL_PREFIX?}_user_points` AS p
115 `{?_MYSQL_PREFIX?}_user_data` AS d
119 d.`status`='CONFIRMED' AND
120 d.`max_mails` > 0 AND
121 d.`mails_confirmed` >= {?ref_payout?} AND
125 array(bigintval($content['userid'])), __FUNCTION__, __LINE__);
128 list($cpoints) = SQL_FETCHROW($result_ref);
131 SQL_FREERESULT($result_ref);
133 if (empty($cpoints)) $cpoints = '0.00000';
136 SQL_QUERY_ESC("INSERT INTO
137 `{?_MYSQL_PREFIX?}_rallye_users`
138 (`rallye_id`,`userid`,`refs`,`curr_points`)
143 bigintval($content['userid']),
146 ), __FUNCTION__, __LINE__);
151 SQL_FREERESULT($result_ref);
153 // Ignored but for the template required refs (made before start of rallye)
154 $content['refs'] = $count;
156 // Shall I notify this member?
157 if (($notify == 'Y') && ($un)) {
158 // Load email template and send it to the user
159 $message = loadEmailTemplate('member_rallye_notify', $content, $content['userid']);
160 sendEmail($content['userid'], '{%message,RALLYE_MEMBER_NOTIFY=' . $title . '%}', $message);
164 // Choose the right admin template
165 $templ = 'admin_rallye_no_notify';
166 if ($notify == 'Y') $templ = 'admin_rallye_notify';
168 // Send email to admin
169 sendAdminNotification('{%message,RALLYE_ADMIN_NOTIFY=' . $title . '%}', $templ, $prices);
172 SQL_FREERESULT($result_user);
176 function addReferralRallyePrices ($rallye, $mode = 'email') {
179 case 'email': $mode = "\n"; break;
180 case 'html' : $mode = '<br />'; break;
184 $result_prices = SQL_QUERY_ESC("SELECT
185 `price_level`,`points`,`info`
187 `{?_MYSQL_PREFIX?}_rallye_prices`
192 array($rallye), __FUNCTION__, __LINE__);
195 if (!SQL_HASZERONUMS($result_prices)) {
197 if ($mode == "\n") $prices = '{--RALLYE_MEMBER_PRICES_ADDED--}:' . $mode . '------------------------------' . $mode;
200 while ($content = SQL_FETCHARRAY($result_prices)) {
201 $prices .= $content['price_level']. '{--RALLYE_PRICE--}: ';
202 if (!empty($content['info'])) {
203 $prices .= $content['info'];
205 $prices .= $content['points'] . ' {?POINTS?}';
207 $prices .= '' . $mode;
211 SQL_FREERESULT($result_prices);
214 $prices = '{%message,RALLYE_MEMBER_NO_PRICES=' . $mode . '%}';
217 // Add last line for email mode
218 if ($mode == "\n") $prices .= '------------------------------';
225 function addReferralRallyeTopUsers ($mode, $rallye, $default=0) {
227 $min_users = 0; $min_prices = 0;
229 // First check how many prices are set
230 $prices = countSumTotalData($rallye, 'rallye_prices', 'id', 'rallye_id', true);
232 // And load only limited users
233 $result = SQL_QUERY_ESC("SELECT
234 u.userid, u.refs, u.curr_points, rd.min_users, rd.min_prices
236 `{?_MYSQL_PREFIX?}_rallye_users` AS u
238 `{?_MYSQL_PREFIX?}_refsystem` AS r
242 `{?_MYSQL_PREFIX?}_rallye_data` AS rd
250 array(bigintval($rallye)), __FUNCTION__, __LINE__);
260 while ($content = SQL_FETCHARRAY($result)) {
262 $count = getReferralRallyeRefsCount($content['userid'], $content['refs']);
265 $result_ref = SQL_QUERY_ESC("SELECT
268 `{?_MYSQL_PREFIX?}_user_points` AS p
270 `{?_MYSQL_PREFIX?}_user_data` AS d
275 d.`status`='CONFIRMED' AND
278 d.mails_confirmed >= {?ref_payout?}
280 array(bigintval($content['userid'])), __FUNCTION__, __LINE__);
283 list($refpoints) = SQL_FETCHROW($result_ref);
286 SQL_FREERESULT($result_ref);
288 if (empty($refpoints)) $refpoints = '0';
290 // Init userid for list
293 // List only users with at least one ref!
294 //* DEBUG: */ debugOutput('*'.$count.'/'.$content['userid'].'/'.$content['curr_points'].'/'.$refpoints.'*');
295 if (($count > 0) && ($refpoints > $content['curr_points'])) {
296 $userid = $content['userid'];
301 // Save values to array
302 $content['userid'][] = $userid;
303 $content['ref'][] = $count;
304 $content['cpoints'][] = $content['curr_points'];
305 $min_users = $content['min_users'];
306 $min_prices = $content['min_prices'];
310 SQL_FREERESULT($result);
313 array_pk_sort($content, array('ref', 'cpoints'), 0, 1, true);
317 for ($idx = '0'; $idx < $prices; $idx++) {
318 // Prepare marking of default (maybe current user's) id
319 $start = ''; $end = '';
320 if (($content['userid'][$idx] == $default) && ($default > 0)) {
330 'userid' => $content['userid'][$idx],
331 'ref' => $content['ref'][$idx],
335 // Load row template and switch color
336 $OUT .= loadTemplate($mode . '_list_rallye_row', true, $row);
339 // Add min_prices/users
340 $content['rows'] = $OUT;
341 $content['min_prices'] = bigintval($min_prices);
342 $content['min_users'] = bigintval($min_users);
344 // And finnally return the output
345 return loadTemplate($mode . '_list_rallye', true, $content);
348 // Run this function only when a new member has confirmed his email address!
349 function addUserToReferralRallye ($userid, $content = array()) {
352 // Updated extension?
353 if (isExtensionInstalledAndNewer('rallye', '0.2.0')) {
354 $add .= ',`min_users`,`min_prices`';
357 // Check for an auto-add rallye
358 $result = SQL_QUERY("SELECT
359 `id`,`title`,`start_time`,`end_time`,`send_notify`".$add."
361 `{?_MYSQL_PREFIX?}_rallye_data`
365 `auto_add_new_user`='Y' AND
367 LIMIT 1", __FUNCTION__, __LINE__);
368 if (SQL_NUMROWS($result) == 1) {
370 $min_users = '0'; $min_prices = '0';
373 if (isExtensionInstalledAndNewer('rallye', '0.2.0')) {
374 list($id, $title, $start, $end, $notify, $min_users, $min_prices) = SQL_FETCHROW($result);
376 list($id, $title, $start, $end, $notify) = SQL_FETCHROW($result);
380 SQL_FREERESULT($result);
382 if ($notify == 'Y') {
383 // Transfer all neccessary data to $content array
384 $content['start'] = generateDateTime($start, 2);
385 $content['end'] = generateDateTime($end , 2);
386 $content['now_t'] = generateDateTime(time(), 2);
387 $content['title'] = $title;
388 $content['id'] = $id; // id for the rallye details link
389 $content['ref'] = '0';
390 $content['refs'] = countSumTotalData($userid, 'user_data', 'userid', 'refid', true);
393 $content['prices'] = addReferralRallyePrices($id);
395 // Determine min_users/prices tring
396 $content['min_users'] = determineReferralRallyeMinimumUsers($min_users);
397 $content['min_prices'] = determineReferralRallyeMinimumPrices($min_prices);
399 // Send notification to member
400 $message = loadEmailTemplate('member_rallye_notify', $content, $userid);
401 sendEmail($userid, '{%message,RALLYE_MEMBER_NOTIFY=' . $title . '%}', $message);
404 // Check if line is already included...
405 $result = SQL_QUERY_ESC("SELECT
408 `{?_MYSQL_PREFIX?}_rallye_users`
416 ), __FUNCTION__, __LINE__);
418 // Is this user added?
419 if (SQL_HASZERONUMS($result)) {
420 // Add userid and his ref count to table
421 SQL_QUERY_ESC("INSERT INTO
422 `{?_MYSQL_PREFIX?}_rallye_users`
423 (`rallye_id`,`userid`,`refs`)
429 ), __FUNCTION__, __LINE__);
433 SQL_FREERESULT($result);
438 function markReferralRallyesAsExpired ($result) {
440 list($id, $title, $start, $end, $notify, $min_users, $min_prices) = SQL_FETCHROW($result);
443 SQL_FREERESULT($result);
449 $content['title'] = $title;
450 $content['start'] = generateDateTime($start, 1);
451 $content['end'] = generateDateTime($end , 1);
452 $content['now_t'] = generateDateTime(time(), 1);
454 // Load users array (!) with assigned prices
455 $prices = getArrayFromReferralRallyeUsers($id);
459 foreach ($prices['userid'] as $key => $userid) {
461 // active = 1: account is still confirmed
462 // active = 0: account is deleted or locked
463 $active = countSumTotalData($userid, 'user_data', 'userid', 'userid', true, " AND `status`='CONFIRMED'");
465 $prices['active'][$key] = $active;
467 // Allow valid and active users with at least one ref to get points
468 if ((isValidUserId($userid)) && ($prices['ref'][$key] > 0) && ($active == 1) && ($prices['cpoints'][$key] > 0)) {
473 if (($total < $min_prices) || ($total == '0')) {
474 // Do not end this rallye!
480 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET `expired`='Y' WHERE `id`=%s LIMIT 1",
481 array(bigintval($id)), __FUNCTION__, __LINE__);
483 // Run array through (by userid is the most important 2nd-level-array)
484 foreach ($prices['userid'] as $key => $userid) {
485 // Allow valid and active users with at least one ref to get points
486 if ((isValidUserId($userid)) && ($prices['ref'][$key] > 0) && ($prices['active'][$key] == 1) && ($prices['cpoints'][$key] > 0)) {
487 // Transfer data to array for the mail template
488 $content['level'] = $prices['level'][$key];
489 $content['points'] = $prices['points'][$key];
490 $content['info'] = $prices['info'][$key];
491 $content['ref'] = $prices['ref'][$key];
494 $winnerLevel = 'other';
496 // Determine winner level
497 if ($content['level'] == 1) {
499 $winnerLevel = 'gold';
500 } elseif ($content['level'] == 2) {
502 $winnerLevel = 'silver';
503 } elseif ($content['level'] == 3) {
505 $winnerLevel = 'bronce';
508 if ($content['points'] > 0) {
509 // Add points directly to user's account
510 initReferralSystem();
511 addPointsThroughReferralSystem('rallye_winner:' . $winnerLevel, $userid, $content['points']);
514 if ($notify == 'Y') {
515 // Prepare infos for the mail template
516 if (!empty($content['info'])) {
518 $content['infos'] = $content['info'];
521 $content['infos'] = $content['points'] . ' {?POINTS?}';
524 // Add suffix to template name
525 $template = 'member_rallye_expired_' . $winnerLevel;
528 $message = loadEmailTemplate($template, $content, $userid);
529 sendEmail($userid, '{%message,RALLYE_MEMBER_EXPIRED_SUBJECT=' . $content['level'] . '%}', $message);
534 $users['userid'][$userid] = $userid;
535 $users['poi'][$userid] = $content['infos'];
539 // Select template depending on notfication is switch on / off
540 if ($notify == 'Y') {
541 $templ = 'admin_rallye_expired';
542 } elseif (is_array($users['userid'])) {
543 $templ = 'admin_rallye_expired_no';
544 $count = getReferralRallyeUserDataFromArray($users);
548 $content['count'] = $count;
550 // Send mail to admin
551 sendAdminNotification('{%message,RALLYE_ADMIN_EXPIRED_SUBJECT=' . $title . '%}', $templ, $content);
553 // Add task (we ignore the task id here)
554 createNewTask('{--RALLYE_ADMIN_EXPIRED--}: ' . $title, '{--RALLYE_ADMIN_EXPIRED_TEXT--}', 'RALLYE_EXPIRED');
558 function getReferralRallyeUserDataFromArray ($userIds) {
560 $userid_string = implode(',', $userIds['userid']);
562 // Init result string
566 $result = SQL_QUERY_ESC("SELECT
567 `userid`,`gender`,`surname`,`family`,`email`
569 `{?_MYSQL_PREFIX?}_user_data`
579 ), __FUNCTION__, __LINE__);
580 while ($content = SQL_FETCHARRAY($result)) {
581 // Construct the message masked and add it
582 $ret .= sprintf("{%%pipe,translateGender=%s%} %s %s (%s) - %s\n",
587 $userIds['poi'][$content['userid']]
592 return substr($ret, 0, -1);
596 function getArrayFromReferralRallyePrices ($rallye) {
605 $result = SQL_QUERY_ESC("SELECT
606 `price_level`,`points`,`info`
608 `{?_MYSQL_PREFIX?}_rallye_prices`
613 array(bigintval($rallye)), __FUNCTION__, __LINE__);
616 while ($content = SQL_FETCHARRAY($result)) {
617 $prices['level'][] = $content['price_level'];
618 $prices['points'][] = $content['points'];
619 $prices['info'][] = $content['info'];
623 SQL_FREERESULT($result);
630 function getArrayFromReferralRallyeUsers ($rallye) {
631 // Fix zero points to 0.00000
632 if (getConfig('ref_payout') == '0') setConfigEntry('ref_payout', '0.00000');
638 'cpoints' => array(),
641 // Load users userid old points earned
642 $result_user = SQL_QUERY_ESC("SELECT `userid`,`refs`,`curr_points` FROM `{?_MYSQL_PREFIX?}_rallye_users` WHERE `rallye_id`=%s ORDER BY `userid` ASC",
643 array(bigintval($rallye)), __FUNCTION__, __LINE__);
644 while ($content = SQL_FETCHARRAY($result_user)) {
645 // Load current ref count
646 $count = getReferralRallyeRefsCount($content['userid'], $content['refs']);
649 $result_ref = SQL_QUERY_ESC("SELECT
650 SUM(p.points) AS `points`
652 `{?_MYSQL_PREFIX?}_user_points` AS p
654 `{?_MYSQL_PREFIX?}_user_data` AS d
658 d.`status`='CONFIRMED' AND
660 d.mails_confirmed >= {?ref_payout?} AND
665 array(bigintval($content['userid'])), __FUNCTION__, __LINE__);
668 list($refpoints) = SQL_FETCHROW($result_ref);
671 SQL_FREERESULT($result_ref);
673 // Fix empty refpoints
674 if (empty($refpoints)) $refpoints = '0';
676 // Store calculated new refs to array
677 $users['userid'][] = $content['userid'];
678 $users['ref'][] = abs($count - $content['refs']);
679 $users['cpoints'][] = $refpoints - $content['curr_points'];
683 SQL_FREERESULT($result_user);
685 // Sort array for refs (descending)
686 array_pk_sort($users, array('ref', 'cpoints'), 0, 1, true);
688 // Load prices array (!)
689 $prices = getArrayFromReferralRallyePrices($rallye);
691 // Merge users into prices
692 foreach ($prices['level'] as $k => $level) {
693 // We only need to check one element in $users, see above while() block
694 if (isset($users['userid'][$k])) {
695 $prices['userid'][$k] = $users['userid'][$k];
696 $prices['ref'][$k] = $users['ref'][$k];
697 $prices['cpoints'][$k] = $users['cpoints'][$k];
701 // Return completed array
705 // @TODO This function does not load min_users, min_prices, please encapsulate loading rallye data with e.g. getRallyeDataFromId()
706 function addReferralRallyeWinners ($mode, $rallye, $default=0) {
707 // First check how many prices are set
708 $prices = countSumTotalData(bigintval($rallye), 'rallye_prices', 'id', 'rallye_id', true);
711 $content = getArrayFromReferralRallyeUsers($rallye);
715 for ($idx = '0'; $idx < $prices; $idx++) {
717 // active = 1: account is still confirmed
718 // active = 0: account is deleted or locked
719 $active = countSumTotalData($content['userid'][$idx], 'user_data', 'userid', 'userid', true, " AND `status`='CONFIRMED'");
721 if ((empty($content['ref'][$idx])) || ($content['ref'][$idx] == '0') || ($active == '0') || ('' . round($content['cpoints'][$idx]) . '' == '0') || (empty($content['cpoints'][$idx]))) {
722 // Allow valid and active users with at least one ref to get points
723 $content['ref'][$idx] = '---';
724 $content['userid'][$idx] = '---';
727 if (!empty($content['info'][$idx])) {
729 $content['infos'][$idx] = $content['info'][$idx];
732 $content['infos'][$idx] = $content['points'][$idx] . ' {?POINTS?}';
735 // Prepare marking of default (maybe current user's) id
736 $start = ''; $end = '';
737 if (($content['userid'][$idx] == $default) && ($default > 0)) {
745 'userid' => $content['userid'][$idx],
746 'ref' => $content['ref'][$idx],
747 'infos' => $content['infos'][$idx],
753 $OUT .= loadTemplate($mode . '_list_rallye_row', true, $row);
759 'min_users' => '???',
760 'min_prices' => '???'
763 // Load main template and finnally return the output
764 return loadTemplate($mode . '_list_rallye', true, $content);
768 function purgeExpiredReferralRallyes () {
769 // Check for expired rallyes
770 $EXPIRE = 3; // @TODO The hard-coded value...
771 $result_rallye = SQL_QUERY_ESC("SELECT
772 `id`,`title`,`start_time`,`end_time`
774 `{?_MYSQL_PREFIX?}_rallye_data`
776 (UNIX_TIMESTAMP() - `end_time`) > ({?ONE_DAY?} * %s) AND
778 array($EXPIRE), __FUNCTION__, __LINE__);
780 if (!SQL_HASZERONUMS($result_rallye)) {
784 // Expire found rallyes and notify admin
785 while ($content = SQL_FETCHARRAY($result_rallye)) {
786 // Prepare data for mail template
787 $content['start_time'] = generateDateTime($content['start_time'], 1);
788 $content['end_time'] = generateDateTime($content['end_time'] , 1);
789 $content['now_time'] = generateDateTime(time(), 1);
791 // Send mail to admin
792 sendAdminNotification('{%message,RALLYE_ADMIN_PURGED_SUBJECT=' . $content['title'] . '%}', 'admin_rallye_purged', $content);
794 // Purge whole rallye
795 addSql(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_rallye_data` WHERE `id`=%s LIMIT 1",
796 array(bigintval($content['id'])), __FUNCTION__, __LINE__, false));
797 addSql(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `rallye_id`=%s LIMIT 1",
798 array(bigintval($content['id'])), __FUNCTION__, __LINE__, false));
799 addSql(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_rallye_users` WHERE `rallye_id`=%s LIMIT 1",
800 array(bigintval($content['id'])), __FUNCTION__, __LINE__, false));
802 // Add task (we ignore the task id here
803 createNewTask('{--RALLYE_ADMIN_PURGED--}: ' . $content['title'], '{--RALLYE_ADMIN_PURGED_TEXT--}', 'RALLYE_PURGED');
807 runFilterChain('run_sqls');
811 SQL_FREERESULT($result_rallye);
815 function addReferralRallyeTemplateSelection ($name = 'template', $default = '') {
820 // Check templates directory
821 $basePath = sprintf("templates/%s/html/rallye/", getLanguage());
823 // Read the directory
824 $templates = getArrayFromDirectory($basePath, 'rallye_', false, true, array(), '.tpl');
827 foreach ($templates as $read) {
828 // Cut prefix and extension away
829 $read = substr($read, 7, strpos($read, '.') - 7);
831 // Accept only template names between 1 and 255 chars length
832 if ((strlen($read) < 256) && (!empty($read))) {
837 logDebugMessage(__FUNCTION__, __LINE__, sprintf("WARNING: Template %s not used.", $read));
841 // Do we have found templates which we can link with the new rallye?
842 if (!empty($ral[0])) {
843 // Generate selection box for all found templates
844 $OUT = '<select class="form_select" name="' . $name . '" size="1">';
845 $OUT .= generateOptionList('/ARRAY/', array_keys($ral), array_values($ral), $default, '', 'none');
848 // No rallye templates found
849 $OUT = '{--RALLYE_NO_TEMPLATES_FOUND--}';
856 // @TODO Please document this function
857 function getReferralRallyeRefsCount ($currUserid, $oldReferralCount = '0') {
858 // Check current refs
859 if (isExtensionInstalledAndNewer('cache', '0.1.2')) {
860 // Get refs from cache
862 foreach ($GLOBALS['cache_array']['refsystem']['userid'] as $id => $userid) {
863 // Do we have a ref for this user?
864 //* DEBUG: */ debugOutput('id='.$id.',userid='.$userid.',userid='.$userid.',oldReferralCount='.$oldReferralCount.',level='.$GLOBALS['cache_array']['refsystem']['level'][$id]);
865 if (($currUserid == $userid) && ($GLOBALS['cache_array']['refsystem']['level'][$id] == 1)) {
866 //* DEBUG: */ debugOutput('userid matches!');
867 foreach ($GLOBALS['cache_array']['refdepths']['level'] as $level) {
868 if (($level == $GLOBALS['cache_array']['refsystem']['level'][$id]) && ($level == 1)) {
869 // Level does exist so abort here
870 $count = $GLOBALS['cache_array']['refsystem']['counter'][$id];
871 //* DEBUG: */ debugOutput('*'.$userid.'/'.$count.'*');
873 } elseif ($level > 1) {
874 // Not interesting here...
880 if ($count > 0) break;
884 //* DEBUG: */ debugOutput('<pre>'.print_r($GLOBALS['cache_array']['refsystem'], true).'</pre>');
885 //* DEBUG: */ shutdown();
889 incrementStatsEntry('cache_hits');
892 //* DEBUG: */ debugOutput('+'.$count.'/'.$oldReferralCount.'+');
893 $count -= $oldReferralCount;
896 // Load current refs from database
897 $result_ref = SQL_QUERY_ESC("SELECT
898 SUM(s.counter) AS cnt
900 `{?_MYSQL_PREFIX?}_refsystem` AS s
902 `{?_MYSQL_PREFIX?}_refdepths` AS d
910 ), __FUNCTION__, __LINE__);
912 // Load count @TODO Can't we rewrite this to our API?
913 list($count) = SQL_FETCHROW($result_ref);
916 SQL_FREERESULT($result_ref);
920 $count -= $oldReferralCount;
925 //* DEBUG: */ debugOutput('*'.$userid.'/'.$oldReferralCount.'/'.$count.'*');
929 // Determines the right language string for min_users
930 function determineReferralRallyeMinimumUsers ($min_users) {
931 // Rallye ends without user limitation is the default
932 $return = '{--RALLYE_END_NO_USER_LIMITATION--}';
934 if ($min_users > 0) {
935 // Rallye ends when X members are totally in your exchange
936 $return = '{%message,RALLYE_END_USERS=' . $min_users . '%}';
943 // Determines the right language string for min_prices
944 function determineReferralRallyeMinimumPrices ($min_prices) {
945 // Rallye ends without user limitation is the default
946 $return = '{--RALLYE_END_NO_PRICE_LIMITATION--}';
948 if ($min_prices > 0) {
949 // Rallye ends when X members are totally in your exchange
950 $return = '{%message,RALLYE_END_PRICES=' . $min_prices . '%}';