Bug 19835: Update MARC frameworks to Updates 23+24+25 (Nov 2016, May and Dec 2017)
[koha.git] / authorities / authorities-home.pl
blob3f400722c3edef15542544c2fe13c015062157ef
1 #!/usr/bin/perl
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>.
20 use strict;
21 use warnings;
23 use CGI qw ( -utf8 );
24 use URI::Escape;
25 use C4::Auth;
27 use C4::Context;
28 use C4::Auth;
29 use C4::Output;
30 use C4::AuthoritiesMarc;
31 use C4::Acquisition;
32 use C4::Koha;
33 use C4::Biblio;
34 use C4::Search::History;
36 use Koha::Authority::Types;
37 use Koha::SearchEngine::Search;
38 use Koha::SearchEngine::QueryBuilder;
39 use Koha::Token;
40 use Koha::Z3950Servers;
42 my $query = new CGI;
43 my $dbh = C4::Context->dbh;
44 my $op = $query->param('op') || '';
45 my $authtypecode = $query->param('authtypecode') || '';
46 my $authid = $query->param('authid') || '';
48 my ( $template, $loggedinuser, $cookie );
50 my $authority_types = Koha::Authority::Types->search( {}, { order_by => ['authtypetext'] } );
52 if ( $op eq "delete" ) {
53 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
55 template_name => "authorities/authorities-home.tt",
56 query => $query,
57 type => 'intranet',
58 authnotrequired => 0,
59 flagsrequired => { catalogue => 1 },
60 debug => 1,
64 die "Wrong CSRF token" unless Koha::Token->new->check_csrf({
65 session_id => scalar $query->cookie('CGISESSID'),
66 token => scalar $query->param('csrf_token'),
67 });
69 DelAuthority({ authid => $authid });
71 if ( $query->param('operator') ) {
72 # query contains search params so perform search
73 $op = "do_search";
75 else {
76 $op = '';
79 if ( $op eq "do_search" ) {
80 my $marclist = $query->param('marclist') || '';
81 my $and_or = $query->param('and_or') || '';
82 my $excluding = $query->param('excluding') || '';
83 my $operator = $query->param('operator') || '';
84 my $orderby = $query->param('orderby') || '';
85 my $value = $query->param('value') || '';
87 my $startfrom = $query->param('startfrom') || 1;
88 my $resultsperpage = $query->param('resultsperpage') || 20;
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, $startfrom, $resultsperpage
102 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
104 template_name => "authorities/searchresultlist.tt",
105 query => $query,
106 type => 'intranet',
107 authnotrequired => 0,
108 flagsrequired => { catalogue => 1 },
109 debug => 1,
113 $template->param(
114 csrf_token => Koha::Token->new->generate_csrf({
115 session_id => scalar $query->cookie('CGISESSID'),
119 # search history
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,
132 total => $total,
133 type => "authority",
138 $template->param(
139 marclist => $marclist,
140 and_or => $and_or,
141 excluding => $excluding,
142 operator => $operator,
143 orderby => $orderby,
144 value => $value,
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 ."&amp;and_or=$and_or"
159 ."&amp;excluding=$excluding"
160 ."&amp;operator=$operator"
161 ."&amp;value=$value_url"
162 ."&amp;resultsperpage=$resultsperpage"
163 ."&amp;type=intranet"
164 ."&amp;op=do_search"
165 ."&amp;authtypecode=$authtypecode"
166 ."&amp;orderby=$orderby";
168 my $from = ( $startfrom - 1 ) * $resultsperpage + 1;
169 my $to;
170 if ( !defined $total ) {
171 $total = 0;
174 if ( $total < $startfrom * $resultsperpage ) {
175 $to = $total;
177 else {
178 $to = $startfrom * $resultsperpage;
181 $template->param( result => $results ) if $results;
183 $template->param(
184 pagination_bar => pagination_bar(
185 $base_url, int( $total / $resultsperpage ) + 1,
186 $startfrom, 'startfrom'
188 total => $total,
189 from => $from,
190 to => $to,
191 isEDITORS => $authtypecode eq 'EDITORS',
195 if ( $op eq '' ) {
196 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
198 template_name => "authorities/authorities-home.tt",
199 query => $query,
200 type => 'intranet',
201 authnotrequired => 0,
202 flagsrequired => { catalogue => 1 },
203 debug => 1,
209 my $servers = Koha::Z3950Servers->search(
211 recordtype => 'authority',
212 servertype => ['zed', 'sru'],
216 $template->param(
217 servers => $servers,
218 authority_types => $authority_types,
219 op => $op,
222 $template->{VARS}->{marcflavour} = C4::Context->preference("marcflavour");
224 # Print the page
225 output_html_with_http_headers $query, $cookie, $template->output;