<?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 *
* $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 *
- * For more information visit: http://www.mxchange.org *
+ * Copyright (c) 2009 - 2016 by Mailer Developer Team *
+ * For more information visit: http://mxchange.org *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
// Some security stuff...
if (!defined('__SECURITY')) {
- die();
+ exit();
} elseif (!isMember()) {
redirectToIndexMemberOnlyModule();
}
// Add description as navigation point
-addMenuDescription('member', __FILE__);
+addYouAreHereLink('member', __FILE__);
-// Query for referal levels and percents
-$result_depths = SQL_QUERY("SELECT `level`, `percents` FROM `{?_MYSQL_PREFIX?}_refdepths` ORDER BY `level` ASC", __FILE__, __LINE__);
-$depths = SQL_NUMROWS($result_depths);
+// Extension ext-user is highly required
+if ((!isExtensionActive('user')) && (!isAdmin())) {
+ displayMessage('{%pipe,generateExtensionInactiveNotInstalledMessage=user%}');
+ return;
+} // END - if
+
+// Query for referral levels and percents
+$result_depths = sqlQuery('SELECT `level`, `percents` FROM `{?_MYSQL_PREFIX?}_refdepths` ORDER BY `level` ASC', __FILE__, __LINE__);
+
+// Get total depths
+$numDepths = sqlNumRows($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 (isExtensionActive('bonus')) {
+ // Extension ext-bonus is there, okay
+ if (isExtensionInstalledAndNewer('bonus', '0.2.2')) $numDepths += 6;
+ if (isExtensionInstalledAndNewer('bonus', '0.4.4')) $numDepths += 4;
+} else {
+ // Not installed ext-bonus
+ $numDepths += 1;
+}
// Remember row count in constant
-$content['rowspan'] = ($depths*2+15);
+$content['rowspan'] = ($numDepths * 2 + 15);
+
+// Initialize array elements
+$content['part_points'] = '0.00000';
+$content['part_referrals'] = '0';
+$content['part_locked'] = '0.00000';
+$content['part_order'] = '0.00000';
+$content['part_locked_order'] = '0.00000';
-// Init some vars...
-$totalPoints = 0; $TREF = 0; $TLOCK = 0; $OUT = '';
+// And output variable
+$OUT = '';
// Load ref levels
-while ($data = SQL_FETCHARRAY($result_depths)) {
+while ($data = sqlFetchArray($result_depths)) {
+ // Init points and counter here
+ $content['counter'] = '0';
+ $content['points'] = '0.00000';
+ $content['order_points'] = '0.00000';
+ $content['locked_points'] = '0.00000';
+ $content['locked_order_points'] = '0.00000';
+
// Merge it together
$content = merge_array($content, $data);
- // Initialize ref-count
- $REFS = 0;
-
- // 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__);
- 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';
- }
+ // Default for referral level > 0
+ $depth = '`p`.`ref_depth`=%s';
+ if (is_null($content['level'])) {
+ $depth = '`p`.`ref_depth` IS NULL';
+ } // 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__);
- if (SQL_NUMROWS($result_refs) == 1) {
- list($REFS) = SQL_FETCHROW($result_refs);
- $TREF += $REFS;
- } else {
- $REFS = 0;
- }
+ // Load referral points
+ $result_points = sqlQueryEscaped('SELECT
+ ' . getAllPointColumns('p.', ',') . '
+ `r`.`counter`
+FROM
+ `{?_MYSQL_PREFIX?}_user_points` AS `p`
+LEFT JOIN
+ `{?_MYSQL_PREFIX?}_refsystem` AS `r`
+ON
+ `p`.`userid`=`r`.`userid` AND
+ `p`.`ref_depth`=`r`.`level`
+WHERE
+ `p`.`userid`=%s AND
+ ' . $depth . '
+LIMIT 1',
+ array(
+ getMemberId(),
+ convertZeroToNull($content['level'])
+ ), __FILE__, __LINE__);
+
+ // Is there an entry?
+ if (sqlNumRows($result_points) == 1) {
+ // Load data
+ $content = merge_array($content, sqlFetchArray($result_points));
+
+ // Add locked-/points
+ $content['part_points'] += $content['points'];
+ $content['part_locked'] += $content['locked_points'];
+
+ // For these columns, ext-order must be installed as well
+ if (isExtensionInstalled('order')) {
+ $content['part_order'] += $content['order_points'];
+ $content['part_locked_order'] += $content['locked_order_points'];
+ } // END - if
+
+ // Add referral counter
+ $content['part_referrals'] += $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),
- );
+ sqlFreeResult($result_points);
// Output row
- $OUT .= loadTemplate('member_points_row', true, $row);
+ $OUT .= loadTemplate('member_points_row', TRUE, $content);
} // END - while
// Free memory
-SQL_FREERESULT($result_depths);
+sqlFreeResult($result_depths);
+
+// Add userid
+$content['userid'] = getMemberId();
// 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 = '---';
-
-// Only user >= v0.1.2: Fetch confirmed mails counter
-if (getExtensionVersion('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);
-
- // Please update the user extension if you see 3 dashes
- if (empty($SENT)) $SENT = '---';
- if (empty($RECEIVED)) $RECEIVED = '---';
-} else {
- // Please update!
- $CONFIRMED = '---';
-}
-
-// If TLOCK is 0 add 3 zeros for floating
-if ($TLOCK == 0) $TLOCK = '0.00000';
-
-// Remember several values in constants
-$content['used'] = translateComma($usedPoints);
-$content['sum'] = translateComma($totalPoints - $usedPoints);
-$content['tref'] = $TREF;
-$content['tlock'] = translateComma($TLOCK);
-
// 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');
+} // END - if
// 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);
- } // END - if
-
+if ((isExtensionInstalledAndNewer('bonus', '0.2.2')) && (isExtensionActive('bonus')) && (isBonusRallyeActive())) {
// Total bonus points
- $content['ttotal'] = translateComma($turbo + $login + $ref + $order + $stats);
+ $content['bonus_total_points'] = getUserData('turbo_bonus') + getUserData('login_bonus') + getUserData('bonus_ref') + getUserData('bonus_order') + getUserData('bonus_stats');
// Output rows
- $content['special_rows'] = loadTemplate('member_points_bonus_rows', true, $content);
-} elseif (getConfig('bonus_active') != 'Y') {
+ $content['special_rows'] = loadTemplate('member_points_bonus_rows', TRUE, $content);
+} elseif ((isExtensionActive('bonus')) && (!isBonusRallyeActive())) {
// Bonus active rallye deactivated
- $content['special_rows'] = loadTemplate('member_points_bonus_disabled', true);
-} elseif ((isAdmin()) && (isExtensionOlder('bonus', '0.2.2')) && (isExtensionActive('bonus'))) {
+ $content['special_rows'] = loadTemplate('member_points_bonus_disabled', TRUE);
+} elseif ((isAdmin()) && (isExtensionInstalledAndOlder('bonus', '0.2.2')) && (isExtensionActive('bonus'))) {
// Please upgrade your bonus extension to v0.2.2 or newer!
$content['special_rows'] = loadTemplate('member_points_upgrade');
}
-// Remeber values for the final template
-$content['receive'] = $RECEIVED;
-$content['pay'] = $PAY;
-$content['confirmed'] = $CONFIRMED;
-$content['sent'] = $SENT;
-
// Load final template
if (isExtensionActive('user')) {
// Load template when required extension is there
- loadTemplate('member_points', false, $content);
+ loadTemplate('member_points', FALSE, $content);
} elseif (isAdmin()) {
// Missing extension
- loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('user'));
+ displayMessage('{%pipe,generateExtensionInactiveNotInstalledMessage=user%}');
} else {
// Message for user
- loadTemplate('admin_settings_saved', false, getMessage('PROBLEM_POINTS_OVERVIEW_UNAVAILABLE'));
+ displayMessage('{--PROBLEM_POINTS_OVERVIEW_UNAVAILABLE--}');
}
+// Is ext-payout installed?
if (isExtensionActive('payout')) {
// Payput extension is installed and active so we can check if the user has enougth points
- outputPayoutList(convertCommaToDot(($totalPoints - $usedPoints)));
+ outputPayoutList($content['part_points'] - getUserData('used_points'));
} // END - if
// [EOF]