<?php

require_once 'header.php';
?>

<?php 
if (!is_admin()) {
    echo "<div class='alert alert-danger'>You must be an administrator to view this page!</div>";
    die;
}
?>

<?php 
if (isset($_GET['import'])) {
    $ticket = new ticket();
    echo $ticket->importTickets($_POST['data']);
}
?>

<div class="page-header">
  <h1>Import tickets</h1>
</div>

<p>Paste your ticket data here, separated by a comma. One barcode+name pair per line.
  <pre>firstname,barcode</pre>
</p>

<form class="form" action="import.php?import" method="POST">
  <textarea class="form-control" rows="15" name="data"></textarea>
  <button type="submit" class="btn btn-default">Submit</button>
</form>
?>
<br>
Barcode column: <?php 
echo TICKET_COL;
?>
<br>
Scanned boolean column: <?php 
echo SCAN_COL;
?>
<br>
Strict barcode checking is: <?php 
echo !STRICT_CHECKING ? 'Disabled' : 'Enabled';
?>
<br>
<?php 
$ticket = new ticket();
$barcode = 'ZZZ111111111';
echo testCheck("Successful import", $ticket->importTickets("Testing,{$barcode}"), 3);
echo testCheck('Valid scan', $ticket->scanTicket($barcode, 'nick'), 3);
echo testCheck('Duplicate scan', $ticket->scanTicket($barcode, 'nick'), 1);
echo testCheck('Empty barcode', $ticket->scanTicket('', 'nick'), 0);
echo testCheck('Invalid barcode', $ticket->scanTicket('asdfghjkl', 'nick'), 0);
echo testCheck('Empty user', $ticket->scanTicket($barcode, ''), 2);
echo testCheck('Empty user, empty barcode', $ticket->scanTicket('', ''), 2);
$db = new database();
$db->query("DELETE FROM tbl_ticket WHERE tbl_ticket.barcode = '{$barcode}'");
$db->execute();
?>

</pre>