function fileclick(f, d)
{
curr = top.frames[1].document.forms[0].elements[1].value;
if (curr == f) {
// Double-click! Enter directory or select file
if (d) {
// Enter this directory
location = "chooser.cgi?frame=1&add=$add&chroot=$uchroot&type=$utype&file="+f+"/";
}
else {
// Select this file and close the window
if ($add == 0) {
top.opener.ifield.value = f;
}
else {
if (top.opener.ifield.value != "") {
top.opener.ifield.value += "\\n";
}
top.opener.ifield.value += f;
}
top.close();
}
}
else {
top.frames[1].document.forms[0].elements[1].value = f;
}
}
function parentdir(p)
{
top.frames[1].document.forms[0].elements[1].value = p;
location = "chooser.cgi?frame=1&chroot=$uchroot&type=$utype&file="+p;
}
EOF
print "";
print &ui_textbox("filter",$text{'ui_filterbox'}, 50, 0, undef,"style='width:100%;color:#aaa;' onkeyup=\"filter_match(this.value,'row',true);\" onfocus=\"if (this.value == '".$text{'ui_filterbox'}."') {this.value = '';this.style.color='#000';}\" onblur=\"if (this.value == '') {this.value = '".$text{'ui_filterbox'}."';this.style.color='#aaa';}\"");
print &ui_hr("style='width:100%;'")."
";
print "",&text('chooser_dir', &html_escape($dir)),"\n";
$ok = opendir(DIR, $in{'chroot'}.$dir);
&popup_error(&text('chooser_eopen', "$!")) if (!$ok && !$in{'chroot'});
print &ui_columns_start(undef, 100);
my $cnt = 0;
foreach $f (sort { $a cmp $b } readdir(DIR)) {
$path = "$in{'chroot'}$dir$f";
if ($f eq ".") { next; }
if ($f eq ".." && ($dir eq "/" || $dir eq $topdir.'/')) { next; }
if ($f =~ /^\./ && $f ne ".." && $access{'nodot'}) { next; }
if (!(-d $path) && $in{'type'} == 1) { next; }
@st = stat($path);
$isdir = 0; undef($icon);
if (-d $path) { $icon = "dir.gif"; $isdir = 1; }
elsif ($path =~ /\.([^\.\/]+)$/) { $icon = $icon_map{$1}; }
if (!$icon) { $icon = "unknown.gif"; }
if ($f eq "..") {
$dir =~ /^(.*\/)[^\/]+\/$/;
$link = "";
}
else {
$link = "";
}
local @cols;
push(@cols, "$link
");
push(@cols, "$link".&html_escape($f)."");
push(@cols, &nice_size($st[7]));
@tm = localtime($st[9]);
push(@cols, sprintf "%.2d/%s/%.4d",
$tm[3], $text{'smonth_'.($tm[4]+1)}, $tm[5]+1900);
push(@cols, sprintf "%.2d:%.2d", $tm[2], $tm[1]);
print &ui_columns_row(\@cols);
$cnt++;
}
closedir(DIR);
print &ui_columns_end();
if ( $cnt >= 10 ) {
print "";
print "";
}
&popup_footer();
}
elsif ($in{'frame'} == 2) {
# Current file and OK/cancel buttons
&popup_header();
print <
function filechosen()
{
if ($add == 0) {
top.opener.ifield.value = document.forms[0].path.value;
}
else {
if (top.opener.ifield.value != "") {
top.opener.ifield.value += "\\n";
}
top.opener.ifield.value += document.forms[0].path.value;
}
top.close();
}
EOF
print &ui_form_start(undef, undef, undef,
"onSubmit='filechosen(); return false'");
print &ui_table_start(undef, "width=100%", 2);
print &ui_table_row(&ui_submit($text{'chooser_ok'}),
&ui_textbox("path", $dir.$file, 45, 0, undef,
"style='width:100%'"), 1,["width=5% valign=middle nowrap","valign=middle width=95%"]);
print &ui_table_end();
print &ui_form_end();
&popup_footer();
}
# allowed_dir(dir)
# Returns 1 if some directory should be listable
sub allowed_dir
{
local ($dir) = @_;
return 1 if ($rootdir eq "" || $rootdir eq "/" || $rootdir eq "c:");
foreach my $allowed ($rootdir, split(/\t+/, $access{'otherdirs'})) {
return 1 if (&is_under_directory($allowed, $dir));
}
return 0;
}