script to edit the item subcategory table.
[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.5  2005/05/04 08:45:33  tipaul
24 # synch'ing 2.2 and head
25 #
26 # Revision 1.4.2.1  2005/03/25 12:52:44  tipaul
27 # needs "editcatalogue" flag, not "catalogue"
28 #
29 # Revision 1.4  2004/11/19 16:41:49  tipaul
30 # improving behaviour when MARC=OFF
31 #
32 # Revision 1.3  2004/08/13 16:37:25  tipaul
33 # adding frameworkcode to API in some subs
34 #
35 # Revision 1.2  2003/05/11 06:59:11  rangi
36 # Mostly templated.
37 # Still needs some work
38 #
39
40 use CGI;
41 use strict;
42 use C4::Acquisition;
43 use C4::Biblio;
44 use C4::Output;
45 use HTML::Template;
46 use C4::Auth;
47 use C4::Interface::CGI::Output;
48
49 my $input        = new CGI;
50 my $biblionumber = $input->param('biblionumber');
51 my $error        = $input->param('error');
52 my $maxbarcode;
53 my $isbn;
54 my $bibliocount;
55 my @biblios;
56 my $biblioitemcount;
57 my @biblioitems;
58 my $branchcount;
59 my @branches;
60 my %branchnames;
61 my $itemcount;
62 my @items;
63 my $itemtypecount;
64 my @itemtypes;
65 my %itemtypedescriptions;
66
67 if ( !$biblionumber ) {
68     print $input->redirect('addbooks.pl');
69 }
70 else {
71
72     ( $bibliocount, @biblios ) = &getbiblio($biblionumber);
73
74     if ( !$bibliocount ) {
75         print $input->redirect('addbooks.pl');
76     }
77     else {
78
79         ( $biblioitemcount, @biblioitems ) =
80           &getbiblioitembybiblionumber($biblionumber);
81         ( $branchcount,   @branches )  = &branches;
82         ( $itemtypecount, @itemtypes ) = &getitemtypes;
83
84         for ( my $i = 0 ; $i < $itemtypecount ; $i++ ) {
85             $itemtypedescriptions{ $itemtypes[$i]->{'itemtype'} } =
86               $itemtypes[$i]->{'description'};
87         }    # for
88
89         for ( my $i = 0 ; $i < $branchcount ; $i++ ) {
90             $branchnames{ $branches[$i]->{'branchcode'} } =
91               $branches[$i]->{'branchname'};
92         }    # for
93
94         #       print $input->header;
95         #       print startpage();
96         #       print startmenu('acquisitions');
97         my $input = new CGI;
98         my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
99             {
100                 template_name   => "acqui.simple/additem-nomarc.tmpl",
101                 query           => $input,
102                 type            => "intranet",
103                 authnotrequired => 0,
104                 flagsrequired   => { editcatalogue => 1 },
105                 debug           => 1,
106             }
107         );
108
109         if ( $error eq "nobarcode" ) {
110             $template->param( NOBARCODE => 1 );
111         }
112         elsif ( $error eq "nobiblioitem" ) {
113             $template->param( NOBIBLIOITEM => 1 );
114         }
115         elsif ( $error eq "barcodeinuse" ) {
116             $template->param( BARCODEINUSE => 1 );
117         }    # elsif
118
119         for ( my $i = 0 ; $i < $biblioitemcount ; $i++ ) {
120             if ( $biblioitems[$i]->{'itemtype'} eq "WEB" ) {
121                 $biblioitems[$i]->{'WEB'} = 1;
122
123             }
124             $biblioitems[$i]->{'dewey'} =~ /(\d*\.\d\d)/;
125             $biblioitems[$i]->{'dewey'} = $1;
126             ( $itemcount, @items ) =
127               &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             BRANCHES  => \@branches,
139             ITEMTYPES => \@itemtypes,
140
141         );
142
143         output_html_with_http_headers $input, $cookie, $template->output;
144     }    # if
145 }    # if