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