X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fmysql-manager.php;h=91a16286fef6f3f40c91ba36c4fdb724377f4bc1;hb=2763c536e15b838a5df284bca71b7430870edc47;hp=43de04889b35120e41da8ec646ba78a606b41453;hpb=ad85ea5a3690e65e3509d4e4e8c63083b2b71b0c;p=mailer.git diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php index 43de04889b..91a16286fe 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 * @@ -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 @@ -370,61 +368,56 @@ function isMember () { // @TODO Try to rewrite this to one or more functions if ((!isset($GLOBALS['last_online'])) || (!is_array($GLOBALS['last_online']))) $GLOBALS['last_online'] = array(); - // is the cache entry there? - if (isset($GLOBALS['is_member'])) { + // Is the cache entry there? + 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 + // Destroy any existing user session data + destroyMemberSession(); //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'No member set in cookie/session.'); + + // Abort further processing return false; - } else { - // Get it secured from session - setMemberId(getSession('userid')); - setCurrentUserId(getMemberId()); - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . getSession('userid') . ' used from cookie/session.'); } + // Get userid secured from session + setMemberId(getSession('userid')); + + // ... and set it as currently handled user id + setCurrentUserId(getMemberId()); + // Init user data array initUserData(); // Fix "deleted" cookies first fixDeletedCookies(array('userid', 'u_hash')); - // Are cookies set? - if ((isMemberIdSet()) && (isSessionVariableSet('u_hash'))) { - // Cookies are set with values, but are they valid? - if (fetchUserData(getMemberId()) === true) { - // Validate password by created the difference of it and the secret key - $valPass = encodeHashForCookie(getUserData('password')); + // Are cookies set and can the member data be loaded? + if ((isMemberIdSet()) && (isSessionVariableSet('u_hash')) && (fetchUserData(getMemberId()) === true)) { + // Validate password by created the difference of it and the secret key + $valPass = encodeHashForCookie(getUserData('password')); + // So did we now have valid data and an unlocked user? + if ((getUserData('status') == 'CONFIRMED') && ($valPass == getSession('u_hash'))) { // Transfer last module and online time $GLOBALS['last_online']['module'] = getUserData('last_module'); $GLOBALS['last_online']['online'] = getUserData('last_online'); - // So did we now have valid data and an unlocked user? - if ((getUserData('status') == 'CONFIRMED') && ($valPass == getSession('u_hash'))) { - // Account is confirmed and all cookie data is valid so he is definely logged in! :-) - $ret = true; - } else { - // Maybe got locked etc. - //* DEBUG */ logDebugMessage(__FUNCTION__, __LINE__, 'status=' . getUserData('status') . ',' . $valPass . '(' . strlen($valPass) . ')/' . getSession('u_hash') . '(' . strlen(getSession('u_hash')) . ')/' . getUserData('password') . '(' . strlen(getUserData('password')) . ')'); - destroyMemberSession(); - } - } else { - // Cookie data is invalid! - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cookie data invalid or user not found.'); - destroyMemberSession(); - } - } else { - // Cookie data is invalid! - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cookie data not complete.'); + // Account is confirmed and all cookie data is valid so he is definely logged in! :-) + $ret = true; + } // END - if + } // END - if + + // Is $ret still false? + if ($ret === false) { + // Yes, so destroy the session destroyMemberSession(); - } + } // END - if // Cache status - $GLOBALS['is_member'] = $ret; + $GLOBALS[__FUNCTION__] = $ret; // Return status //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret=' . intval($ret)); @@ -442,7 +435,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 +447,6 @@ function fetchUserData ($userid, $column = 'userid') { return true; } - // By default none was found $found = false; @@ -541,9 +533,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 +561,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" @@ -696,10 +688,10 @@ function isMenuActionValid ($mode, $action, $what, $updateEntry=false) { // Should we look for affected rows (only update) or found rows? if ($updateEntry === true) { // Check updated/affected rows - $ret = (SQL_AFFECTEDROWS() == 1); + $ret = (!SQL_HASZEROAFFECTED()); } else { // Check found rows - $ret = (SQL_NUMROWS($result) == 1); + $ret = (!SQL_HASZERONUMS($result)); } // Free memory @@ -717,7 +709,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()) { @@ -825,7 +817,7 @@ function getPaymentTitlePrice ($pid, $full=false) { if ($full === false) { $ret = $data['mail_title']; } else { - $ret = $data['mail_title'] . ' / ' . translateComma($data['price']) . ' {?POINTS?}'; + $ret = $data['mail_title'] . ' / {%pipe,translateComma=' . $data['price'] . '%} {?POINTS?}'; } } @@ -864,7 +856,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 +864,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 +886,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 +981,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 @@ -995,6 +990,9 @@ function getReferalLevelPercents ($level) { * for default value will cause no referal will get points ever!!!) */ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify = false, $refid = '0', $add_mode = 'ref') { + // By default nothing has been added + $added = false; + //* DEBUG: */ debugOutput('----------------------- ' . __FUNCTION__ . ' - ENTRY ------------------------
  • '); // Convert mode to lower-case $add_mode = strtolower($add_mode); @@ -1017,15 +1015,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; @@ -1052,16 +1055,16 @@ 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.' - UPDATE! ('.SQL_AFFECTEDROWS().')'); // No entry updated? - if (SQL_AFFECTEDROWS() < 1) { + 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().')'); } // END - if - // Determine wether the user has some mails to click before he/she gets the points - $locked = false; - if ((getUserData('ref_payout') > 0) && (!isDirectPaymentAllowed())) $locked = true; + // Check affected rows + $added = SQL_AFFECTEDROWS(); + //* DEBUG: */ debugOutput(__FUNCTION__ . '(' . __LINE__ . '):added='.intval($added)); // Prepare data for the filter $filterData = array( @@ -1073,10 +1076,15 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify 'locked' => $locked, 'mode' => 'add', 'sub_mode' => $add_mode, + 'added' => $added ); // Filter it now - runFilterChain('add_points', $filterData); + $filterData = runFilterChain('add_points', $filterData); + + // Extract $added + $added = $filterData['added']; + //* DEBUG: */ debugOutput(__FUNCTION__ . '(' . __LINE__ . '):added='.intval($added)); // Points updated, maybe I shall send him an email? if (($sendNotify === true) && (isValidUserId(getUserData('refid'))) && ($locked === false)) { @@ -1092,10 +1100,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 ); @@ -1104,19 +1112,23 @@ 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')); + $added = ($added && addPointsThroughReferalSystem(sprintf("%s_ref:%s", $subject, $GLOBALS['ref_level']), getUserData('refid'), $points, $sendNotify, getUserData('refid'))); } // END - if } // END - if } // END - if - //* DEBUG: */ debugOutput('
----------------------- '.__FUNCTION__.' - EXIT ------------------------
'); + //* DEBUG: */ debugOutput('----------------------- '.__FUNCTION__.': added=' . intval($added) . ' - EXIT ------------------------
'); + return $added; } // Updates the referal counter @@ -1131,10 +1143,13 @@ function updateReferalCounter ($userid) { // When no entry was updated then we have to create it here //* DEBUG: */ debugOutput(__FUNCTION__ . '(' . __LINE__ . '):updated=' . SQL_AFFECTEDROWS()); - if (SQL_AFFECTEDROWS() < 1) { + if (SQL_HASZEROAFFECTED()) { // First count! SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_refsystem` (`userid`, `level`, `counter`) VALUES (%s,%s,1)", - array(bigintval($userid), $GLOBALS['cache_array']['ref_level'][$userid]), __FUNCTION__, __LINE__); + array( + bigintval($userid), + $GLOBALS['cache_array']['ref_level'][$userid] + ), __FUNCTION__, __LINE__); //* DEBUG: */ debugOutput(__FUNCTION__ . '(' . __LINE__ . '):userid='.$userid); } // END - if @@ -1374,11 +1389,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 { @@ -1576,11 +1609,15 @@ function subtractPoints ($subject, $userid, $points) { 'subject' => $subject, 'userid' => $userid, 'points' => $points, - 'mode' => 'sub' + 'mode' => 'sub', + 'added' => (!SQL_HASZEROAFFECTED()) ); // Insert booking record - runFilterChain('sub_points', $filterData); + $filterData = runFilterChain('sub_points', $filterData); + + // Return result + return $filterData['added']; } // "Getter" for total available receivers @@ -1648,7 +1685,7 @@ function generateCategoryOptionsList ($mode) { } // END - foreach } else { // No cateogries are defined yet - $OUT = ''; + $OUT = ''; } // Return HTML code