#!/usr/local/bin/perl
# emerge_find.cgi
# Show a search form for emerge

require './software-lib.pl';
&ReadParse();

&header();
print <<EOF;
<script>
function sel(m)
{
window.opener.ifield.value = m;
window.close();
return false;
}
</script>
EOF

print "<form action=emerge_find.cgi>\n";
print "<input type=submit value='$text{'emerge_search'}'>\n";
print "<input name=search size=20 value='$in{'search'}'>\n";
print "</form><hr>\n";

if ($in{'search'}) {
	$n = &package_search($in{'search'}, 1);
	if ($n) {
		print "<table border width=100%>\n";
		print "<tr $tb> <td><b>$text{'emerge_pack'}</b></td> ",
		      "<td><b>$text{'emerge_version'}</b></td> ",
		      "<td><b>$text{'emerge_desc'}</b></td> </tr>\n";
		for($i=0; $i<$n; $i++) {
			print "<tr $cb>\n";
			print "<td><a href='' onClick='sel(\"$packages{$i,'name'}\")'>$packages{$i,'name'}</td>\n";
			print "<td>$packages{$i,'version'}</td>\n";
			print "<td>$packages{$i,'desc'}</td>\n";
			print "</tr>\n";
			}
		print "</table>\n";
		}
	else {
		print "<b>$text{'emerge_none'}</b><p>\n";
		}
	}

&footer();

