Some small changes in transferbook: uses the new Reserves2.pm methods.
[koha.git] / updateitem.pl
1 #!/usr/bin/perl
2
3 use C4::Database;
4 use CGI;
5 use strict;
6 use C4::Acquisitions;
7 use C4::Output;
8 use C4::Circulation::Circ2;
9 use C4::Accounts2;
10
11 my $env;
12 my $input= new CGI;
13
14 my $bibnum=checkinp($input->param('bibnum'));
15 my $itemnum=checkinp($input->param('itemnumber'));
16 my $copyright=checkinp($input->param('Copyright'));
17 my $seriestitle=checkinp($input->param('Series'));
18 my $serial=checkinp($input->param('Serial'));
19 my $unititle=checkinp($input->param('Unititle'));
20 my $notes=checkinp($input->param('ItemNotes'));
21
22 #need to do barcode check
23 my $barcode=$input->param('Barcode');
24
25 my $bibitemnum=checkinp($input->param('bibitemnum'));
26 my $itemtype=checkinp($input->param('Item'));
27 my $isbn=checkinp($input->param('ISBN'));
28 my $publishercode=checkinp($input->param('Publisher'));
29 my $publicationdate=checkinp($input->param('Publication'));
30 my $class=checkinp($input->param('Class'));
31 my $homebranch=checkinp($input->param('Home'));
32 my $lost=$input->param('Lost');
33 my $wthdrawn=$input->param('withdrawn');
34 my $classification;
35 my $dewey;
36 my $subclass;
37 my $override=$input->param('override');
38 if ($itemtype ne 'NF'){
39   $classification=$class;
40 }
41 if ($class =~/[0-9]+/){
42    $dewey= $class;
43    $dewey=~ s/[a-z]+//gi;
44    my @temp;
45    if ($class =~ /\./){
46      @temp=split(/[0-9]+\.[0-9]+/,$class);
47    } else {
48      @temp=split(/[0-9]+/,$class);
49    }
50    $classification=$temp[0];
51    $subclass=$temp[1];
52 }else{
53   $dewey='';
54 }
55 my $illus=checkinp($input->param('Illustrations'));
56 my $pages=checkinp($input->param('Pages'));
57 my $volumeddesc=checkinp($input->param('Volume'));
58
59 if ($wthdrawn == 0 && $override ne 'yes'){
60   moditem('loan',$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn);
61   if ($lost ==1){
62     my $dbh=C4Connect;
63     my $sth=$dbh->prepare("Select * from issues where (itemnumber='$itemnum') and (returndate is null)");
64     $sth->execute;
65     my $data=$sth->fetchrow_hashref;
66     if ($data->{'borrowernumber'} ne '') {
67       #item on issue add replacement cost to borrowers record
68       my $accountno=getnextacctno($env,$data->{'borrowernumber'},$dbh);
69       my $item=getiteminformation($env, $itemnum);
70       my $account="Insert into accountlines
71       (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber)
72       values
73       ('$data->{'borrowernumber'}','$accountno',now(),'$item->{'replacementprice'}',
74       'Lost Item $item->{'title'} $item->{'barcode'}','L',
75       '$item->{'replacementprice'}','$itemnum')";
76       my $sth2=$dbh->prepare($account);
77 #      print $input->header;
78 #      print $account;
79       $sth2->execute;
80       $sth2->finish;
81     }
82     $sth->finish;
83   }
84   print $input->redirect("moredetail.pl?type=intra&bib=$bibnum&bi=$bibitemnum");
85 } else {
86   
87 #  print "marking cancelled";
88   #need to check if it is on reserve or issued
89   my $dbh=C4Connect;
90   my $flag=0; 
91   my ($resbor,$resrec)=C4::Circulation::Circ2::checkreserve($env,$dbh,$itemnum);
92  # print $resbor;
93   if ($resbor){
94     print $input->header;
95     print "The biblio or biblioitem this item belongs to has a reserve on it";
96     $flag=1;
97   }
98   my $sth=$dbh->prepare("Select * from issues where (itemnumber='$itemnum') and (returndate is null)"); 
99   $sth->execute;
100   my $data=$sth->fetchrow_hashref;
101   if ($data->{'borrowernumber'} ne '') {
102     print $input->header;
103     print "<p>Item is on issue";
104     $flag=1;
105   }
106   $sth->finish;
107   $dbh->disconnect;
108   if ($flag == 1){
109     my $url=$input->self_url;
110     $url.="&override=yes";
111     print "<p> <a href=$url>Cancel Anyway</a> &nbsp; or <a href=\"\">Back</a>";
112   }else {
113     moditem('loan',$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn);
114     print $input->redirect("moredetail.pl?type=intra&bib=$bibnum&bi=$bibitemnum");
115   }
116 }
117 #print $bibitemnum;
118
119 sub checkinp{
120   my ($inp)=@_;
121   $inp=~ s/\'/\\\'/g;
122   $inp=~ s/\"/\\\"/g;
123   return($inp);
124 }
125
126 #sub checkissue{
127