[vhffs-dev] [1817] No more HTML::Template for broadcast/list |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
Revision: 1817
Author: beuss
Date: 2011-05-26 14:21:08 +0200 (Thu, 26 May 2011)
Log Message:
-----------
No more HTML::Template for broadcast/list
Modified Paths:
--------------
trunk/vhffs-api/src/Vhffs/Makefile.am
trunk/vhffs-panel/admin/broadcast/list.pl
trunk/vhffs-panel/templates/Makefile.am
Added Paths:
-----------
trunk/vhffs-api/src/Vhffs/Panel/Mailings.pm
trunk/vhffs-panel/templates/admin/broadcast/list.tt
Removed Paths:
-------------
trunk/vhffs-panel/templates/admin/misc/broadcast_list.tmpl
trunk/vhffs-panel/templates/admin/misc/broadcast_part.tmpl
Modified: trunk/vhffs-api/src/Vhffs/Makefile.am
===================================================================
--- trunk/vhffs-api/src/Vhffs/Makefile.am 2011-05-26 12:21:00 UTC (rev 1816)
+++ trunk/vhffs-api/src/Vhffs/Makefile.am 2011-05-26 12:21:08 UTC (rev 1817)
@@ -29,6 +29,7 @@
Panel/Group.pm \
Panel/Mail.pm \
Panel/MailingList.pm \
+ Panel/Mailings.pm \
Panel/Main.pm \
Panel/Menu.pm \
Panel/Mercurial.pm \
Added: trunk/vhffs-api/src/Vhffs/Panel/Mailings.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Panel/Mailings.pm (rev 0)
+++ trunk/vhffs-api/src/Vhffs/Panel/Mailings.pm 2011-05-26 12:21:08 UTC (rev 1817)
@@ -0,0 +1,49 @@
+#!%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;
+
+package Vhffs::Panel::Mailings;
+
+sub list {
+ my ($main) = @_;
+
+ my $sql = 'SELECT id_mailing as id, subject, message as body, date, state '.
+ 'FROM vhffs_mailings m '.
+ 'ORDER BY m.date DESC';
+
+ my $dbh = $main->get_db_object();
+ return $dbh->selectall_arrayref($sql, { Slice => {} });
+}
+
+1;
+
Modified: trunk/vhffs-panel/admin/broadcast/list.pl
===================================================================
--- trunk/vhffs-panel/admin/broadcast/list.pl 2011-05-26 12:21:00 UTC (rev 1816)
+++ trunk/vhffs-panel/admin/broadcast/list.pl 2011-05-26 12:21:08 UTC (rev 1817)
@@ -32,7 +32,6 @@
use utf8;
use POSIX qw(locale_h);
-use HTML::Template;
use locale;
use Locale::gettext;
use CGI;
@@ -40,74 +39,26 @@
use strict;
use lib '%VHFFS_LIB_DIR%';
-use Vhffs::User;
-use Vhffs::Group;
-use Vhffs::Main;
-use Vhffs::Panel::Main;
-use Vhffs::Panel::Menu;
-use Vhffs::Constants;
-use Vhffs::Mailings;
+use Vhffs::Panel::Admin;
+use Vhffs::Panel::Mailings;
-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 $subtemplate;
-my $templatesdir = $vhffs->get_config->get_templatedir;
+my $vhffs = $panel->{vhffs};
-if( $user->is_admin != 1 )
-{
-
- $template = new HTML::Template( filename => $templatesdir."/panel/misc/simplemsg.tmpl" );
- my $message = gettext( "You are not allowed to see it");
- $template->param( MESSAGE => $message );
-}
-else
-{
- $template = new HTML::Template( filename => $templatesdir."/panel/admin/misc/broadcast_list.tmpl" );
- $template->param( TITLE => gettext("All mailings sent to hosted"));
- my $mailings = Vhffs::Mailings::getall( $vhffs );
- my $result;
- my $body;
- $result = "";
- foreach ( reverse sort keys %{$mailings} )
- {
- $subtemplate = new HTML::Template( filename => $templatesdir."/panel/admin/misc/broadcast_part.tmpl" );
- $body = $mailings->{$_}{'message'};
- ( $body ) = ( $body =~ /^(.{0,200}).*/ );
- $subtemplate->param( ID => $_ );
- $subtemplate->param( DATE => $mailings->{$_}{'date'} );
- $subtemplate->param( DELETE => gettext("Delete this mailing") );
- $subtemplate->param( VIEW => gettext("View this mailing") );
- $subtemplate->param( SUBJECT => $mailings->{$_}{'subject'} );
- $subtemplate->param( BODY => $body ."..." );
+my $vars = {};
+my $mailings = Vhffs::Panel::Mailings::list( $vhffs );
- if( $mailings->{$_}{'state'} == 3 )
- {
- $subtemplate->param( STATE => gettext("Awaiting sending") );
- }
- elsif( $mailings->{$_}{'state'} == 6 )
- {
- $subtemplate->param( STATE => gettext("Send") );
- }
- else
- {
- $subtemplate->param( STATE => gettext("Unknown status") );
- }
-
- $result .= $subtemplate->output;
- }
- $template->param( MAILINGS => $result );
-
+foreach my $m(@$mailings) {
+ if($m->{state} == 3) {
+ $m->{state} = gettext('Awaiting sending');
+ } elsif($m->{state} == 6) {
+ $m->{state} = gettext('Sent');
+ } else {
+ $m->{state} = gettext('Unknown');
+ }
}
-$panel->build( $template );
-$panel->display;
+$vars->{mailings} = $mailings;
+$panel->render('admin/broadcast/list.tt', $vars);
Modified: trunk/vhffs-panel/templates/Makefile.am
===================================================================
--- trunk/vhffs-panel/templates/Makefile.am 2011-05-26 12:21:00 UTC (rev 1816)
+++ trunk/vhffs-panel/templates/Makefile.am 2011-05-26 12:21:08 UTC (rev 1817)
@@ -3,8 +3,6 @@
admin/main/general-modo.tmpl \
admin/main/general.tmpl \
admin/main/main.tmpl \
- admin/misc/broadcast_list.tmpl \
- admin/misc/broadcast_part.tmpl \
admin/misc/broadcast_view.tmpl \
admin/misc/list.tmpl \
admin/misc/mailings_part.tmpl \
@@ -43,6 +41,7 @@
admin/group/list.tt \
admin/index.tt \
admin/broadcast/create.tt \
+ admin/broadcast/list.tt \
admin/misc/list.tt \
admin/misc/search.tt \
admin/object/edit.tt \
Added: trunk/vhffs-panel/templates/admin/broadcast/list.tt
===================================================================
--- trunk/vhffs-panel/templates/admin/broadcast/list.tt (rev 0)
+++ trunk/vhffs-panel/templates/admin/broadcast/list.tt 2011-05-26 12:21:08 UTC (rev 1817)
@@ -0,0 +1,38 @@
+[% USE date %]
+<h1>[% 'Mailings to hosted people' | i18n | html %]</h1>
+
+[% IF mailings.size() %]
+<table>
+<thead>
+ <tr>
+ <th>[% 'Date' | i18n | html %]</th>
+ <th>[% 'Subject' | i18n | html %]</th>
+ <th>[% 'Body' | i18n | html %]</th>
+ <th>[% 'State' | i18n | html %]</th>
+ <th>[% 'Action' | i18n | html %]</th>
+ </tr>
+</thead>
+<tbody>
+[% FOREACH m IN mailings %]
+<tr>
+ <td>[% date.format(m.date, '%x') %]</td>
+ <td>[% m.subject | html %]</td>
+ <td class="mainColumn">[% m.body | truncate(200) | html_para %]</td>
+ <td>[% m.state %]</td>
+ <td>
+ <form method="post" action="/admin/broadcast/delete.pl" accept-charset="utf-8">
+ <p><input type="hidden" name="ID" value="[% m.id %]" />
+ <input type="submit" value="[% 'Delete' | i18n | html %]" /></p>
+ </form>
+ <form method="post" action="/admin/broadcast/view.pl" accept-charset="utf-8">
+ <p><input type="hidden" name="ID" value="[% m.id %]" />
+ <input type="submit" value="[% 'View' | i18n | html %]" /></p>
+ </form>
+ </td>
+</tr>
+[% END %]
+</tbody>
+</table>
+[% ELSE %]
+<p>[% 'No mailing recorded.' | i18n | html %]</p>
+[% END %]
Deleted: trunk/vhffs-panel/templates/admin/misc/broadcast_list.tmpl
===================================================================
--- trunk/vhffs-panel/templates/admin/misc/broadcast_list.tmpl 2011-05-26 12:21:00 UTC (rev 1816)
+++ trunk/vhffs-panel/templates/admin/misc/broadcast_list.tmpl 2011-05-26 12:21:08 UTC (rev 1817)
@@ -1,3 +0,0 @@
-<h1><TMPL_VAR ESCAPE=1 NAME="TITLE"></h1>
-
-<TMPL_VAR ESCAPE=0 NAME="MAILINGS">
Deleted: trunk/vhffs-panel/templates/admin/misc/broadcast_part.tmpl
===================================================================
--- trunk/vhffs-panel/templates/admin/misc/broadcast_part.tmpl 2011-05-26 12:21:00 UTC (rev 1816)
+++ trunk/vhffs-panel/templates/admin/misc/broadcast_part.tmpl 2011-05-26 12:21:08 UTC (rev 1817)
@@ -1,27 +0,0 @@
-<table>
-<tr>
- <td>
- <TMPL_VAR ESCAPE=1 NAME="DATE">
- </td>
- <td>
- <TMPL_VAR ESCAPE=1 NAME="SUBJECT">
- </td>
- <td class="mainColumn">
- <TMPL_VAR ESCAPE=1 NAME="BODY">
- </td>
- <td>
- <TMPL_VAR ESCAPE=1 NAME="STATE">
- </td>
- <td>
- <form method="post" action="/admin/broadcast/delete.pl" accept-charset="utf-8">
- <input type="hidden" name="ID" value="<TMPL_VAR ESCAPE=1 NAME="ID">" />
- <input type="submit" value="<TMPL_VAR ESCAPE=1 NAME="DELETE">" />
- </form>
- <br/>
- <form method="post" action="/admin/broadcast/view.pl" accept-charset="utf-8">
- <input type="hidden" name="ID" value="<TMPL_VAR ESCAPE=1 NAME="ID">" />
- <input type="submit" value="<TMPL_VAR ESCAPE=1 NAME="VIEW">" />
- </form>
- </td>
-</tr>
-</table>