|
|
@@ -8,93 +8,100 @@ try {
|
|
|
} catch (PDOException $e) {
|
|
|
// handle the exception here
|
|
|
}
|
|
|
-// Select all maintainers
|
|
|
-$query = <<<QUERY
|
|
|
- SELECT maintainer.maintainer, player.value
|
|
|
- FROM maintainer
|
|
|
- JOIN player ON maintainer.maintainer = player.player
|
|
|
- WHERE player.property = 'name';
|
|
|
-QUERY;
|
|
|
-$all_maintainers = [];
|
|
|
-$rows = $pdo->query( $query );
|
|
|
-foreach ( $rows as $row ) {
|
|
|
- $all_maintainers[$row['maintainer']] = $row['value'];
|
|
|
-}
|
|
|
+
|
|
|
$snippets = [];
|
|
|
-$snippets[0] = <<<HTML
|
|
|
- <form>
|
|
|
- <!-- This form adds a new maintainer -->
|
|
|
- <div class="form-group">
|
|
|
- <label for="newAPIKey">New maintainer</label>
|
|
|
- <input type="hidden" name="action" value="i">
|
|
|
- <input type="password" class="form-control" name="api" id="newAPIKey" aria-describedby="newAPIKey" placeholder="Enter API key">
|
|
|
- <small id="newAPIKey" class="form-text text-muted">Assuming you are new here, add your Torn API key</small>
|
|
|
- </div>
|
|
|
- <button type="submit" class="btn btn-primary">Submit</button>
|
|
|
- </form>
|
|
|
- <div><p> </p></div>
|
|
|
- <h4>OR</h4>
|
|
|
- <!-- This part selects an existing maintainer -->
|
|
|
- <form>
|
|
|
- <div class="form-group">
|
|
|
- <label for="existingMaintainer">Existing maintainer</label>
|
|
|
- <input type="hidden" name="action" value="m">
|
|
|
- <select class="form-control" name="maintainer" id="existingMaintainer">
|
|
|
- <option></option><!-- Empty option -->
|
|
|
+
|
|
|
+if ( $screen == 0 ) {
|
|
|
+ // Select all maintainers
|
|
|
+ $query = <<<QUERY
|
|
|
+ SELECT maintainer.maintainer, player.value
|
|
|
+ FROM maintainer
|
|
|
+ JOIN player ON maintainer.maintainer = player.player
|
|
|
+ WHERE player.property = 'name';
|
|
|
+QUERY;
|
|
|
+ $all_maintainers = [];
|
|
|
+ $rows = $pdo->query($query);
|
|
|
+ foreach ($rows as $row) {
|
|
|
+ $all_maintainers[$row['maintainer']] = $row['value'];
|
|
|
+ }
|
|
|
+ $snippets[0] = <<<HTML
|
|
|
+ <form>
|
|
|
+ <!-- This form adds a new maintainer -->
|
|
|
+ <div class="form-group">
|
|
|
+ <label for="newAPIKey">New maintainer</label>
|
|
|
+ <input type="hidden" name="action" value="i">
|
|
|
+ <input type="password" class="form-control" name="api" id="newAPIKey" aria-describedby="newAPIKey" placeholder="Enter API key">
|
|
|
+ <small id="newAPIKey" class="form-text text-muted">Assuming you are new here, add your Torn API key</small>
|
|
|
+ </div>
|
|
|
+ <button type="submit" class="btn btn-primary">Submit</button>
|
|
|
+ </form>
|
|
|
+ <div><p> </p></div>
|
|
|
+ <h4>OR</h4>
|
|
|
+ <!-- This part selects an existing maintainer -->
|
|
|
+ <form>
|
|
|
+ <div class="form-group">
|
|
|
+ <label for="existingMaintainer">Existing maintainer</label>
|
|
|
+ <input type="hidden" name="action" value="m">
|
|
|
+ <select class="form-control" name="maintainer" id="existingMaintainer">
|
|
|
+ <option></option><!-- Empty option -->
|
|
|
HTML;
|
|
|
|
|
|
-foreach ( $all_maintainers as $maintainer_key => $maintainer_value ) {
|
|
|
- $snippets[0] .= "\t\t\t\t<option value=\"$maintainer_key\">$maintainer_value [$maintainer_key]</option>\n";
|
|
|
-}
|
|
|
+ foreach ($all_maintainers as $maintainer_key => $maintainer_value) {
|
|
|
+ $snippets[0] .= "\t\t\t\t<option value=\"$maintainer_key\">$maintainer_value [$maintainer_key]</option>\n";
|
|
|
+ }
|
|
|
|
|
|
-$snippets[0] .= <<<HTML
|
|
|
- </select>
|
|
|
- </div>
|
|
|
- <button type="submit" class="btn btn-primary">Submit</button>
|
|
|
- </form>
|
|
|
+ $snippets[0] .= <<<HTML
|
|
|
+ </select>
|
|
|
+ </div>
|
|
|
+ <button type="submit" class="btn btn-primary">Submit</button>
|
|
|
+ </form>
|
|
|
HTML;
|
|
|
|
|
|
-$query = <<<SQL
|
|
|
- SELECT player, value FROM player
|
|
|
- WHERE maintainer = ?
|
|
|
- AND property = 'name'
|
|
|
- --AND player != ?
|
|
|
+ $query = <<<SQL
|
|
|
+ SELECT player, value FROM player
|
|
|
+ WHERE maintainer = ?
|
|
|
+ AND property = 'name'
|
|
|
+ --AND player != ?
|
|
|
SQL;
|
|
|
-$stmt = $pdo->prepare( $query );
|
|
|
-$stmt->execute( [$maintainer[0]] );
|
|
|
-$rows = $stmt->fetchAll();
|
|
|
-print( "<pre>" );
|
|
|
-print_r( $rows );
|
|
|
-print( "</pre>" );
|
|
|
-$players_id = array();
|
|
|
-foreach ( $rows as $row ) {
|
|
|
- $players_id[] = array($row['player'], $row['value'] . " [" . $row['player'] . "]");
|
|
|
+ $stmt = $pdo->prepare($query);
|
|
|
+ $stmt->execute([$maintainer[0]]);
|
|
|
+ $rows = $stmt->fetchAll();
|
|
|
+ print("<pre>");
|
|
|
+ print_r($rows);
|
|
|
+ print("</pre>");
|
|
|
+ $players_id = array();
|
|
|
+ foreach ($rows as $row) {
|
|
|
+ $players_id[] = array($row['player'], $row['value'] . " [" . $row['player'] . "]");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-$snippets[2] = <<<HTML
|
|
|
- <form id="player">
|
|
|
- <div class="form-group">
|
|
|
- <table class="table">
|
|
|
- <thead>
|
|
|
- <tr>
|
|
|
- <th>Player</th><th>Edit</th><th>Remove</th>
|
|
|
- </tr>
|
|
|
- </thead>
|
|
|
- <tbody>
|
|
|
+if ( $screen == 2 ) {
|
|
|
+ // Let maintainer select (or delete) a player
|
|
|
+ $snippets[2] = <<<HTML
|
|
|
+ <form id="player">
|
|
|
+ <div class="form-group">
|
|
|
+ <table class="table">
|
|
|
+ <thead>
|
|
|
+ <tr>
|
|
|
+ <th>Player</th><th>Edit</th><th>Remove</th>
|
|
|
+ </tr>
|
|
|
+ </thead>
|
|
|
+ <tbody>
|
|
|
HTML;
|
|
|
|
|
|
- foreach ( $players_id as $player ) {
|
|
|
- $snippets[2] .= "\n\t\t\t\t\t<tr>";
|
|
|
- $snippets[2] .= "\n\t\t\t\t\t\t<td>$player[1]";
|
|
|
- $snippets[2] .= "<input type=\"hidden\" name=\"player\" value=\"$player[0]\" form=\"player\"></td><td>";
|
|
|
- $snippets[2] .= "<input type=\"hidden\" name=\"maintainer\" value=\"$maintainer[0]\" form=\"player\">";
|
|
|
- $snippets[2] .= "<button class=\"btn btn-primary\" name=\"action\" value=\"e\" form=\"player\">Edit</button></td>";
|
|
|
- $snippets[2] .= "<td><button class=\"btn btn-danger\" name=\"action\" value=\"x\" form=\"player\">Remove</button></td>\n\t\t\t\t\t</tr>";
|
|
|
- }
|
|
|
+ foreach ($players_id as $player) {
|
|
|
+ $snippets[2] .= "\n\t\t\t\t\t<tr>";
|
|
|
+ $snippets[2] .= "\n\t\t\t\t\t\t<td>$player[1]";
|
|
|
+ $snippets[2] .= "<input type=\"hidden\" name=\"player\" value=\"$player[0]\" form=\"player\"></td><td>";
|
|
|
+ $snippets[2] .= "<input type=\"hidden\" name=\"maintainer\" value=\"$maintainer[0]\" form=\"player\">";
|
|
|
+ $snippets[2] .= "<button class=\"btn btn-primary\" name=\"action\" value=\"e\" form=\"player\">Edit</button></td>";
|
|
|
+ $snippets[2] .= "<td><button class=\"btn btn-danger\" name=\"action\" value=\"x\" form=\"player\">Remove</button></td>\n\t\t\t\t\t</tr>";
|
|
|
+ }
|
|
|
|
|
|
-$snippets[2] .= <<<HTML
|
|
|
-\n </tbody>
|
|
|
- </table>
|
|
|
- </div>
|
|
|
- </form>
|
|
|
+ $snippets[2] .= <<<HTML
|
|
|
+ \n </tbody>
|
|
|
+ </table>
|
|
|
+ </div>
|
|
|
+ </form>
|
|
|
HTML;
|
|
|
+}
|