Files
crm_php/.hta_slug/temp.php
2024-05-01 18:13:22 +05:30

78 lines
4.0 KiB
PHP

<?php
require_once('.hta_config/crm_config.php');
require_once('.htac_header.php');
require_once('.htac_nav.php');
// echo $_SESSION['access'];
?>
<div>
<table style="overflow-x: auto;">
<thead>
<tr>
<th style="text-align: center;">Name</th>
<th style="text-align: center;">ID</th>
<th style="text-align: center;">Status</th>
<th style="text-align: center;">Email</th>
<th style="text-align: center;">Phone</th>
<th style="text-align: center;">business_type</th>
<th style="text-align: center;">Time</th>
<th style="text-align: center;">Action</th>
</tr>
</thead>
<tbody>
<?php
try {
$conn = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$accessArray = explode(",", $_SESSION['access']);
$placeholders = rtrim(str_repeat('?,', count($accessArray)), ','); // Creating placeholders like ?,?,?,?
$stmt = $conn->prepare("SELECT COUNT(*) as total FROM cleads WHERE business_type IN ($placeholders)");
foreach ($accessArray as $key => $value) {
$stmt->bindValue($key + 1, $value);
}
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
$totalRecords = $result['total'];
$recordsPerPage = 100; // Number of records per page
$totalPages = ceil($totalRecords / $recordsPerPage);
$page = isset($_GET['page']) ? $_GET['page'] : 1; // Current page number
$offset = ($page - 1) * $recordsPerPage;
$stmt = $conn->prepare("SELECT * FROM cleads WHERE business_type IN ($placeholders) LIMIT $recordsPerPage OFFSET $offset");
foreach ($accessArray as $key => $value) {
$stmt->bindValue($key + 1, $value);
}
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$num_rows = $stmt->rowCount();
if ($num_rows >= 1) {
foreach($rows as $row){
echo ' <tr>
<td style="text-align: center;">'.$row['name'].'</td>
<td style="text-align: center;"><a href="/edit-lead/?id='.$row['id'].'">'.$row['id'].'</a></td>
<td style="text-align: center;">'.$row['status'].'</td>
<td style="text-align: center;">'.$row['email'].'</td>
<td style="text-align: center;">'.$row['phone'].'</td>
<td style="text-align: center;">'.$row['business_type'].'</td>
<td style="text-align: center;">'.$row['time'].'</td>
<td style="text-align: center;">Delete</td>
</tr>';
}
// Pagination links
// echo '<tr><td colspan="8" style="text-align: center;">';
// for ($i = 1; $i <= $totalPages; $i++) {
// echo '<a href="?page='.$i.'">'.$i.'</a> ';
// }
// echo '</td></tr>';
} else{
echo "<tr><td colspan='8' class='text-danger'>Not Found any Data</td></tr>";
}
} catch (PDOException $e) {
echo "<tr><td colspan='8' class='text-danger'>Error: " . $e->getMessage() . "</td></tr>";
};
?>
</tbody>
</table>
</div>