Bug 6739: (follow-up) fix more issues
[koha.git] / authorities / authorities-home.pl
blobf67f5c9c40e17f68e36ab6f9353c15ffd9c1ddda
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 under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 use strict;
21 use warnings;
23 use CGI;
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;
35 my $query = new CGI;
36 my $dbh = C4::Context->dbh;
37 my $op = $query->param('op') || '';
38 my $authtypecode = $query->param('authtypecode') || '';
39 my $authid = $query->param('authid') || '';
41 my ( $template, $loggedinuser, $cookie );
43 my $authtypes = getauthtypes;
44 my @authtypesloop;
45 foreach my $thisauthtype (
46 sort {
47 $authtypes->{$a}{'authtypetext'} cmp $authtypes->{$b}{'authtypetext'}
49 keys %$authtypes
52 my %row = (
53 value => $thisauthtype,
54 selected => $thisauthtype eq $authtypecode,
55 authtypetext => $authtypes->{$thisauthtype}{'authtypetext'},
57 push @authtypesloop, \%row;
60 if ( $op eq "delete" ) {
61 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
63 template_name => "authorities/authorities-home.tmpl",
64 query => $query,
65 type => 'intranet',
66 authnotrequired => 0,
67 flagsrequired => { catalogue => 1 },
68 debug => 1,
71 &DelAuthority( $authid, 1 );
73 if ( $query->param('operator') ) {
74 # query contains search params so perform search
75 $op = "do_search";
77 else {
78 $op = '';
81 if ( $op eq "do_search" ) {
82 my $marclist = $query->param('marclist') || '';
83 my $and_or = $query->param('and_or') || '';
84 my $excluding = $query->param('excluding') || '';
85 my $operator = $query->param('operator') || '';
86 my $orderby = $query->param('orderby') || '';
87 my $value = $query->param('value') || '';
89 my $startfrom = $query->param('startfrom') || 1;
90 my $resultsperpage = $query->param('resultsperpage') || 20;
92 my ( $results, $total ) = SearchAuthorities(
93 [$marclist], [$and_or],
94 [$excluding], [$operator],
95 [$value], ( $startfrom - 1 ) * $resultsperpage,
96 $resultsperpage, $authtypecode,
97 $orderby
100 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
102 template_name => "authorities/searchresultlist.tmpl",
103 query => $query,
104 type => 'intranet',
105 authnotrequired => 0,
106 flagsrequired => { catalogue => 1 },
107 debug => 1,
111 $template->param(
112 marclist => $marclist,
113 and_or => $and_or,
114 excluding => $excluding,
115 operator => $operator,
116 orderby => $orderby,
117 value => $value,
118 authtypecode => $authtypecode,
119 startfrom => $startfrom,
120 resultsperpage => $resultsperpage,
123 # we must get parameters once again. Because if there is a mainentry, it
124 # has been replaced by something else during the search, thus the links
125 # next/previous would not work anymore
127 # construction of the url of each page
128 my $value_url = uri_escape($value);
129 my $base_url = "authorities-home.pl?"
130 ."marclist=$marclist"
131 ."&and_or=$and_or"
132 ."&excluding=$excluding"
133 ."&operator=$operator"
134 ."&value=$value_url"
135 ."&resultsperpage=$resultsperpage"
136 ."&type=intranet"
137 ."&op=do_search"
138 ."&authtypecode=$authtypecode"
139 ."&orderby=$orderby";
141 my $from = ( $startfrom - 1 ) * $resultsperpage + 1;
142 my $to;
143 if ( !defined $total ) {
144 $total = 0;
147 if ( $total < $startfrom * $resultsperpage ) {
148 $to = $total;
150 else {
151 $to = $startfrom * $resultsperpage;
154 $template->param( result => $results ) if $results;
156 $template->param(
157 pagination_bar => pagination_bar(
158 $base_url, int( $total / $resultsperpage ) + 1,
159 $startfrom, 'startfrom'
161 total => $total,
162 from => $from,
163 to => $to,
164 isEDITORS => $authtypecode eq 'EDITORS',
168 if ( $op eq '' ) {
169 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
171 template_name => "authorities/authorities-home.tmpl",
172 query => $query,
173 type => 'intranet',
174 authnotrequired => 0,
175 flagsrequired => { catalogue => 1 },
176 debug => 1,
182 $template->param(
183 authtypesloop => \@authtypesloop,
184 op => $op,
187 $template->{VARS}->{marcflavour} = C4::Context->preference("marcflavour");
189 # Print the page
190 output_html_with_http_headers $query, $cookie, $template->output;