mig
This commit is contained in:
@@ -204,8 +204,8 @@
|
||||
</thead>
|
||||
<tbody >
|
||||
<?php
|
||||
// Number of records per page
|
||||
$recordsPerPage = 500;
|
||||
//?bv=teenybeans&start_date=2024-05-04&end_date=2024-05-18
|
||||
|
||||
|
||||
// Current page
|
||||
if (isset($_GET['page']) && is_numeric($_GET['page'])) {
|
||||
@@ -217,63 +217,58 @@
|
||||
try {
|
||||
$conn = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
|
||||
$conn->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'] : '';
|
||||
|
||||
$searchTerm =isset($_GET['search']) ? $_GET['search'] : "%";
|
||||
$businessVertical =isset($_GET['bv']) ? $_GET['bv'] : "%";
|
||||
$start_date = isset($_GET['start_date']) ? $_GET['start_date'] : '2014-05-05';
|
||||
$end_date = isset($_GET['end_date']) ? $_GET['end_date'] : date('Y-m-d');
|
||||
$start_time = microtime(true);
|
||||
$resultsPerPage = 100;
|
||||
$page =isset($_GET['page']) ? $_GET['page'] : 1;
|
||||
$offset = ($page - 1) * $resultsPerPage ;
|
||||
$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 ?) 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, 0, PDO::PARAM_INT); // Offset for pagination
|
||||
$stmt->bindValue( 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 ?");
|
||||
$stmt->bindValue(1, $start_date);
|
||||
$stmt->bindValue(2, $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 ORDER BY time DESC LIMIT :offset, :recordsPerPage");
|
||||
$stmt->bindParam(':offset', $offset, PDO::PARAM_INT);
|
||||
$stmt->bindParam(':recordsPerPage', $recordsPerPage, PDO::PARAM_INT);
|
||||
}else{
|
||||
}
|
||||
}
|
||||
//first query to get the total number for pagination
|
||||
$sql = "SELECT COUNT(*) FROM cleads
|
||||
WHERE name LIKE :searchTerm OR phone LIKE :searchTerm OR id LIKE :searchTerm AND time BETWEEN :start_date AND :end_date AND verticals LIKE :businessVertical";
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->bindValue(':searchTerm', "%$searchTerm%");
|
||||
$stmt->bindValue(':limit', $resultsPerPage, PDO::PARAM_INT);
|
||||
$stmt->bindValue(':offset', $offset, PDO::PARAM_INT);
|
||||
$stmt->bindValue(':start_date', $start_date);
|
||||
$stmt->bindValue(':end_date', $end_date);
|
||||
$stmt->bindValue(':businessVertical', $businessVertical);
|
||||
$stmt->execute();
|
||||
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$row_count = count($rows);
|
||||
for ($i = 0; $i < $row_count; $i++) {
|
||||
// echo $row_count . " ";
|
||||
}
|
||||
echo "<p class='px-4'>Total ".$row_count." Rows Found</p>";
|
||||
$totalRows = $stmt->fetchColumn();
|
||||
|
||||
// second & final query to get the page_view data
|
||||
|
||||
$sql = "SELECT * FROM cleads
|
||||
WHERE name LIKE :searchTerm OR phone LIKE :searchTerm OR id LIKE :searchTerm AND time BETWEEN :start_date AND :end_date AND verticals LIKE :businessVertical
|
||||
ORDER BY id DESC LIMIT :limit OFFSET :offset";
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->bindValue(':searchTerm', "%$searchTerm%"); // PDO::PARAM_STR is the default data type binding so is not needed
|
||||
$stmt->bindValue(':limit', $resultsPerPage, PDO::PARAM_INT);
|
||||
$stmt->bindValue(':offset', $offset, PDO::PARAM_INT);
|
||||
$stmt->bindValue(':start_date', $start_date);
|
||||
$stmt->bindValue(':end_date', $end_date);
|
||||
$stmt->bindValue(':businessVertical', $businessVertical);
|
||||
$stmt->execute();
|
||||
$leads = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$totalResults = count($leads);
|
||||
$totalPages = ceil($totalRows / $resultsPerPage);
|
||||
|
||||
echo "<p class='px-4'>Total ".$totalRows." Rows Found</p>";
|
||||
// Status Conditional Color
|
||||
foreach($rows as $row){
|
||||
$only_date = explode(' ', $row['time']);
|
||||
$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;';}
|
||||
foreach($leads as $lead){
|
||||
$only_date =isset($lead['time']) ? substr($lead['time'], 0, 10): 'Not Available';
|
||||
$lead_id = $lead['id'];
|
||||
if($lead['status'] == 'New'){$conditional_background_color = 'background-color: #FFD9D9; border: 2px solid #FB5555; border-radius: 20px; text-align: center; color: #FB5555;';}
|
||||
elseif($lead['status'] == 'Contacted'){$conditional_background_color = 'background-color: #D4FFFF; border: 2px solid #2C9C9C; border-radius: 20px; text-align: center; color: #2C9C9C;';}
|
||||
elseif($lead['status'] == 'Disqualified'){$conditional_background_color = 'background-color: #CECECE; border: 2px solid #3F4254; border-radius: 20px; text-align: center; color: #3F4254;';}
|
||||
elseif($lead['status'] == 'Converted'){$conditional_background_color = 'background-color: #D4FDE7; border: 2px solid #40916C; border-radius: 20px; text-align: center; color: #40916C;';}
|
||||
elseif($lead['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 = '<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'];}
|
||||
?>
|
||||
@@ -298,36 +293,72 @@
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<a href="https://wa.me/<?php echo $row['phone'] ?>?text=Hello%2C%20how%20are%20you%3F"><i class="fab fa-whatsapp" style="font-size: 20px"></i></a>
|
||||
<a href="https://wa.me/<?php echo $lead['phone'] ?>?text=Hello%2C%20how%20are%20you%3F"><i class="fab fa-whatsapp" style="font-size: 20px"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<?php if($_SESSION['user_type'] == 'admin'){?>
|
||||
<td class="border-y-2 p-2">
|
||||
<input type="checkbox" name="selected_records[]" value="<?php echo $row['id']; ?>" id="<?php echo $row['id']; ?>" />
|
||||
<input type="checkbox" name="selected_records[]" value="<?php echo $lead['id']; ?>" id="<?php echo $lead['id']; ?>" />
|
||||
</td>
|
||||
<?php }?>
|
||||
<td class="border-y-2 p-2"><label for="<?php echo $row['id']; ?>"><?php echo $row['name'] ?></label></td>
|
||||
<td class="border-y-2 p-2 text-blue-500 hover:text-blue-700 hover:underline"><a href="/cleads/edit-lead/?id=<?php echo $row['id'] ?>"><?php echo $row['id'] ?></a></td>
|
||||
<td class="border-y-2 p-2"><div style="<?php echo $conditional_background_color; ?> font-weight: bold;"><?php echo $row['status'];?></div></td>
|
||||
<td class="border-y-2 p-2"><label for="<?php echo $lead['id']; ?>"><?php echo $lead['name'] ?></label></td>
|
||||
<td class="border-y-2 p-2 text-blue-500 hover:text-blue-700 hover:underline"><a href="/cleads/edit-lead/?id=<?php echo $lead['id'] ?>"><?php echo $lead['id'] ?></a></td>
|
||||
<td class="border-y-2 p-2"><div style="<?php echo $conditional_background_color; ?> font-weight: bold;"><?php echo $lead['status'];?></div></td>
|
||||
<!-- <td class="border-y-2 p-2">
|
||||
<p><i class="fa fa-envelope"> <?php // echo $row['email'] ?></i></p>
|
||||
<p><i class="fa fa-phone"> <?php // echo $row['phone'] ?></i></p>
|
||||
<p><i class="fa fa-envelope"> <?php // echo $lead['email'] ?></i></p>
|
||||
<p><i class="fa fa-phone"> <?php // echo $lead['phone'] ?></i></p>
|
||||
</td> -->
|
||||
<td class="border-y-2 p-2"><?php echo $row['formname'] ?></td>
|
||||
<td class="border-y-2 p-2"><?php echo $only_date[0]; ?></td>
|
||||
<td class="border-y-2 p-2"><?php echo $lead['formname'] ?></td>
|
||||
<td class="border-y-2 p-2"><?php echo $only_date; ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
echo "<p class='text-danger'>Error: " . $e->getMessage() . "</p>";
|
||||
}
|
||||
|
||||
$end_time = microtime(true);
|
||||
|
||||
// Calculate execution time
|
||||
$execution_time = ($end_time - $start_time);
|
||||
|
||||
// Output execution time
|
||||
echo "Page executed in: " . $execution_time . " seconds";
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
<!-- Pagination Links -->
|
||||
<div class="pagination">
|
||||
<?php
|
||||
|
||||
// $totalPages = ceil($totalRows / $resultsPerPage);
|
||||
// echo "<div>";
|
||||
// echo "<h3>Pages:</h3>-",$page,'-';
|
||||
// for ($i = 1; $i <= $totalPages; $i++) {
|
||||
// echo "<a href='?page=$i'>$i</a> ";
|
||||
// }
|
||||
// echo "</div>";
|
||||
|
||||
?>
|
||||
<?php
|
||||
|
||||
$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="inline-flex">
|
||||
<li><button class="px-4 py-2 text-green-600 transition-colors duration-150 bg-white border border-r-0 border-green-600 rounded-l-lg focus:shadow-outline hover:bg-green-100"> '; if($page>1) echo '<a href="?',$backPage,'"><','</a>'; echo ' </button></li>
|
||||
<li><button class="px-4 py-2 text-white transition-colors duration-150 bg-green-600 border border-r-0 border-green-600 focus:shadow-outline"> '.$page.' </button></li>
|
||||
<li><button class="px-4 py-2 text-green-600 transition-colors duration-150 bg-white border border-green-600 rounded-r-lg focus:shadow-outline hover:bg-green-100"> '; if($page<$totalPages) echo '<a href="?',$nextkPage,'">>','</a>'; echo ' </button></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
';
|
||||
|
||||
?>
|
||||
<!-- <div class="pagination">
|
||||
<?php if ($currentPage > 1): ?>
|
||||
<a href="?page=<?php echo ($currentPage - 1); ?>">Previous</a>
|
||||
<?php endif; ?>
|
||||
@@ -339,7 +370,7 @@
|
||||
<?php if ($currentPage < $totalPages): ?>
|
||||
<a href="?page=<?php echo ($currentPage + 1); ?>">Next</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div> -->
|
||||
|
||||
<!-- New Lead Form Section -->
|
||||
<div id="add-lead-form" class="add-lead-form">
|
||||
@@ -414,26 +445,6 @@
|
||||
<option value="Others">Others</option>
|
||||
</select>
|
||||
</div>
|
||||
<!-- <div class="flex flex-col mr-4">
|
||||
<label for="user">Lead Owner:</label>
|
||||
<select class="" style="border: 1px solid #363650; border-radius: 5px; padding: 6px;" type="text" name="user" id="user" >
|
||||
<?php
|
||||
// $conn = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
|
||||
// $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
// $stmt = $conn->prepare("SELECT * FROM users");
|
||||
// $stmt->execute();
|
||||
// $users_rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
// $row_count = count($users_rows);
|
||||
// if($row_count > 0){
|
||||
// foreach($users_rows as $users_data){
|
||||
// echo '<option value="'.$users_data['email'].'">'.$users_data['email'].'</option>';
|
||||
// }
|
||||
// } else{
|
||||
// echo '<p>No users Found</p>';
|
||||
// }
|
||||
?>
|
||||
</select>
|
||||
</div> -->
|
||||
</div>
|
||||
<div class="flex flex-col mr-4">
|
||||
<label for="note">Note:</label>
|
||||
@@ -532,7 +543,7 @@
|
||||
});
|
||||
function deleteCofermation(){
|
||||
let deleteButton = document.getElementById('delete-button');
|
||||
let leadID = document.getElementById('<?php echo $row['id']; ?>').value;
|
||||
let leadID = document.getElementById('<?php echo $row['id']; ?>').value; //getting Err: here
|
||||
if(leadID != null){
|
||||
if(deleteButton.style.display === 'flex'){
|
||||
deleteButton.style.display = 'none';
|
||||
@@ -570,20 +581,7 @@
|
||||
transform: translateX(0%);
|
||||
}
|
||||
}
|
||||
/* .add-lead-form{
|
||||
background-color: #F8F8F8;
|
||||
display: none;
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
right: 0%;
|
||||
transform: translate(-0%, -50%);
|
||||
width: 100%;
|
||||
max-width: 500px;
|
||||
box-shadow: 0px 0px 20px 0px #443780;
|
||||
border-radius: 5px;
|
||||
z-index: 100;
|
||||
height: 100%;
|
||||
} */
|
||||
|
||||
.delete-confirm{
|
||||
position: fixed;
|
||||
display: none;
|
||||
|
||||
Reference in New Issue
Block a user