root/dev/common/search.php @ 207

Revision 207, 4.0 KB (checked in by ralle030583, 15 years ago)

- added system search
- added 12 new ship Signatures (thx to Arthur Ffrub)
- removed again some not needed includes

Line 
1<?php
2$page = new Page('Search');
3
4$html .= "<form id=search action=\"?a=search\" method=post>";
5$html .= "<table class=kb-subtable><tr>";
6$html .= "<td>Type:</td><td>Text: (3 letters minimum)</td>";
7$html .= "</tr><tr>";
8$html .= "<td><select id=searchtype name=searchtype><option value=pilot>Pilot</option><option value=corp>Corporation</option><option value=alliance>Alliance</option><option value=system>System</option></select></td>";
9$html .= "<td><input id=searchphrase name=searchphrase type=text size=30/></td>";
10$html .= "<td><input type=submit name=submit value=Search></td>";
11$html .= "</tr></table>";
12$html .= "</form>";
13
14if ($_REQUEST['searchphrase'] != "" && strlen($_REQUEST['searchphrase']) >= 3)
15{
16    switch ($_REQUEST['searchtype'])
17    {
18        case "pilot":
19            $sql = "select plt.plt_id, plt.plt_name, crp.crp_name
20                  from kb3_pilots plt, kb3_corps crp
21                 where lower( plt.plt_name ) like lower( '%".slashfix($_REQUEST['searchphrase'])."%' )
22                   and plt.plt_crp_id = crp.crp_id
23                 order by plt.plt_name";
24            $header = "<td>Pilot</td><td>Corporation</td>";
25            break;
26        case "corp":
27            $sql = "select crp.crp_id, crp.crp_name, ali.all_name
28                  from kb3_corps crp, kb3_alliances ali
29                 where lower( crp.crp_name ) like lower( '%".slashfix($_REQUEST['searchphrase'])."%' )
30                   and crp.crp_all_id = ali.all_id
31                 order by crp.crp_name";
32            $header = "<td>Corporation</td><td>Alliance</td>";
33            break;
34        case "alliance":
35            $sql = "select ali.all_id, ali.all_name
36                  from kb3_alliances ali
37                 where lower( ali.all_name ) like lower( '%".slashfix($_REQUEST['searchphrase'])."%' )
38                 order by ali.all_name";
39            $header = "<td>Alliance</td><td></td>";
40            break;
41        case "system":
42            $sql = "select sys.sys_id, sys.sys_name
43                  from kb3_systems sys
44                 where lower( sys.sys_name ) like lower( '%".slashfix($_REQUEST['searchphrase'])."%' )
45                 order by sys.sys_name";
46            $header = "<td>System</td><td></td>";
47            break;
48    }
49
50    $qry = new DBQuery();
51    if (!$qry->execute($sql))
52    {
53        die ($qry->getErrorMsg());
54    }
55
56    $html .= "<div class=block-header>Search results</div>";
57
58    if ($qry->recordCount() > 0)
59    {
60        $html .= "<table class=kb-table width=450 cellspacing=1>";
61        $html .= "<tr class=kb-table-header>".$header."</tr>";
62    }
63    else
64    {
65        $html .= "No results.";
66    }
67
68    while ($row = $qry->getRow())
69    {
70        $html .= "<tr class=kb-table-row-even>";
71        switch ($_REQUEST['searchtype'])
72        {
73            case "pilot":
74                $link = "?a=pilot_detail&plt_id=".$row['plt_id'];
75                $html .= "<td><a href=\"$link\">".$row['plt_name']."</a></td><td>".$row['crp_name']."</td>";
76                break;
77            case "corp":
78                $link = "?a=corp_detail&crp_id=".$row['crp_id'];
79                $html .= "<td><a href=\"$link\">".$row['crp_name']."</a></td><td>".$row['all_name']."</td>";
80                break;
81            case "alliance":
82                $link = "?a=alliance_detail&all_id=".$row['all_id'];
83                $html .= "<td><a href=\"$link\">".$row['all_name']."</a></td><td></td>";
84                break;
85            case "system":
86                $link = "?a=system_detail&sys_id=".$row['sys_id'];
87                $html .= "<td><a href=\"$link\">".$row['sys_name']."</a></td><td></td>";
88                break;
89        }
90        $html .= "</tr>";
91        if ($qry->recordCount() == 1)
92        {
93            // if there is only one entry we redirect the user directly
94            header("Location: $link");
95        }
96    }
97    if ($qry->recordCount() > 0)
98    {
99        $html .= "</table>";
100    }
101}
102
103$page->setContent($html);
104$page->generate();
105?>
Note: See TracBrowser for help on using the browser.