PageRenderTime 43ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/web/index.php

http://github.com/MrMEEE/ironhide
PHP | 137 lines | 116 code | 14 blank | 7 comment | 13 complexity | 18377ad422c0ddee7bbd2ffab0fa0a3d MD5 | raw file
  1. <?php
  2. /**
  3. * XXX: check which characters are allowed!
  4. * - fix data containing pipes (|) from breaking the output of search=showall
  5. */
  6. require "connect.php";
  7. if(isset($_GET["addmachine"])){
  8. $manufacturer = filter_input(INPUT_GET, "manufacturer");
  9. $model = filter_input(INPUT_GET, "model");
  10. $start = filter_input(INPUT_GET, "start");
  11. $shutdown = filter_input(INPUT_GET, "shutdown");
  12. if($start==""){
  13. $start="UNAVAILABLE";
  14. $shutdown="UNAVAILABLE";
  15. }
  16. $user = filter_input(INPUT_GET, "user");
  17. $distro = filter_input(INPUT_GET, "distro");
  18. // if the host allows it, use MySQLi + prepared statements
  19. $sql = sprintf('SELECT * from confirmed
  20. WHERE Manufacturer="%s" AND Model="%s" AND `nVidia Startup`="%s" AND `nVidia Shutdown`="%s"',
  21. mysql_real_escape_string($manufacturer), mysql_real_escape_string($model),
  22. mysql_real_escape_string($start), mysql_real_escape_string($shutdown));
  23. $query = mysql_query($sql);
  24. $row = mysql_fetch_assoc($query);
  25. if($row['Manufacturer'] == $manufacturer){
  26. $id = $row['id'];
  27. $confirmed = $row['Users Confirming'];
  28. $confirmed += 1;
  29. // acceptable since $confirmed and $id are both numbers
  30. mysql_query("UPDATE `confirmed` SET `Users Confirming`=$confirmed WHERE id=$id");
  31. echo "System Added to already existing profile";
  32. }
  33. else{
  34. if($manufacturer!=""&&$model!=""&&$user!=""){ // &&$user!=$row['Confirming User']
  35. $sql = sprintf('INSERT into confirmed (Manufacturer, Model, `nVidia Startup`,
  36. `nVidia Shutdown`, `Submitting User`, `Users Confirming`, Distribution) VALUES
  37. ("%s", "%s", "%s", "%s", "%s", 1, "%s")',
  38. mysql_real_escape_string($manufacturer), mysql_real_escape_string($model),
  39. mysql_real_escape_string($start), mysql_real_escape_string($shutdown),
  40. mysql_real_escape_string($user), mysql_real_escape_string($distro)
  41. );
  42. mysql_query($sql);
  43. echo "System Added";
  44. }
  45. }
  46. }
  47. else if(isset($_GET["search"])){ // addmachine should not be combined with search
  48. // do not render the output as HTML
  49. header('Content-Type: text/plain');
  50. $searchitem = filter_input(INPUT_GET, 'searchitem');
  51. if($searchitem=="showall")
  52. $query = mysql_query("SELECT * FROM `confirmed` ORDER by Manufacturer");
  53. else
  54. $query = mysql_query(sprintf("SELECT * FROM confirmed WHERE Model = '%s'",
  55. mysql_real_escape_string($searchitem)));
  56. while($row = mysql_fetch_assoc($query)){
  57. echo $row['Manufacturer'];
  58. echo "| ";
  59. echo $row['Model'];
  60. echo "| ";
  61. echo $row['nVidia Startup'];
  62. echo "| ";
  63. echo $row['nVidia Shutdown'];
  64. echo "| ";
  65. echo $row['Submitting User'];
  66. echo "| ";
  67. echo $row['Users Confirming'];
  68. echo "| ";
  69. echo $row['Distribution'];
  70. echo "\n";
  71. }
  72. }
  73. if (!isset($_GET["search"])){
  74. echo "<script src=\"sorttable.js\"></script>";
  75. echo "<LINK href=\"style.css\" rel=\"stylesheet\" type=\"text/css\">";
  76. echo '<form type="get">Search: <input type="text" name="searchitem"><input name="search" type="submit">
  77. </form>';
  78. echo '<form type="get">
  79. Manufacturer: <input type="text" name="manufacturer">Model: <input type="text" name="model">nVidia Startup: <input type="text" name="start">nVidia Shutdown: <input type="text" name="shutdown">User Submitted: <input type="text" name="user">Distribution: <input type="text" name="distro"><input name="addmachine" type="submit">
  80. </form>';
  81. $query = mysql_query("SELECT * FROM `confirmed`");
  82. echo "<table class=\"sortable\">";
  83. echo "<thead>";
  84. echo " <tr><th>Manufacturer</th><th>Model</th><th>nVidia Startup</th><th>nVidia Shutdown</th><th>Submitting User</th><th>Users Confirming</th><th>Distro</th></tr>";
  85. echo "</thead>";
  86. echo "<tbody>";
  87. while($row = mysql_fetch_assoc($query)){
  88. echo "<tr>";
  89. echo "<td>";
  90. echo htmlspecialchars($row['Manufacturer']);
  91. echo "</td>";
  92. echo "<td>";
  93. echo htmlspecialchars($row['Model']);
  94. echo "</td>";
  95. if ($row['nVidia Startup'] != "UNAVAILABLE"){
  96. echo '<td><a href="showinfo.php?show=1&id='. htmlspecialchars($row['id']) . '&info=nVidia Startup">Available</a></td>';
  97. }
  98. else
  99. {
  100. echo "<td>Unavailable</td>";
  101. }
  102. if ($row['nVidia Shutdown'] != "UNAVAILABLE"){
  103. echo '<td><a href="showinfo.php?show=1&id='. htmlspecialchars($row['id']) . '&info=nVidia Shutdown">Available</a></td>';
  104. }
  105. else
  106. {
  107. echo "<td>Unavailable</td>";
  108. }
  109. echo "<td>";
  110. echo htmlspecialchars($row['Submitting User']);
  111. echo "</td>";
  112. echo "<td>";
  113. echo htmlspecialchars($row['Users Confirming']);
  114. echo "</td>";
  115. echo "<td>";
  116. echo htmlspecialchars($row['Distribution']);
  117. echo "</td>";
  118. echo "</tr>";
  119. }
  120. echo "</tbody>";
  121. echo "</table>";
  122. }
  123. ?>