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
26 use C4
::AuthoritiesMarc
;
33 dictionnary.pl : script to search in biblio & authority an existing value
37 useful when the user want to search a term before running a query. For example, to see if "computer" is used in the database
39 The parameter "marclist" tells which field is searched (title, author, subject, but could be anything else)
41 This script searches in both biblios & authority
42 * in biblio, the script search in all marc fields related to what the user is looking for (for example, if the dictionnary is used on "author", the script searches in biblio.author, but also in additional authors & any MARC field related to author (through the "seealso" MARC constraint)
43 * in authority, the script search everywhere. Thus, the accepted & rejected forms are found.
45 The script shows all results & the user can choose what he want, that is copied into search form.
50 my $field =$input->param('marclist');
51 #warn "field :$field";
52 my ($tablename, $kohafield)=split /./,$field;
53 #my $tablename=$input->param('tablename');
54 $tablename="biblio" unless ($tablename);
55 #my $kohafield = $input->param('kohafield');
56 my @search = $input->param('search');
57 # warn " ".$search[0];
58 my $index = $input->param('index');
59 # warn " index: ".$index;
60 my $op=$input->param('op');
61 if (($search[0]) and not ($op eq 'do_search')){
64 my $script_name = 'catalogue/dictionary.pl';
66 my $type=$input->param('type');
69 my $dbh = C4
::Context
->dbh;
70 my ($template, $loggedinuser, $cookie);
72 my $startfrom=$input->param('startfrom');
73 $startfrom=0 if(!defined $startfrom);
77 #warn "Starting process";
79 if ($op eq "do_search") {
83 my $sth=$dbh->prepare("Select distinct tagfield,tagsubfield from marc_subfield_structure where kohafield = ?");
84 $sth->execute("$field");
85 my (@tags, @and_or, @operator, @excluding,@value);
87 while ((my $tagfield,my $tagsubfield,my $liblibrarian) = $sth->fetchrow) {
88 push @tags, $dbh->quote("$tagfield$tagsubfield");
91 $resultsperpage= $input->param('resultsperpage');
92 $resultsperpage = 19 if(!defined $resultsperpage);
93 my $orderby = $input->param('orderby');
95 findseealso
($dbh,\
@tags);
97 my @results, my $total;
98 my $strsth="select distinct subfieldvalue, count(marc_subfield_table.bibid) from marc_subfield_table,marc_word where marc_word.word like ? and marc_subfield_table.bibid=marc_word.bibid and marc_subfield_table.tagorder=marc_word.tagorder and marc_word.tagsubfield in ";
100 foreach my $tag (@tags){
101 $listtags .= $tag .",";
104 $strsth .= $listtags." and marc_word.tagsubfield=concat(marc_subfield_table.tag,marc_subfield_table.subfieldcode) group by subfieldvalue ";
105 # warn "search in biblio : ".$strsth;
106 my $value = uc($search[0]);
108 $value.= "%" if not($value=~m/%/);
109 # warn " texte : ".$value;
111 $sth=$dbh->prepare($strsth);
112 $sth->execute($value);
116 while (my ($value,$ctresults)=$sth->fetchrow) {
117 # This $javalue is used for the javascript selectentry function (javalue for javascript value !)
119 $javalue =~s/'/\\'/g;
121 push @catresults,{value
=> $value,
123 even
=>($total-$startfrom*$resultsperpage)%2,
125 } if (($total>=$startfrom*$resultsperpage) and ($total<($startfrom+1)*$resultsperpage));
130 $strsth="Select distinct authtypecode from marc_subfield_structure where (";
131 foreach my $listtags (@tags){
132 my @taglist=split /,/,$listtags;
133 foreach my $curtag (@taglist){
135 $strsth.="(tagfield='".substr($curtag,1,3)."' AND tagsubfield='".substr($curtag,4,1)."') OR";
140 $strsth .= " and authtypecode is not NULL";
142 $sth=$dbh->prepare($strsth);
146 # searching in authorities
150 while ((my $authtypecode) = $sth->fetchrow) {
151 my ($curauthresults,$nbresults) = SearchAuthorities
([''],[''],[''],['contains'],
152 \
@search,$startfrom*$resultsperpage, $resultsperpage,$authtypecode);
153 if (defined(@
$curauthresults)) {
154 for (my $i = 0; $i < @
$curauthresults ;$i++) {
155 @
$curauthresults[$i]->{jamainentry
} = @
$curauthresults[$i]->{mainentry
};
156 @
$curauthresults[$i]->{jamainentry
} =~ s/'/\\'/g;
159 push @authresults, @
$curauthresults;
160 $authnbresults+=$nbresults;
161 # warn "auth : $authtypecode nbauthresults : $nbresults";
165 # OK, filling the template with authorities & biblio entries found.
167 ($template, $loggedinuser, $cookie)
168 = get_template_and_user
({template_name
=> "catalogue/dictionary.tmpl",
171 authnotrequired
=> 0,
172 flagsrequired
=> {catalogue
=> 1},
176 # multi page display gestion
178 my $displayprev=$startfrom;
179 if(($total - (($startfrom+1)*($resultsperpage))) > 0 ) {
185 for(my $i = 0 ; $i <= $#tags ; $i++) {
186 push @field_data, { term
=> "marclist", val
=>$tags[$i] };
187 push @field_data, { term
=> "and_or", val
=>$and_or[$i] };
188 push @field_data, { term
=> "excluding", val
=>$excluding[$i] };
189 push @field_data, { term
=> "operator", val
=>$operator[$i] };
190 push @field_data, { term
=> "value", val
=>$value[$i] };
195 if ($total>$resultsperpage) {
196 for (my $i=1; $i<$total/$resultsperpage+1; $i++) {
199 ($startfrom==($i-1)) && ($highlight=1);
200 push @numbers, { number
=> $i,
201 highlight
=> $highlight ,
202 searchdata
=> \
@field_data,
203 startfrom
=> ($i-1)};
208 my $from = $startfrom*$resultsperpage+1;
211 if($total < (($startfrom+1)*$resultsperpage))
215 $to = (($startfrom+1)*$resultsperpage);
217 $template->param(anindex
=> $input->param('index'));
218 $template->param(result
=> \
@results,
219 catresult
=> \
@catresults,
220 search
=> $search[0],
222 authresult
=> \
@authresults,
223 nbresults
=> $authnbresults,
224 startfrom
=> $startfrom,
225 displaynext
=> $displaynext,
226 displayprev
=> $displayprev,
227 resultsperpage
=> $resultsperpage,
228 startfromnext
=> $startfrom+1,
229 startfromprev
=> $startfrom-1,
230 searchdata
=>\
@field_data,
235 MARC_ON
=> C4
::Context
->preference("marc"),
239 ($template, $loggedinuser, $cookie)
240 = get_template_and_user
({template_name
=> "catalogue/dictionary.tmpl",
243 authnotrequired
=> 0,
244 flagsrequired
=> {catalogue
=> 1},
247 #warn "type : $type";
250 $template->param(search
=> $search[0],
253 anindex
=> $input->param('index'),
257 output_html_with_http_headers
$input, $cookie, $template->output;