using acquisition.pm instead of catalogue.pm
[koha.git] / authorities / auth_finder.pl
1 #!/usr/bin/perl
2 # WARNING: 4-character tab stops here
3
4 # Copyright 2000-2002 Katipo Communications
5 #
6 # This file is part of Koha.
7 #
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.
12 #
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.
16 #
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
20
21 use strict;
22 require Exporter;
23 use CGI;
24 use C4::Auth;
25 use HTML::Template;
26 use C4::Context;
27 use C4::Search;
28 use C4::Auth;
29 use C4::Output;
30 use C4::Interface::CGI::Output;
31 use C4::AuthoritiesMarc;
32 use C4::SearchMarc;
33 use C4::Acquisition;
34 use C4::Koha; # XXX subfield_is_koha_internal_p
35
36 my $query=new CGI;
37 my $op = $query->param('op');
38 my $authtypecode = $query->param('authtypecode');
39 my $index = $query->param('index');
40 my $category = $query->param('category');
41 my $dbh = C4::Context->dbh;
42
43 my $startfrom=$query->param('startfrom');
44 $startfrom=0 if(!defined $startfrom);
45 my ($template, $loggedinuser, $cookie);
46 my $resultsperpage;
47
48 my $authtypes = getauthtypes;
49 my @authtypesloop;
50 foreach my $thisauthtype (keys %$authtypes) {
51         my $selected = 1 if $thisauthtype eq $authtypecode;
52         my %row =(value => $thisauthtype,
53                                 selected => $selected,
54                                 authtypetext => $authtypes->{$thisauthtype}{'authtypetext'},
55                           index => $index,
56                         );
57         push @authtypesloop, \%row;
58 }
59
60 if ($op eq "do_search") {
61         my @marclist = $query->param('marclist');
62         my @and_or = $query->param('and_or');
63         my @excluding = $query->param('excluding');
64         my @operator = $query->param('operator');
65         my @value = $query->param('value');
66
67         $resultsperpage= $query->param('resultsperpage');
68         $resultsperpage = 19 if(!defined $resultsperpage);
69 #       my $orderby = $query->param('orderby');
70
71         # builds tag and subfield arrays
72         my @tags;
73
74         my ($results,$total) = authoritysearch($dbh, \@tags,\@and_or,
75                                                                                 \@excluding, \@operator, \@value,
76                                                                                 $startfrom*$resultsperpage, $resultsperpage,$authtypecode);# $orderby);
77
78         ($template, $loggedinuser, $cookie)
79                 = get_template_and_user({template_name => "authorities/searchresultlist-auth.tmpl",
80                                 query => $query,
81                                 type => 'intranet',
82                                 authnotrequired => 0,
83                                 flagsrequired => {borrowers => 1},
84                                 flagsrequired => {catalogue => 1},
85                                 debug => 1,
86                                 });
87
88         # multi page display gestion
89         my $displaynext=0;
90         my $displayprev=$startfrom;
91         if(($total - (($startfrom+1)*($resultsperpage))) > 0 ){
92                 $displaynext = 1;
93         }
94
95         my @field_data = ();
96
97
98         for(my $i = 0 ; $i <= $#marclist ; $i++)
99         {
100                 push @field_data, { term => "marclist", val=>$marclist[$i] };
101                 push @field_data, { term => "and_or", val=>$and_or[$i] };
102                 push @field_data, { term => "excluding", val=>$excluding[$i] };
103                 push @field_data, { term => "operator", val=>$operator[$i] };
104                 push @field_data, { term => "value", val=>$value[$i] };
105         }
106
107         my @numbers = ();
108
109         if ($total>$resultsperpage)
110         {
111                 for (my $i=1; $i<$total/$resultsperpage+1; $i++)
112                 {
113                         if ($i<16)
114                         {
115                         my $highlight=0;
116                         ($startfrom==($i-1)) && ($highlight=1);
117                         push @numbers, { number => $i,
118                                         highlight => $highlight ,
119                                         searchdata=> \@field_data,
120                                         startfrom => ($i-1)};
121                         }
122         }
123         }
124
125         my $from = $startfrom*$resultsperpage+1;
126         my $to;
127
128         if($total < (($startfrom+1)*$resultsperpage))
129         {
130                 $to = $total;
131         } else {
132                 $to = (($startfrom+1)*$resultsperpage);
133         }
134         $template->param(result => $results) if $results;
135         $template->param(index => $query->param('index'));
136         $template->param(startfrom=> $startfrom,
137                                                         displaynext=> $displaynext,
138                                                         displayprev=> $displayprev,
139                                                         resultsperpage => $resultsperpage,
140                                                         startfromnext => $startfrom+1,
141                                                         startfromprev => $startfrom-1,
142                                                 index => $index,
143                                                         searchdata=>\@field_data,
144                                                         total=>$total,
145                                                         from=>$from,
146                                                         to=>$to,
147                                                         numbers=>\@numbers,
148                                                         );
149 } else {
150         ($template, $loggedinuser, $cookie)
151                 = get_template_and_user({template_name => "authorities/auth_finder.tmpl",
152                                 query => $query,
153                                 type => 'intranet',
154                                 authnotrequired => 0,
155                                 flagsrequired => {catalogue => 1},
156                                 debug => 1,
157                                 });
158
159         $template->param(index => $index);
160 }
161
162 $template->param(authtypesloop => \@authtypesloop);
163 $template->param(category => $category);
164
165 # Print the page
166 output_html_with_http_headers $query, $cookie, $template->output;
167
168 # Local Variables:
169 # tab-width: 4
170 # End: