X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Fmysql-manager.php;h=15a1126c27fbe6fb653f4e6098cf3f0895b892e2;hp=7436f55ae7df70374dc711c1b3516edb5f2e1060;hb=0ee18ff2f17d096211666727d9e47f1528a4d885;hpb=db0c6702086eea2c44d0aae1702dc2e77a0afc4e diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php index 7436f55ae7..15a1126c27 100644 --- a/inc/mysql-manager.php +++ b/inc/mysql-manager.php @@ -108,8 +108,8 @@ function addYouAreHereLink ($accessLevel, $FQFN, $return = false) { $dummy = substr($search, 0, -4); $ADD .= sprintf(" AND `action`='%s'", getActionFromModuleWhat($accessLevel, $dummy)); - } elseif (($accessLevel == 'sponsor') || ($accessLevel == 'engine')) { - // Sponsor / engine menu + } elseif ($accessLevel == 'sponsor') { + // Sponsor menu $type = 'what'; $search = $file; $modCheck = getModule(); @@ -260,7 +260,7 @@ ORDER BY $OUT .= ''; } else { // Not found - open - $OUT .= ''; + $OUT .= ''; } // Menu title @@ -427,19 +427,19 @@ function isMember () { } // Fetch user data for given user id -function fetchUserData ($userid, $column = 'userid') { +function fetchUserData ($value, $column = 'userid') { // If we should look for userid secure&set it here if (substr($column, -2, 2) == 'id') { // Secure userid - $userid = bigintval($userid); + $value = bigintval($value); // Set it here - setCurrentUserId($userid); + setCurrentUserId($value); // Don't look for invalid userids... - if (!isValidUserId($userid)) { + if (!isValidUserId($value)) { // Invalid, so abort here - debug_report_bug(__FUNCTION__, __LINE__, 'User id ' . $userid . ' is invalid.'); + debug_report_bug(__FUNCTION__, __LINE__, 'User id ' . $value . ' is invalid.'); } elseif (isUserDataValid()) { // Use cache, so it is fine return true; @@ -454,11 +454,13 @@ function fetchUserData ($userid, $column = 'userid') { // Extra statements $ADD = ''; - if (isExtensionInstalledAndNewer('user', '0.3.5')) $ADD = ', UNIX_TIMESTAMP(`lock_timestamp`) AS `lock_timestamp`'; + if (isExtensionInstalledAndNewer('user', '0.3.5')) { + $ADD = ', UNIX_TIMESTAMP(`lock_timestamp`) AS `lock_timestamp`'; + } // END - if // Query for the user $result = SQL_QUERY_ESC("SELECT *".$ADD." FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `%s`='%s' LIMIT 1", - array($column, $userid), __FUNCTION__, __LINE__); + array($column, $value), __FUNCTION__, __LINE__); // Do we have a record? if (SQL_NUMROWS($result) == 1) { @@ -467,6 +469,8 @@ function fetchUserData ($userid, $column = 'userid') { // Set the userid for later use setCurrentUserId($data['userid']); + + // And cache the data for this userid $GLOBALS['user_data'][getCurrentUserId()] = $data; // Rewrite 'last_failure' if found and ext-user has version >= 0.3.7 @@ -835,7 +839,7 @@ function getPaymentTitlePrice ($pid, $full=false) { // Get (basicly) the price of given payment id function getPaymentPoints ($pid, $lookFor = 'price') { // Default value... - $data[$lookFor] = '-1'; + $data[$lookFor] = -1; // Search for it in database $result = SQL_QUERY_ESC("SELECT `%s` FROM `{?_MYSQL_PREFIX?}_payments` WHERE `id`=%s LIMIT 1", @@ -992,7 +996,7 @@ function getReferalLevelPercents ($level) { /** * - * Dynamic referal system, can also send mails! + * Dynamic referal and points system, can also send mails! * * subject = Subject line, write in lower-case letters and underscore is allowed * userid = Referal id wich should receive... @@ -1003,19 +1007,18 @@ function getReferalLevelPercents ($level) { * add_mode = Add points only to $userid or also refs? (WARNING! Changing 'ref' to 'direct' * for default value will cause no referal will get points ever!!!) */ -function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify = false, $refid = '0', $add_mode = 'ref') { +function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify = false, $refid = '0', $addMode = 'ref') { // By default nothing has been added $added = false; //* DEBUG: */ debugOutput('----------------------- ' . __FUNCTION__ . ' - ENTRY ------------------------
  • '); // Convert mode to lower-case - $add_mode = strtolower($add_mode); + $addMode = strtolower($addMode); // When $userid = '0' add points to jackpot if (($userid == '0') && (isExtensionActive('jackpot'))) { // Add points to jackpot - addPointsToJackpot($points); - return; + return addPointsToJackpot($points); } // END - if // Count up referal depth @@ -1035,20 +1038,15 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify // Determine wether the user has some mails to click before he/she gets the points $locked = ifUserPointsLocked($userid); - // Default is 'normal' points - $data = 'points'; - - // Which points, locked or normal? - if ($locked === true) { - $data = 'locked_points'; - } // END - if + // Detect database column + $pointsColumn = determinePointsColumnFromSubjectLocked($subject, $locked); // This is the user and his ref $GLOBALS['cache_array']['add_userid'][getUserData('refid')] = $userid; // Get percents $per = getReferalLevelPercents($GLOBALS['ref_level']); - //* DEBUG: */ debugOutput(__FUNCTION__ . '(' . __LINE__ . '):userid='.$userid.',points='.$points.',depth='.$GLOBALS['ref_level'].',per='.$per.',mode='.$add_mode); + //* DEBUG: */ debugOutput(__FUNCTION__ . '(' . __LINE__ . '):userid='.$userid.',points='.$points.',depth='.$GLOBALS['ref_level'].',per='.$per.',mode='.$addMode); // Some percents found? if ($per > 0) { @@ -1057,7 +1055,7 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify $ref_points = $points * $per / 100; // Pay refback here if level > 0 and in ref-mode - if ((isExtensionActive('refback')) && ($GLOBALS['ref_level'] > 0) && ($per < 100) && ($add_mode == 'ref') && (isset($GLOBALS['cache_array']['add_userid'][$userid]))) { + if ((isExtensionActive('refback')) && ($GLOBALS['ref_level'] > 0) && ($per < 100) && ($addMode == 'ref') && (isset($GLOBALS['cache_array']['add_userid'][$userid]))) { //* DEBUG: */ debugOutput(__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: */ debugOutput(__FUNCTION__ . '(' . __LINE__ . '):userid='.$userid.',data='.$GLOBALS['cache_array']['add_userid'][$userid].',ref_points='.$ref_points.',depth='.$GLOBALS['ref_level'].' - AFTER!'); @@ -1065,15 +1063,26 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify // Update points... SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_points` SET `%s`=`%s`+%s WHERE `userid`=%s AND `ref_depth`=%s LIMIT 1", - array($data, $data, $ref_points, bigintval($userid), bigintval($GLOBALS['ref_level'])), __FUNCTION__, __LINE__); - //* DEBUG: */ debugOutput(__FUNCTION__ . '(' . __LINE__ . '):data='.$data.',ref_points='.$ref_points.',userid='.$userid.',depth='.$GLOBALS['ref_level'].',mode='.$add_mode.' - UPDATE! ('.SQL_AFFECTEDROWS().')'); + array( + $pointsColumn, + $pointsColumn, + $ref_points, + bigintval($userid), + bigintval($GLOBALS['ref_level']) + ), __FUNCTION__, __LINE__); + //* DEBUG: */ debugOutput(__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()) { // First ref in this level! :-) - SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_points` (`userid`,`ref_depth`,`%s`) VALUES (%s,%s,%s)", - array($data, bigintval($userid), bigintval($GLOBALS['ref_level']), $ref_points), __FUNCTION__, __LINE__); - //* DEBUG: */ debugOutput(__FUNCTION__ . '(' . __LINE__ . '):data='.$data.',ref_points='.$ref_points.',userid='.$userid.',depth='.$GLOBALS['ref_level'].',mode='.$add_mode.' - INSERTED! ('.SQL_AFFECTEDROWS().')'); + SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_points` (`userid`, `ref_depth`, `%s`) VALUES (%s, %s, %s)", + array( + $pointsColumn, + bigintval($userid), + bigintval($GLOBALS['ref_level']), + $ref_points + ), __FUNCTION__, __LINE__); + //* DEBUG: */ debugOutput(__FUNCTION__ . '(' . __LINE__ . '):data='.$pointsColumn.',ref_points='.$ref_points.',userid='.$userid.',depth='.$GLOBALS['ref_level'].',mode='.$addMode.' - INSERTED! ('.SQL_AFFECTEDROWS().')'); } // END - if // Check affected rows @@ -1082,19 +1091,21 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify // Prepare data for the filter $filterData = array( - 'subject' => $subject, - 'userid' => $userid, - 'points' => $points, - 'notify' => $sendNotify, - 'refid' => $refid, - 'locked' => $locked, - 'mode' => 'add', - 'sub_mode' => $add_mode, - 'added' => $added + 'subject' => $subject, + 'userid' => $userid, + 'points' => $points, + 'ref_points' => $ref_points, + 'column' => $pointsColumn, + 'notify' => $sendNotify, + 'refid' => $refid, + 'locked' => $locked, + 'mode' => 'add', + 'add_mode' => $addMode, + 'added' => $added ); // Filter it now - $filterData = runFilterChain('add_points', $filterData); + $filterData = runFilterChain('post_add_points', $filterData); // Extract $added $added = $filterData['added']; @@ -1114,7 +1125,7 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify // Send email sendEmail($userid, '{--THANX_REFERAL_ONE_SUBJECT--}', $message); - } elseif (($sendNotify === true) && (!isValidUserId(getUserData('refid'))) && ($locked === false) && ($add_mode == 'direct')) { + } elseif (($sendNotify === true) && (!isValidUserId(getUserData('refid'))) && ($locked === false) && ($addMode == 'direct')) { // Prepare content $content = array( 'reason' => '{--REASON_DIRECT_PAYMENT--}', @@ -1133,7 +1144,7 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify } // Maybe there's another ref? - if ((isValidUserId(getUserData('refid'))) && ($points > 0) && (getUserData('refid') != $userid) && ($add_mode == 'ref')) { + if ((isValidUserId(getUserData('refid'))) && ($points > 0) && (getUserData('refid') != $userid) && ($addMode == 'ref')) { // Then let's credit him here... //* DEBUG: */ debugOutput(__FUNCTION__ . '(' . __LINE__ . '):userid='.$userid.',ref='.getUserData('refid').',points='.$points.' - ADVANCE!'); $added = ($added && addPointsThroughReferalSystem(sprintf("%s_ref:%s", $subject, $GLOBALS['ref_level']), getUserData('refid'), $points, $sendNotify, getUserData('refid'))); @@ -1219,7 +1230,7 @@ function sendAdminEmails ($subj, $message) { // Get id number from administrator's login name function getAdminId ($adminLogin) { // By default no admin is found - $data['id'] = '-1'; + $data['id'] = -1; // Check cache if (isset($GLOBALS['cache_array']['admin']['admin_id'][$adminLogin])) { @@ -1274,7 +1285,7 @@ function setCurrentAdminId ($currentAdminId) { // Get password hash from administrator's login name function getAdminHash ($adminId) { // By default an invalid hash is returned - $data['password'] = '-1'; + $data['password'] = -1; if (isAdminHashSet($adminId)) { // Check cache @@ -1438,7 +1449,9 @@ function generateOptionList ($table, $id, $name, $default = '', $special = '', $ } else { // Data from database $SPEC = ', `' . $id . '`'; - if (!empty($special)) $SPEC = ', `' . $special . '`'; + if (!empty($special)) { + $SPEC = ', `' . $special . '`'; + } // END - if // Query the database $result = SQL_QUERY_ESC("SELECT `%s`, `%s`".$SPEC." FROM `{?_MYSQL_PREFIX?}_%s` ".$where." ORDER BY `%s` ASC", @@ -1465,7 +1478,9 @@ function generateOptionList ($table, $id, $name, $default = '', $special = '', $ } // Add it, if set - if (!empty($add)) $add = ' ('.$add.')'; + if (!empty($add)) { + $add = ' ('.$add.')'; + } // END - if // Is the call-back function set? if (!empty($callback)) { @@ -1518,6 +1533,7 @@ function deleteUserAccount ($userid, $reason) { // Init points $data['points'] = '0'; + // Search for the points and user data $result = SQL_QUERY_ESC("SELECT (SUM(p.`points`) - d.`used_points`) AS `points` FROM @@ -1537,6 +1553,7 @@ LIMIT 1", $data = SQL_FETCHARRAY($result); // Delete points entries as well + // @TODO Rewrite these lines to a filter SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_points` WHERE `userid`=%s", array(bigintval($userid)), __FUNCTION__, __LINE__); @@ -1547,7 +1564,9 @@ LIMIT 1", } // END - if // Now, when we have all his points adds them do the jackpot! - if (isExtensionActive('jackpot')) addPointsToJackpot($data['points']); + if (isExtensionActive('jackpot')) { + addPointsToJackpot($data['points']); + } // END - if } // END - if // Free the result @@ -1987,5 +2006,32 @@ function updateLastActivity($userid) { ), __FUNCTION__, __LINE__); } +// Determines database column name from given subject and locked +function determinePointsColumnFromSubjectLocked ($subject, $locked) { + // Default is 'normal' points + $pointsColumn = 'points'; + + // Which points, locked or normal? + if ($locked === true) { + $pointsColumn = 'locked_points'; + } // END - if + + // Prepare array for filter + $filterData = array( + 'subject' => $subject, + 'locked' => $locked, + 'column' => $pointsColumn + ); + + // Run the filter + $filterData = runFilterChain('determine_points_column_name', $filterData); + + // Extract column name from array + $pointsColumn = $filterData['column']; + + // Return it + return $pointsColumn; +} + // [EOF] ?>