is not needed in member-only templates
[mailer.git] / inc / modules / member / what-points.php
index 3bfde38da0803fea1a077e364f002c1dc611333e..38065edd7bf3815c9847cfdaca24c3b4a8e0c9ef 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 10/19/2003 *
- * ===============                              Last change: 11/12/2004 *
+ * Mailer v0.2.1-FINAL                                Start: 10/19/2003 *
+ * ===================                          Last change: 11/12/2004 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : what-points.php                                  *
@@ -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 *
@@ -53,59 +54,69 @@ $depths = SQL_NUMROWS($result_depths);
 // Add many more rows for the login/turbo/ref/order bonus
 // @TODO Should we rewrite this to a filter?
 if (!isExtensionActive('bonus')) $depths += 1;
-if (getExtensionVersion('bonus') >= '0.2.2') $depths += 6;
-if (getExtensionVersion('bonus') >= '0.4.4') $depths += 4;
+if (isExtensionInstalledAndNewer('bonus', '0.2.2')) $depths += 6;
+if (isExtensionInstalledAndNewer('bonus', '0.4.4')) $depths += 4;
 
 // Remember row count in constant
 $content['rowspan'] = ($depths*2+15);
 
 // Init some vars...
-$totalPoints = 0; $TREF = 0; $TLOCK = 0; $OUT = '';
+$totalPoints = '0';
+$totalReferals = '0';
+$totalLocked = '0';
+$OUT = '';
 
 // Load ref levels
 while ($data = SQL_FETCHARRAY($result_depths)) {
        // Merge it together
        $content = merge_array($content, $data);
 
-       // Initialize ref-count
-       $REFS = 0;
+       // Initialize array elements
+       $content['counter'] = '0';
+       $content['points'] = '0.00000';
+       $content['locked_points'] = '0.00000';
 
        // Load referal points
-       $result_points = SQL_QUERY_ESC("SELECT points, locked_points FROM `{?_MYSQL_PREFIX?}_user_points` WHERE `userid`=%s AND `ref_depth`='%s' LIMIT 1", array(getUserId(), bigintval($content['level'])), __FILE__, __LINE__);
+       $result_points = SQL_QUERY_ESC("SELECT `points`, `locked_points` FROM `{?_MYSQL_PREFIX?}_user_points` WHERE `userid`=%s AND `ref_depth`='%s' LIMIT 1",
+               array(
+                       getMemberId(),
+                       bigintval($content['level'])
+               ), __FILE__, __LINE__);
+
+       // Do we have an entry?
        if (SQL_NUMROWS($result_points) == 1) {
-                       list($points, $locked) = SQL_FETCHROW($result_points);
-               // Also count locked points
-               $totalPoints += $points; $TLOCK += $locked;
-       } else {
-               $points = '0.00000'; $locked = '0.00000';
-       }
+               // Load data
+               $content = merge_array($content, SQL_FETCHARRAY($result_points));
+
+               // Add both points
+               $totalPoints += $content['points'];
+               $totalLocked += $content['locked_points'];
+       } // END - if
 
        // Free result
        SQL_FREERESULT($result_points);
 
        // Load referal counts
-       $result_refs = SQL_QUERY_ESC("SELECT counter FROM `{?_MYSQL_PREFIX?}_refsystem` WHERE `userid`=%s AND level='%s' LIMIT 1",
-               array(getUserId(), bigintval($content['level'])), __FILE__, __LINE__);
+       $result_refs = SQL_QUERY_ESC("SELECT `counter` FROM `{?_MYSQL_PREFIX?}_refsystem` WHERE `userid`=%s AND `level`='%s' LIMIT 1",
+               array(
+                       getMemberId(),
+                       bigintval($content['level'])
+               ), __FILE__, __LINE__);
+
+       // Do we have an entry?
        if (SQL_NUMROWS($result_refs) == 1) {
-               list($REFS) = SQL_FETCHROW($result_refs);
-               $TREF += $REFS;
-       } else {
-               $REFS = 0;
-       }
+               // Load data
+               $content = merge_array($content, SQL_FETCHARRAY($result_refs));
+
+               // Add them to total refs
+               $totalReferals += $content['counter'];
+       } // END - if
 
        // Free result
        SQL_FREERESULT($result_refs);
 
-       // Transfer data to array for template
-       $row = array(
-               'level'   => $content['level'],
-               'percents' => translateComma($content['percents']),
-               'points'  => translateComma($points),
-               'refs'    => translateComma($REFS),
-       );
-
        // Output row
-       $OUT .= loadTemplate('member_points_row', true, $row);
+       $OUT .= loadTemplate('member_points_row', true, $content);
 } // END - while
 
 // Free memory
@@ -114,23 +125,20 @@ SQL_FREERESULT($result_depths);
 // Put rows to constant for the main template
 $content['rows'] = $OUT;
 
-$result = SQL_QUERY_ESC("SELECT `used_points`, `ref_payout` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s LIMIT 1",
-       array(getUserId()), __FILE__, __LINE__);
-list($usedPoints, $PAY) = SQL_FETCHROW($result);
-SQL_FREERESULT($result);
-
 // Initialize variables
-$CONFIRMED = '---'; $SENT = '---'; $RECEIVED = '---';
+$CONFIRMED = '---';
+$SENT      = '---';
+$RECEIVED  = '---';
 
 // Only user >= v0.1.2: Fetch confirmed mails counter
-if (getExtensionVersion('user') >= '0.1.2') {
+if (isExtensionInstalledAndNewer('user', '0.1.2')) {
        $add = '';
-       if (getExtensionVersion('user') >= '0.1.4') {
-               $add = ", `emails_sent`, `emails_received`";
-       }
-       $result = SQL_QUERY_ESC("SELECT `mails_confirmed`".$add." FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s LIMIT 1", array(getUserId()), __FILE__, __LINE__);
-       list($CONFIRMED, $SENT, $RECEIVED) = SQL_FETCHROW($result);
-       SQL_FREERESULT($result);
+       $CONFIRMED = getUserData('mails_confirmed');
+
+       if (isExtensionInstalledAndNewer('user', '0.1.4')) {
+               $SENT     = getUserData('emails_sent');
+               $RECEIVED = getUserData('emails_received');
+       } // END - if
 
        // Please update the user extension if you see 3 dashes
        if (empty($SENT))     $SENT     = '---';
@@ -141,52 +149,38 @@ if (getExtensionVersion('user') >= '0.1.2') {
 }
 
 // If TLOCK is 0 add 3 zeros for floating
-if ($TLOCK == '0') $TLOCK = '0.00000';
+if ($totalLocked == '0') $totalLocked = '0.00000';
 
 // Remember several values in constants
-$content['used']  = translateComma($usedPoints);
-$content['tpts']  = translateComma($totalPoints - $usedPoints);
-$content['tref']  = $TREF;
-$content['tlock'] = translateComma($TLOCK);
+$content['sum']   = ($totalPoints - getUserData('used_points'));
+$content['tref']  = $totalReferals;
+$content['tlock'] = $totalLocked;
 
 // Fixes a bug when there is no bonus extension installed
-if (isExtensionOlder('bonus', '0.4.4')) setConfigEntry('bonus_active', "X");
+if (isExtensionInstalledAndOlder('bonus', '0.4.4')) setConfigEntry('bonus_active', 'X');
 
 // Members shall see no special rows here
 $content['special_rows'] = '';
 
 // Display login bonus and turbo-click bonus
-if ((getExtensionVersion('bonus') >= '0.2.2') && (isExtensionActive('bonus')) && (getConfig('bonus_active') == 'Y')) {
-       $add = ", 0, 0, 0";
-       if (getExtensionVersion('bonus') >= '0.4.4') $add = ", `bonus_ref`, `bonus_order`, `bonus_stats`";
-
-       // Load data
-       $result = SQL_QUERY_ESC("SELECT `login_bonus`, `turbo_bonus`".$add." FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s LIMIT 1",
-               array(getUserId()), __FILE__, __LINE__);
-
-       // We don't add this points now. This will be done after each month
-       list($login, $turbo, $ref, $order, $stats) = SQL_FETCHROW($result);
-
-       // Free result
-       SQL_FREERESULT($result);
-
-       // Prepare constants
-       $content['turbo'] = translateComma($turbo);
-       $content['login'] = translateComma($login);
-
-       if (getExtensionVersion('bonus') >= '0.4.4') {
-               // Add referal, stats and order bonys
-               $content['ref']   =  translateComma($ref);
-               $content['order'] = translateComma($order);
-               $content['stats'] = translateComma($stats);
+if ((isExtensionInstalledAndNewer('bonus', '0.2.2')) && (isExtensionActive('bonus')) && (getConfig('bonus_active') == 'Y')) {
+       // Fetch some data and init others (to avoid a notice here)
+       $content['login'] = getUserData('login_bonus');
+       $content['turbo'] = getUserData('turbo_bonus');
+
+       // Get more data if ext-bonus is newer
+       if (isExtensionInstalledAndNewer('bonus', '0.4.4')) {
+               $content['ref']   = getUserData('bonus_ref');
+               $content['order'] = getUserData('bonus_order');
+               $content['stats'] = getUserData('bonus_stats');
        } // END - if
 
        // Total bonus points
-       $content['ttotal'] = translateComma($turbo + $login + $ref + $order + $stats);
+       $content['ttotal'] = $content['turbo'] + $content['login'] + $content['ref'] + $content['order'] + $content['stats'];
 
        // Output rows
        $content['special_rows'] = loadTemplate('member_points_bonus_rows', true, $content);
-} elseif (getConfig('bonus_active') != 'Y') {
+} elseif ((isExtensionActive('bonus')) && (getConfig('bonus_active') != 'Y')) {
        // Bonus active rallye deactivated
        $content['special_rows'] = loadTemplate('member_points_bonus_disabled', true);
 } elseif ((isAdmin()) && (isExtensionOlder('bonus', '0.2.2')) && (isExtensionActive('bonus'))) {
@@ -196,7 +190,6 @@ if ((getExtensionVersion('bonus') >= '0.2.2') && (isExtensionActive('bonus')) &&
 
 // Remeber values for the final template
 $content['receive']   = $RECEIVED;
-$content['pay']       = $PAY;
 $content['confirmed'] = $CONFIRMED;
 $content['sent']      = $SENT;
 
@@ -214,7 +207,7 @@ if (isExtensionActive('user')) {
 
 if (isExtensionActive('payout')) {
        // Payput extension is installed and active so we can check if the user has enougth points
-       outputPayoutList(convertCommaToDot(($totalPoints - $usedPoints)));
+       outputPayoutList(convertCommaToDot(($totalPoints - getUserData('used_points'))));
 } // END - if
 
 // [EOF]