X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fmysql-manager.php;h=460145e7bb57b12374d97676a318940bb9c02e61;hb=879d21c8fbaf8868194aeb456a77ab95b0dc43b0;hp=1dd3aa1ca361c916a3e33212b50524acba610c66;hpb=241acfbd7e38ff9916100dac9d88892713f85c7f;p=mailer.git diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php index 1dd3aa1ca3..460145e7bb 100644 --- a/inc/mysql-manager.php +++ b/inc/mysql-manager.php @@ -125,7 +125,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 +147,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 +262,7 @@ ORDER BY $OUT .= ''; } else { // Not found! - open - $OUT .= ''; + $OUT .= ''; } // Menu title @@ -371,10 +371,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 +424,7 @@ function isMember () { } // Cache status - $GLOBALS['is_member'] = $ret; + $GLOBALS[__FUNCTION__] = $ret; // Return status //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret=' . intval($ret)); @@ -442,7 +442,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 +454,6 @@ function fetchUserData ($userid, $column = 'userid') { return true; } - // By default none was found $found = false; @@ -541,9 +540,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 +568,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 +584,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 +716,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()) { @@ -864,7 +863,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 +871,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 +893,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; @@ -986,7 +988,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 +996,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 +1008,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 +1019,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 = ((getUserData('ref_payout') > 0) && (!isDirectPaymentEnabled())); + + // 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 +1066,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 @@ -1091,7 +1098,7 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify } elseif (($sendNotify === true) && (getUserData('refid') == '0') && ($locked === false) && ($add_mode == 'direct')) { // Prepare content $content = array( - 'text' => '{--REASON_DIRECT_PAYMENT--}', + 'reason' => '{--REASON_DIRECT_PAYMENT--}', 'points' => $ref_points ); @@ -1100,14 +1107,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 +1181,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 +1380,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 { @@ -1467,15 +1495,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__); @@ -1602,7 +1630,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? @@ -1644,7 +1672,7 @@ function generateCategoryOptionsList ($mode) { } // END - foreach } else { // No cateogries are defined yet - $OUT = ''; + $OUT = ''; } // Return HTML code @@ -1735,8 +1763,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?