Cleanup waitingreserves.pl and .tmpl

Use warnings and provide fallback values to avoid them.
Move waitingdate check up to top of loop.
Move $today creation outside loop (should be same for all).
Remove unused and unnecessary variables.
Add subtitle escaping to .tmpl and slightly standardize formatting.

Signed-off-by: Galen Charlton <galen.charlton@liblime.com>
This commit is contained in:
Joe Atzberger 2009-05-26 16:41:03 -05:00 committed by Galen Charlton
parent 400f2bad9e
commit 8c0ac886bf
2 changed files with 103 additions and 116 deletions

View file

@ -1,6 +1,5 @@
#!/usr/bin/perl
# Copyright 2000-2002 Katipo Communications
#
# This file is part of Koha.
@ -19,6 +18,7 @@
# Suite 330, Boston, MA 02111-1307 USA
use strict;
use warnings;
use CGI;
use C4::Context;
use C4::Output;
@ -42,13 +42,11 @@ my $input = new CGI;
my $item = $input->param('itemnumber');
my $borrowernumber = $input->param('borrowernumber');
my $fbr = $input->param('fbr');
my $tbr = $input->param('tbr');
my $fbr = $input->param('fbr') || '';
my $tbr = $input->param('tbr') || '';
my $cancel;
my $theme = $input->param('theme'); # only used if allowthemeoverride is set
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{
template_name => "circ/waitingreserves.tmpl",
@ -64,25 +62,17 @@ my $default = C4::Context->userenv->{'branch'};
# if we have a return from the form we launch the subroutine CancelReserve
if ($item) {
my $messages;
my $nextreservinfo;
my $waiting;
( $messages, $nextreservinfo ) = ModReserveCancelAll( $item, $borrowernumber );
# if we have a result
my ( $messages, $nextreservinfo ) = ModReserveCancelAll( $item, $borrowernumber );
# if we have a result
if ($nextreservinfo) {
my $borrowerinfo = GetMemberDetails( $nextreservinfo );
my $iteminfo = GetBiblioFromItemNumber($item);
if ( $messages->{'transfert'} ) {
my $branchname = GetBranchName( $messages->{'transfert'} );
$template->param(
messagetransfert => $messages->{'transfert'},
branchname => $branchname,
branchname => GetBranchName($messages->{'transfert'}),
);
}
if ( $messages->{'waiting'} ) {
$waiting = 1;
}
$template->param(
message => 1,
@ -91,75 +81,65 @@ if ($item) {
nextreservfirstname => $borrowerinfo->{'firstname'},
nextreservitem => $item,
nextreservtitle => $iteminfo->{'title'},
waiting => $waiting
waiting => ($messages->{'waiting'}) ? 1 : 0,
);
}
# if the document is not in his homebranch location and there is not reservation after, we transfer it
if ( ( $fbr ne $tbr ) and ( not $nextreservinfo ) ) {
# if the document is not in his homebranch location and there is not reservation after, we transfer it
if ($fbr ne $tbr and not $nextreservinfo) {
ModItemTransfer( $item, $fbr, $tbr );
}
}
my @reservloop;
my @getreserves;
if (C4::Context->preference('IndependantBranches')){
# get reserves for the branch we are logged into
@getreserves = GetReservesForBranch($default);
}
else {
# get all reserves waiting
@getreserves = GetReservesForBranch();
}
my @getreserves = C4::Context->preference('IndependantBranches') ? GetReservesForBranch($default) : GetReservesForBranch();
# get reserves for the branch we are logged into, or for all branches
my $today = Date_to_Days(&Today);
foreach my $num (@getreserves) {
next unless ($num->{'waitingdate'} && $num->{'waitingdate'} ne '0000-00-00');
my %getreserv;
my $gettitle = GetBiblioFromItemNumber( $num->{'itemnumber'} );
# fix up item type for display
$gettitle->{'itemtype'} = C4::Context->preference('item-level_itypes') ? $gettitle->{'itype'} : $gettitle->{'itemtype'};
my $getborrower = GetMemberDetails( $num->{'borrowernumber'} );
my $itemtypeinfo = getitemtypeinfo( $gettitle->{'itemtype'} );
my $itemtypeinfo = getitemtypeinfo( $gettitle->{'itemtype'} ); # using the fixed up itype/itemtype
$getreserv{'waitingdate'} = format_date( $num->{'waitingdate'} );
next unless ($num->{'waitingdate'} && $num->{'waitingdate'} ne '0000-00-00');
my ( $waiting_year, $waiting_month, $waiting_day ) = split /-/,
$num->{'waitingdate'};
my ( $waiting_year, $waiting_month, $waiting_day ) = split /-/, $num->{'waitingdate'};
( $waiting_year, $waiting_month, $waiting_day ) =
Add_Delta_Days( $waiting_year, $waiting_month, $waiting_day,
C4::Context->preference('ReservesMaxPickUpDelay'));
my $calcDate = Date_to_Days( $waiting_year, $waiting_month, $waiting_day );
my $today = Date_to_Days(&Today);
my $warning = ( $today > $calcDate );
if ( $warning > 0 ) {
if ($today > $calcDate) {
$getreserv{'messcompa'} = 1;
}
$getreserv{'title'} = $gettitle->{'title'};
$getreserv{'itemnumber'} = $gettitle->{'itemnumber'};
$getreserv{'biblionumber'} = $gettitle->{'biblionumber'};
$getreserv{'barcode'} = $gettitle->{'barcode'};
$getreserv{'itemtype'} = $itemtypeinfo->{'description'};
$getreserv{'homebranch'} = $gettitle->{'homebranch'};
$getreserv{'holdingbranch'} = $gettitle->{'holdingbranch'};
$getreserv{'itemtype'} = $itemtypeinfo->{'description'};
$getreserv{'title'} = $gettitle->{'title'};
$getreserv{'itemnumber'} = $gettitle->{'itemnumber'};
$getreserv{'biblionumber'} = $gettitle->{'biblionumber'};
$getreserv{'barcode'} = $gettitle->{'barcode'};
$getreserv{'homebranch'} = $gettitle->{'homebranch'};
$getreserv{'holdingbranch'} = $gettitle->{'holdingbranch'};
$getreserv{'itemcallnumber'} = $gettitle->{'itemcallnumber'};
if ( $gettitle->{'homebranch'} ne $gettitle->{'holdingbranch'} ) {
$getreserv{'dotransfer'} = 1;
}
$getreserv{'itemcallnumber'} = $gettitle->{'itemcallnumber'};
$getreserv{'borrowernum'} = $getborrower->{'borrowernumber'};
$getreserv{'borrowername'} = $getborrower->{'surname'};
$getreserv{'borrowerfirstname'} = $getborrower->{'firstname'};
$getreserv{'borrowerphone'} = $getborrower->{'phone'};
if ( $getborrower->{'emailaddress'} ) {
$getreserv{'borrowermail'} = $getborrower->{'emailaddress'};
$getreserv{'borrowermail'} = $getborrower->{'emailaddress'};
}
$getreserv{'borrowerphone'} = $getborrower->{'phone'};
push( @reservloop, \%getreserv );
push @reservloop, \%getreserv;
}
$template->param(
reserveloop => \@reservloop,
show_date => format_date(C4::Dates->today('iso')),
dateformat => C4::Context->preference("dateformat"),
dateformat => C4::Context->preference("dateformat"),
);
output_html_with_http_headers $input, $cookie, $template->output;

View file

@ -2,7 +2,7 @@
<title>Koha &rsaquo; Circulation &rsaquo; Holds awaiting pickup</title>
<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
<script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/lib/jquery/plugins/jquery.tablesorter.min.js"></script>
<script type="text/JavaScript" language="JavaScript">
<script type="text/javascript" language="JavaScript">
//<![CDATA[
$.tablesorter.addParser({
id: 'articles',
@ -26,7 +26,10 @@ $.tablesorter.addParser({
<!-- TMPL_INCLUDE NAME="header.inc" -->
<!-- TMPL_INCLUDE NAME="circ-search.inc" -->
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/circ/circulation-home.pl">Circulation</a> &rsaquo; Holds awaiting pickup</div>
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a>
&rsaquo; <a href="/cgi-bin/koha/circ/circulation-home.pl">Circulation</a>
&rsaquo; <a href="/cgi-bin/koha/circ/waitingreserves.pl">Holds awaiting pickup</a>
</div>
<div id="doc" class="yui-t7">
@ -34,80 +37,84 @@ $.tablesorter.addParser({
<div id="yui-main">
<div class="yui-g">
<h2>Holds awaiting pickup for your library on : <!-- TMPL_VAR NAME="show_date" --></h2>
<h2>Holds awaiting pickup for your library on: <!-- TMPL_VAR NAME="show_date" --></h2>
<!-- TMPL_IF NAME="messagetransfert" -->
<div>
<h2>Hold find for (<!-- TMPL_VAR NAME="nextreservtitle" -->) must transfered</h2>
<p>This hold placed by : <b> <!-- TMPL_VAR NAME="nextreservsurname" --> <!-- TMPL_VAR NAME="nextreservfirstname" --></b> at the library : <b> <!-- TMPL_VAR NAME="branchname" --> </b>, Please transfer this hold.
</p>
<form name="cancelReservewithtransfert" action="waitingreserves.pl" method="post">
<input type="submit" class="button" />
</form>
</div>
<div>
<h2>Hold find for (<!-- TMPL_VAR NAME="nextreservtitle" -->) must transfered</h2>
<p>This hold placed by : <b> <!-- TMPL_VAR NAME="nextreservsurname" --> <!-- TMPL_VAR NAME="nextreservfirstname" --></b> at the library : <b> <!-- TMPL_VAR NAME="branchname" --> </b>, Please transfer this hold.
</p>
<form name="cancelReservewithtransfert" action="waitingreserves.pl" method="post">
<input type="submit" class="button" />
</form>
</div>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="waiting" -->
<div id="bloc25">
<h2>This hold is waiting</h2>
<p>This hold (<!-- TMPL_VAR NAME="nextreservtitle" -->) was placed by <b> : <!-- TMPL_VAR NAME="nextreservsurname" --> <!-- TMPL_VAR NAME="nextreservfirstname" --></b>,
Please retain this hold.
</p>
<form name="cancelReservewithwaiting" action="waitingreserves.pl" method="post">
<input type="submit" />
</form>
</div>
<div id="bloc25">
<h2>This hold is waiting</h2>
<p>This hold (<!-- TMPL_VAR NAME="nextreservtitle" -->) was placed by <b> : <!-- TMPL_VAR NAME="nextreservsurname" --> <!-- TMPL_VAR NAME="nextreservfirstname" --></b>,
Please retain this hold.
</p>
<form name="cancelReservewithwaiting" action="waitingreserves.pl" method="post">
<input type="submit" />
</form>
</div>
<!-- /TMPL_IF -->
<!-- TMPL_UNLESS NAME="message" -->
<div id="resultlist">
<!-- TMPL_IF NAME="reserveloop" -->
<table id="holdst">
<thead> <tr>
<th>Available since</th>
<th>Title</th>
<th>Patron</th>
<th>Location</th>
<th>Action</th>
</tr></thead>
<tbody><!-- TMPL_LOOP NAME="reserveloop" -->
<!-- TMPL_IF NAME="messcompa" --><tr class="problem"><!-- TMPL_ELSE --><tr><!-- /TMPL_IF -->
<td><p><!-- TMPL_VAR NAME="waitingdate" --></p> <!-- TMPL_IF NAME="messcompa" --> Hold Over <!-- /TMPL_IF --></td>
<td>
<!-- TMPL_IF name="BiblioDefaultViewmarc" -->
<a href="/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" ESCAPE="URL" -->"><!-- TMPL_VAR NAME="title" escape="html" --></a>
<!-- TMPL_ELSIF NAME="BiblioDefaultViewisbd" -->
<a href="/cgi-bin/koha/catalogue/ISBDdetail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" ESCAPE="URL" -->"><!-- TMPL_VAR NAME="title" escape="html" --></a>
<!-- TMPL_ELSE -->
<a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" ESCAPE="URL" -->"><!-- TMPL_VAR NAME="title" escape="html" --> <!-- TMPL_VAR NAME="subtitle" --></a><!-- /TMPL_IF --> &nbsp; (<b><!-- TMPL_VAR NAME="itemtype" --></b>)
<br />Barcode : <!-- TMPL_VAR NAME="barcode" -->
</td>
<td>
<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=<!--TMPL_VAR Name="borrowernum"-->"><!-- TMPL_VAR NAME="borrowername" -->, <!-- TMPL_VAR NAME="borrowerfirstname" --></a><br /><!-- TMPL_VAR NAME="borrowerphone" --><br />
<!-- TMPL_IF NAME="borrowermail" --><a href="mailto:<!-- TMPL_VAR NAME="email" -->?subject=Reservation: <!-- TMPL_VAR NAME="title" -->">
<!-- TMPL_VAR NAME="borrowermail" --></a><!--/TMPL_IF-->
</td>
<td><!-- TMPL_VAR NAME="homebranch" --> <!-- TMPL_VAR NAME="itemcallnumber" --></td>
<td>
<form name="cancelReserve" action="waitingreserves.pl" method="post">
<input type="hidden" name="borrowernumber" value="<!-- TMPL_VAR NAME="borrowernum" -->" />
<input type="hidden" name="itemnumber" value="<!-- TMPL_VAR NAME="itemnumber" -->" />
<input type="hidden" name="fbr" value="<!-- TMPL_VAR NAME="holdingbranch" -->" />
<input type="hidden" name="tbr" value="<!-- TMPL_VAR NAME="homebranch" -->" />
<!-- TMPL_IF NAME="dotransfer" -->
<input type="submit" value="Cancel hold and return to : <!-- TMPL_VAR NAME="homebranch" -->" />
<!-- TMPL_ELSE -->
<input type="submit" value="Cancel hold" />
<!-- /TMPL_IF -->
</form>
</td>
</tr>
<!-- /TMPL_LOOP --></tbody>
</table>
<!-- TMPL_ELSE -->
<div class="dialog message">No holds found.</div>
<!-- /TMPL_IF -->
<table id="holdst">
<thead><tr>
<th>Available since</th>
<th>Title</th>
<th>Patron</th>
<th>Location</th>
<th>Action</th>
</tr></thead>
<tbody><!-- TMPL_LOOP NAME="reserveloop" -->
<!-- TMPL_IF NAME="messcompa" --><tr class="problem"><!-- TMPL_ELSE --><tr><!-- /TMPL_IF -->
<td><p><!-- TMPL_VAR NAME="waitingdate" --></p>
<!-- TMPL_IF NAME="messcompa" -->Hold Over<!-- /TMPL_IF -->
</td>
<td>
<!-- TMPL_IF name="BiblioDefaultViewmarc" -->
<a href="/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" ESCAPE="URL" -->">
<!-- TMPL_ELSIF NAME="BiblioDefaultViewisbd" -->
<a href="/cgi-bin/koha/catalogue/ISBDdetail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" ESCAPE="URL" -->">
<!-- TMPL_ELSE -->
<a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" ESCAPE="URL" -->">
<!-- /TMPL_IF -->
<!-- TMPL_VAR NAME="title" escape="html" --> <!-- TMPL_VAR NAME="subtitle" ESCAPE="html" -->
</a>
&nbsp; (<b><!-- TMPL_VAR NAME="itemtype" --></b>)
<br />Barcode: <!-- TMPL_VAR NAME="barcode" -->
</td>
<td>
<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=<!--TMPL_VAR Name="borrowernum"-->"><!-- TMPL_VAR NAME="borrowername" -->, <!-- TMPL_VAR NAME="borrowerfirstname" --></a><br /><!-- TMPL_VAR NAME="borrowerphone" --><br />
<!-- TMPL_IF NAME="borrowermail" --><a href="mailto:<!-- TMPL_VAR NAME="email" -->?subject=Reservation: <!-- TMPL_VAR NAME="title" -->">
<!-- TMPL_VAR NAME="borrowermail" --></a><!--/TMPL_IF-->
</td>
<td><!-- TMPL_VAR NAME="homebranch" --> <!-- TMPL_VAR NAME="itemcallnumber" --></td>
<td>
<form name="cancelReserve" action="waitingreserves.pl" method="post">
<input type="hidden" name="borrowernumber" value="<!-- TMPL_VAR NAME="borrowernum" -->" />
<input type="hidden" name="itemnumber" value="<!-- TMPL_VAR NAME="itemnumber" -->" />
<input type="hidden" name="fbr" value="<!-- TMPL_VAR NAME="holdingbranch" -->" />
<input type="hidden" name="tbr" value="<!-- TMPL_VAR NAME="homebranch" -->" />
<!-- TMPL_IF NAME="dotransfer" -->
<input type="submit" value="Cancel hold and return to : <!-- TMPL_VAR NAME="homebranch" -->" />
<!-- TMPL_ELSE -->
<input type="submit" value="Cancel hold" />
<!-- /TMPL_IF -->
</form>
</td>
</tr>
<!-- /TMPL_LOOP --></tbody>
</table>
<!-- TMPL_ELSE -->
<div class="dialog message">No holds found.</div>
<!-- /TMPL_IF -->
</div>
<!-- /TMPL_UNLESS -->
<!-- /TMPL_UNLESS -->
</div>
</div>