Basic database web search implemented
[kewensis.git] / index.php
1 <?php $cvs_id='$Id$';
2
3         include("energie/common.php");
4
5         heading(false/*title*/);
6
7         prepvar("find",".+",false /* require */);
8
9         if (!isset($find)) {
10                 ?>
11 <form action="index.php" method="post">
12 <input type="text" name="find" size="30" />
13 <input type="submit" value="Vyhledat" />
14 </form>
15 <?php
16                 footer(true /* delimit */);
17                 exit();
18                 }
19         $families=db_query("select distinct family_id from $tb_tree"
20                         ." where name like \"".quotemeta($find)."%\""
21                         ." order by family_id");
22
23 function fieldquote($prefix,$field,$class)
24 {
25         global $row;
26         if (!isset($row[$field]))
27                 return "";
28         return $prefix."<span class=\"$class\">".htmlspecialchars($row[$field])."</span>";
29 }
30
31         $family_num=0;
32         while (($family_row=mysql_fetch_array($families))) {
33                 if ($family_num)
34                         print "<hr />\n";
35                 $family_id=$family_row["family_id"];
36                 $result=db_query("select id,name,Publication,Notes,html from $tb_tree"
37                                 ." where family_id=\"$family_id\""
38                                 ." order by family_id,family_order");
39                 $order=0;
40                 while (($row=mysql_fetch_array($result))) {
41                         if ($order==0)
42                                 print "<p>";
43                         elseif ($order==1)
44                                 print "<ul>";
45                         if ($order>=1)
46                                 print "<li>";
47
48                         print(fieldquote("","name","name")
49                                         .fieldquote("\n","Publ. Author","author")
50                                         .fieldquote("<br />\n","Publication","publication")
51                                         .fieldquote("<br />\n","Notes","notes")
52                                         );
53                         if (isset($row["html"])) {
54                                 $import="import: [".$row["id"]."]";
55                                 $html=eregi_replace("< */? *a( [^>]*)?>","",$row["html"]);
56                                 print("<br />\n<blockquote><!-- BEGIN $import -->\n".$html."\n<!-- END $import --></blockquote>");
57                                 }
58                         print("\n");
59
60                         if ($order==0)
61                                 print "</p>";
62                         else
63                                 print "</li>";
64                         print "\n";
65                         $order++;
66                         }
67                 if ($order>=2)
68                         print "</ul>\n";
69                 $family_num++;
70                 }
71         mysql_free_result($result);
72
73         footer(false /* delimit */);
74 ?>