Syntax error fix
[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 *
fd521778 9 * @author Philippe Mingo
4b5049de 10 * @copyright &copy; 1999-2007 The SquirrelMail Project Team
fd521778 11 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
4b4abf93 12 * @version $Id$
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 -------------------------- */
f5da0b1e 222/** main SquirrelMail include */
223require('../../include/init.php');
224/* configuration definitions */
225include_once(SM_PATH . 'plugins/administrator/defines.php');
226/* additional functions */
227include_once(SM_PATH . 'plugins/administrator/auth.php');
abd7a3f8 228
fd521778 229global $data_dir, $username;
a3fab7e3 230
7004cc32 231if ( !adm_check_user() ) {
a28a56da 232 header('Location: ' . SM_PATH . 'src/options.php') ;
dcd6f144 233 exit;
234}
235
abd7a3f8 236displayPageHeader($color, 'None');
237
37d90494 238$newcfg = array( );
0e66bc84 239
240foreach ( $defcfg as $key => $def ) {
241 $newcfg[$key] = '';
242}
243
b59d1a7d 244$cfgfile = SM_PATH . 'config/config.php';
245parseConfig( SM_PATH . 'config/config_default.php' );
37d90494 246parseConfig( $cfgfile );
abd7a3f8 247
88cb1b4d 248$colapse = array( 'Titles' => 'off',
249 'Group1' => getPref($data_dir, $username, 'adm_Group1', 'off' ),
250 'Group2' => getPref($data_dir, $username, 'adm_Group2', 'on' ),
251 'Group3' => getPref($data_dir, $username, 'adm_Group3', 'on' ),
252 'Group4' => getPref($data_dir, $username, 'adm_Group4', 'on' ),
253 'Group5' => getPref($data_dir, $username, 'adm_Group5', 'on' ),
254 'Group6' => getPref($data_dir, $username, 'adm_Group6', 'on' ),
255 'Group7' => getPref($data_dir, $username, 'adm_Group7', 'on' ),
39d3ec89 256 'Group8' => getPref($data_dir, $username, 'adm_Group8', 'on' ),
257 'Group9' => getPref($data_dir, $username, 'adm_Group9', 'on' ),
0f610dca 258 'Group10' => getPref($data_dir, $username, 'adm_Group10', 'on' ),
0b5eb034 259 'Group11' => getPref($data_dir, $username, 'adm_Group11', 'on' ) );
a3fab7e3 260
4cd8ae7d 261/* look in $_GET array for 'switch' */
262if ( sqgetGlobalVar('switch', $switch, SQ_GET) ) {
88cb1b4d 263 if ( $colapse[$switch] == 'on' ) {
ab3fe577 264 $colapse[$switch] = 'off';
88cb1b4d 265 } else {
ab3fe577 266 $colapse[$switch] = 'on';
88cb1b4d 267 }
a3fab7e3 268 setPref($data_dir, $username, "adm_$switch", $colapse[$switch] );
269}
270
78154473 271echo '<form action="options.php" method="post" name="options">' .
0d53a854 272 '<table width="95%" align="center" bgcolor="'.$color[5].'"><tr><td>'.
ab3fe577 273 '<table width="100%" cellspacing="0" bgcolor="'.$color[4].'">'.
274 '<tr bgcolor="'.$color[5].'"><th colspan="2">'.
275 _("Configuration Administrator").'</th></tr>'.
276 '<tr bgcolor="'.$color[5].'"><td colspan="2" align="center"><small>'.
277 _("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.").
278 '<br />'.
279 _("Run or consult conf.pl should you run into difficulty with your configuration.").
280 '</small></td></tr>';
39d3ec89 281
a3fab7e3 282
283$act_grp = 'Titles'; /* Active group */
c83b38c1 284
abd7a3f8 285foreach ( $newcfg as $k => $v ) {
286 $l = strtolower( $v );
287 $type = SMOPT_TYPE_UNDEFINED;
288 $n = substr( $k, 1 );
289 $n = str_replace( '[', '_', $n );
290 $n = str_replace( ']', '_', $n );
291 $e = 'adm_' . $n;
292 $name = $k;
293 $size = 50;
0e66bc84 294 if ( isset( $defcfg[$k] ) ) {
295 $name = $defcfg[$k]['name'];
296 $type = $defcfg[$k]['type'];
88cb1b4d 297 if ( isset( $defcfg[$k]['size'] ) ) {
298 $size = $defcfg[$k]['size'];
299 } else {
300 $size = 40;
301 }
abd7a3f8 302 } else if ( $l == 'true' ) {
303 $v = 'TRUE';
304 $type = SMOPT_TYPE_BOOLEAN;
305 } else if ( $l == 'false' ) {
306 $v = 'FALSE';
307 $type = SMOPT_TYPE_BOOLEAN;
308 } else if ( $v{0} == "'" ) {
309 $type = SMOPT_TYPE_STRING;
310 } else if ( $v{0} == '"' ) {
311 $type = SMOPT_TYPE_STRING;
312 }
313
edd4a552 314 if ( substr( $k, 0, 7 ) == '$theme[' ) {
315 $type = SMOPT_TYPE_THEME;
316 } else if ( substr( $k, 0, 9 ) == '$plugins[' ) {
317 $type = SMOPT_TYPE_PLUGINS;
65a5bae6 318 } else if ( substr( $k, 0, 13 ) == '$ldap_server[' ) {
319 $type = SMOPT_TYPE_LDAP;
439538dc 320 } else if ( substr( $k, 0, 9 ) == '$fontsets' ||
c3d7aa6e 321 substr( $k, 0, 13 ) == '$aTemplateSet' ) {
439538dc 322 $type = SMOPT_TYPE_CUSTOM;
edd4a552 323 }
324
ab3fe577 325 if ( $type == SMOPT_TYPE_TITLE || $colapse[$act_grp] == 'off' ) {
a3fab7e3 326
327 switch ( $type ) {
328 case SMOPT_TYPE_LDAP:
439538dc 329 case SMOPT_TYPE_CUSTOM:
a3fab7e3 330 case SMOPT_TYPE_PLUGINS:
331 case SMOPT_TYPE_THEME:
332 case SMOPT_TYPE_HIDDEN:
333 break;
88cb1b4d 334 case SMOPT_TYPE_EXTERNAL:
335 echo "<tr><td>$name</td><td><b>" .
336 $defcfg[$k]['value'] .
ab3fe577 337 '</b></td></tr>';
88cb1b4d 338 break;
a3fab7e3 339 case SMOPT_TYPE_TITLE:
88cb1b4d 340 if ( $colapse[$k] == 'on' ) {
a3fab7e3 341 $sw = '(+)';
342 } else {
343 $sw = '(-)';
dcd6f144 344 }
ab3fe577 345 echo '<tr bgcolor="'.$color[0].'"><th colspan="2">'.
346 "<a href=\"options.php?switch=$k\" style=\"text-decoration:none\">".
347 '<b>'.$sw.'</b></a> '.$name.'</th></tr>';
a3fab7e3 348 $act_grp = $k;
349 break;
350 case SMOPT_TYPE_COMMENT:
351 $v = substr( $v, 1, strlen( $v ) - 2 );
352 echo "<tr><td>$name</td><td>".
353 "<b>$v</b>";
354 $newcfg[$k] = "'$v'";
355 if ( isset( $defcfg[$k]['comment'] ) ) {
356 echo ' &nbsp; ' . $defcfg[$k]['comment'];
abd7a3f8 357 }
a3fab7e3 358 echo "</td></tr>\n";
359 break;
360 case SMOPT_TYPE_INTEGER:
ab3fe577 361 /* look for variable $e in POST, fill into $v */
0b5eb034 362 if ( sqgetGlobalVar($e, $new_v, SQ_POST) ) {
363 $v = intval( $new_v );
a3fab7e3 364 $newcfg[$k] = $v;
365 }
366 echo "<tr><td>$name</td><td>".
ab3fe577 367 "<input size=\"10\" name=\"adm_$n\" value=\"$v\" />";
a3fab7e3 368 if ( isset( $defcfg[$k]['comment'] ) ) {
369 echo ' &nbsp; ' . $defcfg[$k]['comment'];
370 }
371 echo "</td></tr>\n";
372 break;
373 case SMOPT_TYPE_NUMLIST:
0b5eb034 374 if ( sqgetGlobalVar($e, $new_v, SQ_POST) ) {
375 $v = $new_v;
a3fab7e3 376 $newcfg[$k] = $v;
377 }
378 echo "<tr><td>$name</td><td>";
379 echo "<select name=\"adm_$n\">";
380 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
381 echo "<option value=\"$kp\"";
382 if ( $kp == $v ) {
ab3fe577 383 echo ' selected="selected"';
a3fab7e3 384 }
385 echo ">$vp</option>";
386 }
387 echo '</select>';
388 if ( isset( $defcfg[$k]['comment'] ) ) {
389 echo ' &nbsp; ' . $defcfg[$k]['comment'];
390 }
391 echo "</td></tr>\n";
392 break;
393 case SMOPT_TYPE_STRLIST:
0b5eb034 394 if ( sqgetGlobalVar($e, $new_v, SQ_POST) ) {
395 $v = '"' . $new_v . '"';
a3fab7e3 396 $newcfg[$k] = $v;
397 }
398 echo "<tr><td>$name</td><td>".
399 "<select name=\"adm_$n\">";
400 foreach ( $defcfg[$k]['posvals'] as $kp => $vp ) {
401 echo "<option value=\"$kp\"";
402 if ( $kp == substr( $v, 1, strlen( $v ) - 2 ) ) {
ab3fe577 403 echo ' selected="selected"';
a3fab7e3 404 }
405 echo ">$vp</option>";
406 }
407 echo '</select>';
408 if ( isset( $defcfg[$k]['comment'] ) ) {
409 echo ' &nbsp; ' . $defcfg[$k]['comment'];
410 }
411 echo "</td></tr>\n";
412 break;
c83b38c1 413
a3fab7e3 414 case SMOPT_TYPE_TEXTAREA:
0b5eb034 415 if ( sqgetGlobalVar($e, $new_v, SQ_POST) ) {
c3d7aa6e 416 $v = '"' . addslashes($new_v) . '"';
a3fab7e3 417 $newcfg[$k] = str_replace( "\n", '', $v );
418 }
c3d7aa6e 419 echo "<tr><td valign=\"top\">$name</td><td>"
420 ."<textarea cols=\"$size\" rows=\"4\" name=\"adm_$n\">"
421 .htmlspecialchars(stripslashes(substr( $v, 1, strlen( $v ) - 2 )))
422 ."</textarea>";
a3fab7e3 423 if ( isset( $defcfg[$k]['comment'] ) ) {
424 echo ' &nbsp; ' . $defcfg[$k]['comment'];
425 }
426 echo "</td></tr>\n";
427 break;
428 case SMOPT_TYPE_STRING:
0b5eb034 429 if ( sqgetGlobalVar($e, $new_v, SQ_POST) ) {
c3d7aa6e 430 $v = '"' . addslashes($new_v) . '"';
a3fab7e3 431 $newcfg[$k] = $v;
432 }
feba1a41 433 if ( $v == '""' && isset( $defcfg[$k]['default'] ) ) {
434 $v = "'" . $defcfg[$k]['default'] . "'";
435 $newcfg[$k] = $v;
436 }
c3d7aa6e 437 echo "<tr><td>$name</td><td>"
438 ."<input size=\"$size\" name=\"adm_$n\" value=\""
439 .htmlspecialchars(stripslashes(substr( $v, 1, strlen( $v ) - 2 )))
440 .'" />';
a3fab7e3 441 if ( isset( $defcfg[$k]['comment'] ) ) {
442 echo ' &nbsp; ' . $defcfg[$k]['comment'];
443 }
444 echo "</td></tr>\n";
445 break;
446 case SMOPT_TYPE_BOOLEAN:
0b5eb034 447 if ( sqgetGlobalVar($e, $new_v, SQ_POST) ) {
448 $v = $new_v;
a3fab7e3 449 $newcfg[$k] = $v;
450 } else {
451 $v = strtoupper( $v );
452 }
453 if ( $v == 'TRUE' ) {
ab3fe577 454 $ct = ' checked="checked"';
a3fab7e3 455 $cf = '';
456 } else {
457 $ct = '';
ab3fe577 458 $cf = ' checked="checked"';
a3fab7e3 459 }
460 echo "<tr><td>$name</td><td>" .
ab3fe577 461 "<input$ct type=\"radio\" name=\"adm_$n\" value=\"TRUE\" />" . _("Yes") .
462 "<input$cf type=\"radio\" name=\"adm_$n\" value=\"FALSE\" />" . _("No");
a3fab7e3 463 if ( isset( $defcfg[$k]['comment'] ) ) {
464 echo ' &nbsp; ' . $defcfg[$k]['comment'];
465 }
466 echo "</td></tr>\n";
467 break;
ab3fe577 468 case SMOPT_TYPE_PATH:
0b5eb034 469 if ( sqgetGlobalVar($e, $new_v, SQ_POST) ) {
f8a1ed5a 470 // FIXME: fix use of $data_dir in $attachment_dir
0b5eb034 471 $v = change_to_sm_path($new_v);
472 $newcfg[$k] = $v;
a28a56da 473 }
474 if ( $v == "''" && isset( $defcfg[$k]['default'] ) ) {
475 $v = change_to_sm_path($defcfg[$k]['default']);
476 $newcfg[$k] = $v;
477 }
ab3fe577 478 echo "<tr><td>$name</td><td>".
479 "<input size=\"$size\" name=\"adm_$n\" value=\"" . change_to_rel_path($v) . '" />';
a28a56da 480 if ( isset( $defcfg[$k]['comment'] ) ) {
481 echo ' &nbsp; ' . $defcfg[$k]['comment'];
482 }
ab3fe577 483 echo "</td></tr>\n";
484 break;
a3fab7e3 485 default:
486 echo "<tr><td>$name</td><td>" .
487 "<b><i>$v</i></b>";
488 if ( isset( $defcfg[$k]['comment'] ) ) {
489 echo ' &nbsp; ' . $defcfg[$k]['comment'];
490 }
491 echo "</td></tr>\n";
6a9acbca 492 }
a3fab7e3 493 }
a3fab7e3 494}
495
1fa5ece1 496/* Special Themes Block */
88cb1b4d 497if ( $colapse['Group7'] == 'off' ) {
a3fab7e3 498 $i = 0;
499 echo '<tr><th>' . _("Theme Name") .
500 '</th><th>' . _("Theme Path") .
501 '</th></tr>';
502 while ( isset( $newcfg["\$theme[$i]['NAME']"] ) ) {
503 $k1 = "\$theme[$i]['NAME']";
504 $e1 = "theme_name_$i";
4cd8ae7d 505 if ( sqgetGlobalVar($e, $v1, SQ_POST) ) {
506 $v1 = '"' . str_replace( '\"', '"', $v1 ) . '"';
b5a29535 507 $v1 = '"' . str_replace( '"', '\"', $v1 ) . '"';
a3fab7e3 508 $newcfg[$k1] = $v1;
a55bb207 509 } else {
a3fab7e3 510 $v1 = $newcfg[$k1];
abd7a3f8 511 }
a3fab7e3 512 $k2 = "\$theme[$i]['PATH']";
513 $e2 = "theme_path_$i";
4cd8ae7d 514 if ( sqgetGlobalVar($e, $v2, SQ_POST) ) {
515 $v2 = change_to_sm_path($v2);
ab3fe577 516 $newcfg[$k2] = $v2;
abd7a3f8 517 } else {
a3fab7e3 518 $v2 = $newcfg[$k2];
abd7a3f8 519 }
a3fab7e3 520 $name = substr( $v1, 1, strlen( $v1 ) - 2 );
a28a56da 521 $path = change_to_rel_path($v2);
a3fab7e3 522 echo '<tr>'.
ab3fe577 523 "<td align=\"right\">$i. <input name=\"$e1\" value=\"$name\" size=\"30\" /></td>".
524 "<td><input name=\"$e2\" value=\"$path\" size=\"40\" /></td>".
a3fab7e3 525 "</tr>\n";
526 $i++;
c83b38c1 527
6a9acbca 528 }
6a9acbca 529}
530
1fa5ece1 531/* Special Plugins Block */
88cb1b4d 532if ( $colapse['Group8'] == 'on' ) {
a3fab7e3 533 $sw = '(+)';
534} else {
535 $sw = '(-)';
6a9acbca 536}
ab3fe577 537echo '<tr bgcolor="'.$color[0].'"><th colspan="2">'.
538 '<a href="options.php?switch=Group8" style="text-decoration:none"><b>'.
539 $sw.'</b></a> '._("Plugins").'</th></tr>';
540
541if ( $colapse['Group8'] == 'off' ) {
542
543 $plugpath = SM_PATH . 'plugins/';
544 if ( file_exists($plugpath) ) {
545 $fd = opendir( $plugpath );
546 $op_plugin = array();
547 $p_count = 0;
548 while (false !== ($file = readdir($fd))) {
549 if ($file != '.' && $file != '..' && $file != 'CVS' && is_dir($plugpath . $file) ) {
550 $op_plugin[] = $file;
551 $p_count++;
c83b38c1 552 }
553 }
ab3fe577 554 closedir($fd);
555 asort( $op_plugin );
556
557 /* Lets get the plugins that are active */
558 $plugins = array();
0b5eb034 559 if ( sqgetGlobalVar('plg', $v, SQ_POST) ) {
ab3fe577 560 foreach ( $op_plugin as $plg ) {
0b5eb034 561 if ( sqgetGlobalVar("plgs_$plg", $v2, SQ_POST) && $v2 == 'on' ) {
ab3fe577 562 $plugins[] = $plg;
563 }
564 }
565 $i = 0;
566 foreach ( $plugins as $plg ) {
567 $k = "\$plugins[$i]";
568 $newcfg[$k] = "'$plg'";
569 $i++;
570 }
571 while ( isset( $newcfg["\$plugins[$i]"] ) ) {
572 $k = "\$plugins[$i]";
573 $newcfg[$k] = '';
574 $i++;
575 }
c83b38c1 576 } else {
ab3fe577 577 $i = 0;
578 while ( isset( $newcfg["\$plugins[$i]"] ) ) {
579 $k = "\$plugins[$i]";
580 $v = $newcfg[$k];
581 $plugins[] = substr( $v, 1, strlen( $v ) - 2 );
582 $i++;
583 }
a3fab7e3 584 }
0d53a854 585 echo '<tr><td colspan="2"><input type="hidden" name="plg" value="on" /><table align="center">';
ab3fe577 586 foreach ( $op_plugin as $plg ) {
587 if ( in_array( $plg, $plugins ) ) {
588 $sw = ' checked="checked"';
589 } else {
590 $sw = '';
591 }
592 echo '<tr><td>';
593 if (file_exists(SM_PATH . "plugins/$plg/README")) {
594 echo "<a href=\"../$plg/README\" target=\"_blank\">$plg</a>";
595 } else {
596 echo $plg;
597 }
598 echo "</td>\n".
599 "<td><input$sw type=\"checkbox\" name=\"plgs_$plg\" /></td>".
600 "</tr>\n";
601 }
0d53a854 602 echo '</table></td></tr>';
ab3fe577 603 } else {
604 echo '<tr><td colspan="2" align="center">'.
605 sprintf(_("Plugin directory could not be found: %s"), $plugpath).
606 "</td></tr>\n";
607 }
6a9acbca 608}
ab3fe577 609echo '<tr bgcolor="'.$color[5].'"><th colspan="2"><input value="'.
610 _("Change Settings").'" type="submit" /><br />'.
611 '<a href="'.SM_PATH.'src/configtest.php" target="_blank">'.
612 _("Test Configuration")."</a></th></tr>\n".
0d53a854 613 '</table></td></tr></table></form>';
abd7a3f8 614
615/*
616 Write the options to the file.
617*/
71e5c245 618
ab3fe577 619if ( $fp = @fopen( $cfgfile, 'w' ) ) {
620 fwrite( $fp, "<?php\n".
b5a29535 621 "/**\n".
622 " * SquirrelMail Configuration File\n".
623 " * Created using the Administrator Plugin\n".
39d3ec89 624 " */\n".
625 "\n".
626 "global \$version;\n" );
b5a29535 627
c05c489a 628 foreach ( $newcfg as $k => $v ) {
781da5d4 629 if ( $k{0} == '$' && $v <> '' || is_int($v)) {
c05c489a 630 if ( substr( $k, 1, 11 ) == 'ldap_server' ) {
b5a29535 631 $v = substr( $v, 0, strlen( $v ) - 1 ) . "\n)";
632 $v = str_replace( 'array(', "array(\n\t", $v );
633 $v = str_replace( "',", "',\n\t", $v );
c05c489a 634 }
0b5eb034 635 /* FIXME: add elseif that reverts plugins[#] to plugins[] */
c05c489a 636 fwrite( $fp, "$k = $v;\n" );
ab3fe577 637 }
0e66bc84 638 }
0b5eb034 639 // close php
c05c489a 640 fwrite( $fp, '?>' );
641 fclose( $fp );
642} else {
78154473 643 echo '<br /><p align="center"><big>'.
c05c489a 644 _("Config file can't be opened. Please check config.php.").
78154473 645 '</big></p>';
abd7a3f8 646}
c3d7aa6e 647
dcc1cc82 648?>
78154473 649</body></html>