Changeset 41 for trunk/dns.cgi
- Timestamp:
- 12/03/09 17:59:06 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dns.cgi
r39 r41 74 74 75 75 # NB: these must match the field name and SQL ascend/descend syntax respectively 76 my $sort field = "domains";77 my $sortorder = " asc";76 my $sortby = "domain"; 77 my $sortorder = "ASC"; 78 78 79 79 my ($dbh,$msg) = connectDB("dnsdb","dnsdb","secret","dbhost"); … … 663 663 # le sigh. and we need to strip any previous action 664 664 $tmp_ruri =~ s/\&action=[^&]+//g; 665 # and any bits from the "starts with" letter block - (ab)using this widget 666 # to fill the bulk of the URI so the template doesn't grow to insanity 667 $tmp_ruri =~ s/\&startwith=[a-z09-]+//g; 665 668 # $page->param(whereami => $ENV{REQUEST_URI}); 666 669 $page->param(whereami => $tmp_ruri); … … 860 863 ##fixme 861 864 if ($offset eq 'all') { 862 push @debugbits, "foo! wanna see'em all\n"; 865 # uhm.... 863 866 } else { 864 867 # all these bits only have sensible behaviour if offset is numeric. err, probably. … … 901 904 902 905 sub listdomains { 906 907 ##fixme: account for searches and starts-with filters 903 908 my $sth = $dbh->prepare("SELECT count(*) FROM domains WHERE group_id=?"); 904 909 $sth->execute($curgroup); … … 910 915 fill_fpnla($count); 911 916 912 ##fixme - group 917 # sort/order 918 $sortby= $webvar{sortby} if $webvar{sortby}; 919 $sortorder = $webvar{order} if $webvar{order}; 920 921 if ($sortby eq 'domain') { 922 $page->param(domorder => ($sortorder eq 'ASC' ? 'DESC' : 'ASC')); 923 $page->param(statorder => 'ASC'); 924 $page->param(grporder => 'ASC'); 925 $page->param(sortdomain => 1); 926 } elsif ($sortby eq 'status') { 927 $page->param(domorder => 'ASC'); 928 $page->param(statorder => ($sortorder eq 'ASC' ? 'DESC' : 'ASC')); 929 $page->param(grporder => 'ASC'); 930 $page->param(sortstatus => 1); 931 } elsif ($sortby eq 'group') { 932 $page->param(domorder => 'ASC'); 933 $page->param(statorder => 'ASC'); 934 $page->param(grporder => ($sortorder eq 'ASC' ? 'DESC' : 'ASC')); 935 $page->param(sortgroup => 1); 936 } else { 937 $page->param(domorder => 'ASC'); 938 $page->param(statorder => 'ASC'); 939 $page->param(grporder => 'ASC'); 940 } 941 942 $page->param(sortorder => $sortorder); 943 # hack! hack! pthbttt. have to rethink the status column storage, 944 # or inactive comes "before" active. *sigh* 945 $sortorder = ($sortorder eq 'ASC' ? 'DESC' : 'ASC') if $sortby eq 'status'; 946 947 $page->param("start$webvar{startwith}" => 1) if $webvar{startwith} && $webvar{startwith} =~ /^[a-z]$/; 948 949 $page->param(filter => $webvar{filter}) if $webvar{filter}; 950 951 ##fixme 952 ##fixme push the SQL and direct database fiddling off into a sub in DNSDB.pm 953 ##fixme 954 913 955 $page->param(group => $curgroup); 914 956 my @domlist; 915 $sth = $dbh->prepare("SELECT domain_id,domain,status,groups.group_nameFROM domains".957 my $sql = "SELECT domain_id,domain,status,groups.group_name AS group FROM domains". 916 958 " INNER JOIN groups ON domains.group_id=groups.group_id". 917 959 " WHERE domains.group_id=?". 918 " ORDER BY domain".($offset eq 'all' ? '' : " LIMIT $perpage OFFSET ".$offset*$perpage)); 960 ##fixme: don't do variable subs in SQL, use placeholders and params in ->execute() 961 (defined($webvar{startwith}) ? " AND domain ~* '^[$webvar{startwith}]'" : ''). 962 (defined($webvar{filter}) ? " AND domain ~* '$webvar{filter}'" : ''). 963 " ORDER BY ".($sortby eq 'group' ? 'groups.group_name' : $sortby). 964 " $sortorder ".($offset eq 'all' ? '' : " LIMIT $perpage OFFSET ".$offset*$perpage); 965 $sth = $dbh->prepare($sql); 919 966 $sth->execute($curgroup); 920 967 my $rownum = 0; … … 1029 1076 my $rownum = 0; 1030 1077 while (my @data = $sth->fetchrow_array) { 1078 no warnings "uninitialized"; # Just In Case something stupid happens and a user gets no first or last name 1031 1079 my %row; 1032 1080 $row{userid} = $data[0];
Note:
See TracChangeset
for help on using the changeset viewer.