[vhffs-dev] [1083] Added pagination on websites list.

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


Revision: 1083
Author:   beuss
Date:     2007-11-16 20:55:29 +0000 (Fri, 16 Nov 2007)

Log Message:
-----------
Added pagination on websites list.

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Panel/Commons.pm
    trunk/vhffs-api/src/Vhffs/Panel/Web.pm
    trunk/vhffs-public/allwebsites.pl
    trunk/vhffs-public/templates/websiteslist.tmpl


Modified: trunk/vhffs-api/src/Vhffs/Panel/Commons.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Panel/Commons.pm	2007-11-15 12:07:07 UTC (rev 1082)
+++ trunk/vhffs-api/src/Vhffs/Panel/Commons.pm	2007-11-16 20:55:29 UTC (rev 1083)
@@ -119,7 +119,6 @@
         }
         $template->param( NEXT_PAGES => $pages );
 
-        $template->param( PAGES =>  );
         $template->param( PREVIOUS_PAGE => ($current_page - 1 < 1 ? 0 : $current_page - 1 ) );
         $template->param( NEXT_PAGE => ($current_page + 1 > $max_pages ? 0 : $current_page + 1 ) );
     }

Modified: trunk/vhffs-api/src/Vhffs/Panel/Web.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Panel/Web.pm	2007-11-15 12:07:07 UTC (rev 1082)
+++ trunk/vhffs-api/src/Vhffs/Panel/Web.pm	2007-11-16 20:55:29 UTC (rev 1083)
@@ -141,18 +141,21 @@
 }
 
 sub get_websites_starting_with {
-    my ($vhffs, $letter) = @_;
+    my ($vhffs, $letter, $start, $count) = @_;
 
     my @params;
-    my $sql = 'SELECT w.servername, g.groupname, o.description FROM vhffs_httpd w INNER JOIN vhffs_object o ON o.object_id = w.object_id INNER JOIN vhffs_groups g ON g.gid = o.owner_gid WHERE o.state = ?';
+    my $select = 'SELECT w.servername, g.groupname, o.description';
+    my $from = ' FROM vhffs_httpd w INNER JOIN vhffs_object o ON o.object_id = w.object_id INNER JOIN vhffs_groups g ON g.gid = o.owner_gid WHERE o.state = ?';
     push @params, Vhffs::Constants::ACTIVATED;
     if(defined $letter) {
-        $sql .= ' AND substr(w.servername, 1, 1) = ?';
+        $from .= ' AND substr(w.servername, 1, 1) = ?';
         push @params, $letter;
     }
-    $sql .= ' ORDER BY w.servername';
     my $dbh = $vhffs->get_db_object;
-    return $dbh->selectall_arrayref($sql, { Slice => {} }, @params);
+    my $result = {};
+    $result->{websites} = $dbh->selectall_arrayref($select.$from." ORDER BY w.servername LIMIT $count OFFSET $start", { Slice => {} }, @params);
+    ($result->{total_count}) = @{$dbh->selectrow_arrayref('SELECT COUNT(*)'.$from, undef, @params)};
+    return $result;
 }
 
 =head2 get_used_letters

Modified: trunk/vhffs-public/allwebsites.pl
===================================================================
--- trunk/vhffs-public/allwebsites.pl	2007-11-15 12:07:07 UTC (rev 1082)
+++ trunk/vhffs-public/allwebsites.pl	2007-11-16 20:55:29 UTC (rev 1083)
@@ -38,7 +38,7 @@
 use CGI;
 
 use lib '%VHFFS_LIB_DIR%';
-use Vhffs::Main;
+use Vhffs::Panel::Commons;
 use Vhffs::Panel::Main;
 use Vhffs::Panel::Template;
 use Vhffs::Panel::Web;
@@ -52,22 +52,26 @@
 
 $panel->check_public();
 
-my $template;
 my $letters = Vhffs::Panel::Web::get_used_letters($vhffs);
 my $letter = ( defined $cgi->param('letter') ? $cgi->param('letter') : (defined $letters->[0] ? $letters->[0]->{letter} : undef) );
 undef $letter if ( $letter eq 'all' );
-my $webs = Vhffs::Panel::Web::get_websites_starting_with( $vhffs, $letter );
-my $maintemplate;
+
+my $page = $cgi->param('page');
+$page = 1 unless(defined $page);
+my $per_page_count = 20;
+
+my $res = Vhffs::Panel::Web::get_websites_starting_with( $vhffs, $letter, ($page - 1) * $per_page_count, $per_page_count);
 my $hostname = $vhffs->get_config->get_host_name;
 
-$maintemplate = new Vhffs::Panel::Template( filename => $templatedir."/public/websiteslist.tmpl" );
+my $template = new Vhffs::Panel::Template( filename => $templatedir."/public/websiteslist.tmpl" );
 
+Vhffs::Panel::Commons::paginate($template, $page, $res->{total_count}, $per_page_count, {'letter' => (defined($letter) ? $letter : 'all') });
 
-$maintemplate->param( TEXT_TITLE => sprintf( gettext("All websites on %s") , $hostname ) );
-$maintemplate->param( LETTERS => $letters );
-$maintemplate->param( ALL => gettext('All') );
-$maintemplate->param( URL_PANEL => $vhffs->get_config->get_panel->{'url'} );
-$maintemplate->param( WEBSITES => $webs );
+$template->param( TEXT_TITLE => sprintf( gettext("All websites on %s") , $hostname ) );
+$template->param( LETTERS => $letters );
+$template->param( ALL => gettext('All') );
+$template->param( URL_PANEL => $vhffs->get_config->get_panel->{'url'} );
+$template->param( WEBSITES => $res->{websites} );
 
-$panel->light( $maintemplate );
+$panel->light( $template );
 $panel->display;

Modified: trunk/vhffs-public/templates/websiteslist.tmpl
===================================================================
--- trunk/vhffs-public/templates/websiteslist.tmpl	2007-11-15 12:07:07 UTC (rev 1082)
+++ trunk/vhffs-public/templates/websiteslist.tmpl	2007-11-16 20:55:29 UTC (rev 1083)
@@ -8,6 +8,7 @@
 </TMPL_LOOP>
 [<a href="/allwebsites.pl?letter=all"><TMPL_VAR ESCAPE=1 name="ALL"></a>]
 </p>
+<TMPL_INCLUDE NAME="misc/pagination.tmpl">
 <TMPL_IF NAME="WEBSITES">
 <TMPL_INCLUDE NAME="misc/web-part.tmpl">
 <TMPL_ELSE>


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