Changeset 114


Ignore:
Timestamp:
08/12/11 17:37:01 (13 years ago)
Author:
Kris Deugau
Message:

/trunk

Complete core functionality for bulk domain operations. May
still need some UI polish.

Location:
trunk
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dns.cgi

    r112 r114  
    683683    changepage(page => "domlist", errmsg => "You are not permitted to bulk-move domains")
    684684        unless ($permissions{admin} || ($permissions{domain_edit} && $permissions{domain_create} && $permissions{domain_delete}));
    685 $page->param(action => $webvar{action});
    686 my $tmpstr = 'tmpstr: ';
    687 my @bulkresults;
    688 # nngh.  due to alpha-sorting on the previous page, we can't use domid-numeric
    689 # order here, and since we don't have the domain names until we go around this
    690 # loop, we can't alpha-sort them here.  :(
    691 foreach (keys %webvar) {
    692   my %row;
    693   next unless $_ =~ /^dom_\d+$/;
    694   $row{domain} = domainName($dbh,$webvar{$_});
    695   my ($code, $msg) = changeGroup($dbh, 'domain', $webvar{$_}, $webvar{destgroup});
    696   $row{domok} = ($code eq 'OK');
    697   $row{domerr} = $msg;
    698   push @bulkresults, \%row;
    699 }
    700 $page->param(bulkresults => \@bulkresults);
    701 
    702   } elsif ($webvar{action} eq 'deactivate') {
    703     changepage(page => "domlist", errmsg => "You are not permitted to bulk-deactivate domains")
     685    my $newgname = groupName($dbh,$webvar{destgroup});
     686    $page->param(action => "Move to group $newgname");
     687    my @bulkresults;
     688    # nngh.  due to alpha-sorting on the previous page, we can't use domid-numeric
     689    # order here, and since we don't have the domain names until we go around this
     690    # loop, we can't alpha-sort them here.  :(
     691    foreach (keys %webvar) {
     692      my %row;
     693      next unless $_ =~ /^dom_\d+$/;
     694      $row{domain} = domainName($dbh,$webvar{$_});
     695      my ($code, $msg) = changeGroup($dbh, 'domain', $webvar{$_}, $webvar{destgroup});
     696      if ($code eq 'OK') {
     697        logaction($webvar{$_}, $session->param("username"), parentID($webvar{$_}, 'dom', 'group'),
     698                "Moved domain ".domainName($dbh, $webvar{$_})." to group $newgname");
     699        $row{domok} = ($code eq 'OK');
     700      } else {
     701        logaction($webvar{$_}, $session->param("username"), parentID($webvar{$_}, 'dom', 'group'),
     702                "Failure moving domain ".domainName($dbh, $webvar{$_})." to group $newgname: $msg");
     703      }
     704      $row{domerr} = $msg;
     705      push @bulkresults, \%row;
     706    }
     707    $page->param(bulkresults => \@bulkresults);
     708
     709  } elsif ($webvar{action} eq 'deactivate' || $webvar{action} eq 'activate') {
     710    changepage(page => "domlist", errmsg => "You are not permitted to bulk-$webvar{action} domains")
    704711        unless ($permissions{admin} || $permissions{domain_edit});
    705   } elsif ($webvar{action} eq 'activate') {
    706     changepage(page => "domlist", errmsg => "You are not permitted to bulk-activate domains")
    707         unless ($permissions{admin} || $permissions{domain_edit});
     712    $page->param(action => "$webvar{action} domains");
     713    my @bulkresults;
     714    foreach (keys %webvar) {
     715      my %row;
     716      next unless $_ =~ /^dom_\d+$/;
     717      $row{domain} = domainName($dbh,$webvar{$_});
     718##fixme:  error handling on status change
     719      my $stat = domStatus($dbh,$webvar{$_},($webvar{action} eq 'activate' ? 'domon' : 'domoff'));
     720      logaction($webvar{$_}, $session->param("username"), parentID($webvar{$_}, 'dom', 'group'),
     721                "Changed domain ".domainName($dbh, $webvar{$_})." state to ".($stat ? 'active' : 'inactive'));
     722      $row{domok} = 1;
     723#      $row{domok} = ($code eq 'OK');
     724#      $row{domerr} = $msg;
     725      push @bulkresults, \%row;
     726    }
     727    $page->param(bulkresults => \@bulkresults);
     728
    708729  } elsif ($webvar{action} eq 'delete') {
    709730    changepage(page => "domlist", errmsg => "You are not permitted to bulk-delete domains")
    710731        unless ($permissions{admin} || $permissions{domain_delete});
    711   }
     732    $page->param(action => "$webvar{action} domains");
     733    my @bulkresults;
     734    foreach (keys %webvar) {
     735      my %row;
     736      next unless $_ =~ /^dom_\d+$/;
     737      $row{domain} = domainName($dbh,$webvar{$_});
     738      my $pargroup = parentID($webvar{$_}, 'dom', 'group');
     739      my $dom = domainName($dbh, $webvar{$_});
     740      my ($code, $msg) = delDomain($dbh, $webvar{$_});
     741      if ($code eq 'OK') {
     742        logaction($webvar{$_}, $session->param("username"), $pargroup, "Deleted domain $dom");
     743        $row{domok} = ($code eq 'OK');
     744      } else {
     745        logaction($webvar{$_}, $session->param("username"), $pargroup, "Failure deleting domain $dom: $msg");
     746      }
     747      $row{domerr} = $msg;
     748      push @bulkresults, \%row;
     749    }
     750    $page->param(bulkresults => \@bulkresults);
     751
     752  } # move/(de)activate/delete if()
     753
    712754  # not going to handle the unknown $webvar{action} else;  it should not be possible in normal
    713755  # operations, and anyone who meddles with the URL gets what they deserve.
Note: See TracChangeset for help on using the changeset viewer.