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