Changeset 325 for trunk/dns.cgi


Ignore:
Timestamp:
05/02/12 15:03:07 (13 years ago)
Author:
Kris Deugau
Message:

/trunk

Move SQL from user list code into DNSDB.pm. See #1

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dns.cgi

    r323 r325  
    20482048  my $childlist = join(',',@childgroups);
    20492049
    2050   my $sql = "SELECT count(*) FROM users WHERE group_id IN ($curgroup".($childlist ? ",$childlist" : '').")".
    2051         ($startwith ? " AND username ~* ?" : '').
    2052         ($filter ? " AND username ~* ?" : '');
    2053   my $sth = $dbh->prepare($sql);
    2054   $sth->execute(@filterargs);
    2055   my ($count) = ($sth->fetchrow_array);
     2050  my $count = getUserCount($dbh, (childlist => $childlist, curgroup => $curgroup,
     2051        filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef) ) );
    20562052
    20572053# fill page count and first-previous-next-last-all bits
     
    20782074  $page->param(searchsubs => $searchsubs) if $searchsubs;
    20792075
    2080 # munge sortby for columns in database
    2081   $sortby = 'u.username' if $sortby eq 'user';
    2082   $sortby = 'u.type' if $sortby eq 'type';
    2083   $sortby = 'g.group_name' if $sortby eq 'group';
    2084   $sortby = 'u.status' if $sortby eq 'status';
    2085 
    2086   my @userlist;
    2087   $sql = "SELECT u.user_id, u.username, u.firstname || ' ' || u.lastname AS fname, u.type, g.group_name, u.status ".
    2088         "FROM users u ".
    2089         "INNER JOIN groups g ON u.group_id=g.group_id ".
    2090         "WHERE u.group_id IN ($curgroup".($childlist ? ",$childlist" : '').")".
    2091         ($startwith ? " AND u.username ~* ?" : '').
    2092         ($filter ? " AND u.username ~* ?" : '').
    2093         " ORDER BY $sortby $sortorder ".
    2094         ($offset eq 'all' ? '' : " LIMIT $perpage OFFSET ".$offset*$perpage);
    2095 
    2096   $sth = $dbh->prepare($sql);
    2097   $sth->execute(@filterargs);
    2098 
    2099   my $rownum = 0;
    2100   while (my @data = $sth->fetchrow_array) {
    2101     no warnings "uninitialized";        # Just In Case something stupid happens and a user gets no first or last name
    2102     my %row;
    2103     $row{userid} = $data[0];
    2104     $row{username} = $data[1];
    2105     $row{userfull} = $data[2];
    2106     $row{usertype} = ($data[3] eq 'S' ? 'superuser' : "user");
    2107     $row{usergroup} = $data[4];
    2108     $row{active} = $data[5];
    2109     $row{bg} = ($rownum++)%2;
    2110     $row{sid} = $sid;
    2111     $row{eduser} = ($permissions{admin} ||
    2112         ($permissions{user_edit} && $data[3] ne 'S') ||
    2113         ($permissions{self_edit} && $data[0] == $session->param('uid')) );
    2114     $row{deluser} = ($permissions{admin} || ($permissions{user_delete} && $data[3] ne 'S'));
    2115     push @userlist, \%row;
    2116   }
    2117   $page->param(usertable => \@userlist);
     2076  my $ulist = getUserList($dbh, (childlist => $childlist, curgroup => $curgroup,
     2077        filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef),
     2078        offset => $webvar{offset}, sortby => $sortby, sortorder => $sortorder) );
     2079  # Some UI things need to be done to the list (unlike other lists)
     2080  foreach my $u (@{$ulist}) {
     2081    $u->{eduser} = ($permissions{admin} ||
     2082        ($permissions{user_edit} && $u->{type} ne 'S') ||
     2083        ($permissions{self_edit} && $u->{user_id} == $session->param('uid')) );
     2084    $u->{deluser} = ($permissions{admin} || ($permissions{user_delete} && $u->{type} ne 'S'));
     2085    $u->{type} = ($u->{type} eq 'S' ? 'superuser' : 'user');
     2086  }
     2087  $page->param(usertable => $ulist);
    21182088} # end list_users()
    21192089
Note: See TracChangeset for help on using the changeset viewer.