Bug 19200: Preventing warns when exporting a basket
[koha.git] / authorities / authorities-home.pl
blobd9c5ac83bb4e2213e04c9a72e4c5c77c16ea6849
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;
41 my $query = new CGI;
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",
55 query => $query,
56 type => 'intranet',
57 authnotrequired => 0,
58 flagsrequired => { catalogue => 1 },
59 debug => 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'),
66 });
68 DelAuthority({ authid => $authid });
70 if ( $query->param('operator') ) {
71 # query contains search params so perform search
72 $op = "do_search";
74 else {
75 $op = '';
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 $offset = ( $startfrom - 1 ) * $resultsperpage + 1;
98 my ( $results, $total ) =
99 $searcher->search_auth_compat( $search_query, $offset,
100 $resultsperpage );
101 #my ( $results, $total ) = SearchAuthorities(
102 # [$marclist], [$and_or],
103 # [$excluding], [$operator],
104 # [$value], ( $startfrom - 1 ) * $resultsperpage,
105 # $resultsperpage, $authtypecode,
106 # $orderby
110 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
112 template_name => "authorities/searchresultlist.tt",
113 query => $query,
114 type => 'intranet',
115 authnotrequired => 0,
116 flagsrequired => { catalogue => 1 },
117 debug => 1,
121 $template->param(
122 csrf_token => Koha::Token->new->generate_csrf({
123 session_id => scalar $query->cookie('CGISESSID'),
127 # search history
128 if (C4::Context->preference('EnableSearchHistory')) {
129 if ( $startfrom == 1) {
130 my $path_info = $query->url(-path_info=>1);
131 my $query_cgi_history = $query->url(-query=>1);
132 $query_cgi_history =~ s/^$path_info\?//;
133 $query_cgi_history =~ s/;/&/g;
135 C4::Search::History::add({
136 userid => $loggedinuser,
137 sessionid => $query->cookie("CGISESSID"),
138 query_desc => $value,
139 query_cgi => $query_cgi_history,
140 total => $total,
141 type => "authority",
146 $template->param(
147 marclist => $marclist,
148 and_or => $and_or,
149 excluding => $excluding,
150 operator => $operator,
151 orderby => $orderby,
152 value => $value,
153 authtypecode => $authtypecode,
154 startfrom => $startfrom,
155 resultsperpage => $resultsperpage,
158 # we must get parameters once again. Because if there is a mainentry, it
159 # has been replaced by something else during the search, thus the links
160 # next/previous would not work anymore
162 # construction of the url of each page
163 my $value_url = uri_escape_utf8($value);
164 my $base_url = "authorities-home.pl?"
165 ."marclist=$marclist"
166 ."&amp;and_or=$and_or"
167 ."&amp;excluding=$excluding"
168 ."&amp;operator=$operator"
169 ."&amp;value=$value_url"
170 ."&amp;resultsperpage=$resultsperpage"
171 ."&amp;type=intranet"
172 ."&amp;op=do_search"
173 ."&amp;authtypecode=$authtypecode"
174 ."&amp;orderby=$orderby";
176 my $from = ( $startfrom - 1 ) * $resultsperpage + 1;
177 my $to;
178 if ( !defined $total ) {
179 $total = 0;
182 if ( $total < $startfrom * $resultsperpage ) {
183 $to = $total;
185 else {
186 $to = $startfrom * $resultsperpage;
189 $template->param( result => $results ) if $results;
191 $template->param(
192 pagination_bar => pagination_bar(
193 $base_url, int( $total / $resultsperpage ) + 1,
194 $startfrom, 'startfrom'
196 total => $total,
197 from => $from,
198 to => $to,
199 isEDITORS => $authtypecode eq 'EDITORS',
203 if ( $op eq '' ) {
204 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
206 template_name => "authorities/authorities-home.tt",
207 query => $query,
208 type => 'intranet',
209 authnotrequired => 0,
210 flagsrequired => { catalogue => 1 },
211 debug => 1,
217 $template->param(
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;