Missing holiday images
[koha-ffzg.git] / authorities / auth_linker.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
23 use CGI;
24 use C4::Auth;
25 use C4::Context;
26 use C4::Search;
27
28 use C4::Interface::CGI::Output;
29 use C4::AuthoritiesMarc;
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 $category = $query->param('category');
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         
60         my @operator = $query->param('operator');
61         my @value = $query->param('value');
62
63         $resultsperpage= $query->param('resultsperpage');
64         $resultsperpage = 10 if(!defined $resultsperpage);
65
66         my ($results,$total) = authoritysearch($dbh, \@marclist, \@operator, \@value,$startfrom*$resultsperpage, $resultsperpage,$authtypecode) ;
67
68
69         ($template, $loggedinuser, $cookie)
70                 = get_template_and_user({template_name => "authorities/linkresultlist-auth.tmpl",
71                                 query => $query,
72                                 type => 'intranet',
73                                 authnotrequired => 0,
74                                 flagsrequired => {borrowers => 1},
75                                 flagsrequired => {catalogue => 1},
76                                 debug => 1,
77                                 });
78
79         # multi page display gestion
80         my $displaynext=0;
81         my $displayprev=$startfrom;
82         if(($total - (($startfrom+1)*($resultsperpage))) > 0 ) {
83                 $displaynext = 1;
84         }
85
86         my @field_data = ();
87
88
89         my @marclist_ini = $query->param('marclist'); # get marclist again, as the previous one has been modified by authoritysearch (mainentry replaced by field name
90         for(my $i = 0 ; $i <= $#marclist ; $i++) {
91                 push @field_data, { term => "marclist", val=>$marclist_ini[$i] };
92                 push @field_data, { term => "operator", val=>$operator[$i] };
93                 push @field_data, { term => "value", val=>$value[$i] };
94         }
95
96         my @numbers = ();
97
98         if ($total>$resultsperpage) {
99                 for (my $i=1; $i<$total/$resultsperpage+1; $i++) {
100                         if ($i<16) {
101                         my $highlight=0;
102                         ($startfrom==($i-1)) && ($highlight=1);
103                         push @numbers, { number => $i,
104                                         highlight => $highlight ,
105                                         searchdata=> \@field_data,
106                                         startfrom => ($i-1)};
107                         }
108         }
109         }
110
111         my $from = $startfrom*$resultsperpage+1;
112         my $to;
113
114         if($total < (($startfrom+1)*$resultsperpage)) {
115                 $to = $total;
116         } else {
117                 $to = (($startfrom+1)*$resultsperpage);
118         }
119         $template->param(result => $results) if $results;
120         $template->param(index => $query->param('index')."");
121         $template->param(startfrom=> $startfrom,
122                                                         displaynext=> $displaynext,
123                                                         displayprev=> $displayprev,
124                                                         resultsperpage => $resultsperpage,
125                                                         startfromnext => $startfrom+1,
126                                                         startfromprev => $startfrom-1,
127                                                                 index => $index,
128                                                         searchdata=>\@field_data,
129                                                         total=>$total,
130                                                         from=>$from,
131                                                         to=>$to,
132                                                         numbers=>\@numbers,
133                                                         authtypecode =>$authtypecode,
134                                                         resultstring =>$value[0],
135                                                         );
136 } else {
137         ($template, $loggedinuser, $cookie)
138                 = get_template_and_user({template_name => "authorities/auth_linker.tmpl",
139                                 query => $query,
140                                 type => 'intranet',
141                                 authnotrequired => 0,
142                                 flagsrequired => {catalogue => 1},
143                                 debug => 1,
144                                 });
145
146         $template->param(index=>$query->param('index')."",
147                                         resultstring => $resultstring,
148                                 
149                                         );
150 }
151
152 $template->param(authtypesloop => \@authtypesloop,
153                                 authtypecode => $authtypecode,
154                                 nonav=>"1",);
155
156 # Print the page
157 output_html_with_http_headers $query, $cookie, $template->output;
158
159 # Local Variables:
160 # tab-width: 4
161 # End: