- return $ret;
-}
-//
-function GET_PAY_POINTS($pid, $lookFor="price")
-{
- $ret = "-1";
- $result = SQL_QUERY_ESC("SELECT %s FROM "._MYSQL_PREFIX."_payments WHERE id=%s LIMIT 1",
- array($lookFor, $pid), __FILE__, __LINE__);
- if (SQL_NUMROWS($result) == 1)
- {
- // Payment type found... :-)
- list($ret) = SQL_FETCHROW($result);
- SQL_FREERESULT($result);
- }
- return $ret;
-}
-// Remove a receiver's ID from $ARRAY and add a link for him to confirm
-function REMOVE_RECEIVER(&$ARRAY, $key, $uid, $pool_id, $stats_id="", $bonus=false)
-{
- $ret = "failed";
- if ($uid > 0)
- {
- // Remove entry from array
- unset($ARRAY[$key]);
-
- // Is there already a line for this user available?
- if ($stats_id > 0)
- {
- // Only when we got a real stats ID continue searching for the entry
- $type = "NORMAL"; $rowName = "stats_id";
- if ($bonus) { $type = "BONUS"; $rowName = "bonus_id"; }
- $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_user_links WHERE %s='%s' AND userid=%s AND link_type='%s' LIMIT 1",
- array($rowName, $stats_id, bigintval($uid), $type), __FILE__, __LINE__);
- if (SQL_NUMROWS($result) == 0)
- {
- // No, so we add one!
- $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_user_links (%s, userid, link_type) VALUES ('%s','%s','%s')",
- array($rowName, $stats_id, bigintval($uid), $type), __FILE__, __LINE__);
- $ret = "done";
- }
- else
- {
- // Already found
- $ret = "already";
- }
-
- // Free memory
- SQL_FREERESULT($result);
- }
- }
- // Return status for sending routine
- return $ret;
-}
-//
-function GET_TOTAL_DATA($search, $tableName, $lookFor, $whereStatement="userid", $onlyRows=false, $add="") {
- $ret = 0;
- if ($onlyRows) {
- // Count rows
- $result = SQL_QUERY_ESC("SELECT COUNT(%s) FROM "._MYSQL_PREFIX."_%s WHERE %s='%s'%s",
- array($lookFor, $tableName, $whereStatement, $search, $add), __FILE__, __LINE__);
- } else {
- // Add all rows
- $result = SQL_QUERY_ESC("SELECT SUM(%s) FROM "._MYSQL_PREFIX."_%s WHERE %s='%s'%s",
- array($lookFor, $tableName, $whereStatement, $search, $add), __FILE__, __LINE__);
- }
-
- // Load row
- list($ret) = SQL_FETCHROW($result);
-
- // Free result
- SQL_FREERESULT($result);
-
- // Fix empty values
- if ((empty($ret)) && ($lookFor != "counter") && ($lookFor != "id") && ($lookFor != "userid")) {
- $ret = "0.00000";
- } // END - if
-
- // Return value
- return $ret;
-}
-// "Getter fro ref level percents
-function GET_REF_LEVEL_PERCENTS ($level) {
- global $cacheInstance, $_CONFIG, $cacheArray;
-
- // Default is zero
- $per = 0;
-
- // Do we have cache?
- if ((isset($cacheArray['ref_depths']['level'])) && (EXT_IS_ACTIVE("cache"))) {
- // First look for level
- $key = array_search($level, $cacheArray['ref_depths']['level']);
- if ($key !== false) {
- // Entry found!
- $per = $cacheArray['ref_depths']['percents'][$key];
-
- // Count cache hit
- if (isset($_CONFIG['cache_hits'])) { $_CONFIG['cache_hits']++; } else { $_CONFIG['cache_hits'] = 1; }
- }
- } else {
- // Get referal data
- $result_lvl = SQL_QUERY_ESC("SELECT percents FROM "._MYSQL_PREFIX."_refdepths WHERE level='%s' LIMIT 1",
- array(bigintval($level)), __FILE__, __LINE__);
-
- // Entry found?
- if (SQL_NUMROWS($result_lvl) == 1) {
- // Get percents
- list($per) = SQL_FETCHROW($result_lvl);
- } // END - if
-
- // Free result
- SQL_FREERESULT($result_lvl);
- }
-
- // Return percent
- return $per;
-}
-/**
- *
- * Dynamic referal system, can also send mails!
- *
- * uid = Referal ID wich should receive...
- * points = ... xxx points
- * send_notify = shall I send the referal an email or not?
- * rid = inc/modules/guest/what-confirm.php need this (DEPRECATED???)
- * locked = Shall I pay it to normal (false) or locked (true) points ammount?
- * add_mode = Add points only to $uid or also refs? (WARNING! Changing "ref" to "direct"
- * for default value will cause no referal will get points ever!!!)
- */
-function ADD_POINTS_REFSYSTEM($uid, $points, $send_notify=false, $rid="0", $locked=false, $add_mode="ref") {
- //* DEBUG: */ print "----------------------- <font color=\"#00aa00\">".__FUNCTION__." - ENTRY</font> ------------------------<ul><li>\n";
- global $DEPTH, $_CONFIG, $DATA, $cacheArray;
-
- // Convert mode to lower-case
- $add_mode = strtolower($add_mode);
-
- // When $uid = 0 add points to jackpot
- if ($uid == "0") {
- // Add points to jackpot
- ADD_JACKPOT($points);
- return;
- } // END - if
-
- // Count up referal depth
- if (!isset($DEPTH)) {
- // Initialialize referal system
- $DEPTH = 0;
- } else {
- // Increase referal level
- $DEPTH++;
- }
-
- // Default is "normal" points
- $data = "points";
-
- // Which points, locked or normal?
- if ($locked) $data = "locked_points";
-
- // Check user account
- $result_user = SQL_QUERY_ESC("SELECT refid, email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s AND status='CONFIRMED' LIMIT 1",
- array(bigintval($uid)), __FILE__, __LINE__);
-
- //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},numRows=".SQL_NUMROWS($result_user).",points={$points}<br />\n";
- if (SQL_NUMROWS($result_user) == 1) {
- // This is the user and his ref
- list($ref, $email) = SQL_FETCHROW($result_user);
- $cacheArray['add_uid'][$ref] = $uid;
-
- // Get percents
- $per = GET_REF_LEVEL_PERCENTS($DEPTH);
- //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},points={$points},depth={$DEPTH},per={$per},mode={$add_mode}<br />\n";
-
- // Some percents found?
- if ($per > 0) {
- // Calculate new points
- //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},points={$points},per={$per},depth={$DEPTH}<br />\n";
- $ref_points = $points * $per / 100;
-
- // Pay refback here if level > 0 and in ref-mode
- if ((EXT_IS_ACTIVE("refback")) && ($DEPTH > 0) && ($per < 100) && ($add_mode == "ref") && (isset($cacheArray['add_uid'][$uid]))) {
- //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},data={$cacheArray['add_uid'][$uid]},ref_points={$ref_points},depth={$DEPTH} - BEFORE!<br />\n";
- $ref_points = ADD_REFBACK_POINTS($cacheArray['add_uid'][$uid], $uid, $points, $ref_points);
- //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},data={$cacheArray['add_uid'][$uid]},ref_points={$ref_points},depth={$DEPTH} - AFTER!<br />\n";
- } // END - if
-
- // Update points...
- SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_points SET %s=%s+%s WHERE userid=%s AND ref_depth='%s' LIMIT 1",
- array($data, $data, $ref_points, bigintval($uid), bigintval($DEPTH)), __FILE__, __LINE__);
- //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):data={$data},ref_points={$ref_points},uid={$uid},depth={$DEPTH},mode={$add_mode} - UPDATE! (".SQL_AFFECTEDROWS().")<br />\n";
-
- // No entry updated?
- if (SQL_AFFECTEDROWS() < 1) {
- // First ref in this level! :-)
- $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_user_points (userid,ref_depth,%s) VALUES (%s,%s,%s)",
- array($data, bigintval($uid), bigintval($DEPTH), $ref_points), __FILE__, __LINE__);
- } // END - if
-
- // Update mediadata as well
- if (GET_EXT_VERSION("mediadata") >= "0.0.4") {
- // Update database
- MEDIA_UPDATE_ENTRY(array("total_points"), "add", $ref_points);
- } // END - if
-
- // Points updated, maybe I shall send him an email?
- if (($send_notify) && ($ref > 0) && (!$locked)) {
- // Prepare content
- $content = array(
- 'percent' => $per,
- 'level' => bigintval($DEPTH),
- 'points' => $ref_points,
- 'refid' => bigintval($ref)
- );
-
- // Load email template
- $msg = LOAD_EMAIL_TEMPLATE("confirm-referal", $content, bigintval($uid));
-
- SEND_EMAIL($email, THANX_REFERRAL_ONE, $msg);
- } elseif (($send_notify) && ($ref == 0) && (!$locked) && ($add_mode == "direct") && (!defined('__POINTS_VALUE'))) {
- // Direct payment shall be notified about
- define('__POINTS_VALUE', $ref_points);
-
- // Prepare content
- $content = array(
- 'text' => REASON_DIRECT_PAYMENT,
- 'points' => TRANSLATE_COMMA($ref_points)
- );
-
- // Load message
- $msg = LOAD_EMAIL_TEMPLATE("add-points", $content, $uid);
-
- // And sent it away
- SEND_EMAIL($email, SUBJECT_DIRECT_PAYMENT, $msg);
- if (!isset($_GET['mid'])) LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_POINTS_ADDED);
- }
-
- // Maybe there's another ref?
- if (($ref > 0) && ($points > 0) && ($ref != $uid) && ($add_mode == "ref")) {
- // Then let's credit him here...
- //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},ref={$ref},points={$points} - ADVANCE!<br />\n";
- ADD_POINTS_REFSYSTEM($ref, $points, $send_notify, $ref, $locked);
- } // END - if
- } // END - if
- } // END - if
-
- // Free result
- SQL_FREERESULT($result_user);
- //* DEBUG: */ print "</li></ul>----------------------- <font color=\"#aa0000\">".__FUNCTION__." - EXIT</font> ------------------------<br />\n";