X-Git-Url: https://git.jankratochvil.net/?p=kewensis.git;a=blobdiff_plain;f=index.php;h=5516faa25802a5cf9817194d25757348382d2fea;hp=14f1ff38267d800fd8428aa1d2cf8429ae45d370;hb=refs%2Fheads%2Fmaster;hpb=cc9a120fa1095fe32c186606799e005456fccb54 diff --git a/index.php b/index.php index 14f1ff3..5516faa 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 (!isset($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"); + ?> + + +Window close + +

Window close

+ "); +} + +function formconvert($id,$name,$text,$readonly,$anchor,$hiddens=array()) +{ + global $tb_tree,$row,$winclose; + $readonly=(!$readonly ? "" : " readonly=\"readonly\""); + if ($winclose) + $text.=" (closes window)"; + $row=db_array("select name,PublAuthor,Publication,html from $tb_tree" + ." where id=\"".mysql_escape_string($id)."\""); + $hiddens["id"]=$id; + print("" + ."
\n" + ."
\n" + .fieldedit("name",50,$readonly) + ."\n".fieldedit("PublAuthor",50,$readonly) + ."
\n".fieldedit("Publication",100,$readonly) + ."
\n" + ."

 

\n" + ."\n" + .hiddens($hiddens,true/*doinputs*/) + ."
"); + footer(true /* delimit */); +} + + if (isset($edit)) + formconvert($id,"update","Update entry",false/*readonly*/,"#id_$id"); + if (isset($confirm) && $confirming=="delete") + formconvert($id,$confirming,"Really delete entry?",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,"Really isolate entry?",true/*readonly*/,"#id_$id"); + + $reset_from_script="this.form.elements['limit_from'].value=0;"; + print('
'."\n" + .'

' + .''."\n" + .' '."\n" + .'

'."\n" + .'First Group: '."\n" + .'   ' + .'Max Groups: '.''."\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.="
".formbutton($name,$text,$method,$hidden,false/*newwin*/).""; + $hidden["winclose"]=1; + } + $r.="" + ."
" + ."" + .hiddens($hidden,true/*doinputs*/) + ."
"; + + 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("","Previous","GET",array("limit_from"=>max(0,$limit_from-$limit_max))); + $arrows.=""; + if (mysql_num_rows($families)>$limit_max) + $arrows.=formbutton("","Next","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("
" + ."
" // WARNING: will break the line! + ."Group # " + ."

" + ."Join to this group: " + ." \n" + .hiddens(array("move_dst"=>$family_id),true/*doinputs*/) + ."
\n" + ."
\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 "

\n"; - $family_num++; + print "\n"; // = $limit_max) + break; } - mysql_free_result($result); + mysql_free_result($families); + print "
$arrows\n"; footer(false /* delimit */); ?>