/** * Search function for the search.php page. * * @param string $searchphrase * @param string $type * @param integer $limit * @return xajaxResponse */ function doAjaxSearch($searchphrase = '', $type = 'pilot', $limit = 10) { $qry = new DBPreparedQuery(); switch ($type) { case "pilot": $sql = "select plt.plt_name as name1, crp.crp_name as name2, plt.plt_id as id\n\t\t\t\t from kb3_pilots plt, kb3_corps crp\n\t\t\t\t where plt.plt_name like ?\n\t\t\t\t and plt.plt_crp_id = crp.crp_id\n\t\t\t\t order by plt.plt_name LIMIT {$limit}"; break; case "corp": $sql = "select crp.crp_name as name1, ali.all_name as name2, crp.crp_id as id\n\t\t\t\t from kb3_corps crp, kb3_alliances ali\n\t\t\t\t where crp.crp_name like ?\n\t\t\t\t and crp.crp_all_id = ali.all_id\n\t\t\t\t order by crp.crp_name LIMIT {$limit}"; break; case "alliance": $sql = "select ali.all_name as name1, '' as name2, ali.all_id as id\n\t\t\t\t from kb3_alliances ali\n\t\t\t\t where ali.all_name like ?\n\t\t\t\t order by ali.all_name LIMIT {$limit}"; break; case "system": $sql = "select sys.sys_name as name1, reg.reg_name as name2, sys.sys_id as id\n\t\t\t\t from kb3_systems sys, kb3_constellations con, kb3_regions reg\n\t\t\t\t where sys.sys_name like ?\n\t\t\t\t\tand con.con_id = sys.sys_con_id and reg.reg_id = con.con_reg_id\n\t\t\t\t order by sys.sys_name LIMIT {$limit}"; break; case "item": $sql = "select typeName as name1, '' as name2, typeID as id\n\t\t\t\tfrom kb3_invtypes where typeName like ? LIMIT {$limit}"; break; default: $objResponse = new xajaxResponse(); $objResponse->assign('searchresults', "innerHTML", 'Invalid type'); return $objResponse; } $name1 = 'No result'; $name2 = ''; $id = 0; $qry->prepare($sql); $searchphrase2 = $searchphrase . '%'; $qry->bind_param('s', $searchphrase2); $qry->bind_result($name1, $name2, $id); $result = ''; if (!$qry->execute()) { $result = $qry->getErrorMsg(); } else { if (!$qry->recordCount()) { $result = "No results"; } else { $result = "<table class='kb-table' width='450'><tr class='kb-table-header'>"; switch ($type) { case "pilot": $result .= "<td>Pilot</td><td>Corporation</td></tr>"; break; case "corp": $result .= "<td>Corporation</td><td>Alliance</td></tr>"; break; case "alliance": $result .= "<td>Alliance</td><td></td></tr>"; break; case "system": $result .= "<td>System</td><td>Region</td></tr>"; break; case "item": $result .= "<td>Item</td><td></td></tr>"; break; } while ($qry->fetch()) { $result .= "<tr class='kb-table-row-even'><td><a href='"; switch ($type) { case "pilot": $result .= edkURI::page('pilot_detail', $id, 'plt_id') . "'>"; break; case "corp": $result .= edkURI::page('corp_detail', $id, 'crp_id') . "'>"; break; case "alliance": $result .= edkURI::page('alliance_detail', $id, 'all_id') . "'>"; break; case "system": $result .= edkURI::page('system_detail', $id, 'sys_id') . "'>"; break; case "item": $result .= edkURI::page('invtype', $id) . "'>"; break; } $result .= $name1 . "</a></td><td>" . $name2 . "</td></tr>"; } $result .= "</table>"; } } $objResponse = new xajaxResponse(); $objResponse->assign('searchresults', "innerHTML", $result); return $objResponse; }