#!/usr/bin/perl

# tree-sites.cgi - Example of ODP:: (Version 0.01)
# Copyright (C)2002 Richard P. Fuller <rpfuller@rpfuller.org>

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

use CGI qw(:standard);
use ODP::Tree;

if (!param('cat'))
{
   print header().start_html('Syntax...')."Syntax: tree-sites.cgi?cat=<category>".end_html;
}
else
{
   print header();
   print start_html('Tree');

   my $tree = new ODP::Tree(param('cat'));
   if ($tree->{'root'}->sitecount > 100)
   {
      print 'Test limit, 100 sites.';
      print end_html;
      exit;
   }

   $tree->expand_fully;
   foreach my $cat ($tree->linearlist)
   {
      print "<h4>$cat->{'category'} (".$cat->sitecount.")</h4>";
      foreach my $site ($cat->sites)
      {
         print "<li>$site->{'url'} <a href=\"".$site->editurl."\"><small>[EDIT]</small></a>";
      }
   }

   print end_html;
}