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
;
32 use C4
::Koha
; # XXX subfield_is_koha_internal_p
34 use C4
::Search
::History
;
36 use Koha
::Authority
::Types
;
39 my $dbh = C4
::Context
->dbh;
40 my $op = $query->param('op') || '';
41 my $authtypecode = $query->param('authtypecode') || '';
42 my $authid = $query->param('authid') || '';
44 my ( $template, $loggedinuser, $cookie );
46 my $authority_types = Koha
::Authority
::Types
->search( {}, { order_by
=> ['authtypetext'] } );
48 if ( $op eq "delete" ) {
49 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
51 template_name
=> "authorities/authorities-home.tt",
55 flagsrequired
=> { catalogue
=> 1 },
59 &DelAuthority
( $authid, 1 );
61 if ( $query->param('operator') ) {
62 # query contains search params so perform search
69 if ( $op eq "do_search" ) {
70 my $marclist = $query->param('marclist') || '';
71 my $and_or = $query->param('and_or') || '';
72 my $excluding = $query->param('excluding') || '';
73 my $operator = $query->param('operator') || '';
74 my $orderby = $query->param('orderby') || '';
75 my $value = $query->param('value') || '';
77 my $startfrom = $query->param('startfrom') || 1;
78 my $resultsperpage = $query->param('resultsperpage') || 20;
80 my ( $results, $total ) = SearchAuthorities
(
81 [$marclist], [$and_or],
82 [$excluding], [$operator],
83 [$value], ( $startfrom - 1 ) * $resultsperpage,
84 $resultsperpage, $authtypecode,
89 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
91 template_name
=> "authorities/searchresultlist.tt",
95 flagsrequired
=> { catalogue
=> 1 },
101 if (C4
::Context
->preference('EnableSearchHistory')) {
102 if ( $startfrom == 1) {
103 my $path_info = $query->url(-path_info
=>1);
104 my $query_cgi_history = $query->url(-query
=>1);
105 $query_cgi_history =~ s/^$path_info\?//;
106 $query_cgi_history =~ s/;/&/g;
108 C4
::Search
::History
::add
({
109 userid
=> $loggedinuser,
110 sessionid
=> $query->cookie("CGISESSID"),
111 query_desc
=> $value,
112 query_cgi
=> $query_cgi_history,
120 marclist
=> $marclist,
122 excluding
=> $excluding,
123 operator
=> $operator,
126 authtypecode
=> $authtypecode,
127 startfrom
=> $startfrom,
128 resultsperpage
=> $resultsperpage,
131 # we must get parameters once again. Because if there is a mainentry, it
132 # has been replaced by something else during the search, thus the links
133 # next/previous would not work anymore
135 # construction of the url of each page
136 my $value_url = uri_escape_utf8
($value);
137 my $base_url = "authorities-home.pl?"
138 ."marclist=$marclist"
139 ."&and_or=$and_or"
140 ."&excluding=$excluding"
141 ."&operator=$operator"
142 ."&value=$value_url"
143 ."&resultsperpage=$resultsperpage"
144 ."&type=intranet"
146 ."&authtypecode=$authtypecode"
147 ."&orderby=$orderby";
149 my $from = ( $startfrom - 1 ) * $resultsperpage + 1;
151 if ( !defined $total ) {
155 if ( $total < $startfrom * $resultsperpage ) {
159 $to = $startfrom * $resultsperpage;
162 $template->param( result
=> $results ) if $results;
165 pagination_bar
=> pagination_bar
(
166 $base_url, int( $total / $resultsperpage ) + 1,
167 $startfrom, 'startfrom'
172 isEDITORS
=> $authtypecode eq 'EDITORS',
177 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
179 template_name
=> "authorities/authorities-home.tt",
182 authnotrequired
=> 0,
183 flagsrequired
=> { catalogue
=> 1 },
191 authority_types
=> $authority_types,
195 $template->{VARS
}->{marcflavour
} = C4
::Context
->preference("marcflavour");
198 output_html_with_http_headers
$query, $cookie, $template->output;