Changeset 325
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r324 r325 44 44 &getGroupCount &getGroupList 45 45 &addUser &updateUser &delUser &userFullName &userStatus &getUserData 46 &getUserCount &getUserList 46 47 &getSOA &updateSOA &getRecLine &getDomRecs &getRecCount 47 48 &addRec &updateRec &delRec … … 68 69 &getGroupCount &getGroupList 69 70 &addUser &updateUser &delUser &userFullName &userStatus &getUserData 71 &getUserCount &getUserList 70 72 &getSOA &updateSOA &getRecLine &getDomRecs &getRecCount 71 73 &addRec &updateRec &delRec … … 2356 2358 return ('OK',"User $username ($fname $lname) added"); 2357 2359 } # end addUser 2360 2361 2362 ## DNSDB::getUserCount() 2363 # Get count of users in group 2364 # Takes a database handle and hash containing at least the current group, and optionally: 2365 # - a reference list of secondary groups 2366 # - a filter string 2367 # - a "Starts with" string 2368 sub getUserCount { 2369 my $dbh = shift; 2370 2371 my %args = @_; 2372 2373 my @filterargs; 2374 2375 $args{startwith} = undef if $args{startwith} && $args{startwith} !~ /^(?:[a-z]|0-9)$/; 2376 push @filterargs, "^$args{startwith}" if $args{startwith}; 2377 push @filterargs, $args{filter} if $args{filter}; 2378 2379 2380 my $sql = "SELECT count(*) FROM users ". 2381 "WHERE group_id IN ($args{curgroup}".($args{childlist} ? ",$args{childlist}" : '').")". 2382 ($args{startwith} ? " AND username ~* ?" : ''). 2383 ($args{filter} ? " AND username ~* ?" : ''); 2384 my ($count) = $dbh->selectrow_array($sql, undef, (@filterargs) ); 2385 $errstr = $dbh->errstr if !$count; 2386 return $count; 2387 } # end getUserCount() 2388 2389 2390 ## DNSDB::getUserList() 2391 # Get list of users 2392 # Takes the same arguments as getUserCount() above, plus optional: 2393 # - sort field 2394 # - sort order 2395 # - offset/return-all-everything flag (defaults to $perpage records) 2396 sub getUserList { 2397 my $dbh = shift; 2398 2399 my %args = @_; 2400 2401 my @filterargs; 2402 2403 $args{startwith} = undef if $args{startwith} && $args{startwith} !~ /^(?:[a-z]|0-9)$/; 2404 push @filterargs, "^$args{startwith}" if $args{startwith}; 2405 push @filterargs, $args{filter} if $args{filter}; 2406 2407 # better to request sorts on "simple" names, but it means we need to map it to real columns 2408 my %sortmap = (user => 'u.username', type => 'u.type', group => 'g.group_name', status => 'u.status', 2409 fname => 'fname'); 2410 $args{sortby} = $sortmap{$args{sortby}}; 2411 2412 # protection against bad or missing arguments 2413 $args{sortorder} = 'ASC' if !$args{sortorder}; 2414 $args{sortby} = 'u.username' if !$args{sortby}; 2415 $args{offset} = 0 if !$args{offset}; 2416 2417 my $sql = "SELECT u.user_id, u.username, u.firstname || ' ' || u.lastname AS fname, u.type, g.group_name, u.status ". 2418 "FROM users u ". 2419 "INNER JOIN groups g ON u.group_id=g.group_id ". 2420 "WHERE u.group_id IN ($args{curgroup}".($args{childlist} ? ",$args{childlist}" : '').")". 2421 ($args{startwith} ? " AND u.username ~* ?" : ''). 2422 ($args{filter} ? " AND u.username ~* ?" : ''). 2423 " ORDER BY $args{sortby} $args{sortorder} ". 2424 ($args{offset} eq 'all' ? '' : " LIMIT $config{perpage} OFFSET ".$args{offset}*$config{perpage}); 2425 my $ulist = $dbh->selectall_arrayref($sql, { Slice => {} }, (@filterargs) ); 2426 $errstr = $dbh->errstr if !$ulist; 2427 return $ulist; 2428 } # end getUserList() 2358 2429 2359 2430 -
trunk/dns.cgi
r323 r325 2048 2048 my $childlist = join(',',@childgroups); 2049 2049 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) ) ); 2056 2052 2057 2053 # fill page count and first-previous-next-last-all bits … … 2078 2074 $page->param(searchsubs => $searchsubs) if $searchsubs; 2079 2075 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); 2118 2088 } # end list_users() 2119 2089 -
trunk/templates/useradmin.tmpl
r207 r325 36 36 <TMPL_IF name=usertable> 37 37 <TMPL_LOOP name=usertable> 38 <tr class="row<TMPL_ VAR name=bg>">39 <td align="left"><TMPL_IF eduser><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=user&useraction=edit&user=<TMPL_VAR NAME=user id>"><TMPL_VAR NAME=username></a><TMPL_ELSE><TMPL_VAR NAME=username></TMPL_IF></td>40 <td class="data_nowrap"><TMPL_VAR name= userfull></td>41 <td><TMPL_VAR name= usertype></td>42 <td><TMPL_VAR name= usergroup></td>38 <tr class="row<TMPL_IF __odd__>0<TMPL_ELSE>1</TMPL_IF>"> 39 <td align="left"><TMPL_IF eduser><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=user&useraction=edit&user=<TMPL_VAR NAME=user_id>"><TMPL_VAR NAME=username></a><TMPL_ELSE><TMPL_VAR NAME=username></TMPL_IF></td> 40 <td class="data_nowrap"><TMPL_VAR name=fname></td> 41 <td><TMPL_VAR name=type></td> 42 <td><TMPL_VAR name=group_name></td> 43 43 <td align="center"> 44 44 <TMPL_IF eduser> 45 <a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=useradmin<TMPL_IF NAME=offset>&offset=<TMPL_VAR NAME=offset></TMPL_IF>&id=<TMPL_VAR NAME=user id>&userstatus=<TMPL_IF active>useroff<TMPL_ELSE>useron</TMPL_IF>"><TMPL_IF active>enabled<TMPL_ELSE>disabled</TMPL_IF></a>45 <a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=useradmin<TMPL_IF NAME=offset>&offset=<TMPL_VAR NAME=offset></TMPL_IF>&id=<TMPL_VAR NAME=user_id>&userstatus=<TMPL_IF status>useroff<TMPL_ELSE>useron</TMPL_IF>"><TMPL_IF status>enabled<TMPL_ELSE>disabled</TMPL_IF></a> 46 46 <TMPL_ELSE> 47 <TMPL_IF active>enabled<TMPL_ELSE>disabled</TMPL_IF>47 <TMPL_IF status>enabled<TMPL_ELSE>disabled</TMPL_IF> 48 48 </TMPL_IF> 49 49 </td> 50 50 <TMPL_IF deluser> 51 <td align="center"><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=deluser&id=<TMPL_VAR NAME=user id>"><img src="images/trash2.png" alt="[ Delete ]" /></a></td>51 <td align="center"><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=deluser&id=<TMPL_VAR NAME=user_id>"><img src="images/trash2.png" alt="[ Delete ]" /></a></td> 52 52 </TMPL_IF> 53 53 </tr>
Note:
See TracChangeset
for help on using the changeset viewer.