Files
crm_php/.hta_slug/notifications/_home.php
Suvodip 1ba7ea57eb c
2024-05-08 22:07:11 +05:30

90 lines
4.7 KiB
PHP

<?php
require_once('.hta_config/crm_config.php');
require_once('.htac_header.php');
require_once('.htac_nav.php');
if($_SERVER['REQUEST_METHOD'] == "POST" && isset($_POST['mark_all_read']) && $_POST['mark_all_read']){
try {
$conn = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("UPDATE appointment SET view_status = 1 WHERE view_status = 0 AND email = :email");
$stmt->bindParam(':email', $_SESSION['email']);
$stmt->execute();
$saved_message = "Appointment updated successfully";
} catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
};
?>
<form method="post">
<div>
<div class="flex flex-row place-content-between py-2" style="border-bottom: 2px solid #A0A2AB; border-style: dashed;">
<p class="text-[25px] font-bold">Notifications</p>
<div>
<a href="/notifications?tab=past" class="text-[#6F6BFF]">Past Notifications</a> |
<input name="mark_all_read" type="submit" value="Mark all as read" class="text-[#6F6BFF] pr-6 cursor-pointer " />
</div>
</div>
</form>
<?php
try {
$conn = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$oneWeekAgo = date('Y-m-d', strtotime('-1 week'));
$stmt = $conn->prepare("SELECT * FROM appointment WHERE email = :email AND appt_date > :appoinment_expiry ORDER BY appt_date ASC");
$stmt->bindParam(':email', $_SESSION['email']);
$stmt->bindParam(':appoinment_expiry', $oneWeekAgo);
$stmt->execute();
$appt_data = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach($appt_data as $appt){
$leadID = json_decode($appt['leadid']);
if($appt['view_status'] == 0){
$notification_bg = 'background: #F5F4FFE8;';
$notification_batch = '<div style="width: 8px; height: 8px; background-color: red; border-radius: 50%;"></div>';
$clickButton = '';
}elseif($appt['view_status'] == 1){
$notification_bg = 'background: #fff;';
$notification_batch = '<div style="width: 8px; height: 8px; background-color: #fff; border-radius: 50%;"></div>';
$clickButton = 'disabled';
}
?> <div class="p-2">
<form method="post">
<button type="submit" class="w-full text-left" <?php echo $clickButton; ?>>
<div class="flex flex-col w-full p-2 rounded-md shadow" style="border: 3px solid #F5F4FFE8; <?php echo $notification_bg; ?>">
<div class="flex flex-row place-items-center justify-between">
<div class="flex flex-row place-items-center">🕑 Reminders for &nbsp;<?php echo $appt['name'].'&nbsp;&nbsp;'. $notification_batch; ?></div>
<div><?php echo $appt['appt_date']; ?></div>
</div>
<p><?php echo $appt['date']; ?></p>
<input type="hidden" name="status_id" value="<?php echo $appt['id'] ?>" />
</div>
</button>
</form>
</div>
<?php
}
} catch (PDOException $e) {
echo "<p class='text-danger'>Error: " . $e->getMessage() . "</p>";
};
if($_SERVER['REQUEST_METHOD'] == "POST" && isset($_POST['status_id']) && $_POST['status_id']){
try {
$conn = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("UPDATE appointment SET view_status = 1 WHERE id = :status_id AND email = :email");
$stmt->bindParam(':status_id', $_POST['status_id']);
$stmt->bindParam(':email', $_SESSION['email']);
$stmt->execute();
// $saved_message = "Appointment upd ated successfully";
echo '<script>window.location.href="/edit-lead/?id='.$leadID.'" </script>';
} catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
};
?>
</div>