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
30 use C4::Interface::CGI::Output;
31 use C4::AuthoritiesMarc;
34 use C4::Koha; # XXX subfield_is_koha_internal_p
37 my $op = $query->param('op');
38 my $authtypecode = $query->param('authtypecode');
39 my $dbh = C4::Context->dbh;
41 my $authid=$query->param('authid');
42 my ($template, $loggedinuser, $cookie);
44 my $authtypes = getauthtypes;
46 foreach my $thisauthtype (sort { $authtypes->{$a} <=> $authtypes->{$b} } keys %$authtypes) {
47 my $selected = 1 if $thisauthtype eq $authtypecode;
48 my %row =(value => $thisauthtype,
49 selected => $selected,
50 authtypetext => $authtypes->{$thisauthtype}{'authtypetext'},
52 push @authtypesloop, \%row;
55 if ($op eq "do_search") {
56 my @marclist = $query->param('marclist');
57 my @and_or = $query->param('and_or');
58 my @excluding = $query->param('excluding');
59 my @operator = $query->param('operator');
60 my @value = $query->param('value');
62 my $startfrom = $query->param('startfrom') || 1;
63 my $resultsperpage = $query->param('resultsperpage') || 19;
65 my ($results,$total) = authoritysearch(
72 ($startfrom - 1)*$resultsperpage,
77 ($template, $loggedinuser, $cookie)
78 = get_template_and_user({
79 template_name => "authorities/searchresultlist.tmpl",
83 flagsrequired => {borrowers => 1},
84 flagsrequired => {catalogue => 1},
90 # we must get parameters once again. Because if there is a mainentry, it
91 # has been replaced by something else during the search, thus the links
92 # next/previous would not work anymore
93 my @marclist_ini = $query->param('marclist');
94 for(my $i = 0 ; $i <= $#marclist ; $i++)
96 push @field_data, { term => "marclist" , val=>$marclist_ini[$i] };
97 push @field_data, { term => "and_or" , val=>$and_or[$i] };
98 push @field_data, { term => "excluding" , val=>$excluding[$i] };
99 push @field_data, { term => "operator" , val=>$operator[$i] };
100 push @field_data, { term => "value" , val=>$value[$i] };
103 # construction of the url of each page
105 'authorities-home.pl?'
108 map { $_->{term}.'='.$_->{val} } @field_data
113 map { $_->{term}.'='.$_->{val} } (
114 {term => 'resultsperpage', val => $resultsperpage},
115 {term => 'type' , val => 'intranet'},
116 {term => 'op' , val => 'do_search'},
117 {term => 'authtypecode' , val => $authtypecode}
122 my $from = ($startfrom - 1) * $resultsperpage + 1;
125 if ($total < $startfrom * $resultsperpage) {
129 $to = $startfrom * $resultsperpage;
132 $template->param(result => $results) if $results;
135 pagination_bar => pagination_bar(
137 int($total/$resultsperpage)+1,
144 isEDITORS => $authtypecode eq 'EDITORS',
147 } elsif ($op eq "delete") {
149 &AUTHdelauthority($dbh,$authid, 1);
151 ($template, $loggedinuser, $cookie)
152 = get_template_and_user({template_name => "authorities/authorities-home.tmpl",
155 authnotrequired => 0,
156 flagsrequired => {catalogue => 1},
159 # $template->param("statements" => \@statements,
160 # "nbstatements" => $nbstatements);
162 elsif ($op eq "AddStatement") {
164 ($template, $loggedinuser, $cookie)
165 = get_template_and_user({template_name => "authorities/authorities-home.tmpl",
168 authnotrequired => 0,
169 flagsrequired => {catalogue => 1},
173 # Gets the entered information
174 my @marcfields = $query->param('marclist');
175 my @and_or = $query->param('and_or');
176 my @excluding = $query->param('excluding');
177 my @operator = $query->param('operator');
178 my @value = $query->param('value');
182 # List of the marc tags to display
183 my $marcarray = create_marclist();
185 my $nbstatements = $query->param('nbstatements');
186 $nbstatements = 1 if(!defined $nbstatements);
188 for(my $i = 0 ; $i < $nbstatements ; $i++)
192 # Recreates the old scrolling lists with the previously selected values
193 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",
229 onChange => "sql_update()"});
230 push @statements, {"marclist" => $marclist };
232 $template->param("statements" => \@statements,
233 "nbstatements" => $nbstatements);
237 ($template, $loggedinuser, $cookie)
238 = get_template_and_user({template_name => "authorities/authorities-home.tmpl",
241 authnotrequired => 0,
242 flagsrequired => {catalogue => 1},
248 $template->param(authtypesloop => \@authtypesloop);
251 output_html_with_http_headers $query, $cookie, $template->output;