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;
30 use C4::Koha; # XXX subfield_is_koha_internal_p
33 my $op = $query->param('op');
34 my $authtypecode = $query->param('authtypecode');
35 my $dbh = C4::Context->dbh;
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} }
48 my $selected = 1 if $thisauthtype eq $authtypecode;
50 value => $thisauthtype,
51 selected => $selected,
52 authtypetext => $authtypes->{$thisauthtype}{'authtypetext'},
54 push @authtypesloop, \%row;
57 if ( $op eq "do_search" ) {
58 my @marclist = $query->param('marclist');
59 my @and_or = $query->param('and_or');
60 my @excluding = $query->param('excluding');
61 my @operator = $query->param('operator');
62 my $orderby = $query->param('orderby');
63 my @value = $query->param('value');
65 $resultsperpage = $query->param('resultsperpage');
66 $resultsperpage = 19 if ( !defined $resultsperpage );
68 my ( $results, $total, @fields ) =
69 SearchAuthorities( \@marclist, \@and_or, \@excluding, \@operator,
70 \@value, $startfrom * $resultsperpage,
71 $resultsperpage, $authtypecode );
72 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
74 template_name => "opac-authoritiessearchresultlist.tmpl",
82 # multi page display gestion
84 my $displayprev = $startfrom;
85 if ( ( $total - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) {
91 # 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
92 my @marclist_ini = $query->param('marclist');
93 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] };
103 if ( $total > $resultsperpage ) {
104 for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
107 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
111 highlight => $highlight,
112 searchdata => \@field_data,
113 startfrom => ( $i - 1 )
119 my $from = $startfrom * $resultsperpage + 1;
122 if ( $total < ( ( $startfrom + 1 ) * $resultsperpage ) ) {
126 $to = ( ( $startfrom + 1 ) * $resultsperpage );
128 $template->param( result => $results ) if $results;
129 $template->param( FIELDS => \@fields );
131 startfrom => $startfrom,
132 displaynext => $displaynext,
133 displayprev => $displayprev,
134 resultsperpage => $resultsperpage,
135 startfromnext => $startfrom + 1,
136 startfromprev => $startfrom - 1,
137 searchdata => \@field_data,
141 numbers => \@numbers,
142 authtypecode => $authtypecode,
143 isEDITORS => $authtypecode eq 'EDITORS',
147 elsif ( $op eq "delete" ) {
149 &DelAuthority( $authid, 1 );
151 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
153 template_name => "authorities/authorities-home.tmpl",
156 authnotrequired => 0,
157 flagsrequired => { catalogue => 1 },
162 # $template->param("statements" => \@statements,
163 # "nbstatements" => $nbstatements);
165 elsif ( $op eq "AddStatement" ) {
167 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
169 template_name => "authorities/authorities-home.tmpl",
172 authnotrequired => 0,
173 flagsrequired => { catalogue => 1 },
178 # Gets the entered information
179 my @marcfields = $query->param('marclist');
180 my @and_or = $query->param('and_or');
181 my @excluding = $query->param('excluding');
182 my @operator = $query->param('operator');
183 my @value = $query->param('value');
187 # List of the marc tags to display
188 my $marcarray = create_marclist();
190 my $nbstatements = $query->param('nbstatements');
191 $nbstatements = 1 if ( !defined $nbstatements );
193 for ( my $i = 0 ; $i < $nbstatements ; $i++ ) {
196 # Recreates the old scrolling lists with the previously selected values
197 my $marclist = create_scrolling_list(
200 values => $marcarray,
202 default => $marcfields[$i],
203 onChange => "sql_update()"
207 $fields{'marclist'} = $marclist;
208 $fields{'first'} = 1 if ( $i == 0 );
210 # Restores the and/or parameters (no need to test the 'and' for activation because it's the default value)
211 $fields{'or'} = 1 if ( $and_or[$i] eq "or" );
213 #Restores the "not" parameters
214 $fields{'not'} = 1 if ( $excluding[$i] );
216 #Restores the operators (most common operators first);
217 if ( $operator[$i] eq "=" ) { $fields{'eq'} = 1; }
218 elsif ( $operator[$i] eq "contains" ) { $fields{'contains'} = 1; }
219 elsif ( $operator[$i] eq "start" ) { $fields{'start'} = 1; }
220 elsif ( $operator[$i] eq ">" ) { $fields{'gt'} = 1; } #greater than
221 elsif ( $operator[$i] eq ">=" ) { $fields{'ge'} = 1; } #greater or equal
222 elsif ( $operator[$i] eq "<" ) { $fields{'lt'} = 1; } #lower than
223 elsif ( $operator[$i] eq "<=" ) { $fields{'le'} = 1; } #lower or equal
226 $fields{'value'} = $value[$i];
228 push @statements, \%fields;
232 # The new scrolling list
233 my $marclist = create_scrolling_list(
236 values => $marcarray,
238 onChange => "sql_update()"
241 push @statements, { "marclist" => $marclist };
244 "statements" => \@statements,
245 "nbstatements" => $nbstatements
250 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
252 template_name => "opac-authorities-home.tmpl",
255 authnotrequired => 1,
262 $template->param( authtypesloop => \@authtypesloop );
265 output_html_with_http_headers $query, $cookie, $template->output;