# use C4::Suggestions;
use C4::Members;
use C4::Log;
+use C4::SMS;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
return scalar( @$unsent_messages );
}
+=head2 GetRSSMessages
+
+=over 4
+
+my $message_list = GetRSSMessages( { limit => 10, borrowernumber => '14' } )
+
+returns a listref of all queued RSS messages for a particular person.
+
+=back
+
+=cut
+
+sub GetRSSMessages {
+ my $params = shift;
+
+ return unless $params;
+ return unless ref $params;
+ return unless $params->{'borrowernumber'};
+
+ return _get_unsent_messages( { message_transport_type => 'rss',
+ limit => $params->{'limit'},
+ borrowernumber => $params->{'borrowernumber'}, } );
+}
+
+=head2 GetQueuedMessages
+
+=over 4
+
+my $messages = GetQueuedMessage( { borrowernumber => '123', limit => 20 } );
+
+fetches messages out of the message queue.
+
+returns:
+list of hashes, each has represents a message in the message queue.
+
+=back
+
+=cut
+
+sub GetQueuedMessages {
+ my $params = shift;
+
+ my $dbh = C4::Context->dbh();
+ my $statement = << 'ENDSQL';
+SELECT message_id, borrowernumber, subject, content, message_transport_type, status, time_queued
+FROM message_queue
+ENDSQL
+
+ my @query_params;
+ my @whereclauses;
+ if ( exists $params->{'borrowernumber'} ) {
+ push @whereclauses, ' borrowernumber = ? ';
+ push @query_params, $params->{'borrowernumber'};
+ }
+
+ if ( @whereclauses ) {
+ $statement .= ' WHERE ' . join( 'AND', @whereclauses );
+ }
+
+ if ( defined $params->{'limit'} ) {
+ $statement .= ' LIMIT ? ';
+ push @query_params, $params->{'limit'};
+ }
+
+ my $sth = $dbh->prepare( $statement );
+ my $result = $sth->execute( @query_params );
+ my $messages = $sth->fetchall_arrayref({});
+ return $messages;
+}
+
sub _get_unsent_messages {
+ my $params = shift;
my $dbh = C4::Context->dbh();
my $statement = << 'ENDSQL';
-SELECT message_id, borrowernumber, subject, content, type, status, time_queued
+SELECT message_id, borrowernumber, subject, content, message_transport_type, status, time_queued
FROM message_queue
WHERE status = 'pending'
ENDSQL
+ my @query_params;
+ if ( ref $params ) {
+ if ( $params->{'message_transport_type'} ) {
+ $statement .= ' AND message_transport_type = ? ';
+ push @query_params, $params->{'message_transport_type'};
+ }
+ if ( $params->{'borrowernumber'} ) {
+ $statement .= ' AND borrowernumber = ? ';
+ push @query_params, $params->{'borrowernumber'};
+ }
+ if ( $params->{'limit'} ) {
+ $statement .= ' limit ? ';
+ push @query_params, $params->{'limit'};
+ }
+ }
+
my $sth = $dbh->prepare( $statement );
- my $result = $sth->execute();
+ my $result = $sth->execute( @query_params );
my $unsent_messages = $sth->fetchall_arrayref({});
return $unsent_messages;
}
--- /dev/null
+<?xml version="1.0"?>
+<rss version="2.0">
+ <channel>
+ <title></title>
+ <link></link>
+ <description></description>
+ <language></language>
+ <pubDate></pubDate>
+ <lastBuildDate></lastBuildDate>
+ <docs></docs>
+ <generator></generator>
+ <managingEditor></managingEditor>
+ <webMaster></webMaster>
+ <!-- TMPL_LOOP NAME="message_list" -->
+ <item>
+ <title><!-- TMPL_VAR ESCAPE=HTML NAME="subject" --></title>
+ <link><!-- TMPL_VAR ESCAPE=HTML NAME="title" --></link>
+ <description><!-- TMPL_VAR ESCAPE=HTML NAME="content"--></description>
+ <pubDate><!-- TMPL_VAR ESCAPE=HTML NAME="time_queued" --></pubDate>
+ <guid><!-- TMPL_VAR ESCAPE=HTML NAME="title" --></guid>
+ </item>
+ <!-- /TMPL_LOOP -->
+ </channel>
+</rss>
--- /dev/null
+#!/usr/bin/perl
+
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA 02111-1307 USA
+
+use strict;
+use warnings;
+require Exporter;
+use CGI;
+
+use C4::Auth;
+use C4::Context;
+use C4::Koha;
+use C4::Letters;
+use C4::Output;
+
+my $query = CGI->new();
+
+my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
+ {
+ template_name => 'opac-mymessages.tmpl',
+ query => $query,
+ type => 'opac',
+ authnotrequired => 0,
+ flagsrequired => { borrow => 1 },
+ debug => 1,
+ }
+);
+
+
+my $messages = C4::Letters::GetRSSMessages( { borrowernumber => $borrowernumber,
+ limit => 20 } );
+
+$template->param( message_list => $messages,
+ );
+
+output_html_with_http_headers $query, $cookie, $template->output;