<%doc>

 Management Functions for end users

</%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 = "USER_MANAGEMENT_PAGE";
my $SECTION = "Management";
</%shared>

<%init>

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

my $caller_args = $m->caller_args(-1);

if (exists($caller_args->{page})){
    $user->setAttribute($r, "$PAGE_ATTRIBUTE", $caller_args->{page});
}
my $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"';
}
</%init>
%
%
%# Methods can be called externally.
<%method .section_meta_data>
    <%doc>
        Returns the meta data used to generate this section\'s header in section1.mhtml
    </%doc>
    <%init>
        return {  
	    section      => $SECTION,
	    page         => 'user_management/', 
	    title        => 'Management',
	    attribute    => $PAGE_ATTRIBUTE,
	    sub_sections => [
		{ section => 'HOSTINFO', title => 'DNS/DHCP' },
		{ section => 'DEVICE',   title => 'Devices' },
		{ section => 'CONTACTS', title => 'Contacts' },
	    ]
        };
    </%init>
</%method>

<%perl>

if (($page eq "HOSTINFO" || $page eq "")  && $m->request_comp->name ne "hostinfo_tasks.html" ) {

    $m->comp('hostinfo_tasks.html', user=>$user, showheader=>$showheader);

}elsif ( $page eq "DEVICE" && $m->request_comp->name ne "device_tasks.html" ) {

    $m->comp('device_tasks.html', user=>$user, showheader=>$showheader);

} elsif ($page eq "CONTACTS" && $m->request_comp->name ne "contact_tasks.html" ) {

    $m->comp('contacts_tasks.html', user=>$user, showheader=>$showheader);

}

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

