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
22 use C4::Interface::CGI::Output;
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');
52 #warn "field :$field";
53 my ( $tablename, $kohafield ) = split /./, $field;
55 #my $tablename=$input->param('tablename');
56 $tablename = "biblio" unless ($tablename);
58 #my $kohafield = $input->param('kohafield');
59 my @search = $input->param('search');
61 # warn " ".$search[0];
62 my $index = $input->param('index');
64 # warn " index: ".$index;
65 my $op = $input->param('op');
66 if ( ( $search[0] ) and not( $op eq 'do_search' ) ) {
69 my $script_name = 'opac-dictionary.pl';
71 my $type = $input->param('type');
75 my $dbh = C4::Context->dbh;
76 my ( $template, $loggedinuser, $cookie );
78 my $startfrom = $input->param('startfrom');
79 $startfrom = 0 if ( !defined $startfrom );
83 #warn "Starting process";
85 if ( $op eq "do_search" ) {
92 "Select distinct tagfield,tagsubfield from marc_subfield_structure where kohafield = ?"
94 $sth->execute("$field");
95 my ( @tags, @and_or, @operator, @excluding, @value );
97 while ( ( my $tagfield, my $tagsubfield, my $liblibrarian ) =
100 push @tags, $dbh->quote("$tagfield$tagsubfield");
103 $resultsperpage = $input->param('resultsperpage');
104 $resultsperpage = 19 if ( !defined $resultsperpage );
105 my $orderby = $input->param('orderby');
107 findseealso( $dbh, \@tags );
109 my @results, my $total;
111 "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 ";
113 foreach my $tag (@tags) {
114 $listtags .= $tag . ",";
116 $listtags =~ s/,$/)/;
118 . " and marc_word.tagsubfield=concat(marc_subfield_table.tag,marc_subfield_table.subfieldcode) group by subfieldvalue ";
120 # warn "search in biblio : ".$strsth;
121 my $value = uc( $search[0] );
123 $value .= "%" if not( $value =~ m/%/ );
125 # warn " texte : ".$value;
127 $sth = $dbh->prepare($strsth);
128 $sth->execute($value);
130 while ( my ( $value, $ctresults ) = $sth->fetchrow ) {
132 # warn "countresults : ".$ctresults;
136 even => ( $total - $startfrom * $resultsperpage ) % 2,
139 if ( ( $total >= $startfrom * $resultsperpage )
140 and ( $total < ( $startfrom + 1 ) * $resultsperpage ) );
145 "Select distinct authtypecode from marc_subfield_structure where (";
146 foreach my $listtags (@tags) {
147 my @taglist = split /,/, $listtags;
148 foreach my $curtag (@taglist) {
151 . substr( $curtag, 1, 3 )
152 . "' AND tagsubfield='"
153 . substr( $curtag, 4, 1 ) . "') OR";
157 $strsth =~ s/ OR$/)/;
158 $strsth = $strsth . " and authtypecode is not NULL";
161 $sth = $dbh->prepare($strsth);
165 # searching in authorities
169 while ( ( my $authtypecode ) = $sth->fetchrow ) {
170 my ( $curauthresults, $nbresults ) =
171 authoritysearch( $dbh, [''], [''], [''], ['contains'], \@search,
172 $startfrom * $resultsperpage,
173 $resultsperpage, $authtypecode );
174 push @authresults, @$curauthresults;
175 $authnbresults += $nbresults;
177 # warn "auth : $authtypecode nbauthresults : $nbresults";
181 # OK, filling the template with authorities & biblio entries found.
183 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
185 template_name => "opac-dictionary.tmpl",
188 authnotrequired => 1,
193 # multi page display gestion
195 my $displayprev = $startfrom;
196 if ( ( $total - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) {
202 for ( my $i = 0 ; $i <= $#tags ; $i++ ) {
203 push @field_data, { term => "marclist", val => $tags[$i] };
204 push @field_data, { term => "and_or", val => $and_or[$i] };
205 push @field_data, { term => "excluding", val => $excluding[$i] };
206 push @field_data, { term => "operator", val => $operator[$i] };
207 push @field_data, { term => "value", val => $value[$i] };
212 if ( $total > $resultsperpage ) {
213 for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
216 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
220 highlight => $highlight,
221 searchdata => \@field_data,
222 startfrom => ( $i - 1 )
228 my $from = $startfrom * $resultsperpage + 1;
231 if ( $total < ( ( $startfrom + 1 ) * $resultsperpage ) ) {
235 $to = ( ( $startfrom + 1 ) * $resultsperpage );
238 anindex => $input->param('index'),
239 opaclayoutstylesheet => C4::Context->preference("opaclayoutstylesheet"),
240 opaccolorstylesheet => C4::Context->preference("opaccolorstylesheet"),
244 catresult => \@catresults,
245 search => $search[0],
247 authresult => \@authresults,
248 nbresults => $authnbresults,
249 startfrom => $startfrom,
250 displaynext => $displaynext,
251 displayprev => $displayprev,
252 resultsperpage => $resultsperpage,
253 startfromnext => $startfrom + 1,
254 startfromprev => $startfrom - 1,
255 searchdata => \@field_data,
259 numbers => \@numbers,
260 MARC_ON => C4::Context->preference("marc"),
265 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
267 template_name => "opac-dictionary.tmpl",
270 authnotrequired => 1,
275 #warn "type : $type";
279 search => $search[0],
282 anindex => $input->param('index')
286 output_html_with_http_headers $input, $cookie, $template->output;