Changeset 24 for trunk/dns.cgi


Ignore:
Timestamp:
10/30/09 17:52:55 (15 years ago)
Author:
Kris Deugau
Message:

/trunk

checkpoint

  • group management more or less functional
  • user management partially functional
  • misc minor tweaks and normalizations
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dns.cgi

    r23 r24  
    198198      changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec});
    199199    } else {
    200       $page->param(failed => 1);
    201       $page->param(errmsg => $msg);
     200
     201      $page->param(failed       => 1);
     202      $page->param(errmsg       => $msg);
     203      $page->param(wastrying    => "adding");
     204      $page->param(todo         => "Add record to");
     205      $page->param(recact       => "add");
     206      $page->param(parentid     => $webvar{parentid});
     207      $page->param(defrec       => $webvar{defrec});
     208      $page->param(id           => $webvar{id});
    202209      fill_recdata();   # populate the form... er, mostly.
    203210    }
     
    246253    $page->param(dohere => "default records in group ".groupName($dbh,$webvar{parentid}));
    247254  } else {
     255    $page->param(parentid => $webvar{parentid});
     256#    $page->param(id => $webvar{id});
    248257    $page->param(dohere => domainName($dbh,$webvar{parentid}));
    249258  }
     
    353362# redirect to dns.cgi?etc&page=reclist
    354363    changepage(page => "reclist", id => $msg);
    355     $page = HTML::Template->new(filename => "$templatedir/reclist.tmpl");
    356     showdomain(0,$msg);
    357 ##work
     364#    $page = HTML::Template->new(filename => "$templatedir/reclist.tmpl");
     365#    showdomain(0,$msg);
    358366  } else {
    359367# oooh, yeah, this is supposed to be a redirect.  er, maybe.  whee.
     368##fixme: session ID
    360369    $page = HTML::Template->new(filename => "$templatedir/newdomain.tmpl");
    361370    $page->param(add_failed => 1);
     
    416425  }
    417426  $page->param(delgroupname => groupName($dbh, $webvar{id}));
     427
     428} elsif ($webvar{page} eq 'useradmin') {
     429
     430  list_users();
     431  $page->param(curpage => $webvar{page});
     432
     433} elsif ($webvar{page} eq 'newuser') {
     434
     435  # foo?
     436  fill_actypelist();
     437
     438} elsif ($webvar{page} eq 'adduser') {
     439
     440  my ($code,$msg);
     441 
     442  if ($webvar{pass1} ne $webvar{pass2}) {
     443    $code = 'FAIL';
     444    $msg = "Passwords don't match";
     445  } else {
     446    ($code,$msg) = addUser($dbh,$webvar{username}, $webvar{group}, $webvar{pass1},
     447        ($webvar{makeactive} eq 'on' ? 1 : 0), $webvar{fname}, $webvar{lname});
     448  }
     449
     450# hokay, a bit of magic to decide which page we hit.
     451  if ($code eq 'OK') {
     452# redirect to dns.cgi?etc&page=reclist
     453    changepage(page => "useradmin");
     454#    $page = HTML::Template->new(filename => "$templatedir/reclist.tmpl");
     455#    showdomain(0,$msg);
     456##work
     457  } else {
     458# oooh, yeah, this is supposed to be a redirect.  er, maybe.  whee.
     459#    $page = HTML::Template->new(filename => "$templatedir/newuser.tmpl");
     460    $page->param(add_failed => 1);
     461    $page->param(username => $webvar{username});
     462    $page->param(fname => $webvar{fname});
     463    $page->param(lname => $webvar{lname});
     464    $page->param(pass1 => $webvar{pass1});
     465    $page->param(pass2 => $webvar{pass2});
     466    $page->param(errmsg => $msg);
     467    fill_actypelist();
     468  }
     469
     470  $page->param(add_failed => 1);
    418471}
    419472
     
    421474# start output here so we can redirect pages.
    422475print "Content-type: text/html\n\n", $header->output;
    423 
    424 foreach (@debugbits) { print; }
    425476
    426477##common bits
     
    429480  $page->param(groupname => groupName($dbh,$curgroup));
    430481
     482  # group tree.  should go elsewhere, probably
     483  my $tmpgrplist = fill_grptree($logingroup,$curgroup);
     484  $page->param(grptree => $tmpgrplist);
     485
    431486  # stuff for menu group change.  nb: this is icky.
    432487  fill_grouplist("grouplist");
    433488  $page->param(whereami => $ENV{REQUEST_URI});
    434489}
     490
     491foreach (@debugbits) { print; }
    435492
    436493# spit it out
     
    458515
    459516exit 0;
     517
     518
     519sub fill_grptree {
     520  my $root = shift;
     521  my $cur = shift;
     522
     523  my @childlist;
     524
     525  my $grptree = HTML::Template->new(filename => 'templates/grptree.tmpl');
     526  getChildren($dbh,$root,\@childlist,'immediate');
     527  return if $#childlist == -1;
     528  my @grouplist;
     529  foreach (@childlist) {
     530    my %row;
     531    $row{grpname} = groupName($dbh,$_);
     532    $row{grpname} = "<b>$row{grpname}</b>" if $_ == $cur;
     533    $row{subs} = fill_grptree($_,$cur);
     534    push @grouplist, \%row;
     535  }
     536  $grptree->param(treelvl => \@grouplist);
     537  return $grptree->output;
     538}
    460539
    461540
     
    575654  $page->param(ttl      => ($webvar{ttl} ? $webvar{ttl} : $DNSDB::def{minttl}));
    576655}
     656
     657
     658sub fill_actypelist {
     659  my @actypes;
     660
     661  my %row1 = (actypeval => 'u', actypename => 'user');
     662  $row1{typesel} = 1 if $webvar{accttype} eq 'u';
     663  push @actypes, \%row1;
     664
     665  my %row2 = (actypeval => 'S', actypename => 'superuser');
     666  $row2{typesel} = 1 if $webvar{accttype} eq 'S';
     667  push @actypes, \%row2;
     668
     669  $page->param(actypelist       => \@actypes);
     670}
     671
    577672
    578673sub fill_fpnla {
     
    713808  $page->param("$template_var" => \@grouplist);
    714809
    715 }
     810} # end fill_grouplist()
     811
     812sub list_users {
     813  my $sth = $dbh->prepare("select count(*) from users where group_id=?");
     814  $sth->execute($curgroup);
     815  my ($count) = ($sth->fetchrow_array);
     816
     817# fill page count and first-previous-next-last-all bits
     818##fixme - hardcoded group bit
     819  fill_pgcount($count,"users",'');
     820  fill_fpnla($count);
     821
     822  my @userlist;
     823  $sth = $dbh->prepare("SELECT u.user_id, u.email, u.firstname, u.lastname, u.type, g.group_name, u.status ".
     824        "FROM users u ".
     825        "INNER JOIN groups g ON u.group_id=g.group_id ".
     826        "WHERE u.group_id=?".
     827        ($offset eq 'all' ? '' : " LIMIT $perpage OFFSET ".$offset*$perpage));
     828  $sth->execute($curgroup);
     829
     830  my $rownum = 0;
     831  while (my @data = $sth->fetchrow_array) {
     832    my %row;
     833    $row{userid} = $data[0];
     834    $row{username} = $data[1];
     835    $row{userfull} = "$data[2] $data[3]";
     836    $row{usertype} = ($data[4] eq 'S' ? 'superuser' : "user");
     837    $row{usergroup} = $data[5];
     838    $row{mkactive} = $data[6];
     839    $row{bg} = ($rownum++)%2;
     840    $row{sid} = $sid;
     841    push @userlist, \%row;
     842  }
     843  $page->param(usertable => \@userlist);
     844}
Note: See TracChangeset for help on using the changeset viewer.