/search.php

https://github.com/jwheare/FITB · PHP · 83 lines · 73 code · 10 blank · 0 comment · 19 complexity · 817fbd96aef91b7b113eed6a44a5bca9 MD5 · raw file

  1. <?php
  2. include_once('functions.php');
  3. $searchquery = $_GET['query'];
  4. $start = "";
  5. if(isset($_GET['duration'])) {
  6. $start = "&duration=" . $_GET['duration'];
  7. }
  8. if((isset($_GET['type'])) && ($_GET['type'] != "")) {
  9. $type = $_GET['type'];
  10. }
  11. if((isset($_GET['host'])) && ($_GET['host'] != "")) {
  12. $host = $_GET['host'];
  13. }
  14. ?>
  15. <html>
  16. <head>
  17. <title>FITB - Search Results for <?php echo $searchquery ?></title>
  18. <link rel="stylesheet" href="fitb.css" type="text/css" media="screen" />
  19. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
  20. <script type="text/javascript" src="fitb.js"></script>
  21. <meta http-equiv="refresh" content="60">
  22. </head>
  23. <body>
  24. <?php include_once('header.php'); # includes the <div> for the header ?>
  25. <div id="wrap">
  26. <?php include_once('side.php'); # includes the <div> for the side bar ?>
  27. <div id="main">
  28. <?php
  29. if (isset($host)) {
  30. echo "<h2>Search Results for \"{$searchquery}\" on host {$host}</h2>";
  31. } elseif (isset($type)) {
  32. echo "<h2>Search Results for \"{$searchquery}\", type {$type}</h2>";
  33. } else {
  34. echo "<h2>Search Results for \"{$searchquery}\"</h2>";
  35. }
  36. ?>
  37. <?php
  38. connectToDB();
  39. $searchquery = mysql_real_escape_string($searchquery);
  40. if (isset($host)) {
  41. $host = mysql_real_escape_string($host);
  42. $type = mysql_real_escape_string($type);
  43. $result = mysql_query('SELECT * FROM ports WHERE (name like "%' . $searchquery . '%" OR alias like "%' . $searchquery . '%")
  44. AND graphtype like "%' . $type . '%" AND host="' . $host . '" ORDER BY lastpoll DESC, safename ASC');
  45. } elseif (isset($type)) {
  46. $type = mysql_real_escape_string($type);
  47. $result = mysql_query('SELECT * FROM ports WHERE (name like "%' . $searchquery . '%" OR alias like "%' . $searchquery . '%")
  48. AND graphtype="' . $type . '" ORDER BY lastpoll DESC, safename ASC');
  49. } else {
  50. $result = mysql_query('SELECT * FROM ports WHERE (name like "%' . $searchquery . '%" OR alias like "%' . $searchquery . '%")
  51. ORDER BY lastpoll DESC, safename ASC');
  52. }
  53. if(mysql_num_rows($result) > 0) {
  54. $numresults = mysql_num_rows($result);
  55. echo "<div class=\"small\">{$numresults} results found</div>";
  56. while ($row = mysql_fetch_assoc($result)) {
  57. $staletag = "";
  58. if ((time() - $row['lastpoll']) > $staleage) {
  59. $staletag = "STALE: ";
  60. }
  61. $friendlytitle = urlencode("{$staletag}{$row['host']} - {$row['name']} ({$row['alias']})");
  62. $basegraphurl = "graph.php?host={$row['host']}&rrdname={$row['host']}-{$row['safename']}&type={$row['graphtype']}{$start}&friendlytitle={$friendlytitle}";
  63. echo '<a href="view' . $basegraphurl . '">';
  64. echo '<img src="' . $basegraphurl . '&height=100&width=400" alt="'.$row['alias'].'"></a>';
  65. }
  66. } else {
  67. echo "No results :( ";
  68. }
  69. ?>
  70. <div>
  71. </div>
  72. </body>
  73. </html>