#!/usr/bin/perl
#written 8/5/2002 by Finlay
#script to execute issuing of books
# Copyright 2000-2002 Katipo Communications
#
# 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 CGI;
use C4::Circulation::Circ2;
use C4::Search;
use C4::Output;
use C4::Print;
my %env;
my $headerbackgroundcolor='#99cc33';
my $circbackgroundcolor='#ffffcc';
my $circbackgroundcolor='white';
my $linecolor1='#ffffcc';
my $linecolor2='white';
my $backgroundimage="/images/background-mem.gif";
my $branches = getbranches();
my $printers = getprinters(\%env);
my $query = new CGI;
my $branch = $query->param("branch");
my $printer = $query->param("printer");
($branch) || ($branch=$query->cookie('branch')) ;
($printer) || ($printer=$query->cookie('printer')) ;
#set up cookie.....
my $info = '';
my $branchcookie;
my $printercookie;
if ($query->param('setcookies')) {
$branchcookie = $query->cookie(-name=>'branch', -value=>"$branch", -expires=>'+1y');
$printercookie = $query->cookie(-name=>'printer', -value=>"$printer", -expires=>'+1y');
}
$env{'branchcode'}=$branch;
$env{'printer'}=$printer;
$env{'queue'}=$printer;
my @datearr = localtime(time());
my $tday = localtime(time());
warn "today: $tday \n";
my $todaysdate = (1900+$datearr[5]).sprintf ("%0.2d", ($datearr[4]+1)).sprintf ("%0.2d", ($datearr[3]));
#warn $todaysdate;
my $message;
my $borrowerslist;
# if there is a list of find borrowers....
my $findborrower = $query->param('findborrower');
if ($findborrower) {
my ($borrowers, $flags) = findborrower(\%env, $findborrower);
my @borrowers=@$borrowers;
if ($#borrowers == -1) {
$query->param('findborrower', '');
$message = "No borrower matched '$findborrower'";
} elsif ($#borrowers == 0) {
$query->param('borrnumber', $borrowers[0]->{'borrowernumber'});
$query->param('barcode','');
} else {
$borrowerslist = \@borrowers;
}
}
my $borrowernumber = $query->param('borrnumber');
my $bornum = $query->param('borrnumber');
# check and see if we should print
my $print=$query->param('print');
my $barcode = $query->param('barcode');
if ($barcode eq '' && $print eq 'maybe'){
$print = 'yes';
}
if ($print eq 'yes' && $borrowernumber ne ''){
printslip(\%env,$borrowernumber);
$query->param('borrnumber','');
$borrowernumber='';
}
# get the borrower information.....
my $borrower;
my $flags;
if ($borrowernumber) {
($borrower, $flags) = getpatroninformation(\%env,$borrowernumber,0);
}
# get the responses to any questions.....
my %responses;
foreach (sort $query->param) {
if ($_ =~ /response-(\d*)/) {
$responses{$1} = $query->param($_);
}
}
if (my $qnumber = $query->param('questionnumber')) {
$responses{$qnumber} = $query->param('answer');
}
my ($iteminformation, $duedate, $rejected, $question, $questionnumber, $defaultanswer);
my $year=$query->param('year');
my $month=$query->param('month');
my $day=$query->param('day');
# if the barcode is set
if ($barcode) {
$barcode = cuecatbarcodedecode($barcode);
my ($datedue, $invalidduedate) = fixdate($year, $month, $day);
unless ($invalidduedate) {
$env{'datedue'}=$datedue;
my @time=localtime(time);
my $date= (1900+$time[5])."-".($time[4]+1)."-".$time[3];
($iteminformation, $duedate, $rejected, $question, $questionnumber, $defaultanswer, $message)
= issuebook(\%env, $borrower, $barcode, \%responses, $date);
}
}
# reload the borrower info for the sake of reseting the flags.....
if ($borrowernumber) {
($borrower, $flags) = getpatroninformation(\%env,$borrowernumber,0);
}
##################################################################################
# HTML code....
my $rejectedtext;
if ($rejected) {
if ($rejected == -1) {
} else {
$rejectedtext = << "EOF";
Error Issuing Book
$rejected
EOF
}
}
my $selectborrower;
if ($borrowerslist) {
$selectborrower = <<"EOF";
EOF
my $responsesform = '';
foreach (keys %responses) {
$responsesform.="\n";
}
my $questionform;
if ($question) {
my $stickyduedate=$query->param('stickyduedate');
$questionform = <<"EOF";
Issuing Question
Attempting to issue $iteminformation->{'title'}
by $iteminformation->{'author'} to $borrower->{'firstname'} $borrower->{'surname'}.
$question
EOF
}
# Barcode entry box, with hidden inputs attached....
my $counter = 1;
my $dayoptions = '';
my $monthoptions = '';
my $yearoptions = '';
for (my $i=1; $i<32; $i++) {
my $selected='';
if (($query->param('stickyduedate')) && ($day==$i)) {
$selected='selected';
}
$dayoptions.="