#!/usr/local/bin/perl
# config.cgi
# Display a form for editing the configuration of a module.
# Each module has a number of configurable parameters (stored in the file
# config.txt in the module directory). Descriptions and possible values for
# each option are stored in the file config.info in the module directory.
# Each line of config.info looks like
# name=desc,type[,options]
#  desc - A description of the parameter
#  type - Possible types (and options) are
#	0 - Free text
#	1 - One of many (options are possibilities)
#	2 - Many of many (options are possibilities)
#	3 - Optional free text
#	4 - Like 1, but uses a pulldown menu
#	5 - User name
#	6 - Group name
#	7 - Directory
#	8 - File
#	9 - Multiline text
#	10 - Like 1, but with free text option
#	11 - Section header
#	12 - Password free text
#	13 - Like 2, but uses a list box

require './web-lib.pl';
require './config-lib.pl';
&init_config();
$m = $ARGV[0];
%access = &get_module_acl(undef, $m);
$access{'noconfig'} &&
	&error($text{'config_ecannot'});
%module_info = &get_module_info($m);
&header($text{'config_title'}, "", undef, 0, 1);
print "<center><font size=+2>",&text('config_dir', $module_info{'desc'}),
      "</font></center>\n";
print "<hr>\n";

print "<form action=\"config_save.cgi\" method=post>\n";
print "<input type=hidden name=module value=\"$m\">\n";
print "<table border>\n";
print "<tr $tb> <td><b>",&text('config_header', $module_info{'desc'}),
      "</b></td> </tr>\n";
print "<tr $cb> <td><table width=100%>\n";
&read_file("$config_directory/$m/config", \%config);

if (-r "$m/config_info.pl") {
	# Module has a custom config editor
	&foreign_require($m, "config_info.pl");
	&foreign_call($m, "config_form", \%config);
	}
else {
	# Use config.info to create config inputs
	&generate_config(\%config, "$m/config.info");
	}
print "</table></td></tr></table>\n";
print "<input type=submit value=\"$text{'save'}\"></form>\n";
print "<hr>\n";
&footer("/$m", $text{'index'});

