lasts commits before 1.3.3 release
[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::Acquisitions;
26 use C4::Biblio;
27 use C4::Output;
28 use C4::Circulation::Circ2;
29 use C4::Accounts2;
30
31 my $env;
32 my $input= new CGI;
33
34 my $bibnum=checkinp($input->param('bibnum'));
35 my $itemnum=checkinp($input->param('itemnumber'));
36 my $copyright=checkinp($input->param('Copyright'));
37 my $seriestitle=checkinp($input->param('Series'));
38 my $serial=checkinp($input->param('Serial'));
39 my $unititle=checkinp($input->param('Unititle'));
40 my $notes=checkinp($input->param('ItemNotes'));
41
42 #need to do barcode check
43 my $barcode=$input->param('Barcode');
44
45 my $bibitemnum=checkinp($input->param('bibitemnum'));
46 my $itemtype=checkinp($input->param('Item'));
47 my $isbn=checkinp($input->param('ISBN'));
48 my $publishercode=checkinp($input->param('Publisher'));
49 my $publicationdate=checkinp($input->param('Publication'));
50 my $class=checkinp($input->param('Class'));
51 my $homebranch=checkinp($input->param('Home'));
52 my $lost=$input->param('Lost');
53 my $wthdrawn=$input->param('withdrawn');
54 my $classification;
55 my $dewey;
56 my $subclass;
57 my $override=$input->param('override');
58 if ($itemtype ne 'NF'){
59   $classification=$class;
60 }
61 if ($class =~/[0-9]+/){
62    $dewey= $class;
63    $dewey=~ s/[a-z]+//gi;
64    my @temp;
65    if ($class =~ /\./){
66      @temp=split(/[0-9]+\.[0-9]+/,$class);
67    } else {
68      @temp=split(/[0-9]+/,$class);
69    }
70    $classification=$temp[0];
71    $subclass=$temp[1];
72 }else{
73   $dewey='';
74 }
75 my $illus=checkinp($input->param('Illustrations'));
76 my $pages=checkinp($input->param('Pages'));
77 my $volumeddesc=checkinp($input->param('Volume'));
78
79 if ($wthdrawn == 0 && $override ne 'yes'){
80   moditem( { biblionumber => $bibnum,
81              loan         =>'loan',
82              itemnum      => $itemnum,
83              bibitemnum   => $bibitemnum,
84              barcode      => $barcode,
85              notes        => $notes,
86              homebranch   => $homebranch,
87              lost         => $lost,
88              wthdranw     => $wthdrawn
89              });
90   if ($lost ==1){
91     my $dbh = C4::Context->dbh;
92     my $sth=$dbh->prepare("Select * from issues where (itemnumber='$itemnum') and (returndate is null)");
93     $sth->execute;
94     my $data=$sth->fetchrow_hashref;
95     if ($data->{'borrowernumber'} ne '') {
96       #item on issue add replacement cost to borrowers record
97       my $accountno=getnextacctno($env,$data->{'borrowernumber'},$dbh);
98       my $item=getiteminformation($env, $itemnum);
99       my $account="Insert into accountlines
100       (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber)
101       values
102       ('$data->{'borrowernumber'}','$accountno',now(),'$item->{'replacementprice'}',
103       'Lost Item $item->{'title'} $item->{'barcode'}','L',
104       '$item->{'replacementprice'}','$itemnum')";
105       my $sth2=$dbh->prepare($account);
106 #      print $input->header;
107 #      print $account;
108       $sth2->execute;
109       $sth2->finish;
110     }
111     $sth->finish;
112   }
113   print $input->redirect("moredetail.pl?type=intra&bib=$bibnum&bi=$bibitemnum");
114 } else {
115
116 #  print "marking cancelled";
117   #need to check if it is on reserve or issued
118   my $dbh = C4::Context->dbh;
119   my $flag=0;
120   my ($resbor,$resrec)=C4::Circulation::Circ2::checkreserve($env,$dbh,$itemnum);
121  # print $resbor;
122   if ($resbor){
123     print $input->header;
124     print "The biblio or biblioitem this item belongs to has a reserve on it";
125     $flag=1;
126   }
127   my $sth=$dbh->prepare("Select * from issues where (itemnumber='$itemnum') and (returndate is null)");
128   $sth->execute;
129   my $data=$sth->fetchrow_hashref;
130   if ($data->{'borrowernumber'} ne '') {
131     print $input->header;
132     print "<p>Item is on issue";
133     $flag=1;
134   }
135   $sth->finish;
136   if ($flag == 1){
137     my $url=$input->self_url;
138     $url.="&override=yes";
139     print "<p> <a href=$url>Cancel Anyway</a> &nbsp; or <a href=\"\">Back</a>";
140   }else {
141     moditem({ biblionumber => $bibnum,
142               loan         => 'loan',
143               itemnum      => $itemnum,
144               bibitemnum   => $bibitemnum,
145               barcode      => $barcode,
146               notes        => $notes,
147               homebranch   => $homebranch,
148               lost         => $lost,
149               wthdrawn     => $wthdrawn
150               });
151     print $input->redirect("moredetail.pl?type=intra&bib=$bibnum&bi=$bibitemnum");
152   }
153 }
154 #print $bibitemnum;
155
156 sub checkinp{
157   my ($inp)=@_;
158   $inp=~ s/\'/\\\'/g;
159   $inp=~ s/\"/\\\"/g;
160   return($inp);
161 }
162
163 #sub checkissue{