X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fmysql-manager.php;h=c9fad71c38bd45b68868552f4ecc139b956bb10c;hb=3deb4216cd947c4eb14b0a9e3b9f637ca25e77d3;hp=e691d6cf7cc8a5ea6e4fe1da19b04f9cdf7a4d65;hpb=41d7cc2d4ab3b725d1cd2cbe022dd49fbfc0065a;p=mailer.git diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php index e691d6cf7c..c9fad71c38 100644 --- a/inc/mysql-manager.php +++ b/inc/mysql-manager.php @@ -91,7 +91,7 @@ function getModuleTitle ($mod) { // "Getter" for module description // @TODO Can we cache this? -function getModuleDescription ($mode, $what, $column = 'what') { +function getTitleFromMenu ($mode, $what, $column = 'what', $ADD='') { // Fix empty 'what' if (empty($what)) { $what = getConfig('index_home'); @@ -101,8 +101,12 @@ function getModuleDescription ($mode, $what, $column = 'what') { $ret = '??? (' . $what . ')'; // Look for title - $result = SQL_QUERY_ESC("SELECT `title` FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE %s='%s' LIMIT 1", - array($mode, $column, $what), __FUNCTION__, __LINE__); + $result = SQL_QUERY_ESC("SELECT `title` FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE `%s`='%s'" . $ADD . " LIMIT 1", + array( + $mode, + $column, + $what + ), __FUNCTION__, __LINE__); // Is there an entry? if (SQL_NUMROWS($result) == 1) { @@ -285,14 +289,14 @@ function checkModulePermissions ($mod = '') { } // Add menu description pending on given file name (without path!) -function addMenuDescription ($accessLevel, $FQFN, $return = false, $output = true) { +function addMenuDescription ($accessLevel, $FQFN, $return = false) { // Use only filename of the FQFN... $file = basename($FQFN); // Init variables $LINK_ADD = ''; $OUT = ''; - $AND = ''; + $ADD = ''; // First we have to do some analysis... if (substr($file, 0, 7) == 'action-') { @@ -304,39 +308,39 @@ function addMenuDescription ($accessLevel, $FQFN, $return = false, $output = tru $modCheck = getModuleFromFileName($file, $accessLevel); // Add what - $AND = " AND (`what`='' OR `what` IS NULL)"; + $ADD = " AND (`what`='' OR `what` IS NULL)"; } elseif (substr($file, 0, 5) == 'what-') { - // This is an admin what file! + // This is a 'what file'! $type = 'what'; $search = substr($file, 5); - $AND = " AND `visible`='Y' AND `locked`='N'"; + $ADD = " AND `visible`='Y' AND `locked`='N'"; // Get access level from it $modCheck = getModuleFromFileName($file, $accessLevel); // Do we have admin? Then display all - if (isAdmin()) $AND = ''; + if (isAdmin()) $ADD = ''; $dummy = substr($search, 0, -4); - $AND .= " AND `action`='".getModeAction($accessLevel, $dummy)."'"; + $ADD .= " AND `action`='".getModeAction($accessLevel, $dummy)."'"; } elseif (($accessLevel == 'sponsor') || ($accessLevel == 'engine')) { // Sponsor / engine menu $type = 'what'; $search = $file; $modCheck = getModule(); - $AND = ''; + $ADD = ''; } else { // Other $type = 'menu'; $search = $file; $modCheck = getModule(); - $AND = ''; + $ADD = ''; } // Begin the navigation line if ((!isset($GLOBALS['nav_depth'])) && ($return === false)) { $GLOBALS['nav_depth'] = '0'; - $prefix = "
{--YOU_ARE_HERE--} Home"; + $prefix = "
{--YOU_ARE_HERE--} Home"; } else { if ($return === false) $GLOBALS['nav_depth']++; $prefix = ''; @@ -350,48 +354,33 @@ function addMenuDescription ($accessLevel, $FQFN, $return = false, $output = tru $search = substr($search, 0, -4); } // END - i - // Get the title from menu - $result = SQL_QUERY_ESC("SELECT title FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE %s='%s' ".$AND." LIMIT 1", - array($accessLevel, $type, $search), __FUNCTION__, __LINE__); + if (((isExtensionInstalledAndNewer('sql_patches', '0.2.3')) && (getConfig('youre_here') == 'Y')) || ((isAdmin()) && ($modCheck == 'admin'))) { + // Output HTML code + $OUT = $prefix . ""); + if (($type == 'what') || (($type == 'action') && ((!isWhatSet()) || (getWhat() == 'overview')))) { + //* DEBUG: */ print(__LINE__.'+'.$type."+
"); + // Add closing div and br-tag + $OUT .= "

\n"; + $GLOBALS['nav_depth'] = '0'; - // Shall we return it? - if ($return === true) { - // Return title - return $ret; - } elseif (((isExtensionInstalledAndNewer('sql_patches', '0.2.3')) && (getConfig('youre_here') == 'Y')) || ((isAdmin()) && ($modCheck == 'admin'))) { - // Output HTML code - $OUT = $prefix . "
"); - if (($type == 'what') || (($type == 'action') && ((!isWhatSet()) || (getWhat() == 'overview')))) { - //* DEBUG: */ print(__LINE__.'+'.$type."+
"); - // Add closing div and br-tag - $OUT .= "

\n"; - $GLOBALS['nav_depth'] = '0'; - - // Run the filter chain - $ret = runFilterChain('post_youhere_line', array('access_level' => $accessLevel, 'type' => $type, 'content' => "")); - $OUT .= $ret['content']; - } // END - if - } - } // END - if + // Run the filter chain + $ret = runFilterChain('post_youhere_line', array('access_level' => $accessLevel, 'type' => $type, 'content' => '')); - // Free result - SQL_FREERESULT($result); + // Add additional content + $OUT .= $ret['content']; + } // END - if + } // Return or output HTML code? - if ($output) { - // Output HTML code here - outputHtml($OUT); - } else { + if ($return === true) { // Return HTML code return $OUT; + } else { + // Output HTML code here + outputHtml($OUT); } } @@ -399,7 +388,7 @@ function addMenuDescription ($accessLevel, $FQFN, $return = false, $output = tru function addMenu ($mode, $action, $what) { // Init some variables $main_cnt = '0'; - $AND = ''; + $ADD = ''; // is the menu action valid? if (!isMenuActionValid($mode, $action, $what, true)) { @@ -408,11 +397,11 @@ function addMenu ($mode, $action, $what) { // Non-admin shall not see all menus if (!isAdmin()) { - $AND = " AND `visible`='Y' AND `locked`='N'"; + $ADD = " AND `visible`='Y' AND `locked`='N'"; } // END - if // Load SQL data and add the menu to the output stream... - $result_main = SQL_QUERY_ESC("SELECT `title`, `action` FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE (`what`='' OR `what` IS NULL)".$AND." ORDER BY `sort` ASC", + $result_main = SQL_QUERY_ESC("SELECT `title`, `action` FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE (`what`='' OR `what` IS NULL)".$ADD." ORDER BY `sort` ASC", array($mode), __FUNCTION__, __LINE__); //* DEBUG: */ print(__LINE__.'/'.$main_cnt.':'.getWhat()."*
"); @@ -429,7 +418,7 @@ function addMenu ($mode, $action, $what) { $GLOBALS['rows'] .= loadTemplate($mode . '_menu_title', true, $content); // Sub menu - $result_sub = SQL_QUERY_ESC("SELECT `title` AS sub_title, `what` AS sub_what FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE `action`='%s' AND `what` != '' AND `what` IS NOT NULL ".$AND." ORDER BY `sort`", + $result_sub = SQL_QUERY_ESC("SELECT `title` AS sub_title, `what` AS sub_what FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE `action`='%s' AND `what` != '' AND `what` IS NOT NULL ".$ADD." ORDER BY `sort`", array($mode, $content['action']), __FUNCTION__, __LINE__); // Get number of rows @@ -458,7 +447,7 @@ function addMenu ($mode, $action, $what) { } // END - if // Navigation link - $OUT .= "
"; + $OUT .= ""; } else { // Not found! - open $OUT .= ""; @@ -618,7 +607,7 @@ function isMember () { } // Fetch user data for given user id -function fetchUserData ($userid, $column='userid') { +function fetchUserData ($userid, $column = 'userid') { // If we should look for userid secure&set it here if (substr($column, -2, 2) == 'id') { // Secure userid @@ -816,8 +805,8 @@ function addMaxReceiveList ($mode, $default = '', $return = false) { // Checks wether the given email address is used. function isEmailTaken ($email) { // Query the database - $result = SQL_QUERY_ESC("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE email LIKE '{PER}%s{PER}' LIMIT 1", - array($email), __FUNCTION__, __LINE__); + $result = SQL_QUERY_ESC("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `email` LIKE '{PER}%s{PER}' OR `email` LIKE '{PER}%s{PER}' LIMIT 1", + array($email, str_replace('.', '{DOT}', $email)), __FUNCTION__, __LINE__); // Is the email there? $ret = (SQL_NUMROWS($result) == 1); @@ -1257,7 +1246,8 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify // Load email template $message = loadEmailTemplate('confirm-referal', $content, bigintval($userid)); - sendEmail(getUserData('email'), THANX_REFERAL_ONE, $message); + // Send email + sendEmail($userid, getMessage('THANX_REFERAL_ONE_SUBJECT'), $message); } elseif (($sendNotify) && (getUserData('refid') == '0') && ($locked === false) && ($add_mode == 'direct')) { // Prepare content $content = array( @@ -1269,7 +1259,7 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify $message = loadEmailTemplate('add-points', $content, $userid); // And sent it away - sendEmail(getUserData('email'), getMessage('SUBJECT_DIRECT_PAYMENT'), $message); + sendEmail($userid, getMessage('SUBJECT_DIRECT_PAYMENT'), $message); if (!isGetRequestElementSet('mid')) loadTemplate('admin_settings_saved', false, getMessage('ADMIN_POINTS_ADDED')); } @@ -1659,7 +1649,7 @@ function generateMetaDescriptionCode ($mod, $what) { // Exclude admin and member's area if (($mod != 'admin') && ($mod != 'login')) { // Construct dynamic description - $DESCR = '{?MAIN_TITLE?} '.trim(getConfig('title_middle')) . ' ' . addMenuDescription('guest', 'what-'.$what, true); + $DESCR = '{?MAIN_TITLE?} '.trim(getConfig('title_middle')) . ' ' . getTitleFromMenu('guest', $what); // Output it directly outputHtml(''); @@ -2093,21 +2083,34 @@ ORDER BY ur.refid ASC", // Recuce the amount of received emails for the receipients for given email function reduceRecipientReceivedMails ($column, $id, $count) { // Search for mail in database - $result = SQL_QUERY_ESC("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `%s`=%s ORDER BY `userid` ASC LIMIT %s", + $result = SQL_QUERY_ESC("SELECT * FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `%s`=%s ORDER BY `userid` ASC LIMIT %s", array($column, bigintval($id), $count), __FUNCTION__, __LINE__); // Are there entries? if (SQL_NUMROWS($result) > 0) { // Now load all userids for one big query! - // @TODO This can be somehow rewritten - $UIDs = array(); - while (list($userid) = SQL_FETCHROW($result)) { - $UIDs[$userid] = $userid; + $userids = array(); + while ($data = SQL_FETCHARRAY($result)) { + // By default we want to reduce and have no mails found + $num = 0; + + // We must now look if he has already confirmed this mail, so might sound double, but it may resolve problems + // @TODO Rewrite this to a filter + if ((isset($data['stats_id'])) && ($data['stats_id'] > 0)) { + // User email + $num = countSumTotalData($data['userid'], 'user_stats_data', 'id', 'userid', true, sprintf(" AND `stats_type`='mailid' AND `stats_data`=%s", bigintval($data['stats_id']))); + } elseif ((isset($data['bonus_id'])) && ($data['bonus_id'] > 0)) { + // Bonus mail + $num = countSumTotalData($data['userid'], 'user_stats_data', 'id', 'userid', true, sprintf(" AND `stats_type`='bonusid' AND `stats_data`=%s", bigintval($data['bonus_id']))); + } + + // Reduce this users total received emails? + if ($num === 0) $userids[$data['userid']] = $data['userid']; } // END - while // Now update all user accounts SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `emails_received`=`emails_received`-1 WHERE `userid` IN (%s) LIMIT %s", - array(implode(',', $UIDs), count($UIDs)), __FUNCTION__, __LINE__); + array(implode(',', $userids), count($userids)), __FUNCTION__, __LINE__); } // END - if // Free result