<?php
include('header.php');
if ($_SESSION['userid'] != "ADMIN") {
    ?>
        <script>
            window.location.href = 'index.php';
        </script>
        <?php
        die;
    }

if (isset($_GET['userid']) && $_GET['userid'] != NULL) {
    $id = base64_decode($_GET['userid']);
    $res = mysqli_query($conn, "SELECT * FROM `usertable` WHERE userid='$id'");
    $data = mysqli_fetch_assoc($res);
}


if (isset($_POST['ahkweb'])  && $_POST['ahkweb'] == "ahkwebsolutions") {
    $name = mysqli_real_escape_string($conn,$_POST['name']);
    $walletamount = mysqli_real_escape_string($conn,$_POST['walletamount']);
    $email = mysqli_real_escape_string($conn,$_POST['email']);
    $usertype = mysqli_real_escape_string($conn,$_POST['usertype']);

    $username = $_SESSION['phone'];
    $ires = mysqli_query($conn,"UPDATE `usertable` SET `name`='$name',`walletamount`='$walletamount', `emailid`='$email', `usertype`='$usertype' WHERE userid='$id' ");

    if($ires){
        ?>
        <script>
            $(function(){
                Swal.fire(
                    'Success',
                    'User Updated Successfully',
                    'success'
                )
            });
        </script>
        <?php
    }else{
        ?>
        <script>
            $(function(){
                Swal.fire(
                    'Opps',
                    'Internal Server Error Please try Agin Later',
                    'error'
                )
            });
        </script>
        <?php
    }
}
?>

<style>
        .payment-form {
            max-width: 1000px;
            margin: auto;
            background: #fff;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 4px 10px rgb(0 0 0 / 80%);
        }

        .payment-form input {
            width: calc(100% - 20px);
            padding: 10px;
            margin: 10px 0;
            border: 1px solid #ccc;
            border-radius: 5px;
        }

        .payment-form button {
            width: 100%;
            padding: 10px;
            background: #28a745;
            color: #fff;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }

        .payment-form button:hover {
            background: #218838;
        }

        .qr-popup {
            display: none;
            position: fixed;
            top: 70px;
            left: 50%;
            transform: translateX(-50%);
            width: 300px;
            background: rgb(255, 255, 255);
            justify-content: center;
            padding: 20px;
            border-radius: 10px;
            text-align: center;
            color: #181818;
            border: 5px solid #28a745;
            /* Add a 5px border with green color */
            box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.2);
            /* Optional: Add a shadow for better styling */
        }

        .qr-popup img {
            max-width: 200px;
            margin: 10px auto;
        }

        .qr-popup button {
            margin-top: 10px;
            padding: 10px;
            background: #dc3545;
            color: #fff;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }
    </style>        
                   <div class="payment-form">


                        <!-- form start -->
                        <form method="post" action="" autocomplete="off" enctype="multipart/form-data">
                            <input type="hidden" name="_token" value="1TDde6CMH369W5RCLWCgTOjV8fR50kKPMlAfDgjN"> <input type="hidden" name="_method" value="PUT">
                            <input type="hidden" name="ahkweb" value="ahkwebsolutions">
                            <div class="card-body row">

                                <div class="form-group col-md-6">
                                    <label for="name">Full Name <span class="text-danger">*</span></label>
                                    <input type="text" class="form-control" id="name" name="name" placeholder="FULL NAME" value="<?php echo $data['name'] ?>" required="">
                                </div>
<div class="form-group col-md-6">
                                    <label for="name">Wallet: <span class="text-danger">*</span></label>
                                    <input type="text" class="form-control" id="walletamount" name="walletamount" placeholder="walletamount" value="<?php echo $data['walletamount'] ?>" required="">
                                </div>
                                <div class="form-group col-md-6">
                                    <label for="email">Email</label>
                                    <input type="text" class="form-control" id="email" name="email" placeholder="email" value="<?php echo $data['emailid'] ?>">
                                </div>

                               
                                <div class="form-group col-md-6">
                                    <label for="death_address">User Type<span class="text-danger">*</span></label>
                                    <select class="form-control" name="usertype" id="">
                                        <option  value="">Select Usertype</option>
                                        <option <?php if($data['usertype'] == 'OPERATOR'){ echo 'selected';} ?> value="OPERATOR">OPERATOR</option>
                                        <option <?php if($data['usertype'] == 'DISTRIBUTOR'){ echo 'selected';} ?> value="DISTRIBUTOR">DISTRIBUTOR</option>
                                    </select>
                                </div>

                            </div>
                            <!-- /.card-body -->

                            <div class="card-footer text-right pt-3 pb-3 mt-2">
                                <button type="submit" class="btn btn-primary btn-lg">Update</button>
                            </div>
                        </form>
                    </div>
<?php 
include('userfooter.php');
?>