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