Deleting link pages.
[koha.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 require Exporter;
23 use CGI;
24 use C4::Auth;
25
26 use C4::Context;
27 use C4::Auth;
28 use C4::Output;
29 use C4::Interface::CGI::Output;
30 use C4::AuthoritiesMarc;
31 #use C4::Biblio;
32 use C4::Acquisition;
33 use C4::Koha; # XXX subfield_is_koha_internal_p
34
35 my $query=new CGI;
36 my $op = $query->param('op');
37 my $authtypecode = $query->param('authtypecode');
38 my $index = $query->param('index');
39 # my $category = $query->param('category');
40 my $resultstring = $query->param('result');
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
70     my ($results,$total) = authoritysearch($dbh, \@marclist,\@and_or,
71                                         \@excluding, \@operator, \@value,
72                                         $startfrom*$resultsperpage, $resultsperpage,$authtypecode);# $orderby);
73
74     ($template, $loggedinuser, $cookie)
75         = get_template_and_user({template_name => "authorities/linkresultlist-auth.tmpl",
76                 query => $query,
77                 type => 'intranet',
78                 authnotrequired => 0,
79                 flagsrequired => {catalogue => 1},
80                 debug => 1,
81                 });
82
83     # multi page display gestion
84     my $displaynext=0;
85     my $displayprev=$startfrom;
86     if(($total - (($startfrom+1)*($resultsperpage))) > 0 ) {
87         $displaynext = 1;
88     }
89
90     my @field_data = ();
91
92     # get marclist again, as the previous one has been modified by catalogsearch
93     my @marclist_ini = $query->param('marclist');
94     for(my $i = 0 ; $i <= $#marclist ; $i++) {
95         push @field_data, { term => "marclist", val=>$marclist_ini[$i] };
96         push @field_data, { term => "and_or", val=>$and_or[$i] };
97         push @field_data, { term => "excluding", val=>$excluding[$i] };
98         push @field_data, { term => "operator", val=>$operator[$i] };
99         push @field_data, { term => "value", val=>$value[$i] };
100     }
101
102     my @numbers = ();
103
104     if ($total>$resultsperpage) {
105         for (my $i=1; $i<$total/$resultsperpage+1; $i++) {
106             if ($i<16) {
107                 my $highlight=0;
108                 ($startfrom==($i-1)) && ($highlight=1);
109                 push @numbers, { number => $i,
110                     highlight => $highlight ,
111                     searchdata=> \@field_data,
112                     startfrom => ($i-1)};
113             }
114         }
115     }
116
117     my $from = $startfrom*$resultsperpage+1;
118     my $to;
119
120      if($total < (($startfrom+1)*$resultsperpage)) {
121         $to = $total;
122     } else {
123         $to = (($startfrom+1)*$resultsperpage);
124     }
125     $template->param(result => $results) if $results;
126     $template->param(index => $query->param('index')."");
127     $template->param(startfrom=> $startfrom,
128                             displaynext=> $displaynext,
129                             displayprev=> $displayprev,
130                             resultsperpage => $resultsperpage,
131                             startfromnext => $startfrom+1,
132                             startfromprev => $startfrom-1,
133                             index => $index,
134                             searchdata=>\@field_data,
135                             total=>$total,
136                             from=>$from,
137                             to=>$to,
138                             numbers=>\@numbers,
139                             authtypecode =>$authtypecode,
140                             resultstring =>$value[0],
141                             );
142 } else {
143     ($template, $loggedinuser, $cookie)
144         = get_template_and_user({template_name => "authorities/auth_linker.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                     resultstring => $resultstring,
154     
155                     );
156 }
157
158 $template->param(authtypesloop => \@authtypesloop,
159                 authtypecode => $authtypecode,
160                 nonav=>"1",);
161
162 # Print the page
163 output_html_with_http_headers $query, $cookie, $template->output;
164
165 # Local Variables:
166 # tab-width: 4
167 # End: