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