<?php require ("header.php") ?>


<style>
        label {
            color: white; /* Text color of label */
            background-color: black; /* Set label background color to blue */
            padding: 5px; /* Optional: Add some padding for better look */
            display: inline-block; /* Make the label fit its content */
        }
    </style>
<!--============Password=============================-->

<?php
// session_start();
// require_once 'config.php'; // Include database connection

// Redirect if not logged in
// if (!isset($_SESSION['SESS_ADMINLOGGEDIN']) || $_SESSION['SESS_ADMINLOGGEDIN'] !== true) {
//     header("Location: login.php");
//     exit();
// }

$errorMessage = "";
$successMessage = "";

// Process password change request
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['change_password'])) {
    $currentPassword = trim($_POST['current_password']);
    $newPassword = trim($_POST['new_password']);
    $confirmPassword = trim($_POST['confirm_password']);
    $fullName = trim($_POST['full_name']);
    $username = trim($_POST['username']);

    // Validate the form
    if (!empty($currentPassword) && !empty($newPassword) && !empty($confirmPassword) && !empty($fullName) && !empty($username)) {
        // Fetch the admin data
        $stmt = $pdo->prepare("SELECT * FROM logins WHERE id = :id");
        $stmt->execute(['id' => $_SESSION['SESS_ADMINUSERID']]);
        $admin = $stmt->fetch(PDO::FETCH_ASSOC);

        if ($admin && password_verify($currentPassword, $admin['password'])) {
            // Check if new password matches confirm password
            if ($newPassword === $confirmPassword) {
                // Hash the new password
                $hashedPassword = password_hash($newPassword, PASSWORD_BCRYPT);

                // Update the password and username in the database
                $updateStmt = $pdo->prepare("UPDATE logins SET password = :password, fullname = :fullname, username = :username WHERE id = :id");
                $updateStmt->execute(['password' => $hashedPassword, 'fullname' => $fullName, 'username' => $username, 'id' => $_SESSION['SESS_ADMINUSERID']]);

                // Success message
                $successMessage = "Password and profile updated successfully!";
            } else {
                $errorMessage = "New password and confirm password do not match!";
            }
        } else {
            $errorMessage = "Incorrect current password!";
        }
    } else {
        $errorMessage = "All fields are required!";
    }
}
?>



<!--===========ends==password==================================-->









        <div wire:id="0ho7JEz65LVMGIzD4ceZ" wire:initial-data="{&quot;fingerprint&quot;:{&quot;id&quot;:&quot;0ho7JEz65LVMGIzD4ceZ&quot;,&quot;name&quot;:&quot;admin.manage-users&quot;,&quot;locale&quot;:&quot;en&quot;,&quot;path&quot;:&quot;admin\/dashboard\/manageusers&quot;,&quot;method&quot;:&quot;GET&quot;,&quot;v&quot;:&quot;acj&quot;},&quot;effects&quot;:{&quot;listeners&quot;:[],&quot;path&quot;:&quot;https:\/\/xtbtrading.live\/trade\/admin\/dashboard\/manageusers&quot;},&quot;serverMemo&quot;:{&quot;children&quot;:[],&quot;errors&quot;:[],&quot;htmlHash&quot;:&quot;ed570425&quot;,&quot;data&quot;:{&quot;pagenum&quot;:10,&quot;searchvalue&quot;:&quot;&quot;,&quot;orderby&quot;:&quot;id&quot;,&quot;orderdirection&quot;:&quot;desc&quot;,&quot;selectPage&quot;:false,&quot;selectAll&quot;:false,&quot;checkrecord&quot;:[],&quot;selected&quot;:&quot;&quot;,&quot;action&quot;:&quot;Delete&quot;,&quot;username&quot;:null,&quot;fullname&quot;:null,&quot;email&quot;:null,&quot;password&quot;:null,&quot;message&quot;:null,&quot;subject&quot;:null,&quot;plan&quot;:null,&quot;datecreated&quot;:null,&quot;topamount&quot;:null,&quot;toptype&quot;:null,&quot;topcolumn&quot;:&quot;Bonus&quot;,&quot;page&quot;:1,&quot;paginators&quot;:{&quot;page&quot;:1}},&quot;dataMeta&quot;:[],&quot;checksum&quot;:&quot;9e82a6adabccc53607a584c57da8f89b4130352eb62c7aa9cc50f9455ca3c494&quot;}}">
    <div class="main-panel">
        <div class="content bg-light">
            <div class="page-inner">
               
               
               
               
               
               
                <div class="mb-5 row">
                    <div class="col-md-12 ">
                        <!--<div class="card shadow p-4 bg-light">-->
                           
                           
   
           <?php 
if(isset($success)){
    echo $success;
}
?>

        
                           
                        <center>
     <div class="page-breadcrumb">
                <div class="row">
                    <div class="col-12 d-flex no-block align-items-center">
                        <h4 class="page-title">ADMIN PASSWORD</h4>
                        <div class="ml-auto text-right">
                            <nav aria-label="breadcrumb">
                                <ol class="breadcrumb">
                                    <li class="breadcrumb-item"><a href="index.php">Home</a></li>
                                    <li class="breadcrumb-item active" aria-current="page" #="password.php">Manage Password</li>
                                </ol>
                            </nav>
                        </div>
                    </div>
                </div>
            </div>
    </center>
                                  
                                  
                                  
                  <?php if (!empty($errorMessage)) : ?>
    <div style="color: red;"><?php echo $errorMessage; ?></div>
<?php endif; ?>

<?php if (!empty($successMessage)) : ?>
    <div style="color: green;"><?php echo $successMessage; ?></div>
<?php endif; ?>
                
                                    
                                    
 <h4 class="">Enter your details correctly and Click change Password Below</h4>
      <form method="POST" action="" class="form">             			
                                       <div class="card-body">
                   
                        
                       <div class="form-group">
                            <label for="password">Current Password</label>
                            <input type="password"  name="current_password" autocomplete="off" placeholder="********" required class='form-control bg-light text-dark'>
                        </div>
                        
                        <div class="form-group">
                            <label for="password">New Password</label>
                            <input type="password"  name="new_password" autocomplete="off" placeholder="********" required class='form-control bg-light text-dark'>
                        </div>
                        
                        <div class="form-group">
                            <label for="confirm-password">Confirm Password</label>
                            <input type="password"  name="confirm_password" autocomplete="off" placeholder="********" required class='form-control bg-light text-dark'>
                        </div>
                        
                        
                        <div class="form-group">
                            <label for="username">Username:</label>
                            <input type="text" name="username" value="<?php echo htmlspecialchars($_SESSION['SESS_ADMINUSERNAME']); ?>" required class='form-control bg-light text-dark'>
                        </div>
                        
                        
                        <div class="form-group">
                            <label for="full_name">Full Name:</label>
                            <input type="text" name="full_name" value="<?php echo htmlspecialchars($_SESSION['SESS_ADMINFULLNAME']); ?>" readonly class='form-control bg-light text-dark'>
                        </div>
                        
                        
    <br>
                        
                    </div>
                    <div class="card-footer">
                        <button type="submit" name="change_password" class="btn btn-primary">CHANGE PASSWORD</button>
                     </div>

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

                        
              

<?php require ("footer.php") ?>