setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['new_lead']) && $_POST['new_lead'] && isset($_POST['name']) && $_POST['name'] && isset($_POST['phone']) && $_POST['phone']) {
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$formname = 'crm-portal';
$note = $_POST['note'];
$origin = $_POST['origin'];
$gender = $_POST['gender'];
$profession = $_POST['profession'];
$country = $_POST['country'];
$state = $_POST['state'];
$city = $_POST['city'];
$address = $_POST['address'];
$status = 'New';
try {
$stmt = $conn->prepare("INSERT INTO cleads (name, email, phone, formname, note, origin, status, gender, profession, country, state, city, address ) VALUES (:name, :email, :phone, :formname, :note, :origin, :status, :gender, :profession, :country, :state, :city, :address)");
$stmt->bindParam(':name', $name);
$stmt->bindParam(':email', $email);
$stmt->bindParam(':phone', $phone);
$stmt->bindParam(':formname', $formname);
$stmt->bindParam(':note', $note);
$stmt->bindParam(':origin', $origin);
$stmt->bindParam(':status', $status);
$stmt->bindParam(':gender', $gender);
$stmt->bindParam(':profession', $profession);
$stmt->bindParam(':country', $country);
$stmt->bindParam(':state', $state);
$stmt->bindParam(':city', $city);
$stmt->bindParam(':address', $address);
$stmt->execute();
echo "Record added successfully";
} catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
}
?>
Lead Management
| Name |
ID |
Status Update |
Contact Detail |
Form Name |
Date & Time |
Quick Action |
setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$searchQuery = isset($_GET['search']) ? trim($_GET['search']) : '';
$start_date = isset($_GET['start_date']) ? $_GET['start_date'] : '';
$end_date = isset($_GET['end_date']) ? $_GET['end_date'] : '';
$accessArray = explode(",", $_SESSION['access']);
$placeholders = rtrim(str_repeat('?,', count($accessArray)), ','); // Creating placeholders like ?,?,?,?
$placeholderString = implode(',', array_fill(0, count($accessArray), '?'));
if (!empty($searchQuery)) {
// this is keywords search
$stmt = $conn->prepare("SELECT * FROM cleads WHERE (id LIKE ? OR name LIKE ? OR email LIKE ? OR phone LIKE ?) AND business_type = ? ORDER BY time DESC LIMIT ?, ?");
$stmt->bindValue(1, "%$searchQuery%", PDO::PARAM_STR);
$stmt->bindValue(2, "%$searchQuery%", PDO::PARAM_STR);
$stmt->bindValue(3, "%$searchQuery%", PDO::PARAM_STR);
$stmt->bindValue(4, "%$searchQuery%", PDO::PARAM_STR);
$stmt->bindValue(5, $_GET['bv']);
$stmt->bindValue(6, 0, PDO::PARAM_INT); // Offset for pagination
$stmt->bindValue(7, $recordsPerPage, PDO::PARAM_INT); // Records per page
// this is for date serch
}elseif (!empty($start_date) && !empty($end_date)) {
$start_date = date('Y-m-d', strtotime($start_date));
$end_date = date('Y-m-d', strtotime($end_date));
$stmt = $conn->prepare("SELECT * FROM cleads WHERE business_type = ? AND `time` BETWEEN ? AND ?");
$stmt->bindValue(1, $_GET['bv']);
$stmt->bindValue(2, $start_date);
$stmt->bindValue(3, $end_date);
}else{
// if user type admin then show all lead
if($_SESSION['user_type'] == 'admin'){
$stmt = $conn->prepare("SELECT COUNT(*) FROM cleads");
$stmt->execute();
$totalRecords = $stmt->fetchColumn();
$totalPages = ceil($totalRecords / $recordsPerPage);
$offset = ($currentPage - 1) * $recordsPerPage;
$stmt = $conn->prepare("SELECT * FROM cleads WHERE business_type = :business_type ORDER BY time DESC LIMIT :offset, :recordsPerPage");
$stmt->bindParam(':business_type', $_GET['bv'], PDO::PARAM_INT);
$stmt->bindParam(':offset', $offset, PDO::PARAM_INT);
$stmt->bindParam(':recordsPerPage', $recordsPerPage, PDO::PARAM_INT);
}else{
// if user type user then show only given access lead
$stmt = $conn->prepare("SELECT COUNT(*) FROM cleads WHERE business_type = ?");
$stmt->bindValue(1, $_GET['bv']);
$stmt->execute();
$totalRecords = $stmt->fetchColumn();
$totalPages = ceil($totalRecords / $recordsPerPage);
$offset = ($currentPage - 1) * $recordsPerPage;
$stmt = $conn->prepare("SELECT * FROM cleads WHERE business_type = :business_type ORDER BY time DESC LIMIT :offset, :recordsPerPage");
$stmt->bindParam(':business_type', $_GET['bv']);
$stmt->bindParam(':offset', $offset, PDO::PARAM_INT);
$stmt->bindParam(':recordsPerPage', $recordsPerPage, PDO::PARAM_INT);
}
}
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$row_count = count($rows);
for ($i = 0; $i < $row_count; $i++) {
// echo $row_count . " ";
}
echo "Total ".$row_count." Rows Found
";
// Status Conditional Color
foreach($rows as $row){
if($row['status'] == 'New'){$conditional_background_color = 'background-color: #FFD9D9; border: 2px solid #FB5555; border-radius: 20px; text-align: center; color: #FB5555;';}
elseif($row['status'] == 'Contacted'){$conditional_background_color = 'background-color: #D4FFFF; border: 2px solid #2C9C9C; border-radius: 20px; text-align: center; color: #2C9C9C;';}
elseif($row['status'] == 'Disqualified'){$conditional_background_color = 'background-color: #CECECE; border: 2px solid #3F4254; border-radius: 20px; text-align: center; color: #3F4254;';}
elseif($row['status'] == 'Converted'){$conditional_background_color = 'background-color: #D4FDE7; border: 2px solid #40916C; border-radius: 20px; text-align: center; color: #40916C;';}
elseif($row['status'] == 'Warm'){$conditional_background_color = 'background-color: #FFD9D9; border: 2px solid #FB5555; border-radius: 20px; text-align: center; color: #FB5555;';}
// if status = warm then select
if($row['status'] == 'Warm'){$conditional_status = ''.$row['status'].'
';}elseif($row['status'] != 'Warm'){$conditional_status = $row['status'];}
?>
|
|
|
|
|
|
|
Error: " . $e->getMessage() . "";
}
?>