[vhffs-dev] [1063] Various -part.tmpl are more reusable.

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


Revision: 1063
Author:   beuss
Date:     2007-11-05 20:49:38 +0000 (Mon, 05 Nov 2007)

Log Message:
-----------
Various -part.tmpl are more reusable. allwebsites is working again.

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Panel/Web.pm
    trunk/vhffs-api/src/Vhffs/Services/Web.pm
    trunk/vhffs-public/allwebsites.pl
    trunk/vhffs-public/templates/allwebsites.tmpl
    trunk/vhffs-public/templates/group.tmpl
    trunk/vhffs-public/templates/misc/cvs-part.tmpl
    trunk/vhffs-public/templates/misc/git-part.tmpl
    trunk/vhffs-public/templates/misc/list-part.tmpl
    trunk/vhffs-public/templates/misc/svn-part.tmpl
    trunk/vhffs-public/templates/misc/web-part.tmpl


Modified: trunk/vhffs-api/src/Vhffs/Panel/Web.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Panel/Web.pm	2007-11-04 16:36:25 UTC (rev 1062)
+++ trunk/vhffs-api/src/Vhffs/Panel/Web.pm	2007-11-05 20:49:38 UTC (rev 1063)
@@ -125,8 +125,7 @@
 }
 
 
-sub create_web
-{
+sub create_web {
         my( $main, $servername, $description, $user, $group ) = @_;
 
         return undef if( !defined $user );
@@ -141,4 +140,36 @@
         return $web;
 }
 
+sub get_websites_starting_with {
+    my ($vhffs, $letter) = @_;
+
+    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 = ?';
+    push @params, Vhffs::Constants::ACTIVATED;
+    if(defined $letter) {
+        $sql .= ' 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);
+}
+
+=head2 get_used_letters
+
+Returns a reference on an array, each field is a hash with two fields
+letter and count (count is the number of websites starting with letter).
+0 site letters aren't stored.
+
+=cut
+
+sub get_used_letters {
+    my $main = shift;
+    my $sql = 'SELECT substr(servername, 1, 1) as letter, COUNT(*) as count FROM vhffs_httpd h INNER JOIN vhffs_object o ON o.object_id = h.object_id WHERE state = ? GROUP BY substr(servername, 1, 1) ORDER BY substr(servername, 1, 1)';
+    my $dbh = $main->get_db_object;
+    return $dbh->selectall_arrayref($sql, { Slice => {} }, Vhffs::Constants::ACTIVATED);
+
+}
+
+
 1;

Modified: trunk/vhffs-api/src/Vhffs/Services/Web.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Services/Web.pm	2007-11-04 16:36:25 UTC (rev 1062)
+++ trunk/vhffs-api/src/Vhffs/Services/Web.pm	2007-11-05 20:49:38 UTC (rev 1063)
@@ -180,44 +180,6 @@
     return $objs;
 }
 
-sub getall_by_letter
-{
-    my ($vhffs, $letter, $state) = @_;
-
-    return getall($vhffs, $state) if ( ! defined $letter );
-
-    $letter .= '%';
-
-    my $sql;
-    my @params;
-    my $sth;
-
-    my $objs = [];
-    my $result;
-
-    $sql = 'SELECT  h.httpd_id, h.servername, o.owner_uid, o.owner_gid, h.object_id, o.date_creation, o.description, o.state FROM vhffs_httpd h INNER JOIN vhffs_object o ON o.object_id = h.object_id WHERE h.servername LIKE ?';
-
-    push(@params, $letter);
-
-    if(defined $state) {
-        $sql .= 'AND o.state = ?';
-        push(@params, $state);
-    }
-    $sql .= 'ORDER BY servername';
-
-    $sth = $vhffs->get_db_object->prepare( $sql );
-    my $rows = $sth->execute(@params);
-
-    return undef unless($rows);
-
-    while( $result = $sth->fetchrow_arrayref )
-    {
-        push @{$objs}, _new Vhffs::Services::Web($vhffs, @{$result});
-    }
-    return $objs;
-}
-
-
 sub search
 {
     my ($vhffs, $state, $name) = @_;
@@ -314,24 +276,6 @@
 }
 
 
-=head2 get_used_letters
-
-Returns a reference on an array, each field is a hash with two fields
-letter and count (count is the number of websites starting with letter).
-0 site letters aren't stored.
-
-=cut
-
-sub get_used_letters {
-    my $main = shift;
-    my $state = shift;
-    $state = Vhffs::Constants::ACTIVATED unless(defined $state);
-    my $sql = 'SELECT substr(servername, 1, 1) as letter, COUNT(*) as count FROM vhffs_httpd h INNER JOIN vhffs_object o ON o.object_id = h.object_id WHERE state = ? GROUP BY substr(servername, 1, 1) ORDER BY substr(servername, 1, 1)';
-    my $dbh = $main->get_db_object;
-    return $dbh->selectall_arrayref($sql, { Slice => {} }, $state);
-
-}
-
 sub _new {
     my ($class, $main, $httpd_id, $servername, $owner_uid, $owner_gid, $oid, $date_creation, $description, $state) = @_;
 

Modified: trunk/vhffs-public/allwebsites.pl
===================================================================
--- trunk/vhffs-public/allwebsites.pl	2007-11-04 16:36:25 UTC (rev 1062)
+++ trunk/vhffs-public/allwebsites.pl	2007-11-05 20:49:38 UTC (rev 1063)
@@ -38,14 +38,10 @@
 use CGI;
 
 use lib '%VHFFS_LIB_DIR%';
-use Vhffs::User;
-use Vhffs::Group;
 use Vhffs::Main;
-use Vhffs::Acl;
-use Vhffs::Constants;
 use Vhffs::Panel::Main;
 use Vhffs::Panel::Template;
-use Vhffs::Services::Web;
+use Vhffs::Panel::Web;
 
 my $panel = new Vhffs::Panel::Main();
 exit 0 unless $panel;
@@ -57,14 +53,11 @@
 $panel->check_public();
 
 my $template;
-my $letters = Vhffs::Services::Web::get_used_letters($vhffs);
+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::Services::Web::getall_by_letter( $vhffs, $letter, Vhffs::Constants::ACTIVATED);
-my $output_final = "";	
-my $web;
+my $webs = Vhffs::Panel::Web::get_websites_starting_with( $vhffs, $letter );
 my $maintemplate;
-my $subtemplate;
 my $hostname = $vhffs->get_config->get_host_name;
 
 $maintemplate = new Vhffs::Panel::Template( filename => $templatedir."/public/allwebsites.tmpl" );
@@ -74,30 +67,7 @@
 $maintemplate->param( LETTERS => $letters );
 $maintemplate->param( ALL => gettext('All') );
 $maintemplate->param( URL_PANEL => $vhffs->get_config->get_panel->{'url'} );
+$maintemplate->param( WEBSITES => $webs );
 
-if( @{$webs} == 0 )
-{   
-    $maintemplate->param( MESSAGE => gettext('No webarea') );
-}
-
-my $output = "";
-    
-foreach $web (@{$webs})
-{
-
-    $template = new HTML::Template( filename => $templatedir."/public/misc/web-part.tmpl" );
-    
-    $template->param( SERVERNAME => $web->get_servername );
-    $template->param( TEXT_GROUPNAME => gettext("Owned by"));
-    $template->param( GROUPNAME => Vhffs::Group::get_name_by_gid( $vhffs , $web->get_owner_gid ) );
-    $template->param( DESCRIPTION => CGI::escapeHTML( $web->get_description ) );
-    
-   
-    $output .= $template->output;
-}
-
-
-$maintemplate->param( VALUES => $output );
-
 $panel->light( $maintemplate );
 $panel->display;

Modified: trunk/vhffs-public/templates/allwebsites.tmpl
===================================================================
--- trunk/vhffs-public/templates/allwebsites.tmpl	2007-11-04 16:36:25 UTC (rev 1062)
+++ trunk/vhffs-public/templates/allwebsites.tmpl	2007-11-05 20:49:38 UTC (rev 1063)
@@ -2,18 +2,19 @@
 
 <div id="public">
 <h1><TMPL_VAR NAME="TEXT_TITLE"></h1>
-<tmpl_if name="LETTERS">
+<TMPL_IF NAME="LETTERS">
 <p style="text-align:center">
-<tmpl_loop name="LETTERS">
-[<a href="/allwebsites.pl?letter=<tmpl_var name="letter">" title="<tmpl_var name="count">"><tmpl_var name="letter"></a>]&nbsp;
-</tmpl_loop>
-[<a href="/allwebsites.pl?letter=all"><tmpl_var name="ALL"></a>]
+<TMPL_LOOP name="LETTERS">
+[<a href="/allwebsites.pl?letter=<TMPL_VAR name="letter">" title="<TMPL_VAR name="count"> <TMPL_I18N KEY="website(s)">"><TMPL_VAR name="letter"></a>]&nbsp;
+</TMPL_LOOP>
+[<a href="/allwebsites.pl?letter=all"><TMPL_VAR name="ALL"></a>]
 </p>
-<tmpl_if name="MESSAGE">
-<p style="text-align:center;font-weight:bold;"><tmpl_var name="MESSAGE"></p>
-</tmpl_if>
-</tmpl_if>
-<ul>
-<tmpl_var escape=0 name="VALUES">
-</ul>
+</TMPL_IF>
+<TMPL_IF NAME="WEBSITES">
+<TMPL_INCLUDE NAME="misc/web-part.tmpl">
+<TMPL_ELSE>
+<p style="text-align:center;font-weight:bold;">
+<TMPL_I18N KEY="No websites">
+</p>
+</TMPL_IF>
 </div>

Modified: trunk/vhffs-public/templates/group.tmpl
===================================================================
--- trunk/vhffs-public/templates/group.tmpl	2007-11-04 16:36:25 UTC (rev 1062)
+++ trunk/vhffs-public/templates/group.tmpl	2007-11-05 20:49:38 UTC (rev 1063)
@@ -8,9 +8,30 @@
 <fieldset><legend><TMPL_I18N KEY="Description"></legend>
 <TMPL_VAR ESCAPE=1 NAME="VALUE_DESCRIPTION">
 </fieldset>
+
+<TMPL_IF NAME="WEBSITES">
+<h2><TMPL_I18N KEY="Websites for this group"></h2>
 <TMPL_INCLUDE NAME="misc/web-part.tmpl">
+</TMPL_IF>
+
+<TMPL_IF NAME="CVSREPOS">
+<h2><TMPL_I18N KEY="CVS Repositories for this group"></h2>
 <TMPL_INCLUDE NAME="misc/cvs-part.tmpl">
+</TMPL_IF>
+
+<TMPL_IF NAME="SVNREPOS">
+<h2><TMPL_I18N KEY="Subversion Repositories for this group"></h2>
 <TMPL_INCLUDE NAME="misc/svn-part.tmpl">
+</TMPL_IF>
+
+<TMPL_IF NAME="GITREPOS">
+<h2><TMPL_I18N KEY="GIT Repositories for this group"></h2>
 <TMPL_INCLUDE NAME="misc/git-part.tmpl">
+</TMPL_IF>
+
+<TMPL_IF NAME="LISTS">
+<h2><TMPL_I18N KEY="Mailing Lists for this group"></h2>
 <TMPL_INCLUDE NAME="misc/list-part.tmpl">
+</TMPL_IF>
+
 </div>

Modified: trunk/vhffs-public/templates/misc/cvs-part.tmpl
===================================================================
--- trunk/vhffs-public/templates/misc/cvs-part.tmpl	2007-11-04 16:36:25 UTC (rev 1062)
+++ trunk/vhffs-public/templates/misc/cvs-part.tmpl	2007-11-05 20:49:38 UTC (rev 1063)
@@ -1,8 +1,5 @@
-<TMPL_IF NAME="CVSREPOS">
-<h2><TMPL_I18N KEY="CVS Repositories for this Group"></h2>
 <ul>
 <TMPL_LOOP NAME="CVSREPOS">
 <li><a href="<TMPL_VAR NAME="WEBCVS">/<TMPL_VAR NAME="CVSROOT">"><tmpl_var name="CVSROOT"></a> &mdash; <tmpl_var name="DESCRIPTION"></li>
 </TMPL_LOOP>
 </ul>
-</TMPL_IF>

Modified: trunk/vhffs-public/templates/misc/git-part.tmpl
===================================================================
--- trunk/vhffs-public/templates/misc/git-part.tmpl	2007-11-04 16:36:25 UTC (rev 1062)
+++ trunk/vhffs-public/templates/misc/git-part.tmpl	2007-11-05 20:49:38 UTC (rev 1063)
@@ -1,12 +1,6 @@
-<TMPL_IF NAME="GITREPOS">
-<h2><TMPL_I18N KEY="Git Repositories for this group"></h2>
 <ul>
 <TMPL_LOOP NAME="GITREPOS">
 <li><a href="<TMPL_VAR NAME="WEBGIT">/<TMPL_VAR NAME="REPONAME">"><TMPL_VAR NAME="REPONAME"></a>
-<TMPL_IF NAME="GROUPNAME">
-&mdash; <TMPL_I18N KEY="Owned by"> <a href="group.pl?name=<tmpl_var name="GROUPNAME">"><tmpl_var name="GROUPNAME"></a>
-</TMPL_IF>
 &mdash; <TMPL_VAR NAME="DESCRIPTION"></li>
 </TMPL_LOOP>
 </ul>
-</TMPL_IF>

Modified: trunk/vhffs-public/templates/misc/list-part.tmpl
===================================================================
--- trunk/vhffs-public/templates/misc/list-part.tmpl	2007-11-04 16:36:25 UTC (rev 1062)
+++ trunk/vhffs-public/templates/misc/list-part.tmpl	2007-11-05 20:49:38 UTC (rev 1063)
@@ -1,5 +1,3 @@
-<TMPL_IF NAME="LISTS">
-<h2><TMPL_I18N KEY="Mailing lists for this group"></h2>
 <ul>
 <TMPL_LOOP NAME="LISTS">
 <li>
@@ -8,4 +6,3 @@
 </li>
 </TMPL_LOOP>
 </ul>
-</TMPL_IF>

Modified: trunk/vhffs-public/templates/misc/svn-part.tmpl
===================================================================
--- trunk/vhffs-public/templates/misc/svn-part.tmpl	2007-11-04 16:36:25 UTC (rev 1062)
+++ trunk/vhffs-public/templates/misc/svn-part.tmpl	2007-11-05 20:49:38 UTC (rev 1063)
@@ -1,5 +1,3 @@
-<TMPL_IF NAME="SVNREPOS">
-<h2><TMPL_I18N KEY="Subversion repositories for this group"></h2>
 <ul>
     <TMPL_LOOP NAME="SVNREPOS">
     <li><a href="<TMPL_VAR NAME="WEBSVN">/<TMPL_VAR NAME="REPONAME">"><TMPL_VAR NAME="REPONAME"></a>
@@ -9,5 +7,3 @@
     &mdash; <tmpl_var name="DESCRIPTION"></li>
     </TMPL_LOOP>
 </ul>
-</TMPL_IF>
-

Modified: trunk/vhffs-public/templates/misc/web-part.tmpl
===================================================================
--- trunk/vhffs-public/templates/misc/web-part.tmpl	2007-11-04 16:36:25 UTC (rev 1062)
+++ trunk/vhffs-public/templates/misc/web-part.tmpl	2007-11-05 20:49:38 UTC (rev 1063)
@@ -1,10 +1,11 @@
-<TMPL_IF NAME="WEBSITES">
-<h2><TMPL_VAR NAME="WEBSITES_TITLE"></h2>
 <ul>
 <TMPL_LOOP NAME="WEBSITES">
 <li>
-<a href="http://<tmpl_var name="SERVERNAME">"><tmpl_var name="SERVERNAME"></a> &mdash; <tmpl_var name="DESCRIPTION">
+<a href="http://<tmpl_var name="SERVERNAME">"><tmpl_var name="SERVERNAME"></a>
+<TMPL_IF NAME="GROUPNAME">
+&mdash; <TMPL_I18N KEY="Owned by"> <a href="/group.pl?name=<TMPL_VAR NAME="GROUPNAME">"><TMPL_VAR NAME="GROUPNAME"></a>
+</TMPL_IF>
+&mdash; <tmpl_var name="DESCRIPTION">
 </li>
 </TMPL_LOOP>
 </ul>
-</TMPL_IF>


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