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;
27 use C4::AuthoritiesMarc;
34 dictionnary.pl : script to search in biblio & authority an existing value
38 useful when the user want to search a term before running a query. For example, to see if "computer" is used in the database
40 The parameter "marclist" tells which field is searched (title, author, subject, but could be anything else)
42 This script searches in both biblios & authority
43 * 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)
44 * in authority, the script search everywhere. Thus, the accepted & rejected forms are found.
46 The script shows all results & the user can choose what he want, that is copied into search form.
51 my $field =$input->param('marclist');
52 #warn "field :$field";
53 my ($tablename, $kohafield)=split /./,$field;
54 #my $tablename=$input->param('tablename');
55 $tablename="biblio" unless ($tablename);
56 #my $kohafield = $input->param('kohafield');
57 my @search = $input->param('search');
58 # warn " ".$search[0];
59 my $index = $input->param('index');
60 # warn " index: ".$index;
61 my $op=$input->param('op');
62 if (($search[0]) and not ($op eq 'do_search')){
65 my $script_name = 'catalogue/dictionary.pl';
67 my $type=$input->param('type');
70 my $dbh = C4::Context->dbh;
71 my ($template, $loggedinuser, $cookie);
75 my $startfrom=$input->param('startfrom');
76 $startfrom=0 if(!defined $startfrom);
80 #warn "Starting process";
82 if ($op eq "do_search") {
86 my $sth=$dbh->prepare("Select distinct tagfield,tagsubfield from marc_subfield_structure where kohafield = ?");
87 $sth->execute("$field");
88 my (@tags, @and_or, @operator, @excluding,@value);
90 while ((my $tagfield,my $tagsubfield,my $liblibrarian) = $sth->fetchrow) {
91 push @tags, $dbh->quote("$tagfield$tagsubfield");
94 $resultsperpage= $input->param('resultsperpage');
95 $resultsperpage = 19 if(!defined $resultsperpage);
96 my $orderby = $input->param('orderby');
98 findseealso($dbh,\@tags);
100 my @results, my $total;
101 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 ";
103 foreach my $tag (@tags){
104 $listtags .= $tag .",";
107 $strsth .= $listtags." and marc_word.tagsubfield=concat(marc_subfield_table.tag,marc_subfield_table.subfieldcode) group by subfieldvalue ";
108 # warn "search in biblio : ".$strsth;
109 my $value = uc($search[0]);
111 $value.= "%" if not($value=~m/%/);
112 # warn " texte : ".$value;
114 $sth=$dbh->prepare($strsth);
115 $sth->execute($value);
119 while (my ($value,$ctresults)=$sth->fetchrow) {
120 # This $javalue is used for the javascript selectentry function (javalue for javascript value !)
122 $javalue =~s/'/\\'/g;
124 push @catresults,{value=> $value,
126 even=>($total-$startfrom*$resultsperpage)%2,
128 } if (($total>=$startfrom*$resultsperpage) and ($total<($startfrom+1)*$resultsperpage));
133 my $strsth="Select distinct authtypecode from marc_subfield_structure where (";
134 foreach my $listtags (@tags){
135 my @taglist=split /,/,$listtags;
136 foreach my $curtag (@taglist){
138 $strsth.="(tagfield='".substr($curtag,1,3)."' AND tagsubfield='".substr($curtag,4,1)."') OR";
143 my $strsth = $strsth." and authtypecode is not NULL";
145 my $sth=$dbh->prepare($strsth);
149 # searching in authorities
153 while ((my $authtypecode) = $sth->fetchrow) {
154 my ($curauthresults,$nbresults) = authoritysearch($dbh,[''],[''],[''],['contains'],
155 \@search,$startfrom*$resultsperpage, $resultsperpage,$authtypecode);
156 if (defined(@$curauthresults)) {
157 for (my $i = 0; $i < @$curauthresults ;$i++) {
158 @$curauthresults[$i]->{jamainentry} = @$curauthresults[$i]->{mainentry};
159 @$curauthresults[$i]->{jamainentry} =~ s/'/\\'/g;
162 push @authresults, @$curauthresults;
163 $authnbresults+=$nbresults;
164 # warn "auth : $authtypecode nbauthresults : $nbresults";
168 # OK, filling the template with authorities & biblio entries found.
170 ($template, $loggedinuser, $cookie)
171 = get_template_and_user({template_name => "catalogue/dictionary.tmpl",
174 authnotrequired => 0,
175 flagsrequired => {catalogue => 1},
179 # multi page display gestion
181 my $displayprev=$startfrom;
182 if(($total - (($startfrom+1)*($resultsperpage))) > 0 ) {
188 for(my $i = 0 ; $i <= $#tags ; $i++) {
189 push @field_data, { term => "marclist", val=>$tags[$i] };
190 push @field_data, { term => "and_or", val=>$and_or[$i] };
191 push @field_data, { term => "excluding", val=>$excluding[$i] };
192 push @field_data, { term => "operator", val=>$operator[$i] };
193 push @field_data, { term => "value", val=>$value[$i] };
198 if ($total>$resultsperpage) {
199 for (my $i=1; $i<$total/$resultsperpage+1; $i++) {
202 ($startfrom==($i-1)) && ($highlight=1);
203 push @numbers, { number => $i,
204 highlight => $highlight ,
205 searchdata=> \@field_data,
206 startfrom => ($i-1)};
211 my $from = $startfrom*$resultsperpage+1;
214 if($total < (($startfrom+1)*$resultsperpage))
218 $to = (($startfrom+1)*$resultsperpage);
220 $template->param(anindex => $input->param('index'));
221 $template->param(result => \@results,
222 catresult=> \@catresults,
223 search => $search[0],
225 authresult => \@authresults,
226 nbresults => $authnbresults,
227 startfrom=> $startfrom,
228 displaynext=> $displaynext,
229 displayprev=> $displayprev,
230 resultsperpage => $resultsperpage,
231 startfromnext => $startfrom+1,
232 startfromprev => $startfrom-1,
233 searchdata=>\@field_data,
238 MARC_ON => C4::Context->preference("marc"),
242 ($template, $loggedinuser, $cookie)
243 = get_template_and_user({template_name => "catalogue/dictionary.tmpl",
246 authnotrequired => 0,
247 flagsrequired => {catalogue => 1},
250 #warn "type : $type";
253 $template->param(search => $search[0],
256 anindex => $input->param('index'),
257 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
258 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
259 IntranetNav => C4::Context->preference("IntranetNav"),
263 output_html_with_http_headers $input, $cookie, $template->output;