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