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 - 2012 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 $content = SQL_FETCHARRAY($result);
49 SQL_FREERESULT($result);
53 `{?_MYSQL_PREFIX?}_rallye_data`
59 array(bigintval($content['id'])), __FUNCTION__, __LINE__);
62 $result_user = SQL_QUERY("SELECT
65 `{?_MYSQL_PREFIX?}_user_data`
68 " . runFilterChain('user_exclusion_sql', ' ') . "
70 `userid` ASC", __FUNCTION__, __LINE__);
72 // Let's begin with the userids...
73 while ($row = SQL_FETCHARRAY($result_user)) {
75 $content = merge_array($content, $row);
80 $count = getReferralRallyeRefsCount($content['userid']);
81 if (empty($count)) $count = '0'; // Added prevent some unknown troubles... :-?
83 // Check if line is already included...
84 $result_ref = SQL_QUERY_ESC("SELECT
87 `{?_MYSQL_PREFIX?}_rallye_users`
92 array(bigintval($content['id']), bigintval($content['userid'])), __FUNCTION__, __LINE__);
95 if (SQL_HASZERONUMS($result_ref)) {
96 // Add userid and his ref count to table
97 $result_ref = SQL_QUERY_ESC("SELECT
98 SUM(`p`.`points`) AS `points`
100 `{?_MYSQL_PREFIX?}_user_points` AS `p`
102 `{?_MYSQL_PREFIX?}_user_data` AS `d`
106 `d`.`status`='CONFIRMED'
107 " . runFilterChain('user_exclusion_sql', ' ') . " AND
108 `d`.`max_mails` > 0 AND
109 `d`.`mails_confirmed` >= {?ref_payout?} AND
110 `p`.`ref_depth`=1 AND
113 array(bigintval($content['userid'])), __FUNCTION__, __LINE__);
116 list($cpoints) = SQL_FETCHROW($result_ref);
119 SQL_FREERESULT($result_ref);
121 if (empty($cpoints)) $cpoints = '0.00000';
124 SQL_QUERY_ESC("INSERT INTO
125 `{?_MYSQL_PREFIX?}_rallye_users`
138 bigintval($content['id']),
139 bigintval($content['userid']),
142 ), __FUNCTION__, __LINE__);
147 SQL_FREERESULT($result_ref);
149 // Ignored but for the template required refs (made before start of rallye)
150 $content['refs'] = $count;
152 // Shall I notify this member?
153 if (($content['send_notify'] == 'Y') && ($un === TRUE)) {
154 // Load email template and send it to the user
155 $message = loadEmailTemplate('member_rallye_notify', $content, $content['userid']);
156 sendEmail($content['userid'], '{%message,MEMBER_RALLYE_NOTIFY_SUBJECT=' . $content['title'] . '%}', $message);
160 // Choose the right admin template
161 $templ = 'admin_rallye_no_notify';
162 if ($content['send_notify'] == 'Y') {
163 $templ = 'admin_rallye_notify';
166 // Send email to admin
167 sendAdminNotification('{%message,ADMIN_RALLYE_NOTIFY_SUBJECT=' . $content['title'] . '%}', $templ, $content);
170 SQL_FREERESULT($result_user);
174 function addReferralRallyePrices ($rallye, $mode = 'email') {
177 case 'email': $mode = PHP_EOL; break;
178 case 'html' : $mode = '<br />'; break;
182 $result_prices = SQL_QUERY_ESC("SELECT
187 `{?_MYSQL_PREFIX?}_rallye_prices`
192 array($rallye), __FUNCTION__, __LINE__);
195 if (!SQL_HASZERONUMS($result_prices)) {
198 if ($mode == PHP_EOL) {
199 $prices = '{--RALLYE_MEMBER_PRICES_ADDED--}:' . $mode . '------------------------------' . $mode;
202 while ($content = SQL_FETCHARRAY($result_prices)) {
203 $prices .= $content['price_level']. '{--RALLYE_PRICE--}:';
204 if (!empty($content['info'])) {
205 $prices .= $content['info'];
207 $prices .= '{%pipe,translateComma=' . $content['points'] . '%} {?POINTS?}';
209 $prices .= '' . $mode;
213 SQL_FREERESULT($result_prices);
216 $prices = '{%message,RALLYE_MEMBER_NO_PRICES=' . $mode . '%}';
219 // Add last line for email mode
220 if ($mode == PHP_EOL) {
221 $prices .= '------------------------------';
229 function addReferralRallyeTopUsers ($mode, $rallye, $default=0) {
234 // First check how many prices are set
235 $prices = getTotalRallyePrices($rallye);
237 // And load only limited users
238 $result = SQL_QUERY_ESC("SELECT DISTINCT
245 `{?_MYSQL_PREFIX?}_rallye_users` AS `u`
247 `{?_MYSQL_PREFIX?}_refsystem` AS `r`
251 `{?_MYSQL_PREFIX?}_rallye_data` AS `rd`
253 `u`.`rallye_id`=r`d`.`id`
255 `u`.`rallye_id`=%s AND
259 array(bigintval($rallye)), __FUNCTION__, __LINE__);
269 while ($row = SQL_FETCHARRAY($result)) {
270 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $row['userid'] . ',refs=' . $row['refs']);
272 $count = getReferralRallyeRefsCount($row['userid'], $row['refs']);
275 $result_ref = SQL_QUERY_ESC("SELECT
278 `{?_MYSQL_PREFIX?}_user_points` AS `p`
280 `{?_MYSQL_PREFIX?}_user_data` AS `d`
282 `p`.`userid`=`d`.`userid`
285 `d`.`status`='CONFIRMED'
286 " . runFilterChain('user_exclusion_sql', ' ') . " AND
287 `p`.`ref_depth`=1 AND
288 `d`.`max_mails` > 0 AND
289 `d`.`mails_confirmed` >= {?ref_payout?}
291 array(bigintval($row['userid'])), __FUNCTION__, __LINE__);
294 list($refpoints) = SQL_FETCHROW($result_ref);
297 SQL_FREERESULT($result_ref);
299 // Fix empty values (ugly code again)
300 if (empty($refpoints)) {
304 // Init userid for list
307 // List only users with at least one ref!
308 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'count=' . $count . ',userid=' . $userid . ',refpoints=' . $refpoints . ',curr_points=' . $row['curr_points']);
309 if (($count > 0) && ($refpoints > $row['curr_points'])) {
310 $userid = $row['userid'];
315 // Save values to array
316 $content['userid'][] = $userid;
317 $content['ref'][] = $count;
318 $content['cpoints'][] = $row['curr_points'];
319 $min_users = $row['min_users'];
320 $min_prices = $row['min_prices'];
324 SQL_FREERESULT($result);
327 array_pk_sort($content, array('cpoints', 'ref'), 0, 1, TRUE);
331 for ($idx = 0; $idx < $prices; $idx++) {
332 // Prepare marking of default (maybe current user's) id
333 $start = ''; $end = '';
334 if (($default > 0) && (isset($content['userid'][$idx])) && ($content['userid'][$idx] == $default)) {
344 'userid' => (isset($content['userid'][$idx])) ? $content['userid'][$idx] : '---',
345 'ref' => (isset($content['ref'][$idx])) ? $content['ref'][$idx] : '---'
348 // Load row template and switch color
349 $OUT .= loadTemplate($mode . '_list_rallye_row', TRUE, $row);
352 // Add min_prices/users
353 $content['rows'] = $OUT;
354 $content['min_prices'] = bigintval($min_prices);
355 $content['min_users'] = bigintval($min_users);
357 // And finnally return the output
358 return loadTemplate($mode . '_list_rallye', TRUE, $content);
361 // Sends out a notification about the rallye
362 function sendRallyeNotification ($userid, $content) {
363 // Translate more data
364 $content['start_time'] = generateDateTime($content['start_time'], 2);
365 $content['end_time'] = generateDateTime($content['end_time'] , 2);
366 $content['now_time'] = generateDateTime(time(), 2);
367 $content['ref'] = '0';
368 $content['refs'] = getUsersTotalReferrals($userid);
370 // Send notification to member
371 $message = loadEmailTemplate('member_rallye_notify', $content, $userid);
372 sendEmail($userid, '{%message,MEMBER_RALLYE_NOTIFY_SUBJECT=' . $content['title'] . '%}', $message);
375 // Run this function only when a new member has confirmed his email address!
376 function addUserToReferralRallye ($userid, $content = array()) {
379 // Updated extension?
380 if (isExtensionInstalledAndNewer('rallye', '0.2.0')) {
381 $add .= ',`min_users`, `min_prices`';
384 // Check for an auto-add rallye
385 $result = SQL_QUERY("SELECT
393 `{?_MYSQL_PREFIX?}_rallye_data`
397 `auto_add_new_user`='Y' AND
399 LIMIT 1", __FUNCTION__, __LINE__);
400 if (SQL_NUMROWS($result) == 1) {
405 // Load and merge data
406 $content = merge_array($content, SQL_FETCHARRAY($result));
409 SQL_FREERESULT($result);
412 if ($content['send_notify'] == 'Y') {
413 // Transfer all neccessary data to $content array
414 sendRallyeNotification($userid, $content);
417 // Check if line is already included...
418 $result = SQL_QUERY_ESC("SELECT
421 `{?_MYSQL_PREFIX?}_rallye_users`
427 bigintval($content['id']),
429 ), __FUNCTION__, __LINE__);
431 // Is this user added?
432 if (SQL_HASZERONUMS($result)) {
433 // Add userid and his ref count to table
434 SQL_QUERY_ESC("INSERT INTO
435 `{?_MYSQL_PREFIX?}_rallye_users`
446 bigintval($content['id']),
448 ), __FUNCTION__, __LINE__);
452 SQL_FREERESULT($result);
456 // "Getter" for total rallye winners
457 function getTotalRallyeWinners ($rallyeId) {
459 if (!isset($GLOBALS[__FUNCTION__][$rallyeId])) {
460 // Default total is zero
461 $GLOBALS[__FUNCTION__][$rallyeId] = '0';
464 $prices = getArrayFromReferralRallyeUsers($rallyeId);
466 // "Walk" through all entries
467 foreach ($prices['userid'] as $key => $userid) {
469 $active = countSumTotalData($userid, 'user_data', 'userid', 'userid', TRUE, runFilterChain('user_exclusion_sql', " AND `status`='CONFIRMED'"));
471 // Allow valid and active users with at least one ref
472 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'rallyeId=' . $rallyeId . ',userid=' . $userid . ',ref=' . $prices['ref'][$key] . ',cpoints=' . $prices['cpoints'][$key]);
473 if ((isValidId($userid)) && ($prices['ref'][$key] > 0) && ($active == 1) && ($prices['cpoints'][$key] > 0)) {
474 $GLOBALS[__FUNCTION__][$rallyeId]++;
480 return $GLOBALS[__FUNCTION__][$rallyeId];
483 // Stops the given rallye result (from SQL layer) by marking it as expirced
484 function stopRallyeByResult ($result) {
486 $content = SQL_FETCHARRAY($result);
489 SQL_FREERESULT($result);
494 $content['start_time'] = generateDateTime($content['start_time'], 1);
495 $content['end_time'] = generateDateTime($content['end_time'] , 1);
496 $content['now_time'] = generateDateTime(time(), 1);
498 // Load users array (!) with assigned prices
499 $prices = getArrayFromReferralRallyeUsers($content['id']);
503 foreach ($prices['userid'] as $key => $userid) {
506 * active = 1: account is still confirmed
507 * active = 0: account is deleted or locked
509 $active = countSumTotalData($userid, 'user_data', 'userid', 'userid', TRUE, runFilterChain('user_exclusion_sql', " AND `status`='CONFIRMED'"));
511 $prices['active'][$key] = $active;
513 // Allow valid and active users with at least one ref to get points
514 if ((isValidId($userid)) && ($prices['ref'][$key] > 0) && ($active == 1) && ($prices['cpoints'][$key] > 0)) {
519 // Check on 'min_prices' condition
520 if (($total < $content['min_prices']) || (getTotalConfirmedUser() < $content['min_users'])) {
521 // Do not end this rallye!
526 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET `expired`='Y' WHERE `id`=%s LIMIT 1",
527 array(bigintval($content['id'])), __FUNCTION__, __LINE__);
529 // Run array through (by userid is the most important 2nd-level-array)
530 foreach ($prices['userid'] as $key => $userid) {
531 // Allow valid and active users with at least one ref to get points
532 if ((isValidId($userid)) && ($prices['ref'][$key] > 0) && ($prices['active'][$key] == 1) && ($prices['cpoints'][$key] > 0)) {
533 // Transfer data to array for the mail template
534 $content['level'] = $prices['level'][$key];
535 $content['points'] = $prices['points'][$key];
536 $content['info'] = $prices['info'][$key];
537 $content['ref'] = $prices['ref'][$key];
540 $winnerLevel = 'other';
542 // Determine winner level
543 if ($content['level'] == 1) {
545 $winnerLevel = 'gold';
546 } elseif ($content['level'] == 2) {
548 $winnerLevel = 'silver';
549 } elseif ($content['level'] == 3) {
551 $winnerLevel = 'bronce';
554 if ($content['points'] > 0) {
555 // Add points directly to user's account
556 initReferralSystem();
557 addPointsThroughReferralSystem('rallye_winner:' . $winnerLevel, $userid, $content['points']);
560 if ($content['send_notify'] == 'Y') {
561 // Prepare infos for the mail template
562 if (!empty($content['info'])) {
564 $content['infos'] = $content['info'];
567 $content['infos'] = $content['points'] . ' {?POINTS?}';
570 // Add suffix to template name
571 $template = 'member_rallye_expired_' . $winnerLevel;
574 $message = loadEmailTemplate($template, $content, $userid);
575 sendEmail($userid, '{%message,RALLYE_MEMBER_EXPIRED_SUBJECT=' . $content['level'] . '%}', $message);
580 $users['userid'][$userid] = $userid;
581 $users['poi'][$userid] = $content['infos'];
585 // Select template depending on notfication is switch on / off
586 if ($content['send_notify'] == 'Y') {
587 $templ = 'admin_rallye_expired';
588 } elseif (is_array($users['userid'])) {
589 $templ = 'admin_rallye_expired_no';
590 $count = getReferralRallyeUserDataFromArray($users);
594 $content['count'] = $count;
596 // Send mail to admin
597 sendAdminNotification('{%message,ADMIN_RALLYE_EXPIRED_SUBJECT=' . $content['title'] . '%}', $templ, $content);
599 // Add task (we ignore the task id here)
600 createNewTask('{--ADMIN_RALLYE_EXPIRED_TASK--}: ' . $content['title'], '{--ADMIN_RALLYE_EXPIRED_TEXT--}', 'RALLYE_EXPIRED');
604 function getReferralRallyeUserDataFromArray ($userIds) {
606 $userid_string = implode(',', $userIds['userid']);
608 // Init result string
612 $result = SQL_QUERY_ESC("SELECT
613 `userid`, `gender`, `surname`, `family`, `email`
615 `{?_MYSQL_PREFIX?}_user_data`
619 " . runFilterChain('user_exclusion_sql', ' ' ) . "
626 ), __FUNCTION__, __LINE__);
627 while ($content = SQL_FETCHARRAY($result)) {
628 // Construct the message masked and add it
629 $ret .= sprintf("{%%pipe,translateGender=%s%} %s %s (%s) - %s\n",
634 $userIds['poi'][$content['userid']]
639 return substr($ret, 0, -1);
643 function getArrayFromReferralRallyePrices ($rallye) {
652 $result = SQL_QUERY_ESC("SELECT
657 `{?_MYSQL_PREFIX?}_rallye_prices`
662 array(bigintval($rallye)), __FUNCTION__, __LINE__);
665 while ($content = SQL_FETCHARRAY($result)) {
666 $prices['level'][] = $content['price_level'];
667 array_push($prices['points'], $content['points']);
668 array_push($prices['info'], $content['info']);
672 SQL_FREERESULT($result);
679 function getArrayFromReferralRallyeUsers ($rallye) {
680 // Fix zero points to 0.00000
681 if (getRefPayout() == '0') {
682 setConfigEntry('ref_payout', '0.00000');
689 'cpoints' => array(),
694 * - userid = User's id number
695 * - refs = Old amount of referrals (before the rallye has started)
696 * - curr_points = Current amount of total points
698 $result_user = SQL_QUERY_ESC("SELECT
703 `{?_MYSQL_PREFIX?}_rallye_users`
708 array(bigintval($rallye)), __FUNCTION__, __LINE__);
709 while ($content = SQL_FETCHARRAY($result_user)) {
710 // Load current ref count
711 $count = getReferralRallyeRefsCount($content['userid'], $content['refs']);
714 $result_ref = SQL_QUERY_ESC("SELECT
715 SUM(`p`.`points`) AS `points`
717 `{?_MYSQL_PREFIX?}_user_points` AS `p`
719 `{?_MYSQL_PREFIX?}_user_data` AS `d`
721 `p`.`userid`=`d`.`userid`
723 `d`.`status`='CONFIRMED'
724 " . runFilterChain('user_exclusion_sql', ' ' ) . " AND
725 `d`.`max_mails` > 0 AND
726 `d`.`mails_confirmed` >= {?ref_payout?} AND
727 `p`.`ref_depth`=1 AND
731 array(bigintval($content['userid'])), __FUNCTION__, __LINE__);
734 list($refpoints) = SQL_FETCHROW($result_ref);
737 SQL_FREERESULT($result_ref);
739 // Fix empty refpoints
740 if (empty($refpoints)) $refpoints = '0';
742 // Store calculated new refs to array
743 array_push($users['userid'], $content['userid']);
744 array_push($users['ref'], abs($count - $content['refs']));
745 array_push($users['cpoints'], $refpoints - $content['curr_points']);
749 SQL_FREERESULT($result_user);
751 // Sort array for refs (descending)
752 array_pk_sort($users, array('cpoints', 'ref'), 0, 1, TRUE);
754 // Load prices array (!)
755 $prices = getArrayFromReferralRallyePrices($rallye);
757 // Merge users into prices
758 foreach ($prices['level'] as $k => $level) {
759 // We only need to check one element in $users, see above while() block
760 if (isset($users['userid'][$k])) {
761 $prices['userid'][$k] = $users['userid'][$k];
762 $prices['ref'][$k] = $users['ref'][$k];
763 $prices['cpoints'][$k] = $users['cpoints'][$k];
767 // Return completed array
771 // @TODO This function does not load min_users, min_prices, please encapsulate loading rallye data with e.g. getRallyeDataFromId()
772 function addReferralRallyeWinners ($mode, $rallye, $default=0) {
773 // First check how many prices are set
774 $prices = getTotalRallyePrices($rallye);
777 $content = getArrayFromReferralRallyeUsers($rallye);
781 for ($idx = 0; $idx < $prices; $idx++) {
784 * active = 1: account is still confirmed
785 * active = 0: account is deleted or locked
787 $active = countSumTotalData($content['userid'][$idx], 'user_data', 'userid', 'userid', TRUE, runFilterChain('user_exclusion_sql', " AND `status`='CONFIRMED'"));
789 if ((empty($content['ref'][$idx])) || ($content['ref'][$idx] == '0') || ($active == '0') || ('' . round($content['cpoints'][$idx]) . '' == '0') || (empty($content['cpoints'][$idx]))) {
790 // Allow valid and active users with at least one ref to get points
791 $content['ref'][$idx] = '---';
792 $content['userid'][$idx] = '---';
795 if (!empty($content['info'][$idx])) {
797 $content['infos'][$idx] = $content['info'][$idx];
800 $content['infos'][$idx] = $content['points'][$idx] . ' {?POINTS?}';
803 // Prepare marking of default (maybe current user's) id
804 $start = ''; $end = '';
805 if (($content['userid'][$idx] == $default) && ($default > 0)) {
813 'userid' => $content['userid'][$idx],
814 'ref' => $content['ref'][$idx],
815 'infos' => $content['infos'][$idx],
821 $OUT .= loadTemplate($mode . '_list_rallye_row', TRUE, $row);
827 'min_users' => '???',
828 'min_prices' => '???'
831 // Load main template and finnally return the output
832 return loadTemplate($mode . '_list_rallye', TRUE, $content);
836 function purgeExpiredReferralRallyes () {
837 // Check for expired rallyes
838 $EXPIRE = 3; // @TODO The hard-coded value...
839 $result_rallye = SQL_QUERY_ESC("SELECT
845 `{?_MYSQL_PREFIX?}_rallye_data`
847 (UNIX_TIMESTAMP() - `end_time`) > ({?ONE_DAY?} * %s) AND
849 array($EXPIRE), __FUNCTION__, __LINE__);
851 if (!SQL_HASZERONUMS($result_rallye)) {
855 // Expire found rallyes and notify admin
856 while ($content = SQL_FETCHARRAY($result_rallye)) {
857 // Prepare data for mail template
858 $content['start_time'] = generateDateTime($content['start_time'], 1);
859 $content['end_time'] = generateDateTime($content['end_time'] , 1);
860 $content['now_time'] = generateDateTime(time(), 1);
862 // Send mail to admin
863 sendAdminNotification('{%message,ADMIN_RALLYE_PURGED_SUBJECT=' . $content['title'] . '%}', 'admin_rallye_purged', $content);
865 // Purge whole rallye
866 addSql(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_rallye_data` WHERE `id`=%s LIMIT 1",
867 array(bigintval($content['id'])), __FUNCTION__, __LINE__, FALSE));
868 addSql(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `rallye_id`=%s LIMIT 1",
869 array(bigintval($content['id'])), __FUNCTION__, __LINE__, FALSE));
870 addSql(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_rallye_users` WHERE `rallye_id`=%s LIMIT 1",
871 array(bigintval($content['id'])), __FUNCTION__, __LINE__, FALSE));
873 // Add task (we ignore the task id here
874 createNewTask('{--ADMIN_RALLYE_PURGED_TASK--}: ' . $content['title'], '{--ADMIN_RALLYE_PURGED_TEXT--}', 'RALLYE_PURGED');
878 runFilterChain('run_sqls');
882 SQL_FREERESULT($result_rallye);
886 function addReferralRallyeTemplateSelection ($name = 'template', $default = '') {
891 // Check templates directory
892 $basePath = sprintf("templates/%s/html/rallye/", getLanguage());
894 // Read the directory
895 $templates = getArrayFromDirectory($basePath, 'rallye_', FALSE, TRUE, array(), '.tpl');
898 foreach ($templates as $read) {
899 // Cut prefix and extension away
900 $read = substr($read, 7, strpos($read, '.') - 7);
902 // Accept only template names between 1 and 255 chars length
903 if ((strlen($read) < 256) && (!empty($read))) {
908 logDebugMessage(__FUNCTION__, __LINE__, sprintf("WARNING: Template %s not used.", $read));
912 // Is there found templates which we can link with the new rallye?
913 if (!empty($ral[0])) {
914 // Generate selection box for all found templates
915 $OUT = '<select class="form_select" name="' . $name . '" size="1">';
916 $OUT .= generateOptions('/ARRAY/', array_keys($ral), array_values($ral), $default, '', 'none');
919 // No rallye templates found
920 $OUT = '{--ADMIN_RALLYE_TEMPLATES_404--}';
927 // @TODO Please document this function
928 function getReferralRallyeRefsCount ($currUserid, $oldReferralCount = '0') {
929 // Check current refs
930 if (isExtensionInstalledAndNewer('cache', '0.1.2')) {
931 // Get refs from cache
933 foreach ($GLOBALS['cache_array']['refsystem']['userid'] as $id => $userid) {
934 // Is there a ref for this user?
935 //* DEBUG: */ debugOutput('id='.$id.',userid='.$userid.',userid='.$userid.',oldReferralCount='.$oldReferralCount.',level='.$GLOBALS['cache_array']['refsystem']['level'][$id]);
936 if (($currUserid == $userid) && ($GLOBALS['cache_array']['refsystem']['level'][$id] == 1)) {
937 //* DEBUG: */ debugOutput('userid matches!');
938 foreach ($GLOBALS['cache_array']['refdepths']['level'] as $level) {
939 if (($level == $GLOBALS['cache_array']['refsystem']['level'][$id]) && ($level == 1)) {
940 // Level does exist so abort here
941 $count = $GLOBALS['cache_array']['refsystem']['counter'][$id];
942 //* DEBUG: */ debugOutput('*'.$userid.'/'.$count.'*');
944 } elseif ($level > 1) {
945 // Not interesting here...
951 if ($count > 0) break;
955 //* DEBUG: */ debugOutput('<pre>'.print_r($GLOBALS['cache_array']['refsystem'], TRUE).'</pre>');
956 //* DEBUG: */ doShutdown();
960 incrementStatsEntry('cache_hits');
963 //* DEBUG: */ debugOutput('+'.$count.'/'.$oldReferralCount.'+');
964 $count -= $oldReferralCount;
967 // Load current refs from database
968 $result_ref = SQL_QUERY_ESC("SELECT
969 SUM(s.counter) AS `cnt`
971 `{?_MYSQL_PREFIX?}_refsystem` AS `s`
973 `{?_MYSQL_PREFIX?}_refdepths` AS `d`
975 s.`level`=`d`.`level`
981 ), __FUNCTION__, __LINE__);
983 // Load count @TODO Can't we rewrite this to our API?
984 list($count) = SQL_FETCHROW($result_ref);
987 SQL_FREERESULT($result_ref);
991 $count -= $oldReferralCount;
996 //* DEBUG: */ debugOutput('*'.$userid.'/'.$oldReferralCount.'/'.$count.'*');
1000 // Determines the right language string for min_users
1001 function determineReferralRallyeMinimumUsers ($min_users) {
1002 // Rallye ends without user limitation is the default
1003 $return = '{--RALLYE_END_NO_USER_LIMITATION--}';
1005 if ($min_users > 0) {
1006 // Rallye ends when X members are totally in your exchange
1007 $return = '{%message,RALLYE_END_USERS=' . $min_users . '%}';
1014 // Determines the right language string for min_prices
1015 function determineReferralRallyeMinimumPrices ($min_prices) {
1016 // Rallye ends without user limitation is the default
1017 $return = '{--RALLYE_END_NO_PRICE_LIMITATION--}';
1019 if ($min_prices > 0) {
1020 // Rallye ends when X members are totally in your exchange
1021 $return = '{%message,RALLYE_END_PRICES=' . $min_prices . '%}';
1028 // "Getter" for total rallye prices by given id
1029 function getTotalRallyePrices ($rallyeId) {
1031 if (!isset($GLOBALS[__FUNCTION__][$rallyeId])) {
1033 $GLOBALS[__FUNCTION__][$rallyeId] = countSumTotalData($rallyeId, 'rallye_prices', 'id', 'rallye_id', TRUE);
1037 return $GLOBALS[__FUNCTION__][$rallyeId];