From 23f46658938bcb47c342c83b723ff7beb54b6332 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9rick?= Date: Fri, 24 Aug 2012 14:29:25 -0400 Subject: [PATCH] Add a recall button to the biblio record details page. Content-Type: text/plain; charset="utf-8" The recall button sends an email to the user who currently has the item in his possession, telling him to return the item as soon as possible. Patch sponsored by the CCSR ( http://www.ccsr.qc.ca ) Signed-off-by: Kyle M Hall http://bugs.koha-community.org/show_bug.cgi?id=8688 --- catalogue/detail.pl | 4 + circ/send_recall_notice.pl | 64 ++++++++++++++++++++ .../prog/en/modules/catalogue/detail.tt | 47 ++++++++++++++ 3 files changed, 115 insertions(+), 0 deletions(-) create mode 100644 circ/send_recall_notice.pl diff --git a/catalogue/detail.pl b/catalogue/detail.pl index f2ad4eb..b6ad25c 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -174,6 +174,7 @@ my $shelflocations = GetKohaAuthorisedValues('items.location', $fw); my $collections = GetKohaAuthorisedValues('items.ccode' , $fw); my $copynumbers = GetKohaAuthorisedValues('items.copynumber', $fw); my (@itemloop, %itemfields); +my $items_checked_out = 0; my $norequests = 1; my $authvalcode_items_itemlost = GetAuthValCode('items.itemlost',$fw); my $authvalcode_items_damaged = GetAuthValCode('items.damaged', $fw); @@ -184,6 +185,8 @@ foreach my $item (@items) { $item->{homebranch} = GetBranchName($item->{homebranch}); + $items_checked_out++ if $item->{'onloan'}; + # can place holds defaults to yes $norequests = 0 unless ( ( $item->{'notforloan'} > 0 ) || ( $item->{'itemnotforloan'} > 0 ) ); @@ -328,6 +331,7 @@ foreach ( keys %{$dat} ) { $template->param( AmazonTld => get_amazon_tld() ) if ( C4::Context->preference("AmazonCoverImages")); $template->param( itemloop => \@itemloop, + items_checked_out => $items_checked_out, biblionumber => $biblionumber, ($analyze? 'analyze':'detailview') =>1, subscriptions => \@subs, diff --git a/circ/send_recall_notice.pl b/circ/send_recall_notice.pl new file mode 100644 index 0000000..fe97a9b --- /dev/null +++ b/circ/send_recall_notice.pl @@ -0,0 +1,64 @@ +#!/usr/bin/perl + +# Author : Frédérick Capovilla, 2011 - SYS-TECH +# +# 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., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use strict; +use warnings; + +use C4::Message; +use C4::Circulation; +use C4::Items; +use C4::Auth; +use CGI; +use CGI::Cookie; + +my $input = new CGI; +my $itemnumber = $input->param('itemnumber'); + +# Check the user's permissions +my %cookies = fetch CGI::Cookie; +my $sessid = $cookies{'CGISESSID'}->value || $input->param('CGISESSID'); +my ($auth_status, $auth_sessid) = C4::Auth::check_cookie_auth($sessid, {"circulate_remaining_permissions" => '1'}); +if ($auth_status ne "ok") { + print $input->header; + print "UNAUTHORIZED"; + exit 0; +} + +# Generate the message + +my $borrower = C4::Circulation::GetItemIssue($itemnumber); +my $item = C4::Items::GetItem($itemnumber); + +my $letter = C4::Letters::GetPreparedLetter( + 'module' => 'circulation', + 'letter_code' => 'RECALL', + 'tables' => { + 'biblio' => $item->{biblionumber}, + 'biblioitems' => $item->{biblionumber}, + 'items' => $itemnumber, + 'borrowers' => $borrower->{borrowernumber}, + 'branches' => $item->{homebranch}, + }, +); + +# Try to add the message to the message queue. +if( C4::Letters::EnqueueLetter({letter => $letter, borrowernumber => $borrower->{borrowernumber}, message_transport_type => 'email'}) ) { + print $input->header; + print "SUCCESS"; +} diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt index 22f7908..ec580e3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -42,6 +42,44 @@ function verify_images() { [% IF ( AmazonCoverImages ) %]$(window).load(function() { verify_images(); });[% END %] + + +//AJAX call to send a recall notice to the user who currently has the item. +function recall_item(itemnumber) { + var button = $("#recall_"+itemnumber); + + if(!confirm(_('A request for the immediate return of the item will be sent to the user who currently has it in its possession.\n\nAre you sure you want to send a recall notice?'))) { + return; + } + + //Disable the button to prevent spamming + button.attr("disabled",true); + + $.ajax({ + url: '/cgi-bin/koha/circ/send_recall_notice.pl', + type: 'POST', + dataType: 'text', + data: {itemnumber: itemnumber}, + success: function(msg){ + if(msg == "SUCCESS") { + button.attr("value",_("Recall sent")); + } + else if(msg == "UNAUTHORIZED") { + alert(_("Failed to send the recall notice:")+"\n"+_("You do not have the required permissions to do this action.")+" (circulate_remaining_permissions)"); + button.attr("disabled",false); + } + else { + alert(_("Failed to send the recall notice:")+"\n"+msg); + button.attr("disabled",false); + } + }, + error: function(request,status){ + alert(_("Failed to send the recall notice:")+"\n"+status); + button.attr("disabled",false); + } + }); +} + //]]> @@ -284,6 +322,7 @@ function verify_images() { [% IF ( SpineLabelShowPrintOnBibDetails ) %]Spine label[% END %] [% IF ( hostrecords ) %]Host records[% END %] [% IF ( analyze ) %]Used in[% END %] + [% IF ( items_checked_out ) %]Recall[% END %] [% FOREACH itemloo IN itemloop %] @@ -420,6 +459,14 @@ function verify_images() { Create analytics [% END %] + [% IF ( items_checked_out ) %] + + [% IF ( itemloo.onloan ) %] + + [% END %] + + [% END %] + [% END %] -- 1.7.2.5