This commit is contained in:
Suvodip
2024-05-08 22:07:11 +05:30
parent 72f4f36cb5
commit 1ba7ea57eb
3 changed files with 194 additions and 93 deletions

View File

@@ -60,6 +60,7 @@
require_once('.hta_config/crm_config.php');
require_once('.htac_header.php');
require_once('.htac_nav.php');
// deleteCofermation()
$today_date = date("Y-m-d");
$next_day = date("Y-m-d", strtotime("+1 day"));
$yesterday = date("Y-m-d", strtotime("-1 day"));
@@ -111,6 +112,23 @@
echo "Error: " . $e->getMessage();
}
}
?>
<?php
if(isset($_POST['delete_records']) && isset($_SESSION['user_type']) && $_SESSION['user_type'] == 'admin') {
if(isset($_POST['selected_records']) && !empty($_POST['selected_records'])) {
$selectedIds = $_POST['selected_records'];
try {
$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();
}
}
}
?>
<p class="text-[28px] font-bold p-4">Lead Management</p>
<div id="page-body" class="flex flex-row place-content-between px-4">
@@ -150,6 +168,11 @@
<button class="rounded-r-lg text-[#fff] p-1.5" style="background: linear-gradient(90deg, rgba(111, 107, 255, 0.91) 0%, rgba(68, 55, 128, 0.91) 100%);" type="submit"><i class="fa fa-search"></i></button>
</form>
</div>
<?php
if(isset($_SESSION['user_type']) && $_SESSION['user_type'] == 'admin'){
echo '<p onclick="deleteCofermation();" class="rounded-lg h-fit py-2 px-6 text-[#fff] text-center" style="background: linear-gradient(90deg, rgba(111, 107, 255, 0.91) 0%, rgba(68, 55, 128, 0.91) 100%); cursor: pointer;">Delete</p>';
}
?>
<button onclick="toggleDisplay();" class="rounded-lg p-2 h-fit text-[#fff]" style="background: linear-gradient(90deg, rgba(111, 107, 255, 0.91) 0%, rgba(68, 55, 128, 0.91) 100%); text-align: center;">Add Leads</button>
</div>
@@ -157,7 +180,18 @@
<table class="bg-[#fff] text-[#3F4254] rounded-lg font-bold" style="width: 100%;" >
<thead>
<tr>
<th class="text-center border-b-2 p-3">BV</th>
<?php
if(isset($_SESSION['user_type']) && $_SESSION['user_type'] == 'admin')
echo ' <th class="text-center border-b-2 p-3">
<div class="delete-confirm" id="delete-button" style="display: none;">
<p>Are you sure you want to delete this lead?</p>
<div class="flex flex-row space-x-4">
<p onclick="deleteCofermation();" class="rounded-lg p-2 text-[#443780] mr-4" style="border: 2px solid #443780; cursor: pointer;">No</p>
<button class="rounded-lg p-3 text-[#fff]" type="submit" name="delete_records" style="background: linear-gradient(90deg, rgba(111, 107, 255, 0.91) 0%, rgba(68, 55, 128, 0.91) 100%);">Yes</button>
</div>
</div>
</th>';
?>
<th class="text-center border-b-2 p-3">Quick Action</th>
<th class="text-center border-b-2 p-3">Name</th>
<th class="text-center border-b-2 p-3">ID</th>
@@ -185,33 +219,37 @@
$placeholderString = implode(',', array_fill(0, count($accessArray), '?'));
//first query to get the total number for pagination
$sql= "SELECT COUNT(*) FROM cleads WHERE state IN (".$_SESSION["states"].") AND business_type LIKE :businessVertical AND (name LIKE :searchTerm OR phone LIKE :searchTerm OR id LIKE :searchTerm OR email LIKE :searchTerm ) AND time BETWEEN :start_date AND :end_date ";
$parts = explode(',', $_SESSION["states"]);
$quotedParts = array_map(function($item) { return "'" . $item . "'";}, $parts);
$newStr = implode(',', $quotedParts);
$sql= "SELECT COUNT(*) FROM cleads WHERE state IN ($newStr) OR user LIKE :user AND business_type LIKE :businessVertical AND (name LIKE :searchTerm OR phone LIKE :searchTerm OR id LIKE :searchTerm OR email LIKE :searchTerm ) AND time BETWEEN :start_date AND :end_date ";
$stmt = $conn->prepare($sql);
$stmt->bindValue(':businessVertical', $businessVertical);
$stmt->bindValue(':searchTerm', "%".$searchTerm."%");
$stmt->bindValue(':start_date', $start_date);
$stmt->bindValue(':end_date', $end_date);
$stmt->bindValue(':user', $_SESSION["email"]);
$stmt->execute();
$totalRows = $stmt->fetchColumn();
// second & final query to get the page_view data
//SELECT * FROM cleads WHERE state IN ('HR', 'TR', 'MP', 'CT', 'LA', 'international');
$sql = "SELECT * FROM cleads WHERE business_type LIKE :businessVertical AND (name LIKE :searchTerm OR phone LIKE :searchTerm OR id LIKE :searchTerm OR email LIKE :searchTerm ) AND time BETWEEN :start_date AND :end_date ORDER BY id DESC LIMIT :limit OFFSET :offset";
$sql = "SELECT * FROM cleads WHERE state IN ($newStr) OR user LIKE :user AND business_type LIKE :businessVertical AND (name LIKE :searchTerm OR phone LIKE :searchTerm OR id LIKE :searchTerm OR email LIKE :searchTerm ) AND time BETWEEN :start_date AND :end_date ORDER BY id DESC LIMIT :limit OFFSET :offset";
$stmt = $conn->prepare($sql);
$stmt->bindValue(':businessVertical', $businessVertical, PDO::PARAM_STR );
$stmt->bindValue(':searchTerm', "%$searchTerm%"); // PDO::PARAM_STR is the default data type binding so is not needed
$stmt->bindValue(':start_date', $start_date);
$stmt->bindValue(':end_date', $end_date);
$stmt->bindValue(':user', $_SESSION["email"]);
$stmt->bindValue(':limit', $resultsPerPage, PDO::PARAM_INT);
$stmt->bindValue(':offset', $offset, PDO::PARAM_INT);
$stmt->execute();
$leads = $stmt->fetchAll(PDO::FETCH_ASSOC);
$totalResults = count($leads);
$totalPages = ceil($totalRows / $resultsPerPage);
if($resultsPerPage <= $totalRows) echo "<p class='px-4'>".$resultsPerPage." Out of ".$totalRows." Leads </p>";
else echo "<p class='px-4'>".$totalRows." Leads </p>";
var_dump($_SESSION["states"]);
// Status Conditional Color
foreach($leads as $lead){
$only_date =isset($lead['time']) ? substr($lead['time'], 0, 10): 'Not Available';
@@ -225,7 +263,6 @@
// if($row['status'] == 'Warm'){$conditional_status = '<div class="flex flex-row"><p>'.$row['status'].'</p><select class="focus: outline-none " style="'.$conditional_background_color.' border: none;"><option>Option 1</option><option>Option 2</option></select></div>';}elseif($row['status'] != 'Warm'){$conditional_status = $row['status'];}
?>
<tr>
<td class="border-y-2 p-2"><?php echo $lead['business_type'] ?></td>
<td class="border-y-2 p-2">
<div class="flex flex-row justify-center place-items-center">
<div class="xzmdropdown-wrapper">
@@ -278,7 +315,7 @@
$execution_time = ($end_time - $start_time);
// Output execution time
// echo "Page executed in: " . $execution_time . " seconds";
echo "Page executed in: " . $execution_time . " seconds";
?>
</tbody>
</table>
@@ -289,20 +326,15 @@
$getParams = $_GET; unset($getParams['page']); $getParams['page'] = $page-1; $backPage= http_build_query($getParams); unset($getParams['page']);
$getParams['page'] = $page+1; $nextkPage= http_build_query($getParams);
echo'
<div class="bg-white p-4 flex items-center flex-wrap">
<nav aria-label="Page navigation">
<ul class="flex flex-row ">
<li><button class="px-4 py-2 text-[#443780] border border-[#443780] rounded-l-lg" > &nbsp;'; if($page>1) echo '<a href="?',$backPage,'">&lt;','</a>'; echo ' &nbsp; </button></li>
<li><button class="px-4 py-2 text-white border-y border-[#443780]" style="background: linear-gradient(90deg, rgba(111, 107, 255, 0.91) 0%, rgba(68, 55, 128, 0.91) 100%);"> &nbsp; '.$page.' &nbsp; </button></li>
<li><button class="px-4 py-2 text-[#443780] border border-[#443780] rounded-r-lg" > &nbsp;'; if($page<$totalPages) echo '<a href="?',$nextkPage,'">&gt;','</a>'; echo ' &nbsp;</button></li>
</ul>
</nav>
</div>
';
// echo $totalPages;
echo'<div class="flex flex-row justify-end">
<button class="px-4 py-2 text-[#443780] border border-[#443780] rounded-l-lg" > &nbsp;'; if($page>1) echo '<a href="?',$backPage,'">&lt;','</a>'; echo ' &nbsp; </button>
<button class="px-4 py-2 text-white border-y border-[#443780]" style="background: linear-gradient(90deg, rgba(111, 107, 255, 0.91) 0%, rgba(68, 55, 128, 0.91) 100%);"> &nbsp; '.$page.' &nbsp; </button>
<button class="px-4 py-2 text-[#443780] border border-[#443780] rounded-r-lg" > &nbsp;'; if($page<$totalPages) echo '<a href="?',$nextkPage,'">&gt;','</a>'; echo ' &nbsp;</button>
</div>';
?>
<!-- New Lead Form Section -->
<div id="add-lead-form" class="add-lead-form">
<div class="flex flex-row place-content-between p-2" style="border-bottom: 2px solid #464E5F; border-style: dashed;">
@@ -474,7 +506,17 @@ echo'
}
}
});
function deleteCofermation(){
let deleteButton = document.getElementById('delete-button');
let leadID = document.getElementById('<?php if(isset($lead['id'])) echo $lead['id']; ?>').value; //getting Err: here
if(leadID != null){
if(deleteButton.style.display === 'flex'){
deleteButton.style.display = 'none';
}else{
deleteButton.style.display = 'flex'
}
}
}
</script>
<style>
@@ -505,4 +547,15 @@ echo'
}
}
.delete-confirm{
position: fixed;
display: none;
flex-direction: column;
background-color: #E6E5F4;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
padding: 40px 50px 40px 50px;
border-radius: 5px;
}
</style>