| Server IP : 127.0.0.1 / Your IP : 216.73.216.48 Web Server : Apache/2.4.58 (Win64) OpenSSL/3.1.3 PHP/8.2.12 System : Windows NT DESKTOP-3H4FHQJ 10.0 build 19045 (Windows 10) AMD64 User : win 10 ( 0) PHP Version : 8.2.12 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : D:/xampp/htdocs-coblaa/Cinevaa/ |
Upload File : |
<?php
include('db.php');
session_start();
/**
* 1. HELPER FUNCTION
* Calculates human-readable time remaining
*/
function getRemainingTime($expiry) {
if (!$expiry) return "---";
$remaining = strtotime($expiry) - time();
if ($remaining <= 0) return "<span style='color:red;'>Expired</span>";
$days = floor($remaining / 86400);
$hours = floor(($remaining % 86400) / 3600);
return ($days > 0) ? $days . "d " . $hours . "h left" : $hours . "h left";
}
/**
* 2. ACTION LOGIC (Approve/Reject)
*/
if (isset($_GET['action']) && isset($_GET['id'])) {
$id = intval($_GET['id']);
$action = mysqli_real_escape_string($con, $_GET['action']);
if ($action === 'approved') {
// Fetch plan and unique user id (my_id) from payments
$query = "SELECT plan, my_id FROM payments WHERE id = $id";
$fetchRes = mysqli_query($con, $query);
$payData = mysqli_fetch_assoc($fetchRes);
if ($payData) {
$u_id = mysqli_real_escape_string($con, $payData['my_id']);
$plan = $payData['plan'];
// Determine Duration
switch (strtolower($plan)) {
case 'daily': $duration = "+1 day"; break;
case 'weekly': $duration = "+7 days"; break;
case 'monthly': $duration = "+30 days"; break;
default: $duration = "+30 days";
}
// CALCULATE SYNCED TIME
$final_expiry = date('Y-m-d H:i:s', strtotime($duration));
// 1. Update Payments Table status and expiry
mysqli_query($con, "UPDATE payments SET status = 'approved', expiry_date = '$final_expiry' WHERE id = $id");
// 2. Update Subscription Table (Gatekeeper)
// We use UPDATE here because my_id is your unique identifier.
// If the user doesn't exist yet, we ensure they are active.
$updateSub = "UPDATE cine_subscriptiontb SET
subscription_status = 'active',
expiry_date = '$final_expiry'
WHERE my_id = '$u_id'";
mysqli_query($con, $updateSub);
// OPTIONAL: If the UPDATE affected 0 rows, it means the user isn't in the sub table yet.
if(mysqli_affected_rows($con) == 0) {
mysqli_query($con, "INSERT INTO cine_subscriptiontb (my_id, subscription_status, expiry_date)
VALUES ('$u_id', 'active', '$final_expiry')");
}
}
} else {
// Handle Rejection
mysqli_query($con, "UPDATE payments SET status = '$action' WHERE id = $id");
}
header("Location: admin_payments.php?msg=Status Updated and Dates Synced");
exit();
}
// Fetch all records for the display table
$result = mysqli_query($con, "SELECT * FROM payments ORDER BY created_at DESC");
?>
<!DOCTYPE html>
<html>
<head>
<title>Admin - Subscription Management</title>
<style>
body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: #f0f2f5; padding: 20px; }
.admin-container { max-width: 1100px; margin: auto; background: white; padding: 25px; border-radius: 12px; box-shadow: 0 4px 20px rgba(0,0,0,0.08); }
h2 { color: #1e293b; margin-bottom: 20px; }
table { width: 100%; border-collapse: collapse; }
th { background: #2563eb; color: white; padding: 15px; text-align: left; font-size: 14px; }
td { padding: 15px; border-bottom: 1px solid #e2e8f0; font-size: 14px; color: #475569; }
.status-pending { background: #fef3c7; color: #92400e; padding: 4px 10px; border-radius: 6px; font-size: 12px; font-weight: bold; }
.status-approved { background: #dcfce7; color: #166534; padding: 4px 10px; border-radius: 6px; font-size: 12px; font-weight: bold; }
.status-rejected { background: #fee2e2; color: #991b1b; padding: 4px 10px; border-radius: 6px; font-size: 12px; font-weight: bold; }
.time-badge { font-family: 'Courier New', monospace; font-weight: bold; color: #2563eb; }
.btn { padding: 8px 14px; text-decoration: none; border-radius: 6px; font-size: 12px; color: white; font-weight: 600; display: inline-block; }
.btn-approve { background: #10b981; }
.btn-reject { background: #ef4444; margin-left: 4px; }
</style>
</head>
<body>
<div class="admin-container">
<h2>Subscription Control Center</h2>
<?php if(isset($_GET['msg'])): ?>
<p style="color: #10b981; font-weight: bold;"><?php echo htmlspecialchars($_GET['msg']); ?></p>
<?php endif; ?>
<table>
<thead>
<tr>
<th>User ID</th>
<th>Plan</th>
<th>Ref Number</th>
<th>Amount</th>
<th>Status</th>
<th>Time Remaining</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php if(mysqli_num_rows($result) > 0): ?>
<?php while($row = mysqli_fetch_assoc($result)): ?>
<tr>
<td>#<?php echo htmlspecialchars($row['my_id']); ?></td>
<td><strong><?php echo htmlspecialchars($row['plan']); ?></strong></td>
<td><code><?php echo htmlspecialchars($row['transaction_ref']); ?></code></td>
<td><code><?php echo htmlspecialchars($row['amount']); ?></code></td>
<td><span class="status-<?php echo $row['status']; ?>"><?php echo strtoupper($row['status']); ?></span></td>
<td class="time-badge">
<?php echo ($row['status'] == 'approved') ? getRemainingTime($row['expiry_date']) : '---'; ?>
</td>
<td>
<?php if($row['status'] == 'pending'): ?>
<a href="?action=approved&id=<?php echo $row['id']; ?>" class="btn btn-approve" onclick="return confirm('Approve payment?')">Approve</a>
<a href="?action=rejected&id=<?php echo $row['id']; ?>" class="btn btn-reject" onclick="return confirm('Reject payment?')">Reject</a>
<?php else: ?>
<span style="color:#94a3b8; font-style: italic;">Complete</span>
<?php endif; ?>
</td>
</tr>
<?php endwhile; ?>
<?php else: ?>
<tr><td colspan="6" style="text-align:center;">No records found.</td></tr>
<?php endif; ?>
</tbody>
</table>
</div>
</body>
</html>