Bug 9302: Use patron-title.inc
[koha.git] / cataloguing / addbooks.pl
blob253683db1dd841597743a76c2f72a5be4de87071
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 Modern::Perl;
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;
40 use Koha::Z3950Servers;
42 my $input = new CGI;
44 my $success = $input->param('biblioitem');
45 my $query = $input->param('q');
46 my @value = $input->multi_param('value');
47 my $page = $input->param('page') || 1;
48 my $results_per_page = 20;
51 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
53 template_name => "cataloguing/addbooks.tt",
54 query => $input,
55 type => "intranet",
56 authnotrequired => 0,
57 flagsrequired => { editcatalogue => '*' },
58 debug => 1,
62 # Searching the catalog.
63 if ($query) {
65 # build query
66 my @operands = $query;
68 my $QParser;
69 $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
70 my $builtquery;
71 my $builder = Koha::SearchEngine::QueryBuilder->new(
72 { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
73 my $searcher = Koha::SearchEngine::Search->new(
74 { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
75 if ($QParser) {
76 $builtquery = $query;
77 } else {
78 ( undef,$builtquery,undef,undef,undef,undef,undef,undef,undef,undef) = $builder->build_query_compat(undef,\@operands);
80 # find results
81 my ( $error, $marcresults, $total_hits ) = $searcher->simple_search_compat($builtquery, $results_per_page * ($page - 1), $results_per_page);
83 if ( defined $error ) {
84 $template->param( error => $error );
85 warn "error: " . $error;
86 output_html_with_http_headers $input, $cookie, $template->output;
87 exit;
90 # format output
91 # SimpleSearch() give the results per page we want, so 0 offet here
92 my $total = @{$marcresults};
93 my @newresults = searchResults( 'intranet', $query, $total, $results_per_page, 0, 0, $marcresults );
94 $template->param(
95 total => $total_hits,
96 query => $query,
97 resultsloop => \@newresults,
98 pagination_bar => pagination_bar( "/cgi-bin/koha/cataloguing/addbooks.pl?q=$query&", getnbpages( $total_hits, $results_per_page ), $page, 'page' ),
102 # fill with books in breeding farm
104 my $countbr = 0;
105 my @resultsbr;
106 if ($query) {
107 # fill isbn or title, depending on what has been entered
108 #u must do check on isbn because u can find number in beginning of title
109 #check is on isbn legnth 13 for new isbn and 10 for old isbn
110 my ( $title, $isbn );
111 if ($query=~/\d/) {
112 my $clean_query = $query;
113 $clean_query =~ s/-//g; # remove hyphens
114 my $querylength = length $clean_query;
115 if ( $querylength == 13 || $querylength == 10 ) {
116 $isbn = $query;
119 if (!$isbn) {
120 $title = $query;
122 ( $countbr, @resultsbr ) = BreedingSearch( $title, $isbn );
124 my $breeding_loop = [];
125 for my $resultsbr (@resultsbr) {
126 push @{$breeding_loop}, {
127 id => $resultsbr->{import_record_id},
128 isbn => $resultsbr->{isbn},
129 copyrightdate => $resultsbr->{copyrightdate},
130 editionstatement => $resultsbr->{editionstatement},
131 file => $resultsbr->{file_name},
132 title => $resultsbr->{title},
133 author => $resultsbr->{author},
137 my $servers = Koha::Z3950Servers->search(
139 recordtype => 'biblio',
140 servertype => ['zed','sru'],
144 my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] });
145 $template->param(
146 servers => $servers,
147 frameworks => $frameworks,
148 breeding_count => $countbr,
149 breeding_loop => $breeding_loop,
150 z3950_search_params => C4::Search::z3950_search_args($query),
153 output_html_with_http_headers $input, $cookie, $template->output;