catching oldbiblionumber also
[koha.git] / cataloguing / additem-nomarc.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 # $Log$
23 # Revision 1.1  2006/01/17 16:40:54  tipaul
24 # moving acqui.simple directory to cataloguing, as acqui.simple contains cataloguing scripts...
25 #
26 # Revision 1.8  2005/10/26 09:11:34  tipaul
27 # big commit, still breaking things...
28 #
29 # * synch with rel_2_2. Probably the last non manual synch, as rel_2_2 should not be modified deeply.
30 # * code cleaning (cleaning warnings from perl -w) continued
31 #
32 # Revision 1.4.2.1  2005/03/25 12:52:44  tipaul
33 # needs "editcatalogue" flag, not "catalogue"
34 #
35 # Revision 1.4  2004/11/19 16:41:49  tipaul
36 # improving behaviour when MARC=OFF
37 #
38 # Revision 1.3  2004/08/13 16:37:25  tipaul
39 # adding frameworkcode to API in some subs
40 #
41 # Revision 1.2  2003/05/11 06:59:11  rangi
42 # Mostly templated.
43 # Still needs some work
44 #
45
46 use CGI;
47 use strict;
48 use C4::Biblio;
49 use C4::Koha;
50 use C4::Output;
51 use HTML::Template;
52 use C4::Auth;
53 use C4::Interface::CGI::Output;
54
55 my $input        = new CGI;
56 my $biblionumber = $input->param('biblionumber');
57 my $error        = $input->param('error');
58 my $maxbarcode;
59 my $isbn;
60 my $bibliocount;
61 my @biblios;
62 my $biblioitemcount;
63 my @biblioitems;
64 my $branchcount;
65 # my @branches;
66 # my %branchnames;
67 my $itemcount;
68 my @items;
69
70 if ( !$biblionumber ) {
71         print $input->redirect('addbooks.pl');
72 }
73 else {
74         my $input = new CGI;
75         my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
76                 {
77                         template_name   => "acqui.simple/additem-nomarc.tmpl",
78                         query           => $input,
79                         type            => "intranet",
80                         authnotrequired => 0,
81                         flagsrequired   => { editcatalogue => 1 },
82                         debug           => 1,
83                 }
84         );
85         ( $bibliocount, @biblios ) = &getbiblio($biblionumber);
86
87         if ( !$bibliocount ) {
88                 print $input->redirect('addbooks.pl');
89         }
90         else {
91                 ( $biblioitemcount, @biblioitems ) = &getbiblioitembybiblionumber($biblionumber);
92                 my $branches = getbranches;
93                 my @branchloop;
94                 foreach my $thisbranch (sort keys %$branches) {
95                         my %row =(value => $thisbranch,
96                                                 branchname => $branches->{$thisbranch}->{'branchname'},
97                                         );
98                         push @branchloop, \%row;
99                 }
100                 my $itemtypes = &getitemtypes;
101                 my @itemtypeloop;
102                 foreach my $thisitemtype (sort keys %$itemtypes) {
103                         my %row =(value => $thisitemtype,
104                                                 description => $itemtypes->{$thisitemtype}->{'description'},
105                                         );
106                         push @itemtypeloop, \%row;
107                 }
108                 if ( $error eq "nobarcode" ) {
109                         $template->param( NOBARCODE => 1 );
110                 }
111                 elsif ( $error eq "nobiblioitem" ) {
112                         $template->param( NOBIBLIOITEM => 1 );
113                 }
114                 elsif ( $error eq "barcodeinuse" ) {
115                         $template->param( BARCODEINUSE => 1 );
116                 }    # elsif
117
118                 for ( my $i = 0 ; $i < $biblioitemcount ; $i++ ) {
119                         if ( $biblioitems[$i]->{'itemtype'} eq "WEB" ) {
120                                 $biblioitems[$i]->{'WEB'} = 1;
121                         }
122                         $biblioitems[$i]->{'dewey'} =~ /(\d*\.\d\d)/;
123                         $biblioitems[$i]->{'dewey'} = $1;
124                         ( $itemcount, @items ) = &getitemsbybiblioitem( $biblioitems[$i]->{'biblioitemnumber'} );
125                         $biblioitems[$i]->{'items'} = \@items;
126                 }    # for
127                 $template->param(
128                         BIBNUM    => $biblionumber,
129                         AUTHOR    => $biblios[0]->{'author'},
130                         TITLE     => $biblios[0]->{'title'},
131                         COPYRIGHT => $biblios[0]->{'copyrightdate'},
132                         SERIES    => $biblios[0]->{'seriestitle'},
133                         NOTES     => $biblios[0]->{'notes'},
134                         BIBITEMS  => \@biblioitems,
135                         branchloop  => \@branchloop,
136                         itemtypeloop => \@itemtypeloop,
137
138     ( $bibliocount, @biblios ) = &getbiblio($biblionumber);
139
140     if ( !$bibliocount ) {
141         print $input->redirect('addbooks.pl');
142     }
143     else {
144
145         ( $biblioitemcount, @biblioitems ) =
146           &getbiblioitembybiblionumber($biblionumber);
147         ( $branchcount,   @branches )  = &branches;
148         ( $itemtypecount, @itemtypes ) = &getitemtypes;
149
150         for ( my $i = 0 ; $i < $itemtypecount ; $i++ ) {
151             $itemtypedescriptions{ $itemtypes[$i]->{'itemtype'} } =
152               $itemtypes[$i]->{'description'};
153         }    # for
154
155         for ( my $i = 0 ; $i < $branchcount ; $i++ ) {
156             $branchnames{ $branches[$i]->{'branchcode'} } =
157               $branches[$i]->{'branchname'};
158         }    # for
159
160         #       print $input->header;
161         #       print startpage();
162         #       print startmenu('acquisitions');
163         my $input = new CGI;
164         my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
165             {
166                 template_name   => "acqui.simple/additem-nomarc.tmpl",
167                 query           => $input,
168                 type            => "intranet",
169                 authnotrequired => 0,
170                 flagsrequired   => { editcatalogue => 1 },
171                 debug           => 1,
172             }
173         );
174
175         if ( $error eq "nobarcode" ) {
176             $template->param( NOBARCODE => 1 );
177         }
178         elsif ( $error eq "nobiblioitem" ) {
179             $template->param( NOBIBLIOITEM => 1 );
180         }
181         elsif ( $error eq "barcodeinuse" ) {
182             $template->param( BARCODEINUSE => 1 );
183         }    # elsif
184
185         for ( my $i = 0 ; $i < $biblioitemcount ; $i++ ) {
186             if ( $biblioitems[$i]->{'itemtype'} eq "WEB" ) {
187                 $biblioitems[$i]->{'WEB'} = 1;
188
189             }
190             $biblioitems[$i]->{'dewey'} =~ /(\d*\.\d\d)/;
191             $biblioitems[$i]->{'dewey'} = $1;
192             ( $itemcount, @items ) =
193               &getitemsbybiblioitem( $biblioitems[$i]->{'biblioitemnumber'} );
194             $biblioitems[$i]->{'items'} = \@items;
195         }    # for
196         $template->param(
197             BIBNUM    => $biblionumber,
198             AUTHOR    => $biblios[0]->{'author'},
199             TITLE     => $biblios[0]->{'title'},
200             COPYRIGHT => $biblios[0]->{'copyrightdate'},
201             SERIES    => $biblios[0]->{'seriestitle'},
202             NOTES     => $biblios[0]->{'notes'},
203             BIBITEMS  => \@biblioitems,
204             BRANCHES  => \@branches,
205             ITEMTYPES => \@itemtypes,
206
207         );
208
209         output_html_with_http_headers $input, $cookie, $template->output;
210     }    # if
211 }    # if