Basic database web search implemented
[kewensis.git] / index.php
diff --git a/index.php b/index.php
new file mode 100644 (file)
index 0000000..14f1ff3
--- /dev/null
+++ b/index.php
@@ -0,0 +1,74 @@
+<?php $cvs_id='$Id$';
+
+       include("energie/common.php");
+
+       heading(false/*title*/);
+
+       prepvar("find",".+",false /* require */);
+
+       if (!isset($find)) {
+               ?>
+<form action="index.php" method="post">
+<input type="text" name="find" size="30" />
+<input type="submit" value="Vyhledat" />
+</form>
+<?php
+               footer(true /* delimit */);
+               exit();
+               }
+       $families=db_query("select distinct family_id from $tb_tree"
+                       ." where name like \"".quotemeta($find)."%\""
+                       ." order by family_id");
+
+function fieldquote($prefix,$field,$class)
+{
+       global $row;
+       if (!isset($row[$field]))
+               return "";
+       return $prefix."<span class=\"$class\">".htmlspecialchars($row[$field])."</span>";
+}
+
+       $family_num=0;
+       while (($family_row=mysql_fetch_array($families))) {
+               if ($family_num)
+                       print "<hr />\n";
+               $family_id=$family_row["family_id"];
+               $result=db_query("select id,name,Publication,Notes,html from $tb_tree"
+                               ." where family_id=\"$family_id\""
+                               ." order by family_id,family_order");
+               $order=0;
+               while (($row=mysql_fetch_array($result))) {
+                       if ($order==0)
+                               print "<p>";
+                       elseif ($order==1)
+                               print "<ul>";
+                       if ($order>=1)
+                               print "<li>";
+
+                       print(fieldquote("","name","name")
+                                       .fieldquote("\n","Publ. Author","author")
+                                       .fieldquote("<br />\n","Publication","publication")
+                                       .fieldquote("<br />\n","Notes","notes")
+                                       );
+                       if (isset($row["html"])) {
+                               $import="import: [".$row["id"]."]";
+                               $html=eregi_replace("< */? *a( [^>]*)?>","",$row["html"]);
+                               print("<br />\n<blockquote><!-- BEGIN $import -->\n".$html."\n<!-- END $import --></blockquote>");
+                               }
+                       print("\n");
+
+                       if ($order==0)
+                               print "</p>";
+                       else
+                               print "</li>";
+                       print "\n";
+                       $order++;
+                       }
+               if ($order>=2)
+                       print "</ul>\n";
+               $family_num++;
+               }
+       mysql_free_result($result);
+
+       footer(false /* delimit */);
+?>