# -------------------------------------------------------------------
#  flo::plugin::explorer::Public
# -------------------------------------------------------------------
#
#  flo::plugin::Explorer is the default plugin. The public interface 
#  should let visitors explore the database categories and articles, 
#  whilst the admin interface for editors provides an integrated menu
#  for modifying these categories and articles.
#
#  Author: Jean-Michel Hiver (jhiver@cisedi.com)
#  Copyright MKDoc Holding Ltd.
#
# -------------------------------------------------------------------
package flo::plugin::explorer::Public;
use flo::Standard;
use flo::Template;
use flo::Editor;
use lib::sql::Table;
use lib::cgi::CGI;
use lib::Exception;
use lib::Config;
use flo::HTTP::Header;
use flo::Record::Contributor;
use flo::Record::Document;
use flo::Record::Redirect;
use flo::Object;
use vars qw /@ISA/;
@ISA = qw /flo::Object/;
use strict;


##
# __PACKAGE__->main;
# ------------------
#  Displays a given document
##
sub main
{
    my $class = shift;
    
    my $document_table = lib::sql::Table->table ('Document');
    my $document = $document_table->get ( Full_Path => path_info );
    my $cgi = lib::cgi::CGI->get;
    my $hash = {};
    $hash->{Document} = $document;
    
    my $cgix = $cgi->new;
    foreach ($cgix->param) { $cgix->delete ($_) }
    $hash->{URI} = { Action => $cgix->self_url };
    
    
    if (defined $hash->{Document})
    {
	my $editor = new flo::Editor;
	$editor->parse_xml ($hash->{Document}->{Body});
	$hash->{Session} = {};
	
      flo::HTTP::Header->out
	  ( new flo::Template ( file => template ('explorer/document/' . $document->Template, $document->Lang),
				hash => $hash ) );
    }
    else { throw (new lib::Exception (info => path_info)) }
}


1;
