<?php $this->load->view('admin/comman/header');?>

<div class="clearfix"></div>
<div class="content-wrapper">
    <div class="container-fluid">
        <!-- Breadcrumb-->
        <div class="row pt-2 pb-2">
            <div class="col-sm-9">
                <h4 class="page-title">User Edit</h4>
                <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="javascript:void(0)">Dashboard</a></li>
                    <li class="breadcrumb-item"><a href="javascript:void(0)">Users</a></li>
                    <li class="breadcrumb-item active" aria-current="page">Edit</li>
                </ol>
            </div>

        </div>

        <div class="row">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12 mx-auto">
                        <div class="card">
                            <div class="card-body">

                                <form id="user_form" enctype="multipart/form-data">
                                    <div class="form-row mt-3">
                                        <div class="col-sm-6 ">
                                            <label for="input-1">FullName</label>
                                            <input type="text" required value="<?php echo $userlist[0]->fullname ?>"
                                                name="fullname" class="form-control" id="fullname"
                                                placeholder="Enter Name">
                                        </div>
                                    </div>
                                    <div class="form-row mt-3">
                                        <input type="hidden" name="id" value="<?PHP echo $userlist[0]->id; ?>">
                                        <div class="col-sm-6 ">
                                            <label for="input-1">Email</label>
                                            <input type="text" required value=""
                                                name="email" class="form-control" id="email" placeholder="Enter Email">
                                        </div>
                                    </div>
                                    <div class="form-row mt-3">
                                        <div class="col-sm-6 ">
                                            <label for="input-1">Passoword</label>
                                            <input type="password" required value="<?php echo $userlist[0]->password ?>"
                                                name="password" class="form-control" id="password"
                                                placeholder="Enter Password">
                                        </div>
                                    </div>
                                    <div class="form-row mt-3">
                                        <div class="col-sm-6 ">
                                            <label for="input-1">Mobile Number</label>
                                            <input type="text" required value=""
                                                name="mobile" class="form-control" id="mobile"
                                                placeholder="Enter Mobile Number">
                                        </div>
                                    </div>
                                    <div class="form-row mt-3">
                                        <div class="col-sm-6 ">
                                            <button type="button" onclick="updateuser()"
                                                class="btn btn-primary shadow-primary px-5">Save</button>
                                            <a href="<?php echo base_url(); ?>admin/users"
                                                class="border-primary btn btn-default px-5 ">Cancel
                                            </a>

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

<?php $this->load->view('admin/comman/footerpage');?>
<script type="text/javascript">
function updateuser() {

    displayLoader();
    var formData = new FormData($("#user_form")[0]);
    $.ajax({
        type: 'POST',
        url: '<?php echo base_url(); ?>admin/users/update',
        data: formData,
        cache: false,
        contentType: false,
        processData: false,
        dataType: "json",
        success: function(resp) {
            if (resp.status == '200') {
                hideLoader();
                document.getElementById("user_form").reset();
                toastr.success(resp.message, 'success');
                setTimeout(function() {
                    window.location.replace('<?php echo base_url(); ?>admin/users');
                }, 500);
            } else {
                hideLoader();
                var obj = resp.message;
                $.each(obj, function(i, e) {
                    toastr.error(e);
                });
            }
        }
    });

}
</script>