X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Fmysql-manager.php;h=177da67eb57a0f78f35cc46720a4d8c639d89caf;hp=58564d9b54a388a48e1a99525f58b717e9c6b93e;hb=dc25bd7a76750f02e2d617c9db9eb0aae53270f5;hpb=18eb87f5ec1182966e2ff5ef128a379330534f80 diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php index 58564d9b54..177da67eb5 100644 --- a/inc/mysql-manager.php +++ b/inc/mysql-manager.php @@ -924,7 +924,7 @@ function removeReceiver (&$receivers, $key, $userid, $pool_id, $stats_id = 0, $i } // Calculate sum (default) or count records of given criteria -function countSumTotalData ($search, $tableName, $lookFor = 'id', $whereStatement = 'userid', $countRows = false, $add = '') { +function countSumTotalData ($search, $tableName, $lookFor = 'id', $whereStatement = 'userid', $countRows = false, $add = '', $mode = '=') { // Init count/sum $data['res'] = '0'; @@ -934,22 +934,40 @@ function countSumTotalData ($search, $tableName, $lookFor = 'id', $whereStatemen if ($countRows === true) { // Count whole table $result = SQL_QUERY_ESC("SELECT COUNT(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s`".$add, - array($lookFor, $tableName), __FUNCTION__, __LINE__); + array( + $lookFor, + $tableName + ), __FUNCTION__, __LINE__); } else { // Sum whole table $result = SQL_QUERY_ESC("SELECT SUM(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s`".$add, - array($lookFor, $tableName), __FUNCTION__, __LINE__); + array( + $lookFor, + $tableName + ), __FUNCTION__, __LINE__); } } elseif (($countRows === true) || ($lookFor == 'userid')) { // Count rows //* DEBUG: */ debugOutput('COUNT!'); - $result = SQL_QUERY_ESC("SELECT COUNT(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s` WHERE `%s`='%s'".$add, - array($lookFor, $tableName, $whereStatement, $search), __FUNCTION__, __LINE__); + $result = SQL_QUERY_ESC("SELECT COUNT(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s` WHERE `%s`%s'%s'".$add, + array( + $lookFor, + $tableName, + $whereStatement, + $mode, + $search + ), __FUNCTION__, __LINE__); } else { // Add all rows //* DEBUG: */ debugOutput('SUM!'); - $result = SQL_QUERY_ESC("SELECT SUM(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s` WHERE `%s`='%s'".$add, - array($lookFor, $tableName, $whereStatement, $search), __FUNCTION__, __LINE__); + $result = SQL_QUERY_ESC("SELECT SUM(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s` WHERE `%s`%s'%s'".$add, + array( + $lookFor, + $tableName, + $whereStatement, + $mode, + $search + ), __FUNCTION__, __LINE__); } // Load row @@ -989,7 +1007,7 @@ function getReferalLevelPercents ($level) { } // END - if } elseif (!isExtensionActive('cache')) { // Get referal data - $result_level = SQL_QUERY_ESC("SELECT `percents` FROM `{?_MYSQL_PREFIX?}_refdepths` WHERE `level`='%s' LIMIT 1", + $result_level = SQL_QUERY_ESC("SELECT `percents` FROM `{?_MYSQL_PREFIX?}_refdepths` WHERE `level`=%s LIMIT 1", array(bigintval($level)), __FUNCTION__, __LINE__); // Entry found? @@ -1006,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! @@ -1020,32 +1045,21 @@ 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!'); // By default nothing has been added $added = false; - //* DEBUG: */ debugOutput('----------------------- ' . __FUNCTION__ . ' - ENTRY ----------------------------------------------- '.__FUNCTION__.': added=' . intval($added) . ' - 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), $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 @@ -1850,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 @@ -1866,33 +1906,29 @@ function generateReceiverList ($categoryId, $receiver, $mode = '') { // "Getter" for array for user refs and points in given level function getUserReferalPoints ($userid, $level) { - //* DEBUG: */ debugOutput('----------------------- '.__FUNCTION__.' - ENTRY ----------------------------------------------- '.__FUNCTION__.' - EXIT ------------------------
'); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $level . ' - EXIT!'); return $refs; } @@ -1978,7 +2014,7 @@ function reduceRecipientReceivedMails ($column, $id, $count) { array(implode(',', $userids), count($userids)), __FUNCTION__, __LINE__); } else { // Nothing deleted - displayMessage(getMaskedMessage('ADMIN_MAIL_NOTHING_DELETED', $id)); + displayMessage('{%message,ADMIN_MAIL_NOTHING_DELETED=' . $id . '%}'); } } // END - if