merging 1.2 and main branches. Mostly spaces and typo diffs
[koha.git] / updatebibitem.pl
1 #!/usr/bin/perl
2
3 use C4::Database;
4 use CGI;
5 use strict;
6 use C4::Acquisitions;
7 use C4::Biblio;
8 use C4::Output;
9 use C4::Search;
10
11 my $input= new CGI;
12 #print $input->header;
13 #print $input->Dump;
14
15
16 my $bibitemnum      = checkinp($input->param('bibitemnum'));
17 my $bibnum          = checkinp($input->param('bibnum'));
18 my $itemtype        = checkinp($input->param('Item'));
19 my $isbn            = checkinp($input->param('ISBN'));
20 my $publishercode   = checkinp($input->param('Publisher'));
21 my $publicationdate = checkinp($input->param('Publication'));
22 my $class           = checkinp($input->param('Class'));
23 my $illus           = checkinp($input->param('Illustrations'));
24 my $pages           = checkinp($input->param('Pages'));
25 my $volumeddesc     = checkinp($input->param('Volume'));
26 my $notes           = checkinp($input->param('Notes'));
27 my $size            = checkinp($input->param('Size'));
28 my $place           = checkinp($input->param('Place'));
29 my $classification;
30 my $dewey;
31 my $subclass;
32
33 if ($itemtype ne 'NF') {
34   $classification=$class;
35 } # if
36
37 if ($class =~/[0-9]+/) {
38 #   print $class;
39    $dewey= $class;
40    $dewey=~ s/[a-z]+//gi;
41    my @temp;
42    if ($class =~ /\./) {
43      @temp=split(/[0-9]+\.[0-9]+/,$class);
44    } else {
45      @temp=split(/[0-9]+/,$class);
46    } # else
47    $classification=$temp[0];
48    $subclass=$temp[1];
49 #   print $classification,$dewey,$subclass;
50 } else {
51   $dewey='';
52   $subclass='';
53 } # else
54
55 my (@items)=itemissues($bibitemnum);
56 #print @items;           
57 my $count=@items;
58 #print $count;
59 my @barcodes;
60
61
62 my $existing=$input->param('existing');
63 if ($existing eq 'YES'){
64 #  print "yes";
65   my $group=$input->param('existinggroup');
66   #go thru items assing selected ones to group
67   for (my $i=0;$i<$count;$i++){
68     my $temp="check_group_".$items[$i]->{'barcode'};
69     my $barcode=$input->param($temp);
70     if ($barcode ne ''){
71       moditem($items[$i]->{'notforloan'},$items[$i]->{'itemnumber'},$group);
72 #      print "modify $items[$i]->{'itemnumber'} $group";
73     }
74   }
75   $bibitemnum=$group;
76 } else {
77     my $flag;
78     my $flag2;
79     for (my $i=0;$i<$count;$i++){
80       my $temp="check_group_".$items[$i]->{'barcode'};
81       $barcodes[$i]=$input->param($temp);
82       if ($barcodes[$i] eq ''){
83         $flag="notall";
84       } else {
85         $flag2="leastone";
86       }
87    }
88    my $loan;
89    if ($flag eq 'notall' && $flag2 eq 'leastone'){
90       $bibitemnum = &newbiblioitem({ biblionumber   => $bibnum,
91                                      itemtype       => $itemtype,
92                                      volumeddesc    => $volumeddesc,
93                                      classification => $classification });
94       modbibitem($bibitemnum,$itemtype,$isbn,$publishercode,$publicationdate,$classification,$dewey,$subclass,$illus,$pages,$volumeddesc,$notes,$size,$place);
95       if ($itemtype =~ /REF/){
96         $loan=1;
97       } else {
98         $loan=0;
99       }
100       for (my $i=0;$i<$count;$i++){
101         if ($barcodes[$i] ne ''){
102           moditem($loan,$items[$i]->{'itemnumber'},$bibitemnum);
103         }
104       }
105       
106    } elsif ($flag2 eq 'leastone') {
107       modbibitem($bibitemnum,$itemtype,$isbn,$publishercode,$publicationdate,$classification,$dewey,$subclass,$illus,$pages,$volumeddesc,$notes,$size,$place);
108       if ($itemtype =~ /REF/){
109         $loan=1;
110       } else {
111         $loan=0;
112       }
113         for (my $i=0;$i<$count;$i++){                                             
114           if ($barcodes[$i] ne ''){                                               
115             moditem($loan,$items[$i]->{'itemnumber'},$bibitemnum);                
116           }                                                                       
117         }
118       
119    }
120 }
121 print $input->redirect("moredetail.pl?type=intra&bib=$bibnum&bi=$bibitemnum");
122
123
124 sub checkinp{
125   my ($inp)=@_;
126   $inp=~ s/\'/\\\'/g;
127   $inp=~ s/\"/\\\"/g;
128   return($inp);
129 }