Changeset 52 for trunk


Ignore:
Timestamp:
12/22/09 16:47:28 (15 years ago)
Author:
Kris Deugau
Message:

/trunk

Make subgroup y/n checkbox, search filter more or less work on user, domain, and group lists

  • still need to figure out how to retain the letter-filter, subgroup, and filter data when they're needed but discard them when they should be discarded
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/TODO

    r50 r52  
    3030   - would let users create plugin code to support arbitrary types
    3131 - Push DB name, host, username, password into config file
     32
     332009/12/17
     34 - "complete rewrite" target:  one table of objects, one set of functions;  hooks
     35   to manipulate "special" data for given types of objects?  (even merging
     36   domain/group/user objects would reduce a lot of code almost-duplication)
  • trunk/dns.cgi

    r51 r52  
    726726# le sigh.  and we need to strip any previous action
    727727  $tmp_ruri =~ s/\&action=[^&]+//g;
     728
     729##fixme:  need to sort out how to propagate these without dragging them along too far, and <n>plicating them
    728730# and any bits from the "starts with" letter block - (ab)using this widget
    729731# to fill the bulk of the URI so various templates don't grow to insanity
    730732  $tmp_ruri =~ s/\&amp;startwith=[a-z09-]+//g;
     733# search box webvars
     734  $tmp_ruri =~ s/\&amp;searchsubs=[a-z09-]+//g;
     735  $tmp_ruri =~ s/\&amp;filter=[a-z09-]+//g;
     736
    731737#  $page->param(whereami => $ENV{REQUEST_URI});
    732738  $page->param(whereami => $tmp_ruri);
     
    968974sub listdomains {
    969975
    970 ##fixme:  account for searches and starts-with filters
    971   my $sth = $dbh->prepare("SELECT count(*) FROM domains WHERE group_id=?");
    972   $sth->execute($curgroup);
     976##fixme:  $logingroup or$curgroup?
     977  my @childgroups;
     978  getChildren($dbh, $logingroup, \@childgroups, 'all');
     979  my $childlist = join(',',@childgroups);
     980
     981  my $sql = "SELECT count(*) FROM domains WHERE group_id IN ($logingroup".($childlist ? ",$childlist" : '').")".
     982        (defined($webvar{startwith}) ? " AND domain ~* '^[$webvar{startwith}]'" : '').
     983        (defined($webvar{filter}) ? " AND domain ~* '$webvar{filter}'" : '');
     984  my $sth = $dbh->prepare($sql);
     985  $sth->execute;
    973986  my ($count) = $sth->fetchrow_array;
    974987
     
    10061019  $page->param(group => $curgroup);
    10071020  my @domlist;
    1008   my $sql = "SELECT domain_id,domain,status,groups.group_name AS group FROM domains".
     1021  $sql = "SELECT domain_id,domain,status,groups.group_name AS group FROM domains".
    10091022        " INNER JOIN groups ON domains.group_id=groups.group_id".
    1010         " WHERE domains.group_id=?".
     1023        " WHERE domains.group_id IN ($logingroup".($childlist ? ",$childlist" : '').")".
    10111024##fixme:  don't do variable subs in SQL, use placeholders and params in ->execute()
    10121025        (defined($webvar{startwith}) ? " AND domain ~* '^[$webvar{startwith}]'" : '').
     
    10151028        " $sortorder ".($offset eq 'all' ? '' : " LIMIT $perpage OFFSET ".$offset*$perpage);
    10161029  $sth = $dbh->prepare($sql);
    1017   $sth->execute($curgroup);
     1030  $sth->execute;
    10181031  my $rownum = 0;
    10191032  while (my @data = $sth->fetchrow_array) {
     
    10401053  my $childlist = join(',',@childgroups);
    10411054
    1042   my $sql = "SELECT count(*) FROM groups WHERE group_id IN ($logingroup".($childlist ? ",$childlist" : '').")";
     1055  my $sql = "SELECT count(*) FROM groups WHERE group_id IN ($logingroup".($childlist ? ",$childlist" : '').")".
     1056        (defined($webvar{startwith}) ? " AND group_name ~* '^[$webvar{startwith}]'" : '').
     1057        (defined($webvar{filter}) ? " AND group_name ~* '$webvar{filter}'" : '');
    10431058  my $sth = $dbh->prepare($sql);
    10441059
     
    10881103  $sth->execute;
    10891104
    1090 push @debugbits, $sth->errstr;
    10911105  my $rownum = 0;
    10921106  while (my @data = $sth->fetchrow_array) {
     
    11351149
    11361150sub list_users {
    1137   my $sth = $dbh->prepare("select count(*) from users where group_id=?");
    1138   $sth->execute($curgroup);
     1151
     1152  my @childgroups;
     1153  getChildren($dbh, $curgroup, \@childgroups, 'all') if $webvar{searchsubs};
     1154  my $childlist = join(',',@childgroups);
     1155
     1156  my $sql = "SELECT count(*) FROM users WHERE group_id IN ($curgroup".($childlist ? ",$childlist" : '').")".
     1157        (defined($webvar{startwith}) ? " AND username ~* '^[$webvar{startwith}]'" : '').
     1158        (defined($webvar{filter}) ? " AND username ~* '$webvar{filter}'" : '');
     1159  my $sth = $dbh->prepare($sql);
     1160  $sth->execute;
    11391161  my ($count) = ($sth->fetchrow_array);
    11401162
     
    11611183
    11621184  $page->param(filter => $webvar{filter}) if $webvar{filter};
     1185  $page->param(searchsubs => $webvar{searchsubs}) if $webvar{searchsubs};
    11631186
    11641187# munge sortby for columns in database
     
    11691192
    11701193  my @userlist;
    1171   $sth = $dbh->prepare("SELECT u.user_id, u.username, u.firstname || ' ' || u.lastname AS fname, u.type, g.group_name, u.status ".
     1194  $sql = "SELECT u.user_id, u.username, u.firstname || ' ' || u.lastname AS fname, u.type, g.group_name, u.status ".
    11721195        "FROM users u ".
    11731196        "INNER JOIN groups g ON u.group_id=g.group_id ".
    1174         "WHERE u.group_id=?".
     1197        "WHERE u.group_id IN ($curgroup".($childlist ? ",$childlist" : '').")".
    11751198##fixme:  don't do variable subs in SQL, use placeholders and params in ->execute()
    11761199        (defined($webvar{startwith}) ? " AND u.username ~* '^[$webvar{startwith}]'" : '').
    11771200        (defined($webvar{filter}) ? " AND u.username ~* '$webvar{filter}'" : '').
    11781201        " ORDER BY $sortby $sortorder ".
    1179         ($offset eq 'all' ? '' : " LIMIT $perpage OFFSET ".$offset*$perpage));
     1202        ($offset eq 'all' ? '' : " LIMIT $perpage OFFSET ".$offset*$perpage);
    11801203
    11811204#       " GROUP BY g.group_id, g.group_name, g2.group_name ".
    11821205#       ($offset eq 'all' ? '' : " LIMIT $perpage OFFSET ".$offset*$perpage));
    11831206
    1184   $sth->execute($curgroup);
     1207  $sth = $dbh->prepare($sql);
     1208  $sth->execute;
    11851209
    11861210  my $rownum = 0;
  • trunk/templates/sbox.tmpl

    r46 r52  
    11<form action="<TMPL_VAR NAME=whereami>" method="post">
    22<fieldset>
    3 Search subgroups: <input type="checkbox" <TMPL_IF searchsubs>checked="checked"</TMPL_IF> name="searchsubs" />
     3Search subgroups: <input type="checkbox"<TMPL_IF searchsubs> checked="checked"</TMPL_IF> name="searchsubs" />
     4<input type="hidden" name="searchsubs" value="<TMPL_VAR NAME=searchsubs>">
    45<input name="filter" value="<TMPL_VAR NAME=filter>" />
    56<input type="submit" value="Search" />
Note: See TracChangeset for help on using the changeset viewer.