<?php
include_once '../secure/dbconn.php';

if(isset($_GET['id'])) {
    $id = $_GET['id'];

    $sql = "SELECT * FROM  users WHERE id = '$id'";
    $result = mysqli_query($conn, $sql);
    $result_checker = mysqli_num_rows($result);
    if ($result_checker > 0) {
        while ($data = mysqli_fetch_assoc($result)) {
            // $enrollment_serial_no = $data['enrollment_serial_no'];
            // $company_name = $data['company_name'];
            // $surname = $data['surname'];
            // $first_name = $data['first_name'];
            $first_name = $data['first_name'];
            
            
            $last_name = $data["last_name"];
            $middle_name = $data["middle_name"];
            $username = $data["username"];
            $email_address = $data["email_address"];
            $password = $data["password"];
            $phone_number = $data["phone_number"];
            $total_deposit = $data["total_deposit"];
            $profit = $data["profit"];
            $running_trade = $data["running_trade"];
            $bonus = $data["bonus"];
            $profit_percentage = $data["profit_percentage"];
            $last_deposit = $data["last_deposit"];
            $type_of_plan = $data["type_of_plan"];
            $last_withdrawal = $data["last_wirhdrawal"];
            $status = $data["status"];
            $address = $data["address"];
        }
    }
                    

} else {
    // header("Location: ./index.php");
    die();
}

?>

<?php

$url="http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

  if(strpos($url, 'error') == true){


 echo '<script>
    setTimeout(function() {
        swal({
            title: "Error!",
            text: "Error Occured",
            type: "error"
        }, function() {
            window.location = "#0";
        });
    }, 1000);
  </script>';
  

    }elseif (strpos($url, 'updated') == true) {
        
 echo '<script>
    setTimeout(function() {
        swal({
            title: "Success!",
            text: "Data Updated successfully",
            type: "success"
        }, function() {
            window.location = "#0";
        });
    }, 1000);
</script>';

    } elseif (strpos($url, 'saved') == true) {
        
 echo '<script>
    setTimeout(function() {
        swal({
            title: "Success!",
            text: "Passport updated successfully",
            type: "success"
        }, function() {
            window.location = "#0";
        });
    }, 1000);
</script>';

    }




?>



<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Edit</title>
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome CSS -->
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" rel="stylesheet">

  <script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert-dev.js"></script>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.css">
</head>

<body>

    <style>
    .content {
        width: 80%;
        padding: 50px 5%;
        /* border: 1px solid gray; */
        border-radius: 10px;
        margin: 50px auto;
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    }
    </style>
    <div class="content">
        <a href="index.php" class="btn btn-secondary mb-3">Go Back</a>
        <!-- Modal content -->
        <div class="modal-content">
            
            <div style="margin: 0 auto; padding:20px 0;">
                
                

            </div>

            
            <h2 class='text-center text-primary'>UPDATE DETAILS</h2>
            <!--details -->
            <form id="modalForm" action="./addnew/edit.php" method="post" enctype="multipart/form-data">
                <div class="form-row row py-2">
                       
                    <input type="hidden" name="id" value="<?=$id?>">

                    <div class="form-group col-md-6">
                        <label for="firstName">First Name</label>
                        <input type="text" class="form-control" id="first_name" name="first_name" value="<?= $first_name?>"
                            required placeholder="First Name">
                    </div>
                    
                    <div class="form-group col-md-6">
                        <label for="lastname">Last Name</label>
                        <input type="text" class="form-control" id="last_name" name="last_name"
                            value="<?=$last_name?>" placeholder="Last Name">
                    </div>
                </div>
                <div class="form-row row py-2">
                    <div class="form-group col-md-6">
                            <label for="middleName">Middle Name</label>
                            <input type="text" class="form-control" id="middle_name" name="middle_name" value="<?= $middle_name?>"
                                required placeholder="Middle Name">
                    </div>
                    <div class="form-group col-md-6">
                        <label for="phoneNumber">Phone Number</label>
                        <input type="tel" class="form-control" id="phone_number" name="phone_number"
                            placeholder="Phone Number" value="<?=$phone_number?>">
                    </div>

                </div>
                <div class="form-row row py-2">
                    <div class="form-group col-md-6">
                        <label for="email">Email</label>
                        <input type="email" class="form-control" id="email_address" name="email_address" placeholder="Email"
                            value="<?=$email_address?>">
                    </div>
                    <div class="form-group col-md-6">
                        <label for="username">Username</label>
                        <input type="username" class="form-control" id="username" name="username" placeholder="Username"
                            value="<?=$username?>">
                    </div>
                </div>
                <div class="form-row row py-2">
                    <div class="form-group col-md-6">
                        <label for="status">Status</label>
                        <select id="status" class="form-control" name="status" required>
                            <option value='<?= $status?>' selected><?= $status?></option>
                            <option>live</option>
                            <option>suspended</option>
                        </select>
                    </div>
                    <div class="form-group col-md-6">
                        <label for="password">Password</label>
                        <input type="text" class="form-control" id="password" name="password" placeholder="Password"
                            value="<?=$password?>">
                    </div>


                </div>
                <div class="form-row row py-2">
                    <div class="form-group col-md-6">
                        <label for="total_deposit">Total Deposit</label>
                        <input type="total_deposit" class="form-control" id="total_deosit" name="total_deposit" placeholder="Total Deposit"
                            value="<?=$total_deposit?>">
                    </div>
                    <div class="form-group col-md-6">
                        <label for="bonus">Bonus</label>
                        <input type="bonus" class="form-control" id="bonus" name="bonus" placeholder="Bonus"
                            value="<?=$bonus?>">
                    </div>
                </div>
                <div class="form-row row py-2">
                    <div class="form-group col-md-6">
                        <label for="profit">Profit</label>
                        <input type="profit" class="form-control" id="profit" name="profit" placeholder="Profit"
                            value="<?=$profit?>">
                    </div>
                    <div class="form-group col-md-6">
                        <label for="running_trade">Running Trade</label>
                        <input type="running_trade" class="form-control" id="running_trade" name="running_trade" placeholder="Running Trade"
                            value="<?=$running_trade?>">
                    </div>
                </div>

                <div class="form-row row py-2">
                    <div class="form-group col-md-6">
                        <label for="profit_percentage">Profit Percentage</label>
                        <input type="profit_percentage" class="form-control" id="profit_percentage" name="profit_percentage" placeholder="Profit Percentage"
                            value="<?=$profit_percentage?>">
                    </div>
                    <div class="form-group col-md-6">
                        <label for="address">Address</label>
                        <input type="address" class="form-control" id="address" name="address" placeholder="Address"
                            value="<?=$address?>">
                    </div>
                </div>
                <div class="form-row row py-2">
                    <div class="form-group col-md-6">
                        <label for="last_deposit">Last Deposit</label>
                        <input type="last_deposit" class="form-control" id="last_deposit" name="last_deposit" placeholder="Last Deposit"
                            value="<?=$last_deposit?>">
                    </div>
                    <div class="form-group col-md-6">
                        <label for="last_withdrawal">Last Withdrawal</label>
                        <input type="last_withdrawal" class="form-control" id="last_withdrawal" name="last_withdrawal" placeholder="Last Withdrawal"
                            value="<?=$last_withdrawal?>">
                    </div>
                </div>


                <button type="submit" class="btn btn-success px-4 mt-4" name="update">Update</button>
            </form>
        </div>
    </div>
    <!-- Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
    <!-- jQuery Library -->
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <!-- Font Awesome JS -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/js/all.min.js"></script>
</body>

</html>