Added copyright statement to all .pl and .pm files
[koha.git] / updateitem.pl
1 #!/usr/bin/perl
2
3
4 # Copyright 2000-2002 Katipo Communications
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
12 #
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA  02111-1307 USA
20
21 use C4::Database;
22 use CGI;
23 use strict;
24 use C4::Acquisitions;
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('loan',$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn);
80   if ($lost ==1){
81     my $dbh=C4Connect;
82     my $sth=$dbh->prepare("Select * from issues where (itemnumber='$itemnum') and (returndate is null)");
83     $sth->execute;
84     my $data=$sth->fetchrow_hashref;
85     if ($data->{'borrowernumber'} ne '') {
86       #item on issue add replacement cost to borrowers record
87       my $accountno=getnextacctno($env,$data->{'borrowernumber'},$dbh);
88       my $item=getiteminformation($env, $itemnum);
89       my $account="Insert into accountlines
90       (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber)
91       values
92       ('$data->{'borrowernumber'}','$accountno',now(),'$item->{'replacementprice'}',
93       'Lost Item $item->{'title'} $item->{'barcode'}','L',
94       '$item->{'replacementprice'}','$itemnum')";
95       my $sth2=$dbh->prepare($account);
96 #      print $input->header;
97 #      print $account;
98       $sth2->execute;
99       $sth2->finish;
100     }
101     $sth->finish;
102   }
103   print $input->redirect("moredetail.pl?type=intra&bib=$bibnum&bi=$bibitemnum");
104 } else {
105   
106 #  print "marking cancelled";
107   #need to check if it is on reserve or issued
108   my $dbh=C4Connect;
109   my $flag=0; 
110   my ($resbor,$resrec)=C4::Circulation::Circ2::checkreserve($env,$dbh,$itemnum);
111  # print $resbor;
112   if ($resbor){
113     print $input->header;
114     print "The biblio or biblioitem this item belongs to has a reserve on it";
115     $flag=1;
116   }
117   my $sth=$dbh->prepare("Select * from issues where (itemnumber='$itemnum') and (returndate is null)"); 
118   $sth->execute;
119   my $data=$sth->fetchrow_hashref;
120   if ($data->{'borrowernumber'} ne '') {
121     print $input->header;
122     print "<p>Item is on issue";
123     $flag=1;
124   }
125   $sth->finish;
126   $dbh->disconnect;
127   if ($flag == 1){
128     my $url=$input->self_url;
129     $url.="&override=yes";
130     print "<p> <a href=$url>Cancel Anyway</a> &nbsp; or <a href=\"\">Back</a>";
131   }else {
132     moditem('loan',$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn);
133     print $input->redirect("moredetail.pl?type=intra&bib=$bibnum&bi=$bibitemnum");
134   }
135 }
136 #print $bibitemnum;
137
138 sub checkinp{
139   my ($inp)=@_;
140   $inp=~ s/\'/\\\'/g;
141   $inp=~ s/\"/\\\"/g;
142   return($inp);
143 }
144
145 #sub checkissue{
146