X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Fmysql-manager.php;h=cac6de84178f40acc769a76dc7f50baf8d01bae6;hp=1c0185e5208437b16bb785f9fb75388587382cc3;hb=8a73ce89f88fb09523fce05eb2aff80665e65827;hpb=9b87babf90b27658be4a1cef2c0465e2ce9ed681 diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php index 1c0185e520..cac6de8417 100644 --- a/inc/mysql-manager.php +++ b/inc/mysql-manager.php @@ -10,7 +10,12 @@ * -------------------------------------------------------------------- * * Kurzbeschreibung : Alle MySQL-Relevanten Funktionen * * -------------------------------------------------------------------- * - * * + * $Revision:: $ * + * $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 - 2008 by Roland Haeder * * For more information visit: http://www.mxchange.org * @@ -70,7 +75,7 @@ function ADD_MODULE_TITLE ($mod) { $name = sprintf("%s (%s)", getMessage('LANG_UNKNOWN_MODULE'), $mod); if (SQL_NUMROWS($result) == 0) { // Add module to database - $dummy = CHECK_MODULE($mod); + $dummy = checkModulePermissions($mod); } // END - if } // END - if @@ -79,7 +84,7 @@ function ADD_MODULE_TITLE ($mod) { } // Check validity of a given module name (no file extension) -function CHECK_MODULE ($mod) { +function checkModulePermissions ($mod) { // Filter module name (names with low chars and underlines are fine!) $mod = preg_replace("/[^a-z_]/", "", $mod); @@ -114,6 +119,12 @@ function CHECK_MODULE ($mod) { // Check if cache is latest version if (GET_EXT_VERSION("cache") >= "0.1.2") { + // Is the cache there? + if (!isset($GLOBALS['cache_array']['modules'])) { + // This should normally not happen... + debug_report_bug("Cache 'modules' is gone."); + } // END - if + // Is the module cached? if (isset($GLOBALS['cache_array']['modules']['locked'][$mod_chk])) { // Check cache @@ -194,10 +205,10 @@ function CHECK_MODULE ($mod) { } // END - if // Destroy cache here - REBUILD_CACHE("mod_reg", "modreg"); + rebuildCacheFiles("modreg", "modreg"); // And reload data - $ret = CHECK_MODULE($mod_chk); + $ret = checkModulePermissions($mod_chk); } else { // Module not found we don't add it to the database $ret = "404"; @@ -306,7 +317,7 @@ function ADD_DESCR ($ACC_LVL, $FQFN, $return = false, $output = true) { list($ret) = SQL_FETCHROW($result); // Shall we return it? - if ($return) { + if ($return === true) { // Return title return $ret; } elseif (((GET_EXT_VERSION("sql_patches") >= "0.2.3") && (getConfig('youre_here') == "Y")) || ((IS_ADMIN()) && ($modCheck == "admin"))) { @@ -322,7 +333,7 @@ function ADD_DESCR ($ACC_LVL, $FQFN, $return = false, $output = true) { $GLOBALS['nav_depth'] = "0"; // Run the filter chain - $ret = RUN_FILTER('post_youhere_line', array('access_level' => $ACC_LVL, 'type' => $type, 'content' => "")); + $ret = runFilterChain('post_youhere_line', array('access_level' => $ACC_LVL, 'type' => $type, 'content' => "")); $OUT .= $ret['content']; } // END - if } @@ -351,13 +362,13 @@ function ADD_MENU ($MODE, $act, $wht) { // is the menu action valid? if (!VALIDATE_MENU_ACTION($MODE, $act, $wht, true)) { - return getMessage('CODE_MENU_NOT_VALID'); + return getCode('MENU_NOT_VALID'); } // END - if // Non-admin shall not see all menus if (!IS_ADMIN()) { $AND = " 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`", @@ -366,60 +377,69 @@ function ADD_MENU ($MODE, $act, $wht) { if (SQL_NUMROWS($result_main) > 0) { OUTPUT_HTML(""); // There are menus available, so we simply display them... :) - while (list($main_title, $main_action) = SQL_FETCHROW($result_main)) { - //* DEBUG: */ echo __LINE__."/".$main_cnt."/".$main_action."/".$sub_what.":".$GLOBALS['what']."*
\n"; + while ($content = SQL_FETCHARRAY($result_main)) { + //* DEBUG: */ echo __LINE__."/".$main_cnt."/".$content['action']."/".$sub_what.":".$GLOBALS['what']."*
\n"; // Init variables - $BLOCK_MODE = false; $act = $main_action; - - // Prepare content - $content = array( - 'action' => $main_action, - 'title' => $main_title - ); + $GLOBALS['block_mode'] = false; + $act = $content['action']; // Load menu header template LOAD_TEMPLATE($MODE."_menu_title", false, $content); - $result_sub = SQL_QUERY_ESC("SELECT title, what FROM `{!_MYSQL_PREFIX!}_%s_menu` WHERE `action`='%s' AND `what` != '' AND `what` IS NOT NULL ".$AND." ORDER BY `sort`", - array($MODE, $main_action), __FUNCTION__, __LINE__); + // 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`", + array($MODE, $content['action']), __FUNCTION__, __LINE__); + + // Get number of rows $ctl = SQL_NUMROWS($result_sub); + + // Do we have some entries? if ($ctl > 0) { - $cnt=0; - while (list($sub_title, $sub_what) = SQL_FETCHROW($result_sub)) { + // Init counter + $cnt = 0; + + // Load all sub menus + while ($content2 = SQL_FETCHARRAY($result_sub)) { + // Merge both arrays in one + $content = merge_array($content, $content2); + // Init content - $content = ""; + $OUT = ""; // Full file name for checking menu - //* DEBUG: */ echo __LINE__.":!!!!".$sub_what."!!!
\n"; - $FQFN = sprintf("%sinc/modules/%s/what-%s.php", constant('PATH'), $MODE, $sub_what); - if (FILE_READABLE($FQFN)) { - if ((!empty($wht)) && (($wht == $sub_what))) { - $content = ""; + //* DEBUG: */ echo __LINE__.":!!!!".$content['sub_what']."!!!
\n"; + $INC = sprintf("inc/modules/%s/what-%s.php", $MODE, $content['sub_what']); + if (INCLUDE_READABLE($INC)) { + if ((!empty($wht)) && (($wht == $content['sub_what']))) { + $OUT = ""; } // Navigation link - $content .= ""; + $OUT .= ""; } else { - $content .= ""; + $OUT .= ""; } // Menu title - $content .= getConfig('menu_blur_spacer') . $sub_title; + $OUT .= getConfig('menu_blur_spacer') . $content['sub_title']; - if (FILE_READABLE($FQFN)) { - $content .= ""; + if (INCLUDE_READABLE($INC)) { + $OUT .= ""; } else { - $content .= ""; + $OUT .= ""; } - if ((!empty($wht)) && (($wht == $sub_what))) { - $content .= ""; - } - $wht = $sub_what; $cnt++; - // Prepare array + if ((!empty($wht)) && (($wht == $content['sub_what']))) { + $OUT .= "
"; + } // END - if + + // Remember 'what' for next round and count it up + $wht = $content['sub_what']; $cnt++; + + // Rewrite array $content = array( - 'menu' => $content, - 'what' => $sub_what + 'menu' => $OUT, + 'what' => $content['sub_what'] ); // Add regular menu row or bottom row? @@ -431,31 +451,33 @@ function ADD_MENU ($MODE, $act, $wht) { } } else { // This is a menu block... ;-) - $BLOCK_MODE = true; - $INC_BLOCK = sprintf("inc/modules/%s/action-%s.php", $MODE, $main_action); + $GLOBALS['block_mode'] = true; + $INC_BLOCK = sprintf("inc/modules/%s/action-%s.php", $MODE, $content['action']); if (FILE_READABLE($INC_BLOCK)) { // Load include file - if ((!EXT_IS_ACTIVE($main_action)) || ($main_action == "online")) OUTPUT_HTML(" + if ((!EXT_IS_ACTIVE($content['action'])) || ($content['action'] == "online")) OUTPUT_HTML(" + //* DEBUG: */ echo __LINE__."/".$main_cnt."/".$content['action']."/".$content['sub_what'].":".$GLOBALS['what']."*
\n"; + if ((!EXT_IS_ACTIVE($content['action'])) || ($content['action'] == "online")) OUTPUT_HTML(" "); } - //* DEBUG: */ echo __LINE__."/".$main_cnt."/".$main_action."/".$sub_what.":".$GLOBALS['what']."*
\n"; + //* DEBUG: */ echo __LINE__."/".$main_cnt."/".$content['action']."/".$content['sub_what'].":".$GLOBALS['what']."*
\n"; } $main_cnt++; - //* DEBUG: */ echo __LINE__."/".$main_cnt."/".$main_action."/".$sub_what.":".$GLOBALS['what']."*
\n"; - if (SQL_NUMROWS($result_main) > $main_cnt) OUTPUT_HTML(""); + //* DEBUG: */ echo __LINE__."/".$main_cnt."/".$content['action']."/".$content['sub_what'].":".$GLOBALS['what']."*
\n"; + if (SQL_NUMROWS($result_main) > $main_cnt) { + OUTPUT_HTML(""); + } // END - if } // Free memory SQL_FREERESULT($result_main); // Close table - //* DEBUG: */ echo __LINE__."/".$main_cnt."/".$main_action."/".$sub_what.":".$GLOBALS['what']."*
\n"; + //* DEBUG: */ echo __LINE__."/".$main_cnt."/".$content['action']."/".$content['sub_what'].":".$GLOBALS['what']."*
\n"; OUTPUT_HTML("
"); - //* DEBUG: */ echo __LINE__."/".$main_cnt."/".$main_action."/".$sub_what.":".$GLOBALS['what']."*
\n"; + //* DEBUG: */ echo __LINE__."/".$main_cnt."/".$content['action']."/".$content['sub_what'].":".$GLOBALS['what']."*
\n"; LOAD_INC($INC_BLOCK); - //* DEBUG: */ echo __LINE__."/".$main_cnt."/".$main_action."/".$sub_what.":".$GLOBALS['what']."*
\n"; - if ((!EXT_IS_ACTIVE($main_action)) || ($main_action == "online")) OUTPUT_HTML("
"); } } @@ -523,53 +545,49 @@ function IS_ADMIN ($admin="") { // Generates a list of "max receiveable emails per day" function ADD_MAX_RECEIVE_LIST ($MODE, $default = "", $return = false) { $OUT = ""; + $result = 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", __FUNCTION__, __LINE__); - if (SQL_NUMROWS($result) > 0) { - $OUT = ""; - while (list($value, $comment) = SQL_FETCHROW($result)) { - $OUT .= " \n"; + $ret = "\n"; } } // Return - hopefully - the requested data return $ret; } -// Activate exchange (DEPERECATED???) -function activateExchange() { +// Activate exchange +function activateExchange () { // Check total amount of users $totalUsers = GET_TOTAL_DATA("CONFIRMED", "user_data", "userid", "status", true, " AND max_mails > 0"); if ($totalUsers >= getConfig('activate_xchange')) { // Activate System - $SQLs = array( + SET_SQLS(array( "UPDATE `{!_MYSQL_PREFIX!}_mod_reg` SET `locked`='N', hidden='N', mem_only='Y' WHERE module='order' LIMIT 1", "UPDATE `{!_MYSQL_PREFIX!}_member_menu` SET `visible`='Y', `locked`='N' WHERE `what`='order' OR `what`='unconfirmed' LIMIT 2", "UPDATE `{!_MYSQL_PREFIX!}_config` SET activate_xchange='0' WHERE config=0 LIMIT 1" - ); + )); // Run SQLs - RUN_FILTER('run_sqls', array('dry_run' => false, 'sqls' => $SQLs)); + runFilterChain('run_sqls'); - // Rebuild cache - REBUILD_CACHE("config", "config"); + // Rebuild caches + rebuildCacheFiles("config", "config"); + rebuildCacheFiles("modreg", "modreg"); } // END - if } // @@ -1628,40 +1649,7 @@ function SUB_JACKPOT($points) { function IS_DEMO () { return ((EXT_IS_ACTIVE("demo")) && (get_session('admin_login') == "demo")); } -// -function LOAD_CONFIG ($no="0") { - $CFG_DUMMY = array(); - - // Check for cache extension, cache-array and if the requested configuration is in cache - if ((is_array($GLOBALS['cache_array'])) && (isset($GLOBALS['cache_array']['config'][$no])) && (is_array($GLOBALS['cache_array']['config'][$no]))) { - // Load config from cache - //* DEBUG: */ echo gettype($GLOBALS['cache_array']['config'][$no])."
\n"; - foreach ($GLOBALS['cache_array']['config'][$no] as $key => $value) { - $CFG_DUMMY[$key] = $value; - } // END - foreach - - // Count cache hits if exists - if ((isset($CFG_DUMMY['cache_hits'])) && (EXT_IS_ACTIVE("cache"))) { - $CFG_DUMMY['cache_hits']++; - } // END - if - } elseif ((!EXT_IS_ACTIVE("cache")) || (!isset($GLOBALS['cache_array']['config'][$no]))) { - // Load config from DB - $result_config = SQL_QUERY_ESC("SELECT * FROM `{!_MYSQL_PREFIX!}_config` WHERE config=%d LIMIT 1", - array(bigintval($no)), __FUNCTION__, __LINE__); - - // Get config from database - $CFG_DUMMY = SQL_FETCHARRAY($result_config); - - // Free result - SQL_FREERESULT($result_config); - // Remember this config in the array - $GLOBALS['cache_array']['config'][$no] = $CFG_DUMMY; - } - - // Return config array - return $CFG_DUMMY; -} // Gets the matching what name from module function GET_WHAT ($modCheck) { // Is the request element set? @@ -1743,7 +1731,7 @@ function UPDATE_CONFIG ($entries, $values, $updateMode="") { } } - // Set it in $_CONFIG as well + // Set it in config as well setConfigEntry($entry, $values[$idx]); } // END - foreach @@ -1754,7 +1742,7 @@ function UPDATE_CONFIG ($entries, $values, $updateMode="") { // @TODO Find a way for updating $_CONFIG here $entries .= sprintf("=%s%s%s", $entries, $updateMode, (float)$values); } else { - // Set it in $_CONFIG first + // Set it in config first setConfigEntry($entries, $values); // Regular entry to update @@ -1770,7 +1758,7 @@ function UPDATE_CONFIG ($entries, $values, $updateMode="") { //* DEBUG: */ print __FUNCTION__."(".__LINE__."):entries={$entries},affectedRows={$affectedRows}
\n"; // Rebuild cache - REBUILD_CACHE("config", "config"); + rebuildCacheFiles("config", "config"); } // Prepares an SQL statement part for HTML mail and/or holiday depency @@ -1824,21 +1812,24 @@ function ADD_CATEGORY_OPTIONS ($mode) { $result = SQL_QUERY("SELECT id, cat FROM `{!_MYSQL_PREFIX!}_cats`".$whereStatement." ORDER BY `sort`", __FUNCTION__, __LINE__); if (SQL_NUMROWS($result) > 0) { // ... and begin loading stuff - while (list($id, $cat) = SQL_FETCHROW($result)) { + while ($content = SQL_FETCHARRAY($result)) { // Transfer some data - $CATS['id'][] = $id; - $CATS['name'][] = $cat; + $CATS['id'][] = $content['id']; + $CATS['name'][] = $content['cat']; // Check which users are in this category $result_uids = SQL_QUERY_ESC("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_cats` WHERE cat_id=%s", - array(bigintval($id)), __FUNCTION__, __LINE__); + array(bigintval($content['id'])), __FUNCTION__, __LINE__); // Start adding all $uid_cnt = 0; + // @TODO Rewrite this to $content = SQL_FETCHARRAY() while (list($ucat) = SQL_FETCHROW($result_uids)) { $result_ver = SQL_QUERY_ESC("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s AND `status`='CONFIRMED' AND receive_mails > 0".PREPARE_SQL_HTML_HOLIDAY($mode)." LIMIT 1", - array(bigintval($ucat)), __FUNCTION__, __LINE__); + array(bigintval($ucat)), __FUNCTION__, __LINE__); + + // Add user count $uid_cnt += SQL_NUMROWS($result_ver); // Free memory @@ -1850,7 +1841,7 @@ WHERE userid=%s AND `status`='CONFIRMED' AND receive_mails > 0".PREPARE_SQL_HTML // Add counter $CATS['uids'][] = $uid_cnt; - } + } // END - while // Free memory SQL_FREERESULT($result); @@ -1859,8 +1850,8 @@ WHERE userid=%s AND `status`='CONFIRMED' AND receive_mails > 0".PREPARE_SQL_HTML $OUT = ""; foreach ($CATS['id'] as $key => $value) { if (strlen($CATS['name'][$key]) > 20) $CATS['name'][$key] = substr($CATS['name'][$key], 0, 17)."..."; - $OUT .= " \n"; - } + $OUT .= " \n"; + } // END - foreach } else { // No cateogries are defined yet $OUT = "\n"; @@ -1939,6 +1930,7 @@ function GENERATE_RECEIVER_LIST ($cat, $receiver, $mode="") { $CAT_TABS = "%s"; $CAT_WHERE = ""; $receiverList = ""; + $result = false; // Secure data $cat = bigintval($cat); @@ -1966,19 +1958,19 @@ function GENERATE_RECEIVER_LIST ($cat, $receiver, $mode="") { if ((EXT_IS_ACTIVE("html_mail")) && ($mode == "html")) { // Only include HTML receivers $result = SQL_QUERY_ESC("SELECT d.userid FROM `{!_MYSQL_PREFIX!}_user_data` AS d ".$CAT_TABS." WHERE d.`status`='CONFIRMED' AND d.html='Y'".$CAT_WHERE." ORDER BY d.%s %s LIMIT %s", - array($cat, getConfig('order_select'), getConfig('order_mode'), $receiver), __FUNCTION__, __LINE__); + array($cat, getConfig('order_select'), getConfig('order_mode'), $receiver), __FUNCTION__, __LINE__); } else { // Include all $result = SQL_QUERY_ESC("SELECT d.userid FROM `{!_MYSQL_PREFIX!}_user_data` AS d ".$CAT_TABS." WHERE d.`status`='CONFIRMED'".$CAT_WHERE." ORDER BY d.%s %s LIMIT %s", - array($cat, getConfig('order_select'), getConfig('order_mode'), $receiver), __FUNCTION__, __LINE__); + array($cat, getConfig('order_select'), getConfig('order_mode'), $receiver), __FUNCTION__, __LINE__); } // Entries found? if ((SQL_NUMROWS($result) >= $receiver) && ($receiver > 0)) { // Load all entries - while (list($REC) = SQL_FETCHROW($result)) { + while ($content = SQL_FETCHARRAY($result)) { // Add receiver when not empty - if (!empty($REC)) $receiverList .= $REC.";"; + if (!empty($content['userid'])) $receiverList .= $content['userid'].";"; } // END - while // Free memory @@ -1998,8 +1990,8 @@ function USER_STATS_GET_TIMESTAMP ($type, $data, $uid = 0) { $stamp = 0; // User id set? - if ((isset($GLOBALS['userid'])) && ($uid == 0)) { - $uid = $GLOBALS['userid']; + if ((isUserIdSet()) && ($uid == 0)) { + $uid = getUserId(); } // END - if // Is the extension installed and updated? @@ -2117,7 +2109,7 @@ ORDER BY ur.refid ASC", } // Recuced the amount of received emails for the receipients for given email -function REDUCT_RECIPIENT_RECEIVED_MAILS ($column, $id, $count) { +function REDUCED_RECIPIENT_RECEIVED_MAILS ($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", array($column, bigintval($id), $count), __FUNCTION__, __LINE__); @@ -2125,6 +2117,7 @@ function REDUCT_RECIPIENT_RECEIVED_MAILS ($column, $id, $count) { // 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($uid) = SQL_FETCHROW($result)) { $UIDs[$uid] = $uid; @@ -2139,5 +2132,65 @@ function REDUCT_RECIPIENT_RECEIVED_MAILS ($column, $id, $count) { SQL_FREERESULT($result); } +// Init SQLs array +function INIT_SQLS () { + SET_SQLS(array()); +} + +// Checks wether the sqls array is initialized +function IS_SQLS_INITIALIZED () { + return ((isset($GLOBALS['sqls'])) && (is_array($GLOBALS['sqls']))); +} + +// Setter for SQLs array +function SET_SQLS ($SQLs) { + $GLOBALS['sqls'] = (array) $SQLs; +} + +// Remover for SQLs array +function UNSET_SQLS () { + unset($GLOBALS['sqls']); +} + +// Getter for SQLs array +function GET_SQLS () { + return $GLOBALS['sqls']; +} + +// Add an SQL to the list +function ADD_SQL ($sql) { + //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("sql=%s, count=%d", $sql, COUNT_SQLS())); + $GLOBALS['sqls'][] = (string) $sql; +} + +// Setter for SQLs key +function SET_SQL_KEY ($key, $value) { + $GLOBALS['sqls'][$key] = (string) $value; +} + +// Counter for SQLs array +function COUNT_SQLS () { + // Default is false + $count = false; + + // Is the array there? + if (IS_SQLS_INITIALIZED()) { + // Then count it + $count = count($GLOBALS['sqls']); + //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("count=%d", $count)); + } // END - if + + // Return it + return $count; +} + +// Checks wether the SQLs array is filled +function IS_SQLS_VALID () { + return ( + (IS_SQLS_INITIALIZED()) && + (COUNT_SQLS() > 0) + ); +} + // [EOF] ?>