(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 <galen.charlton@liblime.com>
This commit is contained in:
Nahuel ANGELINETTI 2009-01-12 10:36:31 +01:00 committed by Galen Charlton
parent f35a9d5a27
commit bfebda4ad9
5 changed files with 277 additions and 7 deletions

View File

@ -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);

View File

@ -0,0 +1,54 @@
<SUBJECT>
Your Shelf : <!-- TMPL_VAR NAME="shelfname" -->
<END_SUBJECT>
<HEADER>
Hi,
Here is your shelf called <!-- TMPL_VAR NAME="shelfname" -->, 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.
<END_HEADER>
<MESSAGE>
---------------------------------------------
<!-- TMPL_IF NAME="comment" -->
<!-- TMPL_VAR NAME="comment" -->
<!-- /TMPL_IF -->
<!-- TMPL_LOOP NAME="BIBLIO_RESULTS" -->
<!-- TMPL_VAR NAME="title" -->
<!-- TMPL_IF name="subtitle" -->
<!-- TMPL_VAR NAME="subtitle" -->
<!-- /TMPL_IF -->
<!-- TMPL_IF name="MARCAUTHORS" -->
<!-- TMPL_LOOP NAME="MARCAUTHORS"-->
Authors: <!-- TMPL_VAR NAME="value" -->
<!-- /TMPL_LOOP -->
<!-- /TMPL_IF -->
<!-- TMPL_IF name="ISBN" -->
ISBN: <!-- TMPL_VAR NAME="ISBN" -->
<!-- /TMPL_IF -->
<!-- TMPL_IF name="publishercode" -->
Published by: <!-- TMPL_VAR NAME="publishercode" --><!-- /TMPL_IF --><!-- TMPL_IF name="publicationyear" --> in <!-- /TMPL_IF --><!-- TMPL_VAR NAME="publicationyear" --><!-- TMPL_IF name="pages" -->, <!-- /TMPL_IF --><!-- TMPL_VAR name="pages" --><!-- TMPL_IF name="size" -->, <!-- /TMPL_IF --><!-- TMPL_VAR name="size" --><!-- TMPL_IF name="collection" -->
Collection: <!-- TMPL_VAR NAME="seriestitle" --><!-- /TMPL_IF --><!-- TMPL_IF name="subject" -->
Subject: <!-- TMPL_VAR NAME="subject" --><!-- /TMPL_IF --><!-- TMPL_IF name="copyrightdate" -->
Copyright year: <!-- TMPL_VAR NAME="copyrightdate" --><!-- /TMPL_IF --><!-- TMPL_IF name="notes" -->
Notes : <!-- TMPL_VAR NAME="notes" --><!-- /TMPL_IF --><!-- TMPL_IF name="unititle" -->
Unified title: <!-- TMPL_VAR NAME="unititle" --><!-- /TMPL_IF --><!-- TMPL_IF name="serial" -->
Serial: <!-- TMPL_VAR NAME="serial" --><!-- /TMPL_IF --><!-- TMPL_IF name="dewey" -->
Dewey: <!-- TMPL_VAR name="dewey" --><!-- /TMPL_IF --><!-- TMPL_IF name="classification" -->
Classification: <!-- TMPL_VAR name="classification" --><!-- /TMPL_IF --><!-- TMPL_IF name="lccn" -->
LCCN: <!-- TMPL_VAR name="lccn" --><!-- /TMPL_IF --><!-- TMPL_IF name="url" -->
URL : <!-- TMPL_VAR NAME="url" --><!-- /TMPL_IF -->
Items : <!-- TMPL_LOOP NAME="ITEM_RESULTS" -->
<!-- TMPL_VAR NAME="branchname" --> <!-- TMPL_VAR NAME="location" --> <!-- TMPL_IF name="itemcallnumber" -->(<!-- TMPL_VAR NAME="itemcallnumber" -->)<!-- /TMPL_IF --> <!-- TMPL_VAR NAME="barcode" -->
<!-- /TMPL_LOOP -->
---------------------------------------------
<!-- /TMPL_LOOP -->
<END_MESSAGE>

View File

@ -0,0 +1,38 @@
<!-- TMPL_INCLUDE NAME="doc-head-open.inc" --><!-- TMPL_IF NAME="LibraryNameTitle" --><!-- TMPL_VAR NAME="LibraryNameTitle" --><!-- TMPL_ELSE -->Koha Online<!-- /TMPL_IF --> Catalog &rsaquo; Sending Your Shelf
<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
</head>
<body style="padding: 1em;" id="sendbasket">
<div class="container"><!-- TMPL_IF NAME="email" -->
<!-- TMPL_IF NAME="SENT" -->
<h3>Message Sent</h3>
<p>The shelf was sent to: <!-- TMPL_VAR NAME="email" --></p>
<p><a class="close" href="#">Close window</a></p>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="error" -->
<p>Problem sending the shelf...</p>
<!-- /TMPL_IF -->
<!-- TMPL_ELSE -->
<form action="<!-- TMPL_VAR NAME="url" -->" method="post">
<fieldset class="rows">
<legend>Sending your shelf</legend>
<ol> <li>
<label for="email">Email Address:</label>
<input type="text" id="email" name="email" size="43" />
</li>
<li>
<label for="comment">Comment:</label>
<textarea id="comment" name="comment" rows="4" cols="40"></textarea>
</li>
<li>
<input type="hidden" name="shelfid" value="<!-- TMPL_VAR NAME="shelfid" -->" />
</li></ol></fieldset>
<fieldset class="action"> <input type="submit" value="Send" /> <a class="cancel close" href="#">Cancel</a> </fieldset>
</form>
<!-- /TMPL_IF --></div>
</body>
</html>

View File

@ -81,7 +81,7 @@ $.tablesorter.addParser({
<!-- /TMPL_LOOP -->
<!-- /TMPL_IF -->
<div class="yui-g">
<div id="toolbar" class="yui-g">
<!-- TMPL_IF NAME="viewshelf" -->
@ -96,6 +96,7 @@ $.tablesorter.addParser({
<!-- /TMPL_IF -->
<input type="hidden" value="1" name="DEL-<!-- TMPL_VAR NAME="shelfnumber" -->"/>
<input type="submit" class="deleteshelf" value="Delete List" onclick="return confirmDelete(_('Are you sure you want to remove this List?'));"/></form>
<a href="#" class="send" onClick="open(CGIBIN+'opac-sendshelf.pl?shelfid=<!-- TMPL_VAR NAME="shelfnumber" -->','win_form','dependant=yes,scrollbars=no,resizable=no,height=300,width=450,top=50,left=100')">Send shelf</a>
</div><!-- /TMPL_IF -->
<!-- TMPL_IF NAME="manageshelf" --><form action="/cgi-bin/koha/opac-shelves.pl" method="post" name="myform" class="checkboxed">
<input type="hidden" name="viewshelf" value="<!-- TMPL_VAR NAME="shelfnumber" -->" />
@ -218,7 +219,7 @@ $.tablesorter.addParser({
<!-- TMPL_IF NAME="viewcategory2" -->Public<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="viewcategory3" -->Open<!-- /TMPL_IF -->
</td>
<td>
<td id="toolbar">
<!-- TMPL_IF NAME="mine" -->
<form action="opac-shelves.pl" method="get">
<input type="hidden" name="shelfnumber" value="<!-- TMPL_VAR NAME="shelf" -->" />
@ -238,6 +239,7 @@ $.tablesorter.addParser({
<!-- /TMPL_IF -->
</form>
<!-- /TMPL_IF -->&nbsp;
<a href="#" class="send" onClick="open(CGIBIN+'opac-sendshelf.pl?shelfid=<!-- TMPL_VAR NAME="shelf" -->','win_form','dependant=yes,scrollbars=no,resizable=no,height=300,width=450,top=50,left=100')">Send shelf</a>
</td>
</tr>
<!-- /TMPL_LOOP -->
@ -267,7 +269,7 @@ $.tablesorter.addParser({
<!-- TMPL_IF NAME="viewcategory2" -->Public<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="viewcategory3" -->Open<!-- /TMPL_IF -->
</td>
<td>
<td id="toolbar">
<!-- TMPL_IF NAME="mine" -->
<form action="opac-shelves.pl" method="get">
<input type="hidden" name="shelfnumber" value="<!-- TMPL_VAR NAME="shelf" -->" />
@ -285,6 +287,7 @@ $.tablesorter.addParser({
<!-- /TMPL_IF -->
</form>
<!-- /TMPL_IF -->&nbsp;
<a href="#" class="send" onClick="open(CGIBIN+'opac-sendshelf.pl?shelfid=<!-- TMPL_VAR NAME="shelf" -->','win_form','dependant=yes,scrollbars=no,resizable=no,height=300,width=450,top=50,left=100')">Send shelf</a>
</td>
</tr>
<!-- /TMPL_LOOP -->

173
opac/opac-sendshelf.pl Executable file
View File

@ -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 =~ /<SUBJECT>\n(.*)\n<END_SUBJECT>/s ) {
$mail{'subject'} = $1;
}
else { $mail{'subject'} = "no subject"; }
my $email_header = "";
if ( $template_res =~ /<HEADER>\n(.*)\n<END_HEADER>/s ) {
$email_header = $1;
}
my $email_file = "basket.txt";
if ( $template_res =~ /<FILENAME>\n(.*)\n<END_FILENAME>/s ) {
$email_file = $1;
}
if ( $template_res =~ /<MESSAGE>\n(.*)\n<END_MESSAGE>/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} = <<END_OF_BODY;
$boundary
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
$email_header
$body
$boundary
Content-Type: application/octet-stream; name="shelf.iso2709"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="shelf.iso2709"
$isofile
$boundary--
END_OF_BODY
# Sending mail
if ( sendmail %mail ) {
# do something if it works....
$template->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;
}