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://www.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 referal rallyes
44 function autostartReferalRallyes ($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'] = determineReferalRallyeMinimumUsers($min_users);
71 $content['min_prices'] = determineReferalRallyeMinimumPrices($min_prices);
74 $content['prices'] = addReferalRallyePrices($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 = getReferalRallyeRefsCount($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
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'], getMaskedMessage('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(getMaskedMessage('RALLYE_ADMIN_NOTIFY', $title), $templ, $prices);
172 SQL_FREERESULT($result_user);
176 function addReferalRallyePrices ($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 = getMaskedMessage('RALLYE_MEMBER_NO_PRICES', $mode);
217 // Add last line for email mode
218 if ($mode == "\n") $prices .= '------------------------------';
225 function addReferalRallyeTopUsers ($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 = getReferalRallyeRefsCount($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 $DATA['userid'][] = $userid;
303 $DATA['ref'][] = $count;
304 $DATA['cpoints'][] = $content['curr_points'];
305 $min_users = $content['min_users'];
306 $min_prices = $content['min_prices'];
310 SQL_FREERESULT($result);
313 array_pk_sort($DATA, 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 (($DATA['userid'][$idx] == $default) && ($default > 0)) {
330 'userid' => $DATA['userid'][$idx],
331 'ref' => $DATA['ref'][$idx],
335 // Load row template and switch color
336 $OUT .= loadTemplate('guest_rallye_row', true, $content);
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('guest_rallye', true, $content);
348 // Run this function only when a new member has confirmed his email address!
349 function addUserToReferalRallye ($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'] = addReferalRallyePrices($id);
395 // Determine min_users/prices tring
396 $content['min_users'] = determineReferalRallyeMinimumUsers($min_users);
397 $content['min_prices'] = determineReferalRallyeMinimumPrices($min_prices);
399 // Send notification to member
400 $message = loadEmailTemplate('member_rallye_notify', $content, $userid);
401 sendEmail($userid, getMaskedMessage('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 markReferalRallyesAsExpired ($result) {
442 list($id, $title, $start, $end, $notify, $min_users, $min_prices) = SQL_FETCHROW($result);
445 SQL_FREERESULT($result);
447 // Load users array (!) with assigned prices
448 $prices = getArrayFromReferalRallyeUsers($id);
454 $DATA['title'] = $title;
455 $DATA['start'] = generateDateTime($start, 1);
456 $DATA['end'] = generateDateTime($end , 1);
457 $DATA['now_t'] = generateDateTime(time(), 1);
461 foreach ($prices['userid'] as $key => $userid) {
463 // active = 1: account is still confirmed
464 // active = 0: account is deleted or locked
465 $active = countSumTotalData($userid, 'user_data', 'userid', 'userid', true, " AND `status`='CONFIRMED'");
467 $prices['active'][$key] = $active;
469 // Allow valid and active users with at least one ref to get points
470 if ((isValidUserId($userid)) && ($prices['ref'][$key] > 0) && ($active == 1) && ($prices['cpoints'][$key] > 0)) {
475 if (($total < $min_prices) || ($total == '0')) {
476 // Do not end this rallye!
482 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET `expired`='Y' WHERE `id`=%s LIMIT 1",
483 array(bigintval($id)), __FUNCTION__, __LINE__);
485 // Run array through (by userid is the most important 2nd-level-array)
486 foreach ($prices['userid'] as $key => $userid) {
487 // Allow valid and active users with at least one ref to get points
488 if ((isValidUserId($userid)) && ($prices['ref'][$key] > 0) && ($prices['active'][$key] == 1) && ($prices['cpoints'][$key] > 0)) {
489 // Transfer data to array for the mail template
490 $DATA['level'] = $prices['level'][$key];
491 $DATA['points'] = $prices['points'][$key];
492 $DATA['info'] = $prices['info'][$key];
493 $DATA['ref'] = $prices['ref'][$key];
496 $winnerLevel = 'other';
498 // Determine winner level
499 if ($DATA['level'] == 1) {
501 $winnerLevel = '_gold';
502 } elseif ($DATA['level'] == 2) {
504 $winnerLevel = '_silver';
505 } elseif ($DATA['level'] == 3) {
507 $winnerLevel = '_bronce';
510 if ($DATA['points'] > 0) {
511 // Add points directly to user's account
512 addPointsDirectly('rallye_winner' . $winnerLevel, $userid, $DATA['points']);
515 if ($notify == 'Y') {
516 // Prepare infos for the mail template
517 if (!empty($DATA['info'])) {
519 $DATA['infos'] = $DATA['info'];
522 $DATA['infos'] = $DATA['points'] . ' {?POINTS?}';
525 // Add suffix to template name
526 $template = 'member_rallye_expired' . $winnerLevel;
529 $message = loadEmailTemplate($template, $DATA, $userid);
530 sendEmail($userid, getMaskedMessage('RALLYE_MEMBER_EXPIRED_SUBJECT', $DATA['level']), $message);
535 $users['userid'][$userid] = $userid;
536 $users['poi'][$userid] = $DATA['infos'];
540 // Select template depending on notfication is switch on / off
541 if ($notify == 'Y') {
542 $templ = 'admin_rallye_expired';
543 } elseif (is_array($users['userid'])) {
544 $templ = 'admin_rallye_expired_no';
545 $count = getReferalRallyeUserDataFromArray($users);
548 // Send mail to admin
549 sendAdminNotification(getMaskedMessage('RALLYE_ADMIN_EXPIRED_SUBJECT', $title), $templ, $count);
551 // Add task (we ignore the task id here)
552 createNewTask('{--RALLYE_ADMIN_EXPIRED--}: ' . $title, '{--RALLYE_ADMIN_EXPIRED_TEXT--}', 'RALLYE_EXPIRED');
556 function getReferalRallyeUserDataFromArray ($userIds) {
558 $userid_string = implode(',', $userIds['userid']);
560 // Init result string
564 $result = SQL_QUERY_ESC("SELECT
565 `userid`, `gender`, `surname`, `family`, `email`
567 `{?_MYSQL_PREFIX?}_user_data`
577 ), __FUNCTION__, __LINE__);
578 while ($content = SQL_FETCHARRAY($result)) {
579 // Construct the message masked and add it
580 $ret .= sprintf("%s %s %s (%s) - %s\n",
581 translateGender($content['gender']),
585 $userIds['poi'][$content['userid']]
590 return substr($ret, 0, -1);
594 function getArrayFromReferalRallyePrices ($rallye) {
603 $result = SQL_QUERY_ESC("SELECT
604 `price_level`, `points`, `info`
606 `{?_MYSQL_PREFIX?}_rallye_prices`
611 array(bigintval($rallye)), __FUNCTION__, __LINE__);
614 while ($content = SQL_FETCHARRAY($result)) {
615 $prices['level'][] = $content['price_level'];
616 $prices['points'][] = $content['points'];
617 $prices['info'][] = $content['info'];
621 SQL_FREERESULT($result);
628 function getArrayFromReferalRallyeUsers ($rallye) {
629 // Fix zero points to 0.00000
630 if (getConfig('ref_payout') == '0') setConfigEntry('ref_payout', '0.00000');
636 'cpoints' => array(),
639 // Load users userid old points earned
640 $result_user = SQL_QUERY_ESC("SELECT `userid`, `refs`, `curr_points` FROM `{?_MYSQL_PREFIX?}_rallye_users` WHERE `rallye_id`=%s ORDER BY `userid` ASC",
641 array(bigintval($rallye)), __FUNCTION__, __LINE__);
642 while ($content = SQL_FETCHARRAY($result_user)) {
643 // Load current ref count
644 $count = getReferalRallyeRefsCount($content['userid'], $content['refs']);
647 $result_ref = SQL_QUERY_ESC("SELECT
648 SUM(p.points) AS points
650 `{?_MYSQL_PREFIX?}_user_points` AS p
652 `{?_MYSQL_PREFIX?}_user_data` AS d
656 d.`status`='CONFIRMED' AND
658 d.mails_confirmed >= {?ref_payout?} AND
663 array(bigintval($content['userid'])), __FUNCTION__, __LINE__);
666 list($refpoints) = SQL_FETCHROW($result_ref);
669 SQL_FREERESULT($result_ref);
671 // Fix empty refpoints
672 if (empty($refpoints)) $refpoints = '0';
674 // Store calculated new refs to array
675 $users['userid'][] = $content['userid'];
676 $users['ref'][] = abs($count - $content['refs']);
677 $users['cpoints'][] = $refpoints - $content['curr_points'];
681 SQL_FREERESULT($result_user);
683 // Sort array for refs (descending)
684 array_pk_sort($users, array('ref', 'cpoints'), 0, 1, true);
686 // Load prices array (!)
687 $prices = getArrayFromReferalRallyePrices($rallye);
689 // Merge users into prices
690 foreach ($prices['level'] as $k => $level) {
691 // We only need to check one element in $users, see above while() block
692 if (isset($users['userid'][$k])) {
693 $prices['userid'][$k] = $users['userid'][$k];
694 $prices['ref'][$k] = $users['ref'][$k];
695 $prices['cpoints'][$k] = $users['cpoints'][$k];
699 // Return completed array
703 // @TODO This function does not load min_users, min_prices, please encapsulate loading rallye data with e.g. getRallyeDataFromId()
704 function addReferalRallyeWinners ($rallye, $default=0) {
705 // First check how many prices are set
706 $prices = countSumTotalData(bigintval($rallye), 'rallye_prices', 'id', 'rallye_id', true);
709 $DATA = getArrayFromReferalRallyeUsers($rallye);
713 for ($idx = '0'; $idx < $prices; $idx++) {
715 // active = 1: account is still confirmed
716 // active = 0: account is deleted or locked
717 $active = countSumTotalData($DATA['userid'][$idx], 'user_data', 'userid', 'userid', true, " AND `status`='CONFIRMED'");
719 if ((empty($DATA['ref'][$idx])) || ($DATA['ref'][$idx] == '0') || ($active == '0') || ('' . round($DATA['cpoints'][$idx]) . '' == '0') || (empty($DATA['cpoints'][$idx]))) {
720 // Allow valid and active users with at least one ref to get points
721 $DATA['ref'][$idx] = '---';
722 $DATA['userid'][$idx] = '---';
725 if (!empty($DATA['info'][$idx])) {
727 $DATA['infos'][$idx] = $DATA['info'][$idx];
730 $DATA['infos'][$idx] = $DATA['points'][$idx] . ' {?POINTS?}';
733 // Prepare marking of default (maybe current user's) id
734 $start = ''; $end = '';
735 if (($DATA['userid'][$idx] == $default) && ($default > 0)) {
743 'userid' => $DATA['userid'][$idx],
744 'ref' => $DATA['ref'][$idx],
745 'infos' => $DATA['infos'][$idx],
751 $OUT .= loadTemplate('guest_rallye_row', true, $content);
757 'min_users' => '???',
758 'min_prices' => '???'
761 // Load main template and finnally return the output
762 return loadTemplate('guest_rallye', true, $content);
766 function purgeExpiredReferalRallyes () {
767 // Check for expired rallyes
768 $EXPIRE = 3; // @TODO The hard-coded value...
769 $result_rallye = SQL_QUERY_ESC("SELECT
770 `id`, `title`, `start_time`, `end_time`
772 `{?_MYSQL_PREFIX?}_rallye_data`
774 `end_time` <= (UNIX_TIMESTAMP() - {?ONE_DAY?} - %s) AND
776 array($EXPIRE), __FUNCTION__, __LINE__);
778 if (!SQL_HASZERONUMS($result_rallye)) {
782 // Expire found rallyes and notify admin
783 while ($content = SQL_FETCHARRAY($result_rallye)) {
784 // Prepare data for mail template
785 $content['start_time'] = generateDateTime($content['start_time'], 1);
786 $content['end_time'] = generateDateTime($content['end_time'] , 1);
787 $content['now_time'] = generateDateTime(time(), 1);
789 // Send mail to admin
790 sendAdminNotification(getMaskedMessage('RALLYE_ADMIN_PURGED_SUBJECT', $content['title']), 'admin_rallye_purged', $content);
792 // Purge whole rallye
793 addSql(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_rallye_data` WHERE `id`=%s LIMIT 1",
794 array(bigintval($content['id'])), __FUNCTION__, __LINE__, false));
795 addSql(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `rallye_id`=%s LIMIT 1",
796 array(bigintval($content['id'])), __FUNCTION__, __LINE__, false));
797 addSql(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_rallye_users` WHERE `rallye_id`=%s LIMIT 1",
798 array(bigintval($content['id'])), __FUNCTION__, __LINE__, false));
800 // Add task (we ignore the task id here
801 createNewTask('{--RALLYE_ADMIN_PURGED--}: ' . $content['title'], '{--RALLYE_ADMIN_PURGED_TEXT--}', 'RALLYE_PURGED');
805 runFilterChain('run_sqls');
809 SQL_FREERESULT($result_rallye);
813 function addReferalRallyeTemplateSelection ($name = 'template', $default = '') {
818 // Check templates directory
819 $basePath = sprintf("templates/%s/html/rallye/", getLanguage());
821 // Read the directory
822 $templates = getArrayFromDirectory($basePath, 'rallye_', false, true, array(), '.tpl');
825 foreach ($templates as $read) {
826 // Cut prefix and extension away
827 $read = substr($read, 7, strpos($read, '.') - 7);
829 // Accept only template names between 1 and 255 chars length
830 if ((strlen($read) < 256) && (!empty($read))) {
835 logDebugMessage(__FUNCTION__, __LINE__, sprintf("WARNING: Template %s not used.", $read));
839 // Do we have found templates which we can link with the new rallye?
840 if (!empty($ral[0])) {
841 // Generate selection box for all found templates
842 $OUT = '<select class="form_select" name="' . $name . '" size="1">';
843 $OUT .= generateOptionList('/ARRAY/', array_keys($ral), array_values($ral), $default, '', 'none');
846 // No rallye templates found
847 $OUT = '{--RALLYE_NO_TEMPLATES_FOUND--}';
854 // @TODO Please document this function
855 function getReferalRallyeRefsCount ($currUserid, $old = '0') {
856 // Check current refs
857 if (isExtensionInstalledAndNewer('cache', '0.1.2')) {
858 // Get refs from cache
860 foreach ($GLOBALS['cache_array']['refsystem']['userid'] as $id => $userid) {
861 // Do we have a ref for this user?
862 //* DEBUG: */ debugOutput('id='.$id.',userid='.$userid.',userid='.$userid.',old='.$old.',level='.$GLOBALS['cache_array']['refsystem']['level'][$id]);
863 if (($currUserid == $userid) && ($GLOBALS['cache_array']['refsystem']['level'][$id] == 1)) {
864 //* DEBUG: */ debugOutput('userid matches!');
865 foreach ($GLOBALS['cache_array']['refdepths']['level'] as $level) {
866 if (($level == $GLOBALS['cache_array']['refsystem']['level'][$id]) && ($level == 1)) {
867 // Level does exist so abort here
868 $count = $GLOBALS['cache_array']['refsystem']['counter'][$id];
869 //* DEBUG: */ debugOutput('*'.$userid.'/'.$count.'*');
871 } elseif ($level > 1) {
872 // Not interesting here...
878 if ($count > 0) break;
882 //* DEBUG: */ debugOutput('<pre>'.print_r($GLOBALS['cache_array']['refsystem'], true).'</pre>');
883 //* DEBUG: */ shutdown();
887 incrementStatsEntry('cache_hits');
890 //* DEBUG: */ debugOutput('+'.$count.'/'.$old.'+');
894 // Load current refs from database
895 $result_ref = SQL_QUERY_ESC("SELECT
896 SUM(s.counter) AS cnt
898 `{?_MYSQL_PREFIX?}_refsystem` AS s
900 `{?_MYSQL_PREFIX?}_refdepths` AS d
908 ), __FUNCTION__, __LINE__);
910 // Load count @TODO Can't we rewrite this to our API?
911 list($count) = SQL_FETCHROW($result_ref);
914 SQL_FREERESULT($result_ref);
923 //* DEBUG: */ debugOutput('*'.$userid.'/'.$old.'/'.$count.'*');
927 // Determines the right language string for min_users
928 function determineReferalRallyeMinimumUsers ($min_users) {
929 // Rallye ends without user limitation is the default
930 $return = '{--RALLYE_END_NO_USER_LIMITATION--}';
932 if ($min_users > 0) {
933 // Rallye ends when X members are totally in your exchange
934 $return = getMaskedMessage('RALLYE_END_USERS', $min_users);
941 // Determines the right language string for min_prices
942 function determineReferalRallyeMinimumPrices ($min_prices) {
943 // Rallye ends without user limitation is the default
944 $return = '{--RALLYE_END_NO_PRICE_LIMITATION--}';
946 if ($min_prices > 0) {
947 // Rallye ends when X members are totally in your exchange
948 $return = getMaskedMessage('RALLYE_END_PRICES', $min_prices);