Bug 16029: Hide patron toolbar if patron does not exist
[koha.git] / authorities / authorities-home.pl
blob6e13db6229675c9022035821d024f2d2d182fbdb
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; # XXX subfield_is_koha_internal_p
33 use C4::Biblio;
34 use C4::Search::History;
36 my $query = new CGI;
37 my $dbh = C4::Context->dbh;
38 my $op = $query->param('op') || '';
39 my $authtypecode = $query->param('authtypecode') || '';
40 my $authid = $query->param('authid') || '';
42 my ( $template, $loggedinuser, $cookie );
44 my $authtypes = getauthtypes;
45 my @authtypesloop;
46 foreach my $thisauthtype (
47 sort {
48 $authtypes->{$a}{'authtypetext'} cmp $authtypes->{$b}{'authtypetext'}
50 keys %$authtypes
53 my %row = (
54 value => $thisauthtype,
55 selected => $thisauthtype eq $authtypecode,
56 authtypetext => $authtypes->{$thisauthtype}{'authtypetext'},
58 push @authtypesloop, \%row;
61 if ( $op eq "delete" ) {
62 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
64 template_name => "authorities/authorities-home.tt",
65 query => $query,
66 type => 'intranet',
67 authnotrequired => 0,
68 flagsrequired => { catalogue => 1 },
69 debug => 1,
72 &DelAuthority( $authid, 1 );
74 if ( $query->param('operator') ) {
75 # query contains search params so perform search
76 $op = "do_search";
78 else {
79 $op = '';
82 if ( $op eq "do_search" ) {
83 my $marclist = $query->param('marclist') || '';
84 my $and_or = $query->param('and_or') || '';
85 my $excluding = $query->param('excluding') || '';
86 my $operator = $query->param('operator') || '';
87 my $orderby = $query->param('orderby') || '';
88 my $value = $query->param('value') || '';
90 my $startfrom = $query->param('startfrom') || 1;
91 my $resultsperpage = $query->param('resultsperpage') || 20;
93 my ( $results, $total ) = SearchAuthorities(
94 [$marclist], [$and_or],
95 [$excluding], [$operator],
96 [$value], ( $startfrom - 1 ) * $resultsperpage,
97 $resultsperpage, $authtypecode,
98 $orderby
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 # search history
114 if (C4::Context->preference('EnableSearchHistory')) {
115 if ( $startfrom == 1) {
116 my $path_info = $query->url(-path_info=>1);
117 my $query_cgi_history = $query->url(-query=>1);
118 $query_cgi_history =~ s/^$path_info\?//;
119 $query_cgi_history =~ s/;/&/g;
121 C4::Search::History::add({
122 userid => $loggedinuser,
123 sessionid => $query->cookie("CGISESSID"),
124 query_desc => $value,
125 query_cgi => $query_cgi_history,
126 total => $total,
127 type => "authority",
132 $template->param(
133 marclist => $marclist,
134 and_or => $and_or,
135 excluding => $excluding,
136 operator => $operator,
137 orderby => $orderby,
138 value => $value,
139 authtypecode => $authtypecode,
140 startfrom => $startfrom,
141 resultsperpage => $resultsperpage,
144 # we must get parameters once again. Because if there is a mainentry, it
145 # has been replaced by something else during the search, thus the links
146 # next/previous would not work anymore
148 # construction of the url of each page
149 my $value_url = uri_escape_utf8($value);
150 my $base_url = "authorities-home.pl?"
151 ."marclist=$marclist"
152 ."&amp;and_or=$and_or"
153 ."&amp;excluding=$excluding"
154 ."&amp;operator=$operator"
155 ."&amp;value=$value_url"
156 ."&amp;resultsperpage=$resultsperpage"
157 ."&amp;type=intranet"
158 ."&amp;op=do_search"
159 ."&amp;authtypecode=$authtypecode"
160 ."&amp;orderby=$orderby";
162 my $from = ( $startfrom - 1 ) * $resultsperpage + 1;
163 my $to;
164 if ( !defined $total ) {
165 $total = 0;
168 if ( $total < $startfrom * $resultsperpage ) {
169 $to = $total;
171 else {
172 $to = $startfrom * $resultsperpage;
175 $template->param( result => $results ) if $results;
177 $template->param(
178 pagination_bar => pagination_bar(
179 $base_url, int( $total / $resultsperpage ) + 1,
180 $startfrom, 'startfrom'
182 total => $total,
183 from => $from,
184 to => $to,
185 isEDITORS => $authtypecode eq 'EDITORS',
189 if ( $op eq '' ) {
190 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
192 template_name => "authorities/authorities-home.tt",
193 query => $query,
194 type => 'intranet',
195 authnotrequired => 0,
196 flagsrequired => { catalogue => 1 },
197 debug => 1,
203 $template->param(
204 authtypesloop => \@authtypesloop,
205 op => $op,
208 $template->{VARS}->{marcflavour} = C4::Context->preference("marcflavour");
210 # Print the page
211 output_html_with_http_headers $query, $cookie, $template->output;