[vhffs-dev] [1814] No more HTML::Template in admin/user/*

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


Revision: 1814
Author:   beuss
Date:     2011-05-26 14:20:42 +0200 (Thu, 26 May 2011)
Log Message:
-----------
No more HTML::Template in admin/user/*

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Panel/User.pm
    trunk/vhffs-panel/admin/user/list.pl
    trunk/vhffs-panel/admin/user/search.pl
    trunk/vhffs-panel/templates/Makefile.am

Added Paths:
-----------
    trunk/vhffs-panel/templates/admin/user/list.tt

Removed Paths:
-------------
    trunk/vhffs-panel/templates/admin/user/part.tmpl
    trunk/vhffs-panel/templates/admin/user/search.tmpl

Modified: trunk/vhffs-api/src/Vhffs/Panel/User.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Panel/User.pm	2011-05-25 11:19:02 UTC (rev 1813)
+++ trunk/vhffs-api/src/Vhffs/Panel/User.pm	2011-05-26 12:20:42 UTC (rev 1814)
@@ -105,28 +105,20 @@
 sub search {
 	my ($main, $name) = @_;
 
-	my $sql;
     my @params;
-    my $users = [];
+    my $sql = 'SELECT u.username, u.firstname || \' \' || u.lastname as realname, o.state '.
+        'FROM vhffs_users u '.
+        'INNER JOIN vhffs_object o ON (o.object_id = u.object_id) ';
 
     if( defined $name ) {
-        $sql = 'SELECT u.uid, u.username, u.firstname, u.lastname , o.state FROM vhffs_users u INNER JOIN vhffs_object o ON o.object_id = u.object_id WHERE u.username LIKE ? OR u.firstname ILIKE ? OR u.lastname ILIKE ?';
+        $sql .= 'WHERE u.username LIKE ? OR u.firstname ILIKE ? OR u.lastname ILIKE ? ';
         push(@params, '%'.lc($name).'%', '%'.$name.'%', '%'.$name.'%');
-	} else {
-        $sql = 'SELECT u.uid, u.username, u.firstname, u.lastname , o.state FROM vhffs_users u INNER JOIN vhffs_object o ON o.object_id = u.object_id';
 	}
 
-	my $dbh = $main->get_db_object();
-    my $sth = $dbh->prepare($sql);
-    return undef unless($sth->execute(@params));
+    $sql .= 'ORDER BY u.username';
 
-    while(my $u = $sth->fetchrow_hashref('NAME_lc')) {
-        $u->{state} = Vhffs::Functions::status_string_from_status_id($u->{state});
-        $u->{firstname} = $u->{firstname};
-        $u->{lastname} = $u->{lastname};
-        push(@$users, $u);
-    }
-    return $users;
+	my $dbh = $main->get_db_object();
+    return $dbh->selectall_arrayref($sql, { Slice => {} }, @params);
 }
 
 =head2 public_search

Modified: trunk/vhffs-panel/admin/user/list.pl
===================================================================
--- trunk/vhffs-panel/admin/user/list.pl	2011-05-25 11:19:02 UTC (rev 1813)
+++ trunk/vhffs-panel/admin/user/list.pl	2011-05-26 12:20:42 UTC (rev 1814)
@@ -31,59 +31,26 @@
 
 use strict;
 use utf8;
-use HTML::Template;
 use Locale::gettext;
 
 use lib '%VHFFS_LIB_DIR%';
-use Vhffs::Panel::Main;
+use Vhffs::Panel::Modo;
 use Vhffs::Panel::User;
 
-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 = {
+    type => 'user'
+};
 
-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} = sprintf( gettext('Search result for %s'), $name );
+} else {
+    $vars->{list_title} = gettext('List of all users');
 }
-else
-{
-	$template = new HTML::Template( filename => $templatedir.'/panel/admin/misc/list.tmpl' );
-	my $name = $cgi->param('NAME');
-	if( defined( $name ) )
-	{
-		$template->param( TITLE => gettext('Search result for').': '.$name );
-	}
-	else
-	{
-		$template->param( TITLE => gettext('List of all users') );
-	}
 
-	$template->param( TEXT_TITLE1 => gettext('Username') );
-	$template->param( TEXT_TITLE2 => gettext('Real Name') );
-	$template->param( TEXT_TITLE3 => gettext('State') );
-
-	my $users = Vhffs::Panel::User::search( $vhffs, $name );
-	if( defined $users )
-	{
-		my $subtemplate = new HTML::Template( filename => $templatedir.'/panel/admin/user/part.tmpl', global_vars => 1, die_on_bad_params => 0 );
-		if( $user->is_admin == 1 )  {
-			$subtemplate->param( ACTION => gettext('Modify') );
-		} else {
-			$subtemplate->param( ACTION => gettext('Show') );
-		}
-		$subtemplate->param( USERS => $users );
-		$template->param( LIST => $subtemplate->output );
-	}
-}
-
-$panel->build( $template );
-$panel->display;
+$vars->{users} = Vhffs::Panel::User::search( $vhffs, $name );
+$panel->render('admin/user/list.tt', $vars);

Modified: trunk/vhffs-panel/admin/user/search.pl
===================================================================
--- trunk/vhffs-panel/admin/user/search.pl	2011-05-25 11:19:02 UTC (rev 1813)
+++ trunk/vhffs-panel/admin/user/search.pl	2011-05-26 12:20:42 UTC (rev 1814)
@@ -32,7 +32,6 @@
 
 use utf8;
 use POSIX qw(locale_h);
-use HTML::Template;
 use locale;
 use Locale::gettext;
 use CGI;
@@ -41,42 +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::Modo;
 
-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 $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/user/search.tmpl" );
-
-	$template->param( TITLE => gettext("Search for an user") );
-
-}
-
-$panel->build( $template );
-$panel->display;
+$panel->render('admin/misc/search.tt', {
+    search_title => gettext('User search')
+});

Modified: trunk/vhffs-panel/templates/Makefile.am
===================================================================
--- trunk/vhffs-panel/templates/Makefile.am	2011-05-25 11:19:02 UTC (rev 1813)
+++ trunk/vhffs-panel/templates/Makefile.am	2011-05-26 12:20:42 UTC (rev 1814)
@@ -28,8 +28,6 @@
 	admin/tag/category/list.tmpl \
 	admin/tag/request/details.tmpl \
 	admin/tag/request/list.tmpl \
-	admin/user/part.tmpl \
-	admin/user/search.tmpl \
 	menu/context.tmpl \
 	menu/context-group.tmpl \
 	menu/context-modo.tmpl \
@@ -49,6 +47,7 @@
 	admin/misc/list.tt \
 	admin/misc/search.tt \
 	admin/object/edit.tt \
+	admin/user/list.tt \
 	anonymous/account_created.tt \
 	anonymous/login.tt \
 	anonymous/lost-password.tt \

Added: trunk/vhffs-panel/templates/admin/user/list.tt
===================================================================
--- trunk/vhffs-panel/templates/admin/user/list.tt	                        (rev 0)
+++ trunk/vhffs-panel/templates/admin/user/list.tt	2011-05-26 12:20:42 UTC (rev 1814)
@@ -0,0 +1,26 @@
+<h1>[% list_title | html %]</h1>
+
+[% IF users.size > 0 %]
+<table>
+    <thead>
+		<tr>
+			<th>[% 'Username' | i18n | html %]</th>
+			<th>[% 'Real Name' | i18n | html %]</th>
+			<th>[% 'State' | i18n | html %]</th>
+            <th>[% 'Preferences' | i18n | html %]</th>
+		</tr>
+    </thead>
+    <tbody>
+[% FOREACH u IN users %]
+        <tr>
+            <td>[% u.username | html %]</td>
+            <td>[% u.realname | html %]</td>
+            <td>[% u.state | stringify_status | html %]</td>
+            <td><a href="/user/prefs.pl?name=[% u.username %]">[% 'Preferences' | i18n | html %]</a></td>
+        </tr>
+[% END %]
+    </tbody>
+</table>
+[% ELSE %]
+<p>[% 'No user found' | i18n | html %]
+[% END %]

Deleted: trunk/vhffs-panel/templates/admin/user/part.tmpl
===================================================================
--- trunk/vhffs-panel/templates/admin/user/part.tmpl	2011-05-25 11:19:02 UTC (rev 1813)
+++ trunk/vhffs-panel/templates/admin/user/part.tmpl	2011-05-26 12:20:42 UTC (rev 1814)
@@ -1,16 +0,0 @@
-<TMPL_LOOP NAME="USERS">
-<tr>
-	<td>
-		<TMPL_VAR ESCAPE=1 NAME="USERNAME">
-	</td>
-	<td>
-		<TMPL_VAR ESCAPE=1 NAME="FIRSTNAME"> <TMPL_VAR ESCAPE=1 NAME="LASTNAME">
-	</td>
-	<td>
-		<TMPL_VAR ESCAPE=1 NAME="STATE"> 
-	</td>
-	<td>
-		<a href="/user/prefs.pl?admin_menu=1&amp;name=<TMPL_VAR ESCAPE=1 NAME="USERNAME">"><TMPL_VAR ESCAPE=1 NAME="ACTION"></a>
-	</td>
-</tr>
-</TMPL_LOOP>

Deleted: trunk/vhffs-panel/templates/admin/user/search.tmpl
===================================================================
--- trunk/vhffs-panel/templates/admin/user/search.tmpl	2011-05-25 11:19:02 UTC (rev 1813)
+++ trunk/vhffs-panel/templates/admin/user/search.tmpl	2011-05-26 12:20:42 UTC (rev 1814)
@@ -1,5 +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>


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