Bug 17800: Add admin sidebar menu to marc-subfields-structure.pl
[koha.git] / cataloguing / addbooks.pl
blob1d52bb800794260e64588ce870d31cb409df0fa4
1 #!/usr/bin/perl
4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
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.
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.
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>.
21 =head1 cataloguing:addbooks.pl
23 TODO
25 =cut
27 use strict;
28 use warnings;
29 use CGI qw ( -utf8 );
30 use C4::Auth;
31 use C4::Biblio;
32 use C4::Breeding;
33 use C4::Output;
34 use C4::Koha;
35 use C4::Search;
37 use Koha::BiblioFrameworks;
38 use Koha::SearchEngine::Search;
39 use Koha::SearchEngine::QueryBuilder;
41 my $input = new CGI;
43 my $success = $input->param('biblioitem');
44 my $query = $input->param('q');
45 my @value = $input->multi_param('value');
46 my $page = $input->param('page') || 1;
47 my $results_per_page = 20;
50 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
52 template_name => "cataloguing/addbooks.tt",
53 query => $input,
54 type => "intranet",
55 authnotrequired => 0,
56 flagsrequired => { editcatalogue => '*' },
57 debug => 1,
61 # Searching the catalog.
62 if ($query) {
64 # build query
65 my @operands = $query;
67 my $QParser;
68 $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
69 my $builtquery;
70 my $builder = Koha::SearchEngine::QueryBuilder->new(
71 { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
72 my $searcher = Koha::SearchEngine::Search->new(
73 { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
74 if ($QParser) {
75 $builtquery = $query;
76 } else {
77 ( undef,$builtquery,undef,undef,undef,undef,undef,undef,undef,undef) = $builder->build_query_compat(undef,\@operands);
79 # find results
80 my ( $error, $marcresults, $total_hits ) = $searcher->simple_search_compat($builtquery, $results_per_page * ($page - 1), $results_per_page);
82 if ( defined $error ) {
83 $template->param( error => $error );
84 warn "error: " . $error;
85 output_html_with_http_headers $input, $cookie, $template->output;
86 exit;
89 # format output
90 # SimpleSearch() give the results per page we want, so 0 offet here
91 my $total = @{$marcresults};
92 my @newresults = searchResults( 'intranet', $query, $total, $results_per_page, 0, 0, $marcresults );
93 $template->param(
94 total => $total_hits,
95 query => $query,
96 resultsloop => \@newresults,
97 pagination_bar => pagination_bar( "/cgi-bin/koha/cataloguing/addbooks.pl?q=$query&", getnbpages( $total_hits, $results_per_page ), $page, 'page' ),
101 # fill with books in breeding farm
103 my $countbr = 0;
104 my @resultsbr;
105 if ($query) {
106 # fill isbn or title, depending on what has been entered
107 #u must do check on isbn because u can find number in beginning of title
108 #check is on isbn legnth 13 for new isbn and 10 for old isbn
109 my ( $title, $isbn );
110 if ($query=~/\d/) {
111 my $clean_query = $query;
112 $clean_query =~ s/-//g; # remove hyphens
113 my $querylength = length $clean_query;
114 if ( $querylength == 13 || $querylength == 10 ) {
115 $isbn = $query;
118 if (!$isbn) {
119 $title = $query;
121 ( $countbr, @resultsbr ) = BreedingSearch( $title, $isbn );
123 my $breeding_loop = [];
124 for my $resultsbr (@resultsbr) {
125 push @{$breeding_loop}, {
126 id => $resultsbr->{import_record_id},
127 isbn => $resultsbr->{isbn},
128 copyrightdate => $resultsbr->{copyrightdate},
129 editionstatement => $resultsbr->{editionstatement},
130 file => $resultsbr->{file_name},
131 title => $resultsbr->{title},
132 author => $resultsbr->{author},
136 my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] });
137 $template->param(
138 frameworks => $frameworks,
139 breeding_count => $countbr,
140 breeding_loop => $breeding_loop,
141 z3950_search_params => C4::Search::z3950_search_args($query),
144 output_html_with_http_headers $input, $cookie, $template->output;