X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Fmysql-manager.php;h=db3015241a05653e8326fa33ccd6c73562a577eb;hp=4e10c8874056bca75b325df90ad6ea0926799ff0;hb=b29dab42eab7c64ca1945eb70fa7713f8898f6ae;hpb=cc7c700143bca2420ff0497e648d31a18cc9add2 diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php index 4e10c88740..db3015241a 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 * @@ -39,24 +44,23 @@ if (!defined('__SECURITY')) { // Returns the title for given module function ADD_MODULE_TITLE ($mod) { - global $cacheArray; - // Init variables $name = ""; $result = false; // Is the script installed? - if (isBooleanConstantAndTrue('mxchange_installed')) { + if (isInstalled()) { // Check if cache is valid - if ((GET_EXT_VERSION("cache") >= "0.1.2") && (isset($cacheArray['modules']['module'])) && (in_array($mod, $cacheArray['modules']['module']))) { + if ((GET_EXT_VERSION("cache") >= "0.1.2") && (isset($GLOBALS['cache_array']['modules']['module'])) && (in_array($mod, $GLOBALS['cache_array']['modules']['module']))) { // Load from cache - $name = $cacheArray['modules']['title'][$mod]; + $name = $GLOBALS['cache_array']['modules']['title'][$mod]; // Update cache hits incrementConfigEntry('cache_hits'); } elseif (!EXT_IS_ACTIVE("cache")) { // Load from database - $result = SQL_QUERY_ESC("SELECT title FROM `{!_MYSQL_PREFIX!}_mod_reg` WHERE module='%s' LIMIT 1", array($mod), __FILE__, __LINE__); + $result = SQL_QUERY_ESC("SELECT title FROM `{!_MYSQL_PREFIX!}_mod_reg` WHERE `module`='%s' LIMIT 1", + array($mod), __FUNCTION__, __LINE__); list($name) = SQL_FETCHROW($result); SQL_FREERESULT($result); } @@ -71,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 @@ -80,10 +84,7 @@ function ADD_MODULE_TITLE ($mod) { } // Check validity of a given module name (no file extension) -function CHECK_MODULE ($mod) { - // We need them now here... - global $cacheArray, $cacheInstance; - +function checkModulePermissions ($mod) { // Filter module name (names with low chars and underlines are fine!) $mod = preg_replace("/[^a-z_]/", "", $mod); @@ -97,25 +98,40 @@ function CHECK_MODULE ($mod) { if (EXT_IS_ACTIVE($modSplit[0])) { // The prefix is an extension's name, so let's set it $extension = $modSplit[0]; $mod = $modSplit[1]; - } - } + } // END - if + } // END - if // Major error in module registry is the default $ret = "major"; // Check if script is installed if not return a "done" to prevent some errors - if ((!isBooleanConstantAndTrue('mxchange_installed')) || (isBooleanConstantAndTrue('mxchange_installing')) || (!isBooleanConstantAndTrue('admin_registered'))) return "done"; + if ((!isInstalled()) || (isInstalling()) || (!isAdminRegistered())) { + // Not installed or no admin registered or in installation phase + return "done"; + } // END - if + + // Init variables + $locked = "Y"; + $hidden = "N"; + $admin = "N"; + $mem = "N"; + $found = false; // Check if cache is latest version - $locked = "Y"; $hidden = "N"; $admin = "N"; $mem = "N"; $found = false; 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($cacheArray['modules']['locked'][$mod_chk])) { + if (isset($GLOBALS['cache_array']['modules']['locked'][$mod_chk])) { // Check cache - $locked = $cacheArray['modules']['locked'][$mod_chk]; - $hidden = $cacheArray['modules']['hidden'][$mod_chk]; - $admin = $cacheArray['modules']['admin_only'][$mod_chk]; - $mem = $cacheArray['modules']['mem_only'][$mod_chk]; + $locked = $GLOBALS['cache_array']['modules']['locked'][$mod_chk]; + $hidden = $GLOBALS['cache_array']['modules']['hidden'][$mod_chk]; + $admin = $GLOBALS['cache_array']['modules']['admin_only'][$mod_chk]; + $mem = $GLOBALS['cache_array']['modules']['mem_only'][$mod_chk]; // Update cache hits incrementConfigEntry('cache_hits'); @@ -126,7 +142,8 @@ function CHECK_MODULE ($mod) { } } elseif (!EXT_IS_ACTIVE("cache")) { // Check for module in database - $result = SQL_QUERY_ESC("SELECT locked, hidden, admin_only, mem_only FROM `{!_MYSQL_PREFIX!}_mod_reg` WHERE module='%s' LIMIT 1", array($mod_chk), __FILE__, __LINE__); + $result = SQL_QUERY_ESC("SELECT locked, hidden, admin_only, mem_only FROM `{!_MYSQL_PREFIX!}_mod_reg` WHERE `module`='%s' LIMIT 1", + array($mod_chk), __FUNCTION__, __LINE__); if (SQL_NUMROWS($result) == 1) { // Read data list($locked, $hidden, $admin, $mem) = SQL_FETCHROW($result); @@ -152,12 +169,20 @@ function CHECK_MODULE ($mod) { } elseif (($admin == "Y") && (!IS_ADMIN())) { // Only the Admin is allowed to enter this module! $ret = "admin_only"; + } else { + // @TODO Nothing helped??? + DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("ret=%s,locked=%s,admin=%s,mem=%s", + $ret, + $locked, + $admin, + $mem + )); } } // END - if // Still no luck or not found? if (($ret == "cache_miss") || (!$found)) { - // ----- Legacy module ----- ---- Module in base folder ---- --- Module with extension's name --- + // ----- Legacy module ----- ---- Module in base folder ---- --- Module with extension's name --- if ((FILE_READABLE(sprintf("%sinc/modules/%s.php", constant('PATH'), $mod))) || (FILE_READABLE(sprintf("%s%s.php", constant('PATH'), $mod))) || (FILE_READABLE(sprintf("%s%s/%s.php", constant('PATH'), $extension, $mod)))) { // Data is missing so we add it if (GET_EXT_VERSION("sql_patches") >= "0.3.6") { @@ -165,12 +190,12 @@ function CHECK_MODULE ($mod) { // to find a loop here... *sigh* SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_mod_reg` (module, locked, hidden, mem_only, admin_only, has_menu) VALUES -('%s','Y','N','N','N','N')", array($mod_chk), __FILE__, __LINE__); +('%s','Y','N','N','N','N')", array($mod_chk), __FUNCTION__, __LINE__); } else { // Wrong/missing sql_patches! SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_mod_reg` (module, locked, hidden, mem_only, admin_only) VALUES -('%s','Y','N','N','N')", array($mod_chk), __FILE__, __LINE__); +('%s','Y','N','N','N')", array($mod_chk), __FUNCTION__, __LINE__); } // Everthing is fine? @@ -180,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"; @@ -205,22 +230,21 @@ function CHECK_MODULE ($mod) { } // Add menu description pending on given file name (without path!) -function ADD_DESCR ($ACC_LVL, $file, $return = false, $output = true) { - global $NAV_DEPTH; - - // Use only filename of the file ;) - $file = basename($file); +function ADD_DESCR ($ACC_LVL, $FQFN, $return = false, $output = true) { + // Use only filename of the FQFN... + $file = basename($FQFN); // Init variables - $LINK_ADD = ""; $OUT = ""; $AND = ""; + $LINK_ADD = ""; + $OUT = ""; + $AND = ""; // First we have to do some analysis... if (substr($file, 0, 7) == "action-") { // This is an action file! $type = "action"; $search = substr($file, 7); - switch ($ACC_LVL) - { + switch ($ACC_LVL) { case "admin": $modCheck = "admin"; break; @@ -231,14 +255,13 @@ function ADD_DESCR ($ACC_LVL, $file, $return = false, $output = true) { $modCheck = $GLOBALS['module']; break; } - $AND = " AND (what='' OR `what` IS NULL)"; + $AND = " AND (`what`='' OR `what` IS NULL)"; } elseif (substr($file, 0, 5) == "what-") { // This is an admin what file! $type = "what"; $search = substr($file, 5); $AND = ""; - switch ($ACC_LVL) - { + switch ($ACC_LVL) { case "admin": $modCheck = "admin"; break; @@ -252,25 +275,27 @@ function ADD_DESCR ($ACC_LVL, $file, $return = false, $output = true) { break; } $dummy = substr($search, 0, -4); - $AND .= " AND action='".GET_ACTION($ACC_LVL, $dummy)."'"; + $AND .= " AND `action`='".GET_ACTION($ACC_LVL, $dummy)."'"; } elseif (($ACC_LVL == "sponsor") || ($ACC_LVL == "engine")) { // Sponsor / engine menu - $type = "what"; - $search = $file; + $type = "what"; + $search = $file; $modCheck = $GLOBALS['module']; - $AND = ""; + $AND = ""; } else { // Other - $type = "menu"; - $search = $file; + $type = "menu"; + $search = $file; $modCheck = $GLOBALS['module']; - $AND = ""; + $AND = ""; } - if ((!isset($NAV_DEPTH)) && (!$return)) { - $NAV_DEPTH = 0; - $prefix = "
{!YOU_ARE_HERE!} Home"; + + // Begin the navigation line + if ((!isset($GLOBALS['nav_depth'])) && (!$return)) { + $GLOBALS['nav_depth'] = 0; + $prefix = "
{--YOU_ARE_HERE--} Home"; } else { - if (!$return) $NAV_DEPTH++; + if (!$return) $GLOBALS['nav_depth']++; $prefix = ""; } @@ -284,7 +309,7 @@ function ADD_DESCR ($ACC_LVL, $file, $return = false, $output = true) { // Get the title from menu $result = SQL_QUERY_ESC("SELECT title FROM `{!_MYSQL_PREFIX!}_%s_menu` WHERE %s='%s' ".$AND." LIMIT 1", - array($ACC_LVL, $type, $search), __FILE__, __LINE__); + array($ACC_LVL, $type, $search), __FUNCTION__, __LINE__); // Menu found? if (SQL_NUMROWS($result) == 1) { @@ -292,7 +317,7 @@ function ADD_DESCR ($ACC_LVL, $file, $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"))) { @@ -305,10 +330,10 @@ function ADD_DESCR ($ACC_LVL, $file, $return = false, $output = true) { //* DEBUG: */ echo __LINE__."+".$type."+
\n"; // Add closing div and br-tag $OUT .= "

\n"; - $NAV_DEPTH = "0"; + $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 } @@ -335,74 +360,86 @@ function ADD_MENU ($MODE, $act, $wht) { $main_action = ""; $sub_what = ""; - if (!VALIDATE_MENU_ACTION($MODE, $act, $wht, true)) return getMessage('CODE_MENU_NOT_VALID'); + // is the menu action valid? + if (!VALIDATE_MENU_ACTION($MODE, $act, $wht, true)) { + 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`", - array($MODE), __FILE__, __LINE__); + $result_main = SQL_QUERY_ESC("SELECT title, action FROM `{!_MYSQL_PREFIX!}_%s_menu` WHERE (`what`='' OR `what` IS NULL)".$AND." ORDER BY `sort`", + array($MODE), __FUNCTION__, __LINE__); //* DEBUG: */ echo __LINE__."/".$main_cnt."/".$main_action."/".$sub_what.":".$GLOBALS['what']."*
\n"; 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), __FILE__, __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? @@ -414,39 +451,39 @@ 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("
"); } } // This patched function will reduce many SELECT queries for the specified or current admin login function IS_ADMIN ($admin="") { - global $cacheArray; - // Init variables $ret = false; $passCookie = ""; $valPass = ""; //* DEBUG: */ echo __LINE__."ADMIN:".$admin."
"; @@ -460,22 +497,22 @@ function IS_ADMIN ($admin="") { //* DEBUG: */ echo __LINE__."ADMIN:".$admin."/".$passCookie."
"; // Search in array for entry - if (isset($cacheArray['admin_hash'])) { + if (isset($GLOBALS['cache_array']['admin_hash'])) { // Use cached string - $valPass = $cacheArray['admin_hash']; - } elseif ((!empty($passCookie)) && (isset($cacheArray['admins']['password'][$admin])) && (!empty($admin))) { + $valPass = $GLOBALS['cache_array']['admin_hash']; + } elseif ((!empty($passCookie)) && (isset($GLOBALS['cache_array']['admins']['password'][$admin])) && (!empty($admin))) { // Login data is valid or not? - $valPass = generatePassString($cacheArray['admins']['password'][$admin]); + $valPass = generatePassString($GLOBALS['cache_array']['admins']['password'][$admin]); // Cache it away - $cacheArray['admin_hash'] = $valPass; + $GLOBALS['cache_array']['admin_hash'] = $valPass; // Count cache hits incrementConfigEntry('cache_hits'); - } elseif ((!empty($admin)) && ((!EXT_IS_ACTIVE("cache"))) || (!isset($cacheArray['admins']['password'][$admin]))) { + } elseif ((!empty($admin)) && ((!EXT_IS_ACTIVE("cache"))) || (!isset($GLOBALS['cache_array']['admins']['password'][$admin]))) { // Search for admin $result = SQL_QUERY_ESC("SELECT HIGH_PRIORITY password FROM `{!_MYSQL_PREFIX!}_admins` WHERE login='%s' LIMIT 1", - array($admin), __FILE__, __LINE__); + array($admin), __FUNCTION__, __LINE__); // Is he admin? $passDB = ""; @@ -484,7 +521,7 @@ function IS_ADMIN ($admin="") { list($passDB) = SQL_FETCHROW($result); // Temporary cache it - $cacheArray['admins']['password'][$admin] = $passDB; + $GLOBALS['cache_array']['admins']['password'][$admin] = $passDB; // Generate password hash $valPass = generatePassString($passDB); @@ -507,55 +544,50 @@ function IS_ADMIN ($admin="") { // Generates a list of "max receiveable emails per day" function ADD_MAX_RECEIVE_LIST ($MODE, $default = "", $return = false) { - global $_POST; $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", __FILE__, __LINE__); - if (SQL_NUMROWS($result) > 0) { - $OUT = ""; - while (list($value, $comment) = SQL_FETCHROW($result)) { - $OUT .= "