<?php
ob_start();
session_start();
//error_reporting(0);
require_once('../include/dbconnect.php');
		if(!isset($_SESSION['uid']))
		{
		    header("Location: login.php");
		}else{
			$uid=$_SESSION['uid'];
			
			$dt = date("Y-m-d");
			
			$sql = "select * from users where uID='$uid'"; 
            $rs_result =  $conn->query($sql); //run the query
            while($row = $rs_result->fetch_assoc()) { 
                $uid=$row['uID'];
                $fname=$row['fn'];
                $lname=$row['ln'];
                $add=$row['address'];
                $ct=$row['townCity'];
                $state=$row['state'];
                $country__=$row['country'];
                $pz=$row['zip'];
                $ph=$row['pNumber'];
                $em=$row['email'];
                $dob=$row['dob'];
                $gen=$row['gender'];
                $nat=$row['nation'];
                $occ=$row['occu'];
                $member_id=$row['memID'];
                $pw=$row['pass'];
                $cd=$row['cDate'];
                $llog = strtotime($row['LLogin']);
                $ll = date("jS M, Y h:ia", $llog);
                $pic=$row['picture'];
                $tok=$row['token'];
                $stta=$row['status'];
                $pc_st=$row['pc_status'];
                $twofa=$row['2fa'];
                $pc_ch___= $row['password_change'];
                $pc_ch= strtotime($pc_ch___);

                if(empty($pc_ch___)){
                    $last_p_change = "No registered change";
                }else{
                    $last_p_change = date("jS M, Y h:ia", $pc_ch);
                }
            }
            
            if(empty($pic)){
                $pic = "social-user.png";
            }

            $sqnt = "select * from notifications where user_id='".$uid."' and status='0'";
            $runqnt = $conn->query($sqnt);
            $count_notifs = mysqli_num_rows($runqnt);
		}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1.0, shrink-to-fit=no">
<link href="images/favicon.png" rel="icon" />
<title>Dashboard - Newage Union Bank </title>
<meta name="author" content="">

<!-- Web Fonts
============================================= -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Rubik:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap">

<!-- Stylesheet
============================================= -->
<link rel="stylesheet" type="text/css" href="vendor/bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="vendor/font-awesome/css/all.min.css" />
<link rel="stylesheet" type="text/css" href="css/stylesheet.css" />
<!-- Colors Css -->
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Smartsupp Live Chat script -->
<!-- Smartsupp Live Chat script -->
<!--<script src="//code.tidio.co/gahasrut5vrd6yiwvsgr2hdfdrhgkggi.js" async></script> -->
</head>
<body>
    <style>
    /* Header Styling */
    #header {
        background-color: #23233f;
        color: #fff;
        padding: 10px 0;
        border-bottom: 1px solid #333;
    }

    /* Logo Styling */
    #header .logo {
        margin-right: 20px;
    }

    /* Navbar Toggler Button */
    #header .navbar-toggler {
        border: none;
    }

    /* Navbar List Styling */
    #header .navbar-nav {
        margin-left: 20px;
    }

    /* Primary Navbar Link Styling */
    #header .navbar-nav .nav-link {
        color: #fff; /* Set text color to white */
        padding: 10px 10px; /* Apply padding of 10px 10px */
        font-size: 16px;
        text-decoration: none; /* Ensure no underline */
    }

    /* Navbar Links Hover Effect */
    #header .navbar-nav .nav-link:hover {
        background-color: #333;
        border-radius: 5px;
    }

    /* Dropdown Styling */
    #header .dropdown-menu {
        background-color: #23233f;
        border: none;
        padding: 10px;
        min-width: 200px; /* Ensure the dropdown has a consistent width */
    }

    /* Dropdown Item Styling */
    #header .dropdown-item {
        color: #fff;
        padding: 10px 15px;
        font-size: 14px;
    }

    /* Dropdown Item Hover Effect */
    #header .dropdown-item:hover {
        background-color: #333;
        border-radius: 5px;
    }

    /* Notification Icon Styling */
    .notifications .count {
        background-color: #ea6a28; /* Orange color for notification count */
        color: white;
        font-size: 12px;
        border-radius: 50%;
        padding: 2px 6px;
        position: absolute;
        top: -5px;
        right: -10px;
    }

    /* Responsive Navbar */
    @media (max-width: 991px) {
        /* Adjust the navbar items for smaller screens */
        #header .navbar-nav {
            text-align: center;
            margin-left: 0;
        }

        /* Make the dropdown button larger on mobile */
        #header .navbar-nav .nav-link {
            font-size: 18px;
        }

        /* Navbar Toggler button on mobile */
        .navbar-toggler {
            background-color: #ea6a28;  /* Orange color for toggler button */
        }

        /* Stack Navbar items vertically on mobile */
        .navbar-collapse {
            background-color: #23233f;
        }
    }
</style>


    <!-- Header -->
    <header id="header">
        <div class="container">
            <div class="header-row d-flex justify-content-between">
                <div class="header-column d-flex align-items-center"> 
                    <!-- Logo -->
                    <div class="logo me-3">
                        <a class="d-flex" href="index.php"> 
                            <img src="images/newage.png" style="width: 60%;" alt="Newage Union Bank" />
                        </a> 
                    </div>

                  <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#header-nav"> 
            <span></span> <span></span> <span></span> 
          </button>
          <!-- Collapse Button end --> 
          
          <!-- Primary Navigation
          ============================== -->
          <nav class="primary-menu navbar navbar-expand-lg">
            <div id="header-nav" class="collapse navbar-collapse">
              <ul class="navbar-nav me-auto">
                <li class="<?php echo $link_status1; ?>"><a href="index.php"><i class="fas fa-tachometer-alt"></i> &nbsp;Dashboard</a></li>
                <li class=""><a href="deposit.php"><i class="fas fa-arrow-up"></i>&nbsp;Deposit</a></li>
                <li class="<?php echo $link_status2; ?>"><a href="transactions.php">Transactions</a></li>
                <li class="<?php echo $link_status3; ?>"><a href="select-account.php"><i class="fas fa-share"></i> &nbsp;Wire Transfer</a></li> 
                <li><a class="" href="loan.php"><i class="fas fa-hand-holding-usd"></i>&nbsp;Loan</a></li>
                <li><a class="" href="settings-security.php"><i class="fas fa-shield-alt"> </i> &nbsp;Security</a></li>
                <!--<li><a class="" href="settings-payment-methods.php"><span><i class="fas fa-credit-card"></i> </span> Payment Methods</a></li>-->
                <!--<li><a class="" href="help.php"><i class="fas fa-life-ring"> </i>&nbsp;Need Help?</a></li>-->
                <!--<li><a class="" href="processing.php?request=logout"><i class="fas fa-sign-out-alt"> </i> Sign Out</a></li>-->
              </ul>
            </div>
          </nav>
          <!-- Primary Navigation end --> 
        </div>
        <div class="header-column justify-content-end"> 
          <!-- My Profile
          ============================== -->
          <nav class="login-signup navbar navbar-expand">
            <ul class="navbar-nav">
              <li class="dropdown notifications"> 
                <a class="dropdown-toggle" href="#">
                  <span class="text-5"><i class="far fa-bell"></i></span>
                  <span class="count"><?php echo $count_notifs; ?></span>
                </a>
                <ul class="dropdown-menu">
                  <li class="text-center text-3 py-2">Notifications (<?php echo $count_notifs; ?>)</li>
                  <li class="dropdown-divider mx-n3"></li>
                    <?php
                        $sn = "select * from notifications where user_id='$uid' and status='0' order by date desc";
                        $runq = $conn->query($sn);
                        $count = mysqli_num_rows($runq); 
                        
                        if($count > 0){
                            while($row = $runq->fetch_assoc())
                            {
                                $message=$row['notification'];
                                $n_date=$row['date'];
                                
                                $n_date_ = date("jS M, Y", strtotime($n_date));
                                
                                echo "
                                    <li><a class='dropdown-item' href='#'><i class='fas fa-bell'></i>".$message."<span class='text-1 text-muted d-block'>".$n_date_."</span></a></li>
                                ";
                            }
                        } else {
                            echo "<li style='text-align: center; color: grey;'>No new notifications!</li>";
                        }
                    ?>
                  <li class="dropdown-divider mx-n3"></li>
                  <li><a class="dropdown-item text-center text-primary px-0" href="notifications.php">See all Notifications</a></li>
                </ul>
              </li>
              <li class="dropdown profile ms-2"> 
                <a class="px-0 dropdown-toggle" href="#"><img class="rounded-circle" src="../userPic/<?php echo $pic; ?>" style="width: 50px;" alt=""></a>
                <ul class="dropdown-menu">
                  <li class="text-center text-3 py-2">Hi, <?php echo $fname." ".$lname; ?></li>
                  <li class="dropdown-divider mx-n3"></li>
                  <li><a class="dropdown-item" href="settings-profile.php"><i class="fas fa-user"></i>My Profile</a></li>
                  <!--<li><a class="dropdown-item" href="settings-security.php"><i class="fas fa-shield-alt"></i>Security</a></li>-->
                  <!--<li><a class="dropdown-item" href="settings-payment-methods.php"><i class="fas fa-credit-card"></i>Payment Methods</a></li>-->
                  <!--<li class="dropdown-divider mx-n3"></li>-->
                  <!--<li><a class="dropdown-item" href="help.php"><i class="fas fa-life-ring"></i>Need Help?</a></li>-->
                  <li><a class="dropdown-item" href="processing.php?request=logout"><i class="fas fa-sign-out-alt"></i>Sign Out</a></li>
                </ul>
              </li>
            </ul>
          </nav>
          <!-- My Profile end --> 
        </div>
      </div>
    </div>
  </header>


  <!-- Header End -->