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
;
41 my $dbh = C4
::Context
->dbh;
42 my $op = $query->param('op') || '';
43 my $authtypecode = $query->param('authtypecode') || '';
44 my $authid = $query->param('authid') || '';
46 my ( $template, $loggedinuser, $cookie );
48 my $authority_types = Koha
::Authority
::Types
->search( {}, { order_by
=> ['authtypetext'] } );
50 if ( $op eq "delete" ) {
51 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
53 template_name
=> "authorities/authorities-home.tt",
57 flagsrequired
=> { catalogue
=> 1 },
61 &DelAuthority
( $authid, 1 );
63 if ( $query->param('operator') ) {
64 # query contains search params so perform search
71 if ( $op eq "do_search" ) {
72 my $marclist = $query->param('marclist') || '';
73 my $and_or = $query->param('and_or') || '';
74 my $excluding = $query->param('excluding') || '';
75 my $operator = $query->param('operator') || '';
76 my $orderby = $query->param('orderby') || '';
77 my $value = $query->param('value') || '';
79 my $startfrom = $query->param('startfrom') || 1;
80 my $resultsperpage = $query->param('resultsperpage') || 20;
82 my $builder = Koha
::SearchEngine
::QueryBuilder
->new(
83 { index => $Koha::SearchEngine
::AUTHORITIES_INDEX
} );
84 my $searcher = Koha
::SearchEngine
::Search
->new(
85 { index => $Koha::SearchEngine
::AUTHORITIES_INDEX
} );
86 my $search_query = $builder->build_authorities_query_compat(
87 [$marclist], [$and_or], [$excluding], [$operator],
88 [$value], $authtypecode, $orderby
90 my $offset = ( $startfrom - 1 ) * $resultsperpage + 1;
91 my ( $results, $total ) =
92 $searcher->search_auth_compat( $search_query, $offset,
94 #my ( $results, $total ) = SearchAuthorities(
95 # [$marclist], [$and_or],
96 # [$excluding], [$operator],
97 # [$value], ( $startfrom - 1 ) * $resultsperpage,
98 # $resultsperpage, $authtypecode,
103 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
105 template_name
=> "authorities/searchresultlist.tt",
108 authnotrequired
=> 0,
109 flagsrequired
=> { catalogue
=> 1 },
115 if (C4
::Context
->preference('EnableSearchHistory')) {
116 if ( $startfrom == 1) {
117 my $path_info = $query->url(-path_info
=>1);
118 my $query_cgi_history = $query->url(-query
=>1);
119 $query_cgi_history =~ s/^$path_info\?//;
120 $query_cgi_history =~ s/;/&/g;
122 C4
::Search
::History
::add
({
123 userid
=> $loggedinuser,
124 sessionid
=> $query->cookie("CGISESSID"),
125 query_desc
=> $value,
126 query_cgi
=> $query_cgi_history,
134 marclist
=> $marclist,
136 excluding
=> $excluding,
137 operator
=> $operator,
140 authtypecode
=> $authtypecode,
141 startfrom
=> $startfrom,
142 resultsperpage
=> $resultsperpage,
145 # we must get parameters once again. Because if there is a mainentry, it
146 # has been replaced by something else during the search, thus the links
147 # next/previous would not work anymore
149 # construction of the url of each page
150 my $value_url = uri_escape_utf8
($value);
151 my $base_url = "authorities-home.pl?"
152 ."marclist=$marclist"
153 ."&and_or=$and_or"
154 ."&excluding=$excluding"
155 ."&operator=$operator"
156 ."&value=$value_url"
157 ."&resultsperpage=$resultsperpage"
158 ."&type=intranet"
160 ."&authtypecode=$authtypecode"
161 ."&orderby=$orderby";
163 my $from = ( $startfrom - 1 ) * $resultsperpage + 1;
165 if ( !defined $total ) {
169 if ( $total < $startfrom * $resultsperpage ) {
173 $to = $startfrom * $resultsperpage;
176 $template->param( result
=> $results ) if $results;
179 pagination_bar
=> pagination_bar
(
180 $base_url, int( $total / $resultsperpage ) + 1,
181 $startfrom, 'startfrom'
186 isEDITORS
=> $authtypecode eq 'EDITORS',
191 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
193 template_name
=> "authorities/authorities-home.tt",
196 authnotrequired
=> 0,
197 flagsrequired
=> { catalogue
=> 1 },
205 authority_types
=> $authority_types,
209 $template->{VARS
}->{marcflavour
} = C4
::Context
->preference("marcflavour");
212 output_html_with_http_headers
$query, $cookie, $template->output;