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 $startfrom=$query->param('startfrom');
42 my $authid=$query->param('authid');
43 $startfrom=0 if(!defined $startfrom);
44 my ($template, $loggedinuser, $cookie);
47 my $authtypes = getauthtypes;
49 foreach my $thisauthtype (keys %$authtypes) {
50 my $selected = 1 if $thisauthtype eq $authtypecode;
51 my %row =(value => $thisauthtype,
52 selected => $selected,
53 authtypetext => $authtypes->{$thisauthtype}{'authtypetext'},
55 push @authtypesloop, \%row;
58 if ($op eq "do_search") {
59 my @marclist = $query->param('marclist');
60 my @and_or = $query->param('and_or');
61 my @excluding = $query->param('excluding');
62 my @operator = $query->param('operator');
63 my @value = $query->param('value');
65 $resultsperpage= $query->param('resultsperpage');
66 $resultsperpage = 19 if(!defined $resultsperpage);
68 my ($results,$total) = authoritysearch($dbh, \@tags,\@and_or,
69 \@excluding, \@operator, \@value,
70 $startfrom*$resultsperpage, $resultsperpage,$authtypecode);
72 ($template, $loggedinuser, $cookie)
73 = get_template_and_user({template_name => "authorities/searchresultlist.tmpl",
77 flagsrequired => {borrowers => 1},
78 flagsrequired => {catalogue => 1},
82 # multi page display gestion
84 my $displayprev=$startfrom;
85 if(($total - (($startfrom+1)*($resultsperpage))) > 0 ){
92 for(my $i = 0 ; $i <= $#marclist ; $i++)
94 push @field_data, { term => "marclist", val=>$marclist[$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)
105 for (my $i=1; $i<$total/$resultsperpage+1; $i++)
110 ($startfrom==($i-1)) && ($highlight=1);
111 push @numbers, { number => $i,
112 highlight => $highlight ,
113 searchdata=> \@field_data,
114 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;
130 startfrom=> $startfrom,
131 displaynext=> $displaynext,
132 displayprev=> $displayprev,
133 resultsperpage => $resultsperpage,
134 startfromnext => $startfrom+1,
135 startfromprev => $startfrom-1,
136 searchdata=>\@field_data,
143 } elsif ($op eq "delete") {
145 &AUTHdelauthority($dbh,$authid, 1);
147 ($template, $loggedinuser, $cookie)
148 = get_template_and_user({template_name => "authorities/authorities-home.tmpl",
151 authnotrequired => 0,
152 flagsrequired => {catalogue => 1},
155 # $template->param("statements" => \@statements,
156 # "nbstatements" => $nbstatements);
158 elsif ($op eq "AddStatement") {
160 ($template, $loggedinuser, $cookie)
161 = get_template_and_user({template_name => "authorities/authorities-home.tmpl",
164 authnotrequired => 0,
165 flagsrequired => {catalogue => 1},
169 # Gets the entered information
170 my @marcfields = $query->param('marclist');
171 my @and_or = $query->param('and_or');
172 my @excluding = $query->param('excluding');
173 my @operator = $query->param('operator');
174 my @value = $query->param('value');
178 # List of the marc tags to display
179 my $marcarray = create_marclist();
181 my $nbstatements = $query->param('nbstatements');
182 $nbstatements = 1 if(!defined $nbstatements);
184 for(my $i = 0 ; $i < $nbstatements ; $i++)
188 # Recreates the old scrolling lists with the previously selected values
189 my $marclist = create_scrolling_list({name=>"marclist",
192 default=>$marcfields[$i],
193 onChange => "sql_update()"}
196 $fields{'marclist'} = $marclist;
197 $fields{'first'} = 1 if($i == 0);
199 # Restores the and/or parameters (no need to test the 'and' for activation because it's the default value)
200 $fields{'or'} = 1 if($and_or[$i] eq "or");
202 #Restores the "not" parameters
203 $fields{'not'} = 1 if($excluding[$i]);
205 #Restores the operators (most common operators first);
206 if($operator[$i] eq "=") { $fields{'eq'} = 1; }
207 elsif($operator[$i] eq "contains") { $fields{'contains'} = 1; }
208 elsif($operator[$i] eq "start") { $fields{'start'} = 1; }
209 elsif($operator[$i] eq ">") { $fields{'gt'} = 1; } #greater than
210 elsif($operator[$i] eq ">=") { $fields{'ge'} = 1; } #greater or equal
211 elsif($operator[$i] eq "<") { $fields{'lt'} = 1; } #lower than
212 elsif($operator[$i] eq "<=") { $fields{'le'} = 1; } #lower or equal
215 $fields{'value'} = $value[$i];
217 push @statements, \%fields;
221 # The new scrolling list
222 my $marclist = create_scrolling_list({name=>"marclist",
225 onChange => "sql_update()"});
226 push @statements, {"marclist" => $marclist };
228 $template->param("statements" => \@statements,
229 "nbstatements" => $nbstatements);
233 ($template, $loggedinuser, $cookie)
234 = get_template_and_user({template_name => "authorities/authorities-home.tmpl",
237 authnotrequired => 0,
238 flagsrequired => {catalogue => 1},
244 $template->param(authtypesloop => \@authtypesloop);
247 output_html_with_http_headers $query, $cookie, $template->output;