X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Fmysql-manager.php;h=4b9ee0e0138ad015586eaf8baec4091bb696f930;hp=e1be2665f0ea0af7cfed4d3854b5849e6d24f7ae;hb=0851db137e420b90617f47b77de2302e770f5f02;hpb=eb042d1491b009a13e394d9dc2a69dc9c487e9ed diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php index e1be2665f0..4b9ee0e013 100644 --- a/inc/mysql-manager.php +++ b/inc/mysql-manager.php @@ -6,9 +6,9 @@ * -------------------------------------------------------------------- * * File : mysql-manager.php * * -------------------------------------------------------------------- * - * Short description : All MySQL-related functions * + * Short description : All database-related functions * * -------------------------------------------------------------------- * - * Kurzbeschreibung : Alle MySQL-Relevanten Funktionen * + * Kurzbeschreibung : Alle datenbank-relevanten Funktionen * * -------------------------------------------------------------------- * * $Revision:: $ * * $Date:: $ * @@ -16,7 +16,7 @@ * $Author:: $ * * -------------------------------------------------------------------- * * Copyright (c) 2003 - 2009 by Roland Haeder * - * Copyright (c) 2009, 2010 by Mailer Developer Team * + * Copyright (c) 2009 - 2011 by Mailer Developer Team * * For more information visit: http://www.mxchange.org * * * * This program is free software; you can redistribute it and/or modify * @@ -72,8 +72,8 @@ function getTitleFromMenu ($mode, $what, $column = 'what', $ADD='') { return $data['title']; } -// Add menu description pending on given file name (without path!) -function addMenuDescription ($accessLevel, $FQFN, $return = false) { +// Add link into output stream (or return it) for 'You Are Here' navigation +function addYouAreHereLink ($accessLevel, $FQFN, $return = false) { // Use only filename of the FQFN... $file = basename($FQFN); @@ -108,8 +108,8 @@ function addMenuDescription ($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(); @@ -205,7 +205,7 @@ ORDER BY `sort` ASC", array($mode), __FUNCTION__, __LINE__); - //* DEBUG: */ debugOutput(__LINE__.'/'.$main_cnt.':'.getWhat().'*'); + //* DEBUG: */ debugOutput(__LINE__ . '/' . $main_cnt . ':' . getWhat() . '*'); if (!SQL_HASZERONUMS($result_main)) { // There are menus available, so we simply display them... :) $GLOBALS['rows'] = ''; @@ -237,7 +237,7 @@ ORDER BY // Do we have some entries? if (!SQL_HASZERONUMS($result_sub)) { // Init counter - $cnt = '0'; + $count = '0'; // Load all sub menus while ($content2 = SQL_FETCHARRAY($result_sub)) { @@ -259,8 +259,8 @@ ORDER BY // Navigation link $OUT .= ''; } else { - // Not found! - open - $OUT .= ''; + // Not found - open + $OUT .= ''; } // Menu title @@ -274,12 +274,12 @@ ORDER BY $OUT .= ''; } // END - if } else { - // Not found! - close + // Not found - close $OUT .= ''; } // Cunt it up - $cnt++; + $count++; // Rewrite array $content = array( @@ -290,7 +290,7 @@ ORDER BY ); // Add regular menu row or bottom row? - if ($cnt < SQL_NUMROWS($result_sub)) { + if ($count < SQL_NUMROWS($result_sub)) { $GLOBALS['rows'] .= loadTemplate($mode . '_menu_row', true, $content); } else { $GLOBALS['rows'] .= loadTemplate($mode . '_menu_bottom', true, $content); @@ -305,12 +305,12 @@ ORDER BY if (isFileReadable($INC)) { // Load include file if ((!isExtensionActive($content['action'])) || ($content['action'] == 'online')) $GLOBALS['rows'] .= loadTemplate('menu_what_begin', true, $mode); - //* DEBUG: */ debugOutput(__LINE__.'/'.$main_cnt.'/'.$content['action'].'/'.getWhat().'*'); + //* DEBUG: */ debugOutput(__LINE__ . '/' . $main_cnt . '/' . $content['action'] . '/' . getWhat().'*'); loadInclude($INC); - //* DEBUG: */ debugOutput(__LINE__.'/'.$main_cnt.'/'.$content['action'].'/'.getWhat().'*'); + //* DEBUG: */ debugOutput(__LINE__ . '/' . $main_cnt . '/' . $content['action'] . '/' . getWhat() . '*'); if ((!isExtensionActive($content['action'])) || ($content['action'] == 'online')) $GLOBALS['rows'] .= loadTemplate('menu_what_end', true, $mode); } - //* DEBUG: */ debugOutput(__LINE__.'/'.$main_cnt.'/'.$content['action'].'/'.$content['sub_what'].':'.getWhat().'*'); + //* DEBUG: */ debugOutput(__LINE__ . '/' . $main_cnt . '/' . $content['action'] . '/' . $content['sub_what'] . ':' . getWhat() . '*'); } // Free result @@ -319,7 +319,7 @@ ORDER BY // Count one up $main_cnt++; - //* DEBUG: */ debugOutput(__LINE__.'/'.$main_cnt.':'.getWhat().'*'); + //* DEBUG: */ debugOutput(__LINE__ . '/' . $main_cnt . ':' . getWhat() . '*'); if (SQL_NUMROWS($result_main) > $main_cnt) { // Add seperator $GLOBALS['rows'] .= loadTemplate('menu_seperator', true, $mode); @@ -354,7 +354,7 @@ ORDER BY ); // Load main template - //* DEBUG: */ debugOutput(__LINE__.'/'.$main_cnt.'/'.$content['action'].'/'.$content['sub_what'].':'.getWhat().'*'); + //* DEBUG: */ debugOutput(__LINE__ . '/' . $main_cnt . '/' . $content['action'] . '/' . $content['sub_what'] . ':' . getWhat() . '*'); loadTemplate('menu_table', false, $content); } // END - if } @@ -366,7 +366,9 @@ function isMember () { // Fix missing 'last_online' array, damn stupid code :((( // @TODO Try to rewrite this to one or more functions - if ((!isset($GLOBALS['last_online'])) || (!is_array($GLOBALS['last_online']))) $GLOBALS['last_online'] = array(); + if ((!isset($GLOBALS['last_online'])) || (!is_array($GLOBALS['last_online']))) { + $GLOBALS['last_online'] = array(); + } // END - if // Is the cache entry there? if (isset($GLOBALS[__FUNCTION__])) { @@ -425,25 +427,31 @@ function isMember () { } // Fetch user data for given user id -function fetchUserData ($userid, $column = 'userid') { +function fetchUserData ($value, $column = 'userid') { + // Extension ext-user must be there at any case + if (!isExtensionActive('user')) { + // Absent ext-user is really not good + return false; + } // END - if + // 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; } - } elseif (isUserDataValid()) { - // Use cache, so it is fine + } elseif (isUserDataValid()) { + // Using cache is fine return true; } @@ -452,11 +460,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) { @@ -465,16 +475,18 @@ 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 - if (isset($GLOBALS['user_data'][getCurrentUserId()]['last_failure'])) { + // Rewrite 'last_failure' if found and ext-user has version >= 0.3.7 + if ((isExtensionInstalledAndNewer('user', '0.3.7')) && (isset($GLOBALS['user_data'][getCurrentUserId()]['last_failure']))) { // Backup the raw one and zero it $GLOBALS['user_data'][getCurrentUserId()]['last_failure_raw'] = $GLOBALS['user_data'][getCurrentUserId()]['last_failure']; - $GLOBALS['user_data'][getCurrentUserId()]['last_failure'] = '0'; + $GLOBALS['user_data'][getCurrentUserId()]['last_failure'] = null; // Is it not zero? - if ($GLOBALS['user_data'][getCurrentUserId()]['last_failure_raw'] != '0000-00-00 00:00:00') { + if (!is_null($GLOBALS['user_data'][getCurrentUserId()]['last_failure_raw'])) { // Seperate data/time $array = explode(' ', $GLOBALS['user_data'][getCurrentUserId()]['last_failure_raw']); @@ -522,8 +534,8 @@ function isAdmin () { // If admin login is not given take current from cookies... if ((isSessionVariableSet('admin_id')) && (isSessionVariableSet('admin_md5'))) { // Get admin login and password from session/cookies - $adminId = getSession('admin_id'); - $passCookie = getSession('admin_md5'); + $adminId = getCurrentAdminId(); + $passCookie = getAdminMd5(); } // END - if //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $adminId.'/'.$passCookie); @@ -624,18 +636,21 @@ function addMaxReceiveList ($mode, $default = '', $return = false) { // Checks wether the given email address is used. function isEmailTaken ($email) { + // Replace dot with {DOT} + $email = str_replace('.', '{DOT}', $email); + // Query the database - $result = SQL_QUERY_ESC("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `email` LIKE '%%%s%%' OR `email` LIKE '%%%s%%' LIMIT 1", - array($email, str_replace('.', '{DOT}', $email)), __FUNCTION__, __LINE__); + $result = SQL_QUERY_ESC("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `email` LIKE '%%%s%%' LIMIT 1", + array($email), __FUNCTION__, __LINE__); // Is the email there? - $ret = (SQL_NUMROWS($result) == 1); + $isTaken = (SQL_NUMROWS($result) == 1); // Free the result SQL_FREERESULT($result); // Return result - return $ret; + return $isTaken; } // Validate the given menu action @@ -656,10 +671,10 @@ function isMenuActionValid ($mode, $action, $what, $updateEntry=false) { $add = ''; if ((!isAdmin()) && ($mode != 'admin')) $add = " AND `locked`='N'"; - //* DEBUG: */ debugOutput(__LINE__.':'.$mode.'/'.$action.'/'.$what.'*'); + //* DEBUG: */ debugOutput(__LINE__ . ':' . $mode . '/' . $action . '/' . $what . '*'); if (($mode != 'admin') && ($updateEntry === true)) { // Update guest or member menu - $sql = SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_%s_menu` SET counter=counter+1 WHERE `action`='%s' AND `what`='%s'".$add." LIMIT 1", + $sql = SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_%s_menu` SET `counter`=`counter`+1 WHERE `action`='%s' AND `what`='%s'".$add." LIMIT 1", array( $mode, $action, @@ -743,7 +758,7 @@ function getActionFromModuleWhat ($module, $what) { // Get it directly from URL return getAction(); } - //* DEBUG: */ debugOutput(__FUNCTION__ . '(' . __LINE__ . '): ret=' . $data['action']); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ' ret=' . $data['action']); // Does the module have a menu? if (ifModuleHasMenu($module)) { @@ -809,6 +824,8 @@ function getPaymentTitlePrice ($pid, $full=false) { // Load payment data $result = SQL_QUERY_ESC("SELECT `mail_title`, `price` FROM `{?_MYSQL_PREFIX?}_payments` WHERE `id`=%s LIMIT 1", array(bigintval($pid)), __FUNCTION__, __LINE__); + + // Do we have an entry? if (SQL_NUMROWS($result) == 1) { // Payment type found... :-) $data = SQL_FETCHARRAY($result); @@ -819,7 +836,7 @@ function getPaymentTitlePrice ($pid, $full=false) { } else { $ret = $data['mail_title'] . ' / {%pipe,translateComma=' . $data['price'] . '%} {?POINTS?}'; } - } + } // END - if // Free result SQL_FREERESULT($result); @@ -831,7 +848,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", @@ -851,7 +868,7 @@ function getPaymentPoints ($pid, $lookFor = 'price') { } // Remove a receiver's id from $receivers and add a link for him to confirm -function removeReceiver (&$receivers, $key, $userid, $pool_id, $stats_id = '', $bonus = false) { +function removeReceiver (&$receivers, $key, $userid, $pool_id, $stats_id = 0, $isBonusMail = false) { // Default is not removed $ret = 'failed'; @@ -862,9 +879,12 @@ function removeReceiver (&$receivers, $key, $userid, $pool_id, $stats_id = '', $ // Is there already a line for this user available? if ($stats_id > 0) { + // Default is 'normal' mail + $type = 'NORMAL'; + $rowName = 'stats_id'; + // Only when we got a real stats id continue searching for the entry - $type = 'NORMAL'; $rowName = 'stats_id'; - if ($bonus) { + if ($isBonusMail === true) { $type = 'BONUS'; $rowName = 'bonus_id'; } // END - if @@ -878,6 +898,13 @@ function removeReceiver (&$receivers, $key, $userid, $pool_id, $stats_id = '', $ // So we add one! SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_links` (`%s`, `userid`, `link_type`) VALUES ('%s','%s','%s')", array($rowName, $stats_id, bigintval($userid), $type), __FUNCTION__, __LINE__); + + // Update 'mails_sent' if sql_patches is updated + if (isExtensionInstalledAndNewer('sql_patches', '0.7.4')) { + // Update the pool + SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_pool` SET `mails_sent`=`mails_sent`+1 WHERE `id`=%s LIMIT 1", + array(bigintval($pool_id)), __FUNCTION__, __LINE__); + } // END - if $ret = 'done'; } else { // Already found @@ -951,7 +978,7 @@ function getReferalLevelPercents ($level) { // First look for level $key = array_search($level, $GLOBALS['cache_array']['refdepths']['level']); if ($key !== false) { - // Entry found! + // Entry found $data['percents'] = $GLOBALS['cache_array']['refdepths']['percents'][$key]; // Count cache hit @@ -978,7 +1005,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... @@ -986,105 +1013,112 @@ function getReferalLevelPercents ($level) { * sendNotify = shall I send the referal an email or not? * refid = inc/modules/guest/what-confirm.php need this * locked = Shall I pay it to normal (false) or locked (true) points ammount? - * add_mode = Add points only to $userid or also refs? (WARNING! Changing 'ref' to 'direct' + * add_mode = Add points only to $userid or also refs? (WARNING! Changing 'REFERAL' 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 = 'REFERAL') { // By default nothing has been added $added = false; //* DEBUG: */ debugOutput('----------------------- ' . __FUNCTION__ . ' - ENTRY ------------------------