Administrator Plugin
[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 );
26$newcfg = $defcfg = array( );
27$cm = FALSE;
28foreach ( $cfg as $l ) {
29 $l = preg_replace( '/\/\*.*\*\//', '', $l );
30 $l = preg_replace( '/#.*$/', '', $l );
31 $l = preg_replace( '/\/\/.*$/', '', $l );
32 $v = $s = trim( $l );
33 if ( $cm ) {
34 if( substr( $v, -2 ) == '*/' ) {
35 $v = '';
36 $cm = FALSE;
37 } else if( $i = strpos( $v, '*/' ) ) {
38 $v = substr( $v, $i );
39 $cm = FALSE;
40 } else {
41 $v = '';
42 }
43 } else {
44 if( $v{0}.$v{1} == '/*' ) {
45 $v = '';
46 $cm = TRUE;
47 } else if ( $i = strpos( $v, '/*' ) ) {
48 $v = substr( $v, 0, $i );
49 $cm = TRUE;
50 }
51 }
52
53 if ( $i = strpos( $v, '=' ) ) {
54 $key = trim( substr( $v, 0, $i - 1 ) );
55 $val = str_replace( ';', '', trim( substr( $v, $i + 1 ) ) );
56 $newcfg[$key] = $val;
57 $defcfg[$key] = $val;
58 }
59
60}
61
62$cfg = file( $cfgfile );
63asort( $cfg );
64
65$cm = FALSE;
66foreach ( $cfg as $l ) {
67 $l = preg_replace( '/\/\*.*\*\//', '', $l );
68 $l = preg_replace( '/#.*$/', '', $l );
69 $l = preg_replace( '/\/\/.*$/', '', $l );
70 $v = $s = trim( $l );
71 if ( $cm ) {
72 if( substr( $v, -2 ) == '*/' ) {
73 $v = '';
74 $cm = FALSE;
75 } else if( $i = strpos( $v, '*/' ) ) {
76 $v = substr( $v, $i );
77 $cm = FALSE;
78 } else {
79 $v = '';
80 }
81 } else {
82 if( $v{0}.$v{1} == '/*' ) {
83 $v = '';
84 $cm = TRUE;
85 } else if ( $i = strpos( $v, '/*' ) ) {
86 $v = substr( $v, 0, $i );
87 $cm = TRUE;
88 }
89 }
90
91 if ( $i = strpos( $v, '=' ) ) {
92 $key = trim( substr( $v, 0, $i - 1 ) );
93 $val = str_replace( ';', '', trim( substr( $v, $i + 1 ) ) );
94 $newcfg[$key] = $val;
95 }
96
97}
98
99echo "<form action=$PHP_SELF method=post>" .
100 '<table width=100%>' ,
101 "<tr bgcolor=\"$color[5]\"><th colspan=2>" . _("Configuration Administrator") . "</th></tr>";
102foreach ( $newcfg as $k => $v ) {
103 $l = strtolower( $v );
104 $type = SMOPT_TYPE_UNDEFINED;
105 $n = substr( $k, 1 );
106 $n = str_replace( '[', '_', $n );
107 $n = str_replace( ']', '_', $n );
108 $e = 'adm_' . $n;
109 $name = $k;
110 $size = 50;
111 if ( isset( $namcfg[$k] ) ) {
112 $name = $namcfg[$k]['name'];
113 $type = $namcfg[$k]['type'];
114 $size = $namcfg[$k]['size'];
115 } else if ( $l == 'true' ) {
116 $v = 'TRUE';
117 $type = SMOPT_TYPE_BOOLEAN;
118 } else if ( $l == 'false' ) {
119 $v = 'FALSE';
120 $type = SMOPT_TYPE_BOOLEAN;
121 } else if ( $v{0} == "'" ) {
122 $type = SMOPT_TYPE_STRING;
123 } else if ( $v{0} == '"' ) {
124 $type = SMOPT_TYPE_STRING;
125 }
126
127 echo "<tr><td>$name</td><td>";
128
129 switch ( $type ) {
130 case SMOPT_TYPE_INTEGER:
131 if ( isset( $HTTP_POST_VARS[$e] ) ) {
132 $v = intval( $HTTP_POST_VARS[$e] );
133 $newcfg[$k] = $v;
134 }
135 echo "<input size=10 name=\"adm_$n\" value=\"$v\">";
136 break;
137 case SMOPT_TYPE_STRLIST:
138 if ( isset( $HTTP_POST_VARS[$e] ) ) {
139 $v = '"' . $HTTP_POST_VARS[$e] . '"';
140 $newcfg[$k] = $v;
141 }
142 echo "<select name=\"adm_$n\">";
143 foreach ( $namcfg[$k]['posvals'] as $kp => $vp ) {
144 echo "<option value=\"$kp\"";
145 if ( $kp == substr( $v, 1, strlen( $v ) - 2 ) ) {
146 echo ' selected';
147 }
148 echo ">$vp</option>";
149 }
150 echo '</select>';
151 break;
152
153 case SMOPT_TYPE_STRING:
154 if ( isset( $HTTP_POST_VARS[$e] ) ) {
155 $v = '"' . $HTTP_POST_VARS[$e] . '"';
156 $newcfg[$k] = $v;
157 }
158 echo "<input size=\"$size\" name=\"adm_$n\" value=\"" . substr( $v, 1, strlen( $v ) - 2 ) . "\">";
159 break;
160 case SMOPT_TYPE_BOOLEAN:
161 if ( isset( $HTTP_POST_VARS[$e] ) ) {
162 $v = $HTTP_POST_VARS[$e];
163 $newcfg[$k] = $v;
164 }
165 if ( $v == 'TRUE' ) {
166 $ct = ' checked';
167 $cf = '';
168 } else {
169 $ct = '';
170 $cf = ' checked';
171 }
172 echo "<INPUT$ct type=radio NAME=\"adm_$n\" value=\"TRUE\">" . _("Yes") .
173 "<INPUT$cf type=radio NAME=\"adm_$n\" value=\"FALSE\">" . _("No");
174 break;
175 default:
176 echo "<b><i>$v</i></b>";
177 }
178 echo "</td></tr>\n";
179}
180echo "<tr bgcolor=\"$color[5]\"><th colspan=2><input value=\"" .
181 _("Change Settings") . "\" type=submit></th></tr>" ,
182 '</table></form>';
183
184/*
185 Write the options to the file.
186*/
187$fp = fopen( $cfgfile, 'w' );
188fwrite( $fp, "<?PHP\n".
189 "/**\n".
190 " * SquirrelMail Configuration File\n".
191 " * Created using the Administrator Plugin\n".
192 " */\n\n" );
193
194fwrite( $fp, 'GLOBAL ' );
195$not_first = FALSE;
196foreach ( $newcfg as $k => $v ) {
197 if( $i = strpos( $k, '[' ) ) {
198 if( strpos( $k, '[0]' ) ) {
199 if( $not_first ) {
200 fwrite( $fp, ', ' );
201 }
202 fwrite( $fp, substr( $k, 0, $i) );
203 $not_first = TRUE;
204 }
205 } else {
206 if( $not_first ) {
207 fwrite( $fp, ', ' );
208 }
209 fwrite( $fp, $k );
210 $not_first = TRUE;
211 }
212}
213fwrite( $fp, ";\n" );
214foreach ( $newcfg as $k => $v ) {
215 fwrite( $fp, "$k = $v;\n" );
216}
217fwrite( $fp, '?>' );
218fclose( $fp );
219?>