<?php
session_start();
require_once ('class.admin.php');
include_once ('session.php');

$reg_user = new USER();

if (!isset($_SESSION['email'])) {

    header("Location: login.php");

    exit();
}
$mail = $_SESSION['email'];

$ad = $reg_user->runQuery("SELECT * FROM admin WHERE email = '$mail'");
$ad->execute();
$rom = $ad->fetch(PDO::FETCH_ASSOC);


if (isset($_POST['edit'])) {
    $upass = $_POST['upass']; 
    $email = $_POST['email'];

    $stmt = $reg_user->runQuery("SELECT * FROM admin WHERE email=:email");
    $stmt1 = $reg_user->runQuery("SELECT * FROM admin WHERE upass=:upass");
    $stmt->execute(array(":email" => $email));
    $stmt1->execute(array(":upass" => $upass));
    $row = $stmt->fetch(PDO::FETCH_ASSOC);
    $row1 = $stmt1->fetch(PDO::FETCH_ASSOC);


    if ($stmt->rowCount() > 0 || $stmt1->rowCount() > 0) {
        $msg = "
		      <div class='alert alert-danger'>
				<button class='close' data-dismiss='alert'>&times;</button>
					<strong>Sorry!</strong>Email and Password Already Exist, Choose Another
			  </div>
			  ";
    } else {
        
     
        
        $ed = $reg_user->runQuery("UPDATE `admin` SET `upass` = '$upass', `email` = '$email' WHERE `admin`.`id` = 1");
        $ed->execute(array(":upass" => $password, ":email" => $_SESSION['email']));
        
        echo '<meta content="1; url=logout.php"       http-equiv="refresh" />';
        $msg = "<div class='alert alert-info'>
						<button class='close' data-dismiss='alert'>&times;</button>
						<strong>Login Details Was Successfully Changed!</strong>
						</div>";
    }
}

?>						</div>";
    }
}

?>
 <?php include 'headeradmin.php'; ?>
 

 <!---begin of Mobile View Here   only from Digital Forest Team-->
 
       <?php include 'menu.php'; ?>
  
  <!---End of Mobile View Here   only from Digital Forest Team-->
  
 
      <script type="text/javascript" src="paginator.js"></script>
        <script type="text/javascript" src="table.js"></script>
     
     
  <br><br><br><br><br><br><br><br>
    <div class="container-fluid mt--7">
     <!-- Table -->
      <div class="row">
        <div class="col">
          <div class="card shadow" >
            <div class="card-header border-0">
              <h3 class="mb-0"><a href=""   class="btn btn-danger">CHANGE ADMIN EMAIL & PASSWORD </a></h3>
            </div>
          
           <div class="card-body">
               
              <?php if (isset($msg)) echo $msg; ?>   
                  
               
<div class="container-fluid">
 


 						<form method="POST">
                           
                                <div class="row">
                                	
                                    
                                    <div class="col-md-6 form-group">
                                        <label>Enter New Email</label>
                                        <input type="text" name="email"  value="" class="input-sm form-control " required/>
                                    </div>
                                    
                                    
                                    
                                	<div class="col-md-6 form-group">
                                        <label>New Password</label>
                                        <input type="text" name="upass"  class="input-sm form-control " required/>
                                    </div>
                                    
                                    
                                </div>
                                
                        
                           
                                <div class="modal-footer" style="text-align:right;">
                                    <div class="btn-group">
                                
                                        <button type="submit" name="edit" class="btn btn-success btn-lg">Change Password</button>

                                    </div>
                                </div>
                          
                        </form>







</div>
               
               
               
          </div>
        </div>
      </div>
     </div>
 
    
       <?php include 'foot.php'; ?>



