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>.
30 use C4
::AuthoritiesMarc
;
34 use C4
::Search
::History
;
36 use Koha
::Authority
::Types
;
37 use Koha
::SearchEngine
::Search
;
38 use Koha
::SearchEngine
::QueryBuilder
;
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",
58 flagsrequired
=> { catalogue
=> 1 },
63 die "Wrong CSRF token" 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;
89 my $builder = Koha
::SearchEngine
::QueryBuilder
->new(
90 { index => $Koha::SearchEngine
::AUTHORITIES_INDEX
} );
91 my $searcher = Koha
::SearchEngine
::Search
->new(
92 { index => $Koha::SearchEngine
::AUTHORITIES_INDEX
} );
93 my $search_query = $builder->build_authorities_query_compat(
94 [$marclist], [$and_or], [$excluding], [$operator],
95 [$value], $authtypecode, $orderby
97 my ( $results, $total ) = $searcher->search_auth_compat(
98 $search_query, $startfrom, $resultsperpage
101 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
103 template_name
=> "authorities/searchresultlist.tt",
106 authnotrequired
=> 0,
107 flagsrequired
=> { catalogue
=> 1 },
113 csrf_token
=> Koha
::Token
->new->generate_csrf({
114 session_id
=> scalar $query->cookie('CGISESSID'),
119 if (C4
::Context
->preference('EnableSearchHistory')) {
120 if ( $startfrom == 1) {
121 my $path_info = $query->url(-path_info
=>1);
122 my $query_cgi_history = $query->url(-query
=>1);
123 $query_cgi_history =~ s/^$path_info\?//;
124 $query_cgi_history =~ s/;/&/g;
126 C4
::Search
::History
::add
({
127 userid
=> $loggedinuser,
128 sessionid
=> $query->cookie("CGISESSID"),
129 query_desc
=> $value,
130 query_cgi
=> $query_cgi_history,
138 marclist
=> $marclist,
140 excluding
=> $excluding,
141 operator
=> $operator,
144 authtypecode
=> $authtypecode,
145 startfrom
=> $startfrom,
146 resultsperpage
=> $resultsperpage,
149 # we must get parameters once again. Because if there is a mainentry, it
150 # has been replaced by something else during the search, thus the links
151 # next/previous would not work anymore
153 # construction of the url of each page
154 my $value_url = uri_escape_utf8
($value);
155 my $base_url = "authorities-home.pl?"
156 ."marclist=$marclist"
157 ."&and_or=$and_or"
158 ."&excluding=$excluding"
159 ."&operator=$operator"
160 ."&value=$value_url"
161 ."&resultsperpage=$resultsperpage"
162 ."&type=intranet"
164 ."&authtypecode=$authtypecode"
165 ."&orderby=$orderby";
167 my $from = ( $startfrom - 1 ) * $resultsperpage + 1;
169 if ( !defined $total ) {
173 if ( $total < $startfrom * $resultsperpage ) {
177 $to = $startfrom * $resultsperpage;
180 $template->param( result
=> $results ) if $results;
183 pagination_bar
=> pagination_bar
(
184 $base_url, int( $total / $resultsperpage ) + 1,
185 $startfrom, 'startfrom'
190 isEDITORS
=> $authtypecode eq 'EDITORS',
195 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
197 template_name
=> "authorities/authorities-home.tt",
200 authnotrequired
=> 0,
201 flagsrequired
=> { catalogue
=> 1 },
208 my $schema = Koha
::Database
->new()->schema();
209 my $servers = $schema->resultset('Z3950server')->search(
211 recordtype
=> 'authority',
212 servertype
=> ['zed', 'sru'],
214 { result_class
=> 'DBIx::Class::ResultClass::HashRefInflator',
215 order_by
=> ['rank', 'servername'],
221 authority_types
=> $authority_types,
225 $template->{VARS
}->{marcflavour
} = C4
::Context
->preference("marcflavour");
228 output_html_with_http_headers
$query, $cookie, $template->output;