[vhffs-dev] [1815] No more HTML::Template in admin/group |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
Revision: 1815
Author: beuss
Date: 2011-05-26 14:20:51 +0200 (Thu, 26 May 2011)
Log Message:
-----------
No more HTML::Template in admin/group
Modified Paths:
--------------
trunk/vhffs-api/src/Vhffs/Panel/Group.pm
trunk/vhffs-panel/admin/group/list.pl
trunk/vhffs-panel/admin/group/search.pl
trunk/vhffs-panel/admin/user/list.pl
trunk/vhffs-panel/templates/Makefile.am
Added Paths:
-----------
trunk/vhffs-panel/templates/admin/group/list.tt
Removed Paths:
-------------
trunk/vhffs-panel/templates/admin/group/part.tmpl
trunk/vhffs-panel/templates/admin/group/search.tmpl
Modified: trunk/vhffs-api/src/Vhffs/Panel/Group.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Panel/Group.pm 2011-05-26 12:20:42 UTC (rev 1814)
+++ trunk/vhffs-api/src/Vhffs/Panel/Group.pm 2011-05-26 12:20:51 UTC (rev 1815)
@@ -36,7 +36,6 @@
use DBI;
use POSIX qw(locale_h);
-use HTML::Template;
use locale;
use Locale::gettext;
use CGI;
@@ -88,27 +87,24 @@
sub search
{
my ($main, $name) = @_;
- my $sql;
+
my @params;
- my $groups = [];
+ my $sql = 'SELECT g.groupname, o.state, u.username as owner_user '.
+ 'FROM vhffs_groups g '.
+ 'INNER JOIN vhffs_object o ON (g.object_id = o.object_id) '.
+ 'INNER JOIN vhffs_users u ON (u.uid = o.owner_uid) '.
+ 'LEFT JOIN vhffs_users uu ON (uu.username = g.groupname) '.
+ 'WHERE uu.username IS NULL ';
if( defined $name ) {
- $sql = 'SELECT g.groupname, o.state, u.username FROM vhffs_groups g INNER JOIN vhffs_object o ON g.object_id = o.object_id INNER JOIN vhffs_users u ON u.uid = o.owner_uid WHERE g.groupname LIKE ?';
+ $sql .= ' AND g.groupname LIKE ? ';
push(@params, '%'.lc($name).'%');
- } else {
- $sql = 'SELECT g.groupname, o.state, u.username FROM vhffs_groups g INNER JOIN vhffs_object o ON g.object_id = o.object_id INNER JOIN vhffs_users u ON u.uid = o.owner_uid WHERE g.groupname NOT IN ( SELECT username FROM vhffs_users )';
}
- my $dbh = $main->get_db_object();
- my $sth = $dbh->prepare( $sql ) or return undef;
- return undef unless ( $sth->execute(@params) );
+ $sql .= 'ORDER BY g.groupname';
- while(my $g = $sth->fetchrow_hashref('NAME_lc')) {
- $g->{state} = Vhffs::Functions::status_string_from_status_id($g->{state});
- push(@$groups, $g);
- }
-
- return $groups;
+ my $dbh = $main->get_db_object();
+ return $dbh->selectall_arrayref($sql, { Slice => {} }, @params);
}
Modified: trunk/vhffs-panel/admin/group/list.pl
===================================================================
--- trunk/vhffs-panel/admin/group/list.pl 2011-05-26 12:20:42 UTC (rev 1814)
+++ trunk/vhffs-panel/admin/group/list.pl 2011-05-26 12:20:51 UTC (rev 1815)
@@ -8,23 +8,23 @@
#
# 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.
+# 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
+# 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.
@@ -32,69 +32,27 @@
use strict;
use utf8;
use POSIX qw(locale_h);
-use HTML::Template;
use locale;
use Locale::gettext;
use CGI;
use CGI::Session;
use lib '%VHFFS_LIB_DIR%';
-use Vhffs::User;
-use Vhffs::Group;
-use Vhffs::Main;
-use Vhffs::Panel::Main;
-use Vhffs::Panel::Menu;
+use Vhffs::Panel::Modo;
use Vhffs::Panel::Group;
-use Vhffs::Stats;
-use Vhffs::Constants;
-my $panel = new Vhffs::Panel::Main();
-exit 0 unless $panel;
-my $session = $panel->get_session;
-exit 0 unless $session;
+my $panel = new Vhffs::Panel::Modo();
my $vhffs = $panel->{'vhffs'};
-my $user = $panel->{'user'};
my $cgi = $panel->{'cgi'};
-my $templatedir = $panel->{'templatedir'};
-my $template;
+my $name = $cgi->param('NAME');
+my $vars = {};
-if( ($user->is_moderator != 1 ) && ( $user->is_admin != 1 ) )
-{
- $template = new HTML::Template( filename => $templatedir.'/panel/misc/simplemsg.tmpl' );
- $template->param( MESSAGE => gettext('You are not allowed to see it') );
+if( ! defined $name) {
+ $vars->{list_title} = gettext('List of all groups');
+} else {
+ $vars->{list_title} = sprintf( gettext('Search result for group %s'), $name);
}
-else
-{
- $template = new HTML::Template( filename => $templatedir.'/panel/admin/misc/list.tmpl' );
- my $name = $cgi->param('NAME');
- if( ! defined $name)
- {
- $template->param( TITLE => gettext('List of all groups') );
- }
- else
- {
- $template->param( TITLE => gettext('Search result') );
- }
- $template->param( TEXT_TITLE1 => gettext('Groupname') );
- $template->param( TEXT_TITLE2 => gettext('Owner name') );
- $template->param( TEXT_TITLE3 => gettext('State') );
-
- my $groups = Vhffs::Panel::Group::search( $vhffs, $name );
- if( defined $groups )
- {
- my $subtemplate = new HTML::Template( filename => $templatedir.'/panel/admin/group/part.tmpl', global_vars => 1 );
- if( $user->is_admin == 1 ) {
- $subtemplate->param( ACTION => gettext('Modify') );
- } else {
- $subtemplate->param( ACTION => gettext('Show') );
- }
-
- $subtemplate->param( GROUPS => $groups );
- $template->param( LIST => $subtemplate->output );
- }
-}
-
-$panel->build( $template );
-$panel->display;
+$vars->{groups} = Vhffs::Panel::Group::search( $vhffs, $name );
+$panel->render('admin/group/list.tt', $vars);
Modified: trunk/vhffs-panel/admin/group/search.pl
===================================================================
--- trunk/vhffs-panel/admin/group/search.pl 2011-05-26 12:20:42 UTC (rev 1814)
+++ trunk/vhffs-panel/admin/group/search.pl 2011-05-26 12:20:51 UTC (rev 1815)
@@ -32,7 +32,6 @@
use utf8;
use POSIX qw(locale_h);
-use HTML::Template;
use locale;
use Locale::gettext;
use CGI;
@@ -41,43 +40,10 @@
use lib '%VHFFS_LIB_DIR%';
-use Vhffs::User;
-use Vhffs::Group;
-use Vhffs::Main;
-use Vhffs::Panel::Main;
-use Vhffs::Panel::Menu;
-use Vhffs::Stats;
-use Vhffs::Constants;
+use Vhffs::Panel::Admin;
-my $panel = new Vhffs::Panel::Main();
-exit 0 unless $panel;
-my $session = $panel->get_session;
-exit 0 unless $session;
+my $panel = new Vhffs::Panel::Admin();
-my $vhffs = $panel->{'vhffs'};
-my $maintemplate = $panel->{'template'};
-my $user = $panel->{'user'};
-my $cgi = $panel->{'cgi'};
-my $servername = $cgi->param("name");
-my $template;
-
-my $templatedir = $vhffs->get_config->get_templatedir;
-
-if( ($user->is_moderator != 1 ) && ( $user->is_admin != 1 ) )
-{
-
- $template = new HTML::Template( filename => $templatedir."/panel/misc/simplemsg.tmpl" );
- my $message = gettext( "You are not allowed to see it");
- $template->param( MESSAGE => $message );
-}
-else
-{
- $template = new HTML::Template( filename => $templatedir."/panel/admin/group/search.tmpl" );
-
- $template->param( TITLE => gettext("Search for a group") );
-
-}
-
-
-$panel->build( $template );
-$panel->display;
+$panel->render('admin/misc/search.tt', {
+ search_title => gettext('Group search')
+});
Modified: trunk/vhffs-panel/admin/user/list.pl
===================================================================
--- trunk/vhffs-panel/admin/user/list.pl 2011-05-26 12:20:42 UTC (rev 1814)
+++ trunk/vhffs-panel/admin/user/list.pl 2011-05-26 12:20:51 UTC (rev 1815)
@@ -42,9 +42,7 @@
my $vhffs = $panel->{'vhffs'};
my $cgi = $panel->{'cgi'};
my $name = $cgi->param('NAME');
-my $vars = {
- type => 'user'
-};
+my $vars = {};
if( defined( $name ) ) {
$vars->{list_title} = sprintf( gettext('Search result for %s'), $name );
Modified: trunk/vhffs-panel/templates/Makefile.am
===================================================================
--- trunk/vhffs-panel/templates/Makefile.am 2011-05-26 12:20:42 UTC (rev 1814)
+++ trunk/vhffs-panel/templates/Makefile.am 2011-05-26 12:20:51 UTC (rev 1815)
@@ -1,7 +1,5 @@
paneltemplatesdir = @TEMPLATESDIR@/panel
nobase_dist_paneltemplates_DATA = \
- admin/group/part.tmpl \
- admin/group/search.tmpl \
admin/main/general-modo.tmpl \
admin/main/general.tmpl \
admin/main/main.tmpl \
@@ -43,6 +41,7 @@
misc/simplemsg.tmpl \
acl/form.tt \
acl/view.tt \
+ admin/group/list.tt \
admin/index.tt \
admin/misc/list.tt \
admin/misc/search.tt \
Added: trunk/vhffs-panel/templates/admin/group/list.tt
===================================================================
--- trunk/vhffs-panel/templates/admin/group/list.tt (rev 0)
+++ trunk/vhffs-panel/templates/admin/group/list.tt 2011-05-26 12:20:51 UTC (rev 1815)
@@ -0,0 +1,26 @@
+<h1>[% list_title | html %]</h1>
+
+[% IF groups.size > 0 %]
+<table>
+ <thead>
+ <tr>
+ <th>[% 'Groupname' | i18n | html %]</th>
+ <th>[% 'Owner user' | i18n | html %]</th>
+ <th>[% 'State' | i18n | html %]</th>
+ <th>[% 'Preferences' | i18n | html %]</th>
+ </tr>
+ </thead>
+ <tbody>
+[% FOREACH g IN groups %]
+ <tr>
+ <td>[% g.groupname | html %]</td>
+ <td>[% g.owner_user | html %]</td>
+ <td>[% g.state | stringify_status | html %]</td>
+ <td><a href="/group/prefs.pl?group=[% g.groupname | html %]">[% 'Preferences' | i18n | html %]</a></td>
+ </tr>
+[% END %]
+ </tbody>
+</table>
+[% ELSE %]
+<p>[% 'No group found' | i18n | html %]
+[% END %]
Deleted: trunk/vhffs-panel/templates/admin/group/part.tmpl
===================================================================
--- trunk/vhffs-panel/templates/admin/group/part.tmpl 2011-05-26 12:20:42 UTC (rev 1814)
+++ trunk/vhffs-panel/templates/admin/group/part.tmpl 2011-05-26 12:20:51 UTC (rev 1815)
@@ -1,16 +0,0 @@
-<TMPL_LOOP NAME="GROUPS">
-<tr>
- <td>
- <TMPL_VAR ESCAPE=1 NAME="GROUPNAME">
- </td>
- <td>
- <TMPL_VAR ESCAPE=1 NAME="USERNAME">
- </td>
- <td>
- <TMPL_VAR ESCAPE=1 NAME="STATE">
- </td>
- <td>
- <a href="/group/prefs.pl?admin_menu=1&group=<TMPL_VAR ESCAPE=1 NAME="GROUPNAME">"><TMPL_VAR ESCAPE=1 NAME="ACTION"></a>
- </td>
-</tr>
-</TMPL_LOOP>
Deleted: trunk/vhffs-panel/templates/admin/group/search.tmpl
===================================================================
--- trunk/vhffs-panel/templates/admin/group/search.tmpl 2011-05-26 12:20:42 UTC (rev 1814)
+++ trunk/vhffs-panel/templates/admin/group/search.tmpl 2011-05-26 12:20:51 UTC (rev 1815)
@@ -1,4 +0,0 @@
- <h1><TMPL_VAR ESCAPE=1 NAME="TITLE"></h1>
- <form method="post" action="list.pl" accept-charset="utf-8">
- <input type="text" name="NAME" value=""/>
- </form>