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