<?php

include("../config.php");
session_start();

if(isset($_SESSION["user_login"])){
	$userid = $_SESSION["user_login"];
}else{
		header("location: ../register-login.php");
	}
	

		//get user info
		$stmt="SELECT * FROM users WHERE userid = :userid";
		$stmt=$pdo->prepare($stmt);
		$stmt->bindParam("userid", $userid, PDO::PARAM_STR);
		$stmt->execute();
		$row=$stmt->fetch();
		$userimage = (!empty($row["profilepix"]) ? "../img/users/".$row["profilepix"]: "../img/avatar.png");
		
	
	
	
		//Get all messages
		$stmt=$pdo->prepare("SELECT * FROM contact WHERE status='unread' AND userid !=:userid ORDER BY id DESC");
		$stmt->bindParam(":userid",$userid, PDO::PARAM_STR);
		$stmt->execute();
		$noti=$stmt->fetchAll();
		$count = $stmt->rowCount();
	

		
	
?>

<style>
form label{
	font-weight:500!important;
	color:#444;
	cursor:pointer;
	font-size:16px!important;
}

.unread{
	background:#f8fafb!important;
}
.unread:hover{
	background:#f2f2f2!important;
}
</style>


<!DOCTYPE html>

<html lang="en">

<head>

        <meta charset="utf-8" />

        <title>Notifications</title>

        <meta name="viewport" content="width=device-width, initial-scale=1.0">

        <meta content="A fully featured cryptocurrency investment platform" name="description" />

        <meta content="Coderthemes" name="author" />

        <meta http-equiv="X-UA-Compatible" content="IE=edge" />

      

            <link rel="stylesheet" type="text/css" href="w3.css">

        <!-- Bootstrap Css -->

        <link href="assets/css/bootstrap.min.css" id="bootstrap-stylesheet" rel="stylesheet" type="text/css" />

        <!-- Icons Css -->

        <link href="assets/css/icons.min.css" rel="stylesheet" type="text/css" />

        <!-- App Css-->

        <link href="assets/css/app.min.css" id="app-stylesheet" rel="stylesheet" type="text/css" />

		<link href="../css/style7eda3860.css" rel="stylesheet">

    </head>



    <body>


	<div class='coversoverlay'>
	<center><img src="../img/loader.gif" style="width:60px; margin-top:20%;"></center>
	</div>

  <!-- Begin page -->
  <div id="wrapper" style="overflow:auto!important">

    
	
	  <!-- Topbar Start -->
	<?php
	include("header.php");
	?>
    <!-- end Topbar -->
	
	

    <!-- ========== Left Sidebar Start ========== -->
    <div class="left-side-menu">

      <div class="slimscroll-menu">

        <!-- User box -->
        <div class="user-box text-center ">

          <div class="dropdown">
            <a href="#" class="user-name dropdown-toggle h5 mt-2 mb-1 d-block" data-toggle="dropdown" aria-expanded="false"></a>
            <div class="dropdown-menu user-pro-dropdown">




            </div>
          </div>


        </div>

        <!--- Sidemenu -->
        <?php include("sidebar.php");?>
		
        <!-- End Sidebar -->
        <div class="clearfix"></div>



                </div>

                <!-- Sidebar -left -->



            </div>

            <!-- Left Sidebar End -->






            <div class="content-page" >

                <div class="content" style="width: 100%;color: white;">



                    <!-- Start Content-->

                    <div class="container-fluid" >

                        <div id="google_translate_element"></div>

                         <div class="row">

                            <div class="col-md-12" style="padding-left:0px; padding-right:0px">
                            
						
						
				<div class="col-md-7" style="margin-top:20px!important;margin: auto;">
                <div class="card-box" style="padding:0px;">
				
				
				
				
	<?php

		foreach($noti as $notis){
		
		//get sender info
		$stmt=$pdo->prepare("SELECT * FROM users WHERE userid=:userid");
		$stmt->bindParam("userid", $notis["userid"], PDO::PARAM_STR);
		$stmt->execute();
		$msg=$stmt->fetch();
		$msgImg = (!empty($msg["profilepix"]) ? "../img/users/".$msg["profilepix"]: "../img/avatar.png");

		?>



		<div id="<?php echo $msg["userid"];?>"  class="getMsg">
		  <a href="inbox.php?user=<?php echo $msg["userid"];?>" class="dropdown-item <?php if($notis["status"]=="unread"){echo 'unread';}?>" 
		  style="padding:15px;">
            <!-- Message Start -->
            <div class="media">
              <img src="<?php echo $msgImg;?>" alt="User Avatar" class="img-size-50 mr-3 " 
			  style="width:60px; height:60px;border-radius:50%;border:2px solid #d3d6d7">
              <div class="media-body">
                <h3 class="dropdown-item-title" style="font-size:17px;">
                  <?php echo htmlspecialchars($msg["fullName"]);?> &nbsp; 
				  <span style="color:#979797;font-weight:normal">Reply <i class="fa fa-share"></i></span>
                  <span class="float-right text-sm text-danger"><i class="fas fa-star"></i></span>
                </h3>
                <p class="text-sm">
				<?php echo htmlspecialchars(substr($notis["message"],0,25))."...";?>
				</p>
                <p class="text-sm text-muted"><i class="far fa-clock mr-1"></i><?php echo date("jS F, Y", strtotime($notis["received"]))?></p>
              </div>
            </div>
            <!-- Message End -->
          </a>
		  </div>
		<div class="dropdown-divider" style="margin:0;"></div>
		  
		  
	<?php } ?>	
				
				
				
				
					
					
					</div>
					</div>
					</div> <!-- container-fluid -->



                </div> <!-- content -->
                </div> 
              
					</div> 
	
					</div>
               


       

        <!-- Vendor js -->

        <script src="assets/js/vendor.min.js"></script>



        <!-- knob plugin -->

        <script src="assets/libs/jquery-knob/jquery.knob.min.js"></script>



        <!--Morris Chart-->

        <script src="assets/libs/morris-js/morris.min.js"></script>

        <script src="assets/libs/raphael/raphael.min.js"></script>



        <!-- Dashboard init js-->

        <script src="assets/js/pages/dashboard.init.js"></script>



        <!-- App js -->

        <script src="assets/js/app.min.js"></script>

   
   
   
   
   
   
   
   
   
   <script>
   
   $(document).ready(function(){
	
	$('.coversoverlay').hide();
		 
 
 
 
	
 //Update notification to read when clicked - button in header.php
	$(".getMsg").click(function(){
		
		let senderID = this.id
		
		$.ajax({
			url:'../processChat.php',
			method:'POST',
			data:{senderID:senderID},
			success:function(data){ }
		});
		
	});
 
 
 
 
	 
   });
   
   
   
   
   </script>
   
   
   
   
   
   
   
   
   
   
   

<!--Start of Tawk.to Script-->
<script type="text/javascript">
var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
(function(){
var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
s1.async=true;
s1.src='https://embed.tawk.to/649b88c194cf5d49dc6039bd/1h3vosdlg';
s1.charset='UTF-8';
s1.setAttribute('crossorigin','*');
s0.parentNode.insertBefore(s1,s0);
})();
</script>
<!--End of Tawk.to Script-->

   
   
   
   
    </body>

</html>