Typo
[squirrelmail.git] / plugins / administrator / options.php
CommitLineData
abd7a3f8 1<?php
2
3/**
4 * Administrator Plugin
5 *
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Philippe Mingo
10 *
11 * $Id$
12 */
13
14chdir('..');
15require_once('../src/validate.php');
16require_once('../functions/page_header.php');
17require_once('../functions/imap.php');
18require_once('../src/load_prefs.php');
19require_once('../plugins/administrator/defines.php');
20
21displayPageHeader($color, 'None');
22
23$cfgfile = '../config/config.php';
24$cfg_defaultfile = '../config/config_default.php';
25$cfg = file( $cfg_defaultfile );
0e66bc84 26$newcfg = $dfncfg = array( );
abd7a3f8 27$cm = FALSE;
0e66bc84 28
29foreach ( $defcfg as $key => $def ) {
30 $newcfg[$key] = '';
31}
32
abd7a3f8 33foreach ( $cfg as $l ) {
0e66bc84 34 // Remove inline /* */ Blocks
abd7a3f8 35 $l = preg_replace( '/\/\*.*\*\//', '', $l );
36 $l = preg_replace( '/#.*$/', '', $l );
37 $l = preg_replace( '/\/\/.*$/', '', $l );
38 $v = $s = trim( $l );
39 if ( $cm ) {
40 if( substr( $v, -2 ) == '*/' ) {
41 $v = '';
42 $cm = FALSE;
43 } else if( $i = strpos( $v, '*/' ) ) {
44 $v = substr( $v, $i );
45 $cm = FALSE;
46 } else {
47 $v = '';
48 }
49 } else {
50 if( $v{0}.$v{1} == '/*' ) {
51 $v = '';
52 $cm = TRUE;
53 } else if ( $i = strpos( $v, '/*' ) ) {
54 $v = substr( $v, 0, $i );
55 $cm = TRUE;
56 }
57 }
58
59 if ( $i = strpos( $v, '=' ) ) {
60 $key = trim( substr( $v, 0, $i - 1 ) );
61 $val = str_replace( ';', '', trim( substr( $v, $i + 1 ) ) );
62 $newcfg[$key] = $val;
0e66bc84 63 $dfncfg[$key] = $val;
abd7a3f8 64 }
65
66}
67
68$cfg = file( $cfgfile );
abd7a3f8 69
70$cm = FALSE;
71foreach ( $cfg as $l ) {
72 $l = preg_replace( '/\/\*.*\*\//', '', $l );
73 $l = preg_replace( '/#.*$/', '', $l );
74 $l = preg_replace( '/\/\/.*$/', '', $l );
75 $v = $s = trim( $l );
76 if ( $cm ) {
77 if( substr( $v, -2 ) == '*/' ) {
78 $v = '';
79 $cm = FALSE;
80 } else if( $i = strpos( $v, '*/' ) ) {
81 $v = substr( $v, $i );
82 $cm = FALSE;
83 } else {
84 $v = '';
85 }
86 } else {
87 if( $v{0}.$v{1} == '/*' ) {
88 $v = '';
89 $cm = TRUE;
90 } else if ( $i = strpos( $v, '/*' ) ) {
91 $v = substr( $v, 0, $i );
92 $cm = TRUE;
93 }
94 }
95
96 if ( $i = strpos( $v, '=' ) ) {
97 $key = trim( substr( $v, 0, $i - 1 ) );
98 $val = str_replace( ';', '', trim( substr( $v, $i + 1 ) ) );
99 $newcfg[$key] = $val;
100 }
101
102}
103
104echo "<form action=$PHP_SELF method=post>" .
0e66bc84 105 "<br><center><table width=95% bgcolor=\"$color[5]\"><tr><td>".
106 "<table width=100% cellspacing=0 bgcolor=\"$color[4]\">" ,
abd7a3f8 107 "<tr bgcolor=\"$color[5]\"><th colspan=2>" . _("Configuration Administrator") . "</th></tr>";
108foreach ( $newcfg as $k => $v ) {
109 $l = strtolower( $v );
110 $type = SMOPT_TYPE_UNDEFINED;
111 $n = substr( $k, 1 );
112 $n = str_replace( '[', '_', $n );
113 $n = str_replace( ']', '_', $n );
114 $e = 'adm_' . $n;
115 $name = $k;
116 $size = 50;
0e66bc84 117 if ( isset( $defcfg[$k] ) ) {
118 $name = $defcfg[$k]['name'];
119 $type = $defcfg[$k]['type'];
120 $size = $defcfg[$k]['size'];
abd7a3f8 121 } else if ( $l == 'true' ) {
122 $v = 'TRUE';
123 $type = SMOPT_TYPE_BOOLEAN;
124 } else if ( $l == 'false' ) {
125 $v = 'FALSE';
126 $type = SMOPT_TYPE_BOOLEAN;
127 } else if ( $v{0} == "'" ) {
128 $type = SMOPT_TYPE_STRING;
129 } else if ( $v{0} == '"' ) {
130 $type = SMOPT_TYPE_STRING;
131 }
132
abd7a3f8 133 switch ( $type ) {
0e66bc84 134 case SMOPT_TYPE_TITLE:
135 echo "<tr bgcolor=\"$color[5]\"><th colspan=2>$name</th></tr>";
136 break;
137 case SMOPT_TYPE_COMMENT:
138 $v = substr( $v, 1, strlen( $v ) - 2 );
139 echo "<tr><td>$name</td><td>";
140 echo "<b>$v</b>";
141 $newcfg[$k] = "'$v'";
142 break;
abd7a3f8 143 case SMOPT_TYPE_INTEGER:
144 if ( isset( $HTTP_POST_VARS[$e] ) ) {
145 $v = intval( $HTTP_POST_VARS[$e] );
146 $newcfg[$k] = $v;
147 }
0e66bc84 148 echo "<tr><td>$name</td><td>";
abd7a3f8 149 echo "<input size=10 name=\"adm_$n\" value=\"$v\">";
150 break;
151 case SMOPT_TYPE_STRLIST:
152 if ( isset( $HTTP_POST_VARS[$e] ) ) {
153 $v = '"' . $HTTP_POST_VARS[$e] . '"';
154 $newcfg[$k] = $v;
155 }
0e66bc84 156 echo "<tr><td>$name</td><td>";
abd7a3f8 157 echo "<select name=\"adm_$n\">";
0e66bc84 158 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
abd7a3f8 159 echo "<option value=\"$kp\"";
160 if ( $kp == substr( $v, 1, strlen( $v ) - 2 ) ) {
161 echo ' selected';
162 }
163 echo ">$vp</option>";
164 }
165 echo '</select>';
166 break;
167
168 case SMOPT_TYPE_STRING:
169 if ( isset( $HTTP_POST_VARS[$e] ) ) {
170 $v = '"' . $HTTP_POST_VARS[$e] . '"';
171 $newcfg[$k] = $v;
172 }
0e66bc84 173 echo "<tr><td>$name</td><td>";
abd7a3f8 174 echo "<input size=\"$size\" name=\"adm_$n\" value=\"" . substr( $v, 1, strlen( $v ) - 2 ) . "\">";
175 break;
176 case SMOPT_TYPE_BOOLEAN:
177 if ( isset( $HTTP_POST_VARS[$e] ) ) {
178 $v = $HTTP_POST_VARS[$e];
179 $newcfg[$k] = $v;
180 }
181 if ( $v == 'TRUE' ) {
182 $ct = ' checked';
183 $cf = '';
184 } else {
185 $ct = '';
186 $cf = ' checked';
187 }
0e66bc84 188 echo "<tr><td>$name</td><td>";
abd7a3f8 189 echo "<INPUT$ct type=radio NAME=\"adm_$n\" value=\"TRUE\">" . _("Yes") .
190 "<INPUT$cf type=radio NAME=\"adm_$n\" value=\"FALSE\">" . _("No");
191 break;
192 default:
0e66bc84 193 echo "<tr><td>$name</td><td>";
abd7a3f8 194 echo "<b><i>$v</i></b>";
195 }
196 echo "</td></tr>\n";
197}
198echo "<tr bgcolor=\"$color[5]\"><th colspan=2><input value=\"" .
199 _("Change Settings") . "\" type=submit></th></tr>" ,
0e66bc84 200 '</table></td></tr></table></form>';
abd7a3f8 201
202/*
203 Write the options to the file.
204*/
205$fp = fopen( $cfgfile, 'w' );
206fwrite( $fp, "<?PHP\n".
207 "/**\n".
208 " * SquirrelMail Configuration File\n".
209 " * Created using the Administrator Plugin\n".
210 " */\n\n" );
211
212fwrite( $fp, 'GLOBAL ' );
213$not_first = FALSE;
214foreach ( $newcfg as $k => $v ) {
0e66bc84 215 if ( $k{0} == '$' ) {
216 if( $i = strpos( $k, '[' ) ) {
217 if( strpos( $k, '[0]' ) ) {
218 if( $not_first ) {
219 fwrite( $fp, ', ' );
220 }
221 fwrite( $fp, substr( $k, 0, $i) );
222 $not_first = TRUE;
223 }
224 } else {
abd7a3f8 225 if( $not_first ) {
226 fwrite( $fp, ', ' );
227 }
0e66bc84 228 fwrite( $fp, $k );
abd7a3f8 229 $not_first = TRUE;
230 }
abd7a3f8 231 }
232}
233fwrite( $fp, ";\n" );
234foreach ( $newcfg as $k => $v ) {
0e66bc84 235 if ( $k{0} == '$' ) {
236 fwrite( $fp, "$k = $v;\n" );
237 }
abd7a3f8 238}
239fwrite( $fp, '?>' );
240fclose( $fp );
241?>