PATH:
home
/
u865795251
/
domains
/
whatisnewis.com
/
public_html
/
vfa
/
Editing: admin-users.php
<?php require_once __DIR__ . '/db.php'; session_start(); header('Content-Type: application/json'); if (!isset($_SESSION['authenticated']) || $_SESSION['authenticated'] !== true) { http_response_code(403); echo json_encode(['error' => 'Unauthorized access.']); exit; } try { $page = isset($_GET['page']) ? intval($_GET['page']) : 1; $limit = isset($_GET['limit']) ? intval($_GET['limit']) : 10; $search = isset($_GET['search']) ? trim($_GET['search']) : ''; $status = isset($_GET['status']) ? trim($_GET['status']) : 'All'; $date = isset($_GET['date']) ? trim($_GET['date']) : ''; $offset = ($page - 1) * $limit; // Build SQL Select statement with dynamic parameters $queryStr = "SELECT * FROM users WHERE 1=1"; $countStr = "SELECT COUNT(*) as count FROM users WHERE 1=1"; $params = []; if (!empty($search)) { $searchFilter = "%$search%"; $queryStr .= " AND (name LIKE ? OR email LIKE ? OR phone LIKE ? OR razorpay_order_id LIKE ? OR payment_id LIKE ?)"; $countStr .= " AND (name LIKE ? OR email LIKE ? OR phone LIKE ? OR razorpay_order_id LIKE ? OR payment_id LIKE ?)"; for ($i = 0; $i < 5; $i++) { $params[] = $searchFilter; } } if ($status !== 'All') { $queryStr .= " AND payment_status = ?"; $countStr .= " AND payment_status = ?"; $params[] = $status; } if (!empty($date)) { $queryStr .= " AND date(date) = ?"; $countStr .= " AND date(date) = ?"; $params[] = $date; } // Clone params for count query $countParams = $params; // Complete Select list query with order and offset bounds $queryStr .= " ORDER BY id DESC LIMIT ? OFFSET ?"; $params[] = $limit; $params[] = $offset; // Execute count query $stmtCount = $db->prepare($countStr); $stmtCount->execute($countParams); $totalCount = $stmtCount->fetch()['count']; // Execute data query $stmtData = $db->prepare($queryStr); $stmtData->execute($params); $users = $stmtData->fetchAll(); // Map columns to preserve consistency with frontend $usersFormatted = []; foreach ($users as $u) { $usersFormatted[] = [ 'id' => intval($u['id']), 'name' => $u['name'], 'email' => $u['email'], 'phone' => $u['phone'], 'country_code' => $u['country_code'], 'message' => $u['message'], 'reminder_added' => intval($u['reminder_added']) === 1, 'subtotal' => floatval($u['subtotal']), 'gst_amount' => floatval($u['gst_amount']), 'amount_paid' => floatval($u['amount_paid']), 'razorpay_order_id' => $u['razorpay_order_id'], 'payment_id' => $u['payment_id'], 'payment_status' => $u['payment_status'], 'date' => $u['date'] ]; } $totalPages = ceil($totalCount / $limit); echo json_encode([ 'users' => $usersFormatted, 'totalPages' => $totalPages, 'totalCount' => $totalCount ]); } catch (Exception $e) { http_response_code(500); echo json_encode(['error' => $e->getMessage()]); }
SAVE
CANCEL