Again more fixes from bugtracker, thanks to profi-concept
[mailer.git] / inc / modules / admin / what-usage.php
index 65b2810ca7c01836232fa6005609c9ce52696f74..fb3bd33282d10f34a546ba848698092971b72dea 100644 (file)
@@ -41,14 +41,19 @@ if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
 ADD_DESCR("admin", __FILE__);
 
 // Base directory (should be moved to database)
-$usage = "usage/";
+$usage = getConfig('usage_base')."/";
 
 if (!empty($_GET['image'])) {
        if ($_GET['type'] == "usage") {
-               $file = sprintf("%s%susage.png", PATH, $usage);
+               $file = sprintf("%s%s/usage.png", PATH, getConfig('usage_base'));
        } else {
                if (strpos($_GET['image'], "\\") > 0) $_GET['image'] = substr($_GET['image'], 0, strpos($_GET['image'], "\\"));
-               $file = sprintf("%s%s%s_usage_%s.png", PATH, $usage, SQL_ESCAPE($_GET['type']), SQL_ESCAPE($_GET['image']));
+               $file = sprintf("%s%s/%s_usage_%s.png",
+                       PATH,
+                       getConfig('usage_base'),
+                       SQL_ESCAPE($_GET['type']),
+                       SQL_ESCAPE($_GET['image'])
+               );
        }
 
        if (FILE_READABLE($file)) {
@@ -59,44 +64,48 @@ if (!empty($_GET['image'])) {
        }
        exit();
 } elseif (empty($_GET['usage'])) {
-       $file = sprintf("%s%sindex.html", PATH, $usage);
+       $file = sprintf("%s%s/index.html", PATH, getConfig('usage_base'));
 } else {
-       $file = sprintf("%s%susage_%s.html",
+       $file = sprintf("%s%s/usage_%s.html",
                PATH,
-               $usage,
+               getConfig('usage_base'),
                SQL_ESCAPE($_GET['usage'])
        );
 }
 
-if (!empty($file)) {
-       if (FILE_READABLE($file)) {
-                       // @TODO This code is double, see functions.php, LOAD_TEMPLATE and LOAD_EMAIL_TEMPLATE
-                       $tmpl_file = READ_FILE($file);
-                       $tmpl_file = addslashes($tmpl_file);
-                       $tmpl_file = "\$content=\"".$tmpl_file."\";";
-                       eval($tmpl_file);
-                       // Double code until here
+if ((!empty($file)) && (FILE_READABLE($file) {
+       // @TODO This code is double, see LOAD_TEMPLATE and LOAD_EMAIL_TEMPLATE in functions.php
+       $tmpl_file = READ_FILE($file);
+       $tmpl_file = addslashes($tmpl_file);
+       $tmpl_file = "\$content=\"".$tmpl_file."\";";
+       eval($tmpl_file);
+       // Until here...
+
+       // Replace URLs
+       $content = str_replace("usage.png", URL."/modules.php?module=admin&what=".$GLOBALS['what']."&type=usage&image=usage", $content);
+       $content = str_replace("daily_usage_", URL."/modules.php?module=admin&what=".$GLOBALS['what']."&type=daily&image=", $content);
+       $content = str_replace("hourly_usage_", URL."/modules.php?module=admin&what=".$GLOBALS['what']."&type=hourly&image=", $content);
+       $content = str_replace("ctry_usage_", URL."/modules.php?module=admin&what=".$GLOBALS['what']."&type=ctry&image=", $content);
+       $content = str_replace("usage_", URL."/modules.php?module=admin&what=".$GLOBALS['what']."&usage=", str_replace(".html", "", $content));
+
+       // Disabled due to too much trouble
+       //$content = str_replace("HREF=\"http://", "href=\"".URL."/modules.php?module=loader&url=http://", $content);
+       $test = strtolower($content);
 
-                       // Replace URLs
-                       $content = str_replace("usage.png", URL."/modules.php?module=admin&what=".$GLOBALS['what']."&type=usage&image=usage", $content);
-                       $content = str_replace("daily_usage_", URL."/modules.php?module=admin&what=".$GLOBALS['what']."&type=daily&image=", $content);
-                       $content = str_replace("hourly_usage_", URL."/modules.php?module=admin&what=".$GLOBALS['what']."&type=hourly&image=", $content);
-                       $content = str_replace("ctry_usage_", URL."/modules.php?module=admin&what=".$GLOBALS['what']."&type=ctry&image=", $content);
-                       $content = str_replace("usage_", URL."/modules.php?module=admin&what=".$GLOBALS['what']."&usage=", str_replace(".html", "", $content));
-                       // Disabled due to too much trouble
-                       //$content = str_replace("HREF=\"http://", "href=\"".URL."/modules.php?module=loader&url=http://", $content);
-                       $test = strtolower($content);
-                       $body_start = strpos($test, "<body");
-                       $body_end   = strpos($test, "</body>");
-                       if (($body_start > 0) && ($body_end > 0))
-                       {
-                               $content = substr(substr($content, 0, $body_end), $body_start);
-                               $content = substr($content, strpos($content, ">") + 1);
-                               OUTPUT_HTML("<div align=\"left\">
+       // Do we need to strip out above and including <body> plus trailing </html> tag?
+       if ((strpos($test, "<body") > 0) && (strpos($test, "</body>") > 0)) {
+               // Okay, then do so.
+               $content = substr(substr($content, 0, $body_end), $body_start);
+               $content = substr($content, strpos($content, ">") + 1);
+       } // END - if
+
+       // Output code
+       OUTPUT_HTML("<div align=\"left\">
   ".$content."
 </div>");
-                       }
-       }
+} else {
+       // Nothing to load, then we have no directory "usage"
+       LOAD_TEMPLATE("admin_settings_saved", false, sprintf(ADMIN_USAGE_DIRECTORY_404, getConfig('usage_base')));
 }
 
 //