]> git.koha-community.org Git - koha.git/blob - cataloguing/addbooks.pl
Bug 24810: French SQL files for "news" removed "3"
[koha.git] / cataloguing / addbooks.pl
1 #!/usr/bin/perl
2
3
4 # Copyright 2000-2002 Katipo Communications
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20
21 =head1 cataloguing:addbooks.pl
22
23         TODO
24
25 =cut
26
27 use Modern::Perl;
28
29 use CGI qw ( -utf8 );
30 use URI::Escape;
31 use C4::Auth;
32 use C4::Biblio;
33 use C4::Breeding;
34 use C4::Output;
35 use C4::Koha;
36 use C4::Languages qw(getlanguage);
37 use C4::Search;
38
39 use Koha::BiblioFrameworks;
40 use Koha::SearchEngine::Search;
41 use Koha::SearchEngine::QueryBuilder;
42 use Koha::Z3950Servers;
43
44 my $input = new CGI;
45
46 my $success = $input->param('biblioitem');
47 my $query   = $input->param('q');
48 my @value   = $input->multi_param('value');
49 my $page    = $input->param('page') || 1;
50 my $results_per_page = 20;
51 my $lang = C4::Languages::getlanguage($input);
52
53
54 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
55     {
56         template_name   => "cataloguing/addbooks.tt",
57         query           => $input,
58         type            => "intranet",
59         flagsrequired   => { editcatalogue => '*' },
60         debug           => 1,
61     }
62 );
63
64 # Searching the catalog.
65 if ($query) {
66
67     # build query
68     my @operands = $query;
69
70     my $QParser;
71     $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
72     my $builtquery;
73     my $query_cgi;
74     my $builder = Koha::SearchEngine::QueryBuilder->new(
75         { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
76     my $searcher = Koha::SearchEngine::Search->new(
77         { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
78     if ($QParser) {
79         $builtquery = $query;
80         $query_cgi = "q=".uri_escape_utf8($query);
81     } else {
82         ( undef, $builtquery, undef, $query_cgi, undef, undef, undef, undef, undef, undef ) =
83           $builder->build_query_compat( undef, \@operands, undef, undef, undef, 0, $lang );
84     }
85
86     $template->param( search_query => $builtquery ) if C4::Context->preference('DumpSearchQueryTemplate');
87
88     # find results
89     my ( $error, $marcresults, $total_hits ) = $searcher->simple_search_compat($builtquery, $results_per_page * ($page - 1), $results_per_page);
90
91     if ( defined $error ) {
92         $template->param( error => $error );
93         warn "error: " . $error;
94         output_html_with_http_headers $input, $cookie, $template->output;
95         exit;
96     }
97
98     # format output
99     # SimpleSearch() give the results per page we want, so 0 offet here
100     my $total = @{$marcresults};
101     my @newresults = searchResults( {'interface' => 'intranet'}, $query, $total, $results_per_page, 0, 0, $marcresults );
102     foreach my $line (@newresults) {
103         if ( not exists $line->{'size'} ) { $line->{'size'} = "" }
104     }
105     $template->param(
106         total          => $total_hits,
107         query          => $query,
108         resultsloop    => \@newresults,
109         pagination_bar => pagination_bar( "/cgi-bin/koha/cataloguing/addbooks.pl?$query_cgi&", getnbpages( $total_hits, $results_per_page ), $page, 'page' ),
110     );
111 }
112
113 # fill with books in breeding farm
114
115 my $countbr = 0;
116 my @resultsbr;
117 if ($query) {
118 # fill isbn or title, depending on what has been entered
119 #u must do check on isbn because u can find number in beginning of title
120 #check is on isbn legnth 13 for new isbn and 10 for old isbn
121     my ( $title, $isbn );
122     if ($query=~/\d/) {
123         my $clean_query = $query;
124         $clean_query =~ s/-//g; # remove hyphens
125         my $querylength = length $clean_query;
126         if ( $querylength == 13 || $querylength == 10 ) {
127             $isbn = $query;
128         }
129     }
130     if (!$isbn) {
131         $title = $query;
132     }
133     ( $countbr, @resultsbr ) = BreedingSearch( $title, $isbn );
134 }
135 my $breeding_loop = [];
136 for my $resultsbr (@resultsbr) {
137     push @{$breeding_loop}, {
138         id               => $resultsbr->{import_record_id},
139         isbn             => $resultsbr->{isbn},
140         copyrightdate    => $resultsbr->{copyrightdate},
141         editionstatement => $resultsbr->{editionstatement},
142         file             => $resultsbr->{file_name},
143         title            => $resultsbr->{title},
144         author           => $resultsbr->{author},
145     };
146 }
147
148 my $servers = Koha::Z3950Servers->search(
149     {
150         recordtype => 'biblio',
151         servertype => ['zed','sru'],
152     }
153 );
154
155 my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] });
156 $template->param(
157     servers           => $servers,
158     frameworks        => $frameworks,
159     breeding_count    => $countbr,
160     breeding_loop     => $breeding_loop,
161     z3950_search_params => C4::Search::z3950_search_args($query),
162 );
163
164 output_html_with_http_headers $input, $cookie, $template->output;
165