]> git.mxchange.org Git - mailer.git/blobdiff - inc/libs/refback_functions.php
Some language strings fixed, renamed. Copyright notice updated
[mailer.git] / inc / libs / refback_functions.php
index 9278ccc5554807e2534dbfd703434e63bac77664..bb42f8f11d2d0bc649e96c1be4dbb284e4ce79ba 100644 (file)
  * $Date::                                                            $ *
  * $Tag:: 0.2.1-FINAL                                                 $ *
  * $Author::                                                          $ *
- * Needs to be in all Files and every File needs "svn propset           *
- * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
- * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
+ * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
  * For more information visit: http://www.mxchange.org                  *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
@@ -52,7 +50,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
@@ -114,36 +112,39 @@ 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
-function getArrayFromRefbackLevel ($rid, $level) {
+function getArrayFromRefbackLevel ($refid, $level) {
        //* DEBUG: */ print("----------------------- <font color=\"#00aa00\">".__FUNCTION__." - ENTRY</font> ------------------------<ul><li>\n");
-       //* DEBUG: */ print(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>):rid={$rid},level={$level}<br />");
+       //* DEBUG: */ print(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>):refid={$refid},level={$level}<br />");
        // Init userids
        $userIds = array();
 
@@ -156,14 +157,14 @@ WHERE
        `refid`=%s AND `level`=%s
 ORDER BY
        `userid` ASC",
-               array($rid, $level), __FUNCTION__, __LINE__);
+               array($refid, $level), __FUNCTION__, __LINE__);
 
        // Entries found?
        //* DEBUG: */ print(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>):numRows=".SQL_NUMROWS($result)."<br />");
-       if (SQL_NUMROWS($result) > 0) {
+       if (!SQL_HASZERONUMS($result)) {
                // Add all
                while ($content = SQL_FETCHARRAY($result)) {
-                       //* DEBUG: */ print(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>):rid={$rid},level={$level},userid={$content['userid']}<br />");
+                       //* DEBUG: */ print(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>):refid={$refid},level={$level},userid={$content['userid']}<br />");
                        $userIds[] = $content['userid'];
                } // END - while
        } // END - if
@@ -172,7 +173,7 @@ ORDER BY
        SQL_FREERESULT($result);
 
        // Return array
-       //* DEBUG: */ print(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>):rid={$rid},count()=".count($userIds)."<br />");
+       //* DEBUG: */ print(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>):refid={$refid},count()=".count($userIds)."<br />");
        //* DEBUG: */ print("</li></ul>----------------------- <font color=\"#aa0000\">".__FUNCTION__." - EXIT</font> ------------------------<br />");
        return $userIds;
 }
@@ -194,7 +195,7 @@ function updateRefbackTable ($userid) {
 
        // When no entry was updated then we have to create it here
        //* DEBUG: */ print(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>):found=".SQL_NUMROWS($result_refid)."<br />");
-       if (SQL_NUMROWS($result_refid) > 0) {
+       if (!SQL_HASZERONUMS($result_refid)) {
                // Load all refids
                while (list($GLOBALS['refback_refid'][$GLOBALS['refback_level']]) = SQL_FETCHROW($result_refid)) {
                        // Remmber userid
@@ -225,7 +226,8 @@ function updateRefbackTable ($userid) {
                                                array(bigintval($userid), $GLOBALS['refback_level'], bigintval($GLOBALS['refback_refid'][$GLOBALS['refback_level']])), __FUNCTION__, __LINE__);
 
                                        // Move to next referal level and count his counter one up!
-                                       $GLOBALS['refback_level']++; updateRefbackTable($GLOBALS['refback_refid'][($GLOBALS['refback_level'] - 1)]);
+                                       $GLOBALS['refback_level']++;
+                                       updateRefbackTable($GLOBALS['refback_refid'][($GLOBALS['refback_level'] - 1)]);
                                } // END - if
 
                                // Do we have another level here?
@@ -305,7 +307,7 @@ ORDER BY
                array(bigintval($userid), bigintval($level)), __FUNCTION__, __LINE__);
 
        // Are there some entries?
-       if (SQL_NUMROWS($result) > 0) {
+       if (!SQL_HASZERONUMS($result)) {
                // Fetch all entries
                while ($row = SQL_FETCHARRAY($result)) {
                        // Add row
@@ -352,20 +354,20 @@ function getArrayFromUserRefbackData ($id) {
 function updateMemberRefbackPercents ($id, $percents) {
        //* DEBUG: */ print("----------------------- <font color=\"#00aa00\">".__FUNCTION__." - ENTRY</font> ------------------------<ul><li>\n");
        // Default status is failed
-       $status['message'] = getMessage('MEMBER_REFBACK_ERROR_GENERAL');
+       $status['message'] = '{--MEMBER_REFBACK_ERROR_GENERAL--}';
 
        // Do some sanity-checks
        if (!isMember()) {
                // No member!
-               $status['message'] = getMessage('MEMBER_REFBACK_ERROR_NO_MEMBER');
+               $status['message'] = '{--MEMBER_REFBACK_ERROR_NO_MEMBER--}';
                return $status;
        } elseif (''.$id.'' != ''.($id + 0).'') {
                // No number!
-               $status['message'] = getMessage('MEMBER_REFBACK_ERROR_INVALID_ID_NUMBER');
+               $status['message'] = '{--MEMBER_REFBACK_ERROR_INVALID_ID_NUMBER--}';
                return $status;
        } elseif (($percents < 0) || ($percents > 100)) {
                // Percentage is not valid!
-               $status['message'] = getMessage('MEMBER_REFBACK_ERROR_INVALID_PERCENTAGE');
+               $status['message'] = '{--MEMBER_REFBACK_ERROR_INVALID_PERCENTAGE--}';
                return $status;
        }
 
@@ -375,7 +377,7 @@ function updateMemberRefbackPercents ($id, $percents) {
        // Is this valid?
        if (count($dummy) == 0) {
                // id does not belong to user!
-               $status['message'] = getMessage('MEMBER_REFBACK_ERROR_ID_MISMATCH');
+               $status['message'] = '{--MEMBER_REFBACK_ERROR_ID_MISMATCH--}';
                return $status;
        } // END - if
 
@@ -387,28 +389,23 @@ function updateMemberRefbackPercents ($id, $percents) {
                array($percents, $id, getMemberId()), __FUNCTION__, __LINE__);
 
        // Entry updated?
-       if (SQL_AFFECTEDROWS() < 1) {
+       if (SQL_HASZEROAFFECTED()) {
                // Entry not updated!
-               $status['message'] = getMessage('MEMBER_REFBACK_ERROR_NOT_UPDATED');
+               $status['message'] = '{--MEMBER_REFBACK_ERROR_NOT_UPDATED--}';
                return $status;
        } // 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);
+       sendEmail($dummy['refid'], '{--MEMBER_REFBACK_SUBJECT--}', $mail);
 
        // Send admin notification
-       sendAdminNotification(getMessage('ADMIN_REFBACK_SUBJECT'), 'admin_refback', $content, getMemberId());
+       sendAdminNotification('{--ADMIN_REFBACK_SUBJECT--}', 'admin_refback', $dummy, getMemberId());
 
        // All fine!
        $status['ok'] = true;
@@ -417,5 +414,18 @@ function updateMemberRefbackPercents ($id, $percents) {
        //* DEBUG: */ print("</li></ul>----------------------- <font color=\"#aa0000\">".__FUNCTION__." - EXIT</font> ------------------------<br />");
        return $status;
 }
-//
+
+// Checks wether refback is enabled
+function isRefbackEnabled () {
+       // Do we have cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = (getConfig('refback_enabled') == 'Y');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
+// [EOF]
 ?>