<?php
/** board script
* Displayes the submitted flowIDs of the
* last X time with meta information
* If the submission to gameserver was successfull (submitsuccess)
* and we got points for it (scoresuccess) it should be green bg
*
* 2014-15 by Jan "Someone" Vales <someone@somenet.org>
* do not publish!
*/

$GLOBALS['db'] = new PDO('pgsql:host=localhost;port=5432;dbname=flagbot;user=flagbot;password=flagbotpw');
$GLOBALS['db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query = "SELECT * FROM flags WHERE not (received + INTERVAL '30 minute') > now() ORDER BY received DESC";

?>
<!DOCTYPE html>
  <html>
  <head>
    <link rel="stylesheet" type="text/css" href="styles.css"></link>
  </head>
  <body>
    <h1>Submission Board - Flags</h1>
    <p><a href="./index_flag_ids.php">go to flag_ids</a></p>
    <p>Shows all submissions of the last 30 min<br>
    NUM ROWS: <?php echo sizeof($GLOBALS['db']->query($query)->fetchAll()); ?></p>
    <table style="width: 100%">
      <thead>
        <tr>
            <th>fid</th>
            <th>flag</th>
            <th>service</th>
            <th>flag_id</th>
            <th>submitter</th>
            <th>received</th>
            <th>submitted</th>
            <th>status</th>
            <th>srvresponse</th>
          </tr>
        </thead>
        <tbody>
          <?php
          $stmt = $GLOBALS['db']->query($query);
          while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
          ?>
            <tr class="score-<?php echo $row['status']; ?>">
              <td><?php echo $row['fid']; ?></td>
              <td><?php echo $row['flag']; ?></td>
              <td><?php echo $row['service']; ?>&nbsp;</td>
              <td><?php echo $row['flag_id']; ?>&nbsp;</td>
              <td><?php echo $row['submitter']; ?>&nbsp;</td>
              <td><?php echo $row['received']; ?></td>
              <td><?php echo $row['submitted']; ?>&nbsp;</td>
              <td><?php echo $row['status']; ?></td>
              <td><?php echo htmlentities($row['srvresponse']); ?>&nbsp;</td>
            </tr>
            <?php
          }
          ?>
        </tbody>
      </table>
    <p>Status: 0=submission pending; 1=submitted:OK; 2=submitted:Fail</p>
    </body>
    </html>