Ticket 1110 : Balance carts and lists
[koha.git] / authorities / auth_finder.pl
blob7070b12d383e7acedbd1498ce9c06e00b4d26d4c
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 under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA 02111-1307 USA
21 use strict;
23 use CGI;
24 use C4::Output;
25 use C4::Auth;
26 use C4::Context;
27 use C4::AuthoritiesMarc;
28 use C4::Acquisition;
29 use C4::Koha; # XXX subfield_is_koha_internal_p
31 my $query = new CGI;
32 my $op = $query->param('op');
33 my $authtypecode = $query->param('authtypecode');
34 my $index = $query->param('index');
35 my $tagid = $query->param('tagid');
36 my $resultstring = $query->param('result');
37 my $dbh = C4::Context->dbh;
39 my $startfrom = $query->param('startfrom');
40 $startfrom = 0 if ( !defined $startfrom );
41 my ( $template, $loggedinuser, $cookie );
42 my $resultsperpage;
44 my $authtypes = getauthtypes;
45 my @authtypesloop;
46 foreach my $thisauthtype ( keys %$authtypes ) {
47 my $selected = 1 if $thisauthtype eq $authtypecode;
48 my %row = (
49 value => $thisauthtype,
50 selected => $selected,
51 authtypetext => $authtypes->{$thisauthtype}{'authtypetext'},
52 index => $index,
54 push @authtypesloop, \%row;
57 if ( $op eq "do_search" ) {
58 my @marclist = $query->param('marclist');
59 my @and_or = $query->param('and_or');
60 my @excluding = $query->param('excluding');
61 my @operator = $query->param('operator');
62 my @value = ($query->param('value_mainstr'), $query->param('value_main'), $query->param('value_any'));
63 my $orderby = $query->param('orderby');
65 $resultsperpage = $query->param('resultsperpage');
66 $resultsperpage = 20 if ( !defined $resultsperpage );
68 my ( $results, $total ) =
69 SearchAuthorities( \@marclist, \@and_or, \@excluding, \@operator, \@value,
70 $startfrom * $resultsperpage,
71 $resultsperpage, $authtypecode, $orderby);
72 # multi page display gestion
73 my $displaynext = 0;
74 my $displayprev = $startfrom;
75 if ( ( $total - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) {
76 $displaynext = 1;
79 my @field_data = ();
81 my @marclist_ini =
82 $query->param('marclist')
83 ; # get marclist again, as the previous one has been modified by catalogsearch (mainentry replaced by field name
84 for ( my $i = 0 ; $i <= $#marclist ; $i++ ) {
85 push @field_data, { term => "marclist", val => $marclist_ini[$i] };
86 push @field_data, { term => "and_or", val => $and_or[$i] };
87 push @field_data, { term => "excluding", val => $excluding[$i] };
88 push @field_data, { term => "operator", val => $operator[$i] };
91 push @field_data, { term => "value_mainstr", val => $query->param('value_mainstr') || "" };
92 push @field_data, { term => "value_main", val => $query->param('value_main') || "" };
93 push @field_data, { term => "value_any", val => $query->param('value_any') || ""};
95 my @numbers = ();
97 if ( $total > $resultsperpage ) {
98 for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
99 if ( $i < 16 ) {
100 my $highlight = 0;
101 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
102 push @numbers,
104 number => $i,
105 highlight => $highlight,
106 searchdata => \@field_data,
107 startfrom => ( $i - 1 )
113 my $from = $startfrom * $resultsperpage + 1;
114 my $to;
116 if ( $total < ( ( $startfrom + 1 ) * $resultsperpage ) ) {
117 $to = $total;
119 else {
120 $to = ( ( $startfrom + 1 ) * $resultsperpage );
122 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
124 template_name => "authorities/searchresultlist-auth.tmpl",
125 query => $query,
126 type => 'intranet',
127 authnotrequired => 0,
128 flagsrequired => { catalogue => 1 },
132 $template->param( result => $results ) if $results;
133 $template->param(
134 orderby => $orderby,
135 startfrom => $startfrom,
136 displaynext => $displaynext,
137 displayprev => $displayprev,
138 resultsperpage => $resultsperpage,
139 startfromnext => $startfrom + 1,
140 startfromprev => $startfrom - 1,
141 searchdata => \@field_data,
142 total => $total,
143 from => $from,
144 to => $to,
145 numbers => \@numbers,
146 authtypecode => $authtypecode,
147 value_mainstr => $query->param('value_mainstr') || "",
148 value_main => $query->param('value_main') || "",
149 value_any => $query->param('value_any') || "",
151 } else {
152 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
154 template_name => "authorities/auth_finder.tmpl",
155 query => $query,
156 type => 'intranet',
157 authnotrequired => 0,
158 flagsrequired => { catalogue => 1 },
162 $template->param(
163 resultstring => $resultstring,
167 $template->param(
168 tagid => $tagid,
169 index => $index,
170 authtypesloop => \@authtypesloop,
171 authtypecode => $authtypecode,
172 value_mainstr => $query->param('value_mainstr') || "",
173 value_main => $query->param('value_main') || "",
174 value_any => $query->param('value_any') || "",
177 # Print the page
178 output_html_with_http_headers $query, $cookie, $template->output;
180 # Local Variables:
181 # tab-width: 4
182 # End: