| <?php |
| session_start(); |
| if (!isset($_SESSION['logged_in']) || $_SESSION['logged_in'] !== true) { |
| header('HTTP/1.1 401 Unauthorized'); |
| exit(json_encode(['success' => false, 'message' => 'Unauthorized'])); |
| } |
|
|
| require_once '../../db.php'; |
|
|
| $database = new Database(); |
| $db = $database->getConnection(); |
|
|
| $user = new User($db); |
| $transaction = new Transaction($db); |
|
|
| if ($user->getUserByUsername($_SESSION['username'])) { |
| $offset = isset($_GET['offset']) ? (int)$_GET['offset'] : 0; |
| $transactions_stmt = $transaction->getTransactionsByUserId($user->id, 20, $offset); |
| |
| $transactions = []; |
| while ($row = $transactions_stmt->fetch(PDO::FETCH_ASSOC)) { |
| $transactions[] = $row; |
| } |
| |
| echo json_encode(['success' => true, 'transactions' => $transactions]); |
| } else { |
| echo json_encode(['success' => false, 'message' => 'User not found']); |
| } |
| ?> |