Changeset 22 for trunk


Ignore:
Timestamp:
10/15/09 17:50:22 (15 years ago)
Author:
Kris Deugau
Message:

/trunk

checkpoint - basic group management should be complete

  • fiddled HTML so that group-delete and domain-delete errors don't sit on top of the menu column
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r20 r22  
    2323@ISA            = qw(Exporter);
    2424@EXPORT_OK      = qw(
    25         &initGlobals &connectDB &finish &addDomain &delDomain &domainName &addGroup &getChildren &groupName
    26         &getSOA &getRecLine &getDomRecs &addRec &updateRec &delRec &domStatus
     25        &initGlobals &connectDB &finish
     26        &addDomain &delDomain &domainName
     27        &addGroup &delGroup &getChildren &groupName
     28        &getSOA &getRecLine &getDomRecs
     29        &addRec &updateRec &delRec
     30        &domStatus
    2731        %typemap %reverse_typemap
    2832        );
     
    3034@EXPORT         = (); # Export nothing by default.
    3135%EXPORT_TAGS    = ( ALL => [qw(
    32                 &initGlobals &connectDB &finish &addDomain &delDomain &domainName &addGroup &getChildren
    33                 &groupName &getSOA &getRecLine &getDomRecs &addRec &updateRec &delRec &domStatus
     36                &initGlobals &connectDB &finish
     37                &addDomain &delDomain &domainName
     38                &addGroup &delGroup &getChildren &groupName
     39                &getSOA &getRecLine &getDomRecs
     40                &addRec &updateRec &delRec
     41                &domStatus
    3442                %typemap %reverse_typemap
    3543                )]
     
    225233    $sth->execute($domid);
    226234
     235#die "full of fail\n";
    227236    # once we get here, we should have suceeded.
    228     $dbh->commit;
     237#    $dbh->commit;
    229238  }; # end eval
    230239
     
    302311    }
    303312
    304 die "epic FAIL..  hahahah, just testing!\n";
    305313    # once we get here, we should have suceeded.
    306314    $dbh->commit;
     
    316324
    317325} # end addGroup()
     326
     327
     328## DNSDB::delGroup()
     329# Delete a group.
     330# Takes a group ID
     331# Returns a status code and message
     332sub delGroup {
     333  my $dbh = shift;
     334  my $groupid = shift;
     335
     336  # Allow transactions, and raise an exception on errors so we can catch it later.
     337  # Use local to make sure these get "reset" properly on exiting this block
     338  local $dbh->{AutoCommit} = 0;
     339  local $dbh->{RaiseError} = 1;
     340
     341##fixme:  locate "knowable" error conditions and deal with them before the eval
     342# -> domains still exist in group
     343# -> ...
     344
     345  # Wrap all the SQL in a transaction
     346  eval {
     347    my $sth = $dbh->prepare("delete from default_records where group_id=?");
     348    $sth->execute($groupid);
     349    $sth = $dbh->prepare("delete from groups where group_id=?");
     350    $sth->execute($groupid);
     351
     352die "epic group fail FTW!\n";
     353    # once we get here, we should have suceeded.
     354    $dbh->commit;
     355  }; # end eval
     356
     357  if ($@) {
     358    my $msg = $@;
     359    eval { $dbh->rollback; };
     360    return ('FAIL',$msg);
     361  } else {
     362    return ('OK','OK');
     363  }
     364} # end delGroup()
    318365
    319366
  • trunk/dns.cgi

    r20 r22  
    165165      $page->param(del_failed => 1);
    166166      $page->param(errmsg => $msg);
     167      listdomains($curgroup);
    167168    } else {
    168169      # success.  go back to the domain list, do not pass "GO"
     
    365366} elsif ($webvar{page} eq 'grpman') {
    366367
    367   my $sth = $dbh->prepare("select count(*) from groups");
    368   $sth->execute;
    369   my ($count) = ($sth->fetchrow_array);
    370 
    371 # fill page count and first-previous-next-last-all bits
    372 ##fixme - hardcoded group bit
    373   fill_pgcount($count,"groups",'');
    374   fill_fpnla($count);
    375 
    376   my @grouplist;
    377   $sth = $dbh->prepare("SELECT g.group_id, g.group_name, g2.group_name, ".
    378         "count(distinct(u.email)), count(distinct(d.domain)) ".
    379         "FROM groups g ".
    380         "INNER JOIN groups g2 ON g2.group_id=g.parent_group_id ".
    381         "LEFT OUTER JOIN users u ON u.group_id=g.group_id ".
    382         "LEFT OUTER JOIN domains d ON d.group_id=g.group_id ".
    383         "GROUP BY g.group_id, g.group_name, g2.group_name ".
    384         "ORDER BY g.group_id".($offset eq 'all' ? '' : " LIMIT $perpage OFFSET ".$offset*$perpage));
    385   $sth->execute;
    386 
    387   my $rownum = 0;
    388   while (my @data = $sth->fetchrow_array) {
    389     my %row;
    390     $row{groupid} = $data[0];
    391     $row{groupname} = $data[1];
    392     $row{pgroup} = $data[2];
    393     $row{nusers} = $data[3];
    394     $row{ndomains} = $data[4];
    395     $row{bg} = ($rownum++)%2;
    396     $row{sid} = $sid;
    397     push @grouplist, \%row;
    398   }
    399   $page->param(grouptable => \@grouplist);
    400 
     368  listgroups();
    401369  $page->param(curpage => $webvar{page});
    402370
     
    418386  }
    419387
    420 } elsif ($webvar{page} eq 'delgroup') {
     388} elsif ($webvar{page} eq 'delgrp') {
    421389
    422390  $page->param(id => $webvar{id});
     
    436404      $page->param(del_failed => 1);
    437405      $page->param(errmsg => $msg);
     406      $page->param(curpage => $webvar{page});
     407      listgroups();
    438408    } else {
    439409      # success.  go back to the domain list, do not pass "GO"
     
    646616
    647617sub listdomains {
    648 
    649618  my $sth = $dbh->prepare("SELECT count(*) FROM domains WHERE group_id=?");
    650619  $sth->execute($curgroup);
     
    683652
    684653
     654sub listgroups {
     655  my $sth = $dbh->prepare("select count(*) from groups");
     656  $sth->execute;
     657  my ($count) = ($sth->fetchrow_array);
     658
     659# fill page count and first-previous-next-last-all bits
     660##fixme - hardcoded group bit
     661  fill_pgcount($count,"groups",'');
     662  fill_fpnla($count);
     663
     664  my @grouplist;
     665  $sth = $dbh->prepare("SELECT g.group_id, g.group_name, g2.group_name, ".
     666        "count(distinct(u.email)), count(distinct(d.domain)) ".
     667        "FROM groups g ".
     668        "INNER JOIN groups g2 ON g2.group_id=g.parent_group_id ".
     669        "LEFT OUTER JOIN users u ON u.group_id=g.group_id ".
     670        "LEFT OUTER JOIN domains d ON d.group_id=g.group_id ".
     671        "GROUP BY g.group_id, g.group_name, g2.group_name ".
     672        "ORDER BY g.group_id".($offset eq 'all' ? '' : " LIMIT $perpage OFFSET ".$offset*$perpage));
     673  $sth->execute;
     674
     675  my $rownum = 0;
     676  while (my @data = $sth->fetchrow_array) {
     677    my %row;
     678    $row{groupid} = $data[0];
     679    $row{groupname} = $data[1];
     680    $row{pgroup} = $data[2];
     681    $row{nusers} = $data[3];
     682    $row{ndomains} = $data[4];
     683    $row{bg} = ($rownum++)%2;
     684    $row{sid} = $sid;
     685    push @grouplist, \%row;
     686  }
     687  $page->param(grouptable => \@grouplist);
     688} # end listgroups()
     689
     690
    685691sub fill_grouplist {
    686692  my $template_var = shift;
  • trunk/templates/deldom.tmpl

    r7 r22  
    99
    1010<TMPL_ELSE>
    11  <TMPL_IF del_failed>
     11 <!-- <TMPL_IF del_failed>
    1212  <div class='errmsg'>Error deleting domain <TMPL_VAR NAME=domain>: <TMPL_VAR NAME=errmsg></div>
    13  </TMPL_IF>
     13 </TMPL_IF> -->
    1414 <TMPL_INCLUDE NAME="domlist.tmpl">
    1515</TMPL_IF>
  • trunk/templates/delgrp.tmpl

    r21 r22  
    1010
    1111<TMPL_ELSE>
    12  <TMPL_IF del_failed>
     12 <!-- <TMPL_IF del_failed>
    1313  <div class='errmsg'>Error deleting group <TMPL_VAR NAME=groupname>: <TMPL_VAR NAME=errmsg></div>
    14  </TMPL_IF>
     14 </TMPL_IF> -->
    1515 <TMPL_INCLUDE NAME="grpman.tmpl">
    1616</TMPL_IF>
  • trunk/templates/domlist.tmpl

    r17 r22  
    44
    55<td align="center">
     6
     7 <TMPL_IF del_failed>
     8  <div class='errmsg'>Error deleting domain <TMPL_VAR NAME=domain>: <TMPL_VAR NAME=errmsg></div>
     9 </TMPL_IF>
     10
    611<table width="98%">
    712<tr><td colspan=3 align=center>Domain list</td></tr>
  • trunk/templates/grpman.tmpl

    r20 r22  
    44
    55<td align="center">
     6
     7 <TMPL_IF del_failed>
     8  <div class='errmsg'>Error deleting group <TMPL_VAR NAME=groupname>: <TMPL_VAR NAME=errmsg></div>
     9 </TMPL_IF>
     10
    611<table width="98%">
    712<tr><td colspan=3 align=center><span class="pgtitle">Manage groups</span></td></tr>
Note: See TracChangeset for help on using the changeset viewer.