[vhffs-dev] [1074] I leave my computer 2 seconds and gradator commits for me...

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


Revision: 1074
Author:   beuss
Date:     2007-11-08 19:46:52 +0000 (Thu, 08 Nov 2007)

Log Message:
-----------
I leave my computer 2 seconds and gradator commits for me...

Added Paths:
-----------
    trunk/vhffs-public/usersearch.pl


Added: trunk/vhffs-public/usersearch.pl
===================================================================
--- trunk/vhffs-public/usersearch.pl	                        (rev 0)
+++ trunk/vhffs-public/usersearch.pl	2007-11-08 19:46:52 UTC (rev 1074)
@@ -0,0 +1,103 @@
+#!%PERL%
+# Copyright (c) vhffs project and its contributors
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without 
+# modification, are permitted provided that the following conditions 
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright 
+#   notice, this list of conditions and the following disclaimer.
+#2. Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in 
+#   the documentation and/or other materials provided with the 
+#   distribution.
+#3. Neither the name of vhffs nor the names of its contributors 
+#   may be used to endorse or promote products derived from this 
+#   software without specific prior written permission.
+#
+#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
+#"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
+#LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
+#FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+#COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+#INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
+#BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
+#LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
+#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
+# POSSIBILITY OF SUCH DAMAGE.
+
+use strict;
+use utf8;
+
+use POSIX qw(locale_h);
+use locale;
+use Locale::gettext;
+use CGI;
+
+use lib '%VHFFS_LIB_DIR%';
+use Vhffs::Panel::Main;
+use Vhffs::Panel::Template;
+
+my $panel = new Vhffs::Panel::Main();
+exit 0 unless $panel;
+
+my $vhffs = $panel->{'vhffs'};
+my $templatedir = $panel->{'templatedir'};
+my $cgi = $panel->{'cgi'};
+
+$panel->check_public();
+
+my $template = new Vhffs::Panel::Template( filename => $templatedir.'/public/userslist.tmpl', die_on_bad_params => 0 );
+my $username = $cgi->param('username');
+my $firstname = $cgi->param('firstname');
+my $lastname = $cgi->param('lastname');
+my $page = $cgi->param('page');
+my $per_page_count = 5;
+$page = 1 unless(defined $page);
+
+my $result = Vhffs::Panel::User::public_search(
+    $vhffs,
+    ( $username =~ /^\s*$/ ? undef : $username ),
+    ( $firstname =~ /^\s*$/ ? undef : $firstname ),
+    ( $lastname =~ /^\s*$/ ? undef : $lastname ),
+    ($page -1) * $per_page_count,
+    $per_page_count
+);
+
+$template->param( URL_PANEL => $vhffs->get_config->get_panel->{'url'} );
+
+if($result->{total_count} == 0) {
+    $template->param( TEXT_TITLE => gettext('No user found') );
+} else {
+    my $max_pages = int( ($result->{total_count} + ($per_page_count - 1)) / $per_page_count );
+    if($max_pages > 1) {
+        my @params;
+        push @params, 'username='.$username unless($username =~ /^\s*$/);
+        push @params, 'firstname='.$firstname unless($firstname =~ /^\s*$/);
+        push @params, 'lastname='.$lastname unless($lastname =~ /^\s*$/);
+        $template->param( SEARCH_CRITERIA => join('&', @params) );
+        $template->param( CURRENT_PAGE => $page );
+        $template->param( PAGES => paginate($page, $max_pages ) );
+        $template->param( PREVIOUS_PAGE => ($page - 1 < 1 ? 0 : $page - 1 ) );
+        $template->param( NEXT_PAGE => ($page + 1 > $max_pages ? 0 : $max_pages ) );
+    }
+    $template->param( TEXT_TITLE => sprintf( gettext('%d user(s) found'), $result->{total_count} ) );
+    $template->param( USERS => $result->{users} );
+}
+
+$panel->light( $template );
+$panel->display;
+
+sub paginate {
+    my ($page, $max_pages) = @_;
+    my $pages = ();
+    for(($page - 5 < 1 ? 1 : $page - 5)..($page + 5 > $max_pages ? $max_pages : $page + 5) ) {
+        push @$pages, { PAGE => $_ };
+    }
+    return $pages;
+}
+
+


Property changes on: trunk/vhffs-public/usersearch.pl
___________________________________________________________________
Name: svn:executable
   + *


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