Changeset 53


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

/trunk

checkpoint
Starts with, search subgroups, and filter all maintain state properly

across requests on a single page; requests back and forth between domain,
user, and group listings sometimes reset as desired but sometimes maintain
state - this leads to confusing results sometimes.

Starts with, search subgroups, and filter all correctly influence both the

"n - m of o" and data lines in domain, user, and group listings

Tweaks to templates to correctly pass "empty" states for starts with, search

subgroups, and filter

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/dns.cgi

    r52 r53  
    5858  $session->param('reclistsortby','name');
    5959  $session->param('reclistorder','ASC');
     60#  $session->param('filter','login');
     61#  $session->param('startwith','login');
     62#  $session->param('searchsubs','login');
    6063}
    6164
     
    6366my $curgroup = ($session->param('curgroup') ? $session->param('curgroup') : $logingroup);
    6467my $group = ($webvar{group} ? $webvar{group} : 1);
     68
     69# filter, starts with, search subgroups
     70$session->param('filter', "$webvar{page}:filter$webvar{filter}") if defined($webvar{filter});
     71my $filter = $session->param('filter');
     72$filter = ($filter =~ /^$webvar{page}:filter(.+)$/ ? $1 : '');
     73
     74$session->param('startwith', "$webvar{page}:startwith$webvar{startwith}") if defined($webvar{startwith});
     75my $startwith = $session->param('startwith');
     76$startwith = ($startwith =~ /^$webvar{page}:startwith(.+)$/ ? $1 : '');
     77
     78$webvar{searchsubs} =~ s/^n ?// if $webvar{searchsubs};
     79$session->param('searchsubs', "$webvar{page}:searchsubs$webvar{searchsubs}") if defined($webvar{searchsubs});
     80my $searchsubs = $session->param('searchsubs');
     81$searchsubs = ($searchsubs =~ /^$webvar{page}:searchsubs(.+)$/ ? $1 : '');
    6582
    6683# nrgh, can't handle login here because we don't have a database handle to check the user/pass with yet
     
    721738  # stuff for menu group change.  nb: this is icky.
    722739  fill_grouplist("grouplist");
     740
     741## set up "URL to self"
    723742# @#$%@%@#% XHTML - & in a URL must be escaped.  >:(
    724743  my $tmp_ruri = $ENV{REQUEST_URI};
    725744  $tmp_ruri =~ s/\&([a-z])/\&amp\;$1/g;
     745
    726746# le sigh.  and we need to strip any previous action
    727747  $tmp_ruri =~ s/\&action=[^&]+//g;
    728748
    729 ##fixme:  need to sort out how to propagate these without dragging them along too far, and <n>plicating them
    730 # and any bits from the "starts with" letter block - (ab)using this widget
    731 # to fill the bulk of the URI so various templates don't grow to insanity
    732   $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 
    737 #  $page->param(whereami => $ENV{REQUEST_URI});
     749# and search filter options.  these get stored in the session, but discarded
     750# as soon as you switch to a different page.
     751##fixme:  think about retaining these on a per-page basis, as well as offset;  same as the sort-order bits
     752  no warnings qw(uninitialized);
     753  $tmp_ruri =~ s/\&amp;startwith=[a-z09-]*(\&)?/$1/g;
     754  $tmp_ruri =~ s/\&amp;searchsubs=[a-z09-]*(\&)?/$1/g;
     755  $tmp_ruri =~ s/\&amp;filter=[a-z09-]*(\&)?/$1/g;
     756  use warnings qw(uninitialized);
     757
     758# fill in the URL-to-self
    738759  $page->param(whereami => $tmp_ruri);
    739760}
     
    974995sub listdomains {
    975996
    976 ##fixme:  $logingroup or$curgroup?
     997##fixme:  $logingroup or $curgroup?
    977998  my @childgroups;
    978   getChildren($dbh, $logingroup, \@childgroups, 'all');
     999  getChildren($dbh, $logingroup, \@childgroups, 'all') if $searchsubs;
    9791000  my $childlist = join(',',@childgroups);
    9801001
    9811002  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}'" : '');
     1003        ($startwith ? " AND domain ~* '^[$startwith]'" : '').
     1004        ($filter ? " AND domain ~* '$filter'" : '');
    9841005  my $sth = $dbh->prepare($sql);
    9851006  $sth->execute;
     
    10091030
    10101031# waffle, waffle - keep state on these as well as sortby, sortorder?
    1011   $page->param("start$webvar{startwith}" => 1) if $webvar{startwith} && $webvar{startwith} =~ /^[a-z]$/;
    1012 
    1013   $page->param(filter => $webvar{filter}) if $webvar{filter};
     1032  $page->param("start$startwith" => 1) if $startwith && $startwith =~ /^(?:[a-z]|0-9)$/;
     1033
     1034  $page->param(filter => $filter) if $filter;
     1035  $page->param(searchsubs => $searchsubs) if $searchsubs;
    10141036
    10151037##fixme
     
    10231045        " WHERE domains.group_id IN ($logingroup".($childlist ? ",$childlist" : '').")".
    10241046##fixme:  don't do variable subs in SQL, use placeholders and params in ->execute()
    1025         (defined($webvar{startwith}) ? " AND domain ~* '^[$webvar{startwith}]'" : '').
    1026         (defined($webvar{filter}) ? " AND domain ~* '$webvar{filter}'" : '').
     1047        ($startwith ? " AND domain ~* '^[$startwith]'" : '').
     1048        ($filter ? " AND domain ~* '$filter'" : '').
    10271049        " ORDER BY ".($sortby eq 'group' ? 'groups.group_name' : $sortby).
    10281050        " $sortorder ".($offset eq 'all' ? '' : " LIMIT $perpage OFFSET ".$offset*$perpage);
     
    10491071
    10501072sub listgroups {
     1073
    10511074  my @childgroups;
    1052   getChildren($dbh, $logingroup, \@childgroups, 'all');
     1075  getChildren($dbh, $logingroup, \@childgroups, 'all') if $searchsubs;
    10531076  my $childlist = join(',',@childgroups);
    10541077
    10551078  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}'" : '');
     1079        ($startwith ? " AND group_name ~* '^[$startwith]'" : '').
     1080        ($filter ? " AND group_name ~* '$filter'" : '');
    10581081  my $sth = $dbh->prepare($sql);
    10591082
     
    10811104  $page->param("start$webvar{startwith}" => 1) if $webvar{startwith} && $webvar{startwith} =~ /^[a-z]$/;
    10821105
    1083   $page->param(filter => $webvar{filter}) if $webvar{filter};
     1106  $page->param(filter => $filter) if $filter;
     1107  $page->param(searchsubs => $searchsubs) if $searchsubs;
    10841108
    10851109# munge sortby for columns in database
     
    10961120        "WHERE g.group_id IN ($logingroup".($childlist ? ",$childlist" : '').") ".
    10971121##fixme:  don't do variable subs in SQL, use placeholders and params in ->execute()
    1098         (defined($webvar{startwith}) ? " AND g.group_name ~* '^[$webvar{startwith}]'" : '').
    1099         (defined($webvar{filter}) ? " AND g.group_name ~* '$webvar{filter}'" : '').
     1122        ($startwith ? " AND g.group_name ~* '^[$startwith]'" : '').
     1123        ($filter ? " AND g.group_name ~* '$filter'" : '').
    11001124        " GROUP BY g.group_id, g.group_name, g2.group_name ".
    11011125        " ORDER BY $sortby $sortorder ".
     
    11511175
    11521176  my @childgroups;
    1153   getChildren($dbh, $curgroup, \@childgroups, 'all') if $webvar{searchsubs};
     1177  getChildren($dbh, $curgroup, \@childgroups, 'all') if $searchsubs;
    11541178  my $childlist = join(',',@childgroups);
    11551179
    11561180  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}'" : '');
     1181        ($startwith ? " AND username ~* '^[$startwith]'" : '').
     1182        ($filter ? " AND username ~* '$filter'" : '');
    11591183  my $sth = $dbh->prepare($sql);
    11601184  $sth->execute;
     
    11801204
    11811205# waffle, waffle - keep state on these as well as sortby, sortorder?
    1182   $page->param("start$webvar{startwith}" => 1) if $webvar{startwith} && $webvar{startwith} =~ /^[a-z]$/;
    1183 
    1184   $page->param(filter => $webvar{filter}) if $webvar{filter};
    1185   $page->param(searchsubs => $webvar{searchsubs}) if $webvar{searchsubs};
     1206  $page->param("start$startwith" => 1) if $startwith && $startwith =~ /^[a-z]$/;
     1207
     1208  $page->param(filter => $filter) if $filter;
     1209  $page->param(searchsubs => $searchsubs) if $searchsubs;
    11861210
    11871211# munge sortby for columns in database
     
    11971221        "WHERE u.group_id IN ($curgroup".($childlist ? ",$childlist" : '').")".
    11981222##fixme:  don't do variable subs in SQL, use placeholders and params in ->execute()
    1199         (defined($webvar{startwith}) ? " AND u.username ~* '^[$webvar{startwith}]'" : '').
    1200         (defined($webvar{filter}) ? " AND u.username ~* '$webvar{filter}'" : '').
     1223        ($startwith ? " AND u.username ~* '^[$startwith]'" : '').
     1224        ($filter ? " AND u.username ~* '$filter'" : '').
    12011225        " ORDER BY $sortby $sortorder ".
    12021226        ($offset eq 'all' ? '' : " LIMIT $perpage OFFSET ".$offset*$perpage);
    1203 
    1204 #       " GROUP BY g.group_id, g.group_name, g2.group_name ".
    1205 #       ($offset eq 'all' ? '' : " LIMIT $perpage OFFSET ".$offset*$perpage));
    12061227
    12071228  $sth = $dbh->prepare($sql);
  • trunk/templates/lettsearch.tmpl

    r45 r53  
    1 <a href="<TMPL_VAR NAME=whereami>">All</a> |
     1<a href="<TMPL_VAR NAME=whereami>&amp;startwith=">All</a> |
    22<TMPL_UNLESS startnum><a href="<TMPL_VAR NAME=whereami>&amp;startwith=0-9">0-9</a><TMPL_ELSE><b>0-9</b></TMPL_UNLESS> |
    33<TMPL_UNLESS starta><a href="<TMPL_VAR NAME=whereami>&amp;startwith=a">A</a><TMPL_ELSE><b>A</b></TMPL_UNLESS> |
  • trunk/templates/sbox.tmpl

    r52 r53  
    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" />
    4 <input type="hidden" name="searchsubs" value="<TMPL_VAR NAME=searchsubs>">
     3<input type="hidden" name="searchsubs" value="n" />
     4Search subgroups: <input type="checkbox"<TMPL_IF searchsubs> checked="checked"</TMPL_IF> name="searchsubs" value="y" />
    55<input name="filter" value="<TMPL_VAR NAME=filter>" />
    66<input type="submit" value="Search" />
Note: See TracChangeset for help on using the changeset viewer.