Changeset 135


Ignore:
Timestamp:
10/07/11 14:43:59 (13 years ago)
Author:
Kris Deugau
Message:

/trunk

Tweak getDomRecs and getRecCount to return useful, correct
results when something is entered in the "filter" space on
the record list page

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r132 r135  
    12111211  my $direction = shift || 'ASC';
    12121212
     1213  my $filter = shift || '';
     1214  # keep the nasties down, since we can't ?-sub this bit.  :/
     1215  # note this is chars allowed in DNS hostnames
     1216  $filter =~ s/[^a-zA-Z0-9_.:-]//g;
     1217
    12131218  $type = 'y' if $type eq 'def';
    12141219
     
    12231228  }
    12241229  $sql .= " AND NOT r.type=$reverse_typemap{SOA}";
     1230  $sql .= " AND host ILIKE '%$filter%'" if $filter;
    12251231  # use alphaorder column for "correct" ordering of sort-by-type instead of DNS RR type number
    12261232  $sql .= " ORDER BY ".($order eq 'type' ? 't.alphaorder' : "r.$order")." $direction";
     
    12421248## DNSDB::getRecCount()
    12431249# Return count of non-SOA records in domain (or default records in a group)
    1244 # Takes a database handle, default/live flag and group/domain ID
     1250# Takes a database handle, default/live flag, group/domain ID, and optional filtering modifier
    12451251# Returns the count
    12461252sub getRecCount {
     
    12481254  my $defrec = shift;
    12491255  my $id = shift;
     1256  my $filter = shift || '';
     1257
     1258  # keep the nasties down, since we can't ?-sub this bit.  :/
     1259  # note this is chars allowed in DNS hostnames
     1260  $filter =~ s/[^a-zA-Z0-9_.:-]//g;
    12501261
    12511262  my ($count) = $dbh->selectrow_array("SELECT count(*) FROM ".
    12521263        ($defrec eq 'y' ? 'default_' : '')."records ".
    12531264        "WHERE ".($defrec eq 'y' ? 'group' : 'domain')."_id=? ".
    1254         "AND NOT type=$reverse_typemap{SOA}", undef, ($id) );
     1265        "AND NOT type=$reverse_typemap{SOA}".
     1266        ($filter ? " AND host ILIKE '%$filter%'" : ''),
     1267        undef, ($id) );
    12551268
    12561269  return $count;
Note: See TracChangeset for help on using the changeset viewer.