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
23 use C4::Interface::CGI::Output;
28 use C4::AuthoritiesMarc;
34 my $field =$input->param('marclist');
35 #warn "field :$field";
36 my ($tablename, $kohafield)=split /./,$field;
37 #my $tablename=$input->param('tablename');
38 $tablename="biblio" unless ($tablename);
39 #my $kohafield = $input->param('kohafield');
40 my @search = $input->param('search');
42 my $op=$input->param('op');
43 if (($search[0]) and not ($op eq 'do_search')){
46 my $script_name = 'search.marc/dictionary.pl';
48 my $type=$input->param('type');
51 my $dbh = C4::Context->dbh;
52 my ($template, $loggedinuser, $cookie);
56 my $startfrom=$input->param('startfrom');
57 $startfrom=0 if(!defined $startfrom);
61 #warn "Starting process";
63 if ($op eq "do_search") {
64 ($template, $loggedinuser, $cookie)
65 = get_template_and_user({template_name => "search.marc/dictionary.tmpl",
69 flagsrequired => {catalogue => 1},
72 my $sth=$dbh->prepare("Select distinct tagfield,tagsubfield from marc_subfield_structure where kohafield = ?");
73 $sth->execute("$field");
74 my (@tags, @and_or, @operator, @excluding,@value);
76 while ((my $tagfield,my $tagsubfield,my $liblibrarian) = $sth->fetchrow) {
77 push @tags, $dbh->quote("$tagfield$tagsubfield");
79 push @operator, "contains";
81 push @value, @search ;
84 $resultsperpage= $input->param('resultsperpage');
85 $resultsperpage = 19 if(!defined $resultsperpage);
86 my $orderby = $input->param('orderby');
88 findseealso($dbh,\@tags);
89 # select distinct m1.bibid from biblio,biblioitems,marc_biblio,marc_word as m1 where biblio.biblionumber=marc_biblio.biblionumber and biblio.biblionumber=biblioitems.biblionumber and m1.bibid=marc_biblio.bibid and (m1.word like 'Paul' and m1.tagsubfield in ('200f','710a','711a','712a','701a','702a','700a')) order by biblio.title
92 my ($results,$total) = catalogsearch($dbh,\@tags ,\@and_or,
93 \@excluding, \@operator, \@value,
94 $startfrom*$resultsperpage, $resultsperpage,$orderby);
96 my $strsth="Select distinct authtypecode from marc_subfield_structure where ";
97 my $strtagfields="tagfield in (";
98 my $strtagsubfields=" and tagsubfield in (";
99 foreach my $listtags (@tags){
100 my @taglist=split /,/,$listtags;
101 foreach my $curtag (@taglist){
102 $strtagfields=$strtagfields."'".substr($curtag,1,3)."',";
103 $strtagsubfields=$strtagsubfields."'".substr($curtag,4,1)."',";
106 $strtagfields=~s/,$/)/;
107 $strtagsubfields=~s/,$/)/;
108 my $strsth = $strsth.$strtagfields.$strtagsubfields." and authtypecode is not NULL";
110 my $sth=$dbh->prepare($strsth);
115 while ((my $authtypecode) = $sth->fetchrow) {
116 my ($curauthresults,$nbresults) = authoritysearch($dbh,[''],[''],[''],['contains'],
117 \@search,$startfrom*$resultsperpage, $resultsperpage,$authtypecode);
118 push @authresults, @$curauthresults;
119 $authnbresults+=$nbresults;
120 # warn "auth : $authtypecode nbauthresults : $nbresults";
123 ($template, $loggedinuser, $cookie)
124 = get_template_and_user({template_name => "search.marc/dictionary.tmpl",
127 authnotrequired => 0,
128 flagsrequired => {borrowers => 1},
129 flagsrequired => {catalogue => 1},
133 # multi page display gestion
135 my $displayprev=$startfrom;
136 if(($total - (($startfrom+1)*($resultsperpage))) > 0 ) {
142 for(my $i = 0 ; $i <= $#tags ; $i++) {
143 push @field_data, { term => "marclist", val=>$tags[$i] };
144 push @field_data, { term => "and_or", val=>$and_or[$i] };
145 push @field_data, { term => "excluding", val=>$excluding[$i] };
146 push @field_data, { term => "operator", val=>$operator[$i] };
147 push @field_data, { term => "value", val=>$value[$i] };
152 if ($total>$resultsperpage) {
153 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 $template->param(result => $results,
175 search => $search[0],
177 authresult => \@authresults,
178 nbresults => $authnbresults,
179 startfrom=> $startfrom,
180 displaynext=> $displaynext,
181 displayprev=> $displayprev,
182 resultsperpage => $resultsperpage,
183 startfromnext => $startfrom+1,
184 startfromprev => $startfrom-1,
185 searchdata=>\@field_data,
190 MARC_ON => C4::Context->preference("marc"),
194 ($template, $loggedinuser, $cookie)
195 = get_template_and_user({template_name => "search.marc/dictionary.tmpl",
198 authnotrequired => 0,
199 flagsrequired => {catalogue => 1},
201 search => $search[0],
204 #warn "type : $type";
207 $template->param(search => $search[0],
212 output_html_with_http_headers $input, $cookie, $template->output;