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