First step for working authorities
[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::Catalogue;
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 $dbh = C4::Context->dbh;
41
42 my $startfrom=$query->param('startfrom');
43 $startfrom=0 if(!defined $startfrom);
44 my ($template, $loggedinuser, $cookie);
45 my $resultsperpage;
46
47 my $authtypes = getauthtypes;
48 my @authtypesloop;
49 foreach my $thisauthtype (keys %$authtypes) {
50         my $selected = 1 if $thisauthtype eq $authtypecode;
51         my %row =(value => $thisauthtype,
52                                 selected => $selected,
53                                 authtypetext => $authtypes->{$thisauthtype}{'authtypetext'},
54                           index => $index,
55                         );
56         push @authtypesloop, \%row;
57 }
58
59 if ($op eq "do_search") {
60         my @marclist = $query->param('marclist');
61         my @and_or = $query->param('and_or');
62         my @excluding = $query->param('excluding');
63         my @operator = $query->param('operator');
64         my @value = $query->param('value');
65
66         $resultsperpage= $query->param('resultsperpage');
67         $resultsperpage = 19 if(!defined $resultsperpage);
68 #       my $orderby = $query->param('orderby');
69
70         # builds tag and subfield arrays
71         my @tags;
72
73         my ($results,$total) = authoritysearch($dbh, \@tags,\@and_or,
74                                                                                 \@excluding, \@operator, \@value,
75                                                                                 $startfrom*$resultsperpage, $resultsperpage,$authtypecode);# $orderby);
76
77         ($template, $loggedinuser, $cookie)
78                 = get_template_and_user({template_name => "authorities/searchresultlist-auth.tmpl",
79                                 query => $query,
80                                 type => 'intranet',
81                                 authnotrequired => 0,
82                                 flagsrequired => {borrowers => 1},
83                                 flagsrequired => {catalogue => 1},
84                                 debug => 1,
85                                 });
86         # multi page display gestion
87         my $displaynext=0;
88         my $displayprev=$startfrom;
89         if(($total - (($startfrom+1)*($resultsperpage))) > 0 ){
90                 $displaynext = 1;
91         }
92
93         my @field_data = ();
94
95
96         for(my $i = 0 ; $i <= $#marclist ; $i++)
97         {
98                 push @field_data, { term => "marclist", val=>$marclist[$i] };
99                 push @field_data, { term => "and_or", val=>$and_or[$i] };
100                 push @field_data, { term => "excluding", val=>$excluding[$i] };
101                 push @field_data, { term => "operator", val=>$operator[$i] };
102                 push @field_data, { term => "value", val=>$value[$i] };
103         }
104
105         my @numbers = ();
106
107         if ($total>$resultsperpage)
108         {
109                 for (my $i=1; $i<$total/$resultsperpage+1; $i++)
110                 {
111                         if ($i<16)
112                         {
113                         my $highlight=0;
114                         ($startfrom==($i-1)) && ($highlight=1);
115                         push @numbers, { number => $i,
116                                         highlight => $highlight ,
117                                         searchdata=> \@field_data,
118                                         startfrom => ($i-1)};
119                         }
120         }
121         }
122
123         my $from = $startfrom*$resultsperpage+1;
124         my $to;
125
126         if($total < (($startfrom+1)*$resultsperpage))
127         {
128                 $to = $total;
129         } else {
130                 $to = (($startfrom+1)*$resultsperpage);
131         }
132         $template->param(result => $results) if $results;
133         $template->param(index => $query->param('index'));
134         warn "ici query $index  $query->param('resultsperpage')" ;
135         $template->param(startfrom=> $startfrom,
136                                                         displaynext=> $displaynext,
137                                                         displayprev=> $displayprev,
138                                                         resultsperpage => $resultsperpage,
139                                                         startfromnext => $startfrom+1,
140                                                         startfromprev => $startfrom-1,
141                                                 index => $index,
142                                                         searchdata=>\@field_data,
143                                                         total=>$total,
144                                                         from=>$from,
145                                                         to=>$to,
146                                                         numbers=>\@numbers,
147                                                         );
148 } else {
149         warn "Je suis la de base $index\n";
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
164 # Print the page
165 output_html_with_http_headers $query, $cookie, $template->output;
166
167 # Local Variables:
168 # tab-width: 4
169 # End: