Clean up before final commits
[koha.git] / authorities / authorities-home.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 use CGI;
23 use C4::Auth;
24 use C4::Context;
25 use C4::Interface::CGI::Output;
26 use C4::AuthoritiesMarc;
27 use C4::Koha; # XXX subfield_is_koha_internal_p
28 use C4::Biblio;
29
30
31 my $query=new CGI;
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);
41 my $resultsperpage;
42
43 my $authtypes = getauthtypes;
44 my @authtypesloop;
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'},
50                         );
51         push @authtypesloop, \%row;
52 }
53
54
55 if ($op eq "do_search") {
56         my @marclist = $query->param('marclist');
57         
58         my @operator = $query->param('operator');
59         my @value = $query->param('value');
60
61         $resultsperpage= $query->param('resultsperpage');
62         $resultsperpage = 10 unless $resultsperpage;
63         my @tags;
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",
67                                 query => $query,
68                                 type => 'intranet',
69                                 authnotrequired => 0,
70                                 authtypecode=> $authtypecode,
71                                 flagsrequired => {borrowers => 1},
72                                 flagsrequired => {catalogue => 1},
73                                 debug => 1,
74                                 });
75
76         # multi page display gestion
77         my $displaynext=0;
78         my $displayprev=$startfrom;
79         if(($total - (($startfrom+1)*($resultsperpage))) > 0 ){
80                 $displaynext = 1;
81         }
82
83         my @field_data = ();
84
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++)
88         {
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] };
92         }
93
94         my @numbers = ();
95
96         if ($total>$resultsperpage)
97         {
98                 for (my $i=1; $i<$total/$resultsperpage+1; $i++)
99                 {
100                         if ($i<31)
101                         {
102                         my $highlight=0;
103                         ($startfrom==($i-1)) && ($highlight=1);
104                         push @numbers, { number => $i,
105                                         highlight => $highlight ,
106                                         searchdata=> \@field_data,
107                                         startfrom => ($i-1)};
108                         }
109         }
110         }
111
112         my $from = $startfrom*$resultsperpage+1;
113         my $to;
114
115         if($total < (($startfrom+1)*$resultsperpage))
116         {
117                 $to = $total;
118         } else {
119                 $to = (($startfrom+1)*$resultsperpage);
120         }
121         $template->param(result => $results) if $results;
122         $template->param(
123                                                         startfrom=> $startfrom,
124                                                         displaynext=> $displaynext,
125                                                         displayprev=> $displayprev,
126                                                         resultsperpage => $resultsperpage,
127                                                         startfromnext => $startfrom+1,
128                                                         startfromprev => $startfrom-1,
129                                                         searchdata=>\@field_data,
130                                                         total=>$total,
131                                                         from=>$from,
132                                                         to=>$to,
133                                                         numbers=>\@numbers,
134                                                         authtypecode=>$authtypecode,
135                                                         );
136
137 } elsif ($op eq "delete") {
138
139         &AUTHdelauthority($dbh,$authid);
140
141         ($template, $loggedinuser, $cookie)
142                 = get_template_and_user({template_name => "authorities/authorities-home.tmpl",
143                                 query => $query,
144                                 type => 'intranet',
145                                 authnotrequired => 0,
146                                 flagsrequired => {catalogue => 1},
147                                 debug => 1,
148                                 });
149
150
151 }elsif ($op eq "merge") {
152
153
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",
159                                 query => $query,
160                                 type => 'intranet',
161                                 authnotrequired => 0,
162                                 flagsrequired => {catalogue => 1},
163                                 debug => 1,
164                                 });
165 }else {
166         ($template, $loggedinuser, $cookie)
167                 = get_template_and_user({template_name => "authorities/authorities-home.tmpl",
168                                 query => $query,
169                                 type => 'intranet',
170                                 authnotrequired => 0,
171                                 flagsrequired => {catalogue => 1},
172                                 debug => 1,
173                                 });
174
175 }
176
177
178
179 $template->param(authtypesloop => \@authtypesloop);
180
181 # Print the page
182 output_html_with_http_headers $query, $cookie, $template->output;
183
184 # Local Variables:
185 # tab-width: 4
186 # End: