| Server IP : 173.209.174.21 / Your IP : 216.73.216.89 Web Server : Apache/2.4.58 (Ubuntu) System : Linux wcfs-server 6.8.0-124-generic #124-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 13:00:45 UTC 2026 x86_64 User : nodor ( 1000) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/thelittlebigshow/self-hosted/ |
Upload File : |
<?php include 'protect.php'; ?>
<?php
include 'db.php';
require_once __DIR__ . '/brand_header.php';
$success = false;
$error = '';
$selected_id = isset($_POST['customer_id']) ? intval($_POST['customer_id']) : 0;
// Update name if submitted
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['save'])) {
$first = trim($_POST['first_name'] ?? '');
$last = trim($_POST['last_name'] ?? '');
if ($selected_id > 0 && $first !== '' && $last !== '') {
$stmt = $conn->prepare("UPDATE customers SET first_name = ?, last_name = ? WHERE id = ?");
$stmt->bind_param("ssi", $first, $last, $selected_id);
$stmt->execute();
$success = true;
} else {
$error = "Please provide both first and last names.";
}
}
// Fetch all customers for the dropdown
$customers_result = $conn->query("SELECT id, first_name, last_name FROM customers ORDER BY last_name, first_name");
$customers = [];
while ($row = $customers_result->fetch_assoc()) {
$customers[] = $row;
}
// Fetch selected customer info
$selected_customer = null;
if ($selected_id > 0) {
$stmt = $conn->prepare("SELECT first_name, last_name FROM customers WHERE id = ?");
$stmt->bind_param("i", $selected_id);
$stmt->execute();
$res = $stmt->get_result();
$selected_customer = $res->fetch_assoc();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Rename Customers</title>
<style>
body { font-family: Arial, sans-serif; background: #f9f9f9; padding: 40px; }
.container { max-width: 500px; margin: auto; background: #fff; padding: 25px; box-shadow: 0 0 10px rgba(0,0,0,0.1); }
label { display: block; margin-top: 15px; font-weight: bold; }
input, select { width: 100%; padding: 8px; margin-top: 5px; }
.submit-btn { margin-top: 20px; background: #4CAF50; color: white; border: none; padding: 10px; font-size: 16px; cursor: pointer; }
.submit-btn:hover { background: #45a049; }
.success { color: green; margin-top: 15px; }
.error { color: red; margin-top: 15px; }
.back-link { display: inline-block; margin-top: 30px; text-decoration: none; color: #4CAF50; font-weight: bold; }
.back-link:hover { text-decoration: underline; }
</style>
<?php echo appBrandStyles(); ?>
</head>
<body>
<div class="container">
<?php renderAppBrandHeader(); ?>
<h2>Rename Customer</h2>
<form method="post">
<label for="customer_id">Select Customer:</label>
<select name="customer_id" id="customer_id" onchange="this.form.submit()">
<option value="">-- Select --</option>
<?php foreach ($customers as $cust): ?>
<option value="<?= $cust['id'] ?>" <?= ($cust['id'] == $selected_id) ? 'selected' : '' ?>>
<?= htmlspecialchars($cust['last_name'] . ', ' . $cust['first_name']) ?>
</option>
<?php endforeach; ?>
</select>
</form>
<?php if ($selected_customer): ?>
<form method="post">
<input type="hidden" name="customer_id" value="<?= $selected_id ?>">
<input type="hidden" name="save" value="1">
<label for="first_name">First Name:</label>
<input type="text" name="first_name" value="<?= htmlspecialchars($selected_customer['first_name']) ?>" required>
<label for="last_name">Last Name:</label>
<input type="text" name="last_name" value="<?= htmlspecialchars($selected_customer['last_name']) ?>" required>
<input class="submit-btn" type="submit" value="Save Changes">
</form>
<?php endif; ?>
<?php if ($success): ?>
<p class="success">Customer name updated successfully.</p>
<?php endif; ?>
<?php if ($error): ?>
<p class="error"><?= $error ?></p>
<?php endif; ?>
<a class="back-link" href="index.php">← Back to Dashboard</a>
</div>
</body>
</html>