serials-home.tmpl
[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::Output;
25 use C4::Auth;
26
27 use C4::Context;
28 use C4::AuthoritiesMarc;
29 use C4::Acquisition;
30 use C4::Koha; # XXX subfield_is_koha_internal_p
31
32 my $query=new CGI;
33 my $op = $query->param('op');
34 my $authtypecode = $query->param('authtypecode');
35 my $index = $query->param('index');
36 my $tagid=$query->param('tagid');
37 my $resultstring = $query->param('result');
38 my $dbh = C4::Context->dbh;
39
40 my $startfrom=$query->param('startfrom');
41 $startfrom=0 if(!defined $startfrom);
42 my ($template, $loggedinuser, $cookie);
43 my $resultsperpage;
44
45 my $authtypes = getauthtypes;
46 my @authtypesloop;
47 foreach my $thisauthtype (keys %$authtypes) {
48     my $selected = 1 if $thisauthtype eq $authtypecode;
49     my %row =(value => $thisauthtype,
50                 selected => $selected,
51                 authtypetext => $authtypes->{$thisauthtype}{'authtypetext'},
52               index => $index,
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
67     my ($results,$total) = SearchAuthorities(\@marclist,\@and_or,
68                                         \@excluding, \@operator, \@value,
69                                         $startfrom*$resultsperpage, $resultsperpage,$authtypecode);# $orderby);
70
71         # multi page display gestion
72         my $displaynext=0;
73         my $displayprev=$startfrom;
74         if(($total - (($startfrom+1)*($resultsperpage))) > 0 ) {
75                 $displaynext = 1;
76         }
77
78         my @field_data = ();
79
80
81         my @marclist_ini = $query->param('marclist'); # get marclist again, as the previous one has been modified by catalogsearch (mainentry replaced by field name
82         for(my $i = 0 ; $i <= $#marclist ; $i++) {
83                 push @field_data, { term => "marclist", val=>$marclist_ini[$i] };
84                 push @field_data, { term => "and_or", val=>$and_or[$i] };
85                 push @field_data, { term => "excluding", val=>$excluding[$i] };
86                 push @field_data, { term => "operator", val=>$operator[$i] };
87                 push @field_data, { term => "value", val=>$value[$i] };
88         }
89
90         my @numbers = ();
91
92         if ($total>$resultsperpage) {
93                 for (my $i=1; $i<$total/$resultsperpage+1; $i++) {
94                         if ($i<16) {
95                         my $highlight=0;
96                         ($startfrom==($i-1)) && ($highlight=1);
97                         push @numbers, { number => $i,
98                                         highlight => $highlight ,
99                                         searchdata=> \@field_data,
100                                         startfrom => ($i-1)};
101                         }
102         }
103         }
104
105         my $from = $startfrom*$resultsperpage+1;
106         my $to;
107
108         if($total < (($startfrom+1)*$resultsperpage)) {
109                 $to = $total;
110         } else {
111                 $to = (($startfrom+1)*$resultsperpage);
112         }
113    ($template, $loggedinuser, $cookie)
114         = get_template_and_user({template_name => "authorities/searchresultlist-auth.tmpl",
115                 query => $query,
116                 type => 'intranet',
117                 authnotrequired => 0,
118                 flagsrequired => {catalogue => 1},
119                 debug => 1,
120                 });
121
122     $template->param(result => $results) if $results;
123     $template->param(index => $query->param('index')."");
124     $template->param(startfrom=> $startfrom,
125                             displaynext=> $displaynext,
126                             displayprev=> $displayprev,
127                             resultsperpage => $resultsperpage,
128                             startfromnext => $startfrom+1,
129                             startfromprev => $startfrom-1,
130                             index => $index,
131                             tagid => $tagid,
132                             searchdata=>\@field_data,
133                             total=>$total,
134                             from=>$from,
135                             to=>$to,
136                             numbers=>\@numbers,
137                             authtypecode =>$authtypecode,
138                             mainmainstring =>$value[0],
139                             mainstring =>$value[1],
140                             anystring =>$value[2],
141                             );
142 } else {
143     ($template, $loggedinuser, $cookie)
144         = get_template_and_user({template_name => "authorities/auth_finder.tmpl",
145                 query => $query,
146                 type => 'intranet',
147                 authnotrequired => 0,
148                 flagsrequired => {catalogue => 1},
149                 debug => 1,
150                 });
151
152     $template->param(index=>$query->param('index')."",
153                     tagid => $tagid,
154                     resultstring => $resultstring,
155                     );
156 }
157
158 $template->param(authtypesloop => \@authtypesloop,
159         authtypecode => $authtypecode,
160         intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
161         intranetstylesheet => C4::Context->preference("intranetstylesheet"),
162         IntranetNav => C4::Context->preference("IntranetNav"),
163         );
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: