71 lines
3.0 KiB
PHP
71 lines
3.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>
|
|
<a style="float: right; padding: 10px;" href="/cleads/add-lead">Add Leads</a>
|
|
</div>
|
|
<?php
|
|
// try {
|
|
// $conn = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
|
|
// $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
// $stmt = $conn->prepare("SELECT * FROM users WHERE email=:email");
|
|
// $stmt->bindParam(':email', $_SESSION['email']);
|
|
// $stmt->execute();
|
|
// $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
// $num_rows = $stmt->rowCount();
|
|
// foreach($rows as $row){
|
|
// $user_access_data = explode(",", $row['access']);
|
|
// foreach($user_access_data as $access_data){
|
|
// echo '<div style="display: flex; flex-direction: row;"><a href="/cleads/by-business-verticals/?bv='.$access_data.'" style="margin: 10px;">'.$access_data.'</a></div>';
|
|
// }
|
|
// }
|
|
// } catch (PDOException $e) {
|
|
// echo "<p class='text-danger'>Error: " . $e->getMessage() . "</p>";
|
|
// };
|
|
|
|
try {
|
|
$conn = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
|
|
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
if($_SESSION['user_type'] == 'admin'){
|
|
$stmt = $conn->prepare("SELECT * FROM cleads ORDER BY time DESC");
|
|
}else{
|
|
$accessArray = explode(",", $_SESSION['access']);
|
|
$placeholders = rtrim(str_repeat('?,', count($accessArray)), ','); // Creating placeholders like ?,?,?,?
|
|
$stmt = $conn->prepare("SELECT * FROM cleads WHERE business_type IN ($placeholders) ORDER BY time DESC");
|
|
foreach ($accessArray as $key => $value) {
|
|
$stmt->bindValue($key + 1, $value);
|
|
}
|
|
// $stmt->bindValue(":user", $_SESSION['email']);
|
|
}
|
|
$stmt->execute();
|
|
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
?>
|
|
<div id="grid"></div>
|
|
<script>
|
|
const grid = new gridjs.Grid({
|
|
columns: ["Name",{name: "ID", formatter: (cell) => {return gridjs.html(`<a href="/cleads/edit-lead/?id=${cell}">${cell}</a>`);}},"Status", "Email", "Phone", "Time", {name: "ID", formatter: (cell) => {return gridjs.html(`<a href="/cleads/delete-lead/?id=${cell}">Delete</a>`);}}],
|
|
pagination: {limit: 100},
|
|
search: true,
|
|
sort: true,
|
|
resizable: true,
|
|
data: () => {
|
|
return new Promise((resolve, reject) => {
|
|
setTimeout(() => {
|
|
resolve(<?php echo json_encode($rows); ?>);
|
|
}, 1000);
|
|
});
|
|
},
|
|
loading: true
|
|
});
|
|
grid.render(document.getElementById("grid"));
|
|
</script>
|
|
<?php
|
|
} catch (PDOException $e) {
|
|
echo "<p class='text-danger'>Error: " . $e->getMessage() . "</p>";
|
|
}
|
|
?>
|
|
|