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