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
25 use C4
::AuthoritiesMarc
;
32 dictionnary.pl : script to search in biblio & authority an existing value
36 useful when the user want to search a term before running a query. For example, to see if "computer" is used in the database
38 The parameter "marclist" tells which field is searched (title, author, subject, but could be anything else)
40 This script searches in both biblios & authority
41 * 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)
42 * in authority, the script search everywhere. Thus, the accepted & rejected forms are found.
44 The script shows all results & the user can choose what he want, that is copied into search form.
49 my $field = $input->param('marclist');
51 #warn "field :$field";
52 my ( $tablename, $kohafield ) = split /./, $field;
54 #my $tablename=$input->param('tablename');
55 $tablename = "biblio" unless ($tablename);
57 #my $kohafield = $input->param('kohafield');
58 my @search = $input->param('search');
60 # warn " ".$search[0];
61 my $index = $input->param('index');
63 # warn " index: ".$index;
64 my $op = $input->param('op');
65 if ( ( $search[0] ) and not( $op eq 'do_search' ) ) {
68 my $script_name = 'opac-dictionary.pl';
70 my $type = $input->param('type');
74 my $dbh = C4
::Context
->dbh;
75 my ( $template, $loggedinuser, $cookie );
77 my $startfrom = $input->param('startfrom');
78 $startfrom = 0 if ( !defined $startfrom );
82 #warn "Starting process";
84 if ( $op eq "do_search" ) {
91 "Select distinct tagfield,tagsubfield from marc_subfield_structure where kohafield = ?"
93 $sth->execute("$field");
94 my ( @tags, @and_or, @operator, @excluding, @value );
96 while ( ( my $tagfield, my $tagsubfield, my $liblibrarian ) =
99 push @tags, $dbh->quote("$tagfield$tagsubfield");
102 $resultsperpage = $input->param('resultsperpage');
103 $resultsperpage = 19 if ( !defined $resultsperpage );
104 my $orderby = $input->param('orderby');
106 findseealso
( $dbh, \
@tags );
108 my @results, my $total;
110 "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 ";
112 foreach my $tag (@tags) {
113 $listtags .= $tag . ",";
115 $listtags =~ s/,$/)/;
117 . " and marc_word.tagsubfield=concat(marc_subfield_table.tag,marc_subfield_table.subfieldcode) group by subfieldvalue ";
119 # warn "search in biblio : ".$strsth;
120 my $value = uc( $search[0] );
122 $value .= "%" if not( $value =~ m/%/ );
124 # warn " texte : ".$value;
126 $sth = $dbh->prepare($strsth);
127 $sth->execute($value);
129 while ( my ( $value, $ctresults ) = $sth->fetchrow ) {
131 # warn "countresults : ".$ctresults;
135 even
=> ( $total - $startfrom * $resultsperpage ) % 2,
138 if ( ( $total >= $startfrom * $resultsperpage )
139 and ( $total < ( $startfrom + 1 ) * $resultsperpage ) );
144 "Select distinct authtypecode from marc_subfield_structure where (";
145 foreach my $listtags (@tags) {
146 my @taglist = split /,/, $listtags;
147 foreach my $curtag (@taglist) {
150 . substr( $curtag, 1, 3 )
151 . "' AND tagsubfield='"
152 . substr( $curtag, 4, 1 ) . "') OR";
156 $strsth =~ s/ OR$/)/;
157 $strsth = $strsth . " and authtypecode is not NULL";
160 $sth = $dbh->prepare($strsth);
164 # searching in authorities
168 while ( ( my $authtypecode ) = $sth->fetchrow ) {
169 my ( $curauthresults, $nbresults ) =
170 authoritysearch
( $dbh, [''], [''], [''], ['contains'], \
@search,
171 $startfrom * $resultsperpage,
172 $resultsperpage, $authtypecode );
173 push @authresults, @
$curauthresults;
174 $authnbresults += $nbresults;
176 # warn "auth : $authtypecode nbauthresults : $nbresults";
180 # OK, filling the template with authorities & biblio entries found.
182 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
184 template_name
=> "opac-dictionary.tmpl",
187 authnotrequired
=> 1,
192 # multi page display gestion
194 my $displayprev = $startfrom;
195 if ( ( $total - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) {
201 for ( my $i = 0 ; $i <= $#tags ; $i++ ) {
202 push @field_data, { term
=> "marclist", val
=> $tags[$i] };
203 push @field_data, { term
=> "and_or", val
=> $and_or[$i] };
204 push @field_data, { term
=> "excluding", val
=> $excluding[$i] };
205 push @field_data, { term
=> "operator", val
=> $operator[$i] };
206 push @field_data, { term
=> "value", val
=> $value[$i] };
211 if ( $total > $resultsperpage ) {
212 for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
215 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
219 highlight
=> $highlight,
220 searchdata
=> \
@field_data,
221 startfrom
=> ( $i - 1 )
227 my $from = $startfrom * $resultsperpage + 1;
230 if ( $total < ( ( $startfrom + 1 ) * $resultsperpage ) ) {
234 $to = ( ( $startfrom + 1 ) * $resultsperpage );
237 anindex
=> $input->param('index'),
238 opaclayoutstylesheet
=> C4
::Context
->preference("opaclayoutstylesheet"),
239 opaccolorstylesheet
=> C4
::Context
->preference("opaccolorstylesheet"),
243 catresult
=> \
@catresults,
244 search
=> $search[0],
246 authresult
=> \
@authresults,
247 nbresults
=> $authnbresults,
248 startfrom
=> $startfrom,
249 displaynext
=> $displaynext,
250 displayprev
=> $displayprev,
251 resultsperpage
=> $resultsperpage,
252 startfromnext
=> $startfrom + 1,
253 startfromprev
=> $startfrom - 1,
254 searchdata
=> \
@field_data,
258 numbers
=> \
@numbers,
259 MARC_ON
=> C4
::Context
->preference("marc"),
264 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
266 template_name
=> "opac-dictionary.tmpl",
269 authnotrequired
=> 1,
274 #warn "type : $type";
278 search
=> $search[0],
281 anindex
=> $input->param('index')
285 output_html_with_http_headers
$input, $cookie, $template->output;