#!/usr/local/bin/perl
# list_hosts.cgi
# Display host-level permissions

require './mysql-lib.pl';
$access{'perms'} || &error($text{'perms_ecannot'});
&header($text{'hosts_title'}, "");
print "<hr>\n";

$d = &execute_sql($master_db, "select * from host order by host");
if (@{$d->{'data'}}) {
	print "<a href='edit_host.cgi?new=1'>$text{'hosts_add'}</a> <br>\n";
	print "<table border>\n";
	print "<tr $tb> <td><b>$text{'hosts_db'}</b></td>\n",
	      "<td><b>$text{'hosts_host'}</b></td>\n",
	      "<td><b>$text{'hosts_perms'}</b></td> </tr>\n";
	}
else {
	print "<p> <b>$text{'hosts_empty'}</b> <p>\n";
	}
$i = -1;
foreach $u (@{$d->{'data'}}) {
	$i++;
	next if ($access{'perms'} == 2 && !&can_edit_db($u->[1]));
	print "<tr $cb>\n";
	print "<td><a href='edit_host.cgi?idx=$i'>",
		$u->[1] eq '%' || $u->[1] eq '' ? $text{'hosts_any'}
			: &html_escape($u->[1]), "</a></td>\n";
	print "<td>",$u->[0] eq '%' || $u->[0] eq '' ? $text{'hosts_any'}
				     	: &html_escape($u->[0]),"</td>\n";
	local @priv;
	for($j=2; $j<=11; $j++) {
		push(@priv, $text{"hosts_priv$j"}) if ($u->[$j] eq 'Y');
		}
	printf "<td>%s</td>\n",
		scalar(@priv) == 10 ? $text{'hosts_all'} :
		!@priv ? $text{'hosts_none'} : join("&nbsp;| ", @priv);
	print "</tr>\n";
	}
print "</table>\n" if (@{$d->{'data'}});
print "<a href='edit_host.cgi?new=1'>$text{'hosts_add'}</a> <p>\n";

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

