Changeset 53 for trunk/dns.cgi
- Timestamp:
- 12/28/09 17:50:12 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dns.cgi
r52 r53 58 58 $session->param('reclistsortby','name'); 59 59 $session->param('reclistorder','ASC'); 60 # $session->param('filter','login'); 61 # $session->param('startwith','login'); 62 # $session->param('searchsubs','login'); 60 63 } 61 64 … … 63 66 my $curgroup = ($session->param('curgroup') ? $session->param('curgroup') : $logingroup); 64 67 my $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}); 71 my $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}); 75 my $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}); 80 my $searchsubs = $session->param('searchsubs'); 81 $searchsubs = ($searchsubs =~ /^$webvar{page}:searchsubs(.+)$/ ? $1 : ''); 65 82 66 83 # nrgh, can't handle login here because we don't have a database handle to check the user/pass with yet … … 721 738 # stuff for menu group change. nb: this is icky. 722 739 fill_grouplist("grouplist"); 740 741 ## set up "URL to self" 723 742 # @#$%@%@#% XHTML - & in a URL must be escaped. >:( 724 743 my $tmp_ruri = $ENV{REQUEST_URI}; 725 744 $tmp_ruri =~ s/\&([a-z])/\&\;$1/g; 745 726 746 # le sigh. and we need to strip any previous action 727 747 $tmp_ruri =~ s/\&action=[^&]+//g; 728 748 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/\&startwith=[a-z09-]+//g; 733 # search box webvars 734 $tmp_ruri =~ s/\&searchsubs=[a-z09-]+//g; 735 $tmp_ruri =~ s/\&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/\&startwith=[a-z09-]*(\&)?/$1/g; 754 $tmp_ruri =~ s/\&searchsubs=[a-z09-]*(\&)?/$1/g; 755 $tmp_ruri =~ s/\&filter=[a-z09-]*(\&)?/$1/g; 756 use warnings qw(uninitialized); 757 758 # fill in the URL-to-self 738 759 $page->param(whereami => $tmp_ruri); 739 760 } … … 974 995 sub listdomains { 975 996 976 ##fixme: $logingroup or $curgroup?997 ##fixme: $logingroup or $curgroup? 977 998 my @childgroups; 978 getChildren($dbh, $logingroup, \@childgroups, 'all') ;999 getChildren($dbh, $logingroup, \@childgroups, 'all') if $searchsubs; 979 1000 my $childlist = join(',',@childgroups); 980 1001 981 1002 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'" : ''); 984 1005 my $sth = $dbh->prepare($sql); 985 1006 $sth->execute; … … 1009 1030 1010 1031 # 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; 1014 1036 1015 1037 ##fixme … … 1023 1045 " WHERE domains.group_id IN ($logingroup".($childlist ? ",$childlist" : '').")". 1024 1046 ##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'" : ''). 1027 1049 " ORDER BY ".($sortby eq 'group' ? 'groups.group_name' : $sortby). 1028 1050 " $sortorder ".($offset eq 'all' ? '' : " LIMIT $perpage OFFSET ".$offset*$perpage); … … 1049 1071 1050 1072 sub listgroups { 1073 1051 1074 my @childgroups; 1052 getChildren($dbh, $logingroup, \@childgroups, 'all') ;1075 getChildren($dbh, $logingroup, \@childgroups, 'all') if $searchsubs; 1053 1076 my $childlist = join(',',@childgroups); 1054 1077 1055 1078 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'" : ''); 1058 1081 my $sth = $dbh->prepare($sql); 1059 1082 … … 1081 1104 $page->param("start$webvar{startwith}" => 1) if $webvar{startwith} && $webvar{startwith} =~ /^[a-z]$/; 1082 1105 1083 $page->param(filter => $webvar{filter}) if $webvar{filter}; 1106 $page->param(filter => $filter) if $filter; 1107 $page->param(searchsubs => $searchsubs) if $searchsubs; 1084 1108 1085 1109 # munge sortby for columns in database … … 1096 1120 "WHERE g.group_id IN ($logingroup".($childlist ? ",$childlist" : '').") ". 1097 1121 ##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'" : ''). 1100 1124 " GROUP BY g.group_id, g.group_name, g2.group_name ". 1101 1125 " ORDER BY $sortby $sortorder ". … … 1151 1175 1152 1176 my @childgroups; 1153 getChildren($dbh, $curgroup, \@childgroups, 'all') if $ webvar{searchsubs};1177 getChildren($dbh, $curgroup, \@childgroups, 'all') if $searchsubs; 1154 1178 my $childlist = join(',',@childgroups); 1155 1179 1156 1180 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'" : ''); 1159 1183 my $sth = $dbh->prepare($sql); 1160 1184 $sth->execute; … … 1180 1204 1181 1205 # 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; 1186 1210 1187 1211 # munge sortby for columns in database … … 1197 1221 "WHERE u.group_id IN ($curgroup".($childlist ? ",$childlist" : '').")". 1198 1222 ##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'" : ''). 1201 1225 " ORDER BY $sortby $sortorder ". 1202 1226 ($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));1206 1227 1207 1228 $sth = $dbh->prepare($sql);
Note:
See TracChangeset
for help on using the changeset viewer.