Time to stop coding for tonight. Making this kind of terrible bugs is bad.
[squirrelmail.git] / plugins / administrator / options.php
index 1a9baab4281ac6ccd8840be97a5ee35f8b4e6044..32c7cb77849c128dbe5596ddf3fdae969343752e 100644 (file)
@@ -132,13 +132,15 @@ function parseConfig( $cfg_file ) {
 
 /* ---------------------- main -------------------------- */
 
-chdir('..');
-require_once('../src/validate.php');
-require_once('../functions/page_header.php');
-require_once('../functions/imap.php');
-require_once('../src/load_prefs.php');
-require_once('../plugins/administrator/defines.php');
-require_once('../plugins/administrator/auth.php');
+define('SM_PATH','../../');
+
+/* SquirrelMail required files. */
+require_once(SM_PATH . 'include/validate.php');
+require_once(SM_PATH . 'functions/page_header.php');
+require_once(SM_PATH . 'functions/imap.php');
+require_once(SM_PATH . 'include/load_prefs.php');
+require_once(SM_PATH . 'plugins/administrator/defines.php');
+require_once(SM_PATH . 'plugins/administrator/auth.php');
 
 GLOBAL $data_dir, $username;
 
@@ -181,7 +183,7 @@ if ( isset( $switch ) ) {
 }
 
 echo "<form action=options.php method=post name=options>" .
-    "<br><center><table width=95% bgcolor=\"$color[5]\"><tr><td>".
+    "<center><table width=95% bgcolor=\"$color[5]\"><tr><td>".
     "<table width=100% cellspacing=0 bgcolor=\"$color[4]\">" ,
     "<tr bgcolor=\"$color[5]\"><th colspan=2>" . _("Configuration Administrator") . "</th></tr>";
 
@@ -383,7 +385,8 @@ if ( $colapse['Group7'] == 'off' ) {
         $k1 = "\$theme[$i]['NAME']";
         $e1 = "theme_name_$i";
         if ( isset( $HTTP_POST_VARS[$e1] ) ) {
-            $v1 = '"' . $HTTP_POST_VARS[$e1] . '"';
+            $v1 = '"' . str_replace( '\"', '"', $HTTP_POST_VARS[$e1] ) . '"';
+            $v1 = '"' . str_replace( '"', '\"', $v1 ) . '"';
             $newcfg[$k1] = $v1;
         } else {
             $v1 = $newcfg[$k1];
@@ -391,7 +394,8 @@ if ( $colapse['Group7'] == 'off' ) {
         $k2 = "\$theme[$i]['PATH']";
         $e2 = "theme_path_$i";
         if ( isset( $HTTP_POST_VARS[$e2] ) ) {
-            $v2 = '"' . $HTTP_POST_VARS[$e2] . '"';
+            $v2 = '"' . str_replace( '\"', '"', $HTTP_POST_VARS[$e2] ) . '"';
+            $v2 = '"' . str_replace( '"', '\"', $v2 ) . '"';
             $newcfg[$k2] = $v2;
         } else {
             $v2 = $newcfg[$k2];
@@ -486,43 +490,20 @@ echo "<tr bgcolor=\"$color[5]\"><th colspan=2><input value=\"" .
 
 if( $fp = @fopen( $cfgfile, 'w' ) ) {
     fwrite( $fp, "<?PHP\n".
-            "/**\n".
-            " * SquirrelMail Configuration File\n".
-            " * Created using the Administrator Plugin\n".
-            " */\n" );
-
-    /*
-    fwrite( $fp, 'GLOBAL ' );
-    $not_first = FALSE;
-    foreach ( $newcfg as $k => $v ) {
-    if ( $k{0} == '$' ) {
-            if( $i = strpos( $k, '[' ) ) {
-            if( strpos( $k, '[0]' ) ) {
-                    if( $not_first ) {
-                    fwrite( $fp, ', ' );
-                    }
-                    fwrite( $fp, substr( $k, 0, $i) );
-            }
-            } else {
-            if( $not_first ) {
-                    fwrite( $fp, ', ' );
-            }
-            fwrite( $fp, $k );
-            }
-            $not_first = TRUE;
-    }
-    }
-    fwrite( $fp, ";\n" );
-    */
+    "/**\n".
+    " * SquirrelMail Configuration File\n".
+    " * Created using the Administrator Plugin\n".
+    " */\n" );
+
     foreach ( $newcfg as $k => $v ) {
-    if ( $k{0} == '$' && $v <> '' ) {
+        if ( $k{0} == '$' && $v <> '' ) {
             if ( substr( $k, 1, 11 ) == 'ldap_server' ) {
-            $v = substr( $v, 0, strlen( $v ) - 1 ) . "\n)";
-            $v = str_replace( 'array(', "array(\n\t", $v );
-            $v = str_replace( "',", "',\n\t", $v );
+                $v = substr( $v, 0, strlen( $v ) - 1 ) . "\n)";
+                $v = str_replace( 'array(', "array(\n\t", $v );
+                $v = str_replace( "',", "',\n\t", $v );
             }
             fwrite( $fp, "$k = $v;\n" );
-    }
+        }
     }
     fwrite( $fp, '?>' );
     fclose( $fp );
@@ -532,4 +513,4 @@ if( $fp = @fopen( $cfgfile, 'w' ) ) {
          '</font>';
 }
 
-?>
\ No newline at end of file
+?>