Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r38 r51 27 27 &addDomain &delDomain &domainName 28 28 &addGroup &delGroup &getChildren &groupName 29 &addUser &delUser &userFullName 29 &addUser &delUser &userFullName &userStatus 30 30 &getSOA &getRecLine &getDomRecs 31 31 &addRec &updateRec &delRec … … 39 39 &addDomain &delDomain &domainName 40 40 &addGroup &delGroup &getChildren &groupName 41 &addUser &delUser &userFullName 41 &addUser &delUser &userFullName &userStatus 42 42 &getSOA &getRecLine &getDomRecs 43 43 &addRec &updateRec &delRec … … 554 554 return $fullformat; 555 555 } # end userFullName 556 557 558 ## DNSDB::userStatus() 559 # Sets and/or returns a user's status 560 # Takes a database handle, user ID and optionally a status argument 561 # Returns undef on errors. 562 sub userStatus { 563 my $dbh = shift; 564 my $id = shift; 565 my $newstatus = shift; 566 567 return undef if $id !~ /^\d+$/; 568 569 my $sth; 570 571 # ooo, fun! let's see what we were passed for status 572 if ($newstatus) { 573 $sth = $dbh->prepare("update users set status=? where user_id=?"); 574 # ass-u-me caller knows what's going on in full 575 if ($newstatus =~ /^[01]$/) { # only two valid for now. 576 $sth->execute($newstatus,$id); 577 } elsif ($newstatus =~ /^usero(?:n|ff)$/) { 578 $sth->execute(($newstatus eq 'useron' ? 1 : 0),$id); 579 } 580 } 581 582 $sth = $dbh->prepare("select status from users where user_id=?"); 583 $sth->execute($id); 584 my ($status) = $sth->fetchrow_array; 585 return $status; 586 } # end userStatus() 556 587 557 588 -
trunk/dns.cgi
r48 r51 50 50 $session->param('logingroup',1); 51 51 $session->param('curgroup',1); # yes, we *do* need to track this too. er, probably. 52 $session->param('domlistsortby','domain'); 53 $session->param('domlistorder','ASC'); 54 $session->param('useradminsortby','username'); 55 $session->param('useradminorder','ASC'); 56 $session->param('grpmansortby','group'); 57 $session->param('grpmanorder','ASC'); 58 $session->param('reclistsortby','name'); 59 $session->param('reclistorder','ASC'); 52 60 } 53 61 … … 470 478 } elsif ($webvar{page} eq 'useradmin') { 471 479 480 if (defined($webvar{action})) { 481 userStatus($dbh,$webvar{id},$webvar{action}); 482 } 483 484 $page->param(curpage => $webvar{page}); 485 472 486 list_users(); 473 $page->param(curpage => $webvar{page});474 487 475 488 } elsif ($webvar{page} eq 'newuser') { … … 966 979 967 980 # sort/order 968 $sortby= $webvar{sortby} if $webvar{sortby}; 969 $sortorder = $webvar{order} if $webvar{order}; 981 $session->param($webvar{page}.'sortby', $webvar{sortby}) if $webvar{sortby}; 982 $session->param($webvar{page}.'order', $webvar{order}) if $webvar{order}; 983 984 $sortby = $session->param($webvar{page}.'sortby'); 985 $sortorder = $session->param($webvar{page}.'order'); 970 986 971 987 # set up the headers … … 979 995 $sortorder = ($sortorder eq 'ASC' ? 'DESC' : 'ASC') if $sortby eq 'status'; 980 996 997 # waffle, waffle - keep state on these as well as sortby, sortorder? 981 998 $page->param("start$webvar{startwith}" => 1) if $webvar{startwith} && $webvar{startwith} =~ /^[a-z]$/; 982 999 … … 1033 1050 fill_fpnla($count); 1034 1051 1035 $sortby = 'group';1052 # $sortby = 'group'; 1036 1053 # sort/order 1037 $sortby = $webvar{sortby} if $webvar{sortby}; 1038 $sortorder = $webvar{order} if $webvar{order}; 1054 $session->param($webvar{page}.'sortby', $webvar{sortby}) if $webvar{sortby}; 1055 $session->param($webvar{page}.'order', $webvar{order}) if $webvar{order}; 1056 1057 $sortby = $session->param($webvar{page}.'sortby'); 1058 $sortorder = $session->param($webvar{page}.'order'); 1039 1059 1040 1060 # set up the headers … … 1043 1063 fill_colheads(\@cols, \%colnames); 1044 1064 1065 # waffle, waffle - keep state on these as well as sortby, sortorder? 1066 $page->param("start$webvar{startwith}" => 1) if $webvar{startwith} && $webvar{startwith} =~ /^[a-z]$/; 1067 1068 $page->param(filter => $webvar{filter}) if $webvar{filter}; 1069 1070 # munge sortby for columns in database 1071 $sortby = 'g.group_name' if $sortby eq 'group'; 1072 $sortby = 'g2.group_name' if $sortby eq 'parent'; 1073 1045 1074 my @grouplist; 1046 1075 $sth = $dbh->prepare("SELECT g.group_id, g.group_name, g2.group_name, ". 1047 "count(distinct(u.username)) , count(distinct(d.domain))".1076 "count(distinct(u.username)) AS nusers, count(distinct(d.domain)) AS ndomains ". 1048 1077 "FROM groups g ". 1049 1078 "INNER JOIN groups g2 ON g2.group_id=g.parent_group_id ". … … 1051 1080 "LEFT OUTER JOIN domains d ON d.group_id=g.group_id ". 1052 1081 "WHERE g.group_id IN ($logingroup".($childlist ? ",$childlist" : '').") ". 1053 "GROUP BY g.group_id, g.group_name, g2.group_name ". 1054 "ORDER BY g.group_id".($offset eq 'all' ? '' : " LIMIT $perpage OFFSET ".$offset*$perpage)); 1082 ##fixme: don't do variable subs in SQL, use placeholders and params in ->execute() 1083 (defined($webvar{startwith}) ? " AND g.group_name ~* '^[$webvar{startwith}]'" : ''). 1084 (defined($webvar{filter}) ? " AND g.group_name ~* '$webvar{filter}'" : ''). 1085 " GROUP BY g.group_id, g.group_name, g2.group_name ". 1086 " ORDER BY $sortby $sortorder ". 1087 ($offset eq 'all' ? '' : " LIMIT $perpage OFFSET ".$offset*$perpage)); 1055 1088 $sth->execute; 1056 1089 1090 push @debugbits, $sth->errstr; 1057 1091 my $rownum = 0; 1058 1092 while (my @data = $sth->fetchrow_array) { … … 1110 1144 fill_fpnla($count); 1111 1145 1112 $sortby = 'user';1146 # $sortby = 'user'; 1113 1147 # sort/order 1114 $sortby = $webvar{sortby} if $webvar{sortby}; 1115 $sortorder = $webvar{order} if $webvar{order}; 1148 $session->param($webvar{page}.'sortby', $webvar{sortby}) if $webvar{sortby}; 1149 $session->param($webvar{page}.'order', $webvar{order}) if $webvar{order}; 1150 1151 $sortby = $session->param($webvar{page}.'sortby'); 1152 $sortorder = $session->param($webvar{page}.'order'); 1116 1153 1117 1154 # set up the headers … … 1120 1157 fill_colheads(\@cols, \%colnames); 1121 1158 1159 # waffle, waffle - keep state on these as well as sortby, sortorder? 1160 $page->param("start$webvar{startwith}" => 1) if $webvar{startwith} && $webvar{startwith} =~ /^[a-z]$/; 1161 1162 $page->param(filter => $webvar{filter}) if $webvar{filter}; 1163 1164 # munge sortby for columns in database 1165 $sortby = 'u.username' if $sortby eq 'user'; 1166 $sortby = 'u.type' if $sortby eq 'type'; 1167 $sortby = 'g.group_name' if $sortby eq 'group'; 1168 $sortby = 'u.status' if $sortby eq 'status'; 1169 1122 1170 my @userlist; 1123 $sth = $dbh->prepare("SELECT u.user_id, u.username, u.firstname , u.lastname, u.type, g.group_name, u.status ".1171 $sth = $dbh->prepare("SELECT u.user_id, u.username, u.firstname || ' ' || u.lastname AS fname, u.type, g.group_name, u.status ". 1124 1172 "FROM users u ". 1125 1173 "INNER JOIN groups g ON u.group_id=g.group_id ". 1126 1174 "WHERE u.group_id=?". 1175 ##fixme: don't do variable subs in SQL, use placeholders and params in ->execute() 1176 (defined($webvar{startwith}) ? " AND u.username ~* '^[$webvar{startwith}]'" : ''). 1177 (defined($webvar{filter}) ? " AND u.username ~* '$webvar{filter}'" : ''). 1178 " ORDER BY $sortby $sortorder ". 1127 1179 ($offset eq 'all' ? '' : " LIMIT $perpage OFFSET ".$offset*$perpage)); 1180 1181 # " GROUP BY g.group_id, g.group_name, g2.group_name ". 1182 # ($offset eq 'all' ? '' : " LIMIT $perpage OFFSET ".$offset*$perpage)); 1183 1128 1184 $sth->execute($curgroup); 1129 1185 … … 1134 1190 $row{userid} = $data[0]; 1135 1191 $row{username} = $data[1]; 1136 $row{userfull} = "$data[2] $data[3]";1137 $row{usertype} = ($data[ 4] eq 'S' ? 'superuser' : "user");1138 $row{usergroup} = $data[ 5];1139 $row{ mkactive} = $data[6];1192 $row{userfull} = $data[2]; 1193 $row{usertype} = ($data[3] eq 'S' ? 'superuser' : "user"); 1194 $row{usergroup} = $data[4]; 1195 $row{active} = $data[5]; 1140 1196 $row{bg} = ($rownum++)%2; 1141 1197 $row{sid} = $sid; -
trunk/templates/useradmin.tmpl
r47 r51 35 35 <td><TMPL_VAR name=usertype></td> 36 36 <td><TMPL_VAR name=usergroup></td> 37 <td align="center"><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=userid>&action=<TMPL_IF NAME= mkactive>useron<TMPL_ELSE>useroff</TMPL_IF>"><TMPL_IF NAME=mkactive>enabled<TMPL_ELSE>disabled</TMPL_IF></a></td>37 <td align="center"><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=userid>&action=<TMPL_IF NAME=active>useroff<TMPL_ELSE>useron</TMPL_IF>"><TMPL_IF NAME=active>enabled<TMPL_ELSE>disabled</TMPL_IF></a></td> 38 38 <td align="center"><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=deluser&id=<TMPL_VAR NAME=userid>"><img src="images/trash2.png" alt="[ Delete ]" /></a></td> 39 39 </tr>
Note:
See TracChangeset
for help on using the changeset viewer.