Changeset 51 for trunk


Ignore:
Timestamp:
12/17/09 15:47:50 (15 years ago)
Author:
Kris Deugau
Message:

/dev

checkpoint
Moved sort order/sort-by tracking on domain, user, and group lists into session
Fixed user activation/deactivation and display
Copy-pasted bits for letter-search and filtering from domains to user and group lists

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r38 r51  
    2727        &addDomain &delDomain &domainName
    2828        &addGroup &delGroup &getChildren &groupName
    29         &addUser &delUser &userFullName
     29        &addUser &delUser &userFullName &userStatus
    3030        &getSOA &getRecLine &getDomRecs
    3131        &addRec &updateRec &delRec
     
    3939                &addDomain &delDomain &domainName
    4040                &addGroup &delGroup &getChildren &groupName
    41                 &addUser &delUser &userFullName
     41                &addUser &delUser &userFullName &userStatus
    4242                &getSOA &getRecLine &getDomRecs
    4343                &addRec &updateRec &delRec
     
    554554  return $fullformat;
    555555} # 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.
     562sub 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()
    556587
    557588
  • trunk/dns.cgi

    r48 r51  
    5050  $session->param('logingroup',1);
    5151  $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');
    5260}
    5361
     
    470478} elsif ($webvar{page} eq 'useradmin') {
    471479
     480  if (defined($webvar{action})) {
     481    userStatus($dbh,$webvar{id},$webvar{action});
     482  }
     483
     484  $page->param(curpage => $webvar{page});
     485
    472486  list_users();
    473   $page->param(curpage => $webvar{page});
    474487
    475488} elsif ($webvar{page} eq 'newuser') {
     
    966979
    967980# 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');
    970986
    971987# set up the headers
     
    979995  $sortorder = ($sortorder eq 'ASC' ? 'DESC' : 'ASC') if $sortby eq 'status';
    980996
     997# waffle, waffle - keep state on these as well as sortby, sortorder?
    981998  $page->param("start$webvar{startwith}" => 1) if $webvar{startwith} && $webvar{startwith} =~ /^[a-z]$/;
    982999
     
    10331050  fill_fpnla($count);
    10341051
    1035   $sortby = 'group';
     1052#  $sortby = 'group';
    10361053# 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');
    10391059
    10401060# set up the headers
     
    10431063  fill_colheads(\@cols, \%colnames);
    10441064
     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
    10451074  my @grouplist;
    10461075  $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 ".
    10481077        "FROM groups g ".
    10491078        "INNER JOIN groups g2 ON g2.group_id=g.parent_group_id ".
     
    10511080        "LEFT OUTER JOIN domains d ON d.group_id=g.group_id ".
    10521081        "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));
    10551088  $sth->execute;
    10561089
     1090push @debugbits, $sth->errstr;
    10571091  my $rownum = 0;
    10581092  while (my @data = $sth->fetchrow_array) {
     
    11101144  fill_fpnla($count);
    11111145
    1112   $sortby = 'user';
     1146#  $sortby = 'user';
    11131147# 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');
    11161153
    11171154# set up the headers
     
    11201157  fill_colheads(\@cols, \%colnames);
    11211158
     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
    11221170  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 ".
    11241172        "FROM users u ".
    11251173        "INNER JOIN groups g ON u.group_id=g.group_id ".
    11261174        "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 ".
    11271179        ($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
    11281184  $sth->execute($curgroup);
    11291185
     
    11341190    $row{userid} = $data[0];
    11351191    $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];
    11401196    $row{bg} = ($rownum++)%2;
    11411197    $row{sid} = $sid;
  • trunk/templates/useradmin.tmpl

    r47 r51  
    3535        <td><TMPL_VAR name=usertype></td>
    3636        <td><TMPL_VAR name=usergroup></td>
    37         <td align="center"><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&amp;page=useradmin<TMPL_IF NAME=offset>&amp;offset=<TMPL_VAR NAME=offset></TMPL_IF>&amp;id=<TMPL_VAR NAME=userid>&amp;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>&amp;page=useradmin<TMPL_IF NAME=offset>&amp;offset=<TMPL_VAR NAME=offset></TMPL_IF>&amp;id=<TMPL_VAR NAME=userid>&amp;action=<TMPL_IF NAME=active>useroff<TMPL_ELSE>useron</TMPL_IF>"><TMPL_IF NAME=active>enabled<TMPL_ELSE>disabled</TMPL_IF></a></td>
    3838        <td align="center"><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&amp;page=deluser&amp;id=<TMPL_VAR NAME=userid>"><img src="images/trash2.png" alt="[ Delete ]" /></a></td>
    3939</tr>
Note: See TracChangeset for help on using the changeset viewer.