<?php

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

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

		//Admin info
		$stmt=$pdo->prepare("SELECT * FROM users WHERE userid = :userid");
		$stmt->bindParam(":userid", $userid, PDO::PARAM_STR);
		$stmt->execute();
		$row=$stmt->fetch();
		$userimage = (!empty($row["profilepix"]) ? "../img/users/".$row["profilepix"]: "../img/avatar.png");
		
		
		//get user ID from URL
		if(isset($_GET["user"])){
			$theUser = intval($_GET["user"]);
		}else{
			header("location: users.php");
		}
		
		
		//get user info
		$stmt=$pdo->prepare("SELECT * FROM users WHERE userid = :userid");
		$stmt->bindParam(":userid", $theUser, PDO::PARAM_STR);
		$stmt->execute();
		$userInfo=$stmt->fetch();
		$siteUserImg = (!empty($userInfo["profilepix"]) ? "../img/users/".$userInfo["profilepix"]: "../img/avatar.png");
		
	
?>

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


<!DOCTYPE html>

<html lang="en">

<head>

        <meta charset="utf-8" />

        <title> Mailing System</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="card-box col-md-7" style="margin-top:20px!important;margin: auto;">
				<h3 align="center" style='color:#767e80' id="wlcm">Send Custom Mail</h3><br>
				<div class="dropdown-divider" style='margin-top:-10px;margin-bottom:10px;'></div>

		<center><img src="<?php echo $siteUserImg;?>" class="avatars"></center><br>
		<div style="color:#405972; font-size:16px; margin-bottom:10px;text-align:center"><b><?php echo htmlspecialchars($userInfo["fullName"]);?>
		</b></div>
				
		<div class="dropdown-divider"></div>
		

		<!--Success on sent Msg-->
		<section id="success" class="display-none">
		<div class="success-display">Mail Sent Successfully <i class="fas fa-check"></i></div>
		<p><br>
		<div class="dropdown-divider"></div>
		<div style="text-align:center">
		<a href="userStats.php?getUser=<?php echo intval($theUser);?>" class="btn btnss"> <i class="fas fa-angle-left"></i> &nbsp; User Stats</a>
		<br><br>
		<a href="dashboard.php" style="color:#2e657e; font-size:16px;"><i class="fas fa-tachometer-alt"></i> Dashboard</a> 
		</div>
		</section>



				
			<div id="mailing" class="">
 
			<div class="form-group">
            <label for="email" style="margin-left:10px"><i class="fas fa-user"></i> Receiver email</label>
            <div class="col-sm-12">
			<input type="email" readonly name="email" class="form-control" id="email" value="<?php echo htmlspecialchars($userInfo["email"]);?>">
            </div></div>
			

			<div class="form-group">
            <label for="title" style="margin-left:10px"><i class="fas fa-envelope"></i> Mail Title</label>
            <div class="col-sm-12">
			<input type="text" name="title" class="form-control" id="title" placeholder="Enter mail title">
            </div></div>
			
			<br>
			<div class="form-group">
            <label for="msg" style="margin-left:10px"><i class="fas fa-edit"></i> Message body</label>
            <div class="col-sm-12">
			<textarea name="msg" class="form-control" id="msg" placeholder="Enter message"></textarea>
            <br>
				  
            
			<button id="send" class="btn btnss btn-block">Send Mail</button>
                
             </div></div></div>
			   
			   
               </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();
		 
 
	//send message
 
	$("#send").click(function(){
	
		let customMial = "customMial";
			
		let email = $("#email").val();
		let title = $("#title").val();
		let msg = $("#msg").val();
		let user = <?php echo $theUser; ?>;
		
		if(msg == ""){
			alert("Enter mailing message");
			return false;
		}else{
		

		$.ajax({
			url:'../mails/adminCustomMailUser.php',
			method:'POST',
			data:{customMial:customMial, email:email, title:title,msg:msg,user:user},
			beforeSend:function(){$(".coversoverlay").show()},
			success:function(data){
				
				console.log(data);
				$(".coversoverlay").hide();
				
			if(data == 1){
		
				//Hide form
				$("#mailing").addClass("display-none");

				//show success
				$("#success").removeClass("display-none");

			}
			
			}

		});
		
		}//Return false - empty msg
	
		});
	
 
 
 
	 
   });
   
   
   
   
   </script>
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
    </body>

</html>