bugfix for bookshelves not in official CVS
[koha.git] / updateitem.pl
1 #!/usr/bin/perl
2
3 # $Id$
4
5 # Copyright 2000-2002 Katipo Communications
6 #
7 # This file is part of Koha.
8 #
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
12 # version.
13 #
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License along with
19 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
20 # Suite 330, Boston, MA  02111-1307 USA
21
22 use strict;
23 use CGI;
24 use C4::Context;
25 use C4::Biblio;
26 use C4::Output;
27 use C4::Circulation::Circ2;
28 use C4::Accounts2;
29
30 my $env;
31 my $input= new CGI;
32
33 my $bibnum=checkinp($input->param('bibnum'));
34 my $itemnum=checkinp($input->param('itemnumber'));
35 my $copyright=checkinp($input->param('Copyright'));
36 my $seriestitle=checkinp($input->param('Series'));
37 my $serial=checkinp($input->param('Serial'));
38 my $unititle=checkinp($input->param('Unititle'));
39 my $notes=checkinp($input->param('ItemNotes'));
40
41 #need to do barcode check
42 my $barcode=$input->param('Barcode');
43
44 my $bibitemnum=checkinp($input->param('bibitemnum'));
45 my $itemtype=checkinp($input->param('Item'));
46 my $isbn=checkinp($input->param('ISBN'));
47 my $publishercode=checkinp($input->param('Publisher'));
48 my $publicationdate=checkinp($input->param('Publication'));
49 my $class=checkinp($input->param('Class'));
50 my $homebranch=checkinp($input->param('Home'));
51 my $lost=$input->param('Lost');
52 my $wthdrawn=$input->param('withdrawn');
53 my $classification;
54 my $dewey;
55 my $subclass;
56 my $override=$input->param('override');
57 if ($itemtype ne 'NF'){
58   $classification=$class;
59 }
60 if ($class =~/[0-9]+/){
61    $dewey= $class;
62    $dewey=~ s/[a-z]+//gi;
63    my @temp;
64    if ($class =~ /\./){
65      @temp=split(/[0-9]+\.[0-9]+/,$class);
66    } else {
67      @temp=split(/[0-9]+/,$class);
68    }
69    $classification=$temp[0];
70    $subclass=$temp[1];
71 }else{
72   $dewey='';
73 }
74 my $illus=checkinp($input->param('Illustrations'));
75 my $pages=checkinp($input->param('Pages'));
76 my $volumeddesc=checkinp($input->param('Volume'));
77
78 if ($wthdrawn == 0 && $override ne 'yes'){
79   moditem( { biblionumber => $bibnum,
80              loan         =>'loan',
81              itemnum      => $itemnum,
82              bibitemnum   => $bibitemnum,
83              barcode      => $barcode,
84              notes        => $notes,
85              homebranch   => $homebranch,
86              lost         => $lost,
87              wthdranw     => $wthdrawn
88              });
89   if ($lost ==1){
90     my $dbh = C4::Context->dbh;
91     my $sth=$dbh->prepare("Select * from issues where (itemnumber=?) and (returndate is null)");
92     $sth->execute($itemnum);
93     my $data=$sth->fetchrow_hashref;
94     if ($data->{'borrowernumber'} ne '') {
95       #item on issue add replacement cost to borrowers record
96       my $accountno=getnextacctno($env,$data->{'borrowernumber'},$dbh);
97       my $item=getiteminformation($env, $itemnum);
98       my $sth2=$dbh->prepare("Insert into accountlines
99       (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber)
100       values
101       (?,?,now(),?,?,'L',?,?)");
102       $sth2->execute($data->{'borrowernumber'},$accountno,$item->{'replacementprice'},
103       "Lost Item $item->{'title'} $item->{'barcode'}",
104       $item->{'replacementprice'},$itemnum);
105       $sth2->finish;
106     }
107     $sth->finish;
108   }
109   print $input->redirect("moredetail.pl?type=intra&bib=$bibnum&bi=$bibitemnum");
110 } else {
111
112 #  print "marking cancelled";
113   #need to check if it is on reserve or issued
114   my $dbh = C4::Context->dbh;
115   my $flag=0;
116   my ($resbor,$resrec)=C4::Circulation::Circ2::checkreserve($env,$dbh,$itemnum);
117  # print $resbor;
118   if ($resbor){
119     print $input->header;
120     print "The biblio or biblioitem this item belongs to has a reserve on it";
121     $flag=1;
122   }
123   my $sth=$dbh->prepare("Select * from issues where (itemnumber=?) and (returndate is null)");
124   $sth->execute($itemnum);
125   my $data=$sth->fetchrow_hashref;
126   if ($data->{'borrowernumber'} ne '') {
127     print $input->header;
128     print "<p>Item is on issue";
129     $flag=1;
130   }
131   $sth->finish;
132   if ($flag == 1){
133     my $url=$input->self_url;
134     $url.="&override=yes";
135     print "<p> <a href=$url>Cancel Anyway</a> &nbsp; or <a href=\"\">Back</a>";
136   }else {
137     moditem({ biblionumber => $bibnum,
138               loan         => 'loan',
139               itemnum      => $itemnum,
140               bibitemnum   => $bibitemnum,
141               barcode      => $barcode,
142               notes        => $notes,
143               homebranch   => $homebranch,
144               lost         => $lost,
145               wthdrawn     => $wthdrawn
146               });
147     print $input->redirect("moredetail.pl?type=intra&bib=$bibnum&bi=$bibitemnum");
148   }
149 }
150 #print $bibitemnum;
151
152 sub checkinp{
153   my ($inp)=@_;
154   $inp=~ s/\'/\\\'/g;
155   $inp=~ s/\"/\\\"/g;
156   return($inp);
157 }
158
159 #sub checkissue{