Search was broken. fixed. List all is weird however, it works but does not alternate...
[squirrelmail.git] / plugins / administrator / options.php
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
14 function parseConfig( $cfg_file ) {
15
16 global $newcfg;
17
18 $cfg = file( $cfg_file );
19 $mode = '';
20 $l = count( $cfg );
21 $modifier = FALSE;
22
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 = '=';
41 } else {
42 $key .= $line{$j};
43 }
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 = '$';
124 }
125 }
126 }
127 }
128
129 }
130
131 /* ---------------------- main -------------------------- */
132
133 chdir('..');
134 require_once('../src/validate.php');
135 require_once('../functions/page_header.php');
136 require_once('../functions/imap.php');
137 require_once('../src/load_prefs.php');
138 require_once('../plugins/administrator/defines.php');
139
140 GLOBAL $data_dir, $username;
141
142 $auth = FALSE;
143 if ( $adm_id = fileowner('../config/config.php') ) {
144 $adm = posix_getpwuid( $adm_id );
145 if ( $username == $adm['name'] ) {
146 $auth = TRUE;
147 }
148 }
149
150 if ( !auth ) {
151 header("Location: ../../src/options.php") ;
152 exit;
153 }
154
155 displayPageHeader($color, 'None');
156
157 $newcfg = array( );
158
159 foreach ( $defcfg as $key => $def ) {
160 $newcfg[$key] = '';
161 }
162
163 $cfgfile = '../config/config.php';
164 parseConfig( '../config/config_default.php' );
165 parseConfig( $cfgfile );
166
167 $colapse = array( 'Titles' => FALSE,
168 'Group1' => getPref($data_dir, $username, 'adm_Group1', FALSE ),
169 'Group2' => getPref($data_dir, $username, 'adm_Group2', TRUE ),
170 'Group3' => getPref($data_dir, $username, 'adm_Group3', TRUE ),
171 'Group4' => getPref($data_dir, $username, 'adm_Group4', TRUE ),
172 'Group5' => getPref($data_dir, $username, 'adm_Group5', TRUE ),
173 'Group6' => getPref($data_dir, $username, 'adm_Group6', TRUE ),
174 'Group7' => getPref($data_dir, $username, 'adm_Group7', TRUE ) );
175
176 if ( isset( $switch ) ) {
177 $colapse[$switch] = !$colapse[$switch];
178 setPref($data_dir, $username, "adm_$switch", $colapse[$switch] );
179 }
180
181 echo "<form action=$PHP_SELF method=post>" .
182 "<br><center><table width=95% bgcolor=\"$color[5]\"><tr><td>".
183 "<table width=100% cellspacing=0 bgcolor=\"$color[4]\">" ,
184 "<tr bgcolor=\"$color[5]\"><th colspan=2>" . _("Configuration Administrator") . "</th></tr>";
185
186 $act_grp = 'Titles'; /* Active group */
187
188 foreach ( $newcfg as $k => $v ) {
189 $l = strtolower( $v );
190 $type = SMOPT_TYPE_UNDEFINED;
191 $n = substr( $k, 1 );
192 $n = str_replace( '[', '_', $n );
193 $n = str_replace( ']', '_', $n );
194 $e = 'adm_' . $n;
195 $name = $k;
196 $size = 50;
197 if ( isset( $defcfg[$k] ) ) {
198 $name = $defcfg[$k]['name'];
199 $type = $defcfg[$k]['type'];
200 $size = $defcfg[$k]['size'];
201 } else if ( $l == 'true' ) {
202 $v = 'TRUE';
203 $type = SMOPT_TYPE_BOOLEAN;
204 } else if ( $l == 'false' ) {
205 $v = 'FALSE';
206 $type = SMOPT_TYPE_BOOLEAN;
207 } else if ( $v{0} == "'" ) {
208 $type = SMOPT_TYPE_STRING;
209 } else if ( $v{0} == '"' ) {
210 $type = SMOPT_TYPE_STRING;
211 }
212
213 if ( substr( $k, 0, 7 ) == '$theme[' ) {
214 $type = SMOPT_TYPE_THEME;
215 } else if ( substr( $k, 0, 9 ) == '$plugins[' ) {
216 $type = SMOPT_TYPE_PLUGINS;
217 } else if ( substr( $k, 0, 13 ) == '$ldap_server[' ) {
218 $type = SMOPT_TYPE_LDAP;
219 }
220
221 if( $type == SMOPT_TYPE_TITLE || !$colapse[$act_grp] ) {
222
223 switch ( $type ) {
224 case SMOPT_TYPE_LDAP:
225 case SMOPT_TYPE_PLUGINS:
226 case SMOPT_TYPE_THEME:
227 case SMOPT_TYPE_HIDDEN:
228 break;
229 case SMOPT_TYPE_TITLE:
230 if ( $colapse[$k] ) {
231 $sw = '(+)';
232 } else {
233 $sw = '(-)';
234 }
235 echo "<tr bgcolor=\"$color[0]\"><th colspan=2>" .
236 "<a href=options.php?switch=$k STYLE=\"text-decoration:none\"><b>$sw</b> </a>" .
237 "$name</th></tr>";
238 $act_grp = $k;
239 break;
240 case SMOPT_TYPE_COMMENT:
241 $v = substr( $v, 1, strlen( $v ) - 2 );
242 echo "<tr><td>$name</td><td>".
243 "<b>$v</b>";
244 $newcfg[$k] = "'$v'";
245 if ( isset( $defcfg[$k]['comment'] ) ) {
246 echo ' &nbsp; ' . $defcfg[$k]['comment'];
247 }
248 echo "</td></tr>\n";
249 break;
250 case SMOPT_TYPE_INTEGER:
251 if ( isset( $HTTP_POST_VARS[$e] ) ) {
252 $v = intval( $HTTP_POST_VARS[$e] );
253 $newcfg[$k] = $v;
254 }
255 echo "<tr><td>$name</td><td>".
256 "<input size=10 name=\"adm_$n\" value=\"$v\">";
257 if ( isset( $defcfg[$k]['comment'] ) ) {
258 echo ' &nbsp; ' . $defcfg[$k]['comment'];
259 }
260 echo "</td></tr>\n";
261 break;
262 case SMOPT_TYPE_NUMLIST:
263 if ( isset( $HTTP_POST_VARS[$e] ) ) {
264 $v = $HTTP_POST_VARS[$e];
265 $newcfg[$k] = $v;
266 }
267 echo "<tr><td>$name</td><td>";
268 echo "<select name=\"adm_$n\">";
269 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
270 echo "<option value=\"$kp\"";
271 if ( $kp == $v ) {
272 echo ' selected';
273 }
274 echo ">$vp</option>";
275 }
276 echo '</select>';
277 if ( isset( $defcfg[$k]['comment'] ) ) {
278 echo ' &nbsp; ' . $defcfg[$k]['comment'];
279 }
280 echo "</td></tr>\n";
281 break;
282 case SMOPT_TYPE_STRLIST:
283 if ( isset( $HTTP_POST_VARS[$e] ) ) {
284 $v = '"' . $HTTP_POST_VARS[$e] . '"';
285 $newcfg[$k] = $v;
286 }
287 echo "<tr><td>$name</td><td>".
288 "<select name=\"adm_$n\">";
289 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
290 echo "<option value=\"$kp\"";
291 if ( $kp == substr( $v, 1, strlen( $v ) - 2 ) ) {
292 echo ' selected';
293 }
294 echo ">$vp</option>";
295 }
296 echo '</select>';
297 if ( isset( $defcfg[$k]['comment'] ) ) {
298 echo ' &nbsp; ' . $defcfg[$k]['comment'];
299 }
300 echo "</td></tr>\n";
301 break;
302
303 case SMOPT_TYPE_TEXTAREA:
304 if ( isset( $HTTP_POST_VARS[$e] ) ) {
305 $v = '"' . $HTTP_POST_VARS[$e] . '"';
306 $newcfg[$k] = str_replace( "\n", '', $v );
307 }
308 echo "<tr><td valign=top>$name</td><td>".
309 "<textarea cols=\"$size\" name=\"adm_$n\">" . substr( $v, 1, strlen( $v ) - 2 ) . "</textarea>";
310 if ( isset( $defcfg[$k]['comment'] ) ) {
311 echo ' &nbsp; ' . $defcfg[$k]['comment'];
312 }
313 echo "</td></tr>\n";
314 break;
315 case SMOPT_TYPE_STRING:
316 if ( isset( $HTTP_POST_VARS[$e] ) ) {
317 $v = '"' . $HTTP_POST_VARS[$e] . '"';
318 $newcfg[$k] = $v;
319 }
320 echo "<tr><td>$name</td><td>".
321 "<input size=\"$size\" name=\"adm_$n\" value=\"" . substr( $v, 1, strlen( $v ) - 2 ) . "\">";
322 if ( isset( $defcfg[$k]['comment'] ) ) {
323 echo ' &nbsp; ' . $defcfg[$k]['comment'];
324 }
325 echo "</td></tr>\n";
326 break;
327 case SMOPT_TYPE_BOOLEAN:
328 if ( isset( $HTTP_POST_VARS[$e] ) ) {
329 $v = $HTTP_POST_VARS[$e];
330 $newcfg[$k] = $v;
331 } else {
332 $v = strtoupper( $v );
333 }
334 if ( $v == 'TRUE' ) {
335 $ct = ' checked';
336 $cf = '';
337 } else {
338 $ct = '';
339 $cf = ' checked';
340 }
341 echo "<tr><td>$name</td><td>" .
342 "<INPUT$ct type=radio NAME=\"adm_$n\" value=\"TRUE\">" . _("Yes") .
343 "<INPUT$cf type=radio NAME=\"adm_$n\" value=\"FALSE\">" . _("No");
344 if ( isset( $defcfg[$k]['comment'] ) ) {
345 echo ' &nbsp; ' . $defcfg[$k]['comment'];
346 }
347 echo "</td></tr>\n";
348 break;
349 default:
350 echo "<tr><td>$name</td><td>" .
351 "<b><i>$v</i></b>";
352 if ( isset( $defcfg[$k]['comment'] ) ) {
353 echo ' &nbsp; ' . $defcfg[$k]['comment'];
354 }
355 echo "</td></tr>\n";
356 }
357 }
358
359 }
360
361 if ( !($colapse['Group6']) ) {
362 $i = 0;
363 echo '<tr><th>' . _("Theme Name") .
364 '</th><th>' . _("Theme Path") .
365 '</th></tr>';
366 while ( isset( $newcfg["\$theme[$i]['NAME']"] ) ) {
367 $k1 = "\$theme[$i]['NAME']";
368 $e1 = "theme_name_$i";
369 if ( isset( $HTTP_POST_VARS[$e1] ) ) {
370 $v1 = '"' . $HTTP_POST_VARS[$e1] . '"';
371 $newcfg[$k1] = $v1;
372 } else {
373 $v1 = $newcfg[$k1];
374 }
375 $k2 = "\$theme[$i]['PATH']";
376 $e2 = "theme_path_$i";
377 if ( isset( $HTTP_POST_VARS[$e2] ) ) {
378 $v2 = '"' . $HTTP_POST_VARS[$e2] . '"';
379 $newcfg[$k2] = $v2;
380 } else {
381 $v2 = $newcfg[$k2];
382 }
383 $name = substr( $v1, 1, strlen( $v1 ) - 2 );
384 $path = substr( $v2, 1, strlen( $v2 ) - 2 );
385 echo '<tr>'.
386 "<td align=right>$i. <input name=\"$e1\" value=\"$name\" size=30></td>".
387 "<td><input name=\"$e2\" value=\"$path\" size=40></td>".
388 "</tr>\n";
389 $i++;
390
391 }
392 }
393
394 if ( $colapse['Group7'] ) {
395 $sw = '(+)';
396 } else {
397 $sw = '(-)';
398 }
399 echo "<tr bgcolor=\"$color[0]\"><th colspan=2>" .
400 "<a href=options.php?switch=Group7 STYLE=\"text-decoration:none\"><b>$sw</b> </a>" .
401 _("Plugins") . '</th></tr>';
402
403 if( !$colapse['Group7'] ) {
404
405 $fd = opendir( '../plugins/' );
406 $op_plugin = array();
407 while (false!==($file = readdir($fd))) {
408 if ($file != '.' && $file != '..' && $file != 'CVS' ) {
409 if ( filetype( $file ) == 'dir' ) {
410 $op_plugin[] = $file;
411 }
412 }
413 }
414 closedir($fd);
415 asort( $op_plugin );
416
417 $i = 0;
418 while ( isset( $newcfg["\$plugins[$i]"] ) ) {
419 $k = "\$plugins[$i]";
420 $e = "plugin_$i";
421 if ( isset( $HTTP_POST_VARS[$e] ) ) {
422 $v = '"' . $HTTP_POST_VARS[$e] . '"';
423 $newcfg[$k] = $v;
424 } else {
425 $v = $newcfg[$k];
426 }
427 $name = substr( $v, 1, strlen( $v ) - 2 );
428 echo '<tr>'.
429 "<td align=right>$i.</td>".
430 "<td><select name=\"$e\">";
431 foreach ( $op_plugin as $op ) {
432 if ( $op == $name ) {
433 $cs = ' selected';
434 } else {
435 $cs = '';
436 }
437 echo "<option$cs>$op</option>";
438 }
439 echo "</select></td>".
440 '</tr>';
441 $i++;
442
443 }
444 }
445 echo "<tr bgcolor=\"$color[5]\"><th colspan=2><input value=\"" .
446 _("Change Settings") . "\" type=submit></th></tr>" ,
447 '</table></td></tr></table></form>';
448
449 /*
450 Write the options to the file.
451 */
452
453 $fp = fopen( $cfgfile, 'w' );
454 fwrite( $fp, "<?PHP\n".
455 "/**\n".
456 " * SquirrelMail Configuration File\n".
457 " * Created using the Administrator Plugin\n".
458 " */\n" );
459
460 /*
461 fwrite( $fp, 'GLOBAL ' );
462 $not_first = FALSE;
463 foreach ( $newcfg as $k => $v ) {
464 if ( $k{0} == '$' ) {
465 if( $i = strpos( $k, '[' ) ) {
466 if( strpos( $k, '[0]' ) ) {
467 if( $not_first ) {
468 fwrite( $fp, ', ' );
469 }
470 fwrite( $fp, substr( $k, 0, $i) );
471 }
472 } else {
473 if( $not_first ) {
474 fwrite( $fp, ', ' );
475 }
476 fwrite( $fp, $k );
477 }
478 $not_first = TRUE;
479 }
480 }
481 fwrite( $fp, ";\n" );
482 */
483 foreach ( $newcfg as $k => $v ) {
484 if ( $k{0} == '$' ) {
485 if ( substr( $k, 1, 11 ) == 'ldap_server' ) {
486 $v = substr( $v, 0, strlen( $v ) - 1 ) . "\n)";
487 $v = str_replace( 'array(', "array(\n\t", $v );
488 $v = str_replace( "',", "',\n\t", $v );
489 }
490 fwrite( $fp, "$k = $v;\n" );
491 }
492 }
493 fwrite( $fp, '?>' );
494 fclose( $fp );
495 ?>