A *lot* more code-cleanups, errors in CSS fixed (missing brackets) and frameset suppo...
[mailer.git] / inc / mysql-manager.php
index a2cb2579fa00f7e7279a23ff1264e15a9736bdb9..562738fc29b00e676dfa6da1bf38758aae58581f 100644 (file)
@@ -79,9 +79,8 @@ function ADD_MODULE_TITLE($mod)
        }
        return $name;
 }
-//
-function CHECK_MODULE($mod)
-{
+// Check validity of a given module name (no file extension)
+function CHECK_MODULE($mod) {
        // We need them now here...
        global $MODULES, $CONFIG, $CACHE;
 
@@ -89,17 +88,15 @@ function CHECK_MODULE($mod)
        $mod = preg_replace("/[^a-z_]/", "", $mod);
 
        // Check for prefix is a extension...
-       $MOD_SPLIT = explode("_", $mod);
+       $modSplit = explode("_", $mod);
        $extension = ""; $mod_chk = $mod;
-       //* DEBUG: */ echo __LINE__."*".count($MOD_SPLIT)."*/".$mod."*<BR>";
-       if (count($MOD_SPLIT) == 2)
-       {
+       //* DEBUG: */ echo __LINE__."*".count($modSplit)."*/".$mod."*<br />";
+       if (count($modSplit) == 2) {
                // Okay, there is a seperator (_) in the name so is the first part a module?
-               //* DEBUG: */ echo __LINE__."*".$MOD_SPLIT[0]."*<BR>";
-               if (EXT_IS_ACTIVE($MOD_SPLIT[0]))
-               {
+               //* DEBUG: */ echo __LINE__."*".$modSplit[0]."*<br />";
+               if (EXT_IS_ACTIVE($modSplit[0])) {
                        // The prefix is an extension's name, so let's set it
-                       $extension = $MOD_SPLIT[0]; $mod = $MOD_SPLIT[1];
+                       $extension = $modSplit[0]; $mod = $modSplit[1];
                }
        }
 
@@ -111,8 +108,7 @@ function CHECK_MODULE($mod)
 
        // 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_array($MODULES['module'])))
-       {
+       if ((GET_EXT_VERSION("cache") >= "0.1.2") && (is_array($MODULES['module']))) {
                // Is the module cached?
                if (isset($MODULES['locked'][$mod_chk])) {
                        // Check cache
@@ -128,13 +124,10 @@ function CHECK_MODULE($mod)
                        // No, then we have to update it!
                        $ret = "cache_miss";
                }
-       }
-        else
-       {
+       } else {
                // 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__);
-               if (SQL_NUMROWS($result) == 1)
-               {
+               if (SQL_NUMROWS($result) == 1) {
                        // Read data
                        list($locked, $hidden, $admin, $mem) = SQL_FETCHROW($result);
                        SQL_FREERESULT($result);
@@ -145,33 +138,24 @@ function CHECK_MODULE($mod)
        // Check returned values against current access permissions
        //
        //  Admin access            ----- Guest access -----           --- Guest   or   member? ---
-       if ((IS_ADMIN()) || (($locked == 'N') && ($admin == 'N') && (($mem == 'N') || (IS_LOGGED_IN()))))
-       {
+       if ((IS_ADMIN()) || (($locked == 'N') && ($admin == 'N') && (($mem == 'N') || (IS_LOGGED_IN())))) {
                // If you are admin you are welcome for everything!
                $ret = "done";
-       }
-        elseif ($locked == 'Y')
-       {
+       } elseif ($locked == 'Y') {
                // Module is locked
                $ret = "locked";
-       }
-        elseif (($mem == 'Y') && (!IS_LOGGED_IN()))
-       {
+       } elseif (($mem == 'Y') && (!IS_LOGGED_IN())) {
                // You have to login first!
                $ret = "mem_only";
-       }
-        elseif (($admin == 'Y') && (!IS_ADMIN()))
-       {
+       } elseif (($admin == 'Y') && (!IS_ADMIN())) {
                // Only the Admin is allowed to enter this module!
                $ret = "admin_only";
        }
 
        // Still no luck or not found?
-       if (($ret == "major") || ($ret == "cache_miss") || (!$found))
-       {
+       if (($ret == "major") || ($ret == "cache_miss") || (!$found)) {
                //         ----- Legacy module -----                      ---- Module in base folder  ----           --- Module with extension's name ---
-               if ((file_exists(PATH."inc/modules/".$mod.".php")) || (file_exists(PATH.$mod.".php")) || (file_exists(PATH.$extension."/".$mod.".php")))
-               {
+               if ((file_exists(PATH."inc/modules/".$mod.".php")) || (file_exists(PATH.$mod.".php")) || (file_exists(PATH.$extension."/".$mod.".php"))) {
                        // Data is missing so we add it
                        if (GET_EXT_VERSION("sql_patches") >= "0.3.6") {
                                // Since 0.3.6 we have a has_menu column, this took me a half hour
@@ -212,14 +196,13 @@ function CHECK_MODULE($mod)
        // Return the value
        return $ret;
 }
-//
+// Add menu description pending on given file name (without path!)
 function ADD_DESCR($ACC_LVL, $file, $return = false, $output = true)
 {
        global $DEPTH, $CONFIG;
        $LINK_ADD = ""; $OUT = ""; $AND = "";
        // First we have to do some analysis...
-       if (ereg("action-", $file))
-       {
+       if (ereg("action-", $file)) {
                // This is an action file!
                $type = "action";
                $search = substr($file, 7);
@@ -236,9 +219,7 @@ function ADD_DESCR($ACC_LVL, $file, $return = false, $output = true)
                        break;
                }
                $AND = " AND what=''";
-       }
-        elseif (ereg("what-", $file))
-       {
+       } elseif (ereg("what-", $file)) {
                // This is an admin what file!
                $type = "what";
                $search = substr($file, 5);
@@ -252,84 +233,67 @@ function ADD_DESCR($ACC_LVL, $file, $return = false, $output = true)
                case "guest":
                case "member":
                        $MOD_CHECK = $GLOBALS['module'];
-                       if (!IS_ADMIN())
-                       {
+                       if (!IS_ADMIN()) {
                                $AND = " AND visible='Y' AND locked='N'";
                        }
                        break;
                }
                $DUMMY = substr($search, 0, -4);
                $AND .= " AND action='".GET_ACTION($ACC_LVL, $DUMMY)."'";
-       }
-        elseif (($ACC_LVL == "sponsor") || ($ACC_LVL == "engine"))
-       {
+       } elseif (($ACC_LVL == "sponsor") || ($ACC_LVL == "engine")) {
                // Sponsor / engine menu
                $type = "what";
                $search = $file;
                $MOD_CHECK = $GLOBALS['module'];
                $AND = "";
-       }
-        else
-       {
+       } else {
                // Other
                $type = "menu";
                $search = $file;
                $MOD_CHECK = $GLOBALS['module'];
                $AND = "";
        }
-       if ((!isset($DEPTH)) && (!$return))
-       {
+       if ((!isset($DEPTH)) && (!$return)) {
                $DEPTH = "0";
                $prefix = "<DIV class=\"you_are_here\">".YOU_ARE_HERE."&nbsp;<STRONG><A class=\"you_are_here\" href=\"".URL."/modules.php?module=".$GLOBALS['module'].$LINK_ADD."\">Home</A></STRONG>";
-       }
-        else
-       {
+       } else {
                if (!$return) $DEPTH++;
                $prefix = "";
        }
        $prefix .= "&nbsp;-&gt;&nbsp;";
-       if (ereg(".php", $search))
-       {
+       if (ereg(".php", $search)) {
                $search = substr($search, 0, strpos($search, ".php"));
        }
        $result = SQL_QUERY_ESC("SELECT title FROM "._MYSQL_PREFIX."_%s_menu WHERE %s='%s' ".$AND." LIMIT 1",
         array($ACC_LVL, $type, $search), __FILE__, __LINE__);
-       if (SQL_NUMROWS($result) == 1)
-       {
+       if (SQL_NUMROWS($result) == 1) {
                list($ret) = SQL_FETCHROW($result);
                SQL_FREERESULT($result);
-               if ($return)
-               {
+               if ($return) {
                        // Return title
                        return $ret;
-               }
-                elseif (((GET_EXT_VERSION("sql_patches") >= "0.2.3") && ($CONFIG['youre_here'] == 'Y')) || ((IS_ADMIN()) && ($MOD_CHECK == "admin")))
-               {
+               } elseif (((GET_EXT_VERSION("sql_patches") >= "0.2.3") && ($CONFIG['youre_here'] == 'Y')) || ((IS_ADMIN()) && ($MOD_CHECK == "admin"))) {
                        // Output HTML code
                        $OUT = $prefix."<STRONG><A class=\"you_are_here\" href=\"".URL."/modules.php?module=".$MOD_CHECK."&amp;".$type."=".$search.$LINK_ADD."\">".$ret."</A></STRONG>\n";
                        //* DEBUG: */ echo __LINE__."*".$type."/".$GLOBALS['what']."*<br />\n";
                        if (($type == "what") || (($type == "action") && (!isset($_GET['what'])) && ($GLOBALS['what'] != "welcome"))) {
                                //* DEBUG: */ echo __LINE__."+".$type."+<br />\n";
-                               $OUT .= "</DIV><BR>\n";
+                               $OUT .= "</DIV><br />\n";
                        }
                }
        }
 
        // Return or output HTML code?
-       if ($output)
-       {
+       if ($output) {
                // Output HTML code here
                OUTPUT_HTML($OUT);
-       }
-        else
-       {
+       } else {
                // Return HTML code
                return $OUT;
        }
 }
 //
-function ADD_MENU($MODE, $act, $wht)
-{
+function ADD_MENU($MODE, $act, $wht) {
        global $CONFIG;
        if (!VALIDATE_MENU_ACTION($MODE, $act, $wht, true)) return CODE_MENU_NOT_VALID;
        $main_cnt = 0; $AND = ""; $main_action = ""; $sub_what = "";
@@ -366,66 +330,41 @@ function ADD_MENU($MODE, $act, $wht)
                                        //* DEBUG: */ echo __LINE__.":!!!!".$sub_what."!!!<br />\n";
                                        $test_inc = sprintf("%sinc/modules/%s/what-%s.php", PATH, $MODE, $sub_what);
                                        $test = (file_exists($test_inc) && is_readable($test_inc));
-                                       if ($test)
-                                       {
-                                               if ((!empty($wht)) && (($wht == $sub_what)))
-                                               {
+                                       if ($test) {
+                                               if ((!empty($wht)) && (($wht == $sub_what))) {
                                                        $content = "<STRONG>";
                                                }
 
                                                // Navigation link
-                                               $content .= "<A name=\"menu\" class=\"menu_blur\" href=\"".URL."/modules.php?module=".$GLOBALS['module']."&amp;what=".$sub_what.ADD_URL_DATA("")."\"";
-
-                                               if (frameset_active)
-                                               {
-                                                       // We need to add a JavaScript here to reload both frames!
-                                               }
-                                                else
-                                               {
-                                                       // Add the default target _self
-                                                       $content .= " target=\"_self\"";
-                                               }
-                                               $content .= ">";
-                                       }
-                                        else
-                                       {
+                                               $content .= "<A name=\"menu\" class=\"menu_blur\" href=\"".URL."/modules.php?module=".$GLOBALS['module']."&amp;what=".$sub_what.ADD_URL_DATA("")."\" target=\"_self\">";
+                                       } else {
                                                $content .= "<I>";
                                        }
 
                                        // Menu title
                                        $content .= $CONFIG['middot'].$sub_title;
 
-                                       if ($test)
-                                       {
+                                       if ($test) {
                                                $content .= "</A>";
-                                       }
-                                        else
-                                       {
+                                       } else {
                                                $content .= "</I>";
                                        }
 
-                                       if ((!empty($wht)) && (($wht == $sub_what)))
-                                       {
+                                       if ((!empty($wht)) && (($wht == $sub_what))) {
                                                $content .= "</STRONG>";
                                        }
                                        $wht = $sub_what; $cnt++;
-                                       if ($cnt < $ctl)
-                                       {
+                                       if ($cnt < $ctl) {
                                                LOAD_TEMPLATE($MODE."_menu_row", false, $content);
-                                       }
-                                        else
-                                       {
+                                       } else {
                                                LOAD_TEMPLATE($MODE."_menu_bottom", false, $content);
                                        }
                                }
-                       }
-                        else
-                       {
+                       } else {
                                // This is a menu block... ;-)
                                $BLOCK_MODE = true;
                                $INC_BLOCK = sprintf(PATH."inc/modules/%s/action-%s.php", $MODE, $main_action);
-                               if ((file_exists($INC_BLOCK)) && (is_readable($INC_BLOCK)))
-                               {
+                               if ((file_exists($INC_BLOCK)) && (is_readable($INC_BLOCK))) {
                                        // Load include file
                                        if ((!EXT_IS_ACTIVE($main_action)) || ($main_action == "online")) OUTPUT_HTML("<TR>
   <TD class=\"".$MODE."_menu_whats\">");
@@ -455,14 +394,14 @@ function IS_ADMIN($admin="")
 {
        global $_COOKIE, $ADMINS, $CONFIG;
        $ret = false; $passCookie = ""; $valPass = "";
-       //* DEBUG: */ echo __LINE__."ADMIN:".$admin."<BR>";
+       //* DEBUG: */ echo __LINE__."ADMIN:".$admin."<br />";
 
        // If admin login is not given take current from cookies...
        if ((empty($admin)) && (!empty($_COOKIE['admin_login'])) && (!empty($_COOKIE['admin_md5'])))
        {
                $admin = SQL_ESCAPE($_COOKIE['admin_login']); $passCookie = $_COOKIE['admin_md5'];
        }
-       //* DEBUG: */ echo __LINE__."ADMIN:".$admin."/".$passCookie."<BR>";
+       //* DEBUG: */ echo __LINE__."ADMIN:".$admin."/".$passCookie."<br />";
 
        // Search in array for entry
        if ((!empty($passCookie)) && (isset($ADMINS['password'][$admin])) && (!empty($admin)))
@@ -1531,7 +1470,7 @@ function META_DESCRIPTION($mod, $wht)
                // Exclude admin and member's area
                $DESCR = MAIN_TITLE." ".trim($CONFIG['title_middle'])." ".ADD_DESCR("guest", "what-".$wht, true);
                unset($DEPTH);
-               OUTPUT_HTML("<META name=\"description\" content=\"".$DESCR."\">\n");
+               OUTPUT_HTML("<META name=\"description\" content=\"".$DESCR."\">");
        }
 }
 //