snippets.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. // This file contains HTML snippets for the several possible forms
  3. $pdo = null;
  4. try {
  5. $pdo = new PDO("sqlite:" . './slork.sqlite');
  6. } catch (PDOException $e) {
  7. // handle the exception here
  8. }
  9. // Select all maintainers
  10. $query = <<<QUERY
  11. SELECT maintainer.maintainer, player.value
  12. FROM maintainer
  13. JOIN player ON maintainer.maintainer = player.player
  14. WHERE player.property = 'name';
  15. QUERY;
  16. $all_maintainers = [];
  17. $rows = $pdo->query( $query );
  18. foreach ( $rows as $row ) {
  19. $all_maintainers[$row['maintainer']] = $row['value'];
  20. }
  21. $snippets = [];
  22. $snippets[0] = <<<HTML
  23. <form>
  24. <!-- This form adds a new maintainer -->
  25. <div class="form-group">
  26. <label for="newAPIKey">New maintainer</label>
  27. <input type="password" class="form-control" name="i" id="newAPIKey" aria-describedby="newAPIKey" placeholder="Enter API key">
  28. <small id="newAPIKey" class="form-text text-muted">Assuming you are new here, add your Torn API key</small>
  29. </div>
  30. <h4>OR</h4>
  31. <!-- This part selects an existing maintainer -->
  32. <div class="form-group">
  33. <label for="existingMaintainer">Existing maintainer</label>
  34. <select class="form-control" name="m" id="existingMaintainer">
  35. <option></option>
  36. HTML;
  37. foreach ( $all_maintainers as $maintainer_key => $maintainer_value ) {
  38. $snippets[0] .= "\t\t\t\t<option value=\"$maintainer_key\">$maintainer_value [$maintainer_key]</option>";
  39. }
  40. $snippets[0] .= <<<HTML
  41. </select>
  42. </div>
  43. <button type="submit" class="btn btn-primary">Submit</button>
  44. </form>
  45. HTML;
  46. $query = <<<SQL
  47. SELECT player, value FROM player
  48. WHERE maintainer = ?
  49. AND property = 'name'
  50. --AND player != ?
  51. SQL;
  52. $stmt = $pdo->prepare( $query );
  53. $stmt->execute( [$maintainer[0]] );
  54. $rows = $stmt->fetchAll();
  55. print( "<pre>" );
  56. print_r( $rows );
  57. print( "</pre>" );
  58. $players_id = array();
  59. foreach ( $rows as $row ) {
  60. $players_id[] = $row['value'] . " [" . $row['player'] . "]";
  61. }
  62. $snippets[2] = <<<HTML
  63. <table class="table">
  64. <thead>
  65. <tr>
  66. <th>Player</th><th>Edit</th><th>Remove</th>
  67. </tr>
  68. </thead>
  69. <tbody>
  70. HTML;
  71. foreach ( $players_id as $player ) {
  72. $snippets[2] .= "<tr><td>$player</td><td><button class=\"btn btn-primary\">Edit</button></td><td><button class=\"btn btn-danger\">Remove</button></td>";
  73. }
  74. $snippets[2] .= <<<HTML
  75. </tbody>
  76. </table>
  77. HTML;