Changeset 370 for trunk/DNSDB.pm


Ignore:
Timestamp:
07/29/12 22:02:48 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Checkpoint; adding location/view support. See #10.

  • add location to menu
  • add table and link fields to initial tabledef and upgrade SQL
  • add listing subs and list page
  • update permissions list and subpage template with new permissions
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r368 r370  
    4747        &addUser &updateUser &delUser &userFullName &userStatus &getUserData
    4848        &getUserCount &getUserList &getUserDropdown
     49        &addLoc &updateLoc &delLoc
     50        &getLocCount &getLocList &getLocDropdown
    4951        &getSOA &updateSOA &getRecLine &getDomRecs &getRecCount
    5052        &addRec &updateRec &delRec
     
    7274                &addUser &updateUser &delUser &userFullName &userStatus &getUserData
    7375                &getUserCount &getUserList &getUserDropdown
     76                &addLoc &updateLoc &delLoc
     77                &getLocCount &getLocList &getLocDropdown
    7478                &getSOA &updateSOA &getRecLine &getDomRecs &getRecCount
    7579                &addRec &updateRec &delRec
     
    106110
    107111# Arguably defined wholly in the db, but little reason to change without supporting code changes
     112# group_view, user_view permissions? separate rDNS permission(s)?
    108113our @permtypes = qw (
    109114        group_edit      group_create    group_delete
     
    111116        domain_edit     domain_create   domain_delete
    112117        record_edit     record_create   record_delete
     118        location_edit   location_create location_delete location_view
    113119        self_edit       admin
    114120);
     
    28912897
    28922898} # end getUserData()
     2899
     2900
     2901## DNSDB::addLoc()
     2902sub addLoc {}
     2903
     2904## DNSDB::updateLoc()
     2905sub updateLoc {}
     2906
     2907## DNSDB::delLoc()
     2908sub delLoc {}
     2909
     2910
     2911## DNSDB::getLocCount()
     2912# Get count of locations/views
     2913# Takes a database handle and hash containing at least the current group, and optionally:
     2914# - a reference list of secondary groups
     2915# - a filter string
     2916# - a "Starts with" string
     2917sub getLocCount {
     2918  my $dbh = shift;
     2919
     2920  my %args = @_;
     2921
     2922  my @filterargs;
     2923
     2924  $args{startwith} = undef if $args{startwith} && $args{startwith} !~ /^(?:[a-z]|0-9)$/;
     2925  push @filterargs, "^$args{startwith}" if $args{startwith};
     2926  push @filterargs, $args{filter} if $args{filter};
     2927
     2928
     2929  my $sql = "SELECT count(*) FROM locations ".
     2930        "WHERE group_id IN ($args{curgroup}".($args{childlist} ? ",$args{childlist}" : '').")".
     2931        ($args{startwith} ? " AND description ~* ?" : '').
     2932        ($args{filter} ? " AND description ~* ?" : '');
     2933  my ($count) = $dbh->selectrow_array($sql, undef, (@filterargs) );
     2934  $errstr = $dbh->errstr if !$count;
     2935  return $count;
     2936} # end getLocCount()
     2937
     2938
     2939## DNSDB::getLocList()
     2940sub getLocList {
     2941  my $dbh = shift;
     2942
     2943  my %args = @_;
     2944
     2945  my @filterargs;
     2946
     2947  $args{startwith} = undef if $args{startwith} && $args{startwith} !~ /^(?:[a-z]|0-9)$/;
     2948  push @filterargs, "^$args{startwith}" if $args{startwith};
     2949  push @filterargs, $args{filter} if $args{filter};
     2950
     2951  # better to request sorts on "simple" names, but it means we need to map it to real columns
     2952#  my %sortmap = (user => 'u.username', type => 'u.type', group => 'g.group_name', status => 'u.status',
     2953#       fname => 'fname');
     2954#  $args{sortby} = $sortmap{$args{sortby}};
     2955
     2956  # protection against bad or missing arguments
     2957  $args{sortorder} = 'ASC' if !$args{sortorder};
     2958  $args{sortby} = 'l.description' if !$args{sortby};
     2959  $args{offset} = 0 if !$args{offset};
     2960
     2961  my $sql = "SELECT l.location, l.description, l.iplist, g.group_name ".
     2962        "FROM locations l ".
     2963        "INNER JOIN groups g ON l.group_id=g.group_id ".
     2964        "WHERE l.group_id IN ($args{curgroup}".($args{childlist} ? ",$args{childlist}" : '').")".
     2965        ($args{startwith} ? " AND l.description ~* ?" : '').
     2966        ($args{filter} ? " AND l.description ~* ?" : '').
     2967        " ORDER BY $args{sortby} $args{sortorder} ".
     2968        ($args{offset} eq 'all' ? '' : " LIMIT $config{perpage} OFFSET ".$args{offset}*$config{perpage});
     2969  my $ulist = $dbh->selectall_arrayref($sql, { Slice => {} }, (@filterargs) );
     2970  $errstr = $dbh->errstr if !$ulist;
     2971  return $ulist;
     2972} # end getLocList()
     2973
     2974
     2975## DNSDB::getLocDropdown()
    28932976
    28942977
Note: See TracChangeset for help on using the changeset viewer.