<?php
$pageName  = "Edit User";
include($_SERVER['DOCUMENT_ROOT'] . "/admin/layout/header.php");

// Ofofonobs Developer WhatsAPP +2348114313795


// Bank Script Developer - Use For Educational Purpose Only

// Other scripts Available


$acct_email = $_GET['id'];
$sql = "SELECT * FROM users WHERE acct_email =:acct_email";
$data = $conn->prepare($sql);
$data->execute(['acct_email' => $acct_email]);

$row = $data->fetch(PDO::FETCH_ASSOC);





if (isset($_POST['profile_save'])) {
    $acct_fullname = $_POST['acct_fullname'];
    $acct_type = $_POST['acct_type'];
    $acct_email = $_POST['acct_email'];
    $acct_phone = $_POST['acct_phone'];
    $acct_dob = $_POST['acct_dob'];
    $acct_balance = $_POST['acct_balance'];
    $acct_country = $_POST['acct_country'];



    $sql = "UPDATE users SET acct_fullname=:acct_fullname,acct_email=:acct_email,acct_phone=:acct_phone,acct_type=:acct_type,acct_country=:acct_country,acct_dob=:acct_dob,acct_balance=:acct_balance  WHERE acct_email=:acct_email";
    $stmt = $conn->prepare($sql);
    $stmt->execute([
                'acct_fullname' => $acct_fullname,
                'acct_email' => $acct_email,
                'acct_phone' => $acct_phone,
                'acct_type' => $acct_type,
                'acct_country' => $acct_country,
                'acct_dob' => $acct_dob,
                'acct_balance' => $acct_balance,
                'acct_email' => $acct_email
    ]);

    if (true) {
        $msg1 = "
        <div class='alert alert-warning'>
        
        <script type='text/javascript'>
             
                function Redirect() {
                window.location='./users.php';
                }
                document.write ('');
                setTimeout('Redirect()', 3000);
             
                </script>
                
        <center><img src='../assets/images/loading.gif' width='180px'  /></center>
        
        
        <center>	<strong style='color:black;'>Account updated successfully, Please Wait while we redirect you...
               </strong></center>
          </div>
        ";
    } else {
        toast_alert('error', 'Sorry something went wrong');
    }
}






if (isset($_POST['change_password'])) {
    $old_password = inputValidation($_POST['old_password']);
    $new_password = inputValidation($_POST['new_password']);
    $confirm_password = inputValidation($_POST['confirm_password']);

    $new_password2 = password_hash((string)$new_password, PASSWORD_BCRYPT);
    $verification = password_verify($old_password, $row['acct_password']);

    if ($verification === false) {
        toast_alert("error", "Incorrect Old Password");
    } else if ($new_password !== $confirm_password) {
        toast_alert("error", "Confirm Password not matched");
    } else if ($new_password === $old_password) {
        toast_alert('error', 'New Password Matched with Old Password');
    } else {
        $sql2 = "UPDATE users SET acct_password=:acct_password WHERE acct_email =:acct_email";
        $passwordUpdate = $conn->prepare($sql2);
        $passwordUpdate->execute([
            'acct_password' => $new_password2,
            'acct_email' => $acct_email
        ]);
        if (true) {
            $msg1 = "
            <div class='alert alert-warning'>
            
            <script type='text/javascript'>
                 
                    function Redirect() {
                    window.location='./users.php';
                    }
                    document.write ('');
                    setTimeout('Redirect()', 3000);
                 
                    </script>
                    
            <center><img src='../assets/images/loading.gif' width='180px'  /></center>
            
            
            <center>	<strong style='color:black;'>Your Password Change Successfully, Please Wait while we redirect you...
                   </strong></center>
              </div>
            ";
        } else {
            toast_alert('error', 'Sorry Something Went Wrong');
        }
    }
}

if (isset($_POST['status_submit'])) {
    $acct_status = $_POST['acct_status'];
    
    $sql = "UPDATE users SET acct_status=:acct_status WHERE acct_email =:acct_email";
    $stmt = $conn->prepare($sql);
    $stmt->execute([
        'acct_status' => $acct_status,
        'acct_email' => $acct_email
    ]);


    // $full_name = $row['firstname'] . " " . $row['lastname'];
    // $APP_NAME = WEB_TITLE;
    // $APP_URL = WEB_URL;
    // $SITE_ADDRESS = $page['url_address'];
    // $user_email = $row['acct_email'];
    // $acct_no = $row['acct_no'];
    // $acct_status = $row['acct_status'];
    // $message = $sendMail->AdminRegisterMsg($full_name, $acct_no, $acct_status, $APP_NAME, $APP_URL, $SITE_ADDRESS);
    // // User Email
    // $subject = "Account Status" . "-" . $APP_NAME;
    // $email_message->send_mail($user_email, $message, $subject);

    if (true) {
        $msg1 = "
        <div class='alert alert-warning'>
        
        <script type='text/javascript'>
             
                function Redirect() {
                window.location='./users.php';
                }
                document.write ('');
                setTimeout('Redirect()', 3000);
             
                </script>
                
        <center><img src='../assets/images/loading.gif' width='180px'  /></center>
        
        
        <center>	<strong style='color:black;'>Account Status Change to ($acct_status), Please Wait while we redirect you...
               </strong></center>
          </div>
        ";
    } else {
        toast_alert('error', 'Sorry Something Went Wrong');
    }
}




?>

<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            Edit User Profile
        </h1>
        <ol class="breadcrumb">
            <li><a href="./dashboard.php"><i class="fa fa-dashboard"></i> Dashboard</a></li>
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">

        <!-- SELECT2 EXAMPLE -->
        <form method="POST" enctype="multipart/form-data" action="">
            <div class="box box-default">
                <div class="box-header with-border">
                    <div class="box-tools pull-right">
                        <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
                    </div>
                </div>
                <!-- /.box-header -->
                <div class="box-body">
                    <div class="row">

                        <?php if (isset($msg1)) echo $msg1; ?>

                        <div class="col-md-6">

                            <div class="form-group">
                                <label for="exampleInputEmail1">Full Name</label>
                                <input type="text" class="form-control" placeholder="Full Name" name="acct_fullname" value="<?= $row['acct_fullname'] ?>">

                            </div>
                            
                            <!-- /.form-group -->
                            <div class="form-group">
                                <label for="exampleInputEmail1">Account Type</label>
                                 <select name="acct_type" class="form-control" data-width='100%'>
                                        <option value="<?= $row['acct_type'] ?>">Select Account Type</option>
                                        <option value="Regular User">Regular User</option>
                                        <option value="Vip User">Vip User</option>
                                    </select>
                            </div>

                            <div class="form-group">
                                <label for="exampleInputEmail1">Email address</label>
                                <input type="email" class="form-control" value="<?= $row['acct_email'] ?>" placeholder="Email address" name="acct_email">
                            </div>

                           
                            


                            <table class="table table-bordered mb-4">
                                <tbody>

                                      <tr>
                                        <th>Profile Picture</th>
                                        <th><a href="<?= $web_url ?>/assets/user/profile/<?= $row['acct_image'] ?>" target="_blank"><img src="<?= $web_url ?>/assets/user/profile/<?= $row['acct_image'] ?>" width="20%" alt=""></a></th>
                                    </tr>
                                    
                                    
                                </tbody>
                            </table>


                            <!-- /.form-group -->
                        </div>
                        <!-- /.col -->
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="exampleInputEmail1">Account Phone</label>
                                <input type="text"  required  minlength="8"  autocomplete="off" placeholder="Phone Number" value="<?= $row['acct_phone'] ?>" class="form-control wizard-required" name="acct_phone">
                            </div>
                            

                            <div class="form-group">
                                <label for="exampleInputEmail1">Date of Birth</label>
                                <input type="date" class="form-control" value="<?= $row['acct_dob'] ?>" name="acct_dob" placeholder="<?= $row['acct_dob'] ?>">
                            </div>
                            
                           
                            <div class="form-group">
                                <label for="exampleInputEmail1">Balance</label>
                                <input type="number" class="form-control" value="<?= $row['acct_balance'] ?>" name="acct_balance" placeholder="Balance">
                            </div>
                            
                            

                            <div class="form-group">
                                <label>Country</label>
                                <input type="text" value="<?= $row['acct_country'] ?>" class="form-control" name="acct_country" placeholder="Account country">
                            </div>

                           
                           
                             

                           

                        </div>

                        <!-- /.col -->
                    </div>
                    <!-- /.row -->
                </div>
                <!-- /.box-body -->
                <div class="box-footer">
                    <button type="submit" name="profile_save" class="btn btn-primary">Update Profile</button>
                </div>
            </div>
        </form>
        <!-- /.box -->

        <div class="row">
            <!-- left column -->
            <div class="col-md-6">
                <!-- general form elements -->
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title">Change Password</h3>
                    </div>
                    <!-- /.box-header -->
                    <!-- form start -->
                    <form method="post">
                        <div class="box-body">
                            <div class="form-group">
                                <label for="exampleInputEmail1">Current Password</label>
                                <input type="password" class="form-control" name="old_password" placeholder="Old Password">
                            </div>
                            <div class="form-group">
                                <label for="exampleInputEmail1">New Password</label>
                                <input type="password" class="form-control" name="new_password" placeholder="Old Password">
                            </div>
                            <div class="form-group">
                                <label for="exampleInputEmail1">Confirm New Password</label>
                                <input type="password" class="form-control" name="confirm_password" placeholder="Old Password">
                            </div>
                        </div>
                        <!-- /.box-body -->

                        <div class="box-footer">
                            <button type="submit" name="change_password" class="btn btn-primary">Change
                                Password</button>
                        </div>
                    </form>
                </div>
               
                <!-- /.box -->
            </div>
            <!--/.col (left) -->
            <!-- right column -->
            <div class="col-md-6">
                <!-- Horizontal Form -->
                 <div>
                    CURRENT STATUS: <b><?= $row['acct_status'] ?></b>
                </div>
                <form method="POST">
                    <div class="form-group">
                        <select class="form-control select2" name="acct_status" style="width: 100%;">
                            <option>Select Account Status</option>
                            <option value="active">Activate/Approve</option>
                            <option value="hold">Hold/Reject</option>
                        </select>
                    </div>
                    <div class="box-footer">
                        <button type="submit" name="status_submit" class="btn btn-primary">Update Account/Kyc</button>
                    </div>
                </form>
                <br><br>
                
                
                <!-- /.box -->
            </div>
            <!--/.col (right) -->
        </div>
        <!-- /.row -->


    </section>
    <!-- /.content -->
</div>
<!-- /.content-wrapper -->


<?php
include($_SERVER['DOCUMENT_ROOT'] . "/admin/layout/footer.php");

?>