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 :-) )
&searchauthority
&delauthority
&modauthority
+ &SearchDeeper
);
=item newauthority
my $id;
if ($#Thierarchy >=0) {
# free form
+ $level='' unless $level;
+ $hierarchy='' unless $hierarchy;
$sth1b->execute($freelib,$hierarchy,$category);
($id) = $sth1b->fetchrow;
unless ($id) {
=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
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 {
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
<textarea name="result" rows=10 cols=50><TMPL_VAR name="result"></textarea>
<br/><input type="button" value="OK" onClick="javascript:report()">
<p>
- <input type="text" name="search_string" value="<TMPL_VAR name="search_string">">
+ Rechercher : <input type="text" name="search_string" value="<TMPL_VAR name="search_string">">
<input type="hidden" name="category" value="<TMPL_VAR name="category">">
<input type="hidden" name="index" value="<TMPL_VAR name="index">">
<input type="hidden" name="op" value="search">
- <input type="submit" value="Rechercher">
+ <input type="submit" value="OK">
</p>
</form>
+ <form name="f2_pop" action="thesaurus_popup.pl" method="post">
+ Descendre : <TMPL_VAR name="dig_list">
+ <input type="hidden" name="category" value="<TMPL_VAR name="category">">
+ <input type="hidden" name="index" value="<TMPL_VAR name="index">">
+ <input type="hidden" name="op" value="select">
+ <input type="hidden" name="result" value="<TMPL_VAR name="result">">
+ <input type="submit" name="OK" value="OK">
+ </form>
+
<TMPL_IF name="search_string">
<form name="f2_pop" action="thesaurus_popup.pl" method="post">
- <TMPL_VAR name="select_list">
+ Sélectionner : <TMPL_VAR name="select_list">
<input type="hidden" name="category" value="<TMPL_VAR name="category">">
<input type="hidden" name="index" value="<TMPL_VAR name="index">">
<input type="hidden" name="op" value="select">
<input type="hidden" name="result" value="<TMPL_VAR name="result">">
- <input type="submit" name="OK" value="Sélectionner">
+ <input type="submit" name="OK" value="OK">
</form>
</TMPL_IF>
<form name="f3_pop" action="thesaurus_popup.pl" method="post">
--- /dev/null
+<html>
+<head>
+ <title>Recherche Thésaurus</title>
+</head>
+<body>
+ <script>
+ function report(value2report) {
+ if (document.f_pop.result.value.length==0) {
+ document.f_pop.result.value = value2report;
+ } else {
+ document.f_pop.result.value = document.f_pop.result.value+'|'+value2report;
+ }
+ return true;
+ }
+ </script>
+ <script>
+ function finish() {
+ opener.document.f.field_value[<TMPL_VAR name="index">].value= document.f_pop.result.value;
+ self.close();
+ return false;
+ }
+ </script>
+ <form name="f_pop" action="plugin_launcher.pl" method="post">
+ <input type="hidden" name="plugin_name" value="unimarc_field_60X.pl">
+ <textarea name="result" rows=10 cols=50><TMPL_VAR name="result"></textarea>
+ <br/><input type="button" value="OK" onClick="javascript:finish()">
+ <p><h2>Recherche</h2>
+ <a href="plugin_launcher.pl?plugin_name=unimarc_field_60X.pl&search_string=A">A</a>
+ <a href="plugin_launcher.pl?plugin_name=unimarc_field_60X.pl&search_string=B">B</a>
+ <a href="plugin_launcher.pl?plugin_name=unimarc_field_60X.pl&search_string=C">C</a>
+ <a href="plugin_launcher.pl?plugin_name=unimarc_field_60X.pl&search_string=D">D</a>
+ <a href="plugin_launcher.pl?plugin_name=unimarc_field_60X.pl&search_string=E">E</a>
+ <a href="plugin_launcher.pl?plugin_name=unimarc_field_60X.pl&search_string=F">F</a>
+ <a href="plugin_launcher.pl?plugin_name=unimarc_field_60X.pl&search_string=G">G</a>
+ <a href="plugin_launcher.pl?plugin_name=unimarc_field_60X.pl&search_string=H">H</a>
+ <a href="plugin_launcher.pl?plugin_name=unimarc_field_60X.pl&search_string=I">I</a>
+ <a href="plugin_launcher.pl?plugin_name=unimarc_field_60X.pl&search_string=J">J</a>
+ <a href="plugin_launcher.pl?plugin_name=unimarc_field_60X.pl&search_string=K">K</a>
+ <a href="plugin_launcher.pl?plugin_name=unimarc_field_60X.pl&search_string=L">L</a>
+ <a href="plugin_launcher.pl?plugin_name=unimarc_field_60X.pl&search_string=M">M</a>
+ <a href="plugin_launcher.pl?plugin_name=unimarc_field_60X.pl&search_string=N">N</a>
+ <a href="plugin_launcher.pl?plugin_name=unimarc_field_60X.pl&search_string=O">O</a>
+ <a href="plugin_launcher.pl?plugin_name=unimarc_field_60X.pl&search_string=P">P</a>
+ <a href="plugin_launcher.pl?plugin_name=unimarc_field_60X.pl&search_string=Q">Q</a>
+ <a href="plugin_launcher.pl?plugin_name=unimarc_field_60X.pl&search_string=R">R</a>
+ <a href="plugin_launcher.pl?plugin_name=unimarc_field_60X.pl&search_string=S">S</a>
+ <a href="plugin_launcher.pl?plugin_name=unimarc_field_60X.pl&search_string=T">T</a>
+ <a href="plugin_launcher.pl?plugin_name=unimarc_field_60X.pl&search_string=U">U</a>
+ <a href="plugin_launcher.pl?plugin_name=unimarc_field_60X.pl&search_string=V">V</a>
+ <a href="plugin_launcher.pl?plugin_name=unimarc_field_60X.pl&search_string=W">W</a>
+ <a href="plugin_launcher.pl?plugin_name=unimarc_field_60X.pl&search_string=X">X</a>
+ <a href="plugin_launcher.pl?plugin_name=unimarc_field_60X.pl&search_string=Y">Y</a>
+ <a href="plugin_launcher.pl?plugin_name=unimarc_field_60X.pl&search_string=Z">Z</a>
+ <br/>
+ <input type="text" name="search_string" value="<TMPL_VAR name="search_string">">
+ <input type="hidden" name="category" value="<TMPL_VAR name="category">">
+ <input type="hidden" name="index" value="<TMPL_VAR name="index">">
+ <input type="hidden" name="op" value="search">
+ <input type="submit" value="Chercher">
+ </p>
+ </form>
+ <table>
+ <tr>
+ <td valign="top">
+ <h2>Résultats</h2>
+ <table>
+ <TMPL_LOOP name="results">
+ <tr>
+ <td>
+ <a href="plugin_launcher.pl?plugin_name=unimarc_field_60X.pl&level=<TMPL_VAR name="level">&search_string=<TMPL_VAR name=value ESCAPE=URL>">
+ <TMPL_VAR name="value">
+ </a>
+ </td>
+ <td>
+ <input type="button" value="Reporter" OnClick="javascript:report('<TMPL_VAR name="value">')"><br/>
+ </td>
+ </tr>
+ </TMPL_LOOP>
+ </table>
+ </td>
+ <td>
+ <TMPL_IF name=deeper>
+ <td valign="top">
+ <h2>Dépendances</h2>
+ </TMPL_IF>
+ <table>
+ <TMPL_LOOP name="deeper">
+ <tr><td>
+ <a href="plugin_launcher.pl?plugin_name=unimarc_field_60X.pl&level=<TMPL_VAR name="level">&search_string=<TMPL_VAR ESCAPE="URL" name="father">+<TMPL_VAR ESCAPE="URL" name="stdlib">">
+ <TMPL_VAR name="father"> <TMPL_VAR name="stdlib">
+ </a></td>
+ <td>
+ <input type="button" value="Reporter" OnClick="javascript:report('<TMPL_VAR ESCAPE=HTML name="father"> <TMPL_VAR ESCAPE=HTML name="stdlib">')"><br/>
+ </td></tr>
+ </TMPL_LOOP>
+ </table>
+ </td>
+ </tr>
+ </table>
+<h2>Création</h2>
+<form name="f3_pop" action="thesaurus_popup.pl" method="post">
+ <input type="hidden" name="index" value="<TMPL_VAR name="index">">
+ <input type="hidden" name="op" value="add">
+ <input type="hidden" name="category" value="<TMPL_VAR name="category">">
+ Insérer une nouvelle autorité : <input type="text" name="insert" value="<TMPL_VAR name="search_string">">
+ <input type="submit" name="NEW" value="Ajouter">
+ </form>
+</body>
+</html>
# 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") {
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',
-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
--- /dev/null
+#!/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="
+<script>
+function Focus$function_name(subfield_managed) {
+return 1;
+}
+
+function Blur$function_name(subfield_managed) {
+ return 1;
+}
+
+function Clic$function_name(index) {
+ defaultvalue=document.f.field_value[index].value;
+ newin=window.open(\"../plugin_launcher.pl?plugin_name=unimarc_field_60X.pl&index=\"+index+\"&result=\"+defaultvalue,\"unimarc 700\",'width=700,height=300,toolbar=false,scrollbars=yes');
+
+}
+</script>
+";
+
+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;