fix typo in address group.
[squirrelmail.git] / plugins / administrator / options.php
CommitLineData
abd7a3f8 1<?php
2
3/**
fd521778 4 * Administrator Plugin - Options Page
abd7a3f8 5 *
fd521778 6 * This script creates separate page, that allows to review and modify
7 * SquirrelMail configuration file.
abd7a3f8 8 *
0df03ce7 9 * @version $Id$
fd521778 10 * @author Philippe Mingo
6c84ba1e 11 * @copyright (c) 1999-2005 The SquirrelMail Project Team
fd521778 12 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
ea5f4b8e 13 * @package plugins
14 * @subpackage administrator
abd7a3f8 15 */
16
ea5f4b8e 17/**
18 * parse the config file
0df03ce7 19 *
20 * @param string $cfg_file
21 * @access private
ea5f4b8e 22 */
37d90494 23function parseConfig( $cfg_file ) {
24
25 global $newcfg;
26
27 $cfg = file( $cfg_file );
71e5c245 28 $mode = '';
29 $l = count( $cfg );
30 $modifier = FALSE;
0b5eb034 31 $arraykey = 0;
37d90494 32
71e5c245 33 for ($i=0;$i<$l;$i++) {
34 $line = trim( $cfg[$i] );
35 $s = strlen( $line );
36 for ($j=0;$j<$s;$j++) {
37 switch ( $mode ) {
38 case '=':
39 if ( $line{$j} == '=' ) {
40 // Ok, we've got a right value, lets detect what type
41 $mode = 'D';
42 } else if ( $line{$j} == ';' ) {
43 // hu! end of command
44 $key = $mode = '';
45 }
46 break;
47 case 'K':
48 // Key detect
ab3fe577 49 if ( $line{$j} == ' ' ) {
71e5c245 50 $mode = '=';
37d90494 51 } else {
71e5c245 52 $key .= $line{$j};
0b5eb034 53 // FIXME: this is only pour workaround for plugins[] array.
54 if ($line{$j}=='[' && $line{($j+1)}==']') {
55 $key .= $arraykey;
56 $arraykey++;
57 }
37d90494 58 }
71e5c245 59 break;
60 case ';':
61 // Skip until next ;
62 if ( $line{$j} == ';' ) {
63 $mode = '';
64 }
65 break;
66 case 'S':
67 if ( $line{$j} == '\\' ) {
68 $value .= $line{$j};
69 $modifier = TRUE;
70 } else if ( $line{$j} == $delimiter && $modifier === FALSE ) {
71 // End of string;
72 $newcfg[$key] = $value . $delimiter;
73 $key = $value = '';
74 $mode = ';';
75 } else {
76 $value .= $line{$j};
77 $modifier = FALSE;
78 }
79 break;
80 case 'N':
81 if ( $line{$j} == ';' ) {
82 $newcfg{$key} = $value;
83 $key = $mode = '';
84 } else {
85 $value .= $line{$j};
86 }
87 break;
88 case 'C':
89 // Comments
88cb1b4d 90 if ( $s > $j + 1 &&
91 $line{$j}.$line{$j+1} == '*/' ) {
71e5c245 92 $mode = '';
93 $j++;
94 }
95 break;
96 case 'D':
97 // Delimiter detect
98 switch ( $line{$j} ) {
99 case '"':
100 case "'":
101 // Double quote string
102 $delimiter = $value = $line{$j};
103 $mode = 'S';
104 break;
105 case ' ':
106 // Nothing yet
107 break;
108 default:
109 if ( strtoupper( substr( $line, $j, 4 ) ) == 'TRUE' ) {
110 // Boolean TRUE
111 $newcfg{$key} = 'TRUE';
112 $key = '';
113 $mode = ';';
114 } else if ( strtoupper( substr( $line, $j, 5 ) ) == 'FALSE' ) {
115 $newcfg{$key} = 'FALSE';
116 $key = '';
117 $mode = ';';
118 } else {
119 // Number or function call
120 $mode = 'N';
121 $value = $line{$j};
122 }
123 }
124 break;
125 default:
88cb1b4d 126 if ( $line{$j} == '$' ) {
127 // We must detect $key name
128 $mode = 'K';
129 $key = '$';
130 } else if ( $s < $j + 2 ) {
131 } else if ( strtoupper( substr( $line, $j, 7 ) ) == 'GLOBAL ' ) {
71e5c245 132 // Skip untill next ;
133 $mode = ';';
134 $j += 6;
135 } else if ( $line{$j}.$line{$j+1} == '/*' ) {
136 $mode = 'C';
137 $j++;
138 } else if ( $line{$j} == '#' || $line{$j}.$line{$j+1} == '//' ) {
139 // Delete till the end of the line
140 $j = $s;
37d90494 141 }
37d90494 142 }
143 }
37d90494 144 }
a28a56da 145}
146
0df03ce7 147/**
148 * Change paths containing SM_PATH to admin-friendly paths
149 * relative to the config dir, i.e.:
150 * '' --> <empty string>
151 * SM_PATH . 'images/logo.gif' --> ../images/logo.gif
152 * '/absolute/path/logo.gif' --> /absolute/path/logo.gif
153 * 'http://whatever/' --> http://whatever
154 * Note removal of quotes in returned value
91e0dccc 155 *
0df03ce7 156 * @param string $old_path path that has to be converted
157 * @return string new path
158 * @access private
159 */
a28a56da 160function change_to_rel_path($old_path) {
91e0dccc 161 $new_path = str_replace("SM_PATH . '", "../", $old_path);
a28a56da 162 $new_path = str_replace("../config/","", $new_path);
163 $new_path = str_replace("'","", $new_path);
164 return $new_path;
165}
37d90494 166
0df03ce7 167/**
91e0dccc 168 * Change relative path (relative to config dir) to
0df03ce7 169 * internal SM_PATH, i.e.:
170 * empty_string --> ''
171 * ../images/logo.gif --> SM_PATH . 'images/logo.gif'
172 * images/logo.gif --> SM_PATH . 'config/images/logo.gif'
173 * /absolute/path/logo.gif --> '/absolute/path/logo.gif'
174 * http://whatever/ --> 'http://whatever'
91e0dccc 175 *
0df03ce7 176 * @param string $old_path path that has to be converted
177 * @return string new path
178 * @access private
91e0dccc 179*/
a28a56da 180function change_to_sm_path($old_path) {
ab3fe577 181 if ( $old_path === '' || $old_path == "''" ) {
182 return "''";
183 } elseif ( preg_match("/^(\/|http)/", $old_path) ) {
184 return "'" . $old_path . "'";
185 } elseif ( preg_match("/^(\$|SM_PATH)/", $old_path) ) {
186 return $old_path;
187 }
91e0dccc 188
ab3fe577 189 $new_path = '';
190 $rel_path = explode("../", $old_path);
191 if ( count($rel_path) > 2 ) {
91e0dccc 192 // Since we're relative to the config dir,
ab3fe577 193 // more than 1 ../ puts us OUTSIDE the SM tree.
194 // get full path to config.php, then pop the filename
195 $abs_path = explode('/', realpath (SM_PATH . 'config/config.php'));
91e0dccc 196 array_pop ($abs_path);
ab3fe577 197 foreach ( $rel_path as $subdir ) {
198 if ( $subdir === '' ) {
199 array_pop ($abs_path);
200 } else {
201 array_push($abs_path, $subdir);
202 }
203 }
204 foreach ($abs_path as $subdir) {
205 $new_path .= $subdir . '/';
206 }
207 $new_path = "'$new_path'";
208 } elseif ( count($rel_path) > 1 ) {
209 // we're within the SM tree, prepend SM_PATH
210 $new_path = str_replace('../',"SM_PATH . '", $old_path . "'");
211 } else {
91e0dccc 212 // Last, if it's a relative path without a .. prefix,
ab3fe577 213 // we're somewhere within the config dir, so prepend
91e0dccc 214 // SM_PATH . 'config/
ab3fe577 215 $new_path = "SM_PATH . 'config/" . $old_path . "'";
216 }
217 return $new_path;
37d90494 218}
71e5c245 219
a28a56da 220
37d90494 221/* ---------------------- main -------------------------- */
71e5c245 222
ea5f4b8e 223/** @ignore */
8d6a115b 224define('SM_PATH','../../');
cf1efdce 225
226/* SquirrelMail required files. */
227require_once(SM_PATH . 'include/validate.php');
cf1efdce 228require_once(SM_PATH . 'functions/imap.php');
cf1efdce 229require_once(SM_PATH . 'plugins/administrator/defines.php');
230require_once(SM_PATH . 'plugins/administrator/auth.php');
abd7a3f8 231
fd521778 232global $data_dir, $username;
a3fab7e3 233
7004cc32 234if ( !adm_check_user() ) {
a28a56da 235 header('Location: ' . SM_PATH . 'src/options.php') ;
dcd6f144 236 exit;
237}
238
abd7a3f8 239displayPageHeader($color, 'None');
240
37d90494 241$newcfg = array( );
0e66bc84 242
243foreach ( $defcfg as $key => $def ) {
244 $newcfg[$key] = '';
245}
246
b59d1a7d 247$cfgfile = SM_PATH . 'config/config.php';
248parseConfig( SM_PATH . 'config/config_default.php' );
37d90494 249parseConfig( $cfgfile );
abd7a3f8 250
88cb1b4d 251$colapse = array( 'Titles' => 'off',
252 'Group1' => getPref($data_dir, $username, 'adm_Group1', 'off' ),
253 'Group2' => getPref($data_dir, $username, 'adm_Group2', 'on' ),
254 'Group3' => getPref($data_dir, $username, 'adm_Group3', 'on' ),
255 'Group4' => getPref($data_dir, $username, 'adm_Group4', 'on' ),
256 'Group5' => getPref($data_dir, $username, 'adm_Group5', 'on' ),
257 'Group6' => getPref($data_dir, $username, 'adm_Group6', 'on' ),
258 'Group7' => getPref($data_dir, $username, 'adm_Group7', 'on' ),
39d3ec89 259 'Group8' => getPref($data_dir, $username, 'adm_Group8', 'on' ),
260 'Group9' => getPref($data_dir, $username, 'adm_Group9', 'on' ),
0f610dca 261 'Group10' => getPref($data_dir, $username, 'adm_Group10', 'on' ),
0b5eb034 262 'Group11' => getPref($data_dir, $username, 'adm_Group11', 'on' ) );
a3fab7e3 263
4cd8ae7d 264/* look in $_GET array for 'switch' */
265if ( sqgetGlobalVar('switch', $switch, SQ_GET) ) {
88cb1b4d 266 if ( $colapse[$switch] == 'on' ) {
ab3fe577 267 $colapse[$switch] = 'off';
88cb1b4d 268 } else {
ab3fe577 269 $colapse[$switch] = 'on';
88cb1b4d 270 }
a3fab7e3 271 setPref($data_dir, $username, "adm_$switch", $colapse[$switch] );
272}
273
78154473 274echo '<form action="options.php" method="post" name="options">' .
ab3fe577 275 '<center><table width="95%" bgcolor="'.$color[5].'"><tr><td>'.
276 '<table width="100%" cellspacing="0" bgcolor="'.$color[4].'">'.
277 '<tr bgcolor="'.$color[5].'"><th colspan="2">'.
278 _("Configuration Administrator").'</th></tr>'.
279 '<tr bgcolor="'.$color[5].'"><td colspan="2" align="center"><small>'.
280 _("Note: it is recommended that you configure your system using conf.pl, and not this plugin. conf.pl contains additional information regarding the purpose of variables and appropriate values, as well as additional verification steps.").
281 '<br />'.
282 _("Run or consult conf.pl should you run into difficulty with your configuration.").
283 '</small></td></tr>';
39d3ec89 284
a3fab7e3 285
286$act_grp = 'Titles'; /* Active group */
c83b38c1 287
abd7a3f8 288foreach ( $newcfg as $k => $v ) {
289 $l = strtolower( $v );
290 $type = SMOPT_TYPE_UNDEFINED;
291 $n = substr( $k, 1 );
292 $n = str_replace( '[', '_', $n );
293 $n = str_replace( ']', '_', $n );
294 $e = 'adm_' . $n;
295 $name = $k;
296 $size = 50;
0e66bc84 297 if ( isset( $defcfg[$k] ) ) {
298 $name = $defcfg[$k]['name'];
299 $type = $defcfg[$k]['type'];
88cb1b4d 300 if ( isset( $defcfg[$k]['size'] ) ) {
301 $size = $defcfg[$k]['size'];
302 } else {
303 $size = 40;
304 }
abd7a3f8 305 } else if ( $l == 'true' ) {
306 $v = 'TRUE';
307 $type = SMOPT_TYPE_BOOLEAN;
308 } else if ( $l == 'false' ) {
309 $v = 'FALSE';
310 $type = SMOPT_TYPE_BOOLEAN;
311 } else if ( $v{0} == "'" ) {
312 $type = SMOPT_TYPE_STRING;
313 } else if ( $v{0} == '"' ) {
314 $type = SMOPT_TYPE_STRING;
315 }
316
edd4a552 317 if ( substr( $k, 0, 7 ) == '$theme[' ) {
318 $type = SMOPT_TYPE_THEME;
319 } else if ( substr( $k, 0, 9 ) == '$plugins[' ) {
320 $type = SMOPT_TYPE_PLUGINS;
65a5bae6 321 } else if ( substr( $k, 0, 13 ) == '$ldap_server[' ) {
322 $type = SMOPT_TYPE_LDAP;
edd4a552 323 }
324
ab3fe577 325 if ( $type == SMOPT_TYPE_TITLE || $colapse[$act_grp] == 'off' ) {
a3fab7e3 326
327 switch ( $type ) {
328 case SMOPT_TYPE_LDAP:
329 case SMOPT_TYPE_PLUGINS:
330 case SMOPT_TYPE_THEME:
331 case SMOPT_TYPE_HIDDEN:
332 break;
88cb1b4d 333 case SMOPT_TYPE_EXTERNAL:
334 echo "<tr><td>$name</td><td><b>" .
335 $defcfg[$k]['value'] .
ab3fe577 336 '</b></td></tr>';
88cb1b4d 337 break;
a3fab7e3 338 case SMOPT_TYPE_TITLE:
88cb1b4d 339 if ( $colapse[$k] == 'on' ) {
a3fab7e3 340 $sw = '(+)';
341 } else {
342 $sw = '(-)';
dcd6f144 343 }
ab3fe577 344 echo '<tr bgcolor="'.$color[0].'"><th colspan="2">'.
345 "<a href=\"options.php?switch=$k\" style=\"text-decoration:none\">".
346 '<b>'.$sw.'</b></a> '.$name.'</th></tr>';
a3fab7e3 347 $act_grp = $k;
348 break;
349 case SMOPT_TYPE_COMMENT:
350 $v = substr( $v, 1, strlen( $v ) - 2 );
351 echo "<tr><td>$name</td><td>".
352 "<b>$v</b>";
353 $newcfg[$k] = "'$v'";
354 if ( isset( $defcfg[$k]['comment'] ) ) {
355 echo ' &nbsp; ' . $defcfg[$k]['comment'];
abd7a3f8 356 }
a3fab7e3 357 echo "</td></tr>\n";
358 break;
359 case SMOPT_TYPE_INTEGER:
ab3fe577 360 /* look for variable $e in POST, fill into $v */
0b5eb034 361 if ( sqgetGlobalVar($e, $new_v, SQ_POST) ) {
362 $v = intval( $new_v );
a3fab7e3 363 $newcfg[$k] = $v;
364 }
365 echo "<tr><td>$name</td><td>".
ab3fe577 366 "<input size=\"10\" name=\"adm_$n\" value=\"$v\" />";
a3fab7e3 367 if ( isset( $defcfg[$k]['comment'] ) ) {
368 echo ' &nbsp; ' . $defcfg[$k]['comment'];
369 }
370 echo "</td></tr>\n";
371 break;
372 case SMOPT_TYPE_NUMLIST:
0b5eb034 373 if ( sqgetGlobalVar($e, $new_v, SQ_POST) ) {
374 $v = $new_v;
a3fab7e3 375 $newcfg[$k] = $v;
376 }
377 echo "<tr><td>$name</td><td>";
378 echo "<select name=\"adm_$n\">";
379 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
380 echo "<option value=\"$kp\"";
381 if ( $kp == $v ) {
ab3fe577 382 echo ' selected="selected"';
a3fab7e3 383 }
384 echo ">$vp</option>";
385 }
386 echo '</select>';
387 if ( isset( $defcfg[$k]['comment'] ) ) {
388 echo ' &nbsp; ' . $defcfg[$k]['comment'];
389 }
390 echo "</td></tr>\n";
391 break;
392 case SMOPT_TYPE_STRLIST:
0b5eb034 393 if ( sqgetGlobalVar($e, $new_v, SQ_POST) ) {
394 $v = '"' . $new_v . '"';
a3fab7e3 395 $newcfg[$k] = $v;
396 }
397 echo "<tr><td>$name</td><td>".
398 "<select name=\"adm_$n\">";
399 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
400 echo "<option value=\"$kp\"";
401 if ( $kp == substr( $v, 1, strlen( $v ) - 2 ) ) {
ab3fe577 402 echo ' selected="selected"';
a3fab7e3 403 }
404 echo ">$vp</option>";
405 }
406 echo '</select>';
407 if ( isset( $defcfg[$k]['comment'] ) ) {
408 echo ' &nbsp; ' . $defcfg[$k]['comment'];
409 }
410 echo "</td></tr>\n";
411 break;
c83b38c1 412
a3fab7e3 413 case SMOPT_TYPE_TEXTAREA:
0b5eb034 414 if ( sqgetGlobalVar($e, $new_v, SQ_POST) ) {
415 $v = '"' . $new_v . '"';
a3fab7e3 416 $newcfg[$k] = str_replace( "\n", '', $v );
417 }
78154473 418 echo "<tr><td valign=\"top\">$name</td><td>".
419 "<textarea cols=\"$size\" rows=\"4\" name=\"adm_$n\">" . substr( $v, 1, strlen( $v ) - 2 ) . "</textarea>";
a3fab7e3 420 if ( isset( $defcfg[$k]['comment'] ) ) {
421 echo ' &nbsp; ' . $defcfg[$k]['comment'];
422 }
423 echo "</td></tr>\n";
424 break;
425 case SMOPT_TYPE_STRING:
0b5eb034 426 if ( sqgetGlobalVar($e, $new_v, SQ_POST) ) {
427 $v = '"' . $new_v . '"';
a3fab7e3 428 $newcfg[$k] = $v;
429 }
feba1a41 430 if ( $v == '""' && isset( $defcfg[$k]['default'] ) ) {
431 $v = "'" . $defcfg[$k]['default'] . "'";
432 $newcfg[$k] = $v;
433 }
a3fab7e3 434 echo "<tr><td>$name</td><td>".
ab3fe577 435 "<input size=\"$size\" name=\"adm_$n\" value=\"" . substr( $v, 1, strlen( $v ) - 2 ) . '" />';
a3fab7e3 436 if ( isset( $defcfg[$k]['comment'] ) ) {
437 echo ' &nbsp; ' . $defcfg[$k]['comment'];
438 }
439 echo "</td></tr>\n";
440 break;
441 case SMOPT_TYPE_BOOLEAN:
0b5eb034 442 if ( sqgetGlobalVar($e, $new_v, SQ_POST) ) {
443 $v = $new_v;
a3fab7e3 444 $newcfg[$k] = $v;
445 } else {
446 $v = strtoupper( $v );
447 }
448 if ( $v == 'TRUE' ) {
ab3fe577 449 $ct = ' checked="checked"';
a3fab7e3 450 $cf = '';
451 } else {
452 $ct = '';
ab3fe577 453 $cf = ' checked="checked"';
a3fab7e3 454 }
455 echo "<tr><td>$name</td><td>" .
ab3fe577 456 "<input$ct type=\"radio\" name=\"adm_$n\" value=\"TRUE\" />" . _("Yes") .
457 "<input$cf type=\"radio\" name=\"adm_$n\" value=\"FALSE\" />" . _("No");
a3fab7e3 458 if ( isset( $defcfg[$k]['comment'] ) ) {
459 echo ' &nbsp; ' . $defcfg[$k]['comment'];
460 }
461 echo "</td></tr>\n";
462 break;
ab3fe577 463 case SMOPT_TYPE_PATH:
0b5eb034 464 if ( sqgetGlobalVar($e, $new_v, SQ_POST) ) {
465 // FIXME: fix use of $data_dir in $attachment_dir
466 $v = change_to_sm_path($new_v);
467 $newcfg[$k] = $v;
a28a56da 468 }
469 if ( $v == "''" && isset( $defcfg[$k]['default'] ) ) {
470 $v = change_to_sm_path($defcfg[$k]['default']);
471 $newcfg[$k] = $v;
472 }
ab3fe577 473 echo "<tr><td>$name</td><td>".
474 "<input size=\"$size\" name=\"adm_$n\" value=\"" . change_to_rel_path($v) . '" />';
a28a56da 475 if ( isset( $defcfg[$k]['comment'] ) ) {
476 echo ' &nbsp; ' . $defcfg[$k]['comment'];
477 }
ab3fe577 478 echo "</td></tr>\n";
479 break;
a3fab7e3 480 default:
481 echo "<tr><td>$name</td><td>" .
482 "<b><i>$v</i></b>";
483 if ( isset( $defcfg[$k]['comment'] ) ) {
484 echo ' &nbsp; ' . $defcfg[$k]['comment'];
485 }
486 echo "</td></tr>\n";
6a9acbca 487 }
a3fab7e3 488 }
a3fab7e3 489}
490
1fa5ece1 491/* Special Themes Block */
88cb1b4d 492if ( $colapse['Group7'] == 'off' ) {
a3fab7e3 493 $i = 0;
494 echo '<tr><th>' . _("Theme Name") .
495 '</th><th>' . _("Theme Path") .
496 '</th></tr>';
497 while ( isset( $newcfg["\$theme[$i]['NAME']"] ) ) {
498 $k1 = "\$theme[$i]['NAME']";
499 $e1 = "theme_name_$i";
4cd8ae7d 500 if ( sqgetGlobalVar($e, $v1, SQ_POST) ) {
501 $v1 = '"' . str_replace( '\"', '"', $v1 ) . '"';
b5a29535 502 $v1 = '"' . str_replace( '"', '\"', $v1 ) . '"';
a3fab7e3 503 $newcfg[$k1] = $v1;
a55bb207 504 } else {
a3fab7e3 505 $v1 = $newcfg[$k1];
abd7a3f8 506 }
a3fab7e3 507 $k2 = "\$theme[$i]['PATH']";
508 $e2 = "theme_path_$i";
4cd8ae7d 509 if ( sqgetGlobalVar($e, $v2, SQ_POST) ) {
510 $v2 = change_to_sm_path($v2);
ab3fe577 511 $newcfg[$k2] = $v2;
abd7a3f8 512 } else {
a3fab7e3 513 $v2 = $newcfg[$k2];
abd7a3f8 514 }
a3fab7e3 515 $name = substr( $v1, 1, strlen( $v1 ) - 2 );
a28a56da 516 $path = change_to_rel_path($v2);
a3fab7e3 517 echo '<tr>'.
ab3fe577 518 "<td align=\"right\">$i. <input name=\"$e1\" value=\"$name\" size=\"30\" /></td>".
519 "<td><input name=\"$e2\" value=\"$path\" size=\"40\" /></td>".
a3fab7e3 520 "</tr>\n";
521 $i++;
c83b38c1 522
6a9acbca 523 }
6a9acbca 524}
525
1fa5ece1 526/* Special Plugins Block */
88cb1b4d 527if ( $colapse['Group8'] == 'on' ) {
a3fab7e3 528 $sw = '(+)';
529} else {
530 $sw = '(-)';
6a9acbca 531}
ab3fe577 532echo '<tr bgcolor="'.$color[0].'"><th colspan="2">'.
533 '<a href="options.php?switch=Group8" style="text-decoration:none"><b>'.
534 $sw.'</b></a> '._("Plugins").'</th></tr>';
535
536if ( $colapse['Group8'] == 'off' ) {
537
538 $plugpath = SM_PATH . 'plugins/';
539 if ( file_exists($plugpath) ) {
540 $fd = opendir( $plugpath );
541 $op_plugin = array();
542 $p_count = 0;
543 while (false !== ($file = readdir($fd))) {
544 if ($file != '.' && $file != '..' && $file != 'CVS' && is_dir($plugpath . $file) ) {
545 $op_plugin[] = $file;
546 $p_count++;
c83b38c1 547 }
548 }
ab3fe577 549 closedir($fd);
550 asort( $op_plugin );
551
552 /* Lets get the plugins that are active */
553 $plugins = array();
0b5eb034 554 if ( sqgetGlobalVar('plg', $v, SQ_POST) ) {
ab3fe577 555 foreach ( $op_plugin as $plg ) {
0b5eb034 556 if ( sqgetGlobalVar("plgs_$plg", $v2, SQ_POST) && $v2 == 'on' ) {
ab3fe577 557 $plugins[] = $plg;
558 }
559 }
560 $i = 0;
561 foreach ( $plugins as $plg ) {
562 $k = "\$plugins[$i]";
563 $newcfg[$k] = "'$plg'";
564 $i++;
565 }
566 while ( isset( $newcfg["\$plugins[$i]"] ) ) {
567 $k = "\$plugins[$i]";
568 $newcfg[$k] = '';
569 $i++;
570 }
c83b38c1 571 } else {
ab3fe577 572 $i = 0;
573 while ( isset( $newcfg["\$plugins[$i]"] ) ) {
574 $k = "\$plugins[$i]";
575 $v = $newcfg[$k];
576 $plugins[] = substr( $v, 1, strlen( $v ) - 2 );
577 $i++;
578 }
a3fab7e3 579 }
ab3fe577 580 echo '<tr><td colspan="2"><input type="hidden" name="plg" value="on" /><center><table>';
581 foreach ( $op_plugin as $plg ) {
582 if ( in_array( $plg, $plugins ) ) {
583 $sw = ' checked="checked"';
584 } else {
585 $sw = '';
586 }
587 echo '<tr><td>';
588 if (file_exists(SM_PATH . "plugins/$plg/README")) {
589 echo "<a href=\"../$plg/README\" target=\"_blank\">$plg</a>";
590 } else {
591 echo $plg;
592 }
593 echo "</td>\n".
594 "<td><input$sw type=\"checkbox\" name=\"plgs_$plg\" /></td>".
595 "</tr>\n";
596 }
597 echo '</table></center></td></tr>';
598 } else {
599 echo '<tr><td colspan="2" align="center">'.
600 sprintf(_("Plugin directory could not be found: %s"), $plugpath).
601 "</td></tr>\n";
602 }
6a9acbca 603}
ab3fe577 604echo '<tr bgcolor="'.$color[5].'"><th colspan="2"><input value="'.
605 _("Change Settings").'" type="submit" /><br />'.
606 '<a href="'.SM_PATH.'src/configtest.php" target="_blank">'.
607 _("Test Configuration")."</a></th></tr>\n".
78154473 608 '</table></td></tr></table></center></form>';
abd7a3f8 609
610/*
611 Write the options to the file.
612*/
71e5c245 613
ab3fe577 614if ( $fp = @fopen( $cfgfile, 'w' ) ) {
615 fwrite( $fp, "<?php\n".
b5a29535 616 "/**\n".
617 " * SquirrelMail Configuration File\n".
618 " * Created using the Administrator Plugin\n".
39d3ec89 619 " */\n".
620 "\n".
621 "global \$version;\n" );
b5a29535 622
c05c489a 623 foreach ( $newcfg as $k => $v ) {
781da5d4 624 if ( $k{0} == '$' && $v <> '' || is_int($v)) {
c05c489a 625 if ( substr( $k, 1, 11 ) == 'ldap_server' ) {
b5a29535 626 $v = substr( $v, 0, strlen( $v ) - 1 ) . "\n)";
627 $v = str_replace( 'array(', "array(\n\t", $v );
628 $v = str_replace( "',", "',\n\t", $v );
c05c489a 629 }
0b5eb034 630 /* FIXME: add elseif that reverts plugins[#] to plugins[] */
c05c489a 631 fwrite( $fp, "$k = $v;\n" );
ab3fe577 632 }
0e66bc84 633 }
0b5eb034 634 // add local config support
635 fwrite( $fp, "@include SM_PATH . 'config/config_local.php';\n" );
636 // close php
c05c489a 637 fwrite( $fp, '?>' );
638 fclose( $fp );
639} else {
78154473 640 echo '<br /><p align="center"><big>'.
c05c489a 641 _("Config file can't be opened. Please check config.php.").
78154473 642 '</big></p>';
abd7a3f8 643}
dcc1cc82 644?>
78154473 645</body></html>