2 # WARNING: 4-character tab stops here
4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
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
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.
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
25 use C4::Interface::CGI::Output;
26 use C4::AuthoritiesMarc;
27 use C4::Koha; # XXX subfield_is_koha_internal_p
32 my $op = $query->param('op');
33 my $authtypecode = $query->param('authtypecode');
34 my $dbh = C4::Context->dbh;
35 my $mergefrom=$query->param('mergefrom');
36 my $mergeto=$query->param('mergeto');
37 my $startfrom=$query->param('startfrom');
38 my $authid=$query->param('authid');
39 $startfrom=0 if(!defined $startfrom);
40 my ($template, $loggedinuser, $cookie);
43 my $authtypes = getauthtypes;
45 foreach my $thisauthtype (sort { $authtypes->{$a} <=> $authtypes->{$b} } keys %$authtypes) {
46 my $selected = 1 if $thisauthtype eq $authtypecode;
47 my %row =(value => $thisauthtype,
48 selected => $selected,
49 authtypetext => $authtypes->{$thisauthtype}{'authtypetext'},
51 push @authtypesloop, \%row;
55 if ($op eq "do_search") {
56 my @marclist = $query->param('marclist');
58 my @operator = $query->param('operator');
59 my @value = $query->param('value');
61 $resultsperpage= $query->param('resultsperpage');
62 $resultsperpage = 10 unless $resultsperpage;
64 my ($results,$total) = authoritysearch($dbh, \@marclist, \@operator, \@value,$startfrom*$resultsperpage, $resultsperpage,$authtypecode) ;
65 ($template, $loggedinuser, $cookie)
66 = get_template_and_user({template_name => "authorities/searchresultlist.tmpl",
70 authtypecode=> $authtypecode,
71 flagsrequired => {borrowers => 1},
72 flagsrequired => {catalogue => 1},
76 # multi page display gestion
78 my $displayprev=$startfrom;
79 if(($total - (($startfrom+1)*($resultsperpage))) > 0 ){
85 # we must get parameters once again. Because if there is a mainentry, it has been replaced by something else during the search, thus the links next/previous would not work anymore
86 my @marclist_ini = $query->param('marclist');
87 for(my $i = 0 ; $i <= $#marclist ; $i++)
89 push @field_data, { term => "marclist", val=>$marclist_ini[$i] };
90 push @field_data, { term => "operator", val=>$operator[$i] };
91 push @field_data, { term => "value", val=>$value[$i] };
96 if ($total>$resultsperpage)
98 for (my $i=1; $i<$total/$resultsperpage+1; $i++)
103 ($startfrom==($i-1)) && ($highlight=1);
104 push @numbers, { number => $i,
105 highlight => $highlight ,
106 searchdata=> \@field_data,
107 startfrom => ($i-1)};
112 my $from = $startfrom*$resultsperpage+1;
115 if($total < (($startfrom+1)*$resultsperpage))
119 $to = (($startfrom+1)*$resultsperpage);
121 $template->param(result => $results) if $results;
123 startfrom=> $startfrom,
124 displaynext=> $displaynext,
125 displayprev=> $displayprev,
126 resultsperpage => $resultsperpage,
127 startfromnext => $startfrom+1,
128 startfromprev => $startfrom-1,
129 searchdata=>\@field_data,
134 authtypecode=>$authtypecode,
137 } elsif ($op eq "delete") {
139 &AUTHdelauthority($dbh,$authid);
141 ($template, $loggedinuser, $cookie)
142 = get_template_and_user({template_name => "authorities/authorities-home.tmpl",
145 authnotrequired => 0,
146 flagsrequired => {catalogue => 1},
151 }elsif ($op eq "merge") {
154 my $MARCfrom = XMLgetauthorityhash($dbh,$mergefrom);
155 my $MARCto = XMLgetauthorityhash($dbh,$mergeto);
156 merge($dbh,$mergefrom,$MARCfrom,$mergeto,$MARCto);
157 ($template, $loggedinuser, $cookie)
158 = get_template_and_user({template_name => "authorities/authorities-home.tmpl",
161 authnotrequired => 0,
162 flagsrequired => {catalogue => 1},
166 ($template, $loggedinuser, $cookie)
167 = get_template_and_user({template_name => "authorities/authorities-home.tmpl",
170 authnotrequired => 0,
171 flagsrequired => {catalogue => 1},
179 $template->param(authtypesloop => \@authtypesloop);
182 output_html_with_http_headers $query, $cookie, $template->output;