Changeset 323 for trunk/dns.cgi


Ignore:
Timestamp:
04/29/12 18:20:17 (13 years ago)
Author:
Kris Deugau
Message:

/trunk

Moved some more SQL out of dns.cgi (see #1). Added pagination
and sorting to the log display while I was at it.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dns.cgi

    r322 r323  
    9696  $session->param('reclistsortby','host');
    9797  $session->param('reclistorder','ASC');
     98  $session->param('logsortby','stamp');
     99  $session->param('logorder','DESC');
    98100}
    99101
     
    14971499} elsif ($webvar{page} eq 'log') {
    14981500
    1499 ##fixme put in some real log-munching stuff
    1500   my $sql = "SELECT user_id, email, name, entry, date_trunc('second',stamp) FROM log WHERE ";
    15011501  my $id = $curgroup;  # we do this because the group log may be called from (almost) any page,
    15021502                       # but the others are much more limited.  this is probably non-optimal.
    15031503
    15041504  if ($webvar{ltype} && $webvar{ltype} eq 'user') {
    1505     $sql .= "user_id=?";
     1505##fixme:  where should we call this from?
    15061506    $id = $webvar{id};
    15071507    if (!check_scope(id => $id, type => 'user')) {
     
    15111511    $page->param(logfor => 'user '.userFullName($dbh,$id));
    15121512  } elsif ($webvar{ltype} && $webvar{ltype} eq 'dom') {
    1513     $sql .= "domain_id=?";
    15141513    $id = $webvar{id};
    15151514    if (!check_scope(id => $id, type => 'domain')) {
     
    15191518    $page->param(logfor => 'domain '.domainName($dbh,$id));
    15201519  } elsif ($webvar{ltype} && $webvar{ltype} eq 'rdns') {
    1521     $sql .= "rdns_id=?";
    15221520    $id = $webvar{id};
    15231521    if (!check_scope(id => $id, type => 'revzone')) {
     
    15281526  } else {
    15291527    # Default to listing curgroup log
    1530     $sql .= "group_id=?";
    15311528    $page->param(logfor => 'group '.groupName($dbh,$id));
    15321529    # note that scope limitations are applied via the change-group check;
    15331530    # group log is always for the "current" group
    15341531  }
     1532  $webvar{ltype} = 'group' if !$webvar{ltype};
     1533  my $lcount = getLogCount($dbh, (id => $id, logtype => $webvar{ltype})) or push @debugbits, $DNSDB::errstr;
     1534
     1535  $page->param(id => $id);
     1536  $page->param(ltype => $webvar{ltype});
     1537
     1538  fill_fpnla($lcount);
     1539  fill_pgcount($lcount, "log entries", '');
     1540  $page->param(curpage => $webvar{page}.($webvar{ltype} ? "&ltype=$webvar{ltype}" : ''));
     1541
     1542  $sortby = 'stamp';
     1543  $sortorder = 'DESC';  # newest-first;  although filtering is probably going to be more useful than sorting
     1544# sort/order
     1545  $session->param($webvar{page}.'sortby', $webvar{sortby}) if $webvar{sortby};
     1546  $session->param($webvar{page}.'order', $webvar{order}) if $webvar{order};
     1547
     1548  $sortby = $session->param($webvar{page}.'sortby') if $session->param($webvar{page}.'sortby');
     1549  $sortorder = $session->param($webvar{page}.'order') if $session->param($webvar{page}.'order');
     1550
     1551  # Set up the column headings with the sort info
     1552  my @cols = ('fname','username','entry','stamp');
     1553  my %colnames = (fname => 'Name', username => 'Username/Email', entry => 'Log Entry', stamp => 'Date/Time');
     1554  fill_colheads($sortby, $sortorder, \@cols, \%colnames);
     1555
     1556##fixme:  increase per-page limit or use separate limit for log?  some ops give *lots* of entries...
     1557  my $logentries = getLogEntries($dbh, (id => $id, logtype => $webvar{ltype},
     1558        offset => $webvar{offset}, sortby => $sortby, sortorder => $sortorder));
     1559  $page->param(logentries => $logentries);
     1560
    15351561##fixme:
    15361562# - filtering
    15371563# - show reverse zone column?
    1538 # - pagination/limiting number of records - put newest-first so user
    1539 #   doesn't always need to go to the last page for recent activity?
    1540   my $sth = $dbh->prepare($sql);
    1541   $sth->execute($id);
    1542   my @logbits;
    1543   while (my ($uid, $email, $name, $entry, $stamp) = $sth->fetchrow_array) {
    1544     my %row;
    1545     $row{userfname} = $name;
    1546     $row{userid} = $uid;
    1547     $row{useremail} = $email;
    1548     ($row{logentry} = $entry) =~ s/\n/<br>\n/g;
    1549     ($row{logtime}) = ($stamp =~ /^(.+)-\d\d$/);
    1550     push @logbits, \%row;
    1551   }
    1552   $page->param(logentries => \@logbits);
     1564# - on log record creation, bundle "parented" log actions (eg, "AXFR record blah for domain foo",
     1565#   or "Add record bar for new domain baz") into one entry (eg, "AXFR domain foo", "Add domain baz")?
     1566#   need a way to expand this into the complete list, and to exclude "child" entries
    15531567
    15541568  # scope check fail target
Note: See TracChangeset for help on using the changeset viewer.