#!/usr/local/bin/perl
# edit_global.cgi
# Display a form for editing some kind of global options

require './apache-lib.pl';
&ReadParse();
$conf = &get_config();
@dirs = &editable_directives($in{'type'}, 'global');
$access{'global'}==1 || &error($text{'global_ecannot'});
$access_types{$in{'type'}} ||
	&error($text{'etype'});
&header($text{"type_$in{'type'}"}, "",
	undef, undef, undef, undef, &restart_button());
print "<hr>\n";

print "<form method=post action=save_global.cgi>\n";
print "<input type=hidden name=type value=$in{'type'}>\n";
print "<table border width=100%>\n";
print "<tr $tb> <td><b>",$text{"type_$in{'type'}"},"</b></td> </tr>\n";
print "<tr $cb> <td><table>\n";
&generate_inputs(\@dirs, $conf);
print "</table></td> </tr></table><br>\n";
print "<input type=submit value=\"$text{'save'}\"></form>\n";

if ($in{'type'} == 6) {
	print "<hr>\n";
	print "<h3>$text{'global_mime'}</h3>\n";
	print "$text{'global_mimedesc'}<p>\n";
	print "<a href=\"edit_gmime_type.cgi?file=$mfile\">",
	      "$text{'global_add'}</a><br>\n";
	print "<table border width=100%>\n";
	print "<tr $tb> <td width=25%><b>$text{'global_type'}</b></td>\n";
	print "<td><b>$text{'global_ext'}</b></td>\n";
	print "<td width=25%><b>$text{'global_type'}</b></td>\n";
	print "<td><b>$text{'global_ext'}</b></td> </tr>\n";
	$mfile = &find_directive("TypesConfig", $conf);
	if (!$mfile) { $mfile = $config{'mime_types'}; }
	if (!$mfile) { $mfile = &server_root("etc/mime.types", $conf); }
	if (!-r $mfile) { $mfile = &server_root("conf/mime.types", $conf); }
	$mfile = &server_root($mfile, $conf);
	open(MIME, $mfile);
	$line = 0;
	while(<MIME>) {
		chop;
		s/#.*$//;
		if (/^\s*(\S+)\s*(.*)$/) {
			if (!$sw) { print "<tr $cb>\n"; }
			print "<td><a href=\"edit_gmime_type.cgi?line=$line",
			      "&file=$mfile\">$1</a></td> <td>$2<br></td>\n";
			if ($sw) { print "</tr>\n"; }
			$sw = !$sw;
			}
		$line++;
		}
	close(MIME);
	print "</table>\n";
	print "<a href=\"edit_gmime_type.cgi?file=$mfile\">",
	      "$text{'global_add'}</a><p>\n";
	}

print "<hr>\n";
&footer("", $text{'index_return'});


