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
29 use C4::AuthoritiesMarc;
31 use C4::Koha; # XXX subfield_is_koha_internal_p
35 my $op = $query->param('op');
36 my $authtypecode = $query->param('authtypecode');
37 my $dbh = C4::Context->dbh;
39 my $authid=$query->param('authid');
40 my ($template, $loggedinuser, $cookie);
42 my $authtypes = getauthtypes;
44 foreach my $thisauthtype (sort { $authtypes->{$a} <=> $authtypes->{$b} } keys %$authtypes) {
45 my $selected = 1 if $thisauthtype eq $authtypecode;
46 my %row =(value => $thisauthtype,
47 selected => $selected,
48 authtypetext => $authtypes->{$thisauthtype}{'authtypetext'},
50 push @authtypesloop, \%row;
53 if ($op eq "do_search") {
54 my @marclist = $query->param('marclist');
55 my @and_or = $query->param('and_or');
56 my @excluding = $query->param('excluding');
57 my @operator = $query->param('operator');
58 my $orderby = $query->param('orderby');
59 my @value = $query->param('value');
61 my $startfrom = $query->param('startfrom') || 1;
62 my $resultsperpage = $query->param('resultsperpage') || 19;
64 my ($results,$total) = SearchAuthorities(
70 ($startfrom - 1)*$resultsperpage,
76 ($template, $loggedinuser, $cookie)
77 = get_template_and_user({
78 template_name => "authorities/searchresultlist.tmpl",
82 flagsrequired => {catalogue => 1},
88 # we must get parameters once again. Because if there is a mainentry, it
89 # has been replaced by something else during the search, thus the links
90 # next/previous would not work anymore
91 my @marclist_ini = $query->param('marclist');
92 for(my $i = 0 ; $i <= $#marclist ; $i++)
94 push @field_data, { term => "marclist" , val=>$marclist_ini[$i] };
95 push @field_data, { term => "and_or" , val=>$and_or[$i] };
96 push @field_data, { term => "excluding" , val=>$excluding[$i] };
97 push @field_data, { term => "operator" , val=>$operator[$i] };
98 push @field_data, { term => "value" , val=>$value[$i] };
101 # construction of the url of each page
103 'authorities-home.pl?'
106 map { $_->{term}.'='.$_->{val} } @field_data
111 map { $_->{term}.'='.$_->{val} } (
112 {term => 'resultsperpage', val => $resultsperpage},
113 {term => 'type' , val => 'intranet'},
114 {term => 'op' , val => 'do_search'},
115 {term => 'authtypecode' , val => $authtypecode},
116 {term => 'orderby' , val => $orderby},
121 my $from = ($startfrom - 1) * $resultsperpage + 1;
124 if ($total < $startfrom * $resultsperpage) {
128 $to = $startfrom * $resultsperpage;
131 $template->param(result => $results) if $results;
134 pagination_bar => pagination_bar(
136 int($total/$resultsperpage)+1,
143 isEDITORS => $authtypecode eq 'EDITORS',
146 } elsif ($op eq "delete") {
148 &DelAuthority($authid, 1);
150 ($template, $loggedinuser, $cookie)
151 = get_template_and_user({template_name => "authorities/authorities-home.tmpl",
154 authnotrequired => 0,
155 flagsrequired => {catalogue => 1},
158 # $template->param("statements" => \@statements,
159 # "nbstatements" => $nbstatements);
161 elsif ($op eq "AddStatement") {
163 ($template, $loggedinuser, $cookie)
164 = get_template_and_user({template_name => "authorities/authorities-home.tmpl",
167 authnotrequired => 0,
168 flagsrequired => {catalogue => 1},
172 # Gets the entered information
173 my @marcfields = $query->param('marclist');
174 my @and_or = $query->param('and_or');
175 my @excluding = $query->param('excluding');
176 my @operator = $query->param('operator');
177 my @value = $query->param('value');
181 # List of the marc tags to display
182 my $marcarray = create_marclist();
184 my $nbstatements = $query->param('nbstatements');
185 $nbstatements = 1 if(!defined $nbstatements);
187 for(my $i = 0 ; $i < $nbstatements ; $i++)
191 # Recreates the old scrolling lists with the previously selected values
192 my $marclist = create_scrolling_list({name=>"marclist",
196 default=>$marcfields[$i],
197 onChange => "sql_update()"}
200 $fields{'marclist'} = $marclist;
201 $fields{'first'} = 1 if($i == 0);
203 # Restores the and/or parameters (no need to test the 'and' for activation because it's the default value)
204 $fields{'or'} = 1 if($and_or[$i] eq "or");
206 #Restores the "not" parameters
207 $fields{'not'} = 1 if($excluding[$i]);
209 #Restores the operators (most common operators first);
210 if($operator[$i] eq "=") { $fields{'eq'} = 1; }
211 elsif($operator[$i] eq "contains") { $fields{'contains'} = 1; }
212 elsif($operator[$i] eq "start") { $fields{'start'} = 1; }
213 elsif($operator[$i] eq ">") { $fields{'gt'} = 1; } #greater than
214 elsif($operator[$i] eq ">=") { $fields{'ge'} = 1; } #greater or equal
215 elsif($operator[$i] eq "<") { $fields{'lt'} = 1; } #lower than
216 elsif($operator[$i] eq "<=") { $fields{'le'} = 1; } #lower or equal
219 $fields{'value'} = $value[$i];
221 push @statements, \%fields;
225 # The new scrolling list
226 my $marclist = create_scrolling_list({name=>"marclist",
230 onChange => "sql_update()"});
231 push @statements, {"marclist" => $marclist };
233 $template->param("statements" => \@statements,
234 "nbstatements" => $nbstatements);
238 ($template, $loggedinuser, $cookie)
239 = get_template_and_user({template_name => "authorities/authorities-home.tmpl",
242 authnotrequired => 0,
243 flagsrequired => {catalogue => 1},
249 $template->param(authtypesloop => \@authtypesloop,
250 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
251 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
252 IntranetNav => C4::Context->preference("IntranetNav"),
256 output_html_with_http_headers $query, $cookie, $template->output;