[vhffs-dev] [1085] Group search works again.

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 1085
Author:   beuss
Date:     2007-11-17 09:09:06 +0000 (Sat, 17 Nov 2007)

Log Message:
-----------
Group search works again.
Validate page # when paginating (we need to factorize all that stuff).

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Panel/Group.pm
    trunk/vhffs-public/Makefile.am
    trunk/vhffs-public/allgroups.pl
    trunk/vhffs-public/allwebsites.pl
    trunk/vhffs-public/usersearch.pl


Modified: trunk/vhffs-api/src/Vhffs/Panel/Group.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Panel/Group.pm	2007-11-17 00:51:36 UTC (rev 1084)
+++ trunk/vhffs-api/src/Vhffs/Panel/Group.pm	2007-11-17 09:09:06 UTC (rev 1085)
@@ -111,6 +111,38 @@
     return $groups;
 }
 
+
+sub public_search {
+    my ($main, $groupname, $description, $start, $count) = @_;
+    my $result = {};
+
+    my $select_clause = 'SELECT g.gid, g.groupname, g.realname, o.description';
+    my $restriction = ' FROM vhffs_groups g LEFT OUTER JOIN vhffs_users u ON u.username=g.groupname INNER JOIN vhffs_object o ON o.object_id=g.object_id WHERE o.state = ? AND u.username IS NULL';
+    my @params;
+
+    if(defined $groupname) {
+        # groupnames are enforced in lowercase
+        $restriction .= ' AND g.groupname LIKE ?';
+        push @params, '%'.lc($groupname).'%';
+    }
+
+    if(defined $description) {
+        $restriction .= ' AND UPPER(description) LIKE UPPER(?)';
+        push @params, '%'.$description.'%';
+    }
+
+    my $order = " ORDER BY g.groupname LIMIT $count OFFSET $start";
+
+    my $dbh = $main->get_db_object;
+    my $sth = $dbh->prepare($select_clause.$restriction.$order);
+    my @users;
+    $sth->execute( Vhffs::Constants::ACTIVATED, @params );
+    $result->{groups} = fetch_groups_and_users($main, $select_clause.$restriction.$order, Vhffs::Constants::ACTIVATED, @params);
+    $select_clause = 'SELECT COUNT(*)';
+    ($result->{total_count}) = @{$dbh->selectrow_arrayref($select_clause.$restriction, undef, Vhffs::Constants::ACTIVATED, @params)};
+    return $result;
+}
+
 sub getall_groups_per_user
 {
 	my ( $user , $main ) = @_;

Modified: trunk/vhffs-public/Makefile.am
===================================================================
--- trunk/vhffs-public/Makefile.am	2007-11-17 00:51:36 UTC (rev 1084)
+++ trunk/vhffs-public/Makefile.am	2007-11-17 09:09:06 UTC (rev 1085)
@@ -7,6 +7,7 @@
 	allwebsites.pl \
 	getavatar.pl \
 	group.pl \
+	groupsearch.pl \
 	index.pl \
 	lastgroups.pl \
 	lastusers.pl \

Modified: trunk/vhffs-public/allgroups.pl
===================================================================
--- trunk/vhffs-public/allgroups.pl	2007-11-17 00:51:36 UTC (rev 1084)
+++ trunk/vhffs-public/allgroups.pl	2007-11-17 09:09:06 UTC (rev 1085)
@@ -58,7 +58,7 @@
 undef $letter if( $letter eq 'all');
 
 my $page = $cgi->param('page');
-$page = 1 unless(defined $page);
+$page = 1 unless(defined $page && int($page) > 0);
 my $per_page_count = 10;
 
 my $result = Vhffs::Panel::Group::get_groups_starting_with( $vhffs , $letter, ($page - 1) *  $per_page_count, $per_page_count);

Modified: trunk/vhffs-public/allwebsites.pl
===================================================================
--- trunk/vhffs-public/allwebsites.pl	2007-11-17 00:51:36 UTC (rev 1084)
+++ trunk/vhffs-public/allwebsites.pl	2007-11-17 09:09:06 UTC (rev 1085)
@@ -57,7 +57,7 @@
 undef $letter if ( $letter eq 'all' );
 
 my $page = $cgi->param('page');
-$page = 1 unless(defined $page);
+$page = 1 unless(defined $page && int($page) > 0);
 my $per_page_count = 20;
 
 my $res = Vhffs::Panel::Web::get_websites_starting_with( $vhffs, $letter, ($page - 1) * $per_page_count, $per_page_count);

Modified: trunk/vhffs-public/usersearch.pl
===================================================================
--- trunk/vhffs-public/usersearch.pl	2007-11-17 00:51:36 UTC (rev 1084)
+++ trunk/vhffs-public/usersearch.pl	2007-11-17 09:09:06 UTC (rev 1085)
@@ -57,7 +57,7 @@
 my $lastname = $cgi->param('lastname') || '';
 my $page = $cgi->param('page');
 my $per_page_count = 5;
-$page = 1 unless(defined $page);
+$page = 1 unless(defined $page && int($page) > 0);
 
 my $result = Vhffs::Panel::User::public_search(
     $vhffs,


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/