<& SELF:matches &>

Port Search

<%args> $port => '' $dates => 1 $specific => '' <%shared> my $matches = []; my $Node_IP_Seen = {}; my $domain = $netdisco::CONFIG{domain}; my ($arg_port); my $odd=0; my $ran_query = 0; my @search = (); my $ouis = undef; my @cols = (); <%init> # Pass the form argument to the global for <%methods> $arg_port = $port; # ----------------- Node Search ------------------------- if ($port){ # Choose columns to show and order to show them in matches() @cols = (['name','Name'],['descr','Description'],['vlan','Vlan'],['port','Port']); $m->flush_buffer; $port =~ s/^\s+//; $port =~ s/\s+$//; # Save search terms to session, change topbar $m->session->{_s_term} = $port; $m->session->{_s_type} = 'port'; # Search for ports my $name = sql_match($port); my $where = { 'descr/name'=>$name}; my $ports = sql_rows('device_port', ['ip','port','descr','vlan','name'], $where ); my @foundports = (); # Add info to each entry foreach my $portinfo (@$ports){ $portinfo->{switch} = $portinfo->{ip}; $portinfo->{switchname} = sql_scalar('device',['dns'],{'ip'=>$portinfo->{switch}}) || ''; $portinfo->{switchname} =~ s/\Q$domain\E//; push (@$matches,$portinfo); } $ran_query++; } %# %# matches() - Outputs each match depending on type %# <%method matches> % return unless $ran_query;

Search Results

%unless (scalar @$matches){ No results found. % return; } % foreach my $c (@cols){ % } <%perl> my @sorted_matches = sort {$a->{name} cmp $b->{name}} @$matches; foreach my $match (@sorted_matches) { $odd++; % foreach my $c (@cols) { % my $col = $c->[0]; % } % } Matched <% scalar $odd %> ports. %# %# FILTER: highlight search term %# <%filter> return $_ unless $arg_port; my $open = ''; my $close = ''; my $search = $arg_port; # Quote all special chars $search =~ s/(\W)/\\$1/g; # But turn back on ? and * $search =~ s/\\\*/[^<]*/g; $search =~ s/\\\?/[^<]/g; # find things after > but before < to make sure we don't mess w/ # the HTML. s{(>[^<]*)($search)([^<]*<)} {$1$open$2$close$3}ig; %# %# $Id: port_search.html,v 1.1 2010/05/25 22:20:56 bldewolf Exp $ %# vim:syntax=mason