From 670bf3198dd46a70d44d922162078a0784244811 Mon Sep 17 00:00:00 2001
From: short <>
Date: Mon, 28 Jan 2002 22:05:28 +0000
Subject: [PATCH] Version developed during Xmas, not tested - it should be
compatible with current version of sub-package "energie"
---
.htaccess | 4 +-
config.php | 9 +-
index.php | 331 ++++++++++++++++++++++++++++++++++++++++++++++------
kewensis-collect.pl | 78 ++++++++-----
4 files changed, 352 insertions(+), 70 deletions(-)
diff --git a/.htaccess b/.htaccess
index cc84824..85ae2c3 100644
--- a/.htaccess
+++ b/.htaccess
@@ -1,4 +1,6 @@
-SourceCharset iso-8859-2
+
+ SourceCharset utf-8
+
DirectoryIndex index.php
php_flag short_open_tag off
php_flag magic_quotes_gpc off
diff --git a/config.php b/config.php
index 3766162..c2faf91 100644
--- a/config.php
+++ b/config.php
@@ -3,11 +3,18 @@
$admin_mail="short@ucw.cz";
$cvs_mailhost="vellum.cz";
$viewcvs=ereg_replace("^/","http://short.vellum.cz/cgi-bin/viewcvs/kewensis/",$HTTP_SERVER_VARS["SCRIPT_NAME"]);
+ $title_prefix="Kewensis";
+ $force_charset="utf-8"; // library texts will be corrupted but who cares
+
+ $limit_max_default=10;
+ $footer_LOCAL=1; // disable remote footer images
$db_host="";
$db_user="short";
- $db_pwd_a=file("/home/short/priv/mysql.${db_user}.pwd");
+ $db_pwd_a=@file("/home/short/priv/mysql.${db_user}.pwd");
$db_pwd=trim($db_pwd_a[0]);
+ if (!$db_pwd) // defaults to $db_pwd=$db_user if no password file found
+ $db_pwd=$db_user;
$db_name="short";
$tb_tree="kewensis_tree";
diff --git a/index.php b/index.php
index 14f1ff3..12a3190 100644
--- a/index.php
+++ b/index.php
@@ -2,73 +2,328 @@
include("energie/common.php");
- heading(false/*title*/);
+ $head_css="
+.name { font-weight: bold; }
+.PublAuthor { font-variant: small-caps; }
+.Publication { }
+";
+ no_cache();
+
+ $buttonre=".+";
+ prepvar("find" ,".*" ,false /* require */);
+ if (isset($find))
+ $find=trim($find);
+ prepvar("confirm" ,$buttonre,false /* require */);
+ prepvar("delete" ,$buttonre,false /* require */);
+ prepvar("isolate" ,$buttonre,false /* require */);
+ prepvar("edit" ,$buttonre,false /* require */);
+ prepvar("update" ,$buttonre,false /* require */);
+ prepvar("move" ,$buttonre,false /* require */);
+ prepvar("reorder" ,$buttonre,false /* require */);
+
+ prepvar("move_src","[-0-9 ,]+" ,isset($move ) /* require */);
+ prepvar("move_dst","[-0-9]+" ,isset($move ) /* require */);
+ prepvar("confirming","[a-z]+" ,isset($confirm) /* require */);
+ prepvar("reorder_by","[+-]?[0-9]+",isset($reorder) /* require */);
+
+ prepvar("id" ,"[-0-9]+",(isset($update) || isset($confirm) || isset($delete) || isset($isolate) || isset($edit)) || isset($reorder) /* require */);
+ prepvar("winclose" ,"1",false /* require */);
+
+ // Database fields:
+ prepvar("name" ,".*" ,false /* require */);
+ prepvar("PublAuthor" ,".*" ,false /* require */);
+ prepvar("Publication",".*" ,false /* require */);
+ prepvar("html" ,".*" ,false /* require */);
+
+ // "find" dump limits:
+ prepvar("limit_from","[0-9]*",false /* require */);
+ if (!isset($limit_from))
+ $limit_from=0;
+ prepvar("limit_max" ,"[0-9]*",false /* require */);
+ if (!isset($limit_max))
+ $limit_max=$limit_max_default;
+
+ $permanents_array=array("find","limit_from","limit_max","winclose");
+
+ if (isset($update)) {
+
+function fieldupdate($field)
+{
+ global $cmd,$cmdargnum;
+
+ $cmd.=(!$cmdargnum?" ":",")."$field=";
+ if ($GLOBALS[$field]!="")
+ $cmd.="\"".mysql_escape_string($GLOBALS[$field])."\"";
+ else
+ $cmd.="NULL";
+ $cmdargnum++;
+}
+
+ $cmd="update $tb_tree set";
+ $cmdargnum=0;
+ fieldupdate("name");
+ fieldupdate("PublAuthor");
+ fieldupdate("Publication");
+ fieldupdate("html");
+ $cmd.=" where id=\"".mysql_escape_string($id)."\"";
+ if ($cmdargnum)
+ db_query($cmd);
+ // PASSTHRU redirect
+ }
+ if (isset($delete)) {
+ db_query("delete from $tb_tree where id=\"".mysql_escape_string($id)."\"");
+ // PASSTHRU redirect
+ }
+ if (isset($isolate)) {
+ $family_id=db_item("select family_id from $tb_tree where id=\"".mysql_escape_string($id)."\"");
+ if ($id!=$family_id)
+ db_query("update $tb_tree set family_id=id where id=\"".mysql_escape_string($id)."\"");
+ else {
+ $where="where family_id=\"".mysql_escape_string($family_id)."\" and family_id<>id";
+ $other_id=db_item("select id from $tb_tree $where limit 1");
+ db_query("update $tb_tree set family_id=\"".mysql_escape_string($other_id)."\" $where");
+ }
+ // PASSTHRU redirect
+ }
+ if (isset($move)) {
+ $order=db_item("select max(family_order) from $tb_tree where family_id=\"".mysql_escape_string($move_dst)."\"");
+ foreach(preg_split('/[ ,]/',$move_src,-1,PREG_SPLIT_NO_EMPTY) as $src) {
+ // UGLY but how to do sequential setting of increasing family_order?
+ $result=db_query("select id from $tb_tree where family_id=\"".mysql_escape_string($src)."\" order by family_order");
+ while (($row=mysql_fetch_array($result)))
+ db_query("update $tb_tree set family_order=\"".(++$order)."\",family_id=\"".mysql_escape_string($move_dst)."\""
+ ." where id=\"".mysql_escape_string($row["id"])."\"");
+ }
+ // PASSTHRU redirect
+ }
+ if (isset($reorder)) {
+ $row=db_array("select family_id,family_order from $tb_tree where id=\"".mysql_escape_string($id)."\"");
+ $other_order=db_item("select family_order from $tb_tree where family_id=\"".mysql_escape_string($row["family_id"])."\""
+ ." and family_order".($reorder_by<0 ? "<" : ">").$row["family_order"]
+ ." order by family_order ".($reorder_by<0 ? "desc" : "asc")." limit 1");
+ db_query("update $tb_tree set family_order=family_order".($reorder_by>=0 ? "+" : "").$reorder_by
+ ." where family_id=\"".mysql_escape_string($row["family_id"])."\""
+ ." and family_order".($reorder_by<0 ? "<" : ">").$other_order);
+ db_query("update $tb_tree set family_order=".($other_order+$reorder_by)." where id=\"".mysql_escape_string($id)."\"");
+ // PASSTHRU redirect
+ }
- prepvar("find",".+",false /* require */);
+function hiddens($array,$doinputs)
+{
+ global $permanents_array;
+ $r="";
+ foreach ($permanents_array as $key)
+ if (!array_key_exists($key,$array) && isset($GLOBALS[$key]))
+ $array[$key]=$GLOBALS[$key];
+ foreach ($array as $key=>$val) {
+ if ($doinputs)
+ $r.=" \n";
+ else
+ $r.=($r==""?"?":"&").addpercents($key)."=".addpercents($val);
+ }
+ if (!$doinputs && $r=="")
+ $r="?_dummy=1";
+ return($r);
+}
- if (!isset($find)) {
- ?>
-
+ if (isset($delete) || isset($update) || isset($move) || isset($isolate) || isset($reorder)) {
+ if (isset($winclose)) {
+ header("Content-type: text/html");
+ ?>
+
+
+Uzavreni okna
+
+Uzavreni okna
+
");
+}
+
+function formconvert($id,$name,$text,$readonly,$anchor,$hiddens=array())
+{
+ global $tb_tree,$row,$winclose;
+ $readonly=(!$readonly ? "" : " readonly=\"readonly\"");
+ if ($winclose)
+ $text.=" (uzavre okno)";
+ $row=db_array("select name,PublAuthor,Publication,html from $tb_tree"
+ ." where id=\"".mysql_escape_string($id)."\"");
+ $hiddens["id"]=$id;
+ print(""
+ ."");
+ footer(true /* delimit */);
+}
+
+ if (isset($edit))
+ formconvert($id,"update","Aktualizuj zaznam",false/*readonly*/,"#id_$id");
+ if (isset($confirm) && $confirming=="delete")
+ formconvert($id,$confirming,"Opravdu smazat zaznam?",true/*readonly*/,
+ "#family_".db_item("select family_id from $tb_tree where id=\"".mysql_escape_string($id)."\""));
+ if (isset($confirm) && $confirming=="isolate")
+ formconvert($id,$confirming,"Opravdu izolovat zaznam?",true/*readonly*/,"#id_$id");
+
+ $reset_from_script="this.form.elements['limit_from'].value=0;";
+ print(''."\n"
+ .''
+ .' '."\n"
+ .' '."\n"
+ .' '."\n"
+ .'Prvni skupina: '."\n"
+ .' '
+ .'Max skupin: '.' '."\n"
+ .' '."\n");
+ if (!isset($find))
+ footer(true /* delimit */);
+
+ print(" \n");
+
+function fieldquote($prefix,$field,$suffix="")
+{
+ global $row,$fieldquote_tot;
if (!isset($row[$field]))
- return "";
- return $prefix."".htmlspecialchars($row[$field])." ";
+ return("");
+ return($prefix."".htmlspecialchars($row[$field])." ".$suffix);
+}
+
+function formbutton($name,$text,$method="GET",$hidden=array(),$newwin=false,$anchor="")
+{
+ $r="";
+ if ($newwin) {
+ $r.="";
+ return($r);
}
- $family_num=0;
+ $families=db_query("select distinct family_id from $tb_tree"
+ ." where name like \"".mysql_escape_string($find)."%\""
+ ." order by name limit $limit_from,".($limit_max+1));
+
+ $arrows="\n"
+ ."";
+ if ($limit_from>0)
+ $arrows.=formbutton("","Predchozi","GET",array("limit_from"=>max(0,$limit_from-$limit_max)));
+ $arrows.=" ";
+ if (mysql_num_rows($families)>$limit_max)
+ $arrows.=formbutton("","Dalsi","GET",array("limit_from"=>$limit_from+$limit_max));
+ $arrows.="
";
+
+ print "$arrows \n";
+ $family_tot=0;
while (($family_row=mysql_fetch_array($families))) {
- if ($family_num)
+ if ($family_tot)
print " \n";
$family_id=$family_row["family_id"];
- $result=db_query("select id,name,Publication,Notes,html from $tb_tree"
+ print("\n");
+ $result=db_query("select id,family_order,name,PublAuthor,Publication,html from $tb_tree"
." where family_id=\"$family_id\""
- ." order by family_id,family_order");
+ ." order by family_order");
$order=0;
while (($row=mysql_fetch_array($result))) {
- if ($order==0)
- print "";
- elseif ($order==1)
- print "
";
if ($order>=1)
- print "";
+ print "";
- print(fieldquote("","name","name")
- .fieldquote("\n","Publ. Author","author")
- .fieldquote(" \n","Publication","publication")
- .fieldquote(" \n","Notes","notes")
- );
+ print("");
+
+ print("");
+ if ($order>=1) {
+ print "• ";
+ $tabpfx=" ";
+ }
+ else
+ $tabpfx="";
+ print("".fieldquote("","name","\n")
+ .fieldquote("","PublAuthor")." ");
+ print(fieldquote("$tabpfx","Publication"," "));
if (isset($row["html"])) {
$import="import: [".$row["id"]."]";
- $html=eregi_replace("< */? *a( [^>]*)?>","",$row["html"]);
- print(" \n\n".$html."\n ");
+ $html=$row["html"];
+ $html=eregi_replace("< *"."/? *a( [^>]*)?>","",$html);
+ print("$tabpfx\n".$html."\n ");
}
- print("\n");
+ print("
");
+ $l="";
+ $r=" ";
+ print(""
+ .($order <= 0 ? "" :
+ $l.formbutton("reorder","^^^ Nahoru ^^^","POST",
+ array("id"=>$row["id"],"reorder_by"=>-1),false/*newwin*/,"family_$family_id").$r)
+ .$l.formbutton("confirm","Smaz zaznam" ,"GET",
+ array("id"=>$row["id"],"confirming"=>"delete"),true/*newwin*/).$r
+ .$l.formbutton("edit" ,"Edituj zaznam","GET",
+ array("id"=>$row["id"]),true/*newwin*/).$r
+ .(mysql_num_rows($result)<=1 ? "" :
+ $l.formbutton("confirm","Izoluj zaznam","GET",
+ array("id"=>$row["id"],"confirming"=>"isolate"),true/*newwin*/).$r)
+ .($order+1 >= mysql_num_rows($result) ? "" :
+ $l.formbutton("reorder","vvv Dolu vvv" ,"POST",
+ array("id"=>$row["id"],"reorder_by"=>+1),false/*newwin*/,"family_$family_id").$r)
+ ."
\n"
+ );
- if ($order==0)
- print "";
- else
- print " ";
+ if ($order>=1)
+ print "";
print "\n";
$order++;
}
+ mysql_free_result($result);
if ($order>=2)
print " \n";
- $family_num++;
+ print "\n"; // = $limit_max)
+ break;
}
- mysql_free_result($result);
+ mysql_free_result($families);
+ print " $arrows\n";
footer(false /* delimit */);
?>
diff --git a/kewensis-collect.pl b/kewensis-collect.pl
index 009be1e..61b6d88 100755
--- a/kewensis-collect.pl
+++ b/kewensis-collect.pl
@@ -7,10 +7,10 @@ use Cwd;
use Data::Dumper;
use DBI;
-my(%DB,%OWNS,$debugmatch,$D,$key,$owner,$ref,$filename,$doimport,$import_xlate);
+my(%DB,$debugmatch,$D,$key,$owner,$ref,$filename,$doimport,$import_xlate);
%DB=();
-$D=0;
+$D=1;
$debugmatch=0;
$doimport=1;
$import_xlate=1;
@@ -64,7 +64,7 @@ my($file)=@_;
Orchidaceae ($word) ($word)
-((?: ($word) ($word)|$bigword(?: \n$word)*)?($bigword)?
($word)?
(?:
+(?: ($word) ($word)|($bigword(?: \n$word)*))?(($bigword)?
($word)?
(?:
remarks: .*)?(Type )?()?(?:
Linked Records
((?:$attrpat)*))?(
@@ -83,11 +83,17 @@ remarks: .*)?(Type )?( )?(?:
my(%rec);
$rec{"name"}=$1;
$rec{"Publ. Author"}=$2;
- $rec{"Publication"}="$5 $6" if defined($5) && defined($6);
- $rec{"html"}=$3 if defined $3;
- my($attrsbody)=$11;
+ my $publ="";
+ $publ.="$4 $5" if defined($4) && defined($5);
+ $publ.=$6 if defined $6;
+ $rec{"html"}=$7 if defined $7;
+ my($attrsbody)=$12;
+ # catch-array destroyed here!
+ $publ.=s/\ //g;
+ $rec{"Publication"}=$publ if $publ ne "";
($rec{"id"}=$file)=~s#^($id)\.html$#$1#os or failed($file);
$rec{"html"}=~s#$ipniservletwordthree#$3 #osg if $import_xlate && exists $rec{"html"};
+ $rec{"refs"}=[];
my $score=0; # -: upper, +: lower
while (defined($attrsbody) && $attrsbody=~s%^(?:$attrpat)%%os) {
# nomenclatural synonym: id=$2
@@ -98,15 +104,15 @@ remarks: .*)?(Type )?()?(?:
# later publication: id=$16
# Is a later publication: id=$18
my(@refs)=($2,$5,$8,$11,$13,$16,$18);
- $rec{"refs"}=[];
while (@refs) {
push(@{$rec{"refs"}},$_) if defined ($_=shift @refs);
}
- $score+=-10 if defined $5; # basionym: id=$5
- $score+=+10 if defined $13; # Is a basionym: id=$13
- $score+=+10 if defined $16; # later publication: id=$16
- $score+=-10 if defined $18; # Is a later publication: id=$18
+ $score+=+10 if defined $5; # basionym: id=$5
+ $score+=-10 if defined $13; # Is a basionym: id=$13
+ $score+=- 4 if defined $16; # later publication: id=$16
+ $score+=+ 4 if defined $18; # Is a later publication: id=$18
}
+ $score+=+9 if $rec{"Publ. Author"}=~/^\s*\(/;
$rec{"score"}=$score;
if ($attrsbody) {
failed($file);
@@ -141,18 +147,15 @@ my( $entry )=@_;
process_file($entry) if -f $entry;
}
-%OWNS=();
-
foreach (@ARGV)
{ process_entry($_); }
-my($id);
-for $id (keys %DB) {
+for my $id (keys %DB) {
my($refid);
my(@refs);
for $refid (@{$DB{$id}{"refs"}}) {
if (!exists $DB{$refid}) {
- warn "Undefined ref id \"$refid\" from id \"$id\"" if $D;
+ print "Undefined ref id \"$refid\" from id \"$id\"\n" if $D>=1;
next;
}
next if $id eq $refid; # self-ref
@@ -162,28 +165,43 @@ for $id (keys %DB) {
$DB{$id}{"refs"}=\@refs;
}
-print Data::Dumper->Dump([\%DB],["%DB"]) if $D;
+print Data::Dumper->Dump([\%DB],["%DB"]) if $D>=2;
+
+my %OWNS=map { $_=>$DB{$_}{"refs"}; } keys(%DB);
+my %NAMES=();
-%OWNS=map { $_=>[] } keys(%DB);
+for my $id (keys %DB) {
+ $NAMES{$DB{$id}{"name"}}=[] if !exists $NAMES{$DB{$id}{"name"}};
+ push @{$NAMES{$DB{$id}{"name"}}},$id;
+ }
-for $id (keys %OWNS) {
+for my $id (keys %DB) {
next if !exists $OWNS{$id};
- for my $refid (@{$DB{$id}{"refs"}}) {
+ my @queue=($id,@{$OWNS{$id}});
+ $OWNS{$id}=[];
+ while (my $refid=shift @queue) {
+ if (exists $NAMES{$DB{$refid}{"name"}}) {
+ push(@queue,@{$NAMES{$DB{$refid}{"name"}}});
+ delete $NAMES{$DB{$refid}{"name"}};
+ }
+ next if $refid eq $id;
next if !exists $OWNS{$refid};
- push(@{$OWNS{$id}},$refid,@{$OWNS{$refid}});
+ push @queue,@{$OWNS{$refid}};
delete $OWNS{$refid};
- print "connected: id=$id,refid=$refid\n" if $D;
+ print "processed connect id=$id <- refid=$refid\n" if $D>=1;
+ push @{$OWNS{$id}},$refid;
}
}
-print Data::Dumper->Dump([\%OWNS],["%OWNS"]) if $D;
+print Data::Dumper->Dump([\%OWNS],["%OWNS"]) if $D>=2;
foreach $key (keys %OWNS) {
my(@keys)=@{$OWNS{$key}};
delete($OWNS{$key});
unshift(@keys,$key);
- @keys=sort { $DB{$a}{"score"} <=> $DB{$b}{"score"}
- || extract_year($DB{$b}{"Publication"}) <=> extract_year($DB{$a}{"Publication"}); } @keys;
+# @keys=sort { $DB{$a}{"score"} <=> $DB{$b}{"score"}
+# || extract_year($DB{$b}{"Publication"}) <=> extract_year($DB{$a}{"Publication"}); } @keys;
+ @keys=sort { $DB{$a}{"name"} cmp $DB{$b}{"name"}; } @keys;
my($pkey)=shift(@keys);
$OWNS{$pkey}=\@keys;
}
@@ -194,7 +212,8 @@ my($tb_tree);
$db_driver="mysql";
$db_host="";
$db_user="short";
-$DB_PWD=$ENV{"HOME"}."/priv/mysql.${db_user}.pwd";
+#$DB_PWD=$ENV{"HOME"}."/priv/mysql.${db_user}.pwd";
+$db_pwd="short";
$db_name="short";
$tb_tree="kewensis_tree";
@@ -216,7 +235,6 @@ eval { &db_do("drop table $tb_tree") };
."name varchar(100) not null,"
."PublAuthor text null,"
."Publication text null,"
- ."Notes text null,"
."html text null"
.")");
@@ -224,7 +242,7 @@ eval { &db_do("drop table $tb_tree") };
&db_do("alter table $tb_tree add index (name)");
&db_do("alter table $tb_tree add unique (family_id,family_order)");
-my $insert_tb_tree=$db->prepare("insert into $tb_tree (id,family_id,family_order,name,PublAuthor,Publication,Notes,html) values (?,?,?,?,?,?,?)")
+my $insert_tb_tree=$db->prepare("insert into $tb_tree (id,family_id,family_order,name,PublAuthor,Publication,html) values (?,?,?,?,?,?,?)")
or die "Prepare fail: $!";
foreach $owner (sort { $DB{$b}{"name"} cmp $DB{$a}{"name"}; } keys %OWNS) {
@@ -233,9 +251,9 @@ foreach $owner (sort { $DB{$b}{"name"} cmp $DB{$a}{"name"}; } keys %OWNS) {
my $family_id=$DB{$owner}{"id"};
for my $family_order (0..$#family) {
my $id=$family[$family_order];
- print "insert:$id,".$DB{$id}{"name"}."\n" if $D;
+ print "insert:$id,".$DB{$id}{"name"}."\n" if $D>=2;
$insert_tb_tree->execute($id,$family_id,$family_order,
- $DB{$id}{"name"},$DB{$id}{"Publ. Author"},$DB{$id}{"Publication"},$DB{$id}{"Notes"},$DB{$id}{"html"}
+ $DB{$id}{"name"},$DB{$id}{"Publ. Author"},$DB{$id}{"Publication"},$DB{$id}{"html"}
) or die "SQL insert failure: $!";
}
}
--
1.8.3.1