#!/usr/bin/perl -w
# DirPorts v0.5 
# maindir.pl v0.5
# By Gianmarco Giovannelli (gmarco@giovannelli.it)
# an happy survivour of the :
# P-Day, C-Day, B-Day, E-Day, R-Day, lib.blabla-Day ....

 
use CGI qw(:standard);  
require "addon.pl";

$timerstart= (times)[0];
$counter = 0;

foreach $file (<$basepath/*>) {
  if (-d $file && $file ne "$basepath/templates" && $file !~ /$ignoredirs/i){
    $basename=basename($file);
    push(@dirs,$basename);
    $desc{$basename}=`cat $file/pkg/COMMENT`;
    $fullpath{$basename}=$file;
  }
}


print header(), start_html(-title => "Ports Collection", -bgcolor=>$bgcolor);
print h1("The FreeBSD Ports Collection"),"\n";
print basefont({-size=>$bfs, -face=>$fontface}),hr();
print p("You are at the top of the ports tree."),"\n";
print p("For information on how to use the ports tree please look at 'The Ports Collection' section of the FreeBSD handbook ",
	a({href=>'file://localhost/usr/share/doc/handbook/handbook.html'},"on your own FreeBSD machine" ), "or",
	a({href=>'http://www.freebsd.org/handbook/ports.html'}, "at the FreeBSD web site"),),"\n";

print p("Also, if you would like to contribute a new port or fix an existing one, ",
	"please refer to the", a({href=>'http://www.freebsd.org/handbook/porting.html'},'Porting Guidelines'),
	" a section of the most current handbook."),"\n";
print p(start_form(-action=>"portdir.pl"),
	"You can", submit("Search"),
	" with ", textfield(-name=>"querystring", -size=>15),
	" in field ",popup_menu(-name=>"qfield",-value=>["name\, path and desc","mantainer"]),end_form(),),"\n";
print p("There are ".($#dirs+1)." active categories.\n");
print hr(),"\n";

print table({-bgcolor=>"$bgcolor", -border=>"$tableborder",-width=>"95%", -align=>"CENTER"}),"\n";
print Tr(th({-align=>"left"},['Name','M.Time','Description']));

foreach $entry (@dirs){
    print Tr();
    print td({-align=>"LEFT", -colspan=>"1", -bgcolor=>"$bgcolor", -width=>"15%"},
	     font({ -size=>"$bfs", -face=>"$fontface",-color=>"$fontcolor"}),
	     a({href=>"./portdir.pl?dirname=$entry"},$entry)),"\n";

    print td({-align=>"LEFT", -colspan=>"1", -bgcolor=>"$bgcolor", -width=>"15%"},
	     font({ -size=>"$bfs", -face=>"$fontface",-color=>"$fontcolor"}),
	     modate($fullpath{$entry})."\n");

    if (-M   $fullpath{$entry} <= $daysarrived){ 
      print td({-align=>"LEFT", -colspan=>"1", -bgcolor=>"$bgcolor", -width=>"70%"},
	       font({ -size=>"$dfs", -face=>"$fontface",-color=>"$fontcolor"}),b($desc{$entry})."\n");
    } else {
      print td({-align=>"LEFT", -colspan=>"1", -width=>"65%", -bgcolor=>"$bgcolor", -width=>"70%"},
	       font({ -size=>"$dfs", -face=>"$fontface",-color=>"$fontcolor"}),$desc{$entry}."\n");
    }
}

print "</TABLE>\n";
print p(),hr(),p({ -align=>"right"},sprintf("Page generation time : %.2f secs",(times)[0]-$timerstart));
print end_html();
