Dedup Notications code and move to a modal instead of a drop menu

This commit is contained in:
johnnyq 2025-02-08 19:54:49 -05:00
parent 4ed0767f1c
commit a69b60703b
5 changed files with 82 additions and 74 deletions

View File

@ -103,11 +103,9 @@ try {
$access_permission_query = ""; // Ensure safe default if query fails
}
// Include the settings vars
require_once "get_settings.php";
//Detects if using an Apple device and uses Apple Maps instead of google
$iPod = stripos($_SERVER['HTTP_USER_AGENT'], "iPod");
$iPhone = stripos($_SERVER['HTTP_USER_AGENT'], "iPhone");
@ -119,12 +117,5 @@ if ($iPod || $iPhone || $iPad) {
$session_map_source = "google";
}
// Check if mobile device
$session_mobile = isMobile();
// Get Notification Count for the badge on the top nav
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('notification_id') AS num FROM notifications WHERE (notification_user_id = $session_user_id OR notification_user_id = 0) AND notification_dismissed_at IS NULL"));
$num_notifications = $row['num'];

View File

@ -1,4 +1,5 @@
<?php
require_once "modals/notifications_modal.php";
require_once "inc_confirm_modal.php";
?>

View File

@ -62,78 +62,22 @@
<!-- New Notifications Dropdown -->
<?php
$sql_notifications = mysqli_query($mysqli, "SELECT * FROM notifications
LEFT JOIN clients ON notification_client_id = client_id
WHERE notification_dismissed_at IS NULL
AND notification_user_id = $session_user_id
ORDER BY notification_id DESC LIMIT 8"
);
$sql_notifications = mysqli_query($mysqli, "SELECT * FROM notifications WHERE notification_user_id = $session_user_id AND notification_dismissed_at IS NULL ORDER BY notification_id DESC LIMIT 8");
$num_notifications = mysqli_num_rows($sql_notifications);
?>
<?php if ($num_notifications > 0) { ?>
<li class="nav-item dropdown" title="Notifications">
<a class="nav-link" data-toggle="dropdown" href="#">
<li class="nav-item">
<a class="nav-link" href="#notificationsModal" data-toggle="modal">
<i class="fas fa-bell"></i>
<span class="badge badge-light badge-pill navbar-badge position-absolute" style="top: 1px; right: 3px;"><?php echo $num_notifications; ?></span>
</a>
<div class="dropdown-menu dropdown-menu-xlg dropdown-menu-right">
<a href="notifications.php" class="dropdown-item dropdown-header">
<i class="fas fa-bell mr-2"></i>
<strong><?php echo $num_notifications; ?></strong>
Notifications
</a>
<div class="dropdown-divider"></div>
<?php
while ($row = mysqli_fetch_array($sql_notifications)) {
$notification_id = intval($row['notification_id']);
$notification_type = nullable_htmlentities($row['notification_type']);
$notification = nullable_htmlentities($row['notification']);
$notification_action = nullable_htmlentities($row['notification_action']);
$notification_timestamp = date('M d g:ia',strtotime($row['notification_timestamp']));
$notification_client_id = intval($row['notification_client_id']);
if(empty($notification_action)) { $notification_action = "#"; }
?>
<div class="dropdown-item">
<a class="text-dark" href="<?php echo $notification_action; ?>">
<p class="mb-1">
<span class="text-bold"><i
class="fas fa-bullhorn mr-2"></i><?php echo $notification_type; ?></span>
<small class="text-muted mt-1 float-right"><?php echo $notification_timestamp; ?></small>
</p>
<small class="text-secondary"><?php echo $notification; ?></small>
</a>
</div>
<?php if ($num_notifications) { ?>
<span class="badge badge-light badge-pill navbar-badge position-absolute" style="top: 1px; right: 3px;">
<?php echo $num_notifications; ?>
</span>
<?php } ?>
<div class="dropdown-divider"></div>
<a href="post.php?dismiss_all_notifications"
class="dropdown-item dropdown-footer text-secondary text-bold"><i
class="fas fa-check-double mr-2"></i>Dismiss all Notifications</a>
</div>
</li>
<?php } else { ?>
<li class="nav-item dropdown">
<a class="nav-link" data-toggle="dropdown" href="#" aria-expanded="false">
<i class="fas fa-bell"></i>
</a>
<div class="dropdown-menu dropdown-menu dropdown-menu-right" style="left: inherit; right: 0px;">
<span class="dropdown-item dropdown-header">No Notifications</span>
<div class="dropdown-divider"></div>
<div class="text-center text-secondary p-3">
<i class='far fa-4x fa-bell-slash'></i>
</div>
<div class="dropdown-divider"></div>
<a href="notifications_dismissed.php" class="dropdown-item dropdown-footer">See Dismissed
Notifications</a>
</div>
</li>
<?php } ?>
<!-- End New Notifications Dropdown -->
<li class="nav-item dropdown user-menu">
<a href="#" class="nav-link" data-toggle="dropdown">
<?php if (empty($session_avatar)) { ?>

View File

@ -0,0 +1,70 @@
<!-- Notifications Modal -->
<div class="modal" id="notificationsModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<?php if ($num_notifications) { ?>
<div class="modal-header">
<h5 class="modal-title">
<i class='fas fa-bell mr-2'></i>Notifications<span class="badge badge-secondary badge-pill px-3 ml-3"><?php echo $num_notifications; ?><span>
</h5>
<button type="button" class="close" data-dismiss="modal">
<span>&times;</span>
</button>
</div>
<?php } ?>
<div class="modal-body">
<?php if ($num_notifications) { ?>
<?php
while ($row = mysqli_fetch_array($sql_notifications)) {
$notification_id = intval($row['notification_id']);
$notification_type = nullable_htmlentities($row['notification_type']);
$notification_details = nullable_htmlentities($row['notification']);
$notification_action = nullable_htmlentities($row['notification_action']);
$notification_created_at_formated = date('M d g:ia',strtotime($row['notification_created_at']));
$notification_client_id = intval($row['notification_client_id']);
if(empty($notification_action)) { $notification_action = "#"; }
?>
<a class="text-dark dropdown-item px-1" href="<?php echo $notification_action; ?>">
<div>
<span class="text-bold">
<i class="fas fa-bullhorn mr-2"></i><?php echo $notification_type; ?>
</span>
<small class="text-muted float-right">
<?php echo $notification_created_at_formated; ?>
</small>
</div>
<small class="text-secondary"><?php echo $notification_details; ?></small>
</a>
<?php
}
} else {
?>
<div class="text-center text-secondary py-5">
<i class='far fa-6x fa-bell-slash'></i>
<h3 class="mt-3">No Notifications</h3>
</div>
<?php } ?>
</div>
<div class="modal-footer justify-content-end">
<?php if ($num_notifications) { ?>
<a href="post.php?dismiss_all_notifications&csrf_token=<?php echo $_SESSION['csrf_token'] ?>" class="btn btn-dark">
<i class="fas fa-check mr-2"></i>Dismiss all
</a>
<?php } else { ?>
<a href="notifications_dismissed.php" class="btn btn-dark">
See Dismissed Notifications
</a>
<?php } ?>
<button type="button" class="btn btn-light" data-dismiss="modal">
<i class="fas fa-times mr-2"></i>Close
</button>
</div>
</div>
</div>
</div>

View File

@ -35,6 +35,8 @@ if (isset($_GET['dismiss_notification'])) {
if (isset($_GET['dismiss_all_notifications'])) {
validateCSRFToken($_GET['csrf_token']);
$sql = mysqli_query($mysqli,"SELECT * FROM notifications WHERE notification_user_id = $session_user_id AND notification_dismissed_at IS NULL");
$num_notifications = mysqli_num_rows($sql);