Changeset 377 for trunk


Ignore:
Timestamp:
08/09/12 16:36:01 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Checkpoint adding locations to UI. See #10.

  • Add location list sort field and order initialization to session setup
  • Fix up a minor copy-paste oversight
  • Fill in location update stubs
  • Add missing logging and code-style bits to addLoc()
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r375 r377  
    29592959    $dbh->do("INSERT INTO locations (location, group_id, iplist, description, comments) VALUES (?,?,?,?,?)",
    29602960        undef, ($loc, $grp, $iplist, $shdesc, $comments) );
     2961    _log($dbh, entry => "Added location ($shdesc, '$iplist')");
     2962    $dbh->commit;
    29612963  };
    29622964  if ($@) {
     
    29722974
    29732975  return ('OK',$loc);
    2974 }
     2976} # end addLoc()
    29752977
    29762978
    29772979## DNSDB::updateLoc()
    2978 sub updateLoc {}
     2980sub updateLoc {
     2981  my $dbh = shift;
     2982  my $loc = shift;
     2983  my $grp = shift;
     2984  my $shdesc = shift;
     2985  my $comments = shift;
     2986  my $iplist = shift;
     2987
     2988  $shdesc = '' if !$shdesc;
     2989  $comments = '' if !$comments;
     2990  $iplist = '' if !$iplist;
     2991
     2992  # Allow transactions, and raise an exception on errors so we can catch it later.
     2993  # Use local to make sure these get "reset" properly on exiting this block
     2994  local $dbh->{AutoCommit} = 0;
     2995  local $dbh->{RaiseError} = 1;
     2996
     2997  my $oldloc = getLoc($dbh, $loc);
     2998  my $okmsg = "Updated location (".$oldloc->{description}.", '".$oldloc->{iplist}."') to ($shdesc, '$iplist')";
     2999
     3000  eval {
     3001    $dbh->do("UPDATE locations SET group_id=?,iplist=?,description=?,comments=? WHERE location=?",
     3002        undef, ($grp, $iplist, $shdesc, $comments, $loc) );
     3003    _log($dbh, entry => $okmsg);
     3004    $dbh->commit;
     3005  };
     3006  if ($@) {
     3007    my $msg = $@;
     3008    eval { $dbh->rollback; };
     3009    if ($config{log_failures}) {
     3010      $shdesc = $loc if !$shdesc;
     3011      _log($dbh, (entry => "Failed updating location ($shdesc, '$iplist'): $msg"));
     3012      $dbh->commit;
     3013    }
     3014    return ('FAIL',$msg);
     3015  }
     3016
     3017  return ('OK',$okmsg);
     3018} # end updateLoc()
     3019
    29793020
    29803021## DNSDB::delLoc()
  • trunk/dns.cgi

    r376 r377  
    9696  $session->param('reclistsortby','host');
    9797  $session->param('reclistorder','ASC');
     98  $session->param('loclistsortby','description');
     99  $session->param('loclistorder','ASC');
    98100  $session->param('logsortby','stamp');
    99101  $session->param('logorder','DESC');
     
    13521354
    13531355    my $loc = getLoc($dbh, $webvar{loc});
    1354     $page->param(wastrying      => "adding");
     1356    $page->param(wastrying      => "editing");
    13551357    $page->param(todo           => "Edit location/view");
    13561358    $page->param(locact         => "update");
     
    13631365    changepage(page => "loclist", errmsg => "You are not permitted to edit locations/views", id => $webvar{parentid})
    13641366        unless ($permissions{admin} || $permissions{location_edit});
    1365 ##work
     1367
     1368    my ($code,$msg) = updateLoc($dbh, $webvar{id}, $curgroup, $webvar{locname}, $webvar{comments}, $webvar{iplist});
     1369
     1370    if ($code eq 'OK') {
     1371      changepage(page => "loclist", resultmsg => $msg);
     1372    } else {
     1373      $page->param(failed       => 1);
     1374      $page->param(errmsg       => $msg);
     1375      $page->param(wastrying    => "editing");
     1376      $page->param(todo         => "Edit location/view");
     1377      $page->param(locact       => "update");
     1378      $page->param(id           => $webvar{loc});
     1379      $page->param(locname      => $webvar{locname});
     1380      $page->param(comments     => $webvar{comments});
     1381      $page->param(iplist       => $webvar{iplist});
     1382    }
    13661383  } else {
    13671384    changepage(page => "loclist", errmsg => "You are not permitted to add locations/views", id => $webvar{parentid})
     
    21692186  # Some UI things need to be done to the list
    21702187  foreach my $l (@{$loclist}) {
     2188    $l->{iplist} = "(All IPs)" if !$l->{iplist};
    21712189    $l->{edloc} = ($permissions{admin} || $permissions{loc_edit});
    21722190    $l->{delloc} = ($permissions{admin} || $permissions{loc_delete});
Note: See TracChangeset for help on using the changeset viewer.