#!/usr/bin/perl
#addlink.cgi - add a link to the link file...
#read parameters.
#Add site if needed.
#build lists of sites -> 2 lists, one of categories for select, one of sites.
use jo;
use CGI;
$query = new CGI;
$query->import_names('R');
print "Content-type: text/html\n\n";
my %links;
my %categories;
load_link_hash();
foreach $k (sort keys %links) {
foreach $k2 (sort keys %{$links{$k}} ) {
#print STDERR "$k:$k2:$links{$k}{$k2}\n";
}
}
##### WRITE OUT LINK - if it exists.
if (length($R::url) > 10) {
#fix category...
my $category = $R::category_input || $R::category_select || 'none';
$query->delete('category_input');
$query->delete('category_select');
$query->append(-name=>'category',-values=>[$category]);
# $R::email =~ s/\s|,//g;
open OUT, ">>../data/sitelist.txt" or print "Sorry...can't save your changes by writing to sitelist.txt |$!|";
print OUT "\n";
my %this_link;
foreach $param ($query->param) {
my $value = $query->param($param);
print_tag($param, $value);
$this_link{$param} = $value;
}
#add the values from this site to the hash of all sites.
foreach $k (keys %this_link) {
$links{$this_link{url}}{$k} = $this_link{$k};
}
#add this category.
my $lclink = lc $this_link{'category'} ;
$categories{$lclink} = $this_link{'category'}++;
print OUT "\n\n\n";
close OUT;
} #writing to file...
close OUT;
#now build the page?
my $list_list;
my %cat;
#### BUILD LINK_LIST -> how it will look.
#walk and build by category, then walk and format.
my %cformat;
foreach $k (sort keys %links) {
# $cat{$links{$k}{'category'}}{$k}{$links{$k}{
my $link;
$link .= "
";
}
#my $page = read_links();
#### Get Header...
open TEMP, "../site/links.txt" or die "Can't open header template: $!\n";
my $template;
{local $/; undef $/; $template = ;}
close TEMP;
#build catlist
my $catlist;
foreach my $k (sort keys %categories) {
$catlist .= "