#!/usr/local/bin/perl
# dir_index.cgi
# Display a menu of icons for per-directory options

require './apache-lib.pl';
&ReadParse();
($conf, $v) = &get_virtual_config($in{'virt'});
&can_edit_virt($v) || &error($text{'virt_ecannot'});
$d = $conf->[$in{'idx'}];
$desc = &text('dir_header', &dir_name($d), &virtual_name($v));
&ui_print_header($desc, $text{'dir_title'}, "",
	undef, undef, undef, undef, &restart_button());

print "<h3>$text{'dir_title'}</h3>\n";
$sw_icon = { "icon" => "images/show.gif",
	     "name" => $text{'dir_show'},
	     "link" => "show.cgi?virt=$in{'virt'}&idx=$in{'idx'}" };
if ($access{'types'} eq '*') {
	$ed_icon = { "icon" => "images/edit.gif",
		     "name" => $text{'dir_edit'},
		     "link" =>
			"manual_form.cgi?virt=$in{'virt'}&idx=$in{'idx'}" };
	}
&config_icons("directory", "edit_dir.cgi?virt=$in{'virt'}&idx=$in{'idx'}&",
	      $sw_icon, $ed_icon ? ( $ed_icon) : ( ));

print "<hr>\n";
print "<form action=change_dir.cgi>\n";
print "<input type=hidden name=virt value=$in{'virt'}>\n";
print "<input type=hidden name=idx value=$in{'idx'}>\n";
print "<table border>\n";
print "<tr $tb> <td><b>$text{'dir_opts'}</b></td> </tr>\n";
print "<tr $cb> <td><table>\n";
print "<tr> <td><b>$text{'dir_type'}</b></td> <td><select name=type>\n";
foreach $t ($httpd_modules{'core'} >= 2.0 ?
		("Directory", "Files", "Location", "Proxy") :
	    $httpd_modules{'core'} >= 1.2 ? ("Directory", "Files", "Location")
					  : ("Directory", "Location")) {
	printf "<option value=%s %s>$text{'virt_'.$t}\n",
		$t, $d->{'name'} =~ /^$t/ ? "selected" : "";
	}
print "</select></td>\n";
if ($httpd_modules{'core'} >= 1.2) {
	print "<td><b>$text{'dir_regexp'}</b></td>\n";
	$regex = $d->{'words'}->[0] eq "~" || $d->{'name'} =~ /Match/i;
	printf "<td><input type=radio name=regexp value=0 %s> %s\n",
		$regex ? "" : "checked", $text{'dir_exact'};
	printf "<input type=radio name=regexp value=1 %s> %s</td>\n",
		$regex ? "checked" : "", $text{'dir_re'};
	print "</tr>\n";
	}
else { print "<td></td> </tr>\n"; }
print "<tr> <td><b>$text{'dir_path'}</b></td>\n";
printf "<td><input name=path size=40 value=\"%s\"></td>\n",
	$d->{'words'}->[0] eq "~" ? $d->{'words'}->[1] : $d->{'words'}->[0];
print "<td colspan=2 align=right>",
      "<input type=submit value=\"$text{'save'}\">&nbsp;",
      "<input type=submit value=\"$text{'delete'}\" name=delete></td> </tr>\n";
print "</table></td></tr></table></form>\n";

&ui_print_footer("virt_index.cgi?virt=$in{'virt'}", $text{'virt_return'});


