| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- // This file contains HTML snippets for the several possible forms
- $pdo = null;
- try {
- $pdo = new PDO("sqlite:" . './slork.sqlite');
- } 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="password" class="form-control" name="i" 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>
- <h4>OR</h4>
- <!-- This part selects an existing maintainer -->
- <div class="form-group">
- <label for="existingMaintainer">Existing maintainer</label>
- <select class="form-control" name="m" id="existingMaintainer">
- <option></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>";
- }
- $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 != ?
- 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[] = $row['value'] . " [" . $row['player'] . "]";
- }
- $snippets[2] = <<<HTML
- <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] .= "<tr><td>$player</td><td><button class=\"btn btn-primary\">Edit</button></td><td><button class=\"btn btn-danger\">Remove</button></td>";
- }
- $snippets[2] .= <<<HTML
- </tbody>
- </table>
- HTML;
|