various bugfixes (minor) and french translation updated
[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
42 use C4::Koha;
43 use C4::Search;
44
45 my $input = new CGI;
46
47 my $success = $input->param('biblioitem');
48 my $query   = $input->param('q');
49 my @value = $input->param('value');
50
51 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
52     {
53         template_name   => "cataloguing/addbooks.tmpl",
54         query           => $input,
55         type            => "intranet",
56         authnotrequired => 0,
57         flagsrequired   => { editcatalogue => 1 },
58         debug           => 1,
59     }
60 );
61
62 # get framework list
63 my $frameworks = getframeworks;
64 my @frameworkcodeloop;
65 foreach my $thisframeworkcode (keys %$frameworks) {
66         my %row =(value => $thisframeworkcode,
67                                 frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'},
68                         );
69         push @frameworkcodeloop, \%row;
70 }
71
72 # Searching the catalog.
73 if($query) {
74     my ($error, $marcresults) = SimpleSearch($query);
75
76     if (defined $error) {
77         $template->param(error => $error);
78         warn "error: ".$error;
79         output_html_with_http_headers $input, $cookie, $template->output;
80         exit;
81     }
82
83     my $total = scalar @$marcresults;
84     my @results;
85
86     for(my $i=0;$i<$total;$i++) {
87         my %resultsloop;
88         my $marcrecord = MARC::File::USMARC::decode($marcresults->[$i]);
89         my $biblio = TransformMarcToKoha(C4::Context->dbh,$marcrecord,'');
90     
91         #hilight the result
92         $biblio->{'title'} =~ s/$query/<span class=term>$&<\/span>/gi;
93         $biblio->{'subtitle'} =~ s/$query/<span class=term>$&<\/span>/gi;
94         $biblio->{'biblionumber'} =~ s/$query/<span class=term>$&<\/span>/gi;
95         $biblio->{'author'} =~ s/$query/<span class=term>$&<\/span>/gi;
96         $biblio->{'publishercode'} =~ s/$query/<span class=term>$&<\/span>/gi;
97         $biblio->{'publicationyear'} =~ s/$query/<span class=term>$&<\/span>/gi;
98     
99         #build the hash for the template.
100         $resultsloop{highlight}       = ($i % 2)?(1):(0);
101         $resultsloop{title}           = $biblio->{'title'};
102         $resultsloop{subtitle}        = $biblio->{'subtitle'};
103         $resultsloop{biblionumber}    = $biblio->{'biblionumber'};
104         $resultsloop{author}          = $biblio->{'author'};
105         $resultsloop{publishercode}   = $biblio->{'publishercode'};
106         $resultsloop{publicationyear} = $biblio->{'publicationyear'};
107
108         push @results, \%resultsloop;
109     }
110     $template->param(
111         total => $total,
112         query => $query,
113         resultsloop => \@results,
114     );
115 }
116
117 # fill with books in breeding farm
118 my $toggle=0;
119 my ($title,$isbn);
120 # fill isbn or title, depending on what has been entered
121 #u must do check on isbn because u can find number in beginning of title
122 #check is on isbn legnth 13 for new isbn and 10 for old isbn
123 my $querylength=length($query);
124  if ($query =~ /\d/ and ($querylength eq 13 or $querylength eq 10))
125 {
126 $isbn=$query;
127 }
128 $title=$query unless $isbn;
129 my ( $countbr, @resultsbr ) = BreedingSearch( $title, $isbn ) if $query;
130 my @breeding_loop = ();
131 for ( my $i = 0 ; $i <= $#resultsbr ; $i++ ) {
132     my %row_data;
133     if ( $i % 2 ) {
134         $toggle = 0;
135     }
136     else {
137         $toggle = 1;
138     }
139     $row_data{toggle} = $toggle;
140     $row_data{id}     = $resultsbr[$i]->{'id'};
141     $row_data{isbn}   = $resultsbr[$i]->{'isbn'};
142     $row_data{file}   = $resultsbr[$i]->{'file'};
143     $row_data{title}  = $resultsbr[$i]->{'title'};
144     $row_data{author} = $resultsbr[$i]->{'author'};
145     push ( @breeding_loop, \%row_data );
146 }
147
148 $template->param( frameworkcodeloop => \@frameworkcodeloop,
149                   breeding_loop => \@breeding_loop,
150               );
151
152 output_html_with_http_headers $input, $cookie, $template->output;