<?php

/**
 * Dashboard shows pending transactions:
 *  Block seats.
 *  Move a booking. For move, amounts must be same. Email customer and support team and ...
 */

// This is a protected page. Check if we have an authenticated user...

global $logger;
require 'auth/check.php';
$user_id = auth($_SERVER['PHP_SELF']);

// Have an authenticated user. Can continue...

require_once '/opt/php/vendor/autoload.php';

//require_once '../../config/constants.php';
$_SESSION['LOGGER_NAME'] = 'main';
require '../lib/init.php';
require 'dbTLK.php';

try {
    $dbTLK = getTLKDB($logger);
    $sql = sprintf("SELECT id, movies_theaters_showtime_id mtsId, refcode, total_ticket_price amount, seat_list, mobile_no FROM transactions WHERE user_id=%d AND status=%d", $user_id, -1);
    $result = $dbTLK->select($sql, []);
    if (0 == sizeof($result)) {
        header('Location: /event/index.php');
    }
    // echo "Pending transactions: " . json_encode($result);
} catch (Exception $e) {
    echo $e;
}

/*
 * Pending transactions:
 * [
 * {"id":8102273,"movies_theaters_showtime_id":16967,"user_id":3,"refcode":"V8MZ8G240210",
 * "total_ticket_price":2000,"commission":0,"status":-1,
 * "seat_list":"non_res_16967_49243, non_res_16967_11381","is_active":1,
 * "created_by":4687,"modified_by":null,"created_at":"2024-02-10 12:54:48","updated_at":"2024-02-10 12:56:44",
 * "is_tickets_issued":0,"booked_by":1,
 * "payment_gate_way_type":null,
 * "mobile_no":"0721097693","sms_sending_status":1,
 * "coupon_value":null,"promotion_id":null,"promotion_count":0,
 * "identity_token":"d3e9a912-8dea-4c1c-9120-7d14e6129ffd"}]
 */

?>

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style>
        table, th, td {
            border: 1px solid black;
            border-collapse: collapse;
        }
        th, td {
            background-color: #96D4D4;
        }
        table tr td:nth-child(3) {
            text-align: center;
        }
    </style>
</head>
<body>
<hr>
<h2>Pending Transactions:</h2>
<table>
    <tr>
        <th>Transaction ID</th>
        <th>MTS ID</th>
        <th>Reference</th>
        <th>Amount</th>
        <th>Seats</th>
        <th>Mobile Number</th>
        <th>Block Seats</th>
        <th>Move Booking</th>
    </tr>
    <?php foreach ($result as $row): ?>
        <tr>
            <td style="text-align: center"><?= $row['id']; ?></td>
            <td style="text-align: center"><?= $row['mtsId']; ?></td>
            <td style="text-align: center"><?= $row['refcode']; ?></td>
            <td style="text-align:right"><?= number_format($row['amount'], 2, ".", ","); ?></td>
            <td style="text-align: center"><?= $row['seat_list']; ?></td>
            <td style="text-align: center"><?= $row['mobile_no']; ?></td>
            <td style="vertical-align: center">
                <?php
                $name = "form1_" . $row['id'];
                $action = "/admin/blockSeats.php?txn_id=" . $row['id'];
                ?>
                <form action=<?php echo $action ?> name=<?php echo $name ?> method="post">
                    <input type="submit" name="submit_block" value="BLOCK SEATS" />
                </form>
            </td>
            <td style="vertical-align: center">
                <?php
                $name = "form2_" . $row['id'];
                $action = "/event/detail.php?id=" . $row['id'];
                ?>
                <form action=<?php echo $action ?> name=<?php echo $name ?> method="post">
                    <input type="submit" name="submit_move" value="MOVE BOOKING" />
                </form>
            </td>
        </tr>
    <?php endforeach; ?>
</table>
<br><hr><br>
</body>
</html>
