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(); } } ?> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $delete_placeholders = rtrim(str_repeat('?,', count($selectedIds)), ','); $stmt = $conn->prepare("DELETE FROM cleads WHERE id IN ($delete_placeholders)"); foreach($selectedIds as $key => $id) { $stmt->bindValue($key + 1, $id, PDO::PARAM_INT); } $stmt->execute(); } catch(PDOException $e) { echo "Error: " . $e->getMessage(); } } } ?>

Lead Management

Choose Date for filter

  |  

Delete

'; ?> 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), '?')); $all_states = "WB, SK"; $state_array = explode(',', $all_states); $state_placeholder = rtrim(str_repeat('?,', count($state_array)), ','); 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 IN ($placeholders) 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); foreach ($accessArray as $key => $value) { $stmt->bindValue($key + 5, $value); } $stmt->bindValue(count($accessArray) + 5, 0, PDO::PARAM_INT); // Offset for pagination $stmt->bindValue(count($accessArray) + 6, $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 time BETWEEN ? AND ? AND business_type IN ($placeholders)"); $stmt->bindValue(1, $start_date); $stmt->bindValue(2, $end_date); foreach ($accessArray as $key => $value) { $stmt->bindValue($key + 3, $value); } }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 ORDER BY time DESC LIMIT :offset, :recordsPerPage"); $stmt->bindParam(':offset', $offset, PDO::PARAM_INT); $stmt->bindParam(':recordsPerPage', $recordsPerPage, PDO::PARAM_INT); }else{ $stmt = $conn->prepare("SELECT COUNT(*) FROM cleads WHERE business_type IN ($placeholders) AND state IN ($state_placeholder)"); // Bind values for business types foreach ($accessArray as $key => $value) { $stmt->bindValue($key + 1, $value); } // Bind values for states $statePlaceholderStartIndex = count($accessArray) + 1; // Start index for state placeholders foreach ($state_array as $key => $state_value) { $stmt->bindValue($statePlaceholderStartIndex + $key, $state_value); } $stmt->execute(); $totalRecords = $stmt->fetchColumn(); $totalPages = ceil($totalRecords / $recordsPerPage); $offset = ($currentPage - 1) * $recordsPerPage; // Adjusting the SQL query to remove duplicate state placeholders $state_placeholders = implode(',', array_fill(0, count($state_array), '?')); // Generate placeholders for states $stmt = $conn->prepare("SELECT * FROM cleads WHERE business_type IN ($placeholders) AND state IN ($state_placeholders) ORDER BY time DESC LIMIT ?, ?"); // Bind values for business types $paramCount = count($accessArray); for ($i = 0; $i < $paramCount; $i++) { $stmt->bindValue($i + 1, $accessArray[$i]); } // Bind values for states $statePlaceholderStartIndex = $paramCount + 1; // Start index for state placeholders for ($i = 0; $i < count($state_array); $i++) { $stmt->bindValue($statePlaceholderStartIndex + $i, $state_array[$i]); } // Bind the offset and recordsPerPage parameters $stmt->bindValue($paramCount + count($state_array) + 1, $offset, PDO::PARAM_INT); $stmt->bindValue($paramCount + count($state_array) + 2, $recordsPerPage, PDO::PARAM_INT); } } $stmt->execute(); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); var_dump($rows); $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){ $lead_id = $row['id']; 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() . "

"; } ?>
Name ID Status Update Form Name Date & Time Quick Action

Add Lead

Lead Information