Added validate to translate
[squirrelmail.git] / plugins / administrator / options.php
index 0f8337e91f04636d947b1696b1ccdc9839ba690f..f9f06adda65a06addea32f87db61eb2681e39316 100644 (file)
@@ -72,7 +72,8 @@ function parseConfig( $cfg_file ) {
                 break;
             case 'C':
                 // Comments
-                if ( $line{$j}.$line{$j+1} == '*/' ) {
+                if ( $s > $j + 1  &&
+                     $line{$j}.$line{$j+1} == '*/' ) {
                     $mode = '';
                     $j++;
                 }
@@ -107,7 +108,12 @@ function parseConfig( $cfg_file ) {
                 }
                 break;
             default:
-                if ( strtoupper( substr( $line, $j, 7 ) ) == 'GLOBAL ' ) {
+                if ( $line{$j} == '$' ) {
+                    // We must detect $key name
+                    $mode = 'K';
+                    $key = '$';
+                } else if ( $s < $j + 2 ) {
+                } else if ( strtoupper( substr( $line, $j, 7 ) ) == 'GLOBAL ' ) {
                     // Skip untill next ;
                     $mode = ';';
                     $j += 6;
@@ -117,10 +123,6 @@ function parseConfig( $cfg_file ) {
                 } else if ( $line{$j} == '#' || $line{$j}.$line{$j+1} == '//' ) {
                     // Delete till the end of the line
                     $j = $s;
-                } else if ( $line{$j} == '$' ) {
-                    // We must detect $key name
-                    $mode = 'K';
-                    $key = '$';
                 }
             }
         }
@@ -136,18 +138,11 @@ 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');
 
 GLOBAL $data_dir, $username;
 
-$auth = FALSE;
-if ( $adm_id = fileowner('../config/config.php') ) {
-    $adm = posix_getpwuid( $adm_id );
-    if ( $username == $adm['name'] ) {
-        $auth = TRUE;
-    }
-}
-
-if ( !auth ) {
+if ( !adm_check_user() ) {
     header("Location: ../../src/options.php") ;
     exit;
 }
@@ -164,27 +159,34 @@ $cfgfile = '../config/config.php';
 parseConfig( '../config/config_default.php' );
 parseConfig( $cfgfile );
 
-$colapse = array( 'Titles' => FALSE,
-                  'Group1' => getPref($data_dir, $username, 'adm_Group1', FALSE ),
-                  'Group2' => getPref($data_dir, $username, 'adm_Group2', TRUE ),
-                  'Group3' => getPref($data_dir, $username, 'adm_Group3', TRUE ),
-                  'Group4' => getPref($data_dir, $username, 'adm_Group4', TRUE ),
-                  'Group5' => getPref($data_dir, $username, 'adm_Group5', TRUE ),
-                  'Group6' => getPref($data_dir, $username, 'adm_Group6', TRUE ),
-                  'Group7' => getPref($data_dir, $username, 'adm_Group7', TRUE ) );
+$colapse = array( 'Titles' => 'off',
+                  'Group1' => getPref($data_dir, $username, 'adm_Group1', 'off' ),
+                  'Group2' => getPref($data_dir, $username, 'adm_Group2', 'on' ),
+                  'Group3' => getPref($data_dir, $username, 'adm_Group3', 'on' ),
+                  'Group4' => getPref($data_dir, $username, 'adm_Group4', 'on' ),
+                  'Group5' => getPref($data_dir, $username, 'adm_Group5', 'on' ),
+                  'Group6' => getPref($data_dir, $username, 'adm_Group6', 'on' ),
+                  'Group7' => getPref($data_dir, $username, 'adm_Group7', 'on' ),
+                  'Group8' => getPref($data_dir, $username, 'adm_Group8', 'on' ) );
 
 if ( isset( $switch ) ) {
-    $colapse[$switch] = !$colapse[$switch];
+
+    if ( $colapse[$switch] == 'on' ) {
+       $colapse[$switch] = 'off';
+    } else {
+       $colapse[$switch] = 'on';
+    }
     setPref($data_dir, $username, "adm_$switch", $colapse[$switch] );
+
 }
 
-echo "<form action=$PHP_SELF method=post>" .
+echo "<form action=options.php method=post name=options>" .
     "<br><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>";
 
 $act_grp = 'Titles';  /* Active group */
-    
+
 foreach ( $newcfg as $k => $v ) {
     $l = strtolower( $v );
     $type = SMOPT_TYPE_UNDEFINED;
@@ -197,7 +199,11 @@ foreach ( $newcfg as $k => $v ) {
     if ( isset( $defcfg[$k] ) ) {
         $name = $defcfg[$k]['name'];
         $type = $defcfg[$k]['type'];
-        $size = $defcfg[$k]['size'];
+        if ( isset( $defcfg[$k]['size'] ) ) {
+            $size = $defcfg[$k]['size'];
+        } else {
+            $size = 40;
+        }
     } else if ( $l == 'true' ) {
         $v = 'TRUE';
         $type = SMOPT_TYPE_BOOLEAN;
@@ -218,7 +224,7 @@ foreach ( $newcfg as $k => $v ) {
         $type = SMOPT_TYPE_LDAP;
     }
 
-    if( $type == SMOPT_TYPE_TITLE || !$colapse[$act_grp] ) {
+    if( $type == SMOPT_TYPE_TITLE || $colapse[$act_grp] == 'off' ) {
 
         switch ( $type ) {
         case SMOPT_TYPE_LDAP:
@@ -226,8 +232,13 @@ foreach ( $newcfg as $k => $v ) {
         case SMOPT_TYPE_THEME:
         case SMOPT_TYPE_HIDDEN:
             break;
+        case SMOPT_TYPE_EXTERNAL:
+            echo "<tr><td>$name</td><td><b>" .
+                 $defcfg[$k]['value'] .
+                 "</b></td></tr>";
+            break;
         case SMOPT_TYPE_TITLE:
-            if ( $colapse[$k] ) {
+            if ( $colapse[$k] == 'on' ) {
                 $sw = '(+)';
             } else {
                 $sw = '(-)';
@@ -299,7 +310,7 @@ foreach ( $newcfg as $k => $v ) {
             }
             echo "</td></tr>\n";
             break;
-    
+
         case SMOPT_TYPE_TEXTAREA:
             if ( isset( $HTTP_POST_VARS[$e] ) ) {
                 $v = '"' . $HTTP_POST_VARS[$e] . '"';
@@ -317,6 +328,10 @@ foreach ( $newcfg as $k => $v ) {
                 $v = '"' . $HTTP_POST_VARS[$e] . '"';
                 $newcfg[$k] = $v;
             }
+            if ( $v == '""' && isset( $defcfg[$k]['default'] ) ) {
+                $v = "'" . $defcfg[$k]['default'] . "'";
+                $newcfg[$k] = $v;
+            }
             echo "<tr><td>$name</td><td>".
                  "<input size=\"$size\" name=\"adm_$n\" value=\"" . substr( $v, 1, strlen( $v ) - 2 ) . "\">";
             if ( isset( $defcfg[$k]['comment'] ) ) {
@@ -358,7 +373,8 @@ foreach ( $newcfg as $k => $v ) {
 
 }
 
-if ( !($colapse['Group6']) ) {
+/* Special Themes Block */
+if ( $colapse['Group7'] == 'off' ) {
     $i = 0;
     echo '<tr><th>' . _("Theme Name") .
          '</th><th>' . _("Theme Path") .
@@ -387,60 +403,78 @@ if ( !($colapse['Group6']) ) {
              "<td><input name=\"$e2\" value=\"$path\" size=40></td>".
              "</tr>\n";
         $i++;
-    
+
     }
 }
 
-if ( $colapse['Group7'] ) {
+/* Special Plugins Block */
+if ( $colapse['Group8'] == 'on' ) {
     $sw = '(+)';
 } else {
     $sw = '(-)';
 }
 echo "<tr bgcolor=\"$color[0]\"><th colspan=2>" .
-     "<a href=options.php?switch=Group7 STYLE=\"text-decoration:none\"><b>$sw</b> </a>" .
+     "<a href=options.php?switch=Group8 STYLE=\"text-decoration:none\"><b>$sw</b> </a>" .
      _("Plugins") . '</th></tr>';
 
-if( !$colapse['Group7'] ) {
+if( $colapse['Group8'] == 'off' ) {
 
     $fd = opendir( '../plugins/' );
     $op_plugin = array();
+    $p_count = 0;
     while (false!==($file = readdir($fd))) {
         if ($file != '.' && $file != '..' && $file != 'CVS' ) {
             if ( filetype( $file ) == 'dir' ) {
                 $op_plugin[] = $file;
+                $p_count++;
             }
         }
     }
     closedir($fd);
     asort( $op_plugin );
-    
-    $i = 0;
-    while ( isset( $newcfg["\$plugins[$i]"] ) ) {
-        $k = "\$plugins[$i]";
-        $e = "plugin_$i";
-        if ( isset( $HTTP_POST_VARS[$e] ) ) {
-            $v = '"' . $HTTP_POST_VARS[$e] . '"';
-            $newcfg[$k] = $v;
-        } else {
+
+    /* Lets get the plugins that are active */
+    $plugins = array();
+    if ( isset( $HTTP_POST_VARS['plg'] ) ) {
+        foreach ( $op_plugin as $plg ) {
+            if ( isset( $HTTP_POST_VARS["plgs_$plg"] ) &&
+                 $HTTP_POST_VARS["plgs_$plg"] == 'on' ) {
+                $plugins[] = $plg;
+            }
+        }
+        $i = 0;
+        foreach ( $plugins as $plg ) {
+            $k = "\$plugins[$i]";
+            $newcfg[$k] = "'$plg'";
+            $i++;
+        }
+        while ( isset( $newcfg["\$plugins[$i]"] ) ) {
+            $k = "\$plugins[$i]";
+            $newcfg[$k] = '';
+            $i++;
+        }
+    } else {
+        $i = 0;
+        while ( isset( $newcfg["\$plugins[$i]"] ) ) {
+            $k = "\$plugins[$i]";
             $v = $newcfg[$k];
+            $plugins[] = substr( $v, 1, strlen( $v ) - 2 );
+            $i++;
         }
-        $name = substr( $v, 1, strlen( $v ) - 2 );
-        echo '<tr>'.
-             "<td align=right>$i.</td>".
-             "<td><select name=\"$e\">";
-        foreach ( $op_plugin as $op ) {
-            if ( $op == $name ) {
-                $cs = ' selected';
-            } else {
-                $cs = '';
-            }
-            echo "<option$cs>$op</option>";
+    }
+    echo "<tr><td colspan=2><input type=hidden name=plg value=on><center><table><tr><td>";
+    foreach ( $op_plugin as $plg ) {
+        if ( in_array( $plg, $plugins ) ) {
+            $sw = ' checked';
+        } else {
+            $sw = '';
         }
-        echo "</select></td>".
-             '</tr>';
-        $i++;
-    
+        echo '<tr>' .
+             "<td>$plg</td><td><input$sw type=checkbox name=plgs_$plg></td>".
+             "</tr>\n";
     }
+    echo '</td></tr></table>';
+
 }
 echo "<tr bgcolor=\"$color[5]\"><th colspan=2><input value=\"" .
      _("Change Settings") . "\" type=submit></th></tr>" ,
@@ -481,7 +515,7 @@ foreach ( $newcfg as $k => $v ) {
 fwrite( $fp, ";\n" );
 */
 foreach ( $newcfg as $k => $v ) {
-    if ( $k{0} == '$' ) {
+    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 );