style sheet to hide styles from Netscape 4.7
[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='$itemnum') and (returndate is null)");
92     $sth->execute;
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 $account="Insert into accountlines
99       (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber)
100       values
101       ('$data->{'borrowernumber'}','$accountno',now(),'$item->{'replacementprice'}',
102       'Lost Item $item->{'title'} $item->{'barcode'}','L',
103       '$item->{'replacementprice'}','$itemnum')";
104       my $sth2=$dbh->prepare($account);
105 #      print $input->header;
106 #      print $account;
107       $sth2->execute;
108       $sth2->finish;
109     }
110     $sth->finish;
111   }
112   print $input->redirect("moredetail.pl?type=intra&bib=$bibnum&bi=$bibitemnum");
113 } else {
114
115 #  print "marking cancelled";
116   #need to check if it is on reserve or issued
117   my $dbh = C4::Context->dbh;
118   my $flag=0;
119   my ($resbor,$resrec)=C4::Circulation::Circ2::checkreserve($env,$dbh,$itemnum);
120  # print $resbor;
121   if ($resbor){
122     print $input->header;
123     print "The biblio or biblioitem this item belongs to has a reserve on it";
124     $flag=1;
125   }
126   my $sth=$dbh->prepare("Select * from issues where (itemnumber='$itemnum') and (returndate is null)");
127   $sth->execute;
128   my $data=$sth->fetchrow_hashref;
129   if ($data->{'borrowernumber'} ne '') {
130     print $input->header;
131     print "<p>Item is on issue";
132     $flag=1;
133   }
134   $sth->finish;
135   if ($flag == 1){
136     my $url=$input->self_url;
137     $url.="&override=yes";
138     print "<p> <a href=$url>Cancel Anyway</a> &nbsp; or <a href=\"\">Back</a>";
139   }else {
140     moditem({ biblionumber => $bibnum,
141               loan         => 'loan',
142               itemnum      => $itemnum,
143               bibitemnum   => $bibitemnum,
144               barcode      => $barcode,
145               notes        => $notes,
146               homebranch   => $homebranch,
147               lost         => $lost,
148               wthdrawn     => $wthdrawn
149               });
150     print $input->redirect("moredetail.pl?type=intra&bib=$bibnum&bi=$bibitemnum");
151   }
152 }
153 #print $bibitemnum;
154
155 sub checkinp{
156   my ($inp)=@_;
157   $inp=~ s/\'/\\\'/g;
158   $inp=~ s/\"/\\\"/g;
159   return($inp);
160 }
161
162 #sub checkissue{