<%doc>

 Network Management Functions

</%doc>

<%args>
$user => $ui->get_current_user($r);
$showheader => 1
</%args>

<%attr>
title   => 'Management' 
# This is used by the toplevel autohandler to determine the section.
# Since attributes aren't inherited (but shouldn't they be ...) we have
# to also specify this in the dhandler
section => "Management" # $SECTION
</%attr>

<%shared>
my $PAGE_ATTRIBUTE = "MANAGEMENT_PAGE";
my $SECTION = "Management";
</%shared>

<%init>

my $DEBUG = 0;
print '%ARGS is  <pre>', Dumper(%ARGS), '</pre><br>' if $DEBUG;

my $page;

my $manager = $ui->get_permission_manager($r);
if ( $manager && $manager->can($user, "access_section", 'management') ){
    
    my $caller_args = $m->caller_args(-1);
    if (exists($caller_args->{page})){
	$user->setAttribute($r, "$PAGE_ATTRIBUTE", $caller_args->{page});
    }
    $page = $user->getAttribute("$PAGE_ATTRIBUTE");
    
    if (exists($caller_args->{tasks})){
	$user->setAttribute($r, "SHOW_TASKS", $caller_args->{tasks});
    }
    my $show_tasks = $user->getAttribute("SHOW_TASKS");
    if ($show_tasks eq "") {
	$user->setAttribute($r, "SHOW_TASKS", "show");
	$show_tasks = "show";
    }
    *print_showtaskslink = $m->comp('SELF:.sub_print_showtaskslink'); 
    
    my $hideheader;
    if( !$showheader ) {
	$hideheader = 'style="display:none"';
    }

    if ( ($page eq "DEVICE" || $page eq "") && $m->request_comp->name ne "device_tasks.html" ) {
	$m->comp('device_tasks.html', user=>$user, showheader=>$showheader);
    } elsif ( $page eq "ADDRESS" && $m->request_comp->name ne "address_tasks.html" ) {
	$m->comp('address_tasks.html', user=>$user, showheader=>$showheader);
    } elsif ($page eq "VLANS" && $m->request_comp->name ne "vlan_tasks.html" ) {
	$m->comp('vlan_tasks.html', user=>$user, showheader=>$showheader);
    } elsif ($page eq "HOSTS" && $m->request_comp->name ne "host_tasks.html" ) {
	$m->comp('host_tasks.html', user=>$user, showheader=>$showheader);
    } elsif ($page eq "ZONES" && $m->request_comp->name ne "zone_tasks.html" ) {
	$m->comp('zone_tasks.html', user=>$user, showheader=>$showheader);
    } elsif ($page eq "DHCP" && $m->request_comp->name ne "dhcp_tasks.html" ) {
	$m->comp('dhcp_tasks.html', user=>$user, showheader=>$showheader);
    } elsif ($page eq "ASSETS" && $m->request_comp->name ne "asset_tasks.html"){
        $m->comp('asset_tasks.html', user=>$user, showheader=>$showheader, %ARGS);	
    }
}else{
    # We intentionally do not call the error page here so that some components
    # in this directory can be executed if called from within unprivileged areas
}
</%init>

<%perl>

if ( my $next = $m->fetch_next ){
    if ( $page ){
	$m->call_next(page => $page);
    }else{
	$m->call_next();
    }
}
</%perl>


%# Methods can be called externally.
<%method .section_meta_data>
    <%doc>
        Returns the meta data used to generate this section\'s header in menu_admin.mhtml
    </%doc>
    <%init>
        return {  
	    section      => $SECTION,
	    page         => 'management/', 
	    title        => 'Management',
	    attribute    => $PAGE_ATTRIBUTE,
	    sub_sections => [
		{ section => 'DEVICE',   title => 'Devices' },
                { section => 'ASSETS',    title => 'Assets' },
		{ section => 'VLANS',    title => 'VLANs' },
		{ section => 'ADDRESS',  title => 'Address Space' },
		{ section => 'HOSTS',    title => 'DNS Records' },
		{ section => 'ZONES',    title => 'DNS Zones' },
		{ section => 'DHCP',     title => 'DHCP' },
	    ]
        };
    </%init>
</%method>


