From c196693358c7071c54d9336cf7890cacb51f76ea Mon Sep 17 00:00:00 2001
From: tipaul
Date: Fri, 14 Nov 2003 22:00:42 +0000
Subject: [PATCH] minor fixes in thesaurus_popup & authorities.pm NEW plugin :
the plugin that manages 60X field in UNIMARC (i think it's the same in
marc21). Used to search a thesaurus entry & parse bibliothesaurus table for
category NC (Common Name in french). The user can enter a search term, and
see entries corresponding. If the search is a real entry in the thesaurus,
and this entry has dependencies, they are shown too. For example, if the
thesaurus contains : Geo -- Europe -- France -- Marseille Geo -- Europe --
France -- Paris Hist -- Europe -- France -- Revolution
A search on "France"
shows
Geo --Europe --France and Hist -- Europe -- France on the left panel
When the user clic on Geo -- Europe -- France,
Marseille & Paris are shown on the right panel.
When the user selects a value, it's reported to the MARC editor.
NOTE : template ONLY IN FRENCH (but it's 11PM for instance, & i plan to go to bed :-) )
---
C4/Authorities.pm | 47 ++++++-
.../default/fr/thesaurus_popup.tmpl | 17 ++-
.../fr/value_builder/unimarc_field_60X.tmpl | 109 ++++++++++++++++
thesaurus_popup.pl | 25 +++-
value_builder/unimarc_field_60X.pl | 120 ++++++++++++++++++
5 files changed, 307 insertions(+), 11 deletions(-)
create mode 100644 koha-tmpl/intranet-tmpl/default/fr/value_builder/unimarc_field_60X.tmpl
create mode 100644 value_builder/unimarc_field_60X.pl
diff --git a/C4/Authorities.pm b/C4/Authorities.pm
index 85bbcf4214..eb2eceb08e 100644
--- a/C4/Authorities.pm
+++ b/C4/Authorities.pm
@@ -52,6 +52,7 @@ It contains every functions to manage/find authorities.
&searchauthority
&delauthority
&modauthority
+ &SearchDeeper
);
=item newauthority
@@ -109,6 +110,8 @@ sub newauthority {
my $id;
if ($#Thierarchy >=0) {
# free form
+ $level='' unless $level;
+ $hierarchy='' unless $hierarchy;
$sth1b->execute($freelib,$hierarchy,$category);
($id) = $sth1b->fetchrow;
unless ($id) {
@@ -152,7 +155,7 @@ sub modauthority {
=item SearchAuthority
- $id = &SearchAuthority($dbh,$category,$branch,$searchstring,$type,$offset,$pagesize);
+ ($count, \@array) = &SearchAuthority($dbh,$category,$branch,$searchstring,$type,$offset,$pagesize);
searches for an authority
@@ -165,6 +168,9 @@ entries beginning by 1024|2345
C<$searchstring> contains a string. Only entries beginning by C<$searchstring> are returned
+return :
+C<$count> : the number of authorities found
+C<\@array> : the authorities found. The array contains stdlib,freelib,father,id,hierarchy and level
=cut
sub searchauthority {
@@ -198,6 +204,45 @@ sub searchauthority {
return ($cnt,\@results);
}
+=item SearchDeeper
+
+ @array = &SearchAuthority($dbh,$category,$father);
+
+ Finds everything depending on the parameter.
+
+C<$dbh> is a DBI::db handle for the Koha database.
+
+C<$category> is the category of the authority
+
+C<$father> Is the string "father".
+
+return :
+@array : the authorities found. The array contains stdlib,freelib,father,id,hierarchy and level
+
+For example :
+Geography -- Europe is the father and the result is : France and Germany if there is
+Geography -- Europe -- France and Geography -- Europe -- Germany in the thesaurus
+
+
+=cut
+sub SearchDeeper {
+ my ($category,$father)=@_;
+ my $dbh = C4::Context->dbh;
+ my $query="Select distinct level,stdlib,father from bibliothesaurus where category =? and father =? order by category,stdlib";
+ my $sth=$dbh->prepare($query);
+ $sth->execute($category,"$father --");
+ my @results;
+ while (my ($level,$stdlib,$father)=$sth->fetchrow){
+ my %line;
+ $line{level} = $level;
+ $line{stdlib}= $stdlib;
+ $line{father} = $father;
+ push(@results,\%line);
+ }
+ $sth->finish;
+ return (@results);
+}
+
=item delauthority
diff --git a/koha-tmpl/intranet-tmpl/default/fr/thesaurus_popup.tmpl b/koha-tmpl/intranet-tmpl/default/fr/thesaurus_popup.tmpl
index de8d452a10..26529b8b36 100644
--- a/koha-tmpl/intranet-tmpl/default/fr/thesaurus_popup.tmpl
+++ b/koha-tmpl/intranet-tmpl/default/fr/thesaurus_popup.tmpl
@@ -7,21 +7,30 @@
+
+
+
diff --git a/thesaurus_popup.pl b/thesaurus_popup.pl
index aaf9b1532c..e952d30273 100755
--- a/thesaurus_popup.pl
+++ b/thesaurus_popup.pl
@@ -47,13 +47,13 @@ my $dbh = C4::Context->dbh;
# make the page ...
#print $input->header;
if ($op eq "select") {
- my $sti = $dbh->prepare("select stdlib from bibliothesaurus where id=?");
+ my $sti = $dbh->prepare("select father,stdlib from bibliothesaurus where id=?");
$sti->execute($id);
- my ($freelib_text) = $sti->fetchrow_array;
+ my ($father,$freelib_text) = $sti->fetchrow_array;
if (length($result)>0) {
- $result .= "|$freelib_text";
+ $result .= "|$father $freelib_text";
} else {
- $result = $freelib_text;
+ $result = "$father $freelib_text";
}
}
if ($op eq "add") {
@@ -74,10 +74,10 @@ my %stdlib;
my $select_list;
if ($search_string) {
# my $sti=$dbh->prepare("select id,freelib from bibliothesaurus where freelib like '".$search_string."%' and category ='$category'");
- my $sti=$dbh->prepare("select id,freelib from bibliothesaurus where match (category,freelib) AGAINST (?) and category ='$category'");
+ my $sti=$dbh->prepare("select id,freelib,father from bibliothesaurus where match (category,freelib) AGAINST (?) and category ='$category'");
$sti->execute($search_string);
while (my $line=$sti->fetchrow_hashref) {
- $stdlib{$line->{'id'}} = "$line->{'freelib'}";
+ $stdlib{$line->{'id'}} = "$line->{'father'} $line->{'freelib'}";
push(@freelib,$line->{'id'});
}
$select_list= CGI::scrolling_list( -name=>'id',
@@ -88,8 +88,21 @@ if ($search_string) {
-labels=> \%stdlib
);
}
+my $x = SearchDeeper('',$category,$search_string);
+#my @son;
+#foreach (my $value @$x) {
+# warn \@$x[$value]->{'stdlib'};
+#}
+my $dig_list= CGI::scrolling_list( -name=>'search_string',
+ -values=> \@$x,
+ -default=> "",
+ -size=>1,
+ -multiple=>0,
+ );
+
$template->param(select_list => $select_list,
search_string => $search_string,
+ dig_list => $dig_list,
result => $result,
category => $category,
index => $index
diff --git a/value_builder/unimarc_field_60X.pl b/value_builder/unimarc_field_60X.pl
new file mode 100644
index 0000000000..b539a6f256
--- /dev/null
+++ b/value_builder/unimarc_field_60X.pl
@@ -0,0 +1,120 @@
+#!/usr/bin/perl
+
+# $Id$
+
+# Copyright 2000-2002 Katipo Communications
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA 02111-1307 USA
+
+use strict;
+use C4::Auth;
+use CGI;
+use C4::Context;
+use HTML::Template;
+use C4::Search;
+use C4::Output;
+use C4::Authorities;
+
+sub plugin_javascript {
+my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
+my $function_name= "100".(int(rand(100000))+1);
+my $res="
+
+";
+
+return ($function_name,$res);
+}
+sub plugin {
+ my ($input) = @_;
+ my %env;
+ my $dbh = C4::Context->dbh;
+ my $index= $input->param('index');
+ my $result= $input->param('result');
+ warn "RES : $result";
+ my $search_string= $input->param('search_string');
+ my $op = $input->param('op');
+ my $id = $input->param('id');
+ my $insert = $input->param('insert');
+ my %stdlib;
+ my $select_list;
+ if ($op eq "add") {
+ newauthority($dbh,'NC',$insert,$insert,'',1,'');
+ $search_string=$insert;
+ }
+ if ($op eq "select") {
+ my $sti = $dbh->prepare("select stdlib from bibliothesaurus where id=?");
+ $sti->execute($id);
+ my ($freelib_text) = $sti->fetchrow_array;
+ $result = $freelib_text;
+ }
+ my $Rsearch_string="$search_string%";
+ my $authoritysep = C4::Context->preference('authoritysep');
+ my @splitted = /$authoritysep/,$search_string;
+ my $level = $#splitted+1;
+ my $query;
+ if ($search_string) { # if no search pattern, returns only the 50 1st top level values
+ $query = "select distinct freelib,father,level from bibliothesaurus where category='NC' and freelib like ? order by father,freelib";
+ } else {
+ $query = "select distinct freelib,father,level from bibliothesaurus where category='NC' and level=0 and freelib like ? order by father,freelib limit 0,50";
+ }
+ my $sti=$dbh->prepare($query);
+ $sti->execute($Rsearch_string);
+ my @results;
+ while (my ($freelib,$father,$level)=$sti->fetchrow) {
+ my %line;
+ if ($father) {
+ $line{value} = "$father $freelib";
+ } else {
+ $line{value} = "$freelib";
+ }
+ $line{level} = $level+1;
+ $line{father} = $father;
+ push @results, \%line;
+ }
+ my @DeeperResults = SearchDeeper('NC',$search_string);
+ my ($template, $loggedinuser, $cookie)
+ = get_template_and_user({template_name => "value_builder/unimarc_field_60X.tmpl",
+ query => $input,
+ type => "intranet",
+ authnotrequired => 0,
+ flagsrequired => {parameters => 1},
+ debug => 1,
+ });
+# builds collection list : search isbn and editor, in parent, then load collections from bibliothesaurus table
+ $template->param(index => $index,
+ result =>$result,
+ search_string => $search_string?$search_string:$result,
+ results => \@results,
+ deeper => \@DeeperResults,
+ );
+ print $input->header(-cookie => $cookie),$template->output;
+}
+
+1;
--
2.39.5