3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
29 use C4
::AuthoritiesMarc
;
33 use C4
::Search
::History
;
35 use Koha
::Authority
::Types
;
36 use Koha
::SearchEngine
::Search
;
37 use Koha
::SearchEngine
::QueryBuilder
;
39 use Koha
::Z3950Servers
;
42 my $dbh = C4
::Context
->dbh;
43 my $op = $query->param('op') || '';
44 my $authtypecode = $query->param('authtypecode') || '';
45 my $authid = $query->param('authid') || '';
47 my ( $template, $loggedinuser, $cookie );
49 my $authority_types = Koha
::Authority
::Types
->search( {}, { order_by
=> ['authtypetext'] } );
51 if ( $op eq "delete" ) {
52 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
54 template_name
=> "authorities/authorities-home.tt",
57 flagsrequired
=> { catalogue
=> 1 },
62 output_and_exit
( $query, $cookie, $template, 'wrong_csrf_token' )
63 unless Koha
::Token
->new->check_csrf({
64 session_id
=> scalar $query->cookie('CGISESSID'),
65 token
=> scalar $query->param('csrf_token'),
68 DelAuthority
({ authid
=> $authid });
70 if ( $query->param('operator') ) {
71 # query contains search params so perform search
78 if ( $op eq "do_search" ) {
79 my $marclist = $query->param('marclist') || '';
80 my $and_or = $query->param('and_or') || '';
81 my $excluding = $query->param('excluding') || '';
82 my $operator = $query->param('operator') || '';
83 my $orderby = $query->param('orderby') || '';
84 my $value = $query->param('value') || '';
86 my $startfrom = $query->param('startfrom') || 1;
87 my $resultsperpage = $query->param('resultsperpage') || 20;
88 my $offset = ( $startfrom - 1 ) * $resultsperpage + 1;
90 my $builder = Koha
::SearchEngine
::QueryBuilder
->new(
91 { index => $Koha::SearchEngine
::AUTHORITIES_INDEX
} );
92 my $searcher = Koha
::SearchEngine
::Search
->new(
93 { index => $Koha::SearchEngine
::AUTHORITIES_INDEX
} );
94 my $search_query = $builder->build_authorities_query_compat(
95 [$marclist], [$and_or], [$excluding], [$operator],
96 [$value], $authtypecode, $orderby
98 my ( $results, $total ) = $searcher->search_auth_compat(
99 $search_query, $offset, $resultsperpage
102 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
104 template_name
=> "authorities/searchresultlist.tt",
107 flagsrequired
=> { catalogue
=> 1 },
112 $template->param( search_query
=> $search_query ) if C4
::Context
->preference('DumpSearchQueryTemplate');
114 csrf_token
=> Koha
::Token
->new->generate_csrf({
115 session_id
=> scalar $query->cookie('CGISESSID'),
120 if (C4
::Context
->preference('EnableSearchHistory')) {
121 if ( $startfrom == 1) {
122 my $path_info = $query->url(-path_info
=>1);
123 my $query_cgi_history = $query->url(-query
=>1);
124 $query_cgi_history =~ s/^$path_info\?//;
125 $query_cgi_history =~ s/;/&/g;
127 C4
::Search
::History
::add
({
128 userid
=> $loggedinuser,
129 sessionid
=> $query->cookie("CGISESSID"),
130 query_desc
=> $value,
131 query_cgi
=> $query_cgi_history,
139 marclist
=> $marclist,
141 excluding
=> $excluding,
142 operator
=> $operator,
145 authtypecode
=> $authtypecode,
146 startfrom
=> $startfrom,
147 resultsperpage
=> $resultsperpage,
150 # we must get parameters once again. Because if there is a mainentry, it
151 # has been replaced by something else during the search, thus the links
152 # next/previous would not work anymore
154 # construction of the url of each page
155 my $value_url = uri_escape_utf8
($value);
156 my $base_url = "authorities-home.pl?"
157 ."marclist=$marclist"
158 ."&and_or=$and_or"
159 ."&excluding=$excluding"
160 ."&operator=$operator"
161 ."&value=$value_url"
162 ."&resultsperpage=$resultsperpage"
163 ."&type=intranet"
165 ."&authtypecode=$authtypecode"
166 ."&orderby=$orderby";
168 my $from = ( $startfrom - 1 ) * $resultsperpage + 1;
170 if ( !defined $total ) {
174 if ( $total < $startfrom * $resultsperpage ) {
178 $to = $startfrom * $resultsperpage;
181 $template->param( result
=> $results ) if $results;
183 my $max_result_window = $searcher->max_result_window;
184 my $hits_to_paginate = ($max_result_window && $max_result_window < $total) ?
$max_result_window : $total;
187 pagination_bar
=> pagination_bar
(
188 $base_url, ceil
( $hits_to_paginate / $resultsperpage ),
189 $startfrom, 'startfrom'
192 hits_to_paginate
=> $hits_to_paginate,
195 isEDITORS
=> $authtypecode eq 'EDITORS',
200 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
202 template_name
=> "authorities/authorities-home.tt",
205 flagsrequired
=> { catalogue
=> 1 },
212 my $servers = Koha
::Z3950Servers
->search(
214 recordtype
=> 'authority',
215 servertype
=> ['zed', 'sru'],
221 authority_types
=> $authority_types,
225 $template->{VARS
}->{marcflavour
} = C4
::Context
->preference("marcflavour");
228 output_html_with_http_headers
$query, $cookie, $template->output;