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 );
80 my $startfrom = $input->param('startfrom');
81 $startfrom = 0 if ( !defined $startfrom );
85 #warn "Starting process";
87 if ( $op eq "do_search" ) {
94 "Select distinct tagfield,tagsubfield from marc_subfield_structure where kohafield = ?"
96 $sth->execute("$field");
97 my ( @tags, @and_or, @operator, @excluding, @value );
99 while ( ( my $tagfield, my $tagsubfield, my $liblibrarian ) =
102 push @tags, $dbh->quote("$tagfield$tagsubfield");
105 $resultsperpage = $input->param('resultsperpage');
106 $resultsperpage = 19 if ( !defined $resultsperpage );
107 my $orderby = $input->param('orderby');
109 findseealso( $dbh, \@tags );
111 my @results, my $total;
113 "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 ";
115 foreach my $tag (@tags) {
116 $listtags .= $tag . ",";
118 $listtags =~ s/,$/)/;
120 . " and marc_word.tagsubfield=concat(marc_subfield_table.tag,marc_subfield_table.subfieldcode) group by subfieldvalue ";
122 # warn "search in biblio : ".$strsth;
123 my $value = uc( $search[0] );
125 $value .= "%" if not( $value =~ m/%/ );
127 # warn " texte : ".$value;
129 $sth = $dbh->prepare($strsth);
130 $sth->execute($value);
132 while ( my ( $value, $ctresults ) = $sth->fetchrow ) {
134 # warn "countresults : ".$ctresults;
138 even => ( $total - $startfrom * $resultsperpage ) % 2,
141 if ( ( $total >= $startfrom * $resultsperpage )
142 and ( $total < ( $startfrom + 1 ) * $resultsperpage ) );
147 "Select distinct authtypecode from marc_subfield_structure where (";
148 foreach my $listtags (@tags) {
149 my @taglist = split /,/, $listtags;
150 foreach my $curtag (@taglist) {
153 . substr( $curtag, 1, 3 )
154 . "' AND tagsubfield='"
155 . substr( $curtag, 4, 1 ) . "') OR";
159 $strsth =~ s/ OR$/)/;
160 $strsth = $strsth . " and authtypecode is not NULL";
163 $sth = $dbh->prepare($strsth);
167 # searching in authorities
171 while ( ( my $authtypecode ) = $sth->fetchrow ) {
172 my ( $curauthresults, $nbresults ) =
173 authoritysearch( $dbh, [''], [''], [''], ['contains'], \@search,
174 $startfrom * $resultsperpage,
175 $resultsperpage, $authtypecode );
176 push @authresults, @$curauthresults;
177 $authnbresults += $nbresults;
179 # warn "auth : $authtypecode nbauthresults : $nbresults";
183 # OK, filling the template with authorities & biblio entries found.
185 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
187 template_name => "opac-dictionary.tmpl",
190 authnotrequired => 1,
195 # multi page display gestion
197 my $displayprev = $startfrom;
198 if ( ( $total - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) {
204 for ( my $i = 0 ; $i <= $#tags ; $i++ ) {
205 push @field_data, { term => "marclist", val => $tags[$i] };
206 push @field_data, { term => "and_or", val => $and_or[$i] };
207 push @field_data, { term => "excluding", val => $excluding[$i] };
208 push @field_data, { term => "operator", val => $operator[$i] };
209 push @field_data, { term => "value", val => $value[$i] };
214 if ( $total > $resultsperpage ) {
215 for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
218 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
222 highlight => $highlight,
223 searchdata => \@field_data,
224 startfrom => ( $i - 1 )
230 my $from = $startfrom * $resultsperpage + 1;
233 if ( $total < ( ( $startfrom + 1 ) * $resultsperpage ) ) {
237 $to = ( ( $startfrom + 1 ) * $resultsperpage );
240 anindex => $input->param('index'),
241 opaclayoutstylesheet => C4::Context->preference("opaclayoutstylesheet"),
242 opaccolorstylesheet => C4::Context->preference("opaccolorstylesheet"),
246 catresult => \@catresults,
247 search => $search[0],
249 authresult => \@authresults,
250 nbresults => $authnbresults,
251 startfrom => $startfrom,
252 displaynext => $displaynext,
253 displayprev => $displayprev,
254 resultsperpage => $resultsperpage,
255 startfromnext => $startfrom + 1,
256 startfromprev => $startfrom - 1,
257 searchdata => \@field_data,
261 numbers => \@numbers,
262 MARC_ON => C4::Context->preference("marc"),
267 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
269 template_name => "opac-dictionary.tmpl",
272 authnotrequired => 1,
277 #warn "type : $type";
281 search => $search[0],
284 anindex => $input->param('index')
288 output_html_with_http_headers $input, $cookie, $template->output;