From bfebda4ad9ea0cf50497cd8eebbaeeb9fac2a0e1 Mon Sep 17 00:00:00 2001 From: Nahuel ANGELINETTI Date: Mon, 12 Jan 2009 10:36:31 +0100 Subject: [PATCH] (bug #2908) adding send shelf by e-mail feature This patch add the form for sending shelf by e-mail, and add a button in shelves that allow the user to send a shelf. It's an approximate copy of the send basket feature. Signed-off-by: Galen Charlton --- C4/VirtualShelves.pm | 10 +- .../prog/en/modules/opac-sendshelf.tmpl | 54 ++++++ .../prog/en/modules/opac-sendshelfform.tmpl | 38 ++++ .../prog/en/modules/opac-shelves.tmpl | 9 +- opac/opac-sendshelf.pl | 173 ++++++++++++++++++ 5 files changed, 277 insertions(+), 7 deletions(-) create mode 100644 koha-tmpl/opac-tmpl/prog/en/modules/opac-sendshelf.tmpl create mode 100644 koha-tmpl/opac-tmpl/prog/en/modules/opac-sendshelfform.tmpl create mode 100755 opac/opac-sendshelf.pl diff --git a/C4/VirtualShelves.pm b/C4/VirtualShelves.pm index 3a9efd03f4..b3e5b26ced 100644 --- a/C4/VirtualShelves.pm +++ b/C4/VirtualShelves.pm @@ -252,7 +252,7 @@ from C4::Circulation. =cut -sub GetShelfContents ($$;$$) { +sub GetShelfContents ($;$$$) { my ($shelfnumber, $row_count, $offset, $sortfield) = @_; my $dbh=C4::Context->dbh(); my $sth1 = $dbh->prepare("SELECT count(*) FROM virtualshelfcontents WHERE shelfnumber = ?"); @@ -277,9 +277,11 @@ sub GetShelfContents ($$;$$) { $query .= " DESC " if ($sortfield eq 'copyrightdate'); push (@params, $sortfield); } - $query .= " LIMIT ?, ? "; - push (@params, ($offset ? $offset : 0)); - push (@params, $row_count); + if($row_count){ + $query .= " LIMIT ?, ? "; + push (@params, ($offset ? $offset : 0)); + push (@params, $row_count); + } my $sth3 = $dbh->prepare($query); $sth3->execute(@params); return ($sth3->fetchall_arrayref({}), $total); diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-sendshelf.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-sendshelf.tmpl new file mode 100644 index 0000000000..0131efb65f --- /dev/null +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-sendshelf.tmpl @@ -0,0 +1,54 @@ + +Your Shelf : + + +
+Hi, + +Here is your shelf called , sent from our Online Catalog. + +Please note that the attached file is a MARC biblographic records file +which can be imported into a Personal Bibliographic Software like EndNote, +Reference Manager or ProCite. + + + +--------------------------------------------- + + + + + + + + + + + + + + Authors: + + + + +ISBN: + + +Published by: in , , +Collection: +Subject: +Copyright year: +Notes : +Unified title: +Serial: +Dewey: +Classification: +LCCN: +URL : +Items : + () + +--------------------------------------------- + + diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-sendshelfform.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-sendshelfform.tmpl new file mode 100644 index 0000000000..0b73b3e57a --- /dev/null +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-sendshelfform.tmpl @@ -0,0 +1,38 @@ +Koha Online Catalog › Sending Your Shelf + + + +
+ + +

Message Sent

+

The shelf was sent to:

+

Close window

+ + +

Problem sending the shelf...

+ + + + +
" method="post"> + +
+Sending your shelf +
  1. + + +
  2. +
  3. + + +
  4. +
  5. + " /> +
+
Cancel
+
+ +
+ + diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-shelves.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-shelves.tmpl index 1dfbb70a1e..d288c83086 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-shelves.tmpl +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-shelves.tmpl @@ -81,7 +81,7 @@ $.tablesorter.addParser({ -
+
" /> @@ -218,7 +219,7 @@ $.tablesorter.addParser({ Public Open - + " /> @@ -238,6 +239,7 @@ $.tablesorter.addParser({
  + ','win_form','dependant=yes,scrollbars=no,resizable=no,height=300,width=450,top=50,left=100')">Send shelf @@ -267,7 +269,7 @@ $.tablesorter.addParser({ Public Open - +
" /> @@ -285,6 +287,7 @@ $.tablesorter.addParser({
  + ','win_form','dependant=yes,scrollbars=no,resizable=no,height=300,width=450,top=50,left=100')">Send shelf diff --git a/opac/opac-sendshelf.pl b/opac/opac-sendshelf.pl new file mode 100755 index 0000000000..340a41c151 --- /dev/null +++ b/opac/opac-sendshelf.pl @@ -0,0 +1,173 @@ +#!/usr/bin/perl + +# Copyright 2009 SARL Biblibre +# +# 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; + +use CGI; +use Encode qw(encode); + +use Mail::Sendmail; +use MIME::QuotedPrint; +use MIME::Base64; +use C4::Auth; +use C4::Biblio; +use C4::Items; +use C4::Output; +use C4::VirtualShelves; + +my $query = new CGI; + +my ( $template, $borrowernumber, $cookie ) = get_template_and_user ( + { + template_name => "opac-sendshelfform.tmpl", + query => $query, + type => "opac", + authnotrequired => 1, + flagsrequired => { borrow => 1 }, + } +); + +my $shelfid = $query->param('shelfid'); +my $email = $query->param('email'); + +my $dbh = C4::Context->dbh; + +if ( $email ) { + my $email_from = C4::Context->preference('KohaAdminEmailAddress'); + my $comment = $query->param('comment'); + + my %mail = ( + To => $email, + From => $email_from + ); + + my ( $template2, $borrowernumber, $cookie ) = get_template_and_user( + { + template_name => "opac-sendshelf.tmpl", + query => $query, + type => "opac", + authnotrequired => 1, + flagsrequired => { borrow => 1 }, + } + ); + + my @shelf = GetShelf($shelfid); + my ($items, $totitems) = GetShelfContents($shelfid); + my $marcflavour = C4::Context->preference('marcflavour'); + my $iso2709; + my @results; + + # retrieve biblios from shelf + foreach my $biblio (@$items) { + my $biblionumber = $biblio->{biblionumber}; + + my $dat = GetBiblioData($biblionumber); + my $record = GetMarcBiblio($biblionumber); + my $marcnotesarray = GetMarcNotes( $record, $marcflavour ); + my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); + my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); + + my @items = &GetItemsInfo( $biblionumber, 'opac' ); + + $dat->{MARCNOTES} = $marcnotesarray; + $dat->{MARCSUBJCTS} = $marcsubjctsarray; + $dat->{MARCAUTHORS} = $marcauthorsarray; + $dat->{'biblionumber'} = $biblionumber; + $dat->{ITEM_RESULTS} = \@items; + + $iso2709 .= $record->as_usmarc(); + + push( @results, $dat ); + } + + $template2->param( + BIBLIO_RESULTS => \@results, + email_sender => $email_from, + comment => $comment, + shelfname => $shelf[1], + ); + + # Getting template result + my $template_res = $template2->output(); + my $body; + + # Analysing information and getting mail properties + if ( $template_res =~ /\n(.*)\n/s ) { + $mail{'subject'} = $1; + } + else { $mail{'subject'} = "no subject"; } + + my $email_header = ""; + if ( $template_res =~ /
\n(.*)\n/s ) { + $email_header = $1; + } + + my $email_file = "basket.txt"; + if ( $template_res =~ /\n(.*)\n/s ) { + $email_file = $1; + } + + if ( $template_res =~ /\n(.*)\n/s ) { $body = $1; } + + my $boundary = "====" . time() . "===="; + + # We set and put the multipart content + $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\""; + + my $isofile = encode_base64(encode("UTF-8", $iso2709)); + $boundary = '--' . $boundary; + + $mail{body} = <param( SENT => "1" ); + } + else { + # do something if it doesnt work.... + warn "Error sending mail: $Mail::Sendmail::error \n"; + $template->param( error => 1 ); + } + + $template->param( email => $email ); + output_html_with_http_headers $query, $cookie, $template->output; + + +}else{ + $template->param( shelfid => $shelfid, + url => "/cgi-bin/koha/opac-sendshelf.pl", + ); + output_html_with_http_headers $query, $cookie, $template->output; +} -- 2.39.2