3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
24 use C4::Interface::CGI::Output;
35 sub plugin_parameters {
36 my ($dbh,$record,$tagslib,$i,$tabloop) = @_;
40 sub plugin_javascript {
41 my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
42 my $function_name= "4XX".(int(rand(100000))+1);
45 function Focus$function_name(subfield_managed) {
49 function Blur$function_name(subfield_managed) {
53 function Clic$function_name(i) {
54 defaultvalue=document.f.field_value[i].value;
55 newin=window.open(\"../plugin_launcher.pl?plugin_name=unimarc_field_4XX.pl&index=\"+i+\"&result=\"+defaultvalue,\"unimarc field 4\"+i+\"\",'width=700,height=700,toolbar=false,scrollbars=yes');
61 return ($function_name,$res);
69 my $dbh=C4::Context->dbh;
71 my $op = $query->param('op');
72 my $type=$query->param('type');
73 warn "operation ".$op;
74 my $startfrom=$query->param('startfrom');
75 $startfrom=0 if(!defined $startfrom);
76 my ($template, $loggedinuser, $cookie);
80 if ($op eq "do_search") {
81 my @marclist = $query->param('marclist');
82 my @and_or = $query->param('and_or');
83 my @excluding = $query->param('excluding');
84 my @operator = $query->param('operator');
85 my @value = $query->param('value');
87 for (my $i=0;$i<=$#marclist;$i++) {
88 if ($searchdesc) { # don't put the and_or on the 1st search term
89 $searchdesc .= $and_or[$i]." ".$excluding[$i]." ".($marclist[$i]?$marclist[$i]:"*")." ".$operator[$i]." ".$value[$i]." " if ($value[$i]);
91 $searchdesc = $excluding[$i]." ".($marclist[$i]?$marclist[$i]:"*")." ".$operator[$i]." ".$value[$i]." " if ($value[$i]);
94 $resultsperpage= $query->param('resultsperpage');
95 $resultsperpage = 19 if(!defined $resultsperpage);
96 my $orderby = $query->param('orderby');
97 my $desc_or_asc = $query->param('desc_or_asc');
99 # builds tag and subfield arrays
101 foreach my $marc (@marclist) {
103 my ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,$marc,'');
105 push @tags,$dbh->quote("$tag$subfield");
107 push @tags, $dbh->quote(substr($marc,0,4));
114 my ($results,$total) = catalogsearch($dbh, \@tags,\@and_or,
115 \@excluding, \@operator, \@value,
116 $startfrom*$resultsperpage, $resultsperpage,$orderby, $desc_or_asc);
117 warn " biblio count : ".$total;
118 warn " biblio count : ".$total;
120 ($template, $loggedinuser, $cookie)
121 = get_template_and_user({template_name => "value_builder/unimarc_field_4XX.tmpl",
124 authnotrequired => 1,
128 # multi page display gestion
130 my $displayprev=$startfrom;
131 if(($total - (($startfrom+1)*($resultsperpage))) > 0 ){
138 for(my $i = 0 ; $i <= $#marclist ; $i++)
140 push @field_data, { term => "marclist", val=>$marclist[$i] };
141 push @field_data, { term => "and_or", val=>$and_or[$i] };
142 push @field_data, { term => "excluding", val=>$excluding[$i] };
143 push @field_data, { term => "operator", val=>$operator[$i] };
144 push @field_data, { term => "value", val=>$value[$i] };
149 if ($total>$resultsperpage)
151 for (my $i=1; $i<$total/$resultsperpage+1; $i++)
156 ($startfrom==($i-1)) && ($highlight=1);
157 push @numbers, { number => $i,
158 highlight => $highlight ,
159 searchdata=> \@field_data,
160 startfrom => ($i-1)};
165 my $from = $startfrom*$resultsperpage+1;
168 if($total < (($startfrom+1)*$resultsperpage))
172 $to = (($startfrom+1)*$resultsperpage);
174 my $defaultview = 'BiblioDefaultView'.C4::Context->preference('BiblioDefaultView');
175 $template->param(result => $results,
176 index => $query->param('index')."",
177 startfrom=> $startfrom,
178 displaynext=> $displaynext,
179 displayprev=> $displayprev,
180 resultsperpage => $resultsperpage,
182 startfromnext => $startfrom+1,
183 startfromprev => $startfrom-1,
184 searchdata=>\@field_data,
189 searchdesc=> $searchdesc,
195 ($template, $loggedinuser, $cookie)
196 = get_template_and_user({template_name => "value_builder/unimarc_field_4XX.tmpl",
199 authnotrequired => 1,
203 my $sth=$dbh->prepare("Select itemtype,description from itemtypes order by description");
209 while (my ($value,$lib) = $sth->fetchrow_array) {
210 push @itemtype, $value;
211 $itemtypes{$value}=$lib;
214 my $CGIitemtype=CGI::scrolling_list( -name => 'value',
215 -values => \@itemtype,
216 -labels => \%itemtypes,
224 my $branches=getbranches;
225 push @select_branch, "";
226 $select_branches{''} = "";
227 foreach my $thisbranch (keys %$branches){
228 push @select_branch, $branches->{$thisbranch}->{'branchcode'};
229 $select_branches{$branches->{$thisbranch}->{'branchcode'}} = $branches->{$thisbranch}->{'branchname'};
231 my $CGIbranch=CGI::scrolling_list( -name => 'value',
232 -values => \@select_branch,
233 -labels => \%select_branches,
238 my $req = $dbh->prepare("select distinctrow left(publishercode,45) from biblioitems order by publishercode");
242 while (my ($value) =$req->fetchrow) {
243 push @select, $value;
245 my $CGIpublisher=CGI::scrolling_list( -name => 'value',
251 # my $sth=$dbh->prepare("select description,itemtype from itemtypes order by description");
253 # while (my ($description,$itemtype) = $sth->fetchrow) {
254 # $classlist.="<option value=\"$itemtype\">$description</option>\n";
258 $template->param(#classlist => $classlist,
259 CGIitemtype => $CGIitemtype,
260 CGIbranch => $CGIbranch,
261 CGIPublisher => $CGIpublisher,
265 output_html_with_http_headers $query, $cookie, $template->output ;