| Server IP : 72.60.21.38 / Your IP : 216.73.217.140 Web Server : LiteSpeed System : Linux uk-fast-web1372.main-hosting.eu 4.18.0-553.121.1.lve.el8.x86_64 #1 SMP Thu Apr 30 16:40:41 UTC 2026 x86_64 User : u390967363 ( 390967363) PHP Version : 8.2.30 Disable Function : system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail MySQL : OFF | cURL : ON | WGET : ON | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home/u390967363/domains/aibenproperties.com/public_html/app/ |
Upload File : |
<?php
require_once 'includes/db.php';
require_once 'includes/functions.php';
// Start Session if not already started
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
// Auth Check
if (!isset($_SESSION['user_id'])) {
header("Location: index.php");
exit;
}
$error = '';
$success = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$first_name = $_POST['first_name'] ?? '';
$last_name = $_POST['last_name'] ?? '';
$email = $_POST['email'] ?? '';
$phone = $_POST['phone'] ?? '';
$status = $_POST['status'] ?? 'active';
// Assign to currently logged in user
$agent_id = $_SESSION['user_id'];
if ($first_name && $last_name && $email) {
try {
$stmt = $pdo->prepare("INSERT INTO clients (first_name, last_name, email, phone, status, agent_id, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, NOW(), NOW())");
$stmt->execute([$first_name, $last_name, $email, $phone, $status, $agent_id]);
// Log Activity
$client_id = $pdo->lastInsertId();
if (function_exists('logActivity')) {
logActivity($_SESSION['user_id'], 'Create Client', "Added new client #$client_id ($first_name $last_name)");
}
header("Location: clients.php?msg=created");
exit;
} catch (Exception $e) {
if (strpos($e->getMessage(), 'Duplicate entry') !== false) {
$error = "A client with this email already exists.";
} else {
$error = "Error adding client: " . $e->getMessage();
}
}
} else {
$error = "First Name, Last Name, and Email are required.";
}
}
require 'includes/header.php';
?>
<div class="container-fluid px-4">
<div class="d-flex justify-content-between align-items-center mt-4 mb-4">
<div>
<h2 class="text-navy fw-bold">Add New Client</h2>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="clients.php" class="text-decoration-none">Clients</a></li>
<li class="breadcrumb-item active">Add New</li>
</ol>
</nav>
</div>
<a href="clients.php" class="btn btn-outline-secondary">
<i class="fa-solid fa-arrow-left me-2"></i>Cancel
</a>
</div>
<?php if ($error): ?>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<i class="fa-solid fa-exclamation-circle me-2"></i><?= $error ?>
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
<?php endif; ?>
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card border-0 shadow-sm">
<div class="card-body p-4">
<form method="POST">
<div class="row mb-3">
<div class="col-md-6">
<label class="form-label fw-bold">First Name <span class="text-danger">*</span></label>
<div class="input-group">
<span class="input-group-text bg-light"><i class="fa-solid fa-user"></i></span>
<input type="text" name="first_name" class="form-control" placeholder="John" required>
</div>
</div>
<div class="col-md-6">
<label class="form-label fw-bold">Last Name <span class="text-danger">*</span></label>
<input type="text" name="last_name" class="form-control" placeholder="Doe" required>
</div>
</div>
<div class="row mb-3">
<div class="col-md-6">
<label class="form-label fw-bold">Email Address <span class="text-danger">*</span></label>
<div class="input-group">
<span class="input-group-text bg-light"><i class="fa-solid fa-envelope"></i></span>
<input type="email" name="email" class="form-control" placeholder="john.doe@example.com" required>
</div>
</div>
<div class="col-md-6">
<label class="form-label fw-bold">Phone Number</label>
<div class="input-group">
<span class="input-group-text bg-light"><i class="fa-solid fa-phone"></i></span>
<input type="text" name="phone" class="form-control" placeholder="+234..." required>
</div>
</div>
</div>
<div class="mb-4">
<label class="form-label fw-bold">Status</label>
<select name="status" class="form-select">
<option value="active">Active</option>
<option value="lead">Lead</option>
<option value="prospect">Prospect</option>
<option value="inactive">Inactive</option>
</select>
<div class="form-text">Set the initial status for this client.</div>
</div>
<div class="d-grid">
<button type="submit" class="btn btn-primary py-2 fw-bold">
<i class="fa-solid fa-save me-2"></i>Save Client
</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<?php require 'includes/footer.php'; ?>