First, run updater/thesaurus_create.pl.
authortipaul <tipaul>
Tue, 14 May 2002 11:26:09 +0000 (11:26 +0000)
committertipaul <tipaul>
Tue, 14 May 2002 11:26:09 +0000 (11:26 +0000)
It creates a thesaurus table and fills it with data in bibliosubject. Thesaurus
contains 2 columns : freelib and stdlib. This permits connecting differents forms for a word/sentence (HUGO may be mapped to V. Hugo, Victor Hugo...)
In modbib.pl, you will see "..." near subject. If you   click on this ..., a popup appear. It has 4 parts : the Subject field, a search field with Search button. If you enter a value here and click Search, a list of thesaurus entries starting by what you enter appear.
If you select a value and click "OK", the value is added to the subject list.
When you've finished, click END. the window is closed, and the value copied to main subject window.

Make heavy use of javascript. TESTED UNDER MOZILLA 0.99. Please test under IE.

Administration of thesaurus table will come soon (with html::template) ...

modbib.pl
thesaurus_popup.pl [new file with mode: 0755]
updater/thesaurus_create.pl [new file with mode: 0755]

index 1baf558..4f88819 100755 (executable)
--- a/modbib.pl
+++ b/modbib.pl
@@ -63,7 +63,7 @@ $data->{'title'} = &tidyhtml($data->{'title'});
 
 print << "EOF";
 <a href="modwebsites.pl?biblionumber=$data->{'biblionumber'}">Modify Website Links</a>
-<form action="updatebiblio.pl" method="post">
+<form action="updatebiblio.pl" method="post" name="f">
 <input type="hidden" name="biblionumber" value="$data->{'biblionumber'}">
 <input type="hidden" name="biblioitemnumber" value="$data=>{'biblioitemnumber'}">
 <table border="0" cellspacing="0" cellpadding="5">
@@ -81,7 +81,9 @@ print << "EOF";
 </tr>
 <tr valign="top">
 <td>Subject</td>
-<td><textarea name="subject" cols="40" rows="4">$sub</textarea></td>
+<td><textarea name="subject" cols="40" rows="4">$sub</textarea>
+<a href="javascript:Dopop()">...</a>
+</td>
 </tr>
 <tr valign="top">
 <td>Copyright Date</td>
@@ -123,6 +125,11 @@ print << "EOF";
 <br>
 <input type="submit" name="submit" value="Save Changes">
 </form>
+<script>
+function Dopop() {
+        newin=window.open("thesaurus_popup.pl?subject="+document.f.subject.value,"thesaurus",'width=500,height=400,toolbar=false,scrollbars=yes');
+}
+</script>
 EOF
 
 print endmenu();
diff --git a/thesaurus_popup.pl b/thesaurus_popup.pl
new file mode 100755 (executable)
index 0000000..cc9ab5d
--- /dev/null
@@ -0,0 +1,73 @@
+#!/usr/bin/perl
+
+# written 10/5/2002 by Paul
+# build Subject field using bibliothesaurus table
+
+use strict;
+use CGI;
+use C4::Database;
+use C4::Search;
+use C4::Circulation::Circ2;
+use C4::Output;
+
+# get all the data ....
+my %env;
+
+my $input = new CGI;
+my $subject = $input->param('subject');
+my $search_string= $input->param('search_string');
+my $op = $input->param('op');
+my $freelib_text = $input->param('freelib_text');
+
+my $dbh=C4Connect;
+
+# make the page ...
+print $input->header;
+if ($op eq "select") {
+       $subject = $subject."|$freelib_text";
+}
+print <<"EOF";
+       <html>
+       <head>
+       <title>Subject builder</title>
+       </head>
+       <body>
+       <form name="f_pop" action="thesaurus_popup.pl" method="post">
+       <textarea name="subject" rows=10 cols=60>$subject </textarea></br>
+       <p><input type="text" name="search_string" value="$search_string">
+       <input type="hidden" name="op" value="search">
+       <input type="submit" value="Search"></p>
+       </form>
+EOF
+# /search thesaurus terms starting by search_string
+       if ($search_string) {
+               print '<form name="f2_pop" action="thesaurus_popup.pl" method="post">';
+               print '<select name="freelib_text">';
+               my $sti=$dbh->prepare("select freelib,stdlib from bibliothesaurus where freelib like '".$search_string."%'");
+               $sti->execute;
+               while (my $line=$sti->fetchrow_hashref) {
+                       print "<option value='$line->{'stdlib'}'>$line->{freelib}</option>";
+               }
+       print <<"EOF";
+               </select>
+               <input type="hidden" name="op" value="select">
+               <input type="hidden" name="subject" value="$subject">
+               <input type="submit" name="OK" value="OK">
+               </form>
+EOF
+       }
+       print <<"EOF";
+               <form name="f3_pop" onSubmit="javascript:report()">
+               <input type="submit" value="END">
+               </form>
+               <script>
+               function report() {
+                       alert("REPORT");
+                       opener.document.f.subject.value= document.f_pop.subject.value;
+                       self.close();
+                       return false;
+               }
+               </script>
+               </body>
+               </html>
+EOF
diff --git a/updater/thesaurus_create.pl b/updater/thesaurus_create.pl
new file mode 100755 (executable)
index 0000000..17c9ebc
--- /dev/null
@@ -0,0 +1,61 @@
+#!/usr/bin/perl
+
+use strict;
+# This script generates and fill the thesaurus table
+# with the data in bibliothesaurus
+
+use C4::Database;
+use C4::Catalogue;
+use DBI;
+use C4::Acquisitions;
+use C4::Output;
+
+my $dbh=C4Connect;
+
+sub dosql {
+       my ($dbh,$sql_cmd)=@_;
+       my $sti=$dbh->prepare($sql_cmd);
+       $sti->execute;
+       if ($sti->err) {
+               print "error : ".$sti->errstr." \n tried to execute : $sql_cmd\n";
+               $sti->finish;
+       }
+}
+
+my $sth=$dbh->prepare("show tables");
+$sth->execute;
+my %tables;
+while (my ($table) = $sth->fetchrow) {
+    $tables{$table}=1;
+#    print "table $table\n";
+}
+
+print "creating thesaurus...\n";
+dosql($dbh,"CREATE TABLE bibliothesaurus (code BIGINT not null AUTO_INCREMENT, freelib CHAR (255) not null , stdlib CHAR (255) not null , type CHAR (80) not null , PRIMARY KEY (code), INDEX (freelib),index(stdlib),index(type))");
+       my $sti=$dbh->prepare("select count(*) as tot from bibliosubject");
+       $sti->execute;
+       my $total = $sti->fetchrow_hashref;
+       my $sti=$dbh->prepare("select subject from bibliosubject");
+       $sti->execute;
+       my $i;
+       while (my $line =$sti->fetchrow_hashref) {
+               $i++;
+               if ($i % 1000==0) {
+                       print "$i / $total->{'tot'}\n";
+               }
+#              print "$i $line->{'subject'}\n";
+               my $sti2=$dbh->prepare("select count(*) as t from bibliothesaurus where freelib=".$dbh->quote($line->{'subject'}));
+               $sti2->execute;
+               if ($sti2->err) {
+                       print "error : ".$sti2->errstr."\n";
+                       die;
+               }
+               my $line2=$sti2->fetchrow_hashref;
+               if ($line2->{'t'} ==0) {
+                       dosql($dbh,"insert into bibliothesaurus (freelib,stdlib) values (".$dbh->quote($line->{'subject'}).",".$dbh->quote($line->{'subject'}).")");
+#              } else {
+#                      print "pas ecriture pour : $line->{'subject'}\n";
+               }
+
+       }
+