#!/usr/local/bin/perl
# user_filesys.cgi
# List all filesystems for which some user has quotas

require './quota-lib.pl';
&ReadParse();
$u = $in{'user'};
&can_edit_user($u) ||
	&error(&text('ufilesys_ecannot', $u));
&header($text{'ufilesys_title'}, "", "user_filesys");
print "<hr>\n";

foreach $f (&list_filesystems()) {
	if ($f->[4]%2 && $f->[5] && &can_edit_filesys($f->[0])) {
		push(@fslist, $f->[0]);
		$fslist{$f->[0]}++;
		}
	}

$n = &user_filesystems($u);
if ($n) {
	print "<h3>",&text('ufilesys_all', &html_escape($u)),"</h3>\n";
	print "<table border width=100%>\n";
	print "<tr $tb> <td><br></td>\n";
	print "<td colspan=3 align=center><b>$text{'ufilesys_blocks'}</b></td>\n";
	print "<td colspan=3 align=center><b>$text{'ufilesys_files'}</b></td> </tr>\n";
	print "<tr $tb> <td><b>$text{'ufilesys_fs'}</b></td>\n";
	print "<td><b>$text{'ufilesys_used'}</b></td> <td><b>$text{'ufilesys_soft'}</b></td>\n";
	print "<td><b>$text{'ufilesys_hard'}</b></td>\n";
	print "<td><b>$text{'ufilesys_used'}</b></td> <td><b>$text{'ufilesys_soft'}</b></td>\n";
	print "<td><b>$text{'ufilesys_hard'}</b></td> </tr>\n";
	for($i=0; $i<$n; $i++) {
		$f = $filesys{$i,'filesys'};
		print "<tr $cb>\n";
		if ($fslist{$f}) {
			print "<td><a href=\"edit_user_quota.cgi?filesys=$f&user=$u&source=1\">$f</a></td>\n";
			}
		else { print "<td>$f</td>\n"; }
		print "<td>$filesys{$i,'ublocks'}</td>\n";
		&print_limit($filesys{$i,'sblocks'});
		&print_limit($filesys{$i,'hblocks'});
		print "<td>$filesys{$i,'ufiles'}</td>\n";
		&print_limit($filesys{$i,'sfiles'});
		&print_limit($filesys{$i,'hfiles'});
		print "</tr>\n";
		}
	print "</table><br>\n";
	}
else {
	print "<b>",&text('ufilesys_nouquota', $u),"</b><p>\n";
	}

print "<table width=100%><tr>\n";
print "<form action=edit_user_quota.cgi>\n";
print "<input type=hidden name=user value=\"$u\">\n";
print "<input type=hidden name=source value=1>\n";
print "<td align=left><input type=submit value=\"$text{'ufilesys_edit'}\">\n";
print "<select name=filesys>\n";
foreach $f (@fslist) { print "<option>$f\n"; }
print "</select></td></form>\n";

if ($access{'filesys'} eq "*") {
	print "<form action=copy_user_form.cgi>\n";
	print "<input type=hidden name=user value=\"$u\">\n";
	print "<td align=right><input type=submit value=\"$text{'ufilesys_copy'}\">\n";
	print "</td></form>\n";
	}
print "</tr></table>\n";

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

sub print_limit
{
if ($_[0] == 0) { print "<td>$text{'quota_unlimited'}</td>\n"; }
else { print "<td>$_[0]</td>\n"; }
}

