<%doc>

Works as a wrapper for the different sections

</%doc>
<%attr>
title      => "Network Documentation Tool"
section    => "Main"
showheader => 1
</%attr>
%
<%args>
$onload     => ""
$showheader => undef;
</%args>
%
<%init>
my $DEBUG = 0;
print '%ARGS is  <pre>', Dumper(%ARGS), '</pre><br>' if $DEBUG;
my $title      = $m->base_comp->attr('title')   || "Network Documentation Tool";
my $section    = $m->base_comp->attr('section') || "Main";

my $user = $ui->get_current_user($r);

    
if ( my $show = $m->base_comp->attr_if_exists('showheader') ){
    $showheader = defined($showheader) ?  $showheader : $show;
}
my $meta_refresh = 0;
$meta_refresh = $m->base_comp->attr_if_exists('meta_refresh');

print "base comp: ", $m->base_comp->name, "<br>"  if $DEBUG;
print "req comp: ", $m->request_comp->name, "<br>"  if $DEBUG;


my $rest_page = 0;
if($m->request_comp->dir_path eq '/rest'){
	$rest_page = 1;
}

</%init>

%if(!$rest_page){
	<& header.mhtml,   title => $title, section => $section, user => $user, showheader=>$showheader, onload=>$onload, meta_refresh=>$meta_refresh &>
%}
<%perl>
# Set user type if needed
if ( defined $user && !defined $user->getAttribute('USER_TYPE') ){
    eval {
	    $ui->set_user_type($r, $user);
    };
    if ( my $e = $@ ){
        if($e =~ /not found in Person table/){
	        #we don't want to give the user too 
            #much information about the underlying 
            #database so lets clean up this message
	        $e = "Sorry but we could not retrieve your permission information"; 
        }
        $user->logout($r);	    
        $m->comp('/generic/error.mhtml', error=>$e);
    }
}
</%perl>

%# Admin/Operator menu
% if ( defined $user && (! $rest_page)){
%     if ( $user->getAttribute('USER_TYPE') eq 'Admin' || $user->getAttribute('USER_TYPE') eq 'Operator') {
          <& menu_admin.mhtml, title => $title, section => $section, user => $user, showheader=>$showheader &>

%     }elsif ( $user->getAttribute('USER_TYPE') eq 'User' ){
          <& menu_user.mhtml, title => $title, section => $section, user => $user, showheader=>$showheader &>
%     }else{
%        #error here    
%     }
% }
%if(! $rest_page){
	<div id="content">
%}
% $m->call_next(showheader => $showheader);
%if(! $rest_page){
	</div> <!-- close content -->
%}
%if(! $rest_page){
	<& footer.mhtml &>
%}
<%method .section_dhandler>
    <%doc>
    Defines how section (e.g. /management) dhandlers dhandle.
    This functionality is defined here so that the identical dhandlers
    in the sections won\'t have to be changed if the way section
    dhandling works changes.
    </%doc>

    <%args>
    # NOTE: You *MUST* pass your %ARGS hash when calling this method,
    # so that the post/get arguments make it to the requested page.
    #
    # The value of $m->dhandler_arg in the dhandler:
    $request 
    </%args>

    <%init>
    # The relative path to the directory storing the generic/utility
    # pages, e.g. device.html.  

    my $generic_pages_path = "./generic";
    my $comp_path = "$generic_pages_path/$request";

    if ( $m->comp_exists($comp_path) ){
        # $m->dhandler_arg returns the path portion after "./", but not
        # the get/post args (e.g. ?foo=bar&baz=fraz).  The args are passed
        # along in %ARGS.
        $m->comp( $comp_path, %ARGS );
    }else{
	$r->content_type('text/html');
        $m->comp('/generic/error.mhtml', error => "The requested page: \"$request\" does not exist");
    }
    </%init>
</%method>


<%method .sub_print_showtaskslink>
    <%doc>
    This is used in multiple places.
    </%doc>
    <%init> 
    return sub {
	my $show_tasks = $_[0];
	my $request_vars = "";
	my $caller_args = $m->caller_args(-1);
	while( my($key, $value) = each(%$caller_args) ) {
	    if( !($key eq "tasks") ) {
		$request_vars .= "$key=$value&";
	    }
	}
	print '<a href="javascript:toggleTasks()" id="tasks_link">['.($show_tasks eq "show"?"hide":"show").']</a>';
    };
    </%init>
</%method>
