Merged with arensb-context branch: use C4::Context->dbh instead of
[koha.git] / acqui.simple / saveitem.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 CGI;
22 use strict;
23 use C4::Catalogue;
24 use C4::Biblio;
25
26 my $input            = new CGI;
27 my $barcode          = $input->param('barcode');
28 my $biblionumber     = $input->param('biblionumber');
29 my $biblioitemnumber = $input->param('biblioitemnumber');
30 my $item             = {
31     biblionumber     => $biblionumber,
32     biblioitemnumber => $biblioitemnumber?$biblioitemnumber:"",
33     homebranch       => $input->param('homebranch'),
34     replacementprice => $input->param('replacementprice')?$input->param('replacementprice'):"",
35     itemnotes        => $input->param('notes')?$input->param('notes'):""
36 }; # my $item
37 my $biblioitem       = {
38     biblionumber      => $biblionumber,
39     itemtype          => $input->param('itemtype'),
40     isbn              => $input->param('isbn')?$input->param('isbn'):"",
41     publishercode     => $input->param('publishercode')?$input->param('publishercode'):"",
42     publicationyear   => $input->param('publicationyear')?$input->param('publicationyear'):"",
43     place             => $input->param('place')?$input->param('place'):"",
44     illus             => $input->param('illus')?$input->param('illus'):"",
45     additionalauthors => $input->param('additionalauthors')?$input->param('additionalauthors'):"",
46     subjectheadings   => $input->param('subjectheadings')?$input->param('subjectheadings'):"",
47     url               => $input->param('url')?$input->param('url'):"",
48     dewey             => $input->param('dewey')?$input->param('dewey'):"",
49     subclass          => $input->param('subclass')?$input->param('subclass'):"",
50     issn              => $input->param('issn')?$input->param('issn'):"",
51     lccn              => $input->param('lccn')?$input->param('lccn'):"",
52     volume            => $input->param('volume')?$input->param('volume'):"",
53     number            => $input->param('number')?$input->param('number'):"",
54     volumeddesc       => $input->param('volumeddesc')?$input->param('volumeddesc'):"",
55     pages             => $input->param('pages')?$input->param('pages'):"",
56     size              => $input->param('size')?$input->param('size'):"",
57     notes             => $input->param('notes')?$input->param('notes'):""
58 }; # my biblioitem
59 my $newgroup = 0;
60 my $website  = 0;
61 my $count;
62 my @results;
63
64 if ($input->param('newgroup')) {
65     $newgroup = 1;
66     if ($biblioitem->{'itemtype'} eq "WEB") {
67         $website = 1;
68     } # if
69 } # if
70
71 if (! $biblionumber) {
72     print $input->redirect('addbooks.pl');
73 } elsif ((! $barcode) && (! $website)) {
74     print $input->redirect("additem.pl?biblionumber=$biblionumber&error=nobarcode");
75 } elsif ((! $newgroup) && (! $biblioitemnumber)) {
76     print $input->redirect("additem.pl?biblionumber=$biblionumber&error=nobiblioitem");
77 } else {
78     
79     if ($website) {
80         &newbiblioitem($biblioitem);
81     } elsif (&checkitems(1,$barcode)) {
82         print $input->redirect("additem.pl?biblionumber=$biblionumber&error=barcodeinuse");
83     } else {
84
85         if ($newgroup) {
86             $biblioitemnumber = &newbiblioitem($biblioitem);
87             $item->{'biblioitemnumber'} = $biblioitemnumber;
88         } # if
89
90         &newitems($item, ($barcode));
91
92         print $input->redirect("additem.pl?biblionumber=$biblionumber");
93     } # else
94 } # else