]> git.mxchange.org Git - mailer.git/blobdiff - inc/libs/refback_functions.php
More rewrites/templates swapped out:
[mailer.git] / inc / libs / refback_functions.php
index 78ad023fc754457c85db26969d3f8f7fa2a9819a..dcd553bf1724a546d801a1ae7ec7dfc672f689ec 100644 (file)
@@ -18,6 +18,7 @@
  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
+ * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
  * For more information visit: http://www.mxchange.org                  *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
@@ -51,7 +52,7 @@ function addRefbackPoints ($userid, $ref, $points, $ref_points) {
        $return = $points;
 
        // Get all ref levels
-       $result_refs = SQL_QUERY("SELECT `level`, `percents` FROM `{?_MYSQL_PREFIX?}_refdepths` WHERE `level` > 0 ORDER BY `level` ASC",
+       $result_refs = SQL_QUERY('SELECT `level`, `percents` FROM `{?_MYSQL_PREFIX?}_refdepths` WHERE `level` > 0 ORDER BY `level` ASC',
                __FUNCTION__, __LINE__);
 
        // "Walk" through all level
@@ -113,30 +114,33 @@ function getRefbackPercents ($userid, $ref) {
        // Skip identical ids
        if ($userid == $ref) return 0;
 
-       // Default is zero
-       $percents = '0';
-
-       // Get percents from database
-       $result = SQL_QUERY_ESC("SELECT refback FROM `{?_MYSQL_PREFIX?}_user_refs` WHERE `userid`=%s AND `refid`=%s LIMIT 1",
-       array($ref, $userid), __FUNCTION__, __LINE__);
-
-       // Entry found? (Should be!)
-       if (SQL_NUMROWS($result) == 1) {
-               // Fetch percents
-               list($percents) = SQL_FETCHROW($result);
-               //* DEBUG: */ print(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>):percents={$percents}<br />");
-       } else {
-               // Debug log
-               //* DEBUG: */ print(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>): NO ENTRY FOUND! :-(<br />");
-               logDebugMessage(__FUNCTION__, __LINE__, "userid={$userid},ref={$ref} - No entry found! :-(");
-       }
-
-       // Free result
-       SQL_FREERESULT($result);
+       // Is it cached?
+       if (!isset($GLOBALS['refback_percents'][$userid][$ref])) {
+               // Default is zero
+               $GLOBALS['refback_percents'][$userid][$ref] = '0';
+
+               // Get percents from database
+               $result = SQL_QUERY_ESC("SELECT `refback` FROM `{?_MYSQL_PREFIX?}_user_refs` WHERE `userid`=%s AND `refid`=%s LIMIT 1",
+                       array($ref, $userid), __FUNCTION__, __LINE__);
+
+               // Entry found? (Should be!)
+               if (SQL_NUMROWS($result) == 1) {
+                       // Fetch percents
+                       list($GLOBALS['refback_percents'][$userid][$ref]) = SQL_FETCHROW($result);
+                       //* DEBUG: */ print(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>):percents=".$GLOBALS['refback_percents'][$userid][$ref]."<br />");
+               } else {
+                       // Debug log
+                       //* DEBUG: */ print(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>): NO ENTRY FOUND! :-(<br />");
+                       logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ' - No entry found! :-(');
+               }
+
+               // Free result
+               SQL_FREERESULT($result);
+       } // END - if
 
        // Return percents
        //* DEBUG: */ print("</li></ul>----------------------- <font color=\"#aa0000\">".__FUNCTION__." - EXIT</font> ------------------------<br />");
-       return $percents;
+       return $GLOBALS['refback_percents'][$userid][$ref];
 }
 
 // "Getter" for userid array which will return only one entry
@@ -217,7 +221,7 @@ function updateRefbackTable ($userid) {
 
                                // Do we have no entry?
                                //* DEBUG: */ print(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>):userid={$userid},level={$GLOBALS['refback_level']},ref={$GLOBALS['refback_refid'][$GLOBALS['refback_level']]},minus={$minus},numRows=".SQL_NUMROWS($result)." - FOUND!<br />");
-                               if (SQL_NUMROWS($result) == '0') {
+                               if (SQL_HASZERONUMS($result)) {
                                        // Insert this level
                                        //* DEBUG: */ print(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>):userid={$userid},level={$GLOBALS['refback_level']},ref={$GLOBALS['refback_refid'][$GLOBALS['refback_level']]} - ADD!<br />");
                                        SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_refs` (`userid`,`level`,`refid`) VALUES (%s,%s,%s)",
@@ -238,7 +242,7 @@ function updateRefbackTable ($userid) {
 
                                        // Do we have no entry?
                                        //* DEBUG: */ print(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>):userid={$userid},level=".($GLOBALS['refback_level']-$minus).",ref={$GLOBALS['refback_refid'][$GLOBALS['refback_level']]},numRows=".SQL_NUMROWS($result)." - BACK!<br />");
-                                       if (SQL_NUMROWS($result) == '0') {
+                                       if (SQL_HASZERONUMS($result)) {
                                                // Insert this level
                                                SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_refs` (`userid`,`level`,`refid`) VALUES (%s,%s,%s)",
                                                        array(bigintval($userid), ($GLOBALS['refback_level']-$minus), bigintval($GLOBALS['refback_refid'][$GLOBALS['refback_level']])), __FUNCTION__, __LINE__);
@@ -372,7 +376,7 @@ function updateMemberRefbackPercents ($id, $percents) {
        $dummy = getArrayFromUserRefbackData($id);
 
        // Is this valid?
-       if (count($dummy) == '0') {
+       if (count($dummy) == 0) {
                // id does not belong to user!
                $status['message'] = getMessage('MEMBER_REFBACK_ERROR_ID_MISMATCH');
                return $status;
@@ -393,21 +397,16 @@ function updateMemberRefbackPercents ($id, $percents) {
        } // END - if
 
        // Prepare email content
-       $content = array(
-               'percents' => translateComma($percents),
-               'refid'    => $dummy['refid'],
-               'level'    => $dummy['level'],
-               'points'   => translateComma($dummy['points']),
-       );
+       $dummy['percents'] = $percents;
 
        // Load member email template
-       $mail = loadEmailTemplate('member_refback', $content, $dummy['refid']);
+       $mail = loadEmailTemplate('member_refback', $dummy, $dummy['refid']);
 
        // Send email to user
        sendEmail($dummy['refid'], getMessage('MEMBER_REFBACK_SUBJECT'), $mail);
 
        // Send admin notification
-       sendAdminNotification(getMessage('ADMIN_REFBACK_SUBJECT'), 'admin_refback', $content, getMemberId());
+       sendAdminNotification(getMessage('ADMIN_REFBACK_SUBJECT'), 'admin_refback', $dummy, getMemberId());
 
        // All fine!
        $status['ok'] = true;
@@ -416,5 +415,6 @@ function updateMemberRefbackPercents ($id, $percents) {
        //* DEBUG: */ print("</li></ul>----------------------- <font color=\"#aa0000\">".__FUNCTION__." - EXIT</font> ------------------------<br />");
        return $status;
 }
-//
+
+// [EOF]
 ?>