Adding a parameter to allow acces to people with management/tools flags
[koha.git] / updatebibitem.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 CGI;
23 use strict;
24 use C4::Biblio;
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({ biblionumber => $bibnum,
88                 notforloan   => $items[$i]->{'notforloan'},
89                 itemnumber   => $items[$i]->{'itemnumber'},
90                 group        => $group
91                     });
92 #      print "modify $items[$i]->{'itemnumber'} $group";
93     }
94   }
95   $bibitemnum=$group;
96 } else {
97     my $flag;
98     my $flag2;
99     for (my $i=0;$i<$count;$i++){
100       my $temp="check_group_".$items[$i]->{'barcode'};
101       $barcodes[$i]=$input->param($temp);
102       if ($barcodes[$i] eq ''){
103         $flag="notall";
104       } else {
105         $flag2="leastone";
106       }
107    }
108    my $loan;
109    if ($flag eq 'notall' && $flag2 eq 'leastone'){
110       $bibitemnum = &newbiblioitem({
111           biblionumber    => $bibnum,
112           itemtype        => $itemtype?$itemtype:"",
113           url             => $url?$url:"",
114           isbn            => $isbn?$isbn:"",
115           publishercode   => $publishercode?$publishercode:"",
116           publicationyear => $publicationdate?$publicationdate:"",
117           volumeddesc     => $volumeddesc?$volumeddesc:"",
118           classification  => $classification?$classification:"",
119           dewey           => $dewey?$dewey:"",
120           subclass        => $subclass?$subclass:"",
121           illus           => $illus?$illus:"",
122           pages           => $pages?$pages:"",
123           notes           => $notes?$notes:"",
124           size            => $size?$size:"",
125           place           => $place?$place:"" });
126       if ($itemtype =~ /REF/){
127         $loan=1;
128       } else {
129         $loan=0;
130       }
131       for (my $i=0;$i<$count;$i++){
132         if ($barcodes[$i] ne ''){
133           moditem({ biblionumber => $bibnum,
134                     loan         => $loan,
135                     itemnumber   => $items[$i]->{'itemnumber'},
136                     bibitemnum   => $bibitemnum
137                     });
138         }
139       }
140
141    } elsif ($flag2 eq 'leastone') {
142       &modbibitem({
143           biblioitemnumber => $bibitemnum,
144           biblionumber     => $bibnum,
145           itemtype         => $itemtype?$itemtype:"",
146           url              => $url?$url:"",
147           isbn             => $isbn?$isbn:"",
148           publishercode    => $publishercode?$publishercode:"",
149           publicationyear  => $publicationdate?$publicationdate:"",
150           classification   => $classification?$classification:"",
151           dewey            => $dewey?$dewey:"",
152           subclass         => $subclass?$subclass:"",
153           illus            => $illus?$illus:"",
154           pages            => $pages?$pages:"",
155           volumeddesc      => $volumeddesc?$volumeddesc:"",
156           notes            => $notes?$notes:"",
157           size             => $size?$size:"",
158           place            => $place?$place:"" });
159       if ($itemtype =~ /REF/){
160         $loan=1;
161       } else {
162         $loan=0;
163       }
164         for (my $i=0;$i<$count;$i++){
165           if ($barcodes[$i] ne ''){
166             moditem( {biblionumber => $bibnum,
167                       loan         => $loan,
168                       itemnumber   => $items[$i]->{'itemnumber'},
169                       bibitemnum   => $bibitemnum
170                       });
171           }
172         }
173
174    } else {
175      &modbibitem({
176          biblioitemnumber => $bibitemnum,
177          itemtype         => $itemtype?$itemtype:"",
178          url              => $url?$url:"",
179          isbn             => $isbn?$isbn:"",
180          publishercode    => $publishercode?$publishercode:"",
181          publicationyear  => $publicationdate?$publicationdate:"",
182          classification   => $classification?$classification:"",
183          dewey            => $dewey?$dewey:"",
184          subclass         => $subclass?$subclass:"",
185          illus            => $illus?$illus:"",
186          pages            => $pages?$pages:"",
187          volumeddesc      => $volumeddesc?$volumeddesc:"",
188          notes            => $notes?$notes:"",
189          size             => $size?$size:"",
190          place            => $place?$place:"" });
191    } # else
192 }
193 print $input->redirect("moredetail.pl?type=intra&bib=$bibnum&bi=$bibitemnum");
194
195
196 sub checkinp{
197   my ($inp)=@_;
198   $inp=~ s/\'/\\\'/g;
199   $inp=~ s/\"/\\\"/g;
200   return($inp);
201 }