a5500f7b899049f615ce0a60bd0e1c81deccd4e2
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
15 require_once('../src/validate.php');
16 require_once('../functions/page_header.php');
17 require_once('../functions/imap.php');
18 require_once('../src/load_prefs.php');
19 require_once('../plugins/administrator/defines.php');
22 if ( $adm_id = fileowner('../config/config.php') ) {
23 $adm = posix_getpwuid( $adm_id );
24 if ( $username == $adm['name'] ) {
30 header("Location: ../../src/options.php") ;
34 displayPageHeader($color, 'None');
36 $cfgfile = '../config/config.php';
37 $cfg_defaultfile = '../config/config_default.php';
38 $cfg = file( $cfg_defaultfile );
39 $newcfg = $dfncfg = array( );
42 foreach ( $defcfg as $key => $def ) {
46 foreach ( $cfg as $l ) {
47 // Remove inline /* */ Blocks
48 $l = preg_replace( '/\/\*.*\*\//', '', $l );
49 $l = preg_replace( '/#.*$/', '', $l );
50 $l = preg_replace( '/\/\/.*$/', '', $l );
53 if( substr( $v, -2 ) == '*/' ) {
56 } else if( $i = strpos( $v, '*/' ) ) {
57 $v = substr( $v, $i );
63 if( $v{0}.$v{1} == '/*' ) {
66 } else if ( $i = strpos( $v, '/*' ) ) {
67 $v = substr( $v, 0, $i );
72 if ( $i = strpos( $v, '=' ) ) {
73 $key = trim( substr( $v, 0, $i - 1 ) );
74 $val = str_replace( ';', '', trim( substr( $v, $i +
1 ) ) );
81 $cfg = file( $cfgfile );
84 foreach ( $cfg as $l ) {
85 $l = preg_replace( '/\/\*.*\*\//', '', $l );
86 $l = preg_replace( '/#.*$/', '', $l );
87 $l = preg_replace( '/\/\/.*$/', '', $l );
90 if( substr( $v, -2 ) == '*/' ) {
93 } else if( $i = strpos( $v, '*/' ) ) {
94 $v = substr( $v, $i );
100 if( $v{0}.$v{1} == '/*' ) {
103 } else if ( $i = strpos( $v, '/*' ) ) {
104 $v = substr( $v, 0, $i );
109 if ( $i = strpos( $v, '=' ) ) {
110 $key = trim( substr( $v, 0, $i - 1 ) );
111 $val = str_replace( ';', '', trim( substr( $v, $i +
1 ) ) );
112 $newcfg[$key] = $val;
117 echo "<form action=$PHP_SELF method=post>" .
118 "<br><center><table width=95% bgcolor=\"$color[5]\"><tr><td>".
119 "<table width=100% cellspacing=0 bgcolor=\"$color[4]\">" ,
120 "<tr bgcolor=\"$color[5]\"><th colspan=2>" . _("Configuration Administrator") . "</th></tr>";
121 foreach ( $newcfg as $k => $v ) {
122 $l = strtolower( $v );
123 $type = SMOPT_TYPE_UNDEFINED
;
124 $n = substr( $k, 1 );
125 $n = str_replace( '[', '_', $n );
126 $n = str_replace( ']', '_', $n );
130 if ( isset( $defcfg[$k] ) ) {
131 $name = $defcfg[$k]['name'];
132 $type = $defcfg[$k]['type'];
133 $size = $defcfg[$k]['size'];
134 } else if ( $l == 'true' ) {
136 $type = SMOPT_TYPE_BOOLEAN
;
137 } else if ( $l == 'false' ) {
139 $type = SMOPT_TYPE_BOOLEAN
;
140 } else if ( $v{0} == "'" ) {
141 $type = SMOPT_TYPE_STRING
;
142 } else if ( $v{0} == '"' ) {
143 $type = SMOPT_TYPE_STRING
;
147 case SMOPT_TYPE_TITLE
:
148 echo "<tr bgcolor=\"$color[0]\"><th colspan=2>$name</th></tr>";
150 case SMOPT_TYPE_COMMENT
:
151 $v = substr( $v, 1, strlen( $v ) - 2 );
152 echo "<tr><td>$name</td><td>";
154 $newcfg[$k] = "'$v'";
156 case SMOPT_TYPE_INTEGER
:
157 if ( isset( $HTTP_POST_VARS[$e] ) ) {
158 $v = intval( $HTTP_POST_VARS[$e] );
161 echo "<tr><td>$name</td><td>";
162 echo "<input size=10 name=\"adm_$n\" value=\"$v\">";
164 case SMOPT_TYPE_NUMLIST
:
165 if ( isset( $HTTP_POST_VARS[$e] ) ) {
166 $v = $HTTP_POST_VARS[$e];
169 echo "<tr><td>$name</td><td>";
170 echo "<select name=\"adm_$n\">";
171 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
172 echo "<option value=\"$kp\"";
176 echo ">$vp</option>";
180 case SMOPT_TYPE_STRLIST
:
181 if ( isset( $HTTP_POST_VARS[$e] ) ) {
182 $v = '"' . $HTTP_POST_VARS[$e] . '"';
185 echo "<tr><td>$name</td><td>";
186 echo "<select name=\"adm_$n\">";
187 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
188 echo "<option value=\"$kp\"";
189 if ( $kp == substr( $v, 1, strlen( $v ) - 2 ) ) {
192 echo ">$vp</option>";
197 case SMOPT_TYPE_STRING
:
198 if ( isset( $HTTP_POST_VARS[$e] ) ) {
199 $v = '"' . $HTTP_POST_VARS[$e] . '"';
202 echo "<tr><td>$name</td><td>";
203 echo "<input size=\"$size\" name=\"adm_$n\" value=\"" . substr( $v, 1, strlen( $v ) - 2 ) . "\">";
205 case SMOPT_TYPE_BOOLEAN
:
206 if ( isset( $HTTP_POST_VARS[$e] ) ) {
207 $v = $HTTP_POST_VARS[$e];
210 if ( $v == 'TRUE' ) {
217 echo "<tr><td>$name</td><td>";
218 echo "<INPUT$ct type=radio NAME=\"adm_$n\" value=\"TRUE\">" . _("Yes") .
219 "<INPUT$cf type=radio NAME=\"adm_$n\" value=\"FALSE\">" . _("No");
222 echo "<tr><td>$name</td><td>";
223 echo "<b><i>$v</i></b>";
227 echo "<tr bgcolor=\"$color[5]\"><th colspan=2><input value=\"" .
228 _("Change Settings") . "\" type=submit></th></tr>" ,
229 '</table></td></tr></table></form>';
232 Write the options to the file.
234 $fp = fopen( $cfgfile, 'w' );
235 fwrite( $fp, "<?PHP\n".
237 " * SquirrelMail Configuration File\n".
238 " * Created using the Administrator Plugin\n".
241 fwrite( $fp, 'GLOBAL ' );
243 foreach ( $newcfg as $k => $v ) {
244 if ( $k{0} == '$' ) {
245 if( $i = strpos( $k, '[' ) ) {
246 if( strpos( $k, '[0]' ) ) {
250 fwrite( $fp, substr( $k, 0, $i) );
262 fwrite( $fp, ";\n" );
263 foreach ( $newcfg as $k => $v ) {
264 if ( $k{0} == '$' ) {
265 fwrite( $fp, "$k = $v;\n" );