<?php

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

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

		//Admin 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");
		
		
		
		if(!isset($_GET["user"])){
			header("location:users.php");
		}else{
			$theUser = intval($_GET["user"]);
		}
		
		
		//get user info
		$stmt="SELECT * FROM users WHERE userid = :userid";
		$stmt=$pdo->prepare($stmt);
		$stmt->bindParam("userid", $theUser, PDO::PARAM_STR);
		$stmt->execute();
		$userInfo=$stmt->fetch();
		$userimg = (!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> Change Password </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">
                            
						
						
				<form class="col-md-7" style="margin-top:20px!important;margin: auto;">
				
                <div class="card-box">
				<h2 align="center" style='color:#767e80' id="wlcm">Update Password</h2><br>
				
		<center><img src="<?php echo $userimg;?>" 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>
		
		<section id="suc" class="display-none">
		<div class="success-display">Password Updated <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-home"></i> Back Home</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 align="center" style="color:#ff3737; margin-left:-20px!important; margin-bottom:30px;font-size:17px;font-weight:500" id="result"></div>
				
				<div id="passwordForm">
				  
				  <div class="form-group">
                    <label for="password" style="margin-left:10px"><i class="fas fa-key"></i> New password</label>
                    <div class="col-sm-12">
					<input type="password" name="password" class="form-control" id="password" placeholder="Enter new password">
                    </div>
                  </div>
				  
				  <div class="form-group">
                    <label for="ConfirmPassword" style="margin-left:10px"><i class="fas fa-key"></i> Confirm password</label>
                    <div class="col-sm-12">
					<input type="password" name="ConfirmPassword" class="form-control" id="ConfirmPassword" placeholder="Comfirm password">
                    </div>
                  </div>
				  
                 
	
                  <button type="submit" id="updatePass" class="btn btnss btn-block">Change password</button>
                
               </div>
			   
			   
               </div>
              </form>

                   
						   </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
 
 $("#updatePass").click(function(e){
	 e.preventDefault();
	 
		let updateUserPass = "updateUserPass";
			
		let user = <?php echo $theUser; ?>;
		let password = $("#password").val();
		let ConfirmPassword = $("#ConfirmPassword").val();
		

		$.ajax({
			url:'function.php',
			method:'POST',
			data:{updateUserPass:updateUserPass, password:password, ConfirmPassword:ConfirmPassword,user:user},
			beforeSend:function(){$(".coversoverlay").show()},
			success:function(data){
				$("#result").html(data);
				
				//console.log(data);
				$(".coversoverlay").hide();
				
			}
		});
		
		});
	
 
 
 
	 
   });
   
   
   
   
   </script>
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
    </body>

</html>