X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fmysql-manager.php;h=885b670ce1f68ded7d59f5e24be56f7ee4a0ee77;hb=07af932574589f4906be5ebf6733fdb95f30e9a2;hp=571697aabd7266bfe36a17ee8d45b071eb230dad;hpb=0f9bc55be42f9851cc87a06f3971c853a83425a7;p=mailer.git diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php index 571697aabd..885b670ce1 100644 --- a/inc/mysql-manager.php +++ b/inc/mysql-manager.php @@ -14,8 +14,6 @@ * $Date:: $ * * $Tag:: 0.2.1-FINAL $ * * $Author:: $ * - * Needs to be in all Files and every File needs "svn propset * - * svn:keywords Date Revision" (autoprobset!) at least!!!!!! * * -------------------------------------------------------------------- * * Copyright (c) 2003 - 2009 by Roland Haeder * * Copyright (c) 2009, 2010 by Mailer Developer Team * @@ -47,7 +45,7 @@ if (!defined('__SECURITY')) { function getTitleFromMenu ($mode, $what, $column = 'what', $ADD='') { // Fix empty 'what' if (empty($what)) { - $what = getConfig('index_home'); + $what = getIndexHome(); } // END - if // Default is not found @@ -109,7 +107,7 @@ function addMenuDescription ($accessLevel, $FQFN, $return = false) { if (isAdmin()) $ADD = ''; $dummy = substr($search, 0, -4); - $ADD .= " AND `action`='".getActionFromModuleWhat($accessLevel, $dummy)."'"; + $ADD .= sprintf(" AND `action`='%s'", getActionFromModuleWhat($accessLevel, $dummy)); } elseif (($accessLevel == 'sponsor') || ($accessLevel == 'engine')) { // Sponsor / engine menu $type = 'what'; @@ -125,7 +123,7 @@ function addMenuDescription ($accessLevel, $FQFN, $return = false) { } // Begin the navigation line - if ((!isset($GLOBALS['nav_depth'])) && ($return === false)) { + if (!isset($GLOBALS['nav_depth'])) { // Init nav_depth $GLOBALS['nav_depth'] = '0'; @@ -147,7 +145,7 @@ function addMenuDescription ($accessLevel, $FQFN, $return = false) { if (substr($search, -4, 4) == '.php') { // Remove the .php $search = substr($search, 0, -4); - } // END - i + } // END - if if (((isExtensionInstalledAndNewer('sql_patches', '0.2.3')) && (getConfig('youre_here') == 'Y')) || ((isAdmin()) && ($modCheck == 'admin'))) { // Output HTML code @@ -262,7 +260,7 @@ ORDER BY $OUT .= ''; } else { // Not found! - open - $OUT .= ''; + $OUT .= ''; } // Menu title @@ -371,10 +369,10 @@ function isMember () { if ((!isset($GLOBALS['last_online'])) || (!is_array($GLOBALS['last_online']))) $GLOBALS['last_online'] = array(); // is the cache entry there? - if (isset($GLOBALS['is_member'])) { + if (isset($GLOBALS[__FUNCTION__])) { // Then return it - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'CACHED! (' . intval($GLOBALS['is_member']) . ')'); - return $GLOBALS['is_member']; + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'CACHED! (' . intval($GLOBALS[__FUNCTION__]) . ')'); + return $GLOBALS[__FUNCTION__]; } elseif ((!isSessionVariableSet('userid')) || (!isSessionVariableSet('u_hash'))) { // No member //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'No member set in cookie/session.'); @@ -424,7 +422,7 @@ function isMember () { } // Cache status - $GLOBALS['is_member'] = $ret; + $GLOBALS[__FUNCTION__] = $ret; // Return status //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret=' . intval($ret)); @@ -442,7 +440,7 @@ function fetchUserData ($userid, $column = 'userid') { setCurrentUserId($userid); // Don't look for invalid userids... - if ($userid < 1) { + if (!isValidUserId($userid)) { // Invalid, so abort here debug_report_bug(__FUNCTION__, __LINE__, 'User id ' . $userid . ' is invalid.'); } elseif (isUserDataValid()) { @@ -454,7 +452,6 @@ function fetchUserData ($userid, $column = 'userid') { return true; } - // By default none was found $found = false; @@ -541,9 +538,9 @@ function isAdmin () { } // END - if // Do we have cache? - if (!isset($GLOBALS['is_admin'][$adminId])) { + if (!isset($GLOBALS[__FUNCTION__][$adminId])) { // Init it with failed - $GLOBALS['is_admin'][$adminId] = false; + $GLOBALS[__FUNCTION__][$adminId] = false; // Search in array for entry if (isset($GLOBALS['admin_hash'])) { @@ -569,12 +566,12 @@ function isAdmin () { if (!empty($valPass)) { // Check if password is valid //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '(' . $valPass . '==' . $passCookie . ')='.intval($valPass == $passCookie)); - $GLOBALS['is_admin'][$adminId] = (($GLOBALS['admin_hash'] == $passCookie) || ((strlen($GLOBALS['admin_hash']) == 32) && ($GLOBALS['admin_hash'] == md5($passCookie))) || (($GLOBALS['admin_hash'] == '*FAILED*') && (!isExtensionActive('cache')))); + $GLOBALS[__FUNCTION__][$adminId] = (($GLOBALS['admin_hash'] == $passCookie) || ((strlen($GLOBALS['admin_hash']) == 32) && ($GLOBALS['admin_hash'] == md5($passCookie))) || (($GLOBALS['admin_hash'] == '*FAILED*') && (!isExtensionActive('cache')))); } // END - if } // END - if // Return result of comparision - return $GLOBALS['is_admin'][$adminId]; + return $GLOBALS[__FUNCTION__][$adminId]; } // Generates a list of "max receiveable emails per day" @@ -585,13 +582,13 @@ function addMaxReceiveList ($mode, $default = '', $return = false) { switch ($mode) { case 'guest': // Guests (in the registration form) are not allowed to select 0 mails per day. - $result = SQL_QUERY("SELECT `value`, `comment` FROM `{?_MYSQL_PREFIX?}_max_receive` WHERE `value` > 0 ORDER BY `value` ASC", + $result = SQL_QUERY('SELECT `value`, `comment` FROM `{?_MYSQL_PREFIX?}_max_receive` WHERE `value` > 0 ORDER BY `value` ASC', __FUNCTION__, __LINE__); break; case 'member': // Members are allowed to set to zero mails per day (we will change this soon!) - $result = SQL_QUERY("SELECT `value`, `comment` FROM `{?_MYSQL_PREFIX?}_max_receive` ORDER BY `value` ASC", + $result = SQL_QUERY('SELECT `value`, `comment` FROM `{?_MYSQL_PREFIX?}_max_receive` ORDER BY `value` ASC', __FUNCTION__, __LINE__); break; @@ -717,7 +714,7 @@ function getActionFromModuleWhat ($module, $what) { // Init status $data['action'] = ''; - //* DEBUG: */ debugOutput(__LINE__.'='.$module.'/'.$what.'/'.getAction().'='); + //* DEBUG: */ debugOutput(__LINE__ . '=' . $module . '/'.$what . '/' . getAction() . '='); if (!isExtensionInstalledAndNewer('sql_patches', '0.0.5')) { // sql_patches is missing so choose depending on mode if (isWhatSet()) { @@ -732,7 +729,7 @@ function getActionFromModuleWhat ($module, $what) { } } elseif ((empty($what)) && ($module != 'admin')) { // Use configured 'home' - $what = getConfig('index_home'); + $what = getIndexHome(); } // END - if if ($module == 'admin') { @@ -864,7 +861,7 @@ function removeReceiver (&$receivers, $key, $userid, $pool_id, $stats_id = '', $ $ret = 'failed'; // Is the userid valid? - if ($userid > 0) { + if (isValidUserId($userid)) { // Remove entry from array unset($receivers[$key]); @@ -872,7 +869,10 @@ function removeReceiver (&$receivers, $key, $userid, $pool_id, $stats_id = '', $ if ($stats_id > 0) { // Only when we got a real stats id continue searching for the entry $type = 'NORMAL'; $rowName = 'stats_id'; - if ($bonus) { $type = 'BONUS'; $rowName = 'bonus_id'; } + if ($bonus) { + $type = 'BONUS'; + $rowName = 'bonus_id'; + } // END - if // Try to look the entry up $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE %s='%s' AND `userid`=%s AND link_type='%s' LIMIT 1", @@ -891,8 +891,8 @@ function removeReceiver (&$receivers, $key, $userid, $pool_id, $stats_id = '', $ // Free memory SQL_FREERESULT($result); - } - } + } // END - if + } // END - if // Return status for sending routine return $ret; @@ -908,22 +908,22 @@ function countSumTotalData ($search, $tableName, $lookFor = 'id', $whereStatemen // Count or sum whole table? if ($countRows === true) { // Count whole table - $result = SQL_QUERY_ESC("SELECT COUNT(`%s`) AS res FROM `{?_MYSQL_PREFIX?}_%s`".$add, + $result = SQL_QUERY_ESC("SELECT COUNT(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s`".$add, array($lookFor, $tableName), __FUNCTION__, __LINE__); } else { // Sum whole table - $result = SQL_QUERY_ESC("SELECT SUM(`%s`) AS res FROM `{?_MYSQL_PREFIX?}_%s`".$add, + $result = SQL_QUERY_ESC("SELECT SUM(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s`".$add, 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, + $result = SQL_QUERY_ESC("SELECT COUNT(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s` WHERE `%s`='%s'".$add, array($lookFor, $tableName, $whereStatement, $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, + $result = SQL_QUERY_ESC("SELECT SUM(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s` WHERE `%s`='%s'".$add, array($lookFor, $tableName, $whereStatement, $search), __FUNCTION__, __LINE__); } @@ -986,7 +986,7 @@ function getReferalLevelPercents ($level) { * Dynamic referal system, can also send mails! * * subject = Subject line, write in lower-case letters and underscore is allowed - * userid = Referal id wich should receive... + * userid = Referal id wich should receive... * points = ... xxx points * sendNotify = shall I send the referal an email or not? * refid = inc/modules/guest/what-confirm.php need this @@ -994,7 +994,7 @@ 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', $locked = false, $add_mode = 'ref') { +function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify = false, $refid = '0', $add_mode = 'ref') { //* DEBUG: */ debugOutput('----------------------- ' . __FUNCTION__ . ' - ENTRY ------------------------
  • '); // Convert mode to lower-case $add_mode = strtolower($add_mode); @@ -1006,21 +1006,6 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify return; } // END - if - // 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, - ); - - // Filter it now - runFilterChain('add_points', $filterData); - // Count up referal depth if (!isset($GLOBALS['ref_level'])) { // Initialialize referal system @@ -1032,15 +1017,20 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify //* DEBUG: */ debugOutput(__FUNCTION__ . '(' . __LINE__ . '): Referal level increased. DEPTH='.$GLOBALS['ref_level']); } - // Default is 'normal' points - $data = 'points'; - - // Which points, locked or normal? - if ($locked === true) $data = 'locked_points'; - // Check user account //* DEBUG: */ debugOutput(__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); + + // Default is 'normal' points + $data = 'points'; + + // Which points, locked or normal? + if ($locked === true) { + $data = 'locked_points'; + } // END - if + // This is the user and his ref $GLOBALS['cache_array']['add_userid'][getUserData('refid')] = $userid; @@ -1074,6 +1064,21 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify //* DEBUG: */ debugOutput(__FUNCTION__ . '(' . __LINE__ . '):data='.$data.',ref_points='.$ref_points.',userid='.$userid.',depth='.$GLOBALS['ref_level'].',mode='.$add_mode.' - INSERTED! ('.SQL_AFFECTEDROWS().')'); } // END - if + // 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, + ); + + // Filter it now + runFilterChain('add_points', $filterData); + // Points updated, maybe I shall send him an email? if (($sendNotify === true) && (isValidUserId(getUserData('refid'))) && ($locked === false)) { // Prepare content @@ -1088,10 +1093,10 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify // Send email sendEmail($userid, '{--THANX_REFERAL_ONE_SUBJECT--}', $message); - } elseif (($sendNotify === true) && (getUserData('refid') == '0') && ($locked === false) && ($add_mode == 'direct')) { + } elseif (($sendNotify === true) && (!isValidUserId(getUserData('refid'))) && ($locked === false) && ($add_mode == 'direct')) { // Prepare content $content = array( - 'text' => '{--REASON_DIRECT_PAYMENT--}', + 'reason' => '{--REASON_DIRECT_PAYMENT--}', 'points' => $ref_points ); @@ -1100,14 +1105,17 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify // And sent it away sendEmail($userid, '{--DIRECT_PAYMENT_SUBJECT--}', $message); - if (!isGetRequestParameterSet('mid')) loadTemplate('admin_settings_saved', false, '{--ADMIN_POINTS_ADDED--}'); + if (!isGetRequestParameterSet('mid')) { + // Output message to admin + loadTemplate('admin_settings_saved', false, '{--ADMIN_POINTS_ADDED--}'); + } // END - if } // Maybe there's another ref? if ((isValidUserId(getUserData('refid'))) && ($points > 0) && (getUserData('refid') != $userid) && ($add_mode == 'ref')) { // Then let's credit him here... //* DEBUG: */ debugOutput(__FUNCTION__ . '(' . __LINE__ . '):userid='.$userid.',ref='.getUserData('refid').',points='.$points.' - ADVANCE!'); - addPointsThroughReferalSystem(sprintf("%s_ref:%s", $subject, $GLOBALS['ref_level']), getUserData('refid'), $points, $sendNotify, getUserData('refid'), $locked); + addPointsThroughReferalSystem(sprintf("%s_ref:%s", $subject, $GLOBALS['ref_level']), getUserData('refid'), $points, $sendNotify, getUserData('refid')); } // END - if } // END - if } // END - if @@ -1171,7 +1179,7 @@ function updateReferalCounter ($userid) { // because we need it when there is no ext-admins installed function sendAdminEmails ($subj, $message) { // Load all admin email addresses - $result = SQL_QUERY("SELECT `email` FROM `{?_MYSQL_PREFIX?}_admins` ORDER BY `id` ASC", __FUNCTION__, __LINE__); + $result = SQL_QUERY('SELECT `email` FROM `{?_MYSQL_PREFIX?}_admins` ORDER BY `id` ASC', __FUNCTION__, __LINE__); while ($content = SQL_FETCHARRAY($result)) { // Send the email out sendEmail($content['email'], $subj, $message); @@ -1370,11 +1378,11 @@ function getAdminDefaultAcl ($adminId) { } // Generates an option list from various parameters -function generateOptionList ($table, $id, $name, $default='', $special='', $where='', $disabled=array()) { +function generateOptionList ($table, $id, $name, $default = '', $special = '', $where = '', $disabled = array(), $callback = '') { $ret = ''; if ($table == '/ARRAY/') { // Selection from array - if ((is_array($id)) && (is_array($name)) && (count($id)) == (count($name))) { + if ((is_array($id)) && (is_array($name)) && ((count($id)) == (count($name)) || (!empty($callback)))) { // Both are arrays foreach ($id as $idx => $value) { $ret .= ''; } // END - while } else { @@ -1443,9 +1469,7 @@ function FILTER_ACTIVATE_EXCHANGE () { } // END - if // Check total amount of users - $totalUsers = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true, ' AND max_mails > 0'); - - if ($totalUsers >= getConfig('activate_xchange')) { + if (getTotalConfirmedUser() >= getConfig('activate_xchange')) { // Activate System setSqlsArray(array( "UPDATE `{?_MYSQL_PREFIX?}_mod_reg` SET `locked`='N', `hidden`='N', `mem_only`='Y' WHERE `module`='order' LIMIT 1", @@ -1469,15 +1493,15 @@ function deleteUserAccount ($userid, $reason) { $data['points'] = '0'; $result = SQL_QUERY_ESC("SELECT - (SUM(p.points) - d.used_points) AS points + (SUM(p.`points`) - d.`used_points`) AS `points` FROM `{?_MYSQL_PREFIX?}_user_points` AS p LEFT JOIN `{?_MYSQL_PREFIX?}_user_data` AS d ON - p.userid=d.userid + p.`userid`=d.`userid` WHERE - p.userid=%s + p.`userid`=%s LIMIT 1", array(bigintval($userid)), __FUNCTION__, __LINE__); @@ -1516,11 +1540,10 @@ LIMIT 1", // Add reason and translate points $data['text'] = $reason; - $data['points'] = translateComma($data['points']); // Now a mail to the user and that's all... $message = loadEmailTemplate('del-user', $data, $userid); - sendEmail($userid, '{--ADMIN_DEL_ACCOUNT--}', $message); + sendEmail($userid, '{--ADMIN_DELETE_ACCOUNT--}', $message); // Ok, delete the account! SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s LIMIT 1", array(bigintval($userid)), __FUNCTION__, __LINE__); @@ -1548,7 +1571,7 @@ function getWhatFromModule ($modCheck) { // Is ext-sql_patches installed and newer than 0.0.5? if (isExtensionInstalledAndNewer('sql_patches', '0.0.5')) { // Use it from config - $what = getConfig('index_home'); + $what = getIndexHome(); } else { // Use default 'welcome' $what = 'welcome'; @@ -1583,21 +1606,9 @@ function subtractPoints ($subject, $userid, $points) { } // "Getter" for total available receivers -function getTotalReceivers ($mode='normal') { - // Query database - $result_all = SQL_QUERY("SELECT - `userid` -FROM - `{?_MYSQL_PREFIX?}_user_data` -WHERE - `status`='CONFIRMED' AND `receive_mails` > 0 ".runFilterChain('exclude_users', $mode), - __FUNCTION__, __LINE__); - +function getTotalReceivers ($mode = 'normal') { // Get num rows - $numRows = SQL_NUMROWS($result_all); - - // Free result - SQL_FREERESULT($result_all); + $numRows = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true, ' AND `receive_mails` > 0' . runFilterChain('exclude_users', $mode)); // Return value return $numRows; @@ -1617,7 +1628,7 @@ function generateCategoryOptionsList ($mode) { ); // Get categories - $result = SQL_QUERY("SELECT `id`, `cat` FROM `{?_MYSQL_PREFIX?}_cats`".$whereStatement." ORDER BY `sort` ASC", + $result = SQL_QUERY('SELECT `id`, `cat` FROM `{?_MYSQL_PREFIX?}_cats`' . $whereStatement . ' ORDER BY `sort` ASC', __FUNCTION__, __LINE__); // Do we have entries? @@ -1659,7 +1670,7 @@ function generateCategoryOptionsList ($mode) { } // END - foreach } else { // No cateogries are defined yet - $OUT = ''; + $OUT = ''; } // Return HTML code @@ -1750,8 +1761,8 @@ function generateReceiverList ($cat, $receiver, $mode = '') { // Category given? if ($cat > 0) { // Select category - $CAT_TABS = "LEFT JOIN `{?_MYSQL_PREFIX?}_user_cats` AS c ON d.userid=c.userid"; - $CAT_WHERE = sprintf(" AND c.cat_id=%s", $cat); + $CAT_TABS = "LEFT JOIN `{?_MYSQL_PREFIX?}_user_cats` AS c ON d.`userid`=c.`userid`"; + $CAT_WHERE = sprintf(" AND c.`cat_id`=%s", $cat); } // END - if // Exclude users in holiday? @@ -1832,7 +1843,7 @@ ORDER BY // Fetch all entries while ($row = SQL_FETCHARRAY($result)) { // Get total points of this user - $row['points'] = countSumTotalData($row['refid'], 'user_points', 'points') - countSumTotalData($row['refid'], 'user_data', 'used_points'); + $row['points'] = getTotalPoints($row['refid']); // Get unconfirmed mails $row['unconfirmed'] = countSumTotalData($row['refid'], 'user_links', 'id', 'userid', true);