<%doc>

-- VLAN tasks --

</%doc>
%
<%attr>
title        => 'VLAN Tasks' 
</%attr>
%
%
%#######################################################################
%#
%# Args section
%#
%#######################################################################
<%args>
$search           => undef
$search_vlan      => undef
$search_vlangroup => undef
$search_type      => undef
$user             => $ui->get_current_user($r);
$submit           => undef
$show_tasks       => undef
$showheader       => 1
$view             => 'search'
</%args>
%
%
%
%#######################################################################
%#
%# INIT section
%#
%#######################################################################
%
<%init>
my $DEBUG = 0;
print '%ARGS is  <pre>', Dumper(%ARGS), '</pre><br>' if $DEBUG;

$show_tasks = $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 = 'style="display:none"' if ( !$showheader );

my @list;

my $manager = $ui->get_permission_manager($r);
</%init>

<div id="sectiontools" <% $hideheader %>>
  <div class="container">
    <div class="containerheadleft">
        VLAN Tasks
    </div>
    <div class="containerheadright">

%   if ( $manager && $manager->can($user, 'access_admin_section', 'vlan_tasks:new') ){
%       if ( $view eq 'search' ){
            <a href="vlan_tasks.html?view=new">[new]</a>
%       }elsif ( $view eq 'new' ){
            <a href="vlan_tasks.html?view=search">[search]</a>
%       }    
%   }    
%   print_showtaskslink($show_tasks);
    </div>
    <div class="containerbody" id="tasks" style="display:<% ($show_tasks eq "show"?"block":"none") %>">
        <table><tr><td>
 
%    if ( $view eq 'search' ){
        <fieldset class="medium">
             <legend>Search</legend>
             <form action="vlan_tasks.html" method="POST">
                <p>
                <label for="Find">Vlan:</label>
                <input type="text" name="search_vlan" class="txt" value="<% $search_vlan %>"> 
                <input name="submit" value="Find" class="btn" type="submit">
		<input type="hidden" name="search_type" value="vlan">
                </p>
            </form>
            <form action="vlan_tasks.html" method="POST">
                <p>
                <label for="Find">Vlan Group:</label>
                <input type="text" name="search_vlangroup" class="txt" value="<% $search_vlangroup %>"> 
                <input name="submit" value="Find" class="btn" type="submit">
		<input type="hidden" name="search_type" value="vlangroup">
                </p>
            </form>
         </fieldset>
%    }elsif ( $view eq 'new' ){
%       unless ( $manager && $manager->can($user, 'access_admin_section', 'vlan_tasks:new') ){
%	    $m->comp('/generic/error.mhtml', error=>"You do not have permission to do this");
%       }
        <fieldset class="medium">
            <legend>Add Vlan Group</legend>
            <form action="vlan.html" method="POST">
                <p>
                <label for="new">Name:</label>
                <input type="text" name="name" class="txt" value="">
                </p>
		<p>
                <label for="new">Start-End:</label>
                <input type="text" name="start" class="shorttxt" value="">
                <input type="text" name="end" class="shorttxt" value=""> 
                <input name="submit" value="Add" class="btn" type="submit">
                <input type="hidden" name="_action" value="INSERT">
                </p>
            </form>
        </fieldset>
%     }

        </td></tr></table>
    </div> <!-- close containerbody -->
  </div> <!-- close container -->
</div> <!-- close sectiontools -->


<%perl>
#######################################################################################
# Search
#
#######################################################################################

if ( $submit eq 'Find' ){
    my %idx;
    if ( $search_type eq 'vlan' ){
	$search = $search_vlan;
	# Remove trailing and leading spaces
	$search = $ui->rem_lt_sp($search);
	$search ||= '*';
        map { $idx{$_->id} = $_ } Vlan->search_like(vid         => $search);
        map { $idx{$_->id} = $_ } Vlan->search_like(name        => $search);
        map { $idx{$_->id} = $_ } Vlan->search_like(description => $search);
	
    }elsif ( $search_type eq 'vlangroup' ) {
	$search = $search_vlangroup;
	# Remove trailing and leading spaces
	$search = $ui->rem_lt_sp($search);
	$search ||= '*';
        map { $idx{$_->id} = $_ } VlanGroup->search_like(name        => $search);
        map { $idx{$_->id} = $_ } VlanGroup->search_like(description => $search);
    }
    @list = values %idx;
}
</%perl>

% if ( $search ){
%     if ( @list ){
	 <div class="container">
           <div class="containerhead">
              Query <em><% $search %></em> returned: <% scalar(@list) %> matches
           </div>
           <div class="containerbody">
               <& /generic/sortresults.mhtml, object=>\@list, page=>'view.html', withedit=>0  &>
          </div>
       </div>
%     }else{
%         $m->comp('/generic/no_search_results.html', search=>$search);
%     }
% }
