Added Default Javascript Adrressbook
[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
37d90494 14function parseConfig( $cfg_file ) {
15
16 global $newcfg;
17
18 $cfg = file( $cfg_file );
71e5c245 19 $mode = '';
20 $l = count( $cfg );
21 $modifier = FALSE;
37d90494 22
71e5c245 23 for ($i=0;$i<$l;$i++) {
24 $line = trim( $cfg[$i] );
25 $s = strlen( $line );
26 for ($j=0;$j<$s;$j++) {
27 switch ( $mode ) {
28 case '=':
29 if ( $line{$j} == '=' ) {
30 // Ok, we've got a right value, lets detect what type
31 $mode = 'D';
32 } else if ( $line{$j} == ';' ) {
33 // hu! end of command
34 $key = $mode = '';
35 }
36 break;
37 case 'K':
38 // Key detect
39 if( $line{$j} == ' ' ) {
40 $mode = '=';
37d90494 41 } else {
71e5c245 42 $key .= $line{$j};
37d90494 43 }
71e5c245 44 break;
45 case ';':
46 // Skip until next ;
47 if ( $line{$j} == ';' ) {
48 $mode = '';
49 }
50 break;
51 case 'S':
52 if ( $line{$j} == '\\' ) {
53 $value .= $line{$j};
54 $modifier = TRUE;
55 } else if ( $line{$j} == $delimiter && $modifier === FALSE ) {
56 // End of string;
57 $newcfg[$key] = $value . $delimiter;
58 $key = $value = '';
59 $mode = ';';
60 } else {
61 $value .= $line{$j};
62 $modifier = FALSE;
63 }
64 break;
65 case 'N':
66 if ( $line{$j} == ';' ) {
67 $newcfg{$key} = $value;
68 $key = $mode = '';
69 } else {
70 $value .= $line{$j};
71 }
72 break;
73 case 'C':
74 // Comments
75 if ( $line{$j}.$line{$j+1} == '*/' ) {
76 $mode = '';
77 $j++;
78 }
79 break;
80 case 'D':
81 // Delimiter detect
82 switch ( $line{$j} ) {
83 case '"':
84 case "'":
85 // Double quote string
86 $delimiter = $value = $line{$j};
87 $mode = 'S';
88 break;
89 case ' ':
90 // Nothing yet
91 break;
92 default:
93 if ( strtoupper( substr( $line, $j, 4 ) ) == 'TRUE' ) {
94 // Boolean TRUE
95 $newcfg{$key} = 'TRUE';
96 $key = '';
97 $mode = ';';
98 } else if ( strtoupper( substr( $line, $j, 5 ) ) == 'FALSE' ) {
99 $newcfg{$key} = 'FALSE';
100 $key = '';
101 $mode = ';';
102 } else {
103 // Number or function call
104 $mode = 'N';
105 $value = $line{$j};
106 }
107 }
108 break;
109 default:
110 if ( strtoupper( substr( $line, $j, 7 ) ) == 'GLOBAL ' ) {
111 // Skip untill next ;
112 $mode = ';';
113 $j += 6;
114 } else if ( $line{$j}.$line{$j+1} == '/*' ) {
115 $mode = 'C';
116 $j++;
117 } else if ( $line{$j} == '#' || $line{$j}.$line{$j+1} == '//' ) {
118 // Delete till the end of the line
119 $j = $s;
120 } else if ( $line{$j} == '$' ) {
121 // We must detect $key name
122 $mode = 'K';
123 $key = '$';
37d90494 124 }
37d90494 125 }
126 }
37d90494 127 }
128
129}
71e5c245 130
37d90494 131/* ---------------------- main -------------------------- */
71e5c245 132
abd7a3f8 133chdir('..');
134require_once('../src/validate.php');
135require_once('../functions/page_header.php');
136require_once('../functions/imap.php');
137require_once('../src/load_prefs.php');
138require_once('../plugins/administrator/defines.php');
139
dcd6f144 140$auth = FALSE;
141if ( $adm_id = fileowner('../config/config.php') ) {
142 $adm = posix_getpwuid( $adm_id );
143 if ( $username == $adm['name'] ) {
144 $auth = TRUE;
145 }
146}
147
148if ( !auth ) {
149 header("Location: ../../src/options.php") ;
150 exit;
151}
152
abd7a3f8 153displayPageHeader($color, 'None');
154
37d90494 155$newcfg = array( );
0e66bc84 156
157foreach ( $defcfg as $key => $def ) {
158 $newcfg[$key] = '';
159}
160
37d90494 161$cfgfile = '../config/config.php';
162parseConfig( '../config/config_default.php' );
163parseConfig( $cfgfile );
abd7a3f8 164
165echo "<form action=$PHP_SELF method=post>" .
0e66bc84 166 "<br><center><table width=95% bgcolor=\"$color[5]\"><tr><td>".
167 "<table width=100% cellspacing=0 bgcolor=\"$color[4]\">" ,
abd7a3f8 168 "<tr bgcolor=\"$color[5]\"><th colspan=2>" . _("Configuration Administrator") . "</th></tr>";
169foreach ( $newcfg as $k => $v ) {
170 $l = strtolower( $v );
171 $type = SMOPT_TYPE_UNDEFINED;
172 $n = substr( $k, 1 );
173 $n = str_replace( '[', '_', $n );
174 $n = str_replace( ']', '_', $n );
175 $e = 'adm_' . $n;
176 $name = $k;
177 $size = 50;
0e66bc84 178 if ( isset( $defcfg[$k] ) ) {
179 $name = $defcfg[$k]['name'];
180 $type = $defcfg[$k]['type'];
181 $size = $defcfg[$k]['size'];
abd7a3f8 182 } else if ( $l == 'true' ) {
183 $v = 'TRUE';
184 $type = SMOPT_TYPE_BOOLEAN;
185 } else if ( $l == 'false' ) {
186 $v = 'FALSE';
187 $type = SMOPT_TYPE_BOOLEAN;
188 } else if ( $v{0} == "'" ) {
189 $type = SMOPT_TYPE_STRING;
190 } else if ( $v{0} == '"' ) {
191 $type = SMOPT_TYPE_STRING;
192 }
193
abd7a3f8 194 switch ( $type ) {
0e66bc84 195 case SMOPT_TYPE_TITLE:
dcd6f144 196 echo "<tr bgcolor=\"$color[0]\"><th colspan=2>$name</th></tr>";
0e66bc84 197 break;
198 case SMOPT_TYPE_COMMENT:
199 $v = substr( $v, 1, strlen( $v ) - 2 );
a55bb207 200 echo "<tr><td>$name</td><td>".
201 "<b>$v</b>";
0e66bc84 202 $newcfg[$k] = "'$v'";
203 break;
abd7a3f8 204 case SMOPT_TYPE_INTEGER:
205 if ( isset( $HTTP_POST_VARS[$e] ) ) {
206 $v = intval( $HTTP_POST_VARS[$e] );
207 $newcfg[$k] = $v;
208 }
a55bb207 209 echo "<tr><td>$name</td><td>".
210 "<input size=10 name=\"adm_$n\" value=\"$v\">";
abd7a3f8 211 break;
dcd6f144 212 case SMOPT_TYPE_NUMLIST:
213 if ( isset( $HTTP_POST_VARS[$e] ) ) {
214 $v = $HTTP_POST_VARS[$e];
215 $newcfg[$k] = $v;
216 }
217 echo "<tr><td>$name</td><td>";
218 echo "<select name=\"adm_$n\">";
219 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
220 echo "<option value=\"$kp\"";
221 if ( $kp == $v ) {
222 echo ' selected';
223 }
224 echo ">$vp</option>";
225 }
226 echo '</select>';
227 break;
abd7a3f8 228 case SMOPT_TYPE_STRLIST:
229 if ( isset( $HTTP_POST_VARS[$e] ) ) {
230 $v = '"' . $HTTP_POST_VARS[$e] . '"';
231 $newcfg[$k] = $v;
232 }
a55bb207 233 echo "<tr><td>$name</td><td>".
234 "<select name=\"adm_$n\">";
0e66bc84 235 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
abd7a3f8 236 echo "<option value=\"$kp\"";
237 if ( $kp == substr( $v, 1, strlen( $v ) - 2 ) ) {
238 echo ' selected';
239 }
240 echo ">$vp</option>";
241 }
242 echo '</select>';
243 break;
244
245 case SMOPT_TYPE_STRING:
246 if ( isset( $HTTP_POST_VARS[$e] ) ) {
247 $v = '"' . $HTTP_POST_VARS[$e] . '"';
248 $newcfg[$k] = $v;
249 }
a55bb207 250 echo "<tr><td>$name</td><td>".
251 "<input size=\"$size\" name=\"adm_$n\" value=\"" . substr( $v, 1, strlen( $v ) - 2 ) . "\">";
abd7a3f8 252 break;
253 case SMOPT_TYPE_BOOLEAN:
254 if ( isset( $HTTP_POST_VARS[$e] ) ) {
255 $v = $HTTP_POST_VARS[$e];
256 $newcfg[$k] = $v;
a55bb207 257 } else {
258 $v = strtoupper( $v );
abd7a3f8 259 }
260 if ( $v == 'TRUE' ) {
261 $ct = ' checked';
262 $cf = '';
263 } else {
264 $ct = '';
265 $cf = ' checked';
266 }
a55bb207 267 echo "<tr><td>$name</td><td>" .
268 "<INPUT$ct type=radio NAME=\"adm_$n\" value=\"TRUE\">" . _("Yes") .
269 "<INPUT$cf type=radio NAME=\"adm_$n\" value=\"FALSE\">" . _("No");
abd7a3f8 270 break;
271 default:
a55bb207 272 echo "<tr><td>$name</td><td>" .
273 "<b><i>$v</i></b>";
abd7a3f8 274 }
275 echo "</td></tr>\n";
276}
277echo "<tr bgcolor=\"$color[5]\"><th colspan=2><input value=\"" .
278 _("Change Settings") . "\" type=submit></th></tr>" ,
0e66bc84 279 '</table></td></tr></table></form>';
abd7a3f8 280
281/*
282 Write the options to the file.
283*/
71e5c245 284
abd7a3f8 285$fp = fopen( $cfgfile, 'w' );
286fwrite( $fp, "<?PHP\n".
287 "/**\n".
288 " * SquirrelMail Configuration File\n".
289 " * Created using the Administrator Plugin\n".
290 " */\n\n" );
291
292fwrite( $fp, 'GLOBAL ' );
293$not_first = FALSE;
294foreach ( $newcfg as $k => $v ) {
0e66bc84 295 if ( $k{0} == '$' ) {
296 if( $i = strpos( $k, '[' ) ) {
297 if( strpos( $k, '[0]' ) ) {
298 if( $not_first ) {
299 fwrite( $fp, ', ' );
300 }
301 fwrite( $fp, substr( $k, 0, $i) );
0e66bc84 302 }
303 } else {
abd7a3f8 304 if( $not_first ) {
305 fwrite( $fp, ', ' );
7c8d1194 306 }
0e66bc84 307 fwrite( $fp, $k );
abd7a3f8 308 }
7c8d1194 309 $not_first = TRUE;
abd7a3f8 310 }
311}
312fwrite( $fp, ";\n" );
313foreach ( $newcfg as $k => $v ) {
0e66bc84 314 if ( $k{0} == '$' ) {
7c8d1194 315 if ( substr( $k, 1, 11 ) == 'ldap_server' ) {
316 $v = substr( $v, 0, strlen( $v ) - 1 ) . "\n)";
317 $v = str_replace( 'array(', "array(\n\t", $v );
318 $v = str_replace( "',", "',\n\t", $v );
319 }
0e66bc84 320 fwrite( $fp, "$k = $v;\n" );
321 }
abd7a3f8 322}
323fwrite( $fp, '?>' );
324fclose( $fp );
37d90494 325?>