Bug 14582 - OPAC detail shows an unuseful link to "add tag" when user is not logged in
[koha.git] / opac / opac-authorities-home.pl
blobf4ab2ab2225e8cb3224ff3824e574f50850b83c1
1 #!/usr/bin/perl
2 # WARNING: 4-character tab stops here
4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21 use strict;
22 use warnings;
24 use CGI qw ( -utf8 );
25 use C4::Auth;
27 use C4::Context;
28 use C4::Auth;
29 use C4::Output;
30 use C4::AuthoritiesMarc;
31 use C4::Koha;
32 use C4::Search::History;
34 use Koha::Authority::Types;
36 my $query = new CGI;
37 my $op = $query->param('op') || '';
38 my $authtypecode = $query->param('authtypecode') || '';
39 my $dbh = C4::Context->dbh;
41 my $startfrom = $query->param('startfrom');
42 my $authid = $query->param('authid');
43 $startfrom = 0 if ( !defined $startfrom );
44 my ( $template, $loggedinuser, $cookie );
45 my $resultsperpage;
47 my $authority_types = Koha::Authority::Types->search({}, { order_by => ['authtypetext']});
49 if ( $op eq "do_search" ) {
50 my @marclist = ($query->param('marclist'));
51 my @and_or = ($query->param('and_or'));
52 my @excluding = ($query->param('excluding'),);
53 my @operator = ($query->param('operator'));
54 my $orderby = $query->param('orderby');
55 my @value = ($query->param('value') || "",);
57 $resultsperpage = $query->param('resultsperpage');
58 $resultsperpage = 20 if ( !defined $resultsperpage );
59 my @tags;
60 my ( $results, $total, @fields ) =
61 SearchAuthorities( \@marclist, \@and_or, \@excluding, \@operator,
62 \@value, $startfrom * $resultsperpage,
63 $resultsperpage, $authtypecode, $orderby );
64 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
66 template_name => "opac-authoritiessearchresultlist.tt",
67 query => $query,
68 type => 'opac',
69 authnotrequired => 1,
70 debug => 1,
74 # multi page display gestion
75 my $displaynext = 0;
76 my $displayprev = $startfrom;
77 $total ||= 0;
78 if ( ( $total - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) {
79 $displaynext = 1;
82 my @field_data = (
83 { term => "marclist", val => $marclist[0] },
84 { term => "and_or", val => $and_or[0] },
85 { term => "excluding", val => $excluding[0] },
86 { term => "operator", val => $operator[0] },
87 { term => "value", val => $value[0] },
90 my @numbers = ();
92 if ( $total > $resultsperpage ) {
93 for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
94 if ( $i < 16 ) {
95 my $highlight = 0;
96 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
97 push @numbers,
99 number => $i,
100 highlight => $highlight,
101 searchdata => \@field_data,
102 startfrom => ( $i - 1 )
108 my $from = $startfrom * $resultsperpage + 1;
109 my $to;
111 if ( $total < ( ( $startfrom + 1 ) * $resultsperpage ) ) {
112 $to = $total;
114 else {
115 $to = ( ( $startfrom + 1 ) * $resultsperpage );
117 unless (C4::Context->preference('OPACShowUnusedAuthorities')) {
118 my @usedauths = grep { $_->{used} > 0 } @$results;
119 $results = \@usedauths;
122 # Opac search history
123 if (C4::Context->preference('EnableOpacSearchHistory')) {
124 unless ( $startfrom ) {
125 my $path_info = $query->url(-path_info=>1);
126 my $query_cgi_history = $query->url(-query=>1);
127 $query_cgi_history =~ s/^$path_info\?//;
128 $query_cgi_history =~ s/;/&/g;
130 unless ( $loggedinuser ) {
131 my $new_search = C4::Search::History::add_to_session({
132 cgi => $query,
133 query_desc => $value[0],
134 query_cgi => $query_cgi_history,
135 total => $total,
136 type => "authority",
138 } else {
139 # To the session (the user is logged in)
140 C4::Search::History::add({
141 userid => $loggedinuser,
142 sessionid => $query->cookie("CGISESSID"),
143 query_desc => $value[0],
144 query_cgi => $query_cgi_history,
145 total => $total,
146 type => "authority",
152 $template->param( result => $results ) if $results;
153 $template->param( FIELDS => \@fields );
154 $template->param( orderby => $orderby );
155 $template->param(
156 startfrom => $startfrom,
157 displaynext => $displaynext,
158 displayprev => $displayprev,
159 resultsperpage => $resultsperpage,
160 startfromnext => $startfrom + 1,
161 startfromprev => $startfrom - 1,
162 searchdata => \@field_data,
163 countfuzzy => !(C4::Context->preference('OPACShowUnusedAuthorities')),
164 total => $total,
165 from => $from,
166 to => $to,
167 resultcount => scalar @$results,
168 numbers => \@numbers,
169 authtypecode => $authtypecode,
170 authtypetext => $authority_types->find($authtypecode)->authtypetext,
171 isEDITORS => $authtypecode eq 'EDITORS',
175 else {
176 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
178 template_name => "opac-authorities-home.tt",
179 query => $query,
180 type => 'opac',
181 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
182 debug => 1,
188 $template->param(
189 authority_types => $authority_types,
190 authtypecode => $authtypecode,
193 # Print the page
194 output_html_with_http_headers $query, $cookie, $template->output;
196 # Local Variables:
197 # tab-width: 4
198 # End: