<?php 
session_start();
require('../db.php');

include('inc/session.php');
						
	$user = $_SESSION['user'];
								
	$ins = mysqli_query($conn,"SELECT * FROM users WHERE email='$user' ");
	$data = mysqli_fetch_array($ins);
								
	$email = $data['email'];
	$rowpas = $data['pass'];
	$bal = $data['bal'];
							
	$deps = "SELECT * FROM deposit  ";
	$payment = $conn->query($deps);
	
	define("sitename","Vtoper");
define("footername","vtoper.com");
include('../inc/logo.php');
							
?> 

<?php include('inc/header.php');?>
<body class="fixed-nav sticky-footer bg-dark" id="page-top">



  <!-- Navigation-->
 <?php include('inc/nav.php');?>
        
  <!-- Navigation Ends--> 
      </ul>
    </div>
  </nav>
  <div class="content-wrapper">
  
    <div class="container-fluid">
      <!-- Breadcrumbs-->
     
      <div class="row">
        <div class="col-12">
          
     
     <h1 class="w3-xxxlarge w3-text-green" align="center"><b>Change Password</b></h1>
       

      <!-- Example Bar Chart Card-->
       
     <?php 
	 
$chek = mysqli_query($conn,"SELECT * FROM administrator WHERE user_id='$user' ");
$pdata = mysqli_fetch_array($chek);
$token = $pdata['pin'];


		  		
		if(isset($_POST['reset'])){
			
$old = $_POST['pwd'];

$new = $_POST['newpwd'];
$new2 = $_POST['newpin'];
$userid = $_POST['userid'];

$old = mysqli_real_escape_string($conn, $_POST['pwd']);
$new = mysqli_real_escape_string($conn, $_POST['newpwd']);
$new2 = mysqli_real_escape_string($conn, $_POST['newpin']);
$userid = mysqli_real_escape_string($conn, $_POST['userid']);

$hash = password_hash($new, PASSWORD_DEFAULT);




$newpwd = md5($new);
$oldpwd = md5($old);
$uid = mt_rand(10000,100000);

 
 if(!empty($old) && !empty($new) && !empty($userid) ){


if($pdata['pass'] == $oldpwd ){
	 
//echo "<div class='alert alert-danger'>Current Password Do not Match </div>"; 

 if($new !== $new2 ){
	 
echo "<div class='alert alert-danger'>New Password do not Match with Confirm New Password </div>";  


	 
	 } else{     
	   
	   

$updat = mysqli_query($conn,"UPDATE administrator SET user_id='$userid',pass='$newpwd' WHERE user_id='$user' ") or die(mysqli_error());


 



echo "<div class='alert alert-success'>Password Changed</div>";

	 }

 }else{
	 
	echo "<div class='alert alert-danger'>Current Password Do not Match</div>"; 
	 }
   
 }else{
	 
	echo "<div class='alert alert-danger'>No Entry made </div>"; 
	 }
       
    } 


			

	 
		?> 
       
  <form action="" method="post" autocomplete = 'off' > 

  <table class="table  margin-tp-10" id="transTable">
                     
                   <tr>
                        <td width="30%">
  
   <div class="form-group">
        <label><strong>Admin Username</strong></label>
		
		 <input type="text" id="userid" name="userid" value="<?php echo $pdata['user_id'];?>"  class="form-control" required>
		
      </div>

  
  <div class="form-group">
        <label><strong>Current Password</strong></label>
		
		 <input type="password" id="pwd" name="pwd"  class="form-control" required>
		
      </div>
  
  <div class="form-group">
        <label><strong>New Password</strong> </label>
		 <input type="password" name="newpwd" id="newpwd" class="form-control" required >
		    
		 <div id="charNum"></div>
		 
      </div> 

<div class="form-group">
        <label><strong>Confirm New Password</strong> </label>
		 <input type="password" name="newpin" id="newpin" class="form-control" required >
		    
		 <div id="charNum"></div>
		 
      </div> 
      
      
	  
      <button type="submit" id="submit" name="reset" class="btn btn-info">Save Changes</button>
    </form>  
                      </td>
                        </tr>
                            </table> 
  
             
            </div>
            
          </div>
          <!-- Card Columns Example Social Feed-->    
         </p>
        </div>
      </div>
    </div>
    <!-- /.container-fluid-->
    <!-- /.content-wrapper-->
   <?php include('inc/footer.php');?>