rel_3_0 moved to HEAD
[koha.git] / cataloguing / addbooks.pl
1 #!/usr/bin/perl
2
3 # $Id$
4
5 #
6 # Modified saas@users.sf.net 12:00 01 April 2001
7 # The biblioitemnumber was not correctly initialised
8 # The max(barcode) value was broken - koha 'barcode' is a string value!
9 # - If left blank, barcode value now defaults to max(biblionumber)
10
11 #
12 # TODO
13 #
14 # Add info on biblioitems and items already entered as you enter new ones
15 #
16 # Add info on biblioitems and items already entered as you enter new ones
17
18 # Copyright 2000-2002 Katipo Communications
19 #
20 # This file is part of Koha.
21 #
22 # Koha is free software; you can redistribute it and/or modify it under the
23 # terms of the GNU General Public License as published by the Free Software
24 # Foundation; either version 2 of the License, or (at your option) any later
25 # version.
26 #
27 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
28 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
29 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
30 #
31 # You should have received a copy of the GNU General Public License along with
32 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
33 # Suite 330, Boston, MA  02111-1307 USA
34
35 use strict;
36 use CGI;
37 use C4::Auth;
38 use C4::Biblio;
39 use C4::Breeding;
40 use C4::Output;
41 use C4::Interface::CGI::Output;
42
43 use C4::Koha;
44 use C4::Search;
45
46 my $input = new CGI;
47
48 my $success = $input->param('biblioitem');
49 my $query   = $input->param('q');
50 my @value = $input->param('value');
51
52 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
53     {
54         template_name   => "cataloguing/addbooks.tmpl",
55         query           => $input,
56         type            => "intranet",
57         authnotrequired => 0,
58         flagsrequired   => { editcatalogue => 1 },
59         debug           => 1,
60     }
61 );
62
63 # get framework list
64 my $frameworks = getframeworks;
65 my @frameworkcodeloop;
66 foreach my $thisframeworkcode (keys %$frameworks) {
67         my %row =(value => $thisframeworkcode,
68                                 frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'},
69                         );
70         push @frameworkcodeloop, \%row;
71 }
72
73 # Searching the catalog.
74 if($query) {
75     my ($error, $marcresults) = SimpleSearch($query);
76
77     if (defined $error) {
78         $template->param(error => $error);
79         warn "error: ".$error;
80         output_html_with_http_headers $input, $cookie, $template->output;
81         exit;
82     }
83
84     my $total = scalar @$marcresults;
85     my @results;
86
87     for(my $i=0;$i<$total;$i++) {
88         my %resultsloop;
89         my $marcrecord = MARC::File::USMARC::decode($marcresults->[$i]);
90         my $biblio = MARCmarc2koha(C4::Context->dbh,$marcrecord,'');
91     
92         #hilight the result
93         $biblio->{'title'} =~ s/$query/<span class=term>$&<\/span>/gi;
94         $biblio->{'subtitle'} =~ s/$query/<span class=term>$&<\/span>/gi;
95         $biblio->{'biblionumber'} =~ s/$query/<span class=term>$&<\/span>/gi;
96         $biblio->{'author'} =~ s/$query/<span class=term>$&<\/span>/gi;
97         $biblio->{'publishercode'} =~ s/$query/<span class=term>$&<\/span>/gi;
98         $biblio->{'publicationyear'} =~ s/$query/<span class=term>$&<\/span>/gi;
99     
100         #build the hash for the template.
101         $resultsloop{highlight}       = ($i % 2)?(1):(0);
102         $resultsloop{title}           = $biblio->{'title'};
103         $resultsloop{subtitle}        = $biblio->{'subtitle'};
104         $resultsloop{biblionumber}    = $biblio->{'biblionumber'};
105         $resultsloop{author}          = $biblio->{'author'};
106         $resultsloop{publishercode}   = $biblio->{'publishercode'};
107         $resultsloop{publicationyear} = $biblio->{'publicationyear'};
108
109         push @results, \%resultsloop;
110     }
111     $template->param(
112         total => $total,
113         query => $query,
114         resultsloop => \@results,
115     );
116 }
117
118 # fill with books in breeding farm
119 my $toggle=0;
120 my ($title,$isbn);
121 # fill isbn or title, depending on what has been entered
122 $isbn=$query if $query =~ /\d/;
123 $title=$query unless $isbn;
124 my ( $countbr, @resultsbr ) = BreedingSearch( $title, $isbn ) if $query;
125 my @breeding_loop = ();
126 for ( my $i = 0 ; $i <= $#resultsbr ; $i++ ) {
127     my %row_data;
128     if ( $i % 2 ) {
129         $toggle = 0;
130     }
131     else {
132         $toggle = 1;
133     }
134     $row_data{toggle} = $toggle;
135     $row_data{id}     = $resultsbr[$i]->{'id'};
136     $row_data{isbn}   = $resultsbr[$i]->{'isbn'};
137     $row_data{file}   = $resultsbr[$i]->{'file'};
138     $row_data{title}  = $resultsbr[$i]->{'title'};
139     $row_data{author} = $resultsbr[$i]->{'author'};
140     push ( @breeding_loop, \%row_data );
141 }
142
143 $template->param( frameworkcodeloop => \@frameworkcodeloop,
144                   breeding_loop => \@breeding_loop,
145               );
146
147 output_html_with_http_headers $input, $cookie, $template->output;