From dc25bd7a76750f02e2d617c9db9eb0aae53270f5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 12 Jul 2011 00:32:40 +0000 Subject: [PATCH] Fixes for referal system, shell scripts overworked: - Various fixes to the referal/points system (still some work needs to be done) - Shell scripts enhanced with check for "root" directory (modules.php) - Shell debug-lines.sh added which will show which debug lines are commented in - Other minor rewrites/fixes - TODOs.txt updated --- DOCS/TODOs.txt | 50 ++--- DOCS/debug.lines.sh | 10 + DOCS/lint.sh | 5 + DOCS/prop-set.sh | 5 + DOCS/remove-deprecated.sh | 5 + DOCS/validator.sh | 5 + birthday_confirm.php | 3 +- inc/db/lib-mysql3.php | 22 +- inc/extensions-functions.php | 4 +- inc/extensions/ext-refback.php | 14 +- inc/extensions/ext-register.php | 4 +- inc/extensions/ext-user.php | 18 +- inc/filter/surfbar_filter.php | 4 +- inc/filter/user_filter.php | 2 +- inc/functions.php | 8 +- inc/gen_refback.php | 3 - inc/header.php | 4 +- inc/js/js-surfbar_frame_top.php | 7 +- inc/language/de.php | 6 +- inc/language/mydata_de.php | 1 + inc/libs/beg_functions.php | 3 +- inc/libs/rallye_functions.php | 10 +- inc/libs/refback_functions.php | 129 +++++++----- inc/libs/register_functions.php | 12 +- inc/libs/surfbar_functions.php | 189 ++++++++++-------- inc/libs/user_functions.php | 8 +- inc/modules/admin/admin-inc.php | 15 +- inc/modules/guest/what-register.php | 2 +- inc/mysql-manager.php | 117 ++++++----- inc/template-functions.php | 7 +- inc/wrapper-functions.php | 6 +- mailid_top.php | 3 +- surfbar.php | 3 + templates/de/html/js/js_surfbar_frame_top.tpl | 2 +- 34 files changed, 394 insertions(+), 292 deletions(-) create mode 100755 DOCS/debug.lines.sh diff --git a/DOCS/TODOs.txt b/DOCS/TODOs.txt index 4e633e8469..561837e4b3 100644 --- a/DOCS/TODOs.txt +++ b/DOCS/TODOs.txt @@ -2,7 +2,6 @@ ### DO NOT EDIT THIS FILE. ### ./autoreg.php:58:// @TODO Add processing of request here ./beg.php:168: // @TODO Opps, what is missing here??? -./birthday_confirm.php:93: // @TODO Try to rewrite the following unset() ./inc/cache/config-local.php:124:// @TODO Rewrite the following three constants, somehow... ./inc/classes/cachesystem.class.php:504: // @TODO Add support for more types which break in last else-block ./inc/config-functions.php:136: // @TODO Make this all better... :-/ @@ -55,9 +54,9 @@ ./inc/functions.php:2200: // @TODO Rename column data_type to e.g. mail_status ./inc/gen_sql_patches.php:95:// @TODO Rewrite this to a filter ./inc/install-functions.php:57: // @TODO DEACTIVATED: changeDataInLocalConfigurationFile('OUTPUT-MODE', "setConfigEntry('OUTPUT_MODE', '", "');", postRequestParameter('omode'), 0); -./inc/language/de.php:1068: // @TODO Rewrite these two constants -./inc/language/de.php:1084: // @TODO Rewrite these three constants -./inc/language/de.php:760:// @TODO Are these constants longer used? +./inc/language/de.php:1066: // @TODO Rewrite these two constants +./inc/language/de.php:1082: // @TODO Rewrite these three constants +./inc/language/de.php:758:// @TODO Are these constants longer used? ./inc/language-functions.php:255: // @TODO These are all valid languages, again hard-coded ./inc/language-functions.php:44:// @TODO Rewrite all language constants to this function. ./inc/language/newsletter_de.php:13: * @TODO This language file is completely out-dated, please do no * @@ -65,7 +64,6 @@ ./inc/language/refback_de.php:44:// @TODO Rewrite these constants to one ./inc/language/sponsor_de.php:117:// @TODO Rewrite these four constants to one and use sprintf() ./inc/libs/admins_functions.php:451: // @TODO This can be, somehow, rewritten -./inc/libs/beg_functions.php:55: // @TODO Try to rewrite the following unset() ./inc/libs/bonus_functions.php:194: // @TODO Move this HTML to a template ./inc/libs/doubler_functions.php:44:// @TODO Lame description ./inc/libs/doubler_functions.php:91: // @TODO Can't this be moved into EL? @@ -74,15 +72,11 @@ ./inc/libs/rallye_functions.php:768: $EXPIRE = 3; // @TODO The hard-coded value... ./inc/libs/rallye_functions.php:854:// @TODO Please document this function ./inc/libs/rallye_functions.php:910: // Load count @TODO Can't we rewrite this to our API? -./inc/libs/refback_functions.php:59: // @TODO Try to rewrite the following unset() ./inc/libs/register_functions.php:290: // @TODO Rewrite these all to a single filter -./inc/libs/register_functions.php:360: // @TODO Rewrite this to a filter -./inc/libs/register_functions.php:367: // @TODO Wether the registration bonus should only be added to user directly or through referal system should be configurable +./inc/libs/register_functions.php:363: // @TODO Wether the registration bonus should only be added to user directly or through referal system should be configurable ./inc/libs/sponsor_functions.php:159: // @TODO Rewrite this to API function ./inc/libs/sponsor_functions.php:430: // @TODO Rewrite this to API function -./inc/libs/surfbar_functions.php:1018: // @TODO Invalid salt should be refused -./inc/libs/surfbar_functions.php:1099: // @TODO Try to rewrite the following unset() -./inc/libs/surfbar_functions.php:1614: // @TODO This can be somehow rewritten +./inc/libs/surfbar_functions.php:1621: // @TODO This can be somehow rewritten ./inc/libs/surfbar_functions.php:729:// @TODO Can't we use our new expression language instead of this ugly code? ./inc/libs/task_functions.php:247: // @TODO These can be rewritten to filter ./inc/libs/task_functions.php:51:// @TODO Move all extension-dependent queries into filters @@ -91,14 +85,13 @@ ./inc/libs/user_functions.php:234:// @TODO Double-check configuration entry here ./inc/libs/user_functions.php:329: // @TODO Make this filter working: $ADDON = runFilterChain('post_login_update', $content); ./inc/libs/user_functions.php:358: // @TODO Make this filter working: $url = runFilterChain('do_login', array('content' => $content, 'addon' => $ADDON)); -./inc/libs/user_functions.php:625: // @TODO Try to rewrite the following unset() ./inc/libs/yoomedia_functions.php:114: $response = YOOMEDIA_QUERY_API('out_textmail.php', true); // @TODO Ask Yoo!Media for test script ./inc/load_config.php:75: // @TODO Rewrite them to avoid this else block ./inc/loader/load-extension.php:13: * @TODO Rewrite this whole file * ./inc/mails/doubler_mails.php:53:// @TODO Can this be rewritten to a filter? ./inc/module-functions.php:267: // @TODO Nothing helped??? ./inc/module-functions.php:308: // @TODO Rewrite this to a filter -./inc/modules/admin/admin-inc.php:1227: // @TODO If we can rewrite the EL sub-system to support more than one parameter, this call_user_func_array() can be avoided +./inc/modules/admin/admin-inc.php:1236: // @TODO If we can rewrite the EL sub-system to support more than one parameter, this call_user_func_array() can be avoided ./inc/modules/admin/admin-inc.php:171: // @TODO This and the next getCurrentAdminId() call might be moved into the templates? ./inc/modules/admin/admin-inc.php:242: // @TODO This can be rewritten into a filter ./inc/modules/admin/admin-inc.php:274: // @TODO Rewrite this to $content = SQL_FETCHARRAY() @@ -178,26 +171,26 @@ ./inc/modules/member/what-unconfirmed.php:209: // @TODO This 'userid' cannot be saved because of encapsulated EL code ./inc/modules/order.php:74: // @TODO Unused: 2,4 ./inc/monthly/monthly_bonus.php:64: // @TODO Rewrite this to a filter -./inc/mysql-manager.php:1241: // @TODO Rewrite this to a filter -./inc/mysql-manager.php:1503: // @TODO Try to rewrite this to $content = SQL_FETCHARRAY() -./inc/mysql-manager.php:1591: // @TODO Rewrite these lines to a filter -./inc/mysql-manager.php:1615: // @TODO Rewrite this to a filter -./inc/mysql-manager.php:1979: // @TODO Rewrite this to a filter -./inc/mysql-manager.php:2023:// @TODO Fix inconsistency between last_module and getWhat() +./inc/mysql-manager.php:1258: // @TODO Rewrite this to a filter +./inc/mysql-manager.php:1520: // @TODO Try to rewrite this to $content = SQL_FETCHARRAY() +./inc/mysql-manager.php:1608: // @TODO Rewrite these lines to a filter +./inc/mysql-manager.php:1632: // @TODO Rewrite this to a filter +./inc/mysql-manager.php:1998: // @TODO Rewrite this to a filter +./inc/mysql-manager.php:2042:// @TODO Fix inconsistency between last_module and getWhat() ./inc/mysql-manager.php:371: // @TODO Try to rewrite this to one or more functions ./inc/mysql-manager.php:44:// @TODO Can we cache this? ./inc/purge/purge-inact.php:55: // @TODO Rewrite these if() blocks to a filter ./inc/revision-functions.php:169:// @TODO This function does also set and get in 'cache_array' -./inc/template-functions.php:1066: // @TODO Deprecate this thing -./inc/template-functions.php:1077: // @TODO Deprecate this thing -./inc/template-functions.php:1170: // @TODO This can be easily moved out after the merge from EL branch to this is complete -./inc/template-functions.php:1203: // @TODO Add a little more infos here -./inc/template-functions.php:1517:// @TODO Lame description for this function -./inc/template-functions.php:1539: // @TODO Move this in a filter +./inc/template-functions.php:1069: // @TODO Deprecate this thing +./inc/template-functions.php:1080: // @TODO Deprecate this thing +./inc/template-functions.php:1173: // @TODO This can be easily moved out after the merge from EL branch to this is complete +./inc/template-functions.php:1206: // @TODO Add a little more infos here +./inc/template-functions.php:1520:// @TODO Lame description for this function +./inc/template-functions.php:1542: // @TODO Move this in a filter ./inc/template-functions.php:189: * @TODO On some pages this is buggy -./inc/template-functions.php:266: // @TODO Remove this sanity-check if all is fine -./inc/template-functions.php:594:// @TODO $simple/$constants are deprecated -./inc/template-functions.php:620: // @TODO Do only use $content and deprecate $GLOBALS and $DATA in templates +./inc/template-functions.php:269: // @TODO Remove this sanity-check if all is fine +./inc/template-functions.php:597:// @TODO $simple/$constants are deprecated +./inc/template-functions.php:623: // @TODO Do only use $content and deprecate $GLOBALS and $DATA in templates ./inc/wrapper-functions.php:130:// @TODO Implement $compress ./inc/wrapper-functions.php:137:// @TODO Implement $decompress ./inc/wrapper-functions.php:514:// @TODO Do some more sanity check here @@ -208,7 +201,6 @@ ./mailid_top.php:183: // @TODO Rewrite this to a filter ./mailid_top.php:190: // @TODO Rewrite this to a filter ./mailid_top.php:225: // @TODO Rewrite these blocks to filter -./mailid_top.php:261: // @TODO Try to rewrite the following unset() ./network-check.php:54:// @TODO Add processing of request here ./show_bonus.php:105: // @TODO No more needed? $content['points'] = translateComma($content['points']); ./view.php:68: // @TODO No banner found, output some default banner diff --git a/DOCS/debug.lines.sh b/DOCS/debug.lines.sh new file mode 100755 index 0000000000..7b31b121f8 --- /dev/null +++ b/DOCS/debug.lines.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +# Shell script to determine where in the code are commented-in debug lines +# +if ! test -e "modules.php"; then + echo "$0: Please execute this script from root directory." + exit 1 +fi + +svn diff |grep -v "svn diff" | grep "DEBUG" | grep "+" | grep -v "//\* DEBUG" > DOCS/debug-lines.log diff --git a/DOCS/lint.sh b/DOCS/lint.sh index 00c4a2c545..1e333eee6a 100755 --- a/DOCS/lint.sh +++ b/DOCS/lint.sh @@ -1,5 +1,10 @@ #!/bin/sh +if ! test -e "modules.php"; then + echo "$0: Please execute this script from root directory." + exit 1 +fi + echo "$0: Analysing PHP scripts for syntax errors (lint) ..." LINT=`find -type f -name "*.php" -exec php -l -f {} 2>&1 \; | grep -v "No syntax errors detected in"` diff --git a/DOCS/prop-set.sh b/DOCS/prop-set.sh index 1df2b4ca7d..caf1bcd542 100755 --- a/DOCS/prop-set.sh +++ b/DOCS/prop-set.sh @@ -1,5 +1,10 @@ #!/bin/sh +if ! test -e "modules.php"; then + echo "$0: Please execute this script from root directory." + exit 1 +fi + find -type f -name "*.php" -exec svn propset svn:keywords "Author Id Revision HeadURL Date Tag" {} \; find -type f -name "*-" -exec svn propset svn:keywords "Author Id Revision HeadURL Date Tag" {} \; find -type f -name "*_" -exec svn propset svn:keywords "Author Id Revision HeadURL Date Tag" {} \; diff --git a/DOCS/remove-deprecated.sh b/DOCS/remove-deprecated.sh index b813380d7f..87bed750d9 100755 --- a/DOCS/remove-deprecated.sh +++ b/DOCS/remove-deprecated.sh @@ -1,5 +1,10 @@ #!/bin/sh +if ! test -e "modules.php"; then + echo "$0: Please execute this script from root directory." + exit 1 +fi + LIST=`find -name "*.tpl" -exec grep -H "@DEPRECATED" {} \;` if test "${LIST}" != ""; then echo "${LIST}" | cut -d ":" -f 1 | xargs svn --force del diff --git a/DOCS/validator.sh b/DOCS/validator.sh index 20aedf2a56..9dea827d03 100755 --- a/DOCS/validator.sh +++ b/DOCS/validator.sh @@ -1,5 +1,10 @@ #!/bin/sh +if ! test -e "modules.php"; then + echo "$0: Please execute this script from root directory." + exit 1 +fi + echo "$0: Validating all templates..." DUMMY=`find templates/de/html/ -type f -name *.tpl -exec php DOCS/tpl-validator.php {} \; 2>&1` echo "${DUMMY}" | \ diff --git a/birthday_confirm.php b/birthday_confirm.php index 8619fc7056..24f71259c4 100644 --- a/birthday_confirm.php +++ b/birthday_confirm.php @@ -90,8 +90,7 @@ if (SQL_NUMROWS($result) == 1) { // Is the account confirmed? if ($data['status'] == 'CONFIRMED') { // Add points to account - // @TODO Try to rewrite the following unset() - unset($GLOBALS['ref_level']); + initReferalSystem(); addPointsThroughReferalSystem('birthday_confirm', $userid, $data['points'], false, 0, strtolower(getConfig('birthday_mode'))); // Remove entry from table diff --git a/inc/db/lib-mysql3.php b/inc/db/lib-mysql3.php index 975cefd78d..68cdd067ad 100644 --- a/inc/db/lib-mysql3.php +++ b/inc/db/lib-mysql3.php @@ -397,16 +397,16 @@ function SQL_ALTER_TABLE ($sql, $F, $L, $enableCodes = true) { //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'columnName=' . $columnName . ',idx=' . $idx . ',sql=' . $sql . ',hasZeroNums=' . intval(isSqlTableColumnFound($tableName, $columnName))); // Do we have no entry on ADD or an entry on DROP/CHANGE? - // 123 4 43 3 4 4 32 23 4 43 3 4 4 32 23 4 43 3 4 4 3 3 3 3 4 4321 - if (((!isSqlTableColumnFound($tableName, $columnName)) && (strpos($sql, 'ADD') !== false)) || ((isSqlTableColumnFound($tableName, $columnName)) && (strpos($sql, 'DROP') !== false)) || ((isSqlTableColumnFound($tableName, $columnName)) && (strpos($sql, 'CHANGE') !== false) && ($idx == 4) && (!isSqlTableColumnFound($tableName, $tableArray[5])))) { + // 123 4 43 3 4 4 32 23 4 43 34 5 5 4 45 6 6 5 5 5 56 7 76 6 654321 + if (((!isSqlTableColumnFound($tableName, $columnName)) && (strpos($sql, 'ADD') !== false)) || ((isSqlTableColumnFound($tableName, $columnName)) && ((strpos($sql, 'DROP') !== false) || ((strpos($sql, 'CHANGE') !== false) && ($idx == 4) && ((!isSqlTableColumnFound($tableName, $tableArray[5])) || ($columnName == $tableArray[5])))))) { // Do the query //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Executing: ' . $sql); $result = SQL_QUERY($sql, $F, $L, false); // Skip further attempt(s) break; - // 1234 5 54 4 5 5 43 34 5 54 4 5 5 43 3 4 4 32 2 21 - } elseif ((((isSqlTableColumnFound($tableName, $columnName)) && (strpos($sql, 'ADD') !== false)) || ((isSqlTableColumnFound($tableName, $columnName)) && (strpos($sql, 'DROP') !== false)) || (strpos($sql, 'CHANGE') !== false)) && ($columnName != 'KEY')) { + // 1234 5 54 4 5 5 43 34 5 54 45 6 6 54 4 5 5 432 2 21 + } elseif ((((isSqlTableColumnFound($tableName, $columnName)) && (strpos($sql, 'ADD') !== false)) || ((!isSqlTableColumnFound($tableName, $columnName)) && ((strpos($sql, 'DROP') !== false)) || (strpos($sql, 'CHANGE') !== false))) && ($columnName != 'KEY')) { // Abort here because it is alreay there //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Skipped: sql=' . $sql . ',columnName=' . $columnName . ',idx=' . $idx); break; @@ -425,7 +425,7 @@ function SQL_ALTER_TABLE ($sql, $F, $L, $enableCodes = true) { } elseif ($noIndex === false) { // And column name as well without backticks $keyName = str_replace('`', '', $tableArray[5]); - /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyName=' . $keyName . ',tableArray=
' . print_r($tableArray, true) . '
'); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyName=' . $keyName . ',tableArray=
' . print_r($tableArray, true) . '
'); // Is this "UNIQUE" or so? FULLTEXT has been handled the elseif() block above if (in_array(strtoupper($tableArray[4]), array('INDEX', 'UNIQUE', 'KEY', 'FULLTEXT'))) { @@ -447,18 +447,18 @@ function SQL_ALTER_TABLE ($sql, $F, $L, $enableCodes = true) { } // END - if // Shall we run it? - /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'tableName=' . $tableName . ', tableArray[3]=' . $tableArray[3] . ',keyName=' . $keyName); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'tableName=' . $tableName . ', tableArray[3]=' . $tableArray[3] . ',keyName=' . $keyName); if ((!isSqlTableIndexAdded($tableName, $tableArray[3], $keyName)) && ($tableArray[3] == 'ADD')) { // Send it to the SQL_QUERY() function to add it - /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $sql); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $sql); $result = SQL_QUERY($sql, $F, $L, $enableCodes); } elseif ((isSqlTableIndexAdded($tableName, $tableArray[3], $keyName)) && ($tableArray[3] == 'DROP')) { // Send it to the SQL_QUERY() function to drop it - /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $sql); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $sql); $result = SQL_QUERY($sql, $F, $L, $enableCodes); } else { // Not executed - /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Not executed: ' . $sql); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Not executed: ' . $sql); } } else { // Other ALTER TABLE query @@ -620,12 +620,12 @@ function isSqlTableIndexAdded ($tableName, $mode, $keyName) { //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'columnName='.$keyName.',content=
' . print_r($content, true) . '
'); if (($content['Key_name'] == $keyName) && ($mode == 'ADD')) { // Skip this query! - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("ADD: Skiped: %s", $sql)); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ADD: Skiped: tableName=' . $tableName . ',mode=' . $mode . ',keyName=' . $keyName); $GLOBALS[__FUNCTION__][$tableName][$mode] = true; break; } elseif (($content['Key_name'] == $keyName) && ($mode == 'DROP')) { // Don't skip this! - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("DROP: Not skiped: %s", $sql)); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'DROP: Not skiped: tableName=' . $tableName . ',mode=' . $mode . ',keyName=' . $keyName); $GLOBALS[__FUNCTION__][$tableName][$mode] = false; break; } diff --git a/inc/extensions-functions.php b/inc/extensions-functions.php index d1c46faf42..be86049739 100644 --- a/inc/extensions-functions.php +++ b/inc/extensions-functions.php @@ -1843,7 +1843,7 @@ function addGuestMenuSql ($action, $what, $title, $sort) { addExtensionSql($sql); } elseif (isDebugModeEnabled()) { // Double menus should be located and fixed! - logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double guest menu action=%s,what=%s,title=%s,locked=%s,visible=%s detected.", $action, $what, $title, $locked, $visible)); + logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double guest menu action=%s,what=%s,title=%s detected.", $action, $what, $title)); } } @@ -1873,7 +1873,7 @@ function addMemberMenuSql ($action, $what, $title, $sort) { addExtensionSql($sql); } elseif (isDebugModeEnabled()) { // Double menus should be located and fixed! - logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double member menu action=%s,what=%s,title=%s,visivle=%s,locked=%s detected.", $action, $what, $title, $visible, $locked)); + logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double member menu action=%s,what=%s,title=%s detected.", $action, $what, $title)); } } diff --git a/inc/extensions/ext-refback.php b/inc/extensions/ext-refback.php index db45a20504..1720650b01 100644 --- a/inc/extensions/ext-refback.php +++ b/inc/extensions/ext-refback.php @@ -41,10 +41,10 @@ if (!defined('__SECURITY')) { } // END - if // Version number -setThisExtensionVersion('0.0.1'); +setThisExtensionVersion('0.0.2'); // Version history array (add more with , '0.0.1' and so on) -setExtensionVersionHistory(array('0.0.0','0.0.1')); +setExtensionVersionHistory(array('0.0.0','0.0.1', '0.0.2')); switch (getExtensionMode()) { case 'register': // Do stuff when installation is running @@ -98,6 +98,16 @@ INDEX (`refid`)", // Update notes (these will be set as task text!) setExtensionUpdateNotes("Refback-System ist nun ein-/ausschaltbar und minimale/maximale Refback-Prozente sind festlegbar."); break; + + case '0.0.2': // SQL queries for v0.0.2 + addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_user_refs` CHANGE `userid` `userid` BIGINT(20) UNSIGNED NULL DEFAULT NULL'); + addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_user_refs` CHANGE `level` `level` SMALLINT(6) UNSIGNED NULL DEFAULT NULL'); + addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_user_refs` CHANGE `refid` `refid` BIGINT(20) UNSIGNED NULL DEFAULT NULL'); + addExtensionSql('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_refs` WHERE `userid` IS NULL OR `refid` IS NULL OR `level` IS NULL'); + + // Update notes (these will be set as task text!) + setExtensionUpdateNotes("Updates von ext-user hier her verschoben."); + break; } // END - switch break; diff --git a/inc/extensions/ext-register.php b/inc/extensions/ext-register.php index 019915876b..26b080afc7 100644 --- a/inc/extensions/ext-register.php +++ b/inc/extensions/ext-register.php @@ -64,12 +64,12 @@ switch (getExtensionMode()) { case 'activate': // Do stuff when admin activates this extension // SQL commands to run - addExtensionSql(''); + addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_guest_menu` SET `locked`='N', `visible`='Y' WHERE `what`='register' LIMIT 1"); break; case 'deactivate': // Do stuff when admin deactivates this extension // SQL commands to run - addExtensionSql(''); + addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_guest_menu` SET `locked`='Y', `visible`='N' WHERE `what`='register' LIMIT 1"); break; case 'update': // Update an extension diff --git a/inc/extensions/ext-user.php b/inc/extensions/ext-user.php index 9f30d00bac..195d0dd1aa 100644 --- a/inc/extensions/ext-user.php +++ b/inc/extensions/ext-user.php @@ -41,10 +41,10 @@ if (!defined('__SECURITY')) { } // END - if // Version number -setThisExtensionVersion('0.4.1'); +setThisExtensionVersion('0.4.2'); // Version history array (add more with , '0.0.1' and so on) -setExtensionVersionHistory(array('0.0.0', '0.1.0', '0.1.1', '0.1.2', '0.1.2', '0.1.3', '0.1.4', '0.1.5', '0.1.6', '0.1.7', '0.1.8', '0.1.9', '0.2.0', '0.2.1', '0.2.2', '0.2.3', '0.2.4', '0.2.5', '0.2.6', '0.2.7', '0.2.8', '0.2.9', '0.3.0', '0.3.1', '0.3.2', '0.3.3', '0.3.4', '0.3.5', '0.3.6', '0.3.7', '0.3.8', '0.3.9', '0.4.0', '0.4.1')); +setExtensionVersionHistory(array('0.0.0', '0.1.0', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5', '0.1.6', '0.1.7', '0.1.8', '0.1.9', '0.2.0', '0.2.1', '0.2.2', '0.2.3', '0.2.4', '0.2.5', '0.2.6', '0.2.7', '0.2.8', '0.2.9', '0.3.0', '0.3.1', '0.3.2', '0.3.3', '0.3.4', '0.3.5', '0.3.6', '0.3.7', '0.3.8', '0.3.9', '0.4.0', '0.4.1', '0.4.2')); // Keep this extension always active! setExtensionAlwaysActive('Y'); @@ -387,9 +387,6 @@ INDEX (`userid`)", addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_user_links` CHANGE `userid` `userid` BIGINT(20) UNSIGNED NULL DEFAULT NULL'); addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_user_points` CHANGE `userid` `userid` BIGINT(20) UNSIGNED NULL DEFAULT NULL'); addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_user_points` CHANGE `ref_depth` `ref_depth` TINYINT(3) UNSIGNED NULL DEFAULT NULL'); - addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_user_refs` CHANGE `userid` `userid` BIGINT(20) UNSIGNED NULL DEFAULT NULL'); - addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_user_refs` CHANGE `level` `level` SMALLINT(6) UNSIGNED NULL DEFAULT NULL'); - addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_user_refs` CHANGE `refid` `refid` BIGINT(20) UNSIGNED NULL DEFAULT NULL'); addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_user_stats` CHANGE `userid` `userid` BIGINT(20) UNSIGNED NULL DEFAULT NULL'); addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_user_stats` CHANGE `cat_id` `cat_id` BIGINT(20) UNSIGNED NULL DEFAULT NULL'); addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_user_stats` CHANGE `payment_id` `payment_id` BIGINT(20) UNSIGNED NULL DEFAULT NULL'); @@ -403,7 +400,6 @@ INDEX (`userid`)", addExtensionSql('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `userid` IS NULL'); addExtensionSql('UPDATE `{?_MYSQL_PREFIX?}_user_points` SET `ref_depth`=NULL WHERE `ref_depth`=0'); addExtensionSql('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_points` WHERE `userid` IS NULL'); - addExtensionSql('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_refs` WHERE `userid` IS NULL OR `refid` IS NULL OR `level` IS NULL'); addExtensionSql('UPDATE `{?_MYSQL_PREFIX?}_user_stats` SET `cat_id`=NULL WHERE `cat_id`=0'); addExtensionSql('UPDATE `{?_MYSQL_PREFIX?}_user_stats` SET `payment_id`=NULL WHERE `payment_id`=0'); addExtensionSql('UPDATE `{?_MYSQL_PREFIX?}_user_stats` SET `pool_id`=NULL WHERE `pool_id`=0'); @@ -413,19 +409,19 @@ INDEX (`userid`)", setExtensionUpdateNotes("NULL ist wichtiger als 0 und UNSIGNED auch."); break; - case '0.3.7': // SQL queries for v0.3.7 + case '0.3.8': // SQL queries for v0.3.8 addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_user_data` CHANGE `last_failure` `last_failure` TIMESTAMP NULL DEFAULT NULL'); // Update notes (these will be set as task text!) setExtensionUpdateNotes("Ausgangswert ist nicht mehr 0000-00-00 00:00:00, sondern einfach NULL."); break; - case '0.3.8': // SQL queries for v0.3.8 + case '0.3.9': // SQL queries for v0.3.9 // Update notes (these will be set as task text!) setExtensionUpdateNotes("Update verschoben nach ext-order (da es Werbeguthaben ist und nichts mit dem Mitglied selbst zu tun hat)."); break; - case '0.3.9': // SQL queries for v0.3.9 + case '0.4.0': // SQL queries for v0.4.0 // Register new filters for gathering points registerFilter('get_total_points', 'USER_POINTS', false, true, isExtensionDryRun()); registerFilter('get_own_points', 'USER_POINTS', false, true, isExtensionDryRun()); @@ -434,7 +430,7 @@ INDEX (`userid`)", setExtensionUpdateNotes("Filter registriert, die das eigene {?POINTS?}-Guthaben des Mitgliedes zurückliefern."); break; - case '0.4.0': // SQL queries for v0.4.0 + case '0.4.1': // SQL queries for v0.4.1 // Add special fix include to fix filters addIncludeToPool('extension', 'inc/fix_user_points.php'); @@ -442,7 +438,7 @@ INDEX (`userid`)", setExtensionUpdateNotes("Das Mitgliederguthaben musste repariert werden, da für Referal-Ebene 0, noch NULL geschrieben wurde."); break; - case '0.4.1': // SQL queries for v0.4.1 + case '0.4.2': // SQL queries for v0.4.2 // Add special fix include to fix filters addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `what`='chk_regs' LIMIT 1"); diff --git a/inc/filter/surfbar_filter.php b/inc/filter/surfbar_filter.php index e0470d3f0a..25b1df08d4 100644 --- a/inc/filter/surfbar_filter.php +++ b/inc/filter/surfbar_filter.php @@ -74,9 +74,9 @@ function FILTER_SURFBAR_CHANGE_URL_VALIDATE_DATA ($filterData) { // Abort here, but fine! //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'newStatus[' . gettype($filterData['new_status']) . ']=' . $filterData['new_status'] . ' - EXIT!'); $filterData['abort'] = true; - } elseif ($filterData[$urlId]['url_status'] != $filterData['prev_status']) { + } elseif ($filterData['data'][$filterData['url_id']]['url_status'] != $filterData['prev_status']) { // Status is not like prevStatus - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $filterData[$urlId]['url_status'] . '!=' . $filterData['prev_status'] . ' - EXIT!'); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $filterData['data'][$filterData['url_id']]['url_status'] . '!=' . $filterData['prev_status'] . ' - EXIT!'); $filterData['abort'] = false; } // END - if diff --git a/inc/filter/user_filter.php b/inc/filter/user_filter.php index 71920260f0..fbc0e5e2fe 100644 --- a/inc/filter/user_filter.php +++ b/inc/filter/user_filter.php @@ -44,7 +44,7 @@ if (!defined('__SECURITY')) { function FILTER_USER_POINTS ($filterData) { // Get the points and add them to the existing //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!'); - $filterData['points'] += countSumTotalData($content['userid'], 'user_points', 'points'); + $filterData['points'] += countSumTotalData($filterData['userid'], 'user_points', 'points'); // Return the data for next filter //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!'); diff --git a/inc/functions.php b/inc/functions.php index bb9301f583..c85d6fde9a 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -640,14 +640,14 @@ function generateRandomCode ($length, $code, $userid, $extraData = '') { // Build key string $keys = getSiteKey() . getEncryptSeperator() . getDateKey(); if (isConfigEntrySet('secret_key')) { - $keys .= getEncryptSeperator().getSecretKey(); + $keys .= getEncryptSeperator() . getSecretKey(); } // END - if if (isConfigEntrySet('file_hash')) { - $keys .= getEncryptSeperator().getFileHash(); + $keys .= getEncryptSeperator() . getFileHash(); } // END - if $keys .= getEncryptSeperator() . getDateFromPatchTime(); if (isConfigEntrySet('master_salt')) { - $keys .= getEncryptSeperator().getMasterSalt(); + $keys .= getEncryptSeperator() . getMasterSalt(); } // END - if // Build string from misc data @@ -2337,6 +2337,7 @@ function getArrayKeysFromSubStrArray ($heystack, $needles, $offset = 0) { // Determines database column name from given subject and locked function determinePointsColumnFromSubjectLocked ($subject, $locked) { + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'subject=' . $subject . ',locked=' . intval($locked) . ' - ENTERED!'); // Default is 'normal' points $pointsColumn = 'points'; @@ -2359,6 +2360,7 @@ function determinePointsColumnFromSubjectLocked ($subject, $locked) { $pointsColumn = $filterData['column']; // Return it + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'subject=' . $subject . ',locked=' . intval($locked) . ',pointsColumn=' . $pointsColumn . ' - EXIT!'); return $pointsColumn; } diff --git a/inc/gen_refback.php b/inc/gen_refback.php index 59e457098d..cd20c0f730 100644 --- a/inc/gen_refback.php +++ b/inc/gen_refback.php @@ -79,9 +79,6 @@ ORDER BY if (!SQL_HASZERONUMS($result_direct)) { // When 'walk' through all users while ($content = SQL_FETCHARRAY($result_direct)) { - // Init level - $GLOBALS['refback_level'] = 1; - // Update refback table //* DEBUG: */ debugOutput('userid=' . $content['userid']); updateRefbackTable($content['userid']); diff --git a/inc/header.php b/inc/header.php index 48b35d40df..0f592edb2b 100644 --- a/inc/header.php +++ b/inc/header.php @@ -57,7 +57,9 @@ if (($GLOBALS['header_sent'] != 1) && ($GLOBALS['header_sent'] != 2)) { } // END - if // Closing HEAD tag - if ($GLOBALS['header_sent'] == '0') $GLOBALS['header_sent'] = 1; + if ($GLOBALS['header_sent'] == '0') { + $GLOBALS['header_sent'] = 1; + } // END - if } // END - if // Add BODY tag or not? diff --git a/inc/js/js-surfbar_frame_top.php b/inc/js/js-surfbar_frame_top.php index 9c9240b145..25bc676197 100644 --- a/inc/js/js-surfbar_frame_top.php +++ b/inc/js/js-surfbar_frame_top.php @@ -51,12 +51,11 @@ SURFBAR_DETERMINE_NEXT_ID(getRequestParameter('url_id')); // Check reload-locks SURFBAR_CHECK_RELOAD_FULL(); -// Update stats -SURFBAR_UPDATE_SALT_STATS(); - // Prepare content $content = array( - 'url_id' => bigintval(getRequestParameter('url_id')) + 'url_id' => bigintval(getRequestParameter('url_id')), + 'check' => SURFBAR_GENERATE_VALIDATION_CODE(getRequestParameter('url_id'), SURFBAR_GET_LAST_SALT()), + 'salt' => SURFBAR_GET_LAST_SALT(), ); // Load template diff --git a/inc/language/de.php b/inc/language/de.php index 8f0dc5d699..81b0e2e829 100644 --- a/inc/language/de.php +++ b/inc/language/de.php @@ -208,8 +208,6 @@ addMessages(array( 'ADMIN_ENTER_POINTS_REGISTER' => "Willkommensgutschrift", 'ADMIN_ENTER_POINTS_REFERAL' => "Einmalige Referal-Gutschrift", 'CHOOSE_MORE_CATEGORIES' => "Bitte wählen Sie mehr Kategorien aus! Minimum ist: {?least_cats?}", - 'GUEST_EMAIL_IS_ALREADY_REGISTERED' => "Sie haben sich bereits mit dieser Email-Adresse angemeldet, oder jemand anderes verwendet Ihre. Doppelte Anmeldungen sind bei uns nicht erlaubt.", - 'MEMBER_EMAIL_IS_ALREADY_REGISTERED' => "Die Email-Adresse wird bereits von einem anderen Account verwendet.", 'ADMIN_CONFIG_REJECT_DOUBLE_EMAIL' => "Doppelt angemeldete Email-Adressen ablehnen?", 'ADMIN_EDIT_POINTS' => "Willkommensgutschrift und andere Festbeträge editieren", 'ADMIN_EDIT_REFERAL_DEPTHS' => "Referal-Ebenen editieren / löschen / hinzufügen", @@ -343,7 +341,7 @@ addMessages(array( 'REFERAL_IS_ACTIVE' => "Aktiv?", 'POINTS_USED' => "Verbrauchte {?POINTS?}", 'MEMBER_NO_POINTS' => "Sie haben keine {?POINTS?} mehr zum Versenden übrig.", - 'MEMBER_NO_PAYMENTS' => "Der Admin diesen {?mt_word?} hat noch keine Mailarten definiert.", + 'MEMBER_NO_PAYMENTS' => "Der Admin dieses {?mt_word3?} hat noch keine Mailarten definiert.", 'MEMBER_POINTS_LEFT' => "{?POINTS?}-Guthaben zum Mailversand übrig", 'SELECT_MAIL_TYPE' => "Mailart auswählen", 'PLEASE_SELECT' => "Bitte auswählen", @@ -644,7 +642,7 @@ addMessages(array( 'ADMIN_EXTENSION_REGISTRATION_FAILED_ID_404' => "Registrierung fehlgeschlagen: Erweiterung-Id nicht auffindbar.", 'ADMIN_EXTENSION_REGISTRATION_FAILED_404' => "Registrierung fehlgeschlagen: Erweiterung %s nicht auffindbar.", 'ADMIN_EXTENSION_REGISTRATION_FAILED_ASSIGED' => "Registrierung fehlgeschlagen: Sie sind nicht zugewiesen oder die Aufgabe ist veraltet.", - 'ADMIN_EXTENSION_REGISTRATION_FAILED_ALREADY' => "Registrierung fehlgeschlagen: Erweiterun bereits installiert.", + 'ADMIN_EXTENSION_REGISTRATION_FAILED_ALREADY' => "Registrierung fehlgeschlagen: Erweiterung bereits installiert.", 'ADMIN_EXTENSION_REGISTRATION_FAILED_DEPRECATED' => "Registrierung fehlgeschlagen: Erweiterung ist veraltet.", 'ADMIN_NO_EXTENSION_REGISTERED' => "Derzeit haben Sie keine Erweiterung in Ihrem {?mt_word?} registriert.", 'ADMIN_EXTENSION_REGISTERED' => "Erweiterung %s wurde in Ihrem {?mt_word?} registriert.", diff --git a/inc/language/mydata_de.php b/inc/language/mydata_de.php index e5d1dbd913..fbc9695bf9 100644 --- a/inc/language/mydata_de.php +++ b/inc/language/mydata_de.php @@ -44,6 +44,7 @@ if (!defined('__SECURITY')) { addMessages(array( 'MEMBER_PROFILE_LAST_CHANGE' => "Letzte Änderung", 'MEMBER_PROFILE_UPDATED' => "Ihre Profildaten wurden aktualisiert.", + 'MEMBER_EMAIL_IS_ALREADY_REGISTERED' => "Die Email-Adresse wird bereits von einem anderen Account verwendet.", )); // [EOF] diff --git a/inc/libs/beg_functions.php b/inc/libs/beg_functions.php index 953a5ff901..8035ccf27d 100644 --- a/inc/libs/beg_functions.php +++ b/inc/libs/beg_functions.php @@ -52,8 +52,7 @@ function addPointsBeg ($userid, $points) { array($points, $userid), __FUNCTION__, __LINE__); } else { // Add points to account - // @TODO Try to rewrite the following unset() - unset($GLOBALS['ref_level']); + initReferalSystem(); $added = addPointsThroughReferalSystem('beg', $userid, $points, false, 0, getBegMode()); } diff --git a/inc/libs/rallye_functions.php b/inc/libs/rallye_functions.php index b3fb7f1fa6..4f86bd6cfd 100644 --- a/inc/libs/rallye_functions.php +++ b/inc/libs/rallye_functions.php @@ -117,11 +117,11 @@ ON p.userid=d.userid WHERE d.`status`='CONFIRMED' AND - d.max_mails > 0 AND - d.mails_confirmed >= {?ref_payout?} AND - p.ref_depth=1 AND - p.points > 0 AND - d.userid=%s", + d.`max_mails` > 0 AND + d.`mails_confirmed` >= {?ref_payout?} AND + p.`ref_depth`=1 AND + p.`points` > 0 AND + d.`userid`=%s", array(bigintval($content['userid'])), __FUNCTION__, __LINE__); // Get points diff --git a/inc/libs/refback_functions.php b/inc/libs/refback_functions.php index 92a13150ae..c66cdcf680 100644 --- a/inc/libs/refback_functions.php +++ b/inc/libs/refback_functions.php @@ -42,12 +42,12 @@ if (!defined('__SECURITY')) { // Payback refback for refid and reduce it for current user function addRefbackPoints ($userid, $ref, $points, $ref_points) { - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ',points=' . $points . ',ref_points=' . $ref_points . ' - ENTERED!'); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ',points=' . $points . ',ref_points=' . $ref_points . ' - ENTERED!'); // Back ref depths $GLOBALS['refback_depth'][$userid][$ref] = $GLOBALS['ref_level']; // Init points - $return = $points; + $return = $ref_points; // Get all ref levels $result_refs = SQL_QUERY('SELECT `level`, `percents` FROM `{?_MYSQL_PREFIX?}_refdepths` WHERE `level` > 0 ORDER BY `level` ASC', @@ -56,39 +56,49 @@ function addRefbackPoints ($userid, $ref, $points, $ref_points) { // "Walk" through all level while ($content = SQL_FETCHARRAY($result_refs)) { // Reset ref depths - // @TODO Try to rewrite the following unset() - unset($GLOBALS['ref_level']); + initReferalSystem(); // "Walk" through all refids - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ',level=' . $content['level'] . ',points=' . $points); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ',level=' . $content['level'] . ',percents=' . $content['percents'] . ',points=' . $points . ' - LOOP START!'); foreach (getArrayFromRefbackLevel($userid, $content['level']) as $refid) { // Skip level zero or if both are the same - if ($userid == $refid) continue; + if ($userid == $refid) { + continue; + } // END - if // Get refback percents $percents = getRefbackPercents($userid, $refid); - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ',refid=' . $refid . ',points=' . $points . ',percents=' . $percents); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ',refid=' . $refid . ',points=' . $points . ',percents=' . $percents); // Some percents given? if ($percents > 0) { - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'points=' . $points . ',[percents]=' . $content['percents'] . ',percents=' . $percents . ',level=' . $content['level']); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'points=' . $points . ',[percents]=' . $content['percents'] . ',percents=' . $percents . ',level=' . $content['level']); // Calculate points for refback $refback = $points * ($content['percents'] / 100) * ($percents / 100); // Update refback table ('refid' and 'userid' must be exchanged!) SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_refs` SET `points`=`points`+%s WHERE `userid`=%s AND `refid`=%s LIMIT 1", - array($refback, $refid, $userid), __FUNCTION__, __LINE__); - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'refback=' . $refback . ',userid=' . $userid . ',refid=' . $refid . ' - UPDATE! (' . SQL_AFFECTEDROWS() . ')'); + array( + $refback, + $refid, + $userid + ), __FUNCTION__, __LINE__); + + // Something must have been updated + if (SQL_HASZEROAFFECTED()) { + // Please report this bug + debug_report_bug(__FUNCTION__, __LINE__, 'Nothing has been updated in user_refs,userid=' . $userid . ',refid=' . $refid . ',refback=' . $refback); + } // END - if // Add points again, but only directly - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'refback=' . $refback); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'refback=' . $refback . ',userid=' . $userid . ',ref=' . $ref . ',refid=' . $refid . ' - UPDATE! (' . SQL_AFFECTEDROWS() . ')'); addPointsDirectly(sprintf("refback:%s", $refid), $userid, $refback); // Reduce points if refid is found if ($refid == $ref) { // Reduce points here! $return = $points * ($content['percents'] / 100) - $refback; - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'return=' . $return . ' - REDUCED!'); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'return=' . $return . ' - REDUCED!'); } // END - if } // END - if } // END foreach @@ -101,15 +111,17 @@ function addRefbackPoints ($userid, $ref, $points, $ref_points) { $GLOBALS['ref_level'] = $GLOBALS['refback_depth'][$userid][$ref]; // Return them - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ',points=' . $points . ',ref_points=' . $ref_points . ',return=' . $return . ' - ENTERED!'); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ',points=' . $points . ',ref_points=' . $ref_points . ',return=' . $return . ' - EXIT!'); return $return; } // "Getter" for refback percents function getRefbackPercents ($userid, $ref) { - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ' - ENTERED!'); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ' - ENTERED!'); // Skip identical ids - if ($userid == $ref) return 0; + if ($userid == $ref) { + return 0; + } // END - if // Is it cached? if (!isset($GLOBALS['refback_percents'][$userid][$ref])) { @@ -124,7 +136,7 @@ function getRefbackPercents ($userid, $ref) { if (SQL_NUMROWS($result) == 1) { // Fetch percents list($GLOBALS['refback_percents'][$userid][$ref]) = SQL_FETCHROW($result); - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ',percents=' . $GLOBALS['refback_percents'][$userid][$ref]); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ',percents=' . $GLOBALS['refback_percents'][$userid][$ref]); } else { // Debug log logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ' - No entry found. :-('); @@ -135,13 +147,13 @@ function getRefbackPercents ($userid, $ref) { } // END - if // Return percents - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ',refback_percents=' . $GLOBALS['refback_percents'][$userid][$ref] . ' - EXIT!'); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ',refback_percents=' . $GLOBALS['refback_percents'][$userid][$ref] . ' - EXIT!'); return $GLOBALS['refback_percents'][$userid][$ref]; } // "Getter" for userid array which will return only one entry function getArrayFromRefbackLevel ($refid, $level) { - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'refid=' . $refid . ',level=' . $level); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'refid=' . $refid . ',level=' . $level); // Init userids $userIds = array(); @@ -157,11 +169,11 @@ ORDER BY array($refid, $level), __FUNCTION__, __LINE__); // Entries found? - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'numRows=' . SQL_NUMROWS($result)); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'numRows=' . SQL_NUMROWS($result)); if (!SQL_HASZERONUMS($result)) { // Add all while ($content = SQL_FETCHARRAY($result)) { - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'refid=' . $refid . ',level=' . $level . ',userid=' . $content['userid']); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'refid=' . $refid . ',level=' . $level . ',userid=' . $content['userid']); $userIds[] = $content['userid']; } // END - while } // END - if @@ -170,7 +182,7 @@ ORDER BY SQL_FREERESULT($result); // Return array - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'refid=' . $refid . ',userIds()=' . count($userIds) . ' - EXIT!'); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'refid=' . $refid . ',userIds()=' . count($userIds) . ' - EXIT!'); return $userIds; } @@ -178,20 +190,21 @@ ORDER BY function updateRefbackTable ($userid) { // Make it sure referal level zero (member him-/herself) is at least selected if (empty($GLOBALS['refback_level'])) { - $GLOBALS['refback_level'] = 1; + $GLOBALS['refback_level'] = NULL; } // END - if - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $GLOBALS['refback_level'] . ' - ENTERED!'); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $GLOBALS['refback_level'] . ' - ENTERED!'); - // Init refid + // Init refid and variables $GLOBALS['refback_refid'][$GLOBALS['refback_level']] = '0'; - $old = '0'; $minus = '0'; + $old = '0'; + $minus = '0'; // Check for his referal $result_refid = SQL_QUERY_ESC("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `refid`=%s ORDER BY `userid` ASC", array(bigintval($userid)), __FUNCTION__, __LINE__); // When no entry was updated then we have to create it here - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'SQL_NUMROWS()=' . SQL_NUMROWS($result_refid)); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'SQL_NUMROWS()=' . SQL_NUMROWS($result_refid)); if (!SQL_HASZERONUMS($result_refid)) { // Load all refids while (list($GLOBALS['refback_refid'][$GLOBALS['refback_level']]) = SQL_FETCHROW($result_refid)) { @@ -199,7 +212,7 @@ function updateRefbackTable ($userid) { $GLOBALS['refback_userid'][$GLOBALS['refback_refid'][$GLOBALS['refback_level']]] = $userid; // Refid set? - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $GLOBALS['refback_refid'][$GLOBALS['refback_level']]); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $GLOBALS['refback_refid'][$GLOBALS['refback_level']]); if (($GLOBALS['refback_refid'][$GLOBALS['refback_level']] > 0) && ($GLOBALS['refback_refid'][$GLOBALS['refback_level']] != $userid) && (isset($GLOBALS['refback_refid'][$GLOBALS['refback_level']]))) { // New userid? if ((isset($GLOBALS['refback_refid'][$GLOBALS['refback_level']-1])) && (isset($GLOBALS['refback_userid'][$GLOBALS['refback_refid'][$GLOBALS['refback_level']-1]]))) { @@ -207,24 +220,38 @@ function updateRefbackTable ($userid) { $old = $userid; $userid = $GLOBALS['refback_userid'][$GLOBALS['refback_refid'][$GLOBALS['refback_level']-1]]; $minus = 1; - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',old=' . $old . ',level=' . $GLOBALS['refback_level'] . ',ref=' . $GLOBALS['refback_refid'][$GLOBALS['refback_level']] . ' - NEW UID!'); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',old=' . $old . ',level=' . $GLOBALS['refback_level'] . ',ref=' . $GLOBALS['refback_refid'][$GLOBALS['refback_level']] . ' - NEW UID!'); } // END - if // Check existence - $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_refs` WHERE `userid`=%s AND `level`=%s AND `refid`=%s LIMIT 1", - array( - bigintval($userid), - bigintval($GLOBALS['refback_level']), - bigintval($GLOBALS['refback_refid'][$GLOBALS['refback_level']]) - ), __FUNCTION__, __LINE__); + if (is_null($GLOBALS['refback_level'])) { + // Level is NULL + $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_refs` WHERE `userid`=%s AND `level` IS NULL AND `refid`=%s LIMIT 1", + array( + bigintval($userid), + bigintval($GLOBALS['refback_refid'][$GLOBALS['refback_level']]) + ), __FUNCTION__, __LINE__); + } else { + // Level is > 0 + $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_refs` WHERE `userid`=%s AND `level`=%s AND `refid`=%s LIMIT 1", + array( + bigintval($userid), + bigintval($GLOBALS['refback_level']), + bigintval($GLOBALS['refback_refid'][$GLOBALS['refback_level']]) + ), __FUNCTION__, __LINE__); + } // Do we have no entry? - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $GLOBALS['refback_level'] . ',ref=' . $GLOBALS['refback_refid'][$GLOBALS['refback_level']] . ',minus=' . $minus . ',numRows=' . SQL_NUMROWS($result) . ' - FOUND!'); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $GLOBALS['refback_level'] . ',ref=' . $GLOBALS['refback_refid'][$GLOBALS['refback_level']] . ',minus=' . $minus . ',numRows=' . SQL_NUMROWS($result) . ' - FOUND!'); if (SQL_HASZERONUMS($result)) { // Insert this level - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $GLOBALS['refback_level'] . ',ref=' . $GLOBALS['refback_refid'][$GLOBALS['refback_level']] . ' - ADD!'); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $GLOBALS['refback_level'] . ',ref=' . $GLOBALS['refback_refid'][$GLOBALS['refback_level']] . ' - ADD!'); SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_refs` (`userid`,`level`,`refid`) VALUES (%s,%s,%s)", - array(bigintval($userid), $GLOBALS['refback_level'], bigintval($GLOBALS['refback_refid'][$GLOBALS['refback_level']])), __FUNCTION__, __LINE__); + 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']++; @@ -245,12 +272,16 @@ function updateRefbackTable ($userid) { ), __FUNCTION__, __LINE__); // Do we have no entry? - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . ($GLOBALS['refback_level'] - $minus) . ',minus=' . $minus . ',ref=' . $GLOBALS['refback_refid'][$GLOBALS['refback_level']] . ',numRows=' . SQL_NUMROWS($result) . ' - BACK!'); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . ($GLOBALS['refback_level'] - $minus) . ',minus=' . $minus . ',ref=' . $GLOBALS['refback_refid'][$GLOBALS['refback_level']] . ',numRows=' . SQL_NUMROWS($result) . ' - BACK!'); 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__); - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . ($GLOBALS['refback_level'] - $minus) . ',ref=' . $GLOBALS['refback_refid'][$GLOBALS['refback_level']] . ' - RETURNED!'); + array( + bigintval($userid), + ($GLOBALS['refback_level'] - $minus), + bigintval($GLOBALS['refback_refid'][$GLOBALS['refback_level']]) + ), __FUNCTION__, __LINE__); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . ($GLOBALS['refback_level'] - $minus) . ',ref=' . $GLOBALS['refback_refid'][$GLOBALS['refback_level']] . ' - RETURNED!'); } // END - if } // END - if } // END - if @@ -263,25 +294,25 @@ function updateRefbackTable ($userid) { // When he has a referal... if ((($GLOBALS['refback_refid'][$GLOBALS['refback_level']] == $userid) || ($GLOBALS['refback_refid'][$GLOBALS['refback_level']] == '0')) && (isExtensionInstalledAndNewer('cache', '0.1.2')) && (!isset($GLOBALS['refback_cached']))) { // Remove cache here - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $GLOBALS['refback_refid'][$GLOBALS['refback_level']] . ' - CACHE!'); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $GLOBALS['refback_refid'][$GLOBALS['refback_level']] . ' - CACHE!'); if ($GLOBALS['cache_instance']->loadCacheFile('refback')) $GLOBALS['cache_instance']->removeCacheFile(); $GLOBALS['refback_cached'] = 1; } // END - if // "Walk" back here $GLOBALS['refback_level']--; - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',refback_level=' . $GLOBALS['refback_level'] .' - LEVEL!'); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',refback_level=' . $GLOBALS['refback_level'] .' - LEVEL!'); // Fix empty refid if (!isset($GLOBALS['refback_refid'][$GLOBALS['refback_level']-1])) { $GLOBALS['refback_refid'][$GLOBALS['refback_level']-1] = '0'; } // END - if - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',refback_level=' . {$GLOBALS['refback_level'] . ',ref=' . $GLOBALS['refback_refid'][$GLOBALS['refback_level']-1] . ' - EXIT!'); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',refback_level=' . $GLOBALS['refback_level'] . ',ref=' . $GLOBALS['refback_refid'][$GLOBALS['refback_level']-1] . ' - EXIT!'); } // "Getter" for array for user refs in given level function getArrayFromRefbackUserRefs ($userid, $level) { - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $level . ' - ENTERED!'); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $level . ' - ENTERED!'); // Default is no refs and no nickname $refs = array(); @@ -320,13 +351,13 @@ ORDER BY SQL_FREERESULT($result); // Return result - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $level . ',refs()=' . count($refs) . ' - EXIT!'); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $level . ',refs()=' . count($refs) . ' - EXIT!'); return $refs; } // "Getter" for refback entry function getArrayFromUserRefbackData ($id) { - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $id . ' - ENTERED!'); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $id . ' - ENTERED!'); // Default data is nothing $data = array(); @@ -347,13 +378,13 @@ function getArrayFromUserRefbackData ($id) { SQL_FREERESULT($result); // Return entry - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $id . ',data()=' . count($data) . ' - EXIT!'); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $id . ',data()=' . count($data) . ' - EXIT!'); return $data; } // Update refback percents (but with some sanity-checks! function updateMemberRefbackPercents ($id, $percents) { - //* logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $id . ',percents=' . $percents . ' - ENTERED!'); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $id . ',percents=' . $percents . ' - ENTERED!'); // Default status is failed $status['message'] = '{--MEMBER_REFBACK_ERROR_GENERAL--}'; @@ -412,7 +443,7 @@ function updateMemberRefbackPercents ($id, $percents) { $status['ok'] = true; // Return status array - //* logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $id . ',percents=' . $percents . ' - EXIT!'); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $id . ',percents=' . $percents . ' - EXIT!'); return $status; } diff --git a/inc/libs/register_functions.php b/inc/libs/register_functions.php index 5bf3cdbb91..0b2f58f63a 100644 --- a/inc/libs/register_functions.php +++ b/inc/libs/register_functions.php @@ -320,9 +320,9 @@ function doRegistration () { // Create user's account... SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_data` -(`gender`, `surname`, `family`, `street_nr`,%s, `zip`, `city`, `email`, `birth_day`, `birth_month`, `birth_year`, `password`, `max_mails`, `receive_mails`, `refid`, `status`, `user_hash`, `REMOTE_ADDR`, `joined`, `last_update`".$GLOBALS['register_sql_columns'].") +(`gender`, `surname`, `family`, `street_nr`,%s, `zip`, `city`, `email`, `birth_day`, `birth_month`, `birth_year`, `password`, `max_mails`, `receive_mails`, `refid`, `status`, `user_hash`, `REMOTE_ADDR`, `joined`, `last_update`,`ref_payout`".$GLOBALS['register_sql_columns'].") VALUES -('%s','%s','%s','%s','%s',%s,'%s','%s',%s, %s,%s,'%s',%s, %s,'%s','UNCONFIRMED','%s','%s', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()".$GLOBALS['register_sql_data'].")", +('%s','%s','%s','%s','%s',%s,'%s','%s',%s, %s,%s,'%s',%s, %s,'%s','UNCONFIRMED','%s','%s', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), {?ref_payout?}".$GLOBALS['register_sql_data'].")", array( $countryRow, substr(postRequestParameter('gender'), 0, 1), @@ -356,12 +356,8 @@ function doRegistration () { return; } // END - if - // Is the refback extension there? - // @TODO Rewrite this to a filter - if (isExtensionActive('refback')) { - // Update refback table - updateRefbackTable($userid); - } // END - if + // Update referal table + updateReferalCounter($userid); // Write his welcome-points // @TODO Wether the registration bonus should only be added to user directly or through referal system should be configurable diff --git a/inc/libs/surfbar_functions.php b/inc/libs/surfbar_functions.php index fdf5473283..2e5c248c66 100644 --- a/inc/libs/surfbar_functions.php +++ b/inc/libs/surfbar_functions.php @@ -873,18 +873,20 @@ function SURFBAR_DETERMINE_TEMPLATE_NAME() { // Check if the "reload lock" of the current user is full, call this function // before you call SURFBAR_CHECK_RELOAD_LOCK(). function SURFBAR_CHECK_RELOAD_FULL () { + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Fixed surf lock is ' . getConfig('surfbar_static_lock') . ' - ENTERED!'); // Default is full! $isFull = true; // Cache static reload lock $GLOBALS['surfbar_cache']['surf_lock'] = getConfig('surfbar_static_lock'); - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Fixed surf lock is '.getConfig('surfbar_static_lock') . '', false); // Do we have dynamic model? + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'surf_lock=' . $GLOBALS['surfbar_cache']['surf_lock'] . ' - BEFORE'); if (getSurfbarPaymentModel() == 'DYNAMIC') { // "Calculate" dynamic lock $GLOBALS['surfbar_cache']['surf_lock'] += SURFBAR_CALCULATE_DYNAMIC_ADD(); } // END - if + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'surf_lock=' . $GLOBALS['surfbar_cache']['surf_lock'] . ' - AFTER'); // Ask the database $result = SQL_QUERY_ESC("SELECT @@ -922,10 +924,10 @@ LIMIT 1", $total = SURFBAR_GET_TOTAL_URLS(); // Do we have some URLs in lock? Admins can always surf on own URLs! - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userLocks=' . SURFBAR_GET_USER_LOCKS() . ',total=' . $total); $isFull = ((SURFBAR_GET_USER_LOCKS() == $total) && ($total > 0)); // Return result + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userLocks=' . SURFBAR_GET_USER_LOCKS() . ',total=' . $total . 'isFull=' . intval($isFull) . ' - EXIT!'); return $isFull; } @@ -965,7 +967,7 @@ LIMIT 1", SQL_FREERESULT($result); // Debug message - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'cnt=' . $count); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'cnt=' . $count); // Return result return $count; @@ -1015,53 +1017,32 @@ function SURFBAR_GET_TOTAL_USER_URLS ($userid = '0', $status = '', $exclude = '' // Generate a validation code for the given id number function SURFBAR_GENERATE_VALIDATION_CODE ($urlId, $salt = '') { - // @TODO Invalid salt should be refused - $length = '0'; - $GLOBALS['surfbar_cache']['salt'] = 'INVALID'; - - // Is extension ext-other there? - if (isExtensionActive('other')) { - // Get code length from config - $length = getCodeLength(); - } // END - if - - // Fix length to 10 - if ($length == '0') { - $length = 10; - } // END - if - - // Generate a code until the length matches - $valCode = ''; - while (strlen($valCode) != $length) { - // Is the salt set? - if (empty($salt)) { - // Generate random hashed string - $GLOBALS['surfbar_cache']['salt'] = sha1(generatePassword(mt_rand(200, 255))); - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'newSalt='.SURFBAR_GET_SALT().'', false); - } else { - // Use this as salt! - $GLOBALS['surfbar_cache']['salt'] = $salt; - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'oldSalt='.SURFBAR_GET_SALT().'', false); - } - - // ... and now the validation code - $valCode = generateRandomCode($length, sha1(SURFBAR_GET_SALT() . getEncryptSeperator() . $urlId), getMemberId()); - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'valCode='.valCode.'', false); - } // END - while + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'urlId=' . $urlId . ',salt=' . $salt . ' - ENTERED!'); + // Init hash with invalid value + if (empty($salt)) { + // Generate random hashed string + $GLOBALS['surfbar_cache']['salt'] = sha1(generatePassword(mt_rand(200, 255))); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'newSalt='.SURFBAR_GET_SALT().'', false); + } else { + // Use this as salt! + $GLOBALS['surfbar_cache']['salt'] = $salt; + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'oldSalt='.SURFBAR_GET_SALT().'', false); + } // Hash it with md5() and salt it with the random string - $hashedCode = generateHash(md5($valCode), SURFBAR_GET_SALT()); + $hashedCode = generateHash(md5($urlId . getEncryptSeperator() . getMemberId()), SURFBAR_GET_SALT()); // Finally encrypt it PGP-like and return it $valHashedCode = encodeHashForCookie($hashedCode); // Return hashed value - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'finalValCode='.$valHashedCode.'', false); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'urlId=' . $urlId . ',salt=' . $salt . ',urlId=' . $urlId . ',salt=' . $salt . ',valHashedCode=' . $valHashedCode . ' - EXIT!'); return $valHashedCode; } // Check validation code function SURFBAR_CHECK_VALIDATION_CODE ($urlId, $check, $salt) { + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'urlId=' . $urlId . ',check=' . $check . ',salt=' . $salt . ' - ENTERED!'); // Secure id number $urlId = bigintval($urlId); @@ -1069,38 +1050,51 @@ function SURFBAR_CHECK_VALIDATION_CODE ($urlId, $check, $salt) { $code = SURFBAR_GENERATE_VALIDATION_CODE($urlId, $salt); // Return result of checking hashes and salts - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '---'.$code.'|'.$check.'---', false); - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '+++'.$salt.'|'.SURFBAR_GET_DATA('salts_last_salt').'+++', false); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'urlId=' . $urlId . ',(code==check)=' . intval($code == $check) . ',(salt==salts_last_salt)=' . intval($salt == SURFBAR_GET_DATA('salts_last_salt')) . ' - EXIT!'); return (($code == $check) && ($salt == SURFBAR_GET_DATA('salts_last_salt'))); } // Lockdown the userid/id combination (reload lock) function SURFBAR_LOCKDOWN_ID ($urlId) { - //* DEBUG: */ debugOutput('LOCK!'); - ///* DEBUG: */ return; - // Just add it to the database - SQL_QUERY_ESC('INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_locks` (`locks_userid`, `locks_url_id`) VALUES (%s, %s)', - array(getMemberId(), bigintval($urlId)), __FUNCTION__, __LINE__); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'urlId=' . $urlId . ',getMemberId()=' . getMemberId() . ' - ENTERED!'); + // Search for an entry + $countLock = countSumTotalData(getMemberId(), 'surfbar_locks', 'locks_id', 'locks_userid', true, ' AND `locks_url_id`=' . bigintval($urlId)); + + // Do we have no record? + if ($countLock == 0) { + // Just add it to the database + SQL_QUERY_ESC('INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_locks` (`locks_userid`, `locks_url_id`) VALUES (%s, %s)', + array( + getMemberId(), + bigintval($urlId) + ), __FUNCTION__, __LINE__); + } // END - if // Remove the salt from database SQL_QUERY_ESC('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_surfbar_salts` WHERE `salts_url_id`=%s AND `salts_userid`=%s LIMIT 1', - array(bigintval($urlId), getMemberId()), __FUNCTION__, __LINE__); + array( + bigintval($urlId), + getMemberId() + ), __FUNCTION__, __LINE__); + + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'urlId=' . $urlId . ',getMemberId()=' . getMemberId() . ',SQL_AFFECTEDROWS()=' . SQL_AFFECTEDROWS() . ' - EXIT!'); } // Pay points to the user and remove it from the sender if userid is given else it is a "sponsored surf" function SURFBAR_PAY_POINTS () { // Remove it from the URL owner - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.SURFBAR_GET_USERID().',costs='.SURFBAR_GET_COSTS().'', false); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.SURFBAR_GET_USERID().',costs='.SURFBAR_GET_COSTS() . ' - ENTERED!'); if (isValidUserId(SURFBAR_GET_USERID())) { subtractPoints(sprintf("surfbar_%s", getSurfbarPaymentModel()), SURFBAR_GET_USERID(), SURFBAR_GET_COSTS()); } // END - if - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.getMemberId().',reward='.SURFBAR_GET_REWARD().'', false); - // @TODO Try to rewrite the following unset() - unset($GLOBALS['ref_level']); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.getMemberId().',reward='.SURFBAR_GET_REWARD()); + // Init referal system here + initReferalSystem(); // Book it to the user addPointsThroughReferalSystem(sprintf("surfbar_%s", getSurfbarPaymentModel()), getMemberId(), SURFBAR_GET_REWARD()); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.SURFBAR_GET_USERID().',costs='.SURFBAR_GET_COSTS() . ' - EXIT!'); } // Updates the statistics of current URL/userid @@ -1150,12 +1144,18 @@ function SURFBAR_UPDATE_INSERT_STATS_RECORD () { // Update the salt for validation and statistics function SURFBAR_UPDATE_SALT_STATS () { - // Update statistics record - SURFBAR_UPDATE_INSERT_STATS_RECORD(); - // Update salt SURFBAR_GENERATE_VALIDATION_CODE(SURFBAR_GET_ID()); + // Make sure only valid salts can pass + if (SURFBAR_GET_SALT() == 'INVALID') { + // Invalid provided + debug_report_bug(__FUNCTION__, __LINE__, 'Invalid salt provided, id=' . SURFBAR_GET_ID() . ',getMemberId()=' . getMemberId()); + } // END - if + + // Update statistics record + SURFBAR_UPDATE_INSERT_STATS_RECORD(); + // Simply store the salt from cache away in database... SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_surfbar_salts` SET `salts_last_salt`='%s' WHERE `salts_url_id`=%s AND `salts_userid`=%s LIMIT 1", array( @@ -1165,17 +1165,21 @@ function SURFBAR_UPDATE_SALT_STATS () { ), __FUNCTION__, __LINE__); // Debug message - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'salt='.SURFBAR_GET_SALT().',id='.SURFBAR_GET_ID().',userid='.getMemberId().'', false); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'salt=' . SURFBAR_GET_SALT() . ',id=' . SURFBAR_GET_ID() . ',userid=' . getMemberId() . ',SQL_AFFECTEDROWS()=' . SQL_AFFECTEDROWS() . ' - UPDATE!'); // Was that okay? if (SQL_HASZEROAFFECTED()) { // Insert missing entry! SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_salts` (`salts_url_id`, `salts_userid`, `salts_last_salt`) VALUES (%s, %s, '%s')", - array(SURFBAR_GET_ID(), getMemberId(), SURFBAR_GET_SALT()), __FUNCTION__, __LINE__); + array( + SURFBAR_GET_ID(), + getMemberId(), + SURFBAR_GET_SALT() + ), __FUNCTION__, __LINE__); } // END - if // Debug message - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'affectedRows='.SQL_AFFECTEDROWS().'', false); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'affectedRows=' . SQL_AFFECTEDROWS() . ' - EXIT!'); // Return if the update was okay return (!SQL_HASZEROAFFECTED()); @@ -1183,7 +1187,7 @@ function SURFBAR_UPDATE_SALT_STATS () { // Check if the reload lock is active for given id function SURFBAR_CHECK_RELOAD_LOCK ($urlId) { - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $urlId . '', false); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $urlId . ' - ENTERED!'); // Ask the database $result = SQL_QUERY_ESC("SELECT COUNT(`locks_id`) AS cnt FROM @@ -1205,7 +1209,7 @@ LIMIT 1", SQL_FREERESULT($result); // Return check - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'cnt=' . $count . ',' . SURFBAR_GET_SURF_LOCK() . '', false); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'urlId=' . $urlId . ',count=' . $count . ',SURFBAR_GET_SURF_LOCK()=' . SURFBAR_GET_SURF_LOCK() . ' - EXIT!'); return ($count == 1); } @@ -1265,12 +1269,12 @@ ORDER BY while ($content = SQL_FETCHARRAY($result)) { // Get total points $points = getTotalPoints($content['url_userid']); - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $content['url_userid'] . ',points=' . $points); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $content['url_userid'] . ',points=' . $points); // Shall we add this to ignore? if ($points <= $limit) { // Ignore this one! - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $content['url_userid'] . ' has depleted points amount!'); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $content['url_userid'] . ' has depleted points amount!'); $userids['url_userid'][$content['url_userid']] = $content['url_userid']; $userids['points'][$content['url_userid']] = $points; $userids['notified'][$content['url_userid']] = $content['notified']; @@ -1281,7 +1285,7 @@ ORDER BY SQL_FREERESULT($result); // Debug message - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'UIDs::count=' . count($userids) . ' (with own userid=' . getMemberId() . ')'); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'UIDs::count=' . count($userids) . ' (with own userid=' . getMemberId() . ')'); // Return result return $userids; @@ -1335,7 +1339,7 @@ function SURFBAR_DETERMINE_WAIT_TIME () { // Changes the status of an URL from given to other function SURFBAR_CHANGE_STATUS ($urlId, $prevStatus, $newStatus, $data=array()) { - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'urlId=' . $urlId . ',prevStatus=' . $prevStatus . ',newStatus=' . $newStatus . ' - ENTERED!'); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'urlId=' . $urlId . ',prevStatus=' . $prevStatus . ',newStatus=' . $newStatus . ' - ENTERED!'); // Make new status always lower-case $newStatus = strtolower($newStatus); @@ -1387,7 +1391,7 @@ function SURFBAR_CHANGE_STATUS ($urlId, $prevStatus, $newStatus, $data=array()) $data = $filterData['data']; // All done! - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'urlId=' . $urlId . ',prevStatus=' . $prevStatus . ',newStatus=' . $newStatus . ' - EXIT!'); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'urlId=' . $urlId . ',prevStatus=' . $prevStatus . ',newStatus=' . $newStatus . ' - EXIT!'); return true; } @@ -1475,7 +1479,10 @@ function SURFBAR_GET_LOCK_IDS () { $ignored = array(); // Get all id from locks within the timestamp - $result = SQL_QUERY_ESC("SELECT `locks_id`, `locks_url_id`, UNIX_TIMESTAMP(`locks_last_surfed`) AS last_surfed + $result = SQL_QUERY_ESC("SELECT + `locks_id`, + `locks_url_id`, + UNIX_TIMESTAMP(`locks_last_surfed`) AS `last_surfed` FROM `{?_MYSQL_PREFIX?}_surfbar_locks` WHERE @@ -1487,30 +1494,30 @@ ORDER BY // Load all entries while ($content = SQL_FETCHARRAY($result)) { // Debug message - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'next - lid='.$content['id'].',url='.$content['url_id'].',rest='.(time() - $content['last_surfed']).'/'.SURFBAR_GET_SURF_LOCK().'', false); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'next - lid='.$content['locks_id'].',url='.$content['locks_url_id'].',rest='.(time() - $content['last_surfed']).'/'.SURFBAR_GET_SURF_LOCK()); // Skip entries that are too old - if (($content['last_surfed'] > (time() - SURFBAR_GET_SURF_LOCK())) && (!in_array($content['url_id'], $ignored))) { + if (($content['last_surfed'] > (time() - SURFBAR_GET_SURF_LOCK())) && (!in_array($content['locks_url_id'], $ignored))) { // Debug message - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'okay - lid='.$content['id'].',url='.$content['url_id'].',last='.$content['last_surfed'].'', false); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'okay - lid='.$content['locks_id'].',url='.$content['locks_url_id'].',last='.$content['last_surfed']); // Add only if missing or bigger - if ((!isset($IDs[$content['url_id']])) || ($IDs[$content['url_id']] > $content['last_surfed'])) { + if ((!isset($IDs[$content['locks_url_id']])) || ($IDs[$content['locks_url_id']] > $content['last_surfed'])) { // Debug message - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ADD - lid='.$content['id'].',url='.$content['url_id'].',last='.$content['last_surfed'].'', false); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ADD - lid='.$content['locks_id'].',url='.$content['locks_url_id'].',last='.$content['last_surfed']); // Add this id - $IDs[$content['url_id']] = $content['last_surfed']; - $USE[$content['url_id']] = $content['id']; + $IDs[$content['locks_url_id']] = $content['last_surfed']; + $USE[$content['locks_url_id']] = $content['locks_id']; } // END - if } else { // Debug message - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ignore - lid='.$content['id'].',url='.$content['url_id'].',last='.$content['last_surfed'].'', false); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ignore - lid='.$content['locks_id'].',url='.$content['locks_url_id'].',last='.$content['last_surfed']); // Ignore these old entries! - $ignored[] = $content['url_id']; - unset($IDs[$content['url_id']]); - unset($USE[$content['url_id']]); + $ignored[] = $content['locks_url_id']; + unset($IDs[$content['locks_url_id']]); + unset($USE[$content['locks_url_id']]); } } // END - while @@ -1545,7 +1552,7 @@ GROUP BY sbu.url_id ASC", __FUNCTION__, __LINE__); // Log last query - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'lastQuery='.getConfig('db_last_query').'|numRows='.SQL_NUMROWS($result).'|Affected='.SQL_AFFECTEDROWS().'', false); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'lastQuery='.getConfig('db_last_query').'|numRows='.SQL_NUMROWS($result).'|Affected='.SQL_AFFECTEDROWS()); // Fetch max rand $maxRand = SQL_NUMROWS($result); @@ -1627,6 +1634,7 @@ function SURFBAR_GET_ARRAY_FROM_STATUS ($status) { // Reload to configured stop page function SURFBAR_RELOAD_TO_STOP_PAGE ($page = 'stop') { // Internal or external? + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'page=' . $page . ' - ENTERED!'); if ((getConfig('surfbar_pause_mode') == 'INTERNAL') || (getConfig('surfbar_pause_url') == '')) { // Reload to internal page redirectToUrl('surfbar.php?frame=' . $page); @@ -1639,6 +1647,7 @@ function SURFBAR_RELOAD_TO_STOP_PAGE ($page = 'stop') { // Determine next id for surfbar or get data for given id, always call this before you call other // getters below this function! function SURFBAR_DETERMINE_NEXT_ID ($urlId = '0') { + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'urlId=' . $urlId . ' - ENTERED!'); // Default is no id and no random number $nextId = '0'; $randNum = '0'; @@ -1675,7 +1684,7 @@ function SURFBAR_DETERMINE_NEXT_ID ($urlId = '0') { } // END - if // And query the database - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'randNum='.$randNum.',maxRand='.$maxRand.',surfLock='.SURFBAR_GET_SURF_LOCK().'', false); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'randNum='.$randNum.',maxRand='.$maxRand.',surfLock='.SURFBAR_GET_SURF_LOCK()); $result = SQL_QUERY_ESC("SELECT sbu.url_id, sbu.url_userid, @@ -1742,12 +1751,12 @@ LIMIT 1", } // Is there an id number? - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'lastQuery='.getConfig('db_last_query').'|numRows='.SQL_NUMROWS($result).'|Affected='.SQL_AFFECTEDROWS().'', false); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'lastQuery='.getConfig('db_last_query').'|numRows='.SQL_NUMROWS($result).'|Affected='.SQL_AFFECTEDROWS()); if (SQL_NUMROWS($result) == 1) { // Load/cache data - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'count('.count($GLOBALS['surfbar_cache']).') - BEFORE', false); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'count('.count($GLOBALS['surfbar_cache']).') - BEFORE', false); $GLOBALS['surfbar_cache'] = merge_array($GLOBALS['surfbar_cache'], SQL_FETCHARRAY($result)); - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'count('.count($GLOBALS['surfbar_cache']).') - AFTER', false); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'count('.count($GLOBALS['surfbar_cache']).') - AFTER', false); // Determine waiting time $GLOBALS['surfbar_cache']['time'] = SURFBAR_DETERMINE_WAIT_TIME(); @@ -1755,28 +1764,28 @@ LIMIT 1", // Is the last salt there? if (is_null($GLOBALS['surfbar_cache']['salts_last_salt'])) { // Then repair it wit the static! - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'last_salt - FIXED!', false); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'last_salt - FIXED!', false); $GLOBALS['surfbar_cache']['salts_last_salt'] = ''; } // END - if // Fix missing last_surfed if ((!isset($GLOBALS['surfbar_cache']['last_surfed'])) || (is_null($GLOBALS['surfbar_cache']['last_surfed']))) { // Fix it here - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'last_surfed - FIXED!', false); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'last_surfed - FIXED!', false); $GLOBALS['surfbar_cache']['last_surfed'] = '0'; } // END - if // Get base/fixed reward and costs $GLOBALS['surfbar_cache']['reward'] = SURFBAR_DETERMINE_REWARD(); $GLOBALS['surfbar_cache']['costs'] = SURFBAR_DETERMINE_COSTS(); - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'BASE/STATIC - reward='.SURFBAR_GET_REWARD().'|costs='.SURFBAR_GET_COSTS().'', false); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'BASE/STATIC - reward='.SURFBAR_GET_REWARD().'|costs='.SURFBAR_GET_COSTS()); // Only in dynamic model add the dynamic bonus! if (getSurfbarPaymentModel() == 'DYNAMIC') { // Calculate dynamic reward/costs and add it $GLOBALS['surfbar_cache']['reward'] += SURFBAR_CALCULATE_DYNAMIC_ADD(); $GLOBALS['surfbar_cache']['costs'] += SURFBAR_CALCULATE_DYNAMIC_ADD(); - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'DYNAMIC+ - reward='.SURFBAR_GET_REWARD().'|costs='.SURFBAR_GET_COSTS().'', false); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'DYNAMIC+ - reward='.SURFBAR_GET_REWARD().'|costs='.SURFBAR_GET_COSTS()); } // END - if // Now get the id @@ -1787,7 +1796,7 @@ LIMIT 1", SQL_FREERESULT($result); // Return result - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'nextId='.$nextId.'', false); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'urlId=' . $urlId . ',nextId=' . $nextId . ' - EXIT!'); return $nextId; } @@ -1868,7 +1877,7 @@ function SURFBAR_INIT () { // Private getter for data elements function SURFBAR_GET_DATA ($element) { - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element=' . $element . ' - CALLED!'); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element=' . $element . ' - ENTERED!'); // Default is null $data = null; @@ -1885,7 +1894,7 @@ function SURFBAR_GET_DATA ($element) { } // Return result - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element[' . $element . ']=[' . gettype($data) . ']' . $data . ' - EXIT!'); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element[' . $element . ']=[' . gettype($data) . ']' . $data . ' - EXIT!'); return $data; } @@ -1967,5 +1976,11 @@ function SURFBAR_GET_NEW_STATUS () { return SURFBAR_GET_DATA('new_status'); } +// Getter for last salt +function SURFBAR_GET_LAST_SALT () { + // Get data element and return its contents + return SURFBAR_GET_DATA('salts_last_salt'); +} + // [EOF] ?> diff --git a/inc/libs/user_functions.php b/inc/libs/user_functions.php index 18b0cd64c4..09dc679ba2 100644 --- a/inc/libs/user_functions.php +++ b/inc/libs/user_functions.php @@ -43,8 +43,8 @@ if (!defined('__SECURITY')) { // Add links for selecting some users function alpha ($sortby, $colspan, $return=false) { if (!isGetRequestParameterSet('offset')) setGetRequestParameter('offset', 0); - $add = '&page='.getRequestParameter('page').'&offset='.getRequestParameter('offset'); - if (isGetRequestParameterSet('mode')) $add .= '&mode='.getRequestParameter('mode'); + $add = '&page=' . getRequestParameter('page').'&offset=' . getRequestParameter('offset'); + if (isGetRequestParameterSet('mode')) $add .= '&mode=' . getRequestParameter('mode'); /* Creates the list of letters and makes them a link. */ $alphabet = explode(',', 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,'); @@ -588,7 +588,6 @@ function doConfirmUserAccount ($hash) { `{?_MYSQL_PREFIX?}_user_data` SET `status`='CONFIRMED', - `ref_payout`={?ref_payout?}, `user_hash`=NULL WHERE `user_hash`='%s' AND @@ -622,8 +621,7 @@ LIMIT 1", } // END - if // Add one-time referal bonus over referal system or directly - // @TODO Try to rewrite the following unset() - unset($GLOBALS['ref_level']); + initReferalSystem(); addPointsThroughReferalSystem('referal_bonus', $refid, getPointsRef(), true, bigintval($userid), getConfig('reg_points_mode')); } // END - if } // END - if diff --git a/inc/modules/admin/admin-inc.php b/inc/modules/admin/admin-inc.php index d762abd90d..f8017ebbef 100644 --- a/inc/modules/admin/admin-inc.php +++ b/inc/modules/admin/admin-inc.php @@ -787,6 +787,15 @@ function sendAdminBuildMails ($mode, $table, $content, $id, $subjectPart = '', $ // Build a special template list function adminListBuilder ($listType, $IDs, $table, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $userid = 'userid') { + // $table and $idColumn must bove be arrays! + if (!is_array($table)) { + // $table is no array + debug_report_bug(__FUNCTION__, __LINE__, 'table[]=' . gettype($table) . '!=array'); + } elseif (!is_array($idColumn)) { + // $idColumn is no array + debug_report_bug(__FUNCTION__, __LINE__, 'idColumn[]=' . gettype($idColumn) . '!=array'); + } + $OUT = ''; // "Walk" through all entries @@ -795,7 +804,7 @@ function adminListBuilder ($listType, $IDs, $table, $columns, $filterFunctions, $id = bigintval($id); // Get result from a given column array and table name - $result = SQL_RESULT_FROM_ARRAY($table, $columns, $idColumn, $id, __FUNCTION__, __LINE__); + $result = SQL_RESULT_FROM_ARRAY($table[0], $columns, $idColumn[0], $id, __FUNCTION__, __LINE__); // Is there one entry? if (SQL_NUMROWS($result) == 1) { @@ -833,7 +842,7 @@ function adminListBuilder ($listType, $IDs, $table, $columns, $filterFunctions, // Then list it $OUT .= loadTemplate(sprintf("admin_%s_%s_row", $listType, - $table + $table[0] ), true, $content ); } // END - if @@ -845,7 +854,7 @@ function adminListBuilder ($listType, $IDs, $table, $columns, $filterFunctions, // Load master template loadTemplate(sprintf("admin_%s_%s", $listType, - $table + $table[0] ), false, $OUT ); } diff --git a/inc/modules/guest/what-register.php b/inc/modules/guest/what-register.php index 5016b33538..5ea1ecd0ab 100644 --- a/inc/modules/guest/what-register.php +++ b/inc/modules/guest/what-register.php @@ -70,7 +70,7 @@ if ((isFormSent()) && (isRegistrationDataComplete())) { registerOutputFailedMessage('ENTER_EMAIL'); setPostRequestParameter('email', ''); } elseif (postRequestParameter('email') == '?') { - registerOutputFailedMessage('GUEST_EMAIL_ALREADY_DB'); + registerOutputFailedMessage('GUEST_EMAIL_IS_ALREADY_REGISTERED'); setPostRequestParameter('email', ''); } diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php index afed52db34..177da67eb5 100644 --- a/inc/mysql-manager.php +++ b/inc/mysql-manager.php @@ -1024,6 +1024,13 @@ function getReferalLevelPercents ($level) { return $data['percents']; } +// Initializes the referal system +function initReferalSystem () { + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ' Referal system initialized!'); + $GLOBALS['ref_level'] = NULL; + $GLOBALS['ref_system'] = true; +} + /** * * Dynamic referal and points system, can also send mails! @@ -1038,7 +1045,7 @@ function getReferalLevelPercents ($level) { * for default value will cause no referal will get points ever!!!) */ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify = false, $refid = '0', $addMode = 'REFERAL') { - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'subject=' . $subject . ',userid=' . $userid . ',points=' . $points . ',sendNotify=' . intval($sendNotify) . ',refid=' . $refid . ',addMode=' . $addMode . ' - ENTERED!'); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'subject=' . $subject . ',userid=' . $userid . ',points=' . $points . ',sendNotify=' . intval($sendNotify) . ',refid=' . $refid . ',addMode=' . $addMode . ' - ENTERED!'); // By default nothing has been added $added = false; @@ -1046,24 +1053,13 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify $addMode = strtoupper($addMode); // When $userid = '0' add points to jackpot - if (($userid == '0') && (isExtensionActive('jackpot'))) { - // Add points to jackpot + if (($userid == '0') && ($addMode == 'DIRECT') && (isExtensionActive('jackpot'))) { + // Add points to jackpot only in DIRECT mode return addPointsToJackpot($points); } // END - if - // Count up referal depth - if (!isset($GLOBALS['ref_level'])) { - // Initialialize referal system - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ' Referal system initialized!'); - $GLOBALS['ref_level'] = NULL; - } else { - // Increase referal level - $GLOBALS['ref_level']++; - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ' Referal level increased. DEPTH='.$GLOBALS['ref_level']); - } - // Check user account - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.$userid.',points='.$points); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.$userid.',points='.$points); if (fetchUserData($userid)) { // Determine wether the user has some mails to click before he/she gets the points $locked = ifUserPointsLocked($userid); @@ -1076,31 +1072,43 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify // Get percents $per = getReferalLevelPercents($GLOBALS['ref_level']); - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.$userid.',points='.$points.',depth='.$GLOBALS['ref_level'].',per='.$per.',mode='.$addMode); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.$userid.',points='.$points.',depth='.$GLOBALS['ref_level'].',per='.$per.',mode='.$addMode); // Some percents found? if ($per > 0) { // Calculate new points - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.$userid.',points='.$points.',per='.$per.',depth='.$GLOBALS['ref_level']); $ref_points = $points * $per / 100; + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.$userid.',points='.$points.',per='.$per.',depth='.$GLOBALS['ref_level'].',ref_points='.$ref_points); // Pay refback here if level > 0 and in ref-mode if ((isExtensionActive('refback')) && ($GLOBALS['ref_level'] > 0) && ($per < 100) && ($addMode == 'REFERAL') && (isset($GLOBALS['cache_array']['add_userid'][$userid]))) { - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.$userid.',data='.$GLOBALS['cache_array']['add_userid'][$userid].',ref_points='.$ref_points.',depth='.$GLOBALS['ref_level'].' - BEFORE!'); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.$userid.',data='.$GLOBALS['cache_array']['add_userid'][$userid].',ref_points='.$ref_points.',depth='.$GLOBALS['ref_level'].' - BEFORE!'); $ref_points = addRefbackPoints($GLOBALS['cache_array']['add_userid'][$userid], $userid, $points, $ref_points); - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.$userid.',data='.$GLOBALS['cache_array']['add_userid'][$userid].',ref_points='.$ref_points.',depth='.$GLOBALS['ref_level'].' - AFTER!'); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.$userid.',data='.$GLOBALS['cache_array']['add_userid'][$userid].',ref_points='.$ref_points.',depth='.$GLOBALS['ref_level'].' - AFTER!'); } // 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( - $pointsColumn, - $pointsColumn, - $ref_points, - bigintval($userid), - makeZeroToNull($GLOBALS['ref_level']) - ), __FUNCTION__, __LINE__); - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'pointsColumn='.$pointsColumn.',ref_points='.$ref_points.',userid='.$userid.',depth='.$GLOBALS['ref_level'].',mode='.$addMode.' - UPDATE! ('.SQL_AFFECTEDROWS().')'); + if (is_null($GLOBALS['ref_level'])) { + // Level NULL (self) + SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_points` SET `%s`=`%s`+%s WHERE `userid`=%s AND `ref_depth` IS NULL LIMIT 1", + array( + $pointsColumn, + $pointsColumn, + $ref_points, + bigintval($userid) + ), __FUNCTION__, __LINE__); + } else { + // Level 1+ + SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_points` SET `%s`=`%s`+%s WHERE `userid`=%s AND `ref_depth`=%s LIMIT 1", + array( + $pointsColumn, + $pointsColumn, + $ref_points, + bigintval($userid), + bigintval($GLOBALS['ref_level']) + ), __FUNCTION__, __LINE__); + } + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'pointsColumn='.$pointsColumn.',ref_points='.$ref_points.',userid='.$userid.',depth='.$GLOBALS['ref_level'].',mode='.$addMode.' - UPDATE! ('.SQL_AFFECTEDROWS().')'); // No entry updated? if (SQL_HASZEROAFFECTED()) { @@ -1112,12 +1120,12 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify makeZeroToNull($GLOBALS['ref_level']), $ref_points ), __FUNCTION__, __LINE__); - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'data='.$pointsColumn.',ref_points='.$ref_points.',userid='.$userid.',depth='.$GLOBALS['ref_level'].',mode='.$addMode.' - INSERTED! ('.SQL_AFFECTEDROWS().')'); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'data='.$pointsColumn.',ref_points='.$ref_points.',userid='.$userid.',depth='.$GLOBALS['ref_level'].',mode='.$addMode.' - INSERTED! ('.SQL_AFFECTEDROWS().')'); } // END - if // Check affected rows $added = SQL_AFFECTEDROWS(); - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'added='.intval($added)); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'added='.intval($added)); // Prepare data for the filter $filterData = array( @@ -1139,7 +1147,7 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify // Extract $added $added = $filterData['added']; - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'added='.intval($added)); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'added='.intval($added)); // Points updated, maybe I shall send him an email? if (($sendNotify === true) && (isValidUserId(getUserData('refid'))) && ($locked === false)) { @@ -1173,42 +1181,51 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify } // END - if } + // Increase referal level + $GLOBALS['ref_level']++; + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ' Referal level increased, ref_level=' . $GLOBALS['ref_level']); + // Maybe there's another ref? if ((isValidUserId(getUserData('refid'))) && ($points > 0) && (getUserData('refid') != $userid) && ($addMode == 'REFERAL')) { // Then let's credit him here... - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.$userid.',ref='.getUserData('refid').',points='.$points.' - ADVANCE!'); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',refid=' . getUserData('refid') . ',points=' . $points . ',ref_points=' . $ref_points . ' - ADVANCE!'); $added = ($added && addPointsThroughReferalSystem(sprintf("%s_ref:%s", $subject, $GLOBALS['ref_level']), getUserData('refid'), $points, $sendNotify, getUserData('refid'))); } // END - if } // END - if } // END - if - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'subject=' . $subject . ',userid=' . $userid . ',points=' . $points . ',sendNotify=' . intval($sendNotify) . ',refid=' . $refid . ',addMode=' . $addMode . ' - EXIT!'); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'subject=' . $subject . ',userid=' . $userid . ',points=' . $points . ',sendNotify=' . intval($sendNotify) . ',refid=' . $refid . ',addMode=' . $addMode . ' - EXIT!'); return $added; } // Updates the referal counter function updateReferalCounter ($userid) { // Make it sure referal level zero (member him-/herself) is at least selected - if (empty($GLOBALS['cache_array']['ref_level'][$userid])) $GLOBALS['cache_array']['ref_level'][$userid] = 1; + if (empty($GLOBALS['cache_array']['ref_level'][$userid])) { + $GLOBALS['cache_array']['ref_level'][$userid] = NULL; + } // END - if //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.$userid.',level='.$GLOBALS['cache_array']['ref_level'][$userid]); // Update counter - SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_refsystem` SET `counter`=`counter`+1 WHERE `userid`=%s AND `level`=%s LIMIT 1", - array( - bigintval($userid), - bigintval($GLOBALS['cache_array']['ref_level'][$userid]) - ), __FUNCTION__, __LINE__); - - // When no entry was updated then we have to create it here - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'updated=' . SQL_AFFECTEDROWS()); - if (SQL_HASZEROAFFECTED()) { - // First count! - SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_refsystem` (`userid`, `level`, `counter`) VALUES (%s,%s,1)", + if (!is_null($GLOBALS['cache_array']['ref_level'][$userid])) { + // Level is > 0 + SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_refsystem` SET `counter`=`counter`+1 WHERE `userid`=%s AND `level`=%s LIMIT 1", array( - bigintval($userid), - $GLOBALS['cache_array']['ref_level'][$userid] + bigintval($userid), + bigintval($GLOBALS['cache_array']['ref_level'][$userid]) ), __FUNCTION__, __LINE__); - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.$userid); + + // When no entry was updated then we have to create it here + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'updated=' . SQL_AFFECTEDROWS()); + if (SQL_HASZEROAFFECTED()) { + // First count! + SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_refsystem` (`userid`, `level`, `counter`) VALUES (%s,%s,1)", + array( + bigintval($userid), + makeZeroToNull($GLOBALS['cache_array']['ref_level'][$userid]) + ), __FUNCTION__, __LINE__); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',SQL_AFFECTEDROWS()=' . SQL_AFFECTEDROWS()); + } // END - if } // END - if // Init referal id @@ -1871,7 +1888,9 @@ function generateReceiverList ($categoryId, $receiver, $mode = '') { // Load all entries while ($content = SQL_FETCHARRAY($result)) { // Add receiver when not empty - if (!empty($content['userid'])) $receiverList .= $content['userid'] . ';'; + if (!empty($content['userid'])) { + $receiverList .= $content['userid'] . ';'; + } // END - if } // END - while // Free memory diff --git a/inc/template-functions.php b/inc/template-functions.php index db267b1137..10e1240b1d 100644 --- a/inc/template-functions.php +++ b/inc/template-functions.php @@ -217,6 +217,9 @@ function doFinalCompilation ($code, $insertComments = true, $enableCodes = true) // Init counter $count = 0; + // Compile the raw code + $code = compileRawCode($code); + // Compile all out while (((strpos($code, '{--') !== false) || (strpos($code, '{DQUOTE}') !== false) || (strpos($code, '{?') !== false) || (strpos($code, '{%') !== false)) && ($count < 7)) { // Init common variables @@ -1693,8 +1696,8 @@ function generateMetaDescriptionCode () { $GLOBALS['page_header'] .= ''; } // END - if - // Remove depth - unset($GLOBALS['ref_level']); + // Initialize referal system + initReferalSystem(); } // Generates an FQFN for template cache from the given template name diff --git a/inc/wrapper-functions.php b/inc/wrapper-functions.php index a89c49a676..16b10bcb27 100644 --- a/inc/wrapper-functions.php +++ b/inc/wrapper-functions.php @@ -744,7 +744,7 @@ function isBlockModeEnabled () { // Wrapper function for addPointsThroughReferalSystem() function addPointsDirectly ($subject, $userid, $points) { // Reset level here - unset($GLOBALS['ref_level']); + initReferalSystem(); // Call more complicated method (due to more parameters) return addPointsThroughReferalSystem($subject, $userid, $points, false, 0, 'DIRECT'); @@ -1052,6 +1052,7 @@ function isDebuggingTemplateCache () { // Wrapper for fetchUserData() and getUserData() calls function getFetchedUserData ($keyColumn, $userid, $valueColumn) { + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyColumn=' . $keyColumn . ',userid=' . $userid . ',valueColumn=' . $valueColumn . ' - ENTERED!'); // Is it cached? if (!isset($GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn])) { // Default is 'guest' @@ -1068,6 +1069,7 @@ function getFetchedUserData ($keyColumn, $userid, $valueColumn) { } // END - if // Return it + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyColumn=' . $keyColumn . ',userid=' . $userid . ',valueColumn=' . $valueColumn . ',value=' . $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] . ' - EXIT!'); return $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn]; } @@ -2469,6 +2471,7 @@ function generateWrappedUserEmailLink ($email) { // Wrapper to check if user points are locked function ifUserPointsLocked ($userid) { + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ENTERED!'); // Do we have cache? if (!isset($GLOBALS[__FUNCTION__][$userid])) { // Determine it @@ -2476,6 +2479,7 @@ function ifUserPointsLocked ($userid) { } // END - if // Return cache + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',locked=' . intval($GLOBALS[__FUNCTION__][$userid]) . ' - EXIT!'); return $GLOBALS[__FUNCTION__][$userid]; } diff --git a/mailid_top.php b/mailid_top.php index 2f04e4caeb..68aff4de92 100644 --- a/mailid_top.php +++ b/mailid_top.php @@ -258,8 +258,7 @@ if ((isValidUserId($userId)) && (($mailId > 0) || ($bonusId > 0)) && (!ifFatalEr array($userId), __FILE__, __LINE__); // Add points - // @TODO Try to rewrite the following unset() - unset($GLOBALS['ref_level']); + initReferalSystem(); addPointsThroughReferalSystem('mailid_okay', $userId, $payment); // Shall I add bonus points for "turbo clickers" ? diff --git a/surfbar.php b/surfbar.php index ae3fd6fd8c..8ad2c2af01 100644 --- a/surfbar.php +++ b/surfbar.php @@ -163,6 +163,9 @@ if ((SURFBAR_CHECK_RELOAD_FULL()) || ((isGetRequestParameterSet('frame')) && (in // Then load waiting page SURFBAR_RELOAD_TO_STOP_PAGE(); } // END - if + + // Load header to avoid a bug + loadIncludeOnce('inc/header.php'); } else { // Reload to stop frame! SURFBAR_RELOAD_TO_STOP_PAGE(); diff --git a/templates/de/html/js/js_surfbar_frame_top.tpl b/templates/de/html/js/js_surfbar_frame_top.tpl index b5cabc4564..1126345eb5 100644 --- a/templates/de/html/js/js_surfbar_frame_top.tpl +++ b/templates/de/html/js/js_surfbar_frame_top.tpl @@ -27,7 +27,7 @@ function init () { function confirm () { if (parent.surfbar_url != null) { // Is in right frameset - parent.surfbar_url.location.href = "{%url=surfbar.php?id=$content[url_id]&check={%pipe,SURFBAR_GENERATE_VALIDATION_CODE=$content[url_id]%}&salt={%pipe,SURFBAR_GET_SALT%}%}"; + parent.surfbar_url.location.href = "{%url=surfbar.php?id=$content[url_id]&check=$content[check]&salt=$content[salt]%}"; } else { // Called frame=top directly window.location.href = "{%url=surfbar.php%}"; -- 2.39.5