package ISPMan::Utils;

use strict;
use vars qw($AUTOLOAD $VERSION @ISA @EXPORT @EXPORT_OK $Config);

require Exporter;

@ISA = qw(ISPMan Exporter AutoLoader);
@EXPORT = qw(
cat 
getTemplate 
refreshSignal
menu
start
printHeaders
ispman
);
$VERSION = '0.01';

use ISPMan::Config;
$Config=ISPMan::Config->new();
use ISPMan::Log;





sub getTemplate {
   my $self=shift;
   my ($file)=@_;
   
   my $source=($file=~/^\//)?$file:"./tmpl/$file";
   
   log_event("opening $source as template");

   my $template= new Text::Template(
         DELIMITERS => ['<perl>', '</perl>'],
                     TYPE => "FILE",  
                     SOURCE => $source,
   );
   return $template;
}

sub cat {
   my $file=shift;
   return unless $file;
   open "F", $file  || die "Cant open $file\n";
   my $text=join "", <F>;
   close("F");
   return $text;
}

sub refreshSignal {
   my $self=shift;
   return unless $ENV{'HTTP_USER_AGENT'};

   return qq|
   <script>
   top.main_menu.reloadApplet();
   </script>
   |;
}


sub printHeaders {
   my $self=shift;
   my $template=$self->getTemplate("headers.tmpl");
   print $template->fill_in();
}


sub start {
   my $self=shift;
   my $template=$self->getTemplate("index.tmpl");
   print $template->fill_in();

}

sub menu {
   my $self=shift;
   my $template=$self->getTemplate("menu.tmpl");
   print $template->fill_in(PACKAGE => "ISPMan");

}


sub ispman {
   my $self=shift;
   my $template=$self->getTemplate("ispman.tmpl");
   print $template->fill_in();

}


1;
__END__
# Below is the stub of documentation for your module. You better edit it!

=head1 NAME

ISPMan::Utils - Perl extension for blah blah blah

=head1 SYNOPSIS

  use ISPMan::Utils;
  blah blah blah

=head1 DESCRIPTION

Stub documentation for ISPMan::Utils was created by h2xs. It looks like the
author of the extension was negligent enough to leave the stub
unedited.

Blah blah blah.

=head1 AUTHOR

A. U. Thor, a.u.thor@a.galaxy.far.far.away

=head1 SEE ALSO

perl(1).

=cut
