Added copyright statement to all .pl and .pm files
[koha.git] / updatebibitem.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::Output;
26 use C4::Search;
27
28 my $input= new CGI;
29 #print $input->header;
30 #print $input->Dump;
31
32 my $bibitemnum      = checkinp($input->param('bibitemnum'));
33 my $bibnum          = checkinp($input->param('bibnum'));
34 my $itemtype        = checkinp($input->param('Item'));
35 my $url             = checkinp($input->param('url'));
36 my $isbn            = checkinp($input->param('ISBN'));
37 my $publishercode   = checkinp($input->param('Publisher'));
38 my $publicationdate = checkinp($input->param('Publication'));
39 my $class           = checkinp($input->param('Class'));
40 my $illus           = checkinp($input->param('Illustrations'));
41 my $pages           = checkinp($input->param('Pages'));
42 my $volumeddesc     = checkinp($input->param('Volume'));
43 my $notes           = checkinp($input->param('Notes'));
44 my $size            = checkinp($input->param('Size'));
45 my $place           = checkinp($input->param('Place'));
46 my $classification;
47 my $dewey;
48 my $subclass;
49
50 if ($itemtype ne 'NF') {
51   $classification=$class;
52 } # if
53
54 if ($class =~/[0-9]+/) {
55 #   print $class;
56    $dewey= $class;
57    $dewey=~ s/[a-z]+//gi;
58    my @temp;
59    if ($class =~ /\./) {
60      @temp=split(/[0-9]+\.[0-9]+/,$class);
61    } else {
62      @temp=split(/[0-9]+/,$class);
63    } # else
64    $classification=$temp[0];
65    $subclass=$temp[1];
66 #   print $classification,$dewey,$subclass;
67 } else {
68   $dewey='';
69   $subclass='';
70 } # else
71
72 my (@items) = &itemissues($bibitemnum);
73 #print @items;           
74 my $count   = @items;
75 #print $count;
76 my @barcodes;
77
78 my $existing=$input->param('existing');
79 if ($existing eq 'YES'){
80 #  print "yes";
81   my $group=$input->param('existinggroup');
82   #go thru items assing selected ones to group
83   for (my $i=0;$i<$count;$i++){
84     my $temp="check_group_".$items[$i]->{'barcode'};
85     my $barcode=$input->param($temp);
86     if ($barcode ne ''){
87       moditem($items[$i]->{'notforloan'},$items[$i]->{'itemnumber'},$group);
88 #      print "modify $items[$i]->{'itemnumber'} $group";
89     }
90   }
91   $bibitemnum=$group;
92 } else {
93     my $flag;
94     my $flag2;
95     for (my $i=0;$i<$count;$i++){
96       my $temp="check_group_".$items[$i]->{'barcode'};
97       $barcodes[$i]=$input->param($temp);
98       if ($barcodes[$i] eq ''){
99         $flag="notall";
100       } else {
101         $flag2="leastone";
102       }
103    }
104    my $loan;
105    if ($flag eq 'notall' && $flag2 eq 'leastone'){
106       $bibitemnum = &newbiblioitem({
107           biblionumber    => $bibnum,
108           itemtype        => $itemtype?$itemtype:"",
109           url             => $url?$url:"",
110           isbn            => $isbn?$isbn:"",
111           publishercode   => $publishercode?$publishercode:"",
112           publicationyear => $publicationdate?$publicationdate:"",
113           volumeddesc     => $volumeddesc?$volumeddesc:"",
114           classification  => $classification?$classification:"",
115           dewey           => $dewey?$dewey:"",
116           subclass        => $subclass?$subclass:"",
117           illus           => $illus?$illus:"",
118           pages           => $pages?$pages:"",
119           notes           => $notes?$notes:"",
120           size            => $size?$size:"",
121           place           => $place?$place:"" });
122       if ($itemtype =~ /REF/){
123         $loan=1;
124       } else {
125         $loan=0;
126       }
127       for (my $i=0;$i<$count;$i++){
128         if ($barcodes[$i] ne ''){
129           moditem($loan,$items[$i]->{'itemnumber'},$bibitemnum);
130         }
131       }
132       
133    } elsif ($flag2 eq 'leastone') {
134       &modbibitem({
135           biblioitemnumber => $bibitemnum,
136           itemtype         => $itemtype?$itemtype:"",
137           url              => $url?$url:"",
138           isbn             => $isbn?$isbn:"",
139           publishercode    => $publishercode?$publishercode:"",
140           publicationyear  => $publicationdate?$publicationdate:"",
141           classification   => $classification?$classification:"",
142           dewey            => $dewey?$dewey:"",
143           subclass         => $subclass?$subclass:"",
144           illus            => $illus?$illus:"",
145           pages            => $pages?$pages:"",
146           volumeddesc      => $volumeddesc?$volumeddesc:"",
147           notes            => $notes?$notes:"",
148           size             => $size?$size:"",
149           place            => $place?$place:"" });
150       if ($itemtype =~ /REF/){
151         $loan=1;
152       } else {
153         $loan=0;
154       }
155         for (my $i=0;$i<$count;$i++){                                             
156           if ($barcodes[$i] ne ''){                                               
157             moditem($loan,$items[$i]->{'itemnumber'},$bibitemnum);                
158           }                                                                       
159         }
160       
161    } else {
162      &modbibitem({
163          biblioitemnumber => $bibitemnum,
164          itemtype         => $itemtype?$itemtype:"",
165          url              => $url?$url:"",
166          isbn             => $isbn?$isbn:"",
167          publishercode    => $publishercode?$publishercode:"",
168          publicationyear  => $publicationdate?$publicationdate:"",
169          classification   => $classification?$classification:"",
170          dewey            => $dewey?$dewey:"",
171          subclass         => $subclass?$subclass:"",
172          illus            => $illus?$illus:"",
173          pages            => $pages?$pages:"",
174          volumeddesc      => $volumeddesc?$volumeddesc:"",
175          notes            => $notes?$notes:"",
176          size             => $size?$size:"",
177          place            => $place?$place:"" });
178    } # else
179 }
180 print $input->redirect("moredetail.pl?type=intra&bib=$bibnum&bi=$bibitemnum");
181
182
183 sub checkinp{
184   my ($inp)=@_;
185   $inp=~ s/\'/\\\'/g;
186   $inp=~ s/\"/\\\"/g;
187   return($inp);
188 }