Initial groundwork to use phpdocumentor.
[squirrelmail.git] / plugins / administrator / options.php
index ff05481787564bf4b122dd2e7f387cfd2253910c..7f95e5b6831952b10d28e7c05db70b2509888063 100644 (file)
@@ -9,8 +9,13 @@
  * Philippe Mingo
  *
  * $Id$
+ * @package plugins
+ * @subpackage administrator
  */
 
+/**
+ * parse the config file
+ */
 function parseConfig( $cfg_file ) {
 
     global $newcfg;
@@ -195,6 +200,7 @@ function change_to_sm_path($old_path) {
 
 /* ---------------------- main -------------------------- */
 
+/** @ignore */
 define('SM_PATH','../../');
 
 /* SquirrelMail required files. */
@@ -232,10 +238,12 @@ $colapse = array( 'Titles' => 'off',
                   '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' ) );
+                  'Group8' => getPref($data_dir, $username, 'adm_Group8', 'on' ),
+                  'Group9' => getPref($data_dir, $username, 'adm_Group9', 'on' ),
+                  'Group10' => getPref($data_dir, $username, 'adm_Group10', 'on' ) );
 
-if ( isset( $_GET['switch'] ) ) {
-    $switch = $_GET['switch'];
+/* look in $_GET array for 'switch' */
+if ( sqgetGlobalVar('switch', $switch, SQ_GET) ) {
     if ( $colapse[$switch] == 'on' ) {
        $colapse[$switch] = 'off';
     } else {
@@ -247,7 +255,15 @@ if ( isset( $_GET['switch'] ) ) {
 echo "<form action=options.php method=post name=options>" .
     "<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>";
+    "<tr bgcolor=\"$color[5]\"><th colspan=2>" . _("Configuration Administrator") . "</th></tr>",
+    "<tr bgcolor=\"$color[5]\"><td colspan=2 align=\"center\">";
+
+echo "<small>";
+echo _("Note: it is recommended that you configure your system using conf.pl, and not this plugin. conf.pl contains additional information regarding the purpose of variables and appropriate values, as well as additional verification steps.");
+echo "<br />";
+echo _("Run or consult conf.pl should you run into difficulty with your configuration.");
+echo "</small></td></tr>";
+
 
 $act_grp = 'Titles';  /* Active group */
 
@@ -323,8 +339,9 @@ foreach ( $newcfg as $k => $v ) {
             echo "</td></tr>\n";
             break;
         case SMOPT_TYPE_INTEGER:
-            if ( isset( $HTTP_POST_VARS[$e] ) ) {
-                $v = intval( $HTTP_POST_VARS[$e] );
+           /* look for variable $e in POST, fill into $v */
+            if ( sqgetGlobalVar($e, $v, SQ_POST) ) {
+                $v = intval( $v );
                 $newcfg[$k] = $v;
             }
             echo "<tr><td>$name</td><td>".
@@ -335,8 +352,7 @@ foreach ( $newcfg as $k => $v ) {
             echo "</td></tr>\n";
             break;
         case SMOPT_TYPE_NUMLIST:
-            if ( isset( $HTTP_POST_VARS[$e] ) ) {
-                $v = $HTTP_POST_VARS[$e];
+            if (  sqgetGlobalVar($e, $v, SQ_POST) ) {
                 $newcfg[$k] = $v;
             }
             echo "<tr><td>$name</td><td>";
@@ -355,8 +371,8 @@ foreach ( $newcfg as $k => $v ) {
             echo "</td></tr>\n";
             break;
         case SMOPT_TYPE_STRLIST:
-            if ( isset( $HTTP_POST_VARS[$e] ) ) {
-                $v = '"' . $HTTP_POST_VARS[$e] . '"';
+            if (  sqgetGlobalVar($e, $v, SQ_POST) ) {
+                $v = '"' . $v . '"';
                 $newcfg[$k] = $v;
             }
             echo "<tr><td>$name</td><td>".
@@ -376,8 +392,8 @@ foreach ( $newcfg as $k => $v ) {
             break;
 
         case SMOPT_TYPE_TEXTAREA:
-            if ( isset( $HTTP_POST_VARS[$e] ) ) {
-                $v = '"' . $HTTP_POST_VARS[$e] . '"';
+            if (  sqgetGlobalVar($e, $v, SQ_POST) ) {
+                $v = '"' . $v . '"';
                 $newcfg[$k] = str_replace( "\n", '', $v );
             }
             echo "<tr><td valign=top>$name</td><td>".
@@ -388,8 +404,8 @@ foreach ( $newcfg as $k => $v ) {
             echo "</td></tr>\n";
             break;
         case SMOPT_TYPE_STRING:
-            if ( isset( $HTTP_POST_VARS[$e] ) ) {
-                $v = '"' . $HTTP_POST_VARS[$e] . '"';
+            if (  sqgetGlobalVar($e, $v, SQ_POST) ) {
+                $v = '"' . $v . '"';
                 $newcfg[$k] = $v;
             }
             if ( $v == '""' && isset( $defcfg[$k]['default'] ) ) {
@@ -404,8 +420,7 @@ foreach ( $newcfg as $k => $v ) {
             echo "</td></tr>\n";
             break;
         case SMOPT_TYPE_BOOLEAN:
-            if ( isset( $HTTP_POST_VARS[$e] ) ) {
-                $v = $HTTP_POST_VARS[$e];
+            if (  sqgetGlobalVar($e, $v, SQ_POST) ) {
                 $newcfg[$k] = $v;
             } else {
                 $v = strtoupper( $v );
@@ -426,8 +441,8 @@ foreach ( $newcfg as $k => $v ) {
             echo "</td></tr>\n";
             break;
        case SMOPT_TYPE_PATH:
-           if ( isset( $HTTP_POST_VARS[$e] ) ) {
-               $v = change_to_sm_path($HTTP_POST_VARS[$e]);
+            if (  sqgetGlobalVar($e, $v, SQ_POST) ) {
+               $v = change_to_sm_path($v);
                $newcfg[$k] = $v;
             }
             if ( $v == "''" && isset( $defcfg[$k]['default'] ) ) {
@@ -461,8 +476,8 @@ if ( $colapse['Group7'] == 'off' ) {
     while ( isset( $newcfg["\$theme[$i]['NAME']"] ) ) {
         $k1 = "\$theme[$i]['NAME']";
         $e1 = "theme_name_$i";
-        if ( isset( $HTTP_POST_VARS[$e1] ) ) {
-            $v1 = '"' . str_replace( '\"', '"', $HTTP_POST_VARS[$e1] ) . '"';
+        if (  sqgetGlobalVar($e, $v1, SQ_POST) ) {
+            $v1 = '"' . str_replace( '\"', '"', $v1 ) . '"';
             $v1 = '"' . str_replace( '"', '\"', $v1 ) . '"';
             $newcfg[$k1] = $v1;
         } else {
@@ -470,8 +485,8 @@ if ( $colapse['Group7'] == 'off' ) {
         }
         $k2 = "\$theme[$i]['PATH']";
         $e2 = "theme_path_$i";
-        if ( isset( $HTTP_POST_VARS[$e2] ) ) {
-            $v2 = change_to_sm_path($HTTP_POST_VARS[$e2]);
+        if (  sqgetGlobalVar($e, $v2, SQ_POST) ) {
+            $v2 = change_to_sm_path($v2);
            $newcfg[$k2] = $v2;
         } else {
             $v2 = $newcfg[$k2];
@@ -499,26 +514,25 @@ echo "<tr bgcolor=\"$color[0]\"><th colspan=2>" .
 
 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++;
-            }
+  $plugpath = SM_PATH . 'plugins/';
+  if ( file_exists($plugpath) ) {
+      $fd = opendir( $plugpath );
+      $op_plugin = array();
+      $p_count = 0;
+      while (false !== ($file = readdir($fd))) {
+        if ($file != '.' && $file != '..' && $file != 'CVS' && is_dir($plugpath . $file) ) {
+            $op_plugin[] = $file;
+            $p_count++;
         }
-    }
-    closedir($fd);
-    asort( $op_plugin );
+      }
+      closedir($fd);
+      asort( $op_plugin );
 
-    /* Lets get the plugins that are active */
-    $plugins = array();
-    if ( isset( $HTTP_POST_VARS['plg'] ) ) {
+      /* Lets get the plugins that are active */
+      $plugins = array();
+      if (  sqgetGlobalVar('plg', $v, SQ_POST) ) {
         foreach ( $op_plugin as $plg ) {
-            if ( isset( $HTTP_POST_VARS["plgs_$plg"] ) &&
-                 $HTTP_POST_VARS["plgs_$plg"] == 'on' ) {
+            if (  sqgetGlobalVar("plgs_$plg", $v, SQ_POST) && $v == 'on' ) {
                 $plugins[] = $plg;
             }
         }
@@ -533,7 +547,7 @@ if( $colapse['Group8'] == 'off' ) {
             $newcfg[$k] = '';
             $i++;
         }
-    } else {
+      } else {
         $i = 0;
         while ( isset( $newcfg["\$plugins[$i]"] ) ) {
             $k = "\$plugins[$i]";
@@ -541,9 +555,9 @@ if( $colapse['Group8'] == 'off' ) {
             $plugins[] = substr( $v, 1, strlen( $v ) - 2 );
             $i++;
         }
-    }
-    echo "<tr><td colspan=2><input type=hidden name=plg value=on><center><table><tr><td>";
-    foreach ( $op_plugin as $plg ) {
+      }
+      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 {
@@ -552,9 +566,11 @@ if( $colapse['Group8'] == 'off' ) {
         echo '<tr>' .
              "<td>$plg</td><td><input$sw type=checkbox name=plgs_$plg></td>".
              "</tr>\n";
-    }
-    echo '</td></tr></table>';
-
+      }
+      echo '</td></tr></table></td></tr>';
+  } else {
+      echo '<tr><td colspan=2 align="center">Plugin directory could not be found: ' . $plugpath . "</td></tr>\n";
+  }
 }
 echo "<tr bgcolor=\"$color[5]\"><th colspan=2><input value=\"" .
      _("Change Settings") . "\" type=submit></th></tr>" ,
@@ -569,7 +585,9 @@ if( $fp = @fopen( $cfgfile, 'w' ) ) {
     "/**\n".
     " * SquirrelMail Configuration File\n".
     " * Created using the Administrator Plugin\n".
-    " */\n" );
+    " */\n".
+    "\n".
+    "global \$version;\n" );
 
     foreach ( $newcfg as $k => $v ) {
         if ( $k{0} == '$' && $v <> '' ) {
@@ -588,5 +606,4 @@ if( $fp = @fopen( $cfgfile, 'w' ) ) {
          _("Config file can't be opened. Please check config.php.").
          '</font>';
 }
-
 ?>