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